1: <?php
2: /**
3: * Selectable Base File
4: *
5: * The QSelectableBase class defined here provides an interface between the generated
6: * QSelectableGen 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 QSelectable.class.php file instead.
8: *
9: */
10:
11: /**
12: * Impelments a JQuery UI Selectable box
13: *
14: * A selectable box makes the items inside of it selectable. This is a QPanel, so
15: * whatever top level items drown inside of it will become selectable. Make sure
16: * the items have ids.
17: *
18: * @property Array $SelectedItems ControlIds of the items selected
19: *
20: * @link http://jqueryui.com/selectable/
21: * @package Controls\Base
22: */
23: class QSelectableBase extends QSelectableGen
24: {
25: /** @var array */
26: protected $arySelectedItems = null;
27:
28:
29: // These functions are used to keep track of the selected items
30:
31: public function GetEndScript() {
32: $strJS = parent::GetEndScript();
33: QApplication::ExecuteJsFunction('qcubed.selectable', $this->GetJqControlId(), QJsPriority::High);
34: return $strJS;
35: }
36:
37:
38: public function __set($strName, $mixValue) {
39: switch ($strName) {
40: case '_SelectedItems': // Internal only. Do not use. Used by JS above to keep track of selections.
41: try {
42: $strItems = QType::Cast($mixValue, QType::String);
43: $this->arySelectedItems = explode (",", $strItems);
44: } catch (QInvalidCastException $objExc) {
45: $objExc->IncrementOffset();
46: throw $objExc;
47: }
48: break;
49:
50: case 'SelectedItems':
51: // Set the selected items to an array of object ids
52: try {
53: $aValues = QType::Cast($mixValue, QType::ArrayType);
54: $aJqIds = array();
55: foreach ($aValues as $val) {
56: $aJqIds[] = '"#' . $val . '"';
57: }
58: $strJqItems = join (',', $aJqIds);
59:
60: $strJS =<<<FUNC
61: var item = jQuery("#$this->ControlId");
62:
63: jQuery(".ui-selectee", item).each(function() {
64: jQuery(this).removeClass('ui-selected');
65: });
66:
67: jQuery($strJqItems).each(function() {
68: jQuery(this).addClass('ui-selected');
69: });
70: FUNC;
71: $this->arySelectedItems = $aValues;
72: QApplication::ExecuteJavascript ($strJS);
73: } catch (QInvalidCastException $objExc) {
74: $objExc->IncrementOffset();
75: throw $objExc;
76: }
77: break;
78:
79: default:
80: try {
81: parent::__set($strName, $mixValue);
82: break;
83: } catch (QCallerException $objExc) {
84: $objExc->IncrementOffset();
85: throw $objExc;
86: }
87: }
88:
89: }
90:
91: public function __get($strName) {
92: switch ($strName) {
93: case 'SelectedItems': return $this->arySelectedItems;
94:
95: default:
96: try {
97: return parent::__get($strName);
98: } catch (QCallerException $objExc) {
99: $objExc->IncrementOffset();
100: throw $objExc;
101: }
102: }
103: }
104:
105: }