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 creating a sortable table list
14 *
15 * @since 3.0
16 */
17 abstract class JHtmlSortablelist
18 {
19 /**
20 * @var array Array containing information for loaded files
21 * @since 3.0
22 */
23 protected static $loaded = array();
24
25 /**
26 * Method to load the Sortable script and make table sortable
27 *
28 * @param string $tableId DOM id of the table
29 * @param string $formId DOM id of the form
30 * @param string $sortDir Sort direction
31 * @param string $saveOrderingUrl Save ordering url, ajax-load after an item dropped
32 * @param boolean $proceedSaveOrderButton Set whether a save order button is displayed
33 * @param boolean $nestedList Set whether the list is a nested list
34 *
35 * @return void
36 *
37 * @since 3.0
38 *
39 * @throws InvalidArgumentException
40 */
41 public static function sortable($tableId, $formId, $sortDir = 'asc', $saveOrderingUrl = null, $proceedSaveOrderButton = true, $nestedList = false)
42 {
43 // Only load once
44 if (isset(static::$loaded[__METHOD__]))
45 {
46 return;
47 }
48
49 // Note: $i is required but has to be an optional argument in the function call due to argument order
50 if ($saveOrderingUrl === null)
51 {
52 throw new InvalidArgumentException('$saveOrderingUrl is a required argument in JHtmlSortablelist::sortable');
53 }
54
55 $displayData = array(
56 'tableId' => $tableId,
57 'formId' => $formId,
58 'sortDir' => $sortDir,
59 'saveOrderingUrl' => $saveOrderingUrl,
60 'nestedList' => $nestedList,
61 'proceedSaveOrderButton' => $proceedSaveOrderButton,
62 );
63
64 JLayoutHelper::render('joomla.html.sortablelist', $displayData);
65
66 // Set static array
67 static::$loaded[__METHOD__] = true;
68
69 return;
70 }
71
72 /**
73 * Method to inject script for enabled and disable Save order button
74 * when changing value of ordering input boxes
75 *
76 * @return void
77 *
78 * @since 3.0
79 *
80 * @deprecated 4.0 The logic is merged in the JLayout file
81 */
82 public static function _proceedSaveOrderButton()
83 {
84 JFactory::getDocument()->addScriptDeclaration(
85 "(function ($){
86 $(document).ready(function (){
87 var saveOrderButton = $('.saveorder');
88 saveOrderButton.css({'opacity':'0.2', 'cursor':'default'}).attr('onclick','return false;');
89 var oldOrderingValue = '';
90 $('.text-area-order').focus(function ()
91 {
92 oldOrderingValue = $(this).attr('value');
93 })
94 .keyup(function (){
95 var newOrderingValue = $(this).attr('value');
96 if (oldOrderingValue != newOrderingValue)
97 {
98 saveOrderButton.css({'opacity':'1', 'cursor':'pointer'}).removeAttr('onclick')
99 }
100 });
101 });
102 })(jQuery);"
103 );
104
105 return;
106 }
107 }
108