PageRenderTime 91ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/libraries/joomla/html/html/grid.php

https://github.com/joebushi/joomla
PHP | 277 lines | 188 code | 32 blank | 57 comment | 26 complexity | 71a5123765079f11f2d2c9897a586fb2 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. <?php
  2. /**
  3. * @version $Id$
  4. * @package Joomla.Framework
  5. * @subpackage HTML
  6. * @copyright Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE.txt
  8. */
  9. /**
  10. * Utility class for creating HTML Grids
  11. *
  12. * @static
  13. * @package Joomla.Framework
  14. * @subpackage HTML
  15. * @since 1.5
  16. */
  17. abstract class JHtmlGrid
  18. {
  19. /**
  20. * Display a boolean setting widget.
  21. *
  22. * @static
  23. * @param integer The row index.
  24. * @param integer The value of the boolean field.
  25. * @param string Task to turn the boolean setting on.
  26. * @param string Task to turn the boolean setting off.
  27. * @return string The boolean setting widget.
  28. * @since 1.0
  29. */
  30. static function boolean($i, $value, $taskOn = null, $taskOff = null)
  31. {
  32. // Load the behavior.
  33. self::behavior();
  34. // Build the title.
  35. $title = ($value) ? JText::_('JYes') : JText::_('JNo');
  36. $title .= '::'.JText::_('Click_To_Toggle');
  37. // Build the <a> tag.
  38. $bool = ($value) ? 'true' : 'false';
  39. $task = ($value) ? $taskOff : $taskOn;
  40. $toggle = (!$task) ? false : true;
  41. if ($toggle) {
  42. $html = '<a class="grid_'.$bool.' hasTip" title="'.$title.'" rel="{id:\'cb'.$i.'\', task:\''.$task.'\'}" href="#toggle"></a>';
  43. } else {
  44. $html = '<a class="grid_'.$bool.'" rel="{id:\'cb'.$i.'\', task:\''.$task.'\'}"></a>';
  45. }
  46. return $html;
  47. }
  48. /**
  49. * @param string The link title
  50. * @param string The order field for the column
  51. * @param string The current direction
  52. * @param string The selected ordering
  53. * @param string An optional task override
  54. */
  55. public static function sort($title, $order, $direction = 'asc', $selected = 0, $task=NULL)
  56. {
  57. $direction = strtolower($direction);
  58. $images = array('sort_asc.png', 'sort_desc.png');
  59. $index = intval($direction == 'desc');
  60. $direction = ($direction == 'desc') ? 'asc' : 'desc';
  61. $html = '<a href="javascript:tableOrdering(\''.$order.'\',\''.$direction.'\',\''.$task.'\');" title="'.JText::_('CLICK_TO_SORT_THIS_COLUMN').'">';
  62. $html .= JText::_($title);
  63. if ($order == $selected) {
  64. $html .= JHtml::_('image', 'system/'.$images[$index], '', NULL, true);
  65. }
  66. $html .= '</a>';
  67. return $html;
  68. }
  69. /**
  70. * @param int The row index
  71. * @param int The record id
  72. * @param boolean
  73. * @param string The name of the form element
  74. *
  75. * @return string
  76. */
  77. public static function id($rowNum, $recId, $checkedOut=false, $name='cid')
  78. {
  79. if ($checkedOut) {
  80. return '';
  81. } else {
  82. return '<input type="checkbox" id="cb'.$rowNum.'" name="'.$name.'[]" value="'.$recId.'" onclick="isChecked(this.checked);" title="'.JText::sprintf('JGrid_Checkbox_Row_N', ($rowNum + 1)).'" />';
  83. }
  84. }
  85. /**
  86. * @deprecated
  87. */
  88. public static function access(&$row, $i, $archived = NULL)
  89. {
  90. // TODO: This needs to be reworked to suit the new access levels
  91. if ($row->access <= 1) {
  92. $color_access = 'class="allow"';
  93. $task_access = 'accessregistered';
  94. } else if ($row->access == 1) {
  95. $color_access = 'class="deny"';
  96. $task_access = 'accessspecial';
  97. } else {
  98. $color_access = 'class="none"';
  99. $task_access = 'accesspublic';
  100. }
  101. if ($archived == -1)
  102. {
  103. $href = JText::_($row->groupname);
  104. }
  105. else
  106. {
  107. $href = '
  108. <a href="javascript:void(0);" onclick="return listItemTask(\'cb'. $i .'\',\''. $task_access .'\')" '. $color_access .'>
  109. '. JText::_($row->groupname) .'</a>'
  110. ;
  111. }
  112. return $href;
  113. }
  114. public static function checkedOut(&$row, $i, $identifier = 'id')
  115. {
  116. $user = &JFactory::getUser();
  117. $userid = $user->get('id');
  118. $result = false;
  119. if ($row INSTANCEOF JTable) {
  120. $result = $row->isCheckedOut($userid);
  121. } else {
  122. $result = JTable::isCheckedOut($userid, $row->checked_out);
  123. }
  124. $checked = '';
  125. if ($result) {
  126. $checked = JHtmlGrid::_checkedOut($row);
  127. } else {
  128. if ($identifier == 'id')
  129. $checked = JHtml::_('grid.id', $i, $row->$identifier);
  130. else
  131. $checked = JHtml::_('grid.id', $i, $row->$identifier, $result, $identifier);
  132. }
  133. return $checked;
  134. }
  135. /**
  136. * @param mixed $value Either the scalar value, or an object (for backward compatibility, deprecated)
  137. * @param int $i
  138. * @param string $img1 Image for a positive or on value
  139. * @param string $img0 Image for the empty or off value
  140. * @param string $prefix An optional prefix for the task
  141. */
  142. public static function published($value, $i, $img1 = 'tick.png', $img0 = 'publish_x.png', $prefix='')
  143. {
  144. if (is_object($value)) {
  145. $value = $value->published;
  146. }
  147. $img = $value ? $img1 : $img0;
  148. $task = $value ? 'unpublish' : 'publish';
  149. $alt = $value ? JText::_('Published') : JText::_('Unpublished');
  150. $action = $value ? JText::_('UNPUBLISH_ITEM') : JText::_('PUBLISH_ITEM');
  151. $href = '
  152. <a href="javascript:void(0);" onclick="return listItemTask(\'cb'. $i .'\',\''. $prefix.$task .'\')" title="'. $action .'">'.
  153. JHTML::_('image', 'admin/'.$img, $alt, array('border' => 0), true).'</a>'
  154. ;
  155. return $href;
  156. }
  157. public static function state(
  158. $filter_state = '*',
  159. $published = 'Published',
  160. $unpublished = 'Unpublished',
  161. $archived = null,
  162. $trashed = null
  163. ) {
  164. $state = array(
  165. '' => '- ' . JText::_('SELECT_STATE') . ' -',
  166. 'P' => JText::_($published),
  167. 'U' => JText::_($unpublished)
  168. );
  169. if ($archived) {
  170. $state['A'] = JText::_($archived);
  171. }
  172. if ($trashed) {
  173. $state['T'] = JText::_($trashed);
  174. }
  175. return JHtml::_(
  176. 'select.genericlist',
  177. $state,
  178. 'filter_state',
  179. array(
  180. 'list.attr' => 'class="inputbox" size="1" onchange="submitform();"',
  181. 'list.select' => $filter_state,
  182. 'option.key' => null
  183. )
  184. );
  185. }
  186. public static function order($rows, $image = 'filesave.png', $task = 'saveorder')
  187. {
  188. $image = JHtml::_('image', 'admin/'.$image, JText::_('SAVE_ORDER'), NULL, true);
  189. $href = '<a href="javascript:saveorder('.(count($rows)-1).', \''.$task.'\')" title="'.JText::_('SAVE_ORDER').'">'.$image.'</a>';
  190. return $href;
  191. }
  192. protected static function _checkedOut(&$row, $overlib = 1)
  193. {
  194. $hover = '';
  195. if ($overlib)
  196. {
  197. $text = addslashes(htmlspecialchars($row->editor));
  198. $date = JHtml::_('date', $row->checked_out_time, JText::_('DATE_FORMAT_LC1'));
  199. $time = JHtml::_('date', $row->checked_out_time, '%H:%M');
  200. $hover = '<span class="editlinktip hasTip" title="'. JText::_('CHECKED_OUT') .'::'. $text .'<br />'. $date .'<br />'. $time .'">';
  201. }
  202. $checked = $hover .JHTML::_('image', 'admin/checked_out.png', NULL, NULL, true).'</span>';
  203. return $checked;
  204. }
  205. static function behavior()
  206. {
  207. static $loaded;
  208. if (!$loaded)
  209. {
  210. // Build the behavior script.
  211. $js = '
  212. window.addEvent(\'domready\', function(){
  213. actions = $$(\'a.move_up\');
  214. actions.combine($$(\'a.move_down\'));
  215. actions.combine($$(\'a.grid_true\'));
  216. actions.combine($$(\'a.grid_false\'));
  217. actions.combine($$(\'a.grid_trash\'));
  218. actions.each(function(a){
  219. a.addEvent(\'click\', function(){
  220. args = JSON.decode(this.rel);
  221. listItemTask(args.id, args.task);
  222. });
  223. });
  224. $$(\'input.check-all-toggle\').each(function(el){
  225. el.addEvent(\'click\', function(){
  226. if (el.checked) {
  227. document.id(this.form).getElements(\'input[type=checkbox]\').each(function(i){
  228. i.checked = true;
  229. })
  230. }
  231. else {
  232. document.id(this.form).getElements(\'input[type=checkbox]\').each(function(i){
  233. i.checked = false;
  234. })
  235. }
  236. });
  237. });
  238. });';
  239. // Add the behavior to the document head.
  240. $document = & JFactory::getDocument();
  241. $document->addScriptDeclaration($js);
  242. $loaded = true;
  243. }
  244. }
  245. }