1 <?php
2 /**
3 * @package Joomla.Libraries
4 * @subpackage HTML
5 *
6 * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
7 * @license GNU General Public License version 2 or later; see LICENSE.txt
8 */
9
10 defined('JPATH_PLATFORM') or die;
11
12 /**
13 * HTML utility class for building a dropdown menu
14 *
15 * @since 3.2
16 */
17 abstract class JHtmlActionsDropdown
18 {
19 /**
20 * @var string HTML markup for the dropdown list
21 * @since 3.2
22 */
23 protected static $dropDownList = array();
24
25 /**
26 * Method to render current dropdown menu
27 *
28 * @param string $item An item to render.
29 *
30 * @return string HTML markup for the dropdown list
31 *
32 * @since 3.2
33 */
34 public static function render($item = '')
35 {
36 $html = array();
37
38 $html[] = '<button data-toggle="dropdown" class="dropdown-toggle btn btn-micro">';
39 $html[] = '<span class="caret"></span>';
40
41 if ($item)
42 {
43 $html[] = '<span class="element-invisible">' . JText::sprintf('JACTIONS', $item) . '</span>';
44 }
45
46 $html[] = '</button>';
47 $html[] = '<ul class="dropdown-menu">';
48 $html[] = implode('', static::$dropDownList);
49 $html[] = '</ul>';
50
51 static::$dropDownList = null;
52
53 return implode('', $html);
54 }
55
56 /**
57 * Append a publish item to the current dropdown menu
58 *
59 * @param string $id ID of corresponding checkbox of the record
60 * @param string $prefix The task prefix
61 *
62 * @return void
63 *
64 * @since 3.2
65 */
66 public static function publish($id, $prefix = '')
67 {
68 $task = ($prefix ? $prefix . '.' : '') . 'publish';
69 static::addCustomItem(JText::_('JTOOLBAR_PUBLISH'), 'publish', $id, $task);
70 }
71
72 /**
73 * Append an unpublish item to the current dropdown menu
74 *
75 * @param string $id ID of corresponding checkbox of the record
76 * @param string $prefix The task prefix
77 *
78 * @return void
79 *
80 * @since 3.2
81 */
82 public static function unpublish($id, $prefix = '')
83 {
84 $task = ($prefix ? $prefix . '.' : '') . 'unpublish';
85 static::addCustomItem(JText::_('JTOOLBAR_UNPUBLISH'), 'unpublish', $id, $task);
86 }
87
88 /**
89 * Append a feature item to the current dropdown menu
90 *
91 * @param string $id ID of corresponding checkbox of the record
92 * @param string $prefix The task prefix
93 *
94 * @return void
95 *
96 * @since 3.2
97 */
98 public static function feature($id, $prefix = '')
99 {
100 $task = ($prefix ? $prefix . '.' : '') . 'featured';
101 static::addCustomItem(JText::_('JFEATURE'), 'featured', $id, $task);
102 }
103
104 /**
105 * Append an unfeature item to the current dropdown menu
106 *
107 * @param string $id ID of corresponding checkbox of the record
108 * @param string $prefix The task prefix
109 *
110 * @return void
111 *
112 * @since 3.2
113 */
114 public static function unfeature($id, $prefix = '')
115 {
116 $task = ($prefix ? $prefix . '.' : '') . 'unfeatured';
117 static::addCustomItem(JText::_('JUNFEATURE'), 'unfeatured', $id, $task);
118 }
119
120 /**
121 * Append an archive item to the current dropdown menu
122 *
123 * @param string $id ID of corresponding checkbox of the record
124 * @param string $prefix The task prefix
125 *
126 * @return void
127 *
128 * @since 3.2
129 */
130 public static function archive($id, $prefix = '')
131 {
132 $task = ($prefix ? $prefix . '.' : '') . 'archive';
133 static::addCustomItem(JText::_('JTOOLBAR_ARCHIVE'), 'archive', $id, $task);
134 }
135
136 /**
137 * Append an unarchive item to the current dropdown menu
138 *
139 * @param string $id ID of corresponding checkbox of the record
140 * @param string $prefix The task prefix
141 *
142 * @return void
143 *
144 * @since 3.2
145 */
146 public static function unarchive($id, $prefix = '')
147 {
148 $task = ($prefix ? $prefix . '.' : '') . 'unpublish';
149 static::addCustomItem(JText::_('JTOOLBAR_UNARCHIVE'), 'unarchive', $id, $task);
150 }
151
152 /**
153 * Append a duplicate item to the current dropdown menu
154 *
155 * @param string $id ID of corresponding checkbox of the record
156 * @param string $prefix The task prefix
157 *
158 * @return void
159 *
160 * @since 3.2
161 */
162 public static function duplicate($id, $prefix = '')
163 {
164 $task = ($prefix ? $prefix . '.' : '') . 'duplicate';
165 static::addCustomItem(JText::_('JTOOLBAR_DUPLICATE'), 'copy', $id, $task);
166 }
167
168 /**
169 * Append a trash item to the current dropdown menu
170 *
171 * @param string $id ID of corresponding checkbox of the record
172 * @param string $prefix The task prefix
173 *
174 * @return void
175 *
176 * @since 3.2
177 */
178 public static function trash($id, $prefix = '')
179 {
180 $task = ($prefix ? $prefix . '.' : '') . 'trash';
181 static::addCustomItem(JText::_('JTOOLBAR_TRASH'), 'trash', $id, $task);
182 }
183
184 /**
185 * Append an untrash item to the current dropdown menu
186 *
187 * @param string $id ID of corresponding checkbox of the record
188 * @param string $prefix The task prefix
189 *
190 * @return void
191 *
192 * @since 3.2
193 */
194 public static function untrash($id, $prefix = '')
195 {
196 self::publish($id, $prefix);
197 }
198
199 /**
200 * Writes a divider between dropdown items
201 *
202 * @return void
203 *
204 * @since 3.0
205 */
206 public static function divider()
207 {
208 static::$dropDownList[] = '<li class="divider"></li>';
209 }
210
211 /**
212 * Append a custom item to current dropdown menu.
213 *
214 * @param string $label The label of the item.
215 * @param string $icon The icon classname.
216 * @param string $id The item id.
217 * @param string $task The task.
218 *
219 * @return void
220 *
221 * @since 3.2
222 */
223 public static function addCustomItem($label, $icon = '', $id = '', $task = '')
224 {
225 static::$dropDownList[] = '<li>'
226 . '<a href = "javascript://" onclick="listItemTask(\'' . $id . '\', \'' . $task . '\')">'
227 . ($icon ? '<span class="icon-' . $icon . '" aria-hidden="true"></span> ' : '')
228 . $label
229 . '</a>'
230 . '</li>';
231 }
232 }
233