From: cajus Date: Thu, 21 Jan 2010 14:44:24 +0000 (+0000) Subject: Updated list handling X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=37a863af6c001e5760070adb1d74dc77e4df61f9;p=gosa.git Updated list handling git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@15236 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-core/include/class_sortableListing.inc b/gosa-core/include/class_sortableListing.inc index f4ad8d6d3..06d817806 100644 --- a/gosa-core/include/class_sortableListing.inc +++ b/gosa-core/include/class_sortableListing.inc @@ -30,13 +30,14 @@ class sortableListing { private $id; private $data= array(); + private $keys= array(); private $displayData= array(); private $columns= 0; private $deleteable= false; private $editable= false; + private $colorAlternate= false; private $instantDelete= true; private $action; - private $targets; private $mapping; private $current_mapping; private $active_index; @@ -52,15 +53,7 @@ class sortableListing { global $config; // Save data to display - $this->setData($data); - if (!$displayData) { - $displayData= array(); - foreach ($data as $value) { - $displayData[]= array($value); - } - } - - $this->setDisplayData($displayData); + $this->setListData($data, $displayData); // Generate instance wide unique ID $tmp= gettimeofday(); @@ -74,6 +67,21 @@ class sortableListing { } + public function setListData($data, $displayData= null) + { + // Save data to display + $this->setData($data); + if (!$displayData) { + $displayData= array(); + foreach ($data as $key => $value) { + $displayData[$key]= array($value); + } + } + + $this->setDisplayData($displayData); + } + + private function setData($data) { $this->data= $data; @@ -87,10 +95,11 @@ class sortableListing { } // Transfer information - $this->displayData= $data; + $this->displayData= array_values($data); + $this->keys= array_keys($data); // Create initial mapping - $this->mapping= array_keys($data); + $this->mapping= range(0, abs(count($this->keys)-1)); $this->current_mapping= $this->mapping; // Find the number of coluns @@ -121,6 +130,12 @@ class sortableListing { } + public function setColorAlternate($flag) + { + $this->colorAlternate= $flag; + } + + public function setEditable($flag) { $this->editable= $flag; @@ -191,6 +206,7 @@ class sortableListing { // Do we need a header? if ($this->header) { $result.= " \n \n"; + $first= " style='border:0'"; for ($i= 0; $i<$this->columns; $i++) { $link= "href='?plug=".$_GET['plug']."&PID=".$this->id."&act=SORT_$i'"; $sorter= ""; @@ -199,10 +215,11 @@ class sortableListing { } if ($this->reorderable) { - $result.= " ".(isset($this->header[$i])?$this->header[$i]:"").""; + $result.= " ".(isset($this->header[$i])?$this->header[$i]:"").""; } else { - $result.= " ".(isset($this->header[$i])?$this->header[$i]:"")."$sorter"; + $result.= " ".(isset($this->header[$i])?$this->header[$i]:"")."$sorter"; } + $first= ""; } if ($action_width) { $result.= " "; @@ -216,7 +233,7 @@ class sortableListing { if (strpos($this->acl, 'r') !== false) { foreach ($this->mapping as $nr => $row) { $editable= $this->editable?" onclick='$(\"edit_".$this->id."_$nr\").click()'":""; - $result.= " \n"; + $result.= " \n"; $first= " style='border:0'"; foreach ($this->displayData[$row] as $column) { $result.= " ".htmlentities($column)."\n"; @@ -371,7 +388,7 @@ class sortableListing { $tmp= array(); foreach ($this->mapping as $src => $dst) { - $tmp[$src]= $this->data[$dst]; + $tmp[$this->keys[$dst]]= $this->data[$dst]; } return $tmp; @@ -417,11 +434,17 @@ class sortableListing { } - public function addEntry($entry, $displayEntry= null) + public function addEntry($entry, $displayEntry= null, $key= null) { // Only add if not already there - if (in_array($entry, $this->data)) { - return; + if (!$key) { + if (in_array($entry, $this->data)) { + return; + } + } else { + if (isset($this->data[$key])) { + return; + } } // Prefill with default value if not specified @@ -430,11 +453,21 @@ class sortableListing { } // Append to data and mapping - $this->data[]= $entry; + if ($key) { + $this->data[$key]= $entry; + $this->keys[]= $key; + } else { + $this->data[]= $entry; + $this->keys[]= count($this->mapping); + } $this->displayData[]= $displayEntry; $this->mapping[]= count($this->mapping); $this->modified= true; } + public function getKey($index) { + return isset($this->keys[$index])?$this->keys[$index]:null; + } + }