summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 8ece5cb)
raw | patch | inline | side by side (parent: 8ece5cb)
author | cajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Tue, 19 Jan 2010 13:25:00 +0000 (13:25 +0000) | ||
committer | cajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Tue, 19 Jan 2010 13:25:00 +0000 (13:25 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@15201 594d385d-05f5-0310-b6e9-bd551577e9d8
gosa-core/include/class_sortableListing.inc | patch | blob | history |
diff --git a/gosa-core/include/class_sortableListing.inc b/gosa-core/include/class_sortableListing.inc
index 1b2bc4c75e859644896000d19e18bb9183b21700..c81faeb5b305f6cbd7c7dcbc9fdfb06867b3c863 100644 (file)
private $active_index;
private $scrollPosition= 0;
private $sortColumn= 0;
- private $sortColumnOrder= array();
+ 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;
// Generate instance wide unique ID
$tmp= gettimeofday();
$this->id= 'l'.md5($tmp['sec']);
+
+ // Set reorderable flag
+ $this->reorderable= $reorderable;
+ if (!$reorderable) {
+ $this->sortData();
+ }
}
- 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!");
} else {
$this->columns= 1;
}
- }
-
- function setWidth($width)
- {
- $this->width= $width;
+ // Preset sort orders to 'down'
+ for ($column= 0; $column<$this->columns; $column++) {
+ $this->sortDirection[]= true;
+ }
}
- function setReorderable($flag)
+ public function setWidth($width)
{
- $this->reorderable= $flag;
+ $this->width= $width;
}
- function setInstantDelete($flag)
+ public function setInstantDelete($flag)
{
$this->instantDelete= $flag;
}
- function setEditable($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= "<div class='sortableListContainer' id='scroll_".$this->id."' style='width: ".$this->width."; height: ".$this->height."'>\n";
$result.= "<table border='0' cellpadding='0' cellspacing='0' width='100%' height='100%' style='position: relative;'".(!empty($this->cssclass)?" class='".$this->cssclass."'":"").">\n";
if ($this->header) {
$result.= " <thead>\n <tr>\n";
for ($i= 0; $i<$this->columns; $i++) {
- $result.= " <th>".(isset($this->header[$i])?$this->header[$i]:"")."</th>";
+ $link= "href='?plug=".$_GET['plug']."&PID=".$this->id."&act=SORT_$i'";
+ $sorter= "";
+ if ($i == $this->sortColumn){
+ $sorter= " <img border='0' title='".($this->sortDirection[$i]?_("Up"):_("Down"))."' src='images/lists/sort-".($this->sortDirection[$i]?"up":"down").".png' align='top'>";
+ }
+
+ if ($this->reorderable) {
+ $result.= " <th>".(isset($this->header[$i])?$this->header[$i]:"")."</th>";
+ } else {
+ $result.= " <th><a $link>".(isset($this->header[$i])?$this->header[$i]:"")."$sorter</a></th>";
+ }
}
if ($action_width) {
$result.= "<th> </th>";
if (strpos($this->acl, 'r') !== false) {
foreach ($this->mapping as $nr => $row) {
$editable= $this->editable?" onclick='$(\"edit_".$this->id."_$nr\").click()'":"";
- $result.= " <tr class='sortableListItem".($nr&1?'Odd':'')."' id='item_".$this->id."_$nr'$reorderable$editable>\n";
+ $result.= " <tr class='sortableListItem".($nr&1?'Odd':'')."' id='item_".$this->id."_$nr'$reorderable>\n";
foreach ($this->displayData[$row] as $column) {
- $result.= " <td>".htmlentities($column)."</td>\n";
+ $result.= " <td$editable>".htmlentities($column)."</td>\n";
}
if ($action_width) {
$result.= "<td>".str_replace('%ID', "edit_".$this->id."_$nr", $edit_image).
}
$result.= " </tbody>\n</table>\n</div>\n";
+ $result.= " <input type='hidden' name='PID' value='".$this->id."' id='PID'>\n";
$result.= " <input type='hidden' name='position_".$this->id."' id='position_".$this->id."'>\n";
$result.= " <input type='hidden' name='reorder_".$this->id."' id='reorder_".$this->id."'>\n";
}
- function update()
+ public function update()
{
+ // Do not do anything if this is not our PID, or there's even no PID available...
+ if(!isset($_REQUEST['PID']) || $_REQUEST['PID'] != $this->id) {
+ return;
+ }
+
+ // Filter GET with "act" attributes
+ if (!$this->reorderable && isset($_GET['act'])) {
+ $key= validate($_GET['act']);
+ if (preg_match('/^SORT_([0-9]+)$/', $key, $match)) {
+ // Switch to new column or invert search order?
+ $column= $match[1];
+ if ($this->sortColumn != $column) {
+ $this->sortColumn= $column;
+ } else {
+ $this->sortDirection[$column]= !$this->sortDirection[$column];
+ }
+
+ // Update mapping according to sort parameters
+ $this->sortData();
+ }
+ }
+
// Do not do anything if we're not posted - or have no permission
if (strpos($this->acl, 'w') !== false && isset($_POST['reorder_'.$this->id])){
}
- function getAction()
+ public function getAction()
{
// Do not do anything if we're not posted
if(!isset($_POST['reorder_'.$this->id])) {
}
- function deleteEntry($id)
+ private function deleteEntry($id)
{
// Remove mapping
$index= array_search($id, $this->mapping);
}
- function getMaintainedData()
+ public function getMaintainedData()
{
$tmp= array();
}
- function isModified()
+ public function isModified()
{
return $this->modified;
}
- function setAcl($acl)
+ public function setAcl($acl)
{
$this->acl= $acl;
}
+
+ public function sortData()
+ {
+ // Extract data
+ $tmp= array();
+ foreach($this->displayData as $item) {
+ if (isset($item[$this->sortColumn])){
+ $tmp[]= $item[$this->sortColumn];
+ } else {
+ $tmp[]= "";
+ }
+ }
+
+ // Sort entries
+ if ($this->sortDirection[$this->sortColumn]) {
+ asort($tmp);
+ } else {
+ arsort($tmp);
+ }
+
+ // Adapt mapping accordingly
+ $this->mapping= array();
+ foreach ($tmp as $key => $value) {
+ $this->mapping[]= $key;
+ }
+ }
+
}