X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=gosa-core%2Finclude%2Fclass_sortableListing.inc;h=06d817806dd777b8e03ed62e42bf0d15d99deec1;hb=0ed9b1739e716b327ca773724ebcfec83eb2904b;hp=0e346f8ade48a520d03a9116d2218963bb11839b;hpb=53553834328f43ffd06c805c940b18738349ab94;p=gosa.git diff --git a/gosa-core/include/class_sortableListing.inc b/gosa-core/include/class_sortableListing.inc index 0e346f8ad..06d817806 100644 --- a/gosa-core/include/class_sortableListing.inc +++ b/gosa-core/include/class_sortableListing.inc @@ -3,7 +3,7 @@ * This code is part of GOsa (http://www.gosa-project.org) * Copyright (C) 2003-2008 GONICUS GmbH * - * ID: $$Id: class_listing.inc 15087 2010-01-06 13:45:49Z hickert $$ + * ID: $$Id$$ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -30,58 +30,76 @@ 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; + private $scrollPosition= 0; + private $sortColumn= 0; + private $sortDirection= array(); private $acl= ""; private $modified= false; - function sortableListing($data= array(), $displayData= null) + public function sortableListing($data= array(), $displayData= null, $reorderable= false) { global $config; + // Save data to display + $this->setListData($data, $displayData); + + // Generate instance wide unique ID + $tmp= gettimeofday(); + $this->id= 'l'.md5($tmp['sec']); + + // Set reorderable flag + $this->reorderable= $reorderable; + if (!$reorderable) { + $this->sortData(); + } + } + + + public function setListData($data, $displayData= null) + { // Save data to display $this->setData($data); if (!$displayData) { $displayData= array(); - foreach ($data as $value) { - $displayData[]= array($value); + foreach ($data as $key => $value) { + $displayData[$key]= array($value); } - } else { - $this->setDisplayData($displayData); } - // Generate instance wide unique ID - $tmp= gettimeofday(); - $this->id= 'l'.md5($tmp['sec']); + $this->setDisplayData($displayData); } - function setData($data) + private function setData($data) { $this->data= $data; } - function setDisplayData($data) + private function setDisplayData($data) { if (!is_array($data)) { die ("sortableList needs an array as data!"); } // 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 @@ -92,66 +110,77 @@ class sortableListing { } else { $this->columns= 1; } + + // Preset sort orders to 'down' + for ($column= 0; $column<$this->columns; $column++) { + $this->sortDirection[]= true; + } } - function setWidth($width) + public function setWidth($width) { $this->width= $width; } - function setInstantDelete($flag) + public function setInstantDelete($flag) { $this->instantDelete= $flag; } - function setEditable($flag) + public function setColorAlternate($flag) + { + $this->colorAlternate= $flag; + } + + + public function setEditable($flag) { $this->editable= $flag; } - function setDeleteable($flag) + public function setDeleteable($flag) { $this->deleteable= $flag; } - function setHeight($height) + public function setHeight($height) { $this->height= $height; } - function setCssClass($css) + public function setCssClass($css) { $this->cssclass= $css; } - function setHeader($header) + public function setHeader($header) { $this->header= $header; } - function setColspecs($specs) + public function setColspecs($specs) { $this->colspecs= $specs; } - function render() + public function render() { - $result= "
".(isset($this->header[$i])?$this->header[$i]:"")." | "; + $link= "href='?plug=".$_GET['plug']."&PID=".$this->id."&act=SORT_$i'"; + $sorter= ""; + if ($i == $this->sortColumn){ + $sorter= "".(isset($this->header[$i])?$this->header[$i]:"")." | "; + } else { + $result.= "".(isset($this->header[$i])?$this->header[$i]:"")."$sorter | "; + } + $first= ""; } if ($action_width) { $result.= ""; @@ -188,11 +229,15 @@ class sortableListing { // Render table body if we've read permission $result.= " |
---|---|---|---|
".htmlentities($column)." | \n"; + $result.= "".htmlentities($column)." | \n"; + $first= ""; } if ($action_width) { $result.= "".str_replace('%ID', "edit_".$this->id."_$nr", $edit_image). @@ -200,27 +245,34 @@ class sortableListing { } $result.= " | |
"; + $num= $action_width?$this->columns:$this->columns-1; + for ($i= 0; $i<$num; $i++) { + $result.= " | "; + } + $result.= " |