1 <?php
2 3 4 5 6 7 8
9
10 defined('JPATH_PLATFORM') or die;
11
12 13 14 15 16
17 abstract class JHtmlGrid
18 {
19 20 21 22 23 24 25 26 27 28 29 30
31 public static function boolean($i, $value, $taskOn = null, $taskOff = null)
32 {
33
34 static::behavior();
35 JHtml::_('bootstrap.tooltip');
36
37
38 $title = $value ? JText::_('JYES') : JText::_('JNO');
39 $title = JHtml::_('tooltipText', $title, JText::_('JGLOBAL_CLICK_TO_TOGGLE_STATE'), 0);
40
41
42 $bool = $value ? 'true' : 'false';
43 $task = $value ? $taskOff : $taskOn;
44 $toggle = (!$task) ? false : true;
45
46 if ($toggle)
47 {
48 return '<a class="grid_' . $bool . ' hasTooltip" title="' . $title . '" rel="{id:\'cb' . $i . '\', task:\'' . $task
49 . '\'}" href="#toggle"></a>';
50 }
51 else
52 {
53 return '<a class="grid_' . $bool . '"></a>';
54 }
55 }
56
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
73 public static function sort($title, $order, $direction = 'asc', $selected = '', $task = null, $new_direction = 'asc', $tip = '', $form = null)
74 {
75 JHtml::_('behavior.core');
76 JHtml::_('bootstrap.popover');
77
78 $direction = strtolower($direction);
79 $icon = array('arrow-up-3', 'arrow-down-3');
80 $index = (int) ($direction === 'desc');
81
82 if ($order != $selected)
83 {
84 $direction = $new_direction;
85 }
86 else
87 {
88 $direction = $direction === 'desc' ? 'asc' : 'desc';
89 }
90
91 if ($form)
92 {
93 $form = ', document.getElementById(\'' . $form . '\')';
94 }
95
96 $html = '<a href="#" onclick="Joomla.tableOrdering(\'' . $order . '\',\'' . $direction . '\',\'' . $task . '\'' . $form . ');return false;"'
97 . ' class="hasPopover" title="' . htmlspecialchars(JText::_($tip ?: $title)) . '"'
98 . ' data-content="' . htmlspecialchars(JText::_('JGLOBAL_CLICK_TO_SORT_THIS_COLUMN')) . '" data-placement="top">';
99
100 if (isset($title['0']) && $title['0'] === '<')
101 {
102 $html .= $title;
103 }
104 else
105 {
106 $html .= JText::_($title);
107 }
108
109 if ($order == $selected)
110 {
111 $html .= '<span class="icon-' . $icon[$index] . '"></span>';
112 }
113
114 $html .= '</a>';
115
116 return $html;
117 }
118
119 120 121 122 123 124 125 126 127 128 129
130 public static function checkall($name = 'checkall-toggle', $tip = 'JGLOBAL_CHECK_ALL', $action = 'Joomla.checkAll(this)')
131 {
132 JHtml::_('behavior.core');
133 JHtml::_('bootstrap.tooltip');
134
135 return '<input type="checkbox" name="' . $name . '" value="" class="hasTooltip" title="' . JHtml::_('tooltipText', $tip)
136 . '" onclick="' . $action . '" />';
137 }
138
139 140 141 142 143 144 145 146 147 148 149 150 151
152 public static function id($rowNum, $recId, $checkedOut = false, $name = 'cid', $stub = 'cb')
153 {
154 return $checkedOut ? '' : '<input type="checkbox" id="' . $stub . $rowNum . '" name="' . $name . '[]" value="' . $recId
155 . '" onclick="Joomla.isChecked(this.checked);" />';
156 }
157
158 159 160 161 162 163 164 165 166 167 168
169 public static function checkedOut(&$row, $i, $identifier = 'id')
170 {
171 $user = JFactory::getUser();
172 $userid = $user->get('id');
173
174 if ($row instanceof JTable)
175 {
176 $result = $row->isCheckedOut($userid);
177 }
178 else
179 {
180 $result = false;
181 }
182
183 if ($result)
184 {
185 return static::_checkedOut($row);
186 }
187 else
188 {
189 if ($identifier === 'id')
190 {
191 return JHtml::_('grid.id', $i, $row->$identifier);
192 }
193 else
194 {
195 return JHtml::_('grid.id', $i, $row->$identifier, $result, $identifier);
196 }
197 }
198 }
199
200 201 202 203 204 205 206 207 208 209 210 211 212
213 public static function published($value, $i, $img1 = 'tick.png', $img0 = 'publish_x.png', $prefix = '')
214 {
215 if (is_object($value))
216 {
217 $value = $value->published;
218 }
219
220 $img = $value ? $img1 : $img0;
221 $task = $value ? 'unpublish' : 'publish';
222 $alt = $value ? JText::_('JPUBLISHED') : JText::_('JUNPUBLISHED');
223 $action = $value ? JText::_('JLIB_HTML_UNPUBLISH_ITEM') : JText::_('JLIB_HTML_PUBLISH_ITEM');
224
225 return '<a href="#" onclick="return listItemTask(\'cb' . $i . '\',\'' . $prefix . $task . '\')" title="' . $action . '">'
226 . JHtml::_('image', 'admin/' . $img, $alt, null, true) . '</a>';
227 }
228
229 230 231 232 233 234 235 236 237 238 239 240 241 242
243 public static function state($filter_state = '*', $published = 'JPUBLISHED', $unpublished = 'JUNPUBLISHED', $archived = null, $trashed = null)
244 {
245 $state = array('' => '- ' . JText::_('JLIB_HTML_SELECT_STATE') . ' -', 'P' => JText::_($published), 'U' => JText::_($unpublished));
246
247 if ($archived)
248 {
249 $state['A'] = JText::_($archived);
250 }
251
252 if ($trashed)
253 {
254 $state['T'] = JText::_($trashed);
255 }
256
257 return JHtml::_(
258 'select.genericlist',
259 $state,
260 'filter_state',
261 array(
262 'list.attr' => 'class="inputbox" size="1" onchange="Joomla.submitform();"',
263 'list.select' => $filter_state,
264 'option.key' => null,
265 )
266 );
267 }
268
269 270 271 272 273 274 275 276 277 278 279
280 public static function order($rows, $image = 'filesave.png', $task = 'saveorder')
281 {
282 return '<a href="javascript:saveorder('
283 . (count($rows) - 1) . ', \'' . $task . '\')" rel="tooltip" class="saveorder btn btn-micro pull-right" title="'
284 . JText::_('JLIB_HTML_SAVE_ORDER') . '"><span class="icon-menu-2"></span></a>';
285 }
286
287 288 289 290 291 292 293 294 295 296
297 protected static function _checkedOut(&$row, $overlib = true)
298 {
299 $hover = '';
300
301 if ($overlib)
302 {
303 JHtml::_('bootstrap.tooltip');
304
305 $date = JHtml::_('date', $row->checked_out_time, JText::_('DATE_FORMAT_LC1'));
306 $time = JHtml::_('date', $row->checked_out_time, 'H:i');
307
308 $hover = '<span class="editlinktip hasTooltip" title="' . JHtml::_('tooltipText', 'JLIB_HTML_CHECKED_OUT', $row->editor)
309 . '<br />' . $date . '<br />' . $time . '">';
310 }
311
312 return $hover . JHtml::_('image', 'admin/checked_out.png', null, null, true) . '</span>';
313 }
314
315 316 317 318 319 320 321
322 public static function behavior()
323 {
324 static $loaded;
325
326 if (!$loaded)
327 {
328
329 JHtml::_('jquery.framework');
330
331
332 $js = '
333 jQuery(function($){
334 $actions = $(\'a.move_up, a.move_down, a.grid_true, a.grid_false, a.grid_trash\');
335 $actions.each(function(){
336 $(this).on(\'click\', function(){
337 args = JSON.decode(this.rel);
338 listItemTask(args.id, args.task);
339 });
340 });
341 $(\'input.check-all-toggle\').each(function(){
342 $(this).on(\'click\', function(){
343 if (this.checked) {
344 $(this).closest(\'form\').find(\'input[type="checkbox"]\').each(function(){
345 this.checked = true;
346 })
347 }
348 else {
349 $(this).closest(\'form\').find(\'input[type="checkbox"]\').each(function(){
350 this.checked = false;
351 })
352 }
353 });
354 });
355 });';
356
357
358 $document = JFactory::getDocument();
359 $document->addScriptDeclaration($js);
360
361 $loaded = true;
362 }
363 }
364 }
365