Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
repeatable.php
Aller à la documentation de ce fichier.
1 <?php
2 /**
3  * @package Joomla.Platform
4  * @subpackage Form
5  *
6  * @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
7  * @license GNU General Public License version 2 or later; see LICENSE
8  */
9 
10 defined('JPATH_PLATFORM') or die;
11 
12 /**
13  * Form Field class for the Joomla Platform.
14  * Display a JSON loaded window with a repeatable set of sub fields
15  *
16  * @package Joomla.Platform
17  * @subpackage Form
18  * @since 3.2
19  */
21 {
22  /**
23  * The form field type.
24  *
25  * @var string
26  * @since 3.2
27  */
28  protected $type = 'Repeatable';
29 
30  /**
31  * Method to get the field input markup.
32  *
33  * @return string The field input markup.
34  *
35  * @since 3.2
36  */
37  protected function getInput()
38  {
39  // Initialize variables.
40  $subForm = new JForm($this->name, array('control' => 'jform'));
41  $xml = $this->element->children()->asXML();
42  $subForm->load($xml);
43 
44  // Needed for repeating modals in gmaps
45  $subForm->repeatCounter = (int) @$this->form->repeatCounter;
46  $children = $this->element->children();
47 
48  $subForm->setFields($children);
49 
50  $modalid = $this->id . '_modal';
51 
52  $str = array();
53  $str[] = '<div id="' . $modalid . '" style="display:none">';
54  $str[] = '<table id="' . $modalid . '_table" class="adminlist ' . $this->element['class'] . ' table table-striped">';
55  $str[] = '<thead><tr>';
56  $names = array();
57  $attributes = $this->element->attributes();
58 
59  foreach ($subForm->getFieldset($attributes->name . '_modal') as $field)
60  {
61  $names[] = (string) $field->element->attributes()->name;
62  $str[] = '<th>' . strip_tags($field->getLabel($field->name));
63  $str[] = '<br /><small style="font-weight:normal">' . JText::_($field->description) . '</small>';
64  $str[] = '</th>';
65  }
66 
67  $str[] = '<th><a href="#" class="add btn button btn-success"><span class="icon-plus"></span> </a></th>';
68  $str[] = '</tr></thead>';
69  $str[] = '<tbody><tr>';
70 
71  foreach ($subForm->getFieldset($attributes->name . '_modal') as $field)
72  {
73  $str[] = '<td>' . $field->getInput() . '</td>';
74  }
75 
76  $str[] = '<td>';
77  $str[] = '<div class="btn-group"><a class="add btn button btn-success"><span class="icon-plus"></span> </a>';
78  $str[] = '<a class="remove btn button btn-danger"><span class="icon-minus"></span> </a></div>';
79  $str[] = '</td>';
80  $str[] = '</tr></tbody>';
81  $str[] = '</table>';
82  $str[] = '</div>';
83 
84  $names = json_encode($names);
85 
86  JHtml::_('script', 'system/repeatable.js', true, true);
87 
88  // If a maximum value isn't set then we'll make the maximum amount of cells a large number
89  $maximum = $this->element['maximum'] ? (int) $this->element['maximum'] : '999';
90 
91  $script = "(function ($){
92  $(document).ready(function (){
93  var repeatable = new $.JRepeatable('$modalid', $names, '$this->id', '$maximum');
94  });
95  })(jQuery);";
96 
97  $document = JFactory::getDocument();
98  $document->addScriptDeclaration($script);
99 
100  $select = (string) $this->element['select'] ? JText::_((string) $this->element['select']) : JText::_('JLIB_FORM_BUTTON_SELECT');
101  $icon = $this->element['icon'] ? '<i class="icon-' . $this->element['icon'] . '"></i> ' : '';
102  $str[] = '<button class="btn" id="' . $modalid . '_button" data-modal="' . $modalid . '">' . $icon . $select . '</button>';
103 
104  if (is_array($this->value))
105  {
106  $this->value = array_shift($this->value);
107  }
108 
109  $value = htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8');
110  $str[] = '<input type="hidden" name="' . $this->name . '" id="' . $this->id . '" value="' . $value . '" />';
111 
112  JText::script('JAPPLY');
113  JText::script('JCANCEL');
114  return implode("\n", $str);
115  }
116 }