1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @package Redcore |
4
|
|
|
* @subpackage Html |
5
|
|
|
* |
6
|
|
|
* @copyright Copyright (C) 2008 - 2021 redWEB.dk. All rights reserved. |
7
|
|
|
* @license GNU General Public License version 2 or later, see LICENSE. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
defined('JPATH_REDCORE') or die; |
11
|
|
|
|
12
|
|
|
use Joomla\Utilities\ArrayHelper; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Utility class for creating HTML Grids |
16
|
|
|
* |
17
|
|
|
* @package Redcore |
18
|
|
|
* @subpackage Html |
19
|
|
|
* @since 1.0 |
20
|
|
|
*/ |
21
|
|
|
abstract class JHtmlRgrid |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* Extension name to use in the asset calls |
25
|
|
|
* Basically the media/com_xxxxx folder to use |
26
|
|
|
*/ |
27
|
|
|
const EXTENSION = 'redcore'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Load the entire bootstrap framework |
31
|
|
|
* |
32
|
|
|
* @param mixed $debug Is debugging mode on? [optional] |
33
|
|
|
* |
34
|
|
|
* @return void |
35
|
|
|
*/ |
36
|
|
|
public static function main($debug = null) |
|
|
|
|
37
|
|
|
{ |
38
|
|
|
JHtml::_('rjquery.framework'); |
39
|
|
|
|
40
|
|
|
RHelperAsset::load('redgrid.min.js', static::EXTENSION); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Method to create a checkbox for a grid row. |
45
|
|
|
* |
46
|
|
|
* @param integer $rowNum The row index |
47
|
|
|
* @param integer $recId The record id |
48
|
|
|
* @param boolean $checkedOut True if item is checke out |
49
|
|
|
* @param string $name The name of the form element |
50
|
|
|
* @param string $formId The form id |
51
|
|
|
* @param string $idPrefix Custom prefix |
52
|
|
|
* |
53
|
|
|
* @return mixed String of html with a checkbox if item is not checked out, null if checked out. |
54
|
|
|
*/ |
55
|
|
|
public static function id($rowNum, $recId, $checkedOut = false, $name = 'cid', $formId = 'adminForm', $idPrefix = 'cb') |
56
|
|
|
{ |
57
|
|
|
return $checkedOut ? '' : '<input type="checkbox" id="' . $idPrefix . $rowNum . '" name="' . $name . '[]" value="' . $recId |
58
|
|
|
. '" onclick="Joomla.isChecked(this.checked, document.getElementById(\'' . $formId . '\'));" />'; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Method to create an icon for saving a new ordering in a grid |
63
|
|
|
* |
64
|
|
|
* @param array $rows The array of rows of rows |
65
|
|
|
* @param string $task The task to use, defaults to save order |
66
|
|
|
* |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
|
|
public static function order($rows, $task = 'saveorder') |
70
|
|
|
{ |
71
|
|
|
return '<a href="javascript:saveorder(' . (count($rows) - 1) . ', \'' . $task . '\')" |
72
|
|
|
rel="tooltip" class="btn btn-micro pull-right" title="' |
73
|
|
|
. JText::_('JLIB_HTML_SAVE_ORDER') . '"><i class="icon-save"></i></a>'; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Returns an action on a grid |
78
|
|
|
* |
79
|
|
|
* @param integer $i The row index |
80
|
|
|
* @param string $task The task to fire |
81
|
|
|
* @param string|array $prefix An optional task prefix or an array of options |
82
|
|
|
* @param string $text An optional text to display |
83
|
|
|
* @param string $active_title An optional active tooltip to display if $enable is true |
84
|
|
|
* @param string $inactive_title An optional inactive tooltip to display if $enable is true |
85
|
|
|
* @param boolean $tip An optional setting for tooltip |
86
|
|
|
* @param string $active_class An optional active HTML class |
87
|
|
|
* @param string $inactive_class An optional inactive HTML class |
88
|
|
|
* @param boolean $enabled An optional setting for access control on the action. |
89
|
|
|
* @param boolean $translate An optional setting for translation. |
90
|
|
|
* @param string $checkbox An optional prefix for checkboxes. |
91
|
|
|
* @param string $formId An optional form id |
92
|
|
|
* @param string $buttonClass An optional button class |
93
|
|
|
* |
94
|
|
|
* @return string The Html code |
95
|
|
|
*/ |
96
|
|
|
public static function action($i, $task, $prefix = '', $text = '', $active_title = '', $inactive_title = '', |
|
|
|
|
97
|
|
|
$tip = false, $active_class = '',$inactive_class = '', |
98
|
|
|
$enabled = true, $translate = true, $checkbox = 'cb', $formId = 'adminForm', $buttonClass = '' |
99
|
|
|
) |
100
|
|
|
{ |
101
|
|
|
if (is_array($prefix)) |
102
|
|
|
{ |
103
|
|
|
$options = $prefix; |
104
|
|
|
$active_title = array_key_exists('active_title', $options) ? $options['active_title'] : $active_title; |
105
|
|
|
$inactive_title = array_key_exists('inactive_title', $options) ? $options['inactive_title'] : $inactive_title; |
106
|
|
|
$tip = array_key_exists('tip', $options) ? $options['tip'] : $tip; |
107
|
|
|
$active_class = array_key_exists('active_class', $options) ? $options['active_class'] : $active_class; |
108
|
|
|
$inactive_class = array_key_exists('inactive_class', $options) ? $options['inactive_class'] : $inactive_class; |
109
|
|
|
$enabled = array_key_exists('enabled', $options) ? $options['enabled'] : $enabled; |
110
|
|
|
$translate = array_key_exists('translate', $options) ? $options['translate'] : $translate; |
111
|
|
|
$checkbox = array_key_exists('checkbox', $options) ? $options['checkbox'] : $checkbox; |
112
|
|
|
$formId = array_key_exists('formId', $options) ? $options['formId'] : $formId; |
113
|
|
|
$buttonClass = array_key_exists('buttonClass', $options) ? $options['buttonClass'] : $buttonClass; |
114
|
|
|
$prefix = array_key_exists('prefix', $options) ? $options['prefix'] : ''; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
if ($tip) |
118
|
|
|
{ |
119
|
|
|
JHtml::_('rbootstrap.tooltip'); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
if ($enabled) |
123
|
|
|
{ |
124
|
|
|
// Prepare the class. |
125
|
|
|
if ($active_class === 'plus') |
126
|
|
|
{ |
127
|
|
|
$buttonClass = 'published'; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
elseif ($active_class === 'minus') |
131
|
|
|
{ |
132
|
|
|
$buttonClass = 'unpublished'; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
$buttonClass .= $tip ? ' hasTooltip' : ''; |
136
|
|
|
|
137
|
|
|
$html[] = '<a class="btn btn-small btn-sm ' . $buttonClass . '"'; |
|
|
|
|
138
|
|
|
$html[] = ' href="javascript:void(0);" onclick="return listItemTaskForm(\'' . $checkbox . $i . '\',\'' |
139
|
|
|
. $prefix . $task . '\',\'' . $formId . '\')"'; |
140
|
|
|
$html[] = ' title="' . addslashes(htmlspecialchars($translate ? JText::_($active_title) : $active_title, ENT_COMPAT, 'UTF-8')) . '">'; |
141
|
|
|
$html[] = '<i class="icon-' . $active_class . '">'; |
142
|
|
|
$html[] = '</i>'; |
143
|
|
|
$html[] = '</a>'; |
144
|
|
|
} |
145
|
|
|
else |
146
|
|
|
{ |
147
|
|
|
$html[] = '<a class="btn btn-micro disabled jgrid ' . $buttonClass . ' ' . ($tip ? 'hasTooltip' : '') . '" '; |
148
|
|
|
$html[] = ' title="' . addslashes(htmlspecialchars($translate ? JText::_($inactive_title) : $inactive_title, ENT_COMPAT, 'UTF-8')) . '">'; |
149
|
|
|
|
150
|
|
|
if ($active_class == "protected") |
151
|
|
|
{ |
152
|
|
|
$html[] = '<i class="icon-lock"></i>'; |
153
|
|
|
} |
154
|
|
|
else |
155
|
|
|
{ |
156
|
|
|
$html[] = '<i class="icon-' . $inactive_class . '"></i>'; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
$html[] = '</a>'; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
return implode($html); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* Returns a state on a grid |
167
|
|
|
* |
168
|
|
|
* @param array $states array of value/state. Each state is an array of the form |
169
|
|
|
* (task, text, title,html active class, HTML inactive class) |
170
|
|
|
* or ('task'=>task, 'text'=>text, 'active_title'=>active title, |
171
|
|
|
* 'inactive_title'=>inactive title, 'tip'=>boolean, 'active_class'=>html active class, |
172
|
|
|
* 'inactive_class'=>html inactive class) |
173
|
|
|
* @param integer $value The state value. |
174
|
|
|
* @param integer $i The row index |
175
|
|
|
* @param string|array $prefix An optional task prefix or an array of options |
176
|
|
|
* @param boolean $enabled An optional setting for access control on the action. |
177
|
|
|
* @param boolean $translate An optional setting for translation. |
178
|
|
|
* @param string $checkbox An optional prefix for checkboxes. |
179
|
|
|
* @param string $formId An optional form id |
180
|
|
|
* |
181
|
|
|
* @return string The Html code |
182
|
|
|
*/ |
183
|
|
|
public static function state($states, $value, $i, $prefix = '', |
184
|
|
|
$enabled = true, $translate = true, $checkbox = 'cb', $formId = 'adminForm' |
185
|
|
|
) |
186
|
|
|
{ |
187
|
|
|
if (is_array($prefix)) |
188
|
|
|
{ |
189
|
|
|
$options = $prefix; |
190
|
|
|
$enabled = array_key_exists('enabled', $options) ? $options['enabled'] : $enabled; |
191
|
|
|
$translate = array_key_exists('translate', $options) ? $options['translate'] : $translate; |
192
|
|
|
$checkbox = array_key_exists('checkbox', $options) ? $options['checkbox'] : $checkbox; |
193
|
|
|
$prefix = array_key_exists('prefix', $options) ? $options['prefix'] : ''; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
$state = ArrayHelper::getValue($states, (int) $value, $states[0]); |
197
|
|
|
$task = array_key_exists('task', $state) ? $state['task'] : $state[0]; |
198
|
|
|
$text = array_key_exists('text', $state) ? $state['text'] : (array_key_exists(1, $state) ? $state[1] : ''); |
199
|
|
|
$active_title = array_key_exists('active_title', $state) ? $state['active_title'] : (array_key_exists(2, $state) ? $state[2] : ''); |
200
|
|
|
$inactive_title = array_key_exists('inactive_title', $state) ? $state['inactive_title'] : (array_key_exists(3, $state) ? $state[3] : ''); |
201
|
|
|
$tip = array_key_exists('tip', $state) ? $state['tip'] : (array_key_exists(4, $state) ? $state[4] : false); |
202
|
|
|
$active_class = array_key_exists('active_class', $state) ? $state['active_class'] : (array_key_exists(5, $state) ? $state[5] : ''); |
203
|
|
|
$inactive_class = array_key_exists('inactive_class', $state) ? $state['inactive_class'] : (array_key_exists(6, $state) ? $state[6] : ''); |
204
|
|
|
|
205
|
|
|
return self::action( |
206
|
|
|
$i, $task, $prefix, $text, $active_title, $inactive_title, $tip, |
207
|
|
|
$active_class, $inactive_class, $enabled, $translate, $checkbox, $formId |
208
|
|
|
); |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* Returns a published state on a grid |
213
|
|
|
* |
214
|
|
|
* @param integer $value The state value. |
215
|
|
|
* @param integer $i The row index |
216
|
|
|
* @param string|array $prefix An optional task prefix or an array of options |
217
|
|
|
* @param boolean $enabled An optional setting for access control on the action. |
218
|
|
|
* @param string $checkbox An optional prefix for checkboxes. |
219
|
|
|
* @param string $publish_up An optional start publishing date. |
220
|
|
|
* @param string $publish_down An optional finish publishing date. |
221
|
|
|
* @param string $formId An optional form id |
222
|
|
|
* |
223
|
|
|
* @return string The Html code |
224
|
|
|
*/ |
225
|
|
|
public static function published($value, $i, $prefix = '', $enabled = true, |
226
|
|
|
$checkbox = 'cb', $publish_up = null, $publish_down = null, $formId = 'adminForm' |
227
|
|
|
) |
228
|
|
|
{ |
229
|
|
|
if (is_array($prefix)) |
230
|
|
|
{ |
231
|
|
|
$options = $prefix; |
232
|
|
|
$enabled = array_key_exists('enabled', $options) ? $options['enabled'] : $enabled; |
233
|
|
|
$checkbox = array_key_exists('checkbox', $options) ? $options['checkbox'] : $checkbox; |
234
|
|
|
$prefix = array_key_exists('prefix', $options) ? $options['prefix'] : ''; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
$states = array(1 => array('unpublish', 'JPUBLISHED', 'JLIB_HTML_UNPUBLISH_ITEM', 'JPUBLISHED', false, 'ok-sign icon-green', 'ok-sign icon-green'), |
238
|
|
|
0 => array('publish', 'JUNPUBLISHED', 'JLIB_HTML_PUBLISH_ITEM', 'JUNPUBLISHED', false, 'remove icon-red', 'remove icon-red'), |
239
|
|
|
2 => array('unpublish', 'JARCHIVED', 'JLIB_HTML_UNPUBLISH_ITEM', 'JARCHIVED', false, 'hdd', 'hdd'), |
240
|
|
|
-2 => array('publish', 'JTRASHED', 'JLIB_HTML_PUBLISH_ITEM', 'JTRASHED', false, 'trash', 'trash')); |
241
|
|
|
|
242
|
|
|
// Special state for dates |
243
|
|
|
if ($publish_up || $publish_down) |
244
|
|
|
{ |
245
|
|
|
$nullDate = JFactory::getDbo()->getNullDate(); |
246
|
|
|
$nowDate = JFactory::getDate()->toUnix(); |
247
|
|
|
|
248
|
|
|
$tz = new DateTimeZone(JFactory::getUser()->getParam('timezone', JFactory::getConfig()->get('offset'))); |
249
|
|
|
|
250
|
|
|
$publish_up = ($publish_up != $nullDate) ? JFactory::getDate($publish_up, 'UTC')->setTimeZone($tz) : false; |
251
|
|
|
$publish_down = ($publish_down != $nullDate) ? JFactory::getDate($publish_down, 'UTC')->setTimeZone($tz) : false; |
252
|
|
|
|
253
|
|
|
// Create tip text, only we have publish up or down settings |
254
|
|
|
$tips = array(); |
255
|
|
|
|
256
|
|
|
if ($publish_up) |
257
|
|
|
{ |
258
|
|
|
$tips[] = JText::sprintf('JLIB_HTML_PUBLISHED_START', $publish_up->format(JDate::$format, true)); |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
if ($publish_down) |
262
|
|
|
{ |
263
|
|
|
$tips[] = JText::sprintf('JLIB_HTML_PUBLISHED_FINISHED', $publish_down->format(JDate::$format, true)); |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
$tip = empty($tips) ? false : implode('<br/>', $tips); |
267
|
|
|
|
268
|
|
|
// Add tips and special titles |
269
|
|
|
foreach ($states as $key => $state) |
270
|
|
|
{ |
271
|
|
|
// Create special titles for published items |
272
|
|
|
if ($key == 1) |
273
|
|
|
{ |
274
|
|
|
$states[$key][2] = $states[$key][3] = 'JLIB_HTML_PUBLISHED_ITEM'; |
275
|
|
|
|
276
|
|
|
if ($publish_up > $nullDate && $nowDate < $publish_up->toUnix()) |
277
|
|
|
{ |
278
|
|
|
$states[$key][2] = $states[$key][3] = 'JLIB_HTML_PUBLISHED_PENDING_ITEM'; |
279
|
|
|
$states[$key][5] = $states[$key][6] = 'pending'; |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
if ($publish_down > $nullDate && $nowDate > $publish_down->toUnix()) |
283
|
|
|
{ |
284
|
|
|
$states[$key][2] = $states[$key][3] = 'JLIB_HTML_PUBLISHED_EXPIRED_ITEM'; |
285
|
|
|
$states[$key][5] = $states[$key][6] = 'expired'; |
286
|
|
|
} |
287
|
|
|
} |
288
|
|
|
|
289
|
|
|
// Add tips to titles |
290
|
|
|
if ($tip) |
291
|
|
|
{ |
292
|
|
|
$states[$key][1] = JText::_($states[$key][1]); |
293
|
|
|
$states[$key][2] = JText::_($states[$key][2]) . '::' . $tip; |
294
|
|
|
$states[$key][3] = JText::_($states[$key][3]) . '::' . $tip; |
295
|
|
|
$states[$key][4] = true; |
296
|
|
|
} |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
return self::state($states, $value, $i, array('prefix' => $prefix, 'translate' => !$tip), $enabled, true, $checkbox, $formId); |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
return self::state($states, $value, $i, $prefix, $enabled, true, $checkbox, $formId); |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
/** |
306
|
|
|
* Returns a isDefault state on a grid |
307
|
|
|
* |
308
|
|
|
* @param integer $value The state value. |
309
|
|
|
* @param integer $i The row index |
310
|
|
|
* @param string|array $prefix An optional task prefix or an array of options |
311
|
|
|
* @param boolean $enabled An optional setting for access control on the action. |
312
|
|
|
* @param string $checkbox An optional prefix for checkboxes. |
313
|
|
|
* |
314
|
|
|
* @return string The HTML code |
315
|
|
|
*/ |
316
|
|
|
public static function isdefault($value, $i, $prefix = '', $enabled = true, $checkbox = 'cb') |
317
|
|
|
{ |
318
|
|
|
if (is_array($prefix)) |
319
|
|
|
{ |
320
|
|
|
$options = $prefix; |
321
|
|
|
$enabled = array_key_exists('enabled', $options) ? $options['enabled'] : $enabled; |
322
|
|
|
$checkbox = array_key_exists('checkbox', $options) ? $options['checkbox'] : $checkbox; |
323
|
|
|
$prefix = array_key_exists('prefix', $options) ? $options['prefix'] : ''; |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
$states = array( |
327
|
|
|
1 => array('unsetDefault', 'JDEFAULT', 'JLIB_HTML_UNSETDEFAULT_ITEM', 'JDEFAULT', false, 'star', 'star'), |
328
|
|
|
0 => array('setDefault', '', 'JLIB_HTML_SETDEFAULT_ITEM', '', false, 'star-empty', 'star-empty'), |
329
|
|
|
); |
330
|
|
|
|
331
|
|
|
return self::state($states, $value, $i, $prefix, $enabled, true, $checkbox); |
332
|
|
|
} |
333
|
|
|
|
334
|
|
|
/** |
335
|
|
|
* Returns a checked-out icon |
336
|
|
|
* |
337
|
|
|
* @param integer $i The row index. |
338
|
|
|
* @param string $editorName The name of the editor. |
339
|
|
|
* @param string $time The time that the object was checked out. |
340
|
|
|
* @param string|array $prefix An optional task prefix or an array of options |
341
|
|
|
* @param boolean $enabled True to enable the action. |
342
|
|
|
* @param string $checkbox An optional prefix for checkboxes. |
343
|
|
|
* @param string $formId An optional form id |
344
|
|
|
* |
345
|
|
|
* @return string The required HTML. |
346
|
|
|
*/ |
347
|
|
|
public static function checkedout($i, $editorName, $time, $prefix = '', $enabled = false, $checkbox = 'cb', $formId = 'adminForm') |
348
|
|
|
{ |
349
|
|
|
if (is_array($prefix)) |
350
|
|
|
{ |
351
|
|
|
$options = $prefix; |
352
|
|
|
$enabled = array_key_exists('enabled', $options) ? $options['enabled'] : $enabled; |
353
|
|
|
$checkbox = array_key_exists('checkbox', $options) ? $options['checkbox'] : $checkbox; |
354
|
|
|
$prefix = array_key_exists('prefix', $options) ? $options['prefix'] : ''; |
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
$text = addslashes(htmlspecialchars($editorName, ENT_COMPAT, 'UTF-8')); |
358
|
|
|
$date = addslashes(htmlspecialchars(JHtml::_('date', $time, JText::_('DATE_FORMAT_LC')), ENT_COMPAT, 'UTF-8')); |
359
|
|
|
$time = addslashes(htmlspecialchars(JHtml::_('date', $time, 'H:i'), ENT_COMPAT, 'UTF-8')); |
360
|
|
|
$active_title = JText::_('JLIB_HTML_CHECKIN') . '::' . $text . '<br />' . $date . '<br />' . $time; |
361
|
|
|
$inactive_title = JText::_('JLIB_HTML_CHECKED_OUT') . '::' . $text . '<br />' . $date . '<br />' . $time; |
362
|
|
|
|
363
|
|
|
return self::action( |
364
|
|
|
$i, 'checkin', $prefix, JText::_('JLIB_HTML_CHECKED_OUT'), $active_title, $inactive_title, true, 'lock', |
365
|
|
|
'lock', $enabled, false, $checkbox, $formId |
366
|
|
|
); |
367
|
|
|
} |
368
|
|
|
|
369
|
|
|
/** |
370
|
|
|
* Creates a order-up action icon. |
371
|
|
|
* |
372
|
|
|
* @param integer $i The row index. |
373
|
|
|
* @param string $task An optional task to fire. |
374
|
|
|
* @param string|array $prefix An optional task prefix or an array of options |
375
|
|
|
* @param string $text An optional text to display |
376
|
|
|
* @param boolean $enabled An optional setting for access control on the action. |
377
|
|
|
* @param string $checkbox An optional prefix for checkboxes. |
378
|
|
|
* |
379
|
|
|
* @return string The required HTML. |
380
|
|
|
*/ |
381
|
|
|
public static function orderUp($i, $task = 'orderup', $prefix = '', $text = 'JLIB_HTML_MOVE_UP', $enabled = true, $checkbox = 'cb') |
382
|
|
|
{ |
383
|
|
|
if (is_array($prefix)) |
384
|
|
|
{ |
385
|
|
|
$options = $prefix; |
386
|
|
|
$text = array_key_exists('text', $options) ? $options['text'] : $text; |
387
|
|
|
$enabled = array_key_exists('enabled', $options) ? $options['enabled'] : $enabled; |
388
|
|
|
$checkbox = array_key_exists('checkbox', $options) ? $options['checkbox'] : $checkbox; |
389
|
|
|
$prefix = array_key_exists('prefix', $options) ? $options['prefix'] : ''; |
390
|
|
|
} |
391
|
|
|
|
392
|
|
|
return self::action($i, $task, $prefix, $text, $text, $text, false, 'uparrow', 'uparrow_disabled', $enabled, true, $checkbox); |
393
|
|
|
} |
394
|
|
|
|
395
|
|
|
/** |
396
|
|
|
* Creates a order-down action icon. |
397
|
|
|
* |
398
|
|
|
* @param integer $i The row index. |
399
|
|
|
* @param string $task An optional task to fire. |
400
|
|
|
* @param string|array $prefix An optional task prefix or an array of options |
401
|
|
|
* @param string $text An optional text to display |
402
|
|
|
* @param boolean $enabled An optional setting for access control on the action. |
403
|
|
|
* @param string $checkbox An optional prefix for checkboxes. |
404
|
|
|
* |
405
|
|
|
* @return string The required HTML. |
406
|
|
|
*/ |
407
|
|
|
public static function orderDown($i, $task = 'orderdown', $prefix = '', $text = 'JLIB_HTML_MOVE_DOWN', $enabled = true, $checkbox = 'cb') |
408
|
|
|
{ |
409
|
|
|
if (is_array($prefix)) |
410
|
|
|
{ |
411
|
|
|
$options = $prefix; |
412
|
|
|
$text = array_key_exists('text', $options) ? $options['text'] : $text; |
413
|
|
|
$enabled = array_key_exists('enabled', $options) ? $options['enabled'] : $enabled; |
414
|
|
|
$checkbox = array_key_exists('checkbox', $options) ? $options['checkbox'] : $checkbox; |
415
|
|
|
$prefix = array_key_exists('prefix', $options) ? $options['prefix'] : ''; |
416
|
|
|
} |
417
|
|
|
|
418
|
|
|
return self::action($i, $task, $prefix, $text, $text, $text, false, 'downarrow', 'downarrow_disabled', $enabled, true, $checkbox); |
419
|
|
|
} |
420
|
|
|
|
421
|
|
|
/** |
422
|
|
|
* Fake sorting function. Display only the title so it's easy for refactorings. |
423
|
|
|
* |
424
|
|
|
* @param string $title The title. |
425
|
|
|
* |
426
|
|
|
* @return string The title. |
427
|
|
|
*/ |
428
|
|
|
public static function fakesort($title) |
429
|
|
|
{ |
430
|
|
|
return JText::_($title); |
431
|
|
|
} |
432
|
|
|
|
433
|
|
|
/** |
434
|
|
|
* Method to sort a column in a grid |
435
|
|
|
* |
436
|
|
|
* @param string $title The link title |
437
|
|
|
* @param string $order The order field for the column |
438
|
|
|
* @param string $direction The current direction |
439
|
|
|
* @param mixed $selected The selected ordering |
440
|
|
|
* @param string $task An optional task override |
441
|
|
|
* @param string $new_direction An optional direction for the new column |
442
|
|
|
* @param string $tip An optional text shown as tooltip title instead of $title |
443
|
|
|
* @param string $icon Icon to show |
444
|
|
|
* @param string $formId The form id |
445
|
|
|
* |
446
|
|
|
* @return string |
447
|
|
|
*/ |
448
|
|
|
public static function sort($title, $order, $direction = 'asc', $selected = 0, |
449
|
|
|
$task = null, $new_direction = 'asc', $tip = '', $icon = null, $formId = 'adminForm' |
450
|
|
|
) |
451
|
|
|
{ |
452
|
|
|
JHtml::_('rbootstrap.tooltip'); |
453
|
|
|
static::main(); |
454
|
|
|
|
455
|
|
|
$direction = strtolower($direction); |
456
|
|
|
$orderIcons = array('icon-chevron-up', 'icon-chevron-down'); |
457
|
|
|
$index = (int) ($direction == 'desc'); |
458
|
|
|
|
459
|
|
|
if ($order != $selected) |
460
|
|
|
{ |
461
|
|
|
$direction = $new_direction; |
462
|
|
|
} |
463
|
|
|
else |
464
|
|
|
{ |
465
|
|
|
$direction = ($direction == 'desc') ? 'asc' : 'desc'; |
466
|
|
|
} |
467
|
|
|
|
468
|
|
|
// Create an object to pass it to the layouts |
469
|
|
|
$data = new stdClass; |
470
|
|
|
$data->order = $order; |
471
|
|
|
$data->direction = $direction; |
472
|
|
|
$data->metatitle = RHtml::tooltipText(JText::_($tip ? $tip : $title), JText::_('JGLOBAL_CLICK_TO_SORT_THIS_COLUMN'), 0); |
473
|
|
|
$data->selected = $selected; |
474
|
|
|
$data->task = $task; |
475
|
|
|
$data->tip = $tip; |
476
|
|
|
$data->title = $title; |
477
|
|
|
$data->orderIcon = $orderIcons[$index]; |
478
|
|
|
$data->icon = $icon; |
479
|
|
|
$data->form = $formId; |
480
|
|
|
|
481
|
|
|
return RLayoutHelper::render('grid.sort', $data); |
482
|
|
|
} |
483
|
|
|
|
484
|
|
|
/** |
485
|
|
|
* Method to sort a column in a grid |
486
|
|
|
* |
487
|
|
|
* @param string $title The link title |
488
|
|
|
* @param string $order The order field for the column |
489
|
|
|
* @param string $direction The current direction |
490
|
|
|
* @param mixed $selected The selected ordering |
491
|
|
|
* @param string $task An optional task override |
492
|
|
|
* @param string $new_direction An optional direction for the new column |
493
|
|
|
* @param string $tip An optional text shown as tooltip title instead of $title |
494
|
|
|
* @param string $icon Icon to show |
495
|
|
|
* |
496
|
|
|
* @return string |
497
|
|
|
* |
498
|
|
|
* @deprecated 1.1 Use the function self::sort() that already supports icons and uses layouts |
499
|
|
|
*/ |
500
|
|
|
public static function sorto($title, $order, $direction = 'asc', $selected = 0, $task = null, $new_direction = 'asc', $tip = '', $icon = null) |
|
|
|
|
501
|
|
|
{ |
502
|
|
|
JHtml::_('rbootstrap.tooltip'); |
503
|
|
|
static::main(); |
504
|
|
|
|
505
|
|
|
$direction = strtolower($direction); |
506
|
|
|
$icon = array('chevron-up', 'chevron-down'); |
507
|
|
|
$index = (int) ($direction == 'desc'); |
508
|
|
|
|
509
|
|
|
if ($order != $selected) |
510
|
|
|
{ |
511
|
|
|
$direction = $new_direction; |
512
|
|
|
} |
513
|
|
|
else |
514
|
|
|
{ |
515
|
|
|
$direction = ($direction == 'desc') ? 'asc' : 'desc'; |
516
|
|
|
} |
517
|
|
|
|
518
|
|
|
$html = '<a href="#" onclick="Joomla.tableOrdering(\'' . $order . '\',\'' . $direction . '\',\'' . $task . '\');return false;"' |
519
|
|
|
. ' class="hasTooltip" title="' . RHtml::tooltipText(JText::_($tip ? $tip : $title), JText::_('JGLOBAL_CLICK_TO_SORT_THIS_COLUMN'), 0) . '">'; |
520
|
|
|
|
521
|
|
|
$html .= '<i class="icon-sort"></i>'; |
522
|
|
|
|
523
|
|
|
if ($order == $selected) |
524
|
|
|
{ |
525
|
|
|
$html .= ' <i class="icon-' . $icon[$index] . '"></i>'; |
526
|
|
|
} |
527
|
|
|
|
528
|
|
|
$html .= '</a>'; |
529
|
|
|
|
530
|
|
|
return $html; |
531
|
|
|
} |
532
|
|
|
} |
533
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.