**/ class twIf_Generic_Listing extends twIf_Generic_Listbox { // Captions for remove-actions const REMOVE_CAPTION = 'Remove'; const REMOVE_SUCCESS = 'Record was removed successfully'; const REMOVE_DELAYED = 'Record was queued for removal'; const REMOVE_FAILED = 'Record could not be removed'; const SUBMIT_CAPTION = 'Change selection'; // Allow to remove Items from listing by calling remove() const ALLOW_DELETE = true; // Allow the user to change the sorting const ALLOW_SORT = true; // Show enable/disable-buttons by using isEnabled() const ENABLE_TOGGLE = false; // Show checkboxes for every entry const ENABLE_SELECT = false; const SELECT_FIELD = null; private $removed = null; private $removeResult = null; private $Create = false; // {{{ __construct /** * Create a new VPN Address Interface * * @param array $URL * * @access friendly * @return void */ function __construct ($URL, $Base = '', $urlMode = self::MODE_URL) { $this->setBase ($Base); $this->urlMode = $urlMode; } // }}} // {{{ getSortParams /** * Retrive parameters for sorting * * @access protected * @return array */ protected function getSortParams () { if (self::findConstant ('ALLOW_SORT', true)) { $Params = self::getSortParamsEx (); return array ($Params ['Field'], ($Params ['Order'] == 'D' ? 'DESC' : 'ASC')); } return parent::getSortParams (); } // }}} // {{{ prepare /** * Prepare this interface for output * * @access public * @return bool **/ public function prepare () { // Load our classname $Class = $this->getClass (); // Remove an object if requested if ($this->getAllowDelete () && isset ($_REQUEST ['Remove']) && ($_REQUEST ['Remove'] != '') && $Class && is_object ($RO = call_user_func (array ($Class, 'getInstance'), $_REQUEST ['Remove'], twIf_Object::FLAG_ID_MD5))) { $this->removed = true; $this->removeResult = $RO->remove (); } // Handle selections if ($this->getEnableSelect () && (($c = $this->countItems ()) > 0)) { if (count ($Items = twIf_Widget_Table::filterSelected ($this->listItems ($this->getPageCounter ($c)))) > 0) $this->selectItems ($Items); elseif (isset ($_REQUEST [$this->getPageUUID () . '_sel']) && ($_REQUEST [$this->getPageUUID () . '_sel'] == 1)) $this->selectItems (array ()); } return parent::prepare (); } // }}} // {{{ getSortParamsEx /** * Retrive parameters for sorting * * @access protected * @return array */ protected function getSortParamsEx () { if (!self::findConstant ('ALLOW_SORT', true)) return array ('Enable' => false); return twIf_Widget_Table::getSortParams ($this->getFields (), true, self::findConstant ('SORT_FIELD', null), self::findConstant ('SORT_ORDER', null), $this->getPageUUID ()); } // }}} // {{{ getDefintion /** * Retrive Page-Definition from this object * * @access public * @return array */ public function getDefinition () { // Load definition from our top-most parent $Base = parent::getDefinition (); // Post-process the definition $out = array (); $lastID = 0; foreach ($Base as $ID=>$Item) { if ($Item ['Type'] == 'Listbox') { // Check if an item was removed and give feedback if ($this->removed == true) { if (isset ($out [$lastID]) && ($out [$lastID]['Type'] == 'Box')) $lastID--; if ($Failed = ($this->removeResult === false)) $Text = $this->getRemoveFailed (); elseif ($this->removeResult === true) $Text = $this->getRemoveSuccess (); else $Text = $this->getRemoveDelayed (); // Insert new item $tmp = array_splice ($out, $lastID); $out [] = array ( 'Type' => 'Feedback', 'Success' => !$Failed, 'Message' => $Text, ); $out = array_merge ($out, $tmp); } $Item ['Type'] = 'Listing'; $Item ['Options'] = array ($this, 'getOptions'); $Item ['Highlight'] = array ($this, 'getHighlight'); $Item ['EnableToggle'] = $this->getEnableToggle (); $Item ['SortParams'] = array ($this, 'getSortParamsEx'); $Item ['EnableSelect'] = $this->getEnableSelect (); $Item ['Select'] = $this->getSelectField (); $Item ['msgSubmit'] = $this->getSubmitCaption (); $Item ['Group'] = $this->getGroupField (); unset ($Item ['Link']); } $lastID = count ($out); $out [] = $Item; } return $out; } // }}} // {{{ getOptions /** * Get Options for Listing * * @access protected * @return array */ protected function getOptions () { if (!$this->getAllowDelete ()) return array (); return array ( $this->getRemoveCaption () => array ('Link' => $this->insertURLParameter ('Remove', '%{md5::getID()}', $this->getBase (), true), 'Confirm' => 'Do you really want to remove this record?'), ); } // }}} // {{{ getEnableToggle /** * Check wheter to enable toggle in listing * * @access protected * @return bool */ protected function getEnableToggle () { return (self::findConstant ('ENABLE_TOGGLE', 0) == 1); } // }}} // {{{ getEnableSelect /** * Check wheter to add select-boxes in listing * * @access protected * @return bool */ protected function getEnableSelect () { return (self::findConstant ('ENABLE_SELECT', 0) == 1); } // }}} // {{{ getSelectField /** * **/ protected function getSelectField () { return self::findConstant ('SELECT_FIELD', null); } // }}} // {{{ getGroupField /** * Group columns by this field * * @access protected * @return string **/ protected function getGroupField () { return self::findConstant ('GROUP_FIELD', null); } // }}} // {{{ selectItems /** * Callback whenever a set of items was selected * * @param array $Items * * @access protected * @return void **/ protected function selectItems ($Items) { return null; } // }}} // {{{ getSubmitCaption /** * Retrive the caption of our submit-button * * @access protected * @return string **/ protected function getSubmitCaption () { return self::findConstant ('SUBMIT_CAPTION', 'Change selection'); } // }}} // {{{ getAllowDelete /** * Check wheter to allow removal of items * * @access protected * @return bool **/ protected function getAllowDelete () { return self::findConstant ('ALLOW_DELETE', true); } // }}} // {{{ getRemoveCaption /** * Retrive the caption for the remove-option * * @access protected * @return string **/ protected function getRemoveCaption () { return self::findConstant ('REMOVE_CAPTION', 'Remove'); } // }}} // {{{ getRemoveSuccess /** * Retrive message when record was removed * * @access protected * @return string **/ protected function getRemoveSuccess () { return self::findConstant ('REMOVE_SUCCESS', 'Record was removed successfully'); } // }}} // {{{ getRemoveDelayed /** * Retrive message when removal of a record was delayed * * @access protected * @return string **/ protected function getRemoveDelayed () { return self::findConstant ('REMOVE_DELAYED', 'Record was queued for removal'); } // }}} // {{{ getRemoveFailed /** * Retrive message when a record could not be removed * * @access protected * @return string **/ protected function getRemoveFailed () { return self::findConstant ('REMOVE_FAILED', 'Record could not be removed'); } // }}} } ?>