summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0254456)
raw | patch | inline | side by side (parent: 0254456)
author | cajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Thu, 21 Jan 2010 14:44:24 +0000 (14:44 +0000) | ||
committer | cajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Thu, 21 Jan 2010 14:44:24 +0000 (14:44 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@15236 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 f4ad8d6d3d93afa9ca3cac99af75f6c209a7fccd..06d817806dd777b8e03ed62e42bf0d15d99deec1 100644 (file)
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;
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();
}
+ 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;
}
// 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
}
+ public function setColorAlternate($flag)
+ {
+ $this->colorAlternate= $flag;
+ }
+
+
public function setEditable($flag)
{
$this->editable= $flag;
// Do we need a header?
if ($this->header) {
$result.= " <thead>\n <tr>\n";
+ $first= " style='border:0'";
for ($i= 0; $i<$this->columns; $i++) {
$link= "href='?plug=".$_GET['plug']."&PID=".$this->id."&act=SORT_$i'";
$sorter= "";
}
if ($this->reorderable) {
- $result.= " <th>".(isset($this->header[$i])?$this->header[$i]:"")."</th>";
+ $result.= " <th$first>".(isset($this->header[$i])?$this->header[$i]:"")."</th>";
} else {
- $result.= " <th><a $link>".(isset($this->header[$i])?$this->header[$i]:"")."$sorter</a></th>";
+ $result.= " <th$first><a $link>".(isset($this->header[$i])?$this->header[$i]:"")."$sorter</a></th>";
}
+ $first= "";
}
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>\n";
+ $result.= " <tr class='sortableListItem".((($nr&1)||!$this->colorAlternate)?'':'Odd')."' id='item_".$this->id."_$nr'$reorderable>\n";
$first= " style='border:0'";
foreach ($this->displayData[$row] as $column) {
$result.= " <td$editable$first>".htmlentities($column)."</td>\n";
$tmp= array();
foreach ($this->mapping as $src => $dst) {
- $tmp[$src]= $this->data[$dst];
+ $tmp[$this->keys[$dst]]= $this->data[$dst];
}
return $tmp;
}
- 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
}
// 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;
+ }
+
}