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