PluginProbe
CSS & JavaScript Toolbox / 12.0.4
CSS & JavaScript Toolbox v12.0.4
trunk 0.3 0.8 10 10.1 11 11.2 11.3 11.4 11.5 11.6 11.7 11.8 11.9 11.9.1 12 12.0 12.0.1 12.0.3 12.0.4 12.0.5 12.0.6 12.0.7 6.0 6.0.11 All 60 releases
css-javascript-toolbox / framework / html / list.php

list.php in CSS & JavaScript Toolbox 12.0.4, at framework/html/list.php

167 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 *
4 */
5
6 // Import dependencies.
7 cssJSToolbox::import('framework:html:field.inc.php');
8
9 /**
10 *
11 */
12 class CJTListField extends CJTHTMLField {
13
14 /**
15 * put your comment there...
16 *
17 * @var mixed
18 */
19 protected static $instances = array();
20
21 /**
22 * put your comment there...
23 *
24 * @var mixed
25 */
26 protected $items;
27
28 /**
29 * put your comment there...
30 *
31 * @var mixed
32 */
33 protected $mandatory;
34
35 /**
36 * put your comment there...
37 *
38 * @var mixed
39 */
40 protected $moreIntoTag;
41
42 /**
43 * put your comment there...
44 *
45 * @var mixed
46 */
47 protected $optional;
48
49 /**
50 * put your comment there...
51 *
52 * @var mixed
53 */
54 protected $options = array();
55
56 /**
57 * put your comment there...
58 *
59 * @var mixed
60 */
61 protected $propText = 'text';
62
63 /**
64 * put your comment there...
65 *
66 * @var mixed
67 */
68 protected $propValue = null;
69
70 /**
71 * put your comment there...
72 *
73 */
74 public function __construct($form, $name, $value, $id = null, $classesList = '', $propText = null, $propValue = null, $moreIntoTag = null, $optional = null) {
75 parent::__construct($form, $name, $value, $id, $classesList);
76 // Initialize local vars.
77 $this->propText = $propText ? $propText : 'text';
78 $this->propValue = $propValue;
79 $this->moreIntoTag = $moreIntoTag;
80 $this->optional = $optional;
81 }
82
83 /**
84 * put your comment there...
85 *
86 */
87 public function getInput($options = null) {
88 $this->options = ($options !== null) ? $options : array();
89 // Prepare items.
90 $this->prepareItems();
91 if ($this->optional) {
92 $this->items = array('' => (object) array(
93 $this->propText => htmlentities($this->optional),
94 '__params__' => (object) array('className' => 'optional')))+ $this->items;
95 }
96 // Build HTML select.
97 $listName = (isset($this->options['standard']) && ($this->options['standard'] == true)) ? "name='{$this->name}'" : '';
98 $list = "<select id='{$this->id}' {$listName} class='{$this->classesList}' {$this->moreIntoTag}>";
99 foreach ($this->items as $key => $item) {
100 // Standrize the use of object.
101 $item = (object) $item;
102 // Fetch display text.
103 $text = cssJSToolbox::getText($item->{$this->propText});
104 // No value prop defined then use item KEY.
105 $value = ($this->propValue == null) ? $key : $item->{$this->propValue};
106 $selected = ($value == $this->value) ? ' selected="selected"' : '';
107 if (isset($item->__params__->className)) {
108 $class = "class='{$item->__params__->className}'";
109 }
110 else {
111 $class = '';
112 }
113 $list .= "<option {$class} value='{$value}'{$selected}>{$text}</option>" ;
114 }
115 $list .= '</select>';
116 // If this is the first instance to be outputed for the current form output the control field.
117 $fieldKey = "{$this->form}-{$this->name}";
118 if ((!isset($this->options['standard'])) && (!in_array($fieldKey, self::$instances))) {
119 // Output control fields.
120 $list .= "<input type='hidden' name='{$this->name}' value='{$this->value}' />";
121 // Mark form as instantiated!
122 self::$instances[] = $fieldKey;
123 }
124 return $list;
125 }
126
127 /**
128 * put your comment there...
129 *
130 * @param mixed $type
131 * @param mixed $form
132 * @param mixed $name
133 * @param mixed $value
134 * @param mixed $id
135 * @param mixed $classesList
136 * @param mixed $propText
137 * @param mixed $propValue
138 * @param mixed $moreIntoTag
139 */
140 public static function getInstance($type, $form, $name, $value, $id = null, $classesList = '', $propText = 'text', $propValue = null, $moreIntoTag = null, $optional = null) {
141 /* * @ todo Code to importing file and instantiating class should be in CJTHTMLField class not here!! */
142 // Import field file.
143 cssJSToolbox::import("models:fields:{$type}.php");
144 // Create an instance.
145 $type = str_replace(' ', '', ucwords(str_replace(array('-', '_'), ' ', $type)));
146 $className = "CJT{$type}Field";
147 return new $className($form, $name, $value, $id, $classesList, $propText, $propValue, $moreIntoTag, $optional);
148 }
149
150 /**
151 * put your comment there...
152 *
153 */
154 public function &getItems() {
155 return $this->items;
156 }
157
158 /**
159 * put your comment there...
160 *
161 */
162 protected function prepareItems() {
163 $this->items = array();
164 }
165
166 } // End class.
167