From 987e75b4a0c073343cc7b709e153a81c7f1006a2 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Sun, 10 Feb 2013 16:01:41 +0000 Subject: [PATCH] sortable lists --- lam/lib/html.inc | 62 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/lam/lib/html.inc b/lam/lib/html.inc index e5f182cc..4f773b87 100644 --- a/lam/lib/html.inc +++ b/lam/lib/html.inc @@ -2742,4 +2742,66 @@ class htmlEqualWidth extends htmlElement { } +/** + * Creates a list of elements that can be sorted by the user via drag'n'drop. + * + * @package metaHTML + */ +class htmlSortableList extends htmlElement { + + /** list of elements */ + private $elements = array(); + /** HTML ID */ + private $id = ''; + /** element width */ + private $elementWidth = ''; + + /** + * Constructor. + * + * @param array $elements list of element IDs (HTML special chars must be escaped already) + * @param String HTML ID + * @param String $elementWidth width of elements (default 250px) + */ + function __construct($elements, $id, $elementWidth='250px') { + $this->elements = $elements; + $this->id = htmlspecialchars($id); + $this->elementWidth = $elementWidth; + } + + /** + * Prints the HTML code for this element. + * + * @param string $module Name of account module + * @param array $input List of meta-HTML elements + * @param array $values List of values which override the defaults in $input (name => value) + * @param boolean $restricted If true then no buttons will be displayed + * @param integer $tabindex Start value of tabulator index for input fields + * @param string $scope Account type + * @return array List of input field names and their type (name => type) + */ + function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) { + if (sizeof($this->elements) == 0) { + return array(); + } + $return = array(); + echo ''; + $scriptContent = ' + jQuery(function() { + $("#' . $this->id . '").sortable(); + $("#' . $this->id . '").disableSelection(); + });'; + $script = new htmlJavaScript($scriptContent); + $script->generateHTML($module, $input, $values, $restricted, $tabindex, $scope); + return $return; + } + +} + ?>