1: <?php
2: /**
3: * Sortable Base File
4: *
5: * The QSortableBase class defined here provides an interface between the generated
6: * QSortableGen class, and QCubed. This file is part of the core and will be overwritten
7: * when you update QCubed. To override, make your changes to the QSortable.class.php file instead.
8: *
9: */
10:
11: /**
12: * Impelements a JQuery UI Sortable
13: *
14: * Sortable is a group of panels that can be dragged to reorder them. You will need to put
15: * some care into the css styling of the objects so that the css allows them to be moved. It
16: * will use the top level html objects inside the panel to decide what to sort. Make sure
17: * they have ids so it can return the ids of the items in sort order.
18: *
19: * @property-read Array $ItemArray List of ControlIds in sort order.
20: *
21: * @link http://jqueryui.com/sortable/
22: * @package Controls\Base
23: */
24: class QSortableBase extends QSortableGen {
25: /** @var array */
26: protected $aryItemArray = null;
27:
28:
29: // Find out what the sort order is at the beginning so that aryItemArray is up to date
30: public function MakeJqOptions () {
31: $jqOptions = parent::MakeJqOptions();
32:
33: // TODO: Put this in the qcubed.js file, or something like it.
34: $jqOptions['create'] = new QJsClosure('
35: var ary = jQuery(this).sortable("toArray");
36: var str = ary.join(",");
37: qcubed.recordControlModification("$this->ControlId", "_ItemArray", str);
38: ');
39: return $jqOptions;
40: }
41: public function GetEndScript() {
42: $strJS = parent::GetEndScript();
43:
44: $strCtrlJs =<<<FUNC
45: ;\$j('#{$this->ControlId}').on("sortstop", function (event, ui) {
46: var ary = jQuery(this).sortable("toArray");
47: var str = ary.join(",");
48: qcubed.recordControlModification("$this->ControlId", "_ItemArray", str);
49: })
50: FUNC;
51: QApplication::ExecuteJavaScript($strCtrlJs, QJsPriority::High);
52:
53: return $strJS;
54: }
55:
56:
57: public function __set($strName, $mixValue) {
58: switch ($strName) {
59: case '_ItemArray': // Internal only. Do not use. Used by JS above to track selections.
60: try {
61: $data = QType::Cast($mixValue, QType::String);
62: $a = explode (",", $data);
63: $this->aryItemArray = $a;
64: break;
65: } catch (QInvalidCastException $objExc) {
66: $objExc->IncrementOffset();
67: throw $objExc;
68: }
69:
70: default:
71: try {
72: parent::__set($strName, $mixValue);
73: break;
74: } catch (QCallerException $objExc) {
75: $objExc->IncrementOffset();
76: throw $objExc;
77: }
78: }
79:
80: }
81:
82: public function __get($strName) {
83: switch ($strName) {
84: case 'ItemArray': return $this->aryItemArray;
85: default:
86: try {
87: return parent::__get($strName);
88: } catch (QCallerException $objExc) {
89: $objExc->IncrementOffset();
90: throw $objExc;
91: }
92: }
93: }
94: }
95: