Source for file repeatable.php

Documentation is available at repeatable.php

  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.  */
  20. {
  21.     /**
  22.      * The form field type.
  23.      *
  24.      * @var    string 
  25.      * @since  3.2
  26.      */
  27.     protected $type = 'Repeatable';
  28.  
  29.     /**
  30.      * Method to get the field input markup.
  31.      *
  32.      * @return  string  The field input markup.
  33.      *
  34.      * @since   3.2
  35.      */
  36.     protected function getInput()
  37.     {
  38.         // Initialize variables.
  39.         $subForm = new JForm($this->name, array('control' => 'jform'));
  40.         $xml = $this->element->children()->asXML();
  41.         $subForm->load($xml);
  42.  
  43.         // Needed for repeating modals in gmaps
  44.         $subForm->repeatCounter = (int) @$this->form->repeatCounter;
  45.         $children = $this->element->children();
  46.  
  47.         $subForm->setFields($children);
  48.  
  49.         $modalid = $this->id . '_modal';
  50.  
  51.         $str = array();
  52.         $str[] = '<div id="' . $modalid . '" style="display:none">';
  53.         $str[] = '<table id="' . $modalid . '_table" class="adminlist ' . $this->element['class'] . ' table table-striped">';
  54.         $str[] = '<thead><tr>';
  55.         $names = array();
  56.         $attributes = $this->element->attributes();
  57.  
  58.         foreach ($subForm->getFieldset($attributes->name . '_modal') as $field)
  59.         {
  60.             $names[] = (string) $field->element->attributes()->name;
  61.             $str[] = '<th>' . strip_tags($field->getLabel($field->name));
  62.             $str[] = '<br /><small style="font-weight:normal">' . JText::_($field->description) . '</small>';
  63.             $str[] = '</th>';
  64.         }
  65.  
  66.         $str[] = '<th><a href="#" class="add btn button btn-success"><span class="icon-plus"></span> </a></th>';
  67.         $str[] = '</tr></thead>';
  68.         $str[] = '<tbody><tr>';
  69.  
  70.         foreach ($subForm->getFieldset($attributes->name . '_modal') as $field)
  71.         {
  72.             $str[] = '<td>' . $field->getInput() . '</td>';
  73.         }
  74.  
  75.         $str[] = '<td>';
  76.         $str[] = '<div class="btn-group"><a class="add btn button btn-success"><span class="icon-plus"></span> </a>';
  77.         $str[] = '<a class="remove btn button btn-danger"><span class="icon-minus"></span> </a></div>';
  78.         $str[] = '</td>';
  79.         $str[] = '</tr></tbody>';
  80.         $str[] = '</table>';
  81.         $str[] = '</div>';
  82.  
  83.         $names = json_encode($names);
  84.  
  85.         JHtml::_('script', 'system/repeatable.js', true, true);
  86.  
  87.         // If a maximum value isn't set then we'll make the maximum amount of cells a large number
  88.         $maximum = $this->element['maximum'] ? (int) $this->element['maximum'] : '999';
  89.  
  90.         $script = "(function ($){
  91.             $(document).ready(function (){
  92.                 var repeatable = new $.JRepeatable('$modalid', $names, '$this->id', '$maximum');
  93.             });
  94.         })(jQuery);";
  95.  
  96.         $document = JFactory::getDocument();
  97.         $document->addScriptDeclaration($script);
  98.  
  99.         $select = (string) $this->element['select'] ? JText::_((string) $this->element['select']) : JText::_('JLIB_FORM_BUTTON_SELECT');
  100.         $icon = $this->element['icon'] ? '<i class="icon-' . $this->element['icon'] . '"></i> ' : '';
  101.         $str[] = '<button class="btn" id="' . $modalid . '_button" data-modal="' . $modalid . '">' . $icon . $select . '</button>';
  102.  
  103.         if (is_array($this->value))
  104.         {
  105.             $this->value = array_shift($this->value);
  106.         }
  107.  
  108.         $value = htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8');
  109.         $str[] = '<input type="hidden" name="' . $this->name . '" id="' . $this->id . '" value="' . $value . '" />';
  110.  
  111.         JText::script('JAPPLY');
  112.         JText::script('JCANCEL');
  113.         return implode("\n", $str);
  114.     }
  115. }

Documentation generated on Tue, 19 Nov 2013 15:11:48 +0100 by phpDocumentor 1.4.3