X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=gosa-core%2Finclude%2Fclass_sortableListing.inc;h=3af979b285c2ac88fa4a9f016fb592e53e15da6c;hb=198fc11cacca32ca2c0dc33505bde39a38b999e6;hp=b0539c2029bdd44afafb947aade2339d0eff0466;hpb=4da9316a0d7d9a6ac25c9b1c09265b8dc12a382a;p=gosa.git diff --git a/gosa-core/include/class_sortableListing.inc b/gosa-core/include/class_sortableListing.inc index b0539c202..3af979b28 100644 --- a/gosa-core/include/class_sortableListing.inc +++ b/gosa-core/include/class_sortableListing.inc @@ -60,9 +60,27 @@ class sortableListing { // Save data to display $this->setListData($data, $displayData); + // Get list of used IDs + if(!session::is_set('sortableListing_USED_IDS')){ + session::set('sortableListing_USED_IDS',array()); + } + $usedIds = session::get('sortableListing_USED_IDS'); + // Generate instance wide unique ID - $tmp= gettimeofday(); - $this->id= 'l'.md5($tmp['sec']); + $id = ""; + while($id == "" || in_array($id, $usedIds)){ + + // Wait 1 msec to ensure that we definately get a new id + if($id != "") usleep(1); + $tmp= gettimeofday(); + $id = 'l'.md5(microtime().$tmp['sec']); + } + + // Only keep the last 10 list IDsi + $usedIds = array_slice($usedIds, count($usedIds) -10, 10); + $usedIds[] = $id; + session::set('sortableListing_USED_IDS',$usedIds); + $this->id = $id; // Set reorderable flag $this->reorderable= $reorderable; @@ -71,6 +89,15 @@ class sortableListing { } } + public function setReorderable($bool) + { + $this->reorderable= $bool; + } + + public function setDefaultSortColumn($id) + { + $this->sortColumn = $id; + } public function setListData($data, $displayData= null) { @@ -95,18 +122,25 @@ class sortableListing { private function setDisplayData($data) { if (!is_array($data)) { - die ("sortableList needs an array as data!"); + trigger_error ("sortableList needs an array as data!"); } // Transfer information $this->displayData= array(); + $this->modes= array(); + $this->mapping= array(); foreach ($data as $key => $value) { $this->displayData[]= $value['data']; + if (isset($value['mode'])) { + $this->modes[]= $value['mode']; + } } $this->keys= array_keys($data); // Create initial mapping - $this->mapping= range(0, abs(count($this->keys)-1)); + if(count($this->keys)){ + $this->mapping= range(0, abs(count($this->keys)-1)); + } $this->current_mapping= $this->mapping; // Find the number of coluns @@ -120,7 +154,9 @@ class sortableListing { // Preset sort orders to 'down' for ($column= 0; $column<$this->columns; $column++) { - $this->sortDirection[]= true; + if(!isset($this->sortDirection[$column])){ + $this->sortDirection[$column]= true; + } } } @@ -182,30 +218,34 @@ class sortableListing { public function render() { $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= ""; } @@ -239,14 +279,14 @@ class sortableListing { $reorderable= $this->reorderable?"":" style='cursor:default'"; if (strpos($this->acl, 'r') !== false) { foreach ($this->mapping as $nr => $row) { - $editable= $this->editable?" onclick='$(\"edit_".$this->id."_$nr\").click()'":""; + $editable= $this->editable?" onClick='$(\"edit_".$this->id."_$nr\").click()'":""; $id= ""; if (isset($this->modes[$row])) { switch ($this->modes[$row]) { case LIST_DISABLED: $id= " sortableListItemDisabled"; - $editable= false; + $editable= ""; break; case LIST_MARKED: $id= " sortableListItemMarked"; @@ -280,7 +320,7 @@ class sortableListing { $result.= "
---|