| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 | 
							- <?php
 
- /**
 
-  *
 
-  * PHP Pro Bid $Id$ XKsKCHJ9uLGEo2/23FOgvDDJDQ3Ew5qkNjRFWswK0v8=
 
-  *
 
-  * @link        http://www.phpprobid.com
 
-  * @copyright   Copyright (c) 2017 Online Ventures Software & CodeCube SRL
 
-  * @license     http://www.phpprobid.com/license Commercial License
 
-  *
 
-  * @version     7.9 [rev.7.9.01]
 
-  */
 
- /**
 
-  * multi value form element
 
-  *
 
-  * creates an element containing an unlimited (jquery powered) list of value rows
 
-  */
 
- namespace Ppb\Form\Element;
 
- use Cube\Form\Element;
 
- class MultiValue extends Element
 
- {
 
-     /**
 
-      *
 
-      * type of element - override the variable from the parent class
 
-      *
 
-      * @var string
 
-      */
 
-     protected $_element = 'multiValue';
 
-     /**
 
-      *
 
-      * class constructor
 
-      *
 
-      * @param string $name
 
-      */
 
-     public function __construct($name)
 
-     {
 
-         parent::__construct($this->_element, $name);
 
-         $translate = $this->getTranslate();
 
-         $this->setBodyCode(
 
-             "<script type=\"text/javascript\">" . "\n"
 
-             . " function moveUp(item) { " . "\n"
 
-             . "     var before = item.prev(); " . "\n"
 
-             . "     item.insertBefore(before); " . "\n"
 
-             . " } " . "\n"
 
-             . " function moveDown(item) { " . "\n"
 
-             . "     var after = item.next(); " . "\n"
 
-             . "     item.insertAfter(after); " . "\n"
 
-             . " } " . "\n"
 
-             . " $(document).on('click', '.delete-field-row', function(e) { " . "\n"
 
-             . "     e.preventDefault(); " . "\n"
 
-             . "     $(this).closest('.field-row').remove(); " . "\n"
 
-             . " }); " . "\n"
 
-             . " $(document).on('click', '.add-field-row', function(e) { " . "\n"
 
-             . "     e.preventDefault(); " . "\n"
 
-             . "     var parent = $(this).closest('.form-group').find('.multi-value-rows'); " . "\n"
 
-             . "     var row = $(this).closest('.field-row'); " . "\n"
 
-             . "     var cloned = row.clone(true, true); " . "\n"
 
-             . "     row.find('input[type=text]').val(''); " . "\n"
 
-             . "     cloned.find('.add-field-row').remove(); " . "\n"
 
-             . "     $('<a>').attr('href', '#').attr('class', 'btn-fld-move-up').html(' <i class=\"fa fa-angle-up\"></i>').appendTo(cloned); " . "\n"
 
-             . "     $('<a>').attr('href', '#').attr('class', 'btn-fld-move-down').html('<i class=\"fa fa-angle-down\"></i> ').appendTo(cloned); " . "\n"
 
-             . "     $('<button>').attr('class', 'delete-field-row btn btn-default').html('" . $translate->_('Delete') . "').appendTo(cloned); " . "\n"
 
-             . "     parent.append(cloned); " . "\n"
 
-             . " }); " . "\n"
 
-             . " $(document).on('click', '.btn-fld-move-up', function(e) { " . "\n"
 
-             . "     e.preventDefault(); " . "\n"
 
-             . "     var row = $(this).closest('.field-row'); " . "\n"
 
-             . "     moveUp(row); " . "\n"
 
-             . " }); " . "\n"
 
-             . " $(document).on('click', '.btn-fld-move-down', function(e) { " . "\n"
 
-             . "     e.preventDefault(); " . "\n"
 
-             . "     var row = $(this).closest('.field-row'); " . "\n"
 
-             . "     moveDown(row); " . "\n"
 
-             . " }); " . "\n"
 
-             . "</script>");
 
-     }
 
-     /**
 
-      *
 
-      * render the form element
 
-      *
 
-      * @return string
 
-      */
 
-     public function render()
 
-     {
 
-         $output = null;
 
-         $values = $this->getValue();
 
-         $output .= '<div class="multi-value-rows">';
 
-         foreach ((array)$values as $value) {
 
-             if (!empty($value)) {
 
-                 $output .= $this->_renderRow(false, $value);
 
-             }
 
-         }
 
-         $output .= '</div>';
 
-         $output .= $this->_renderRow();
 
-         return $output;
 
-     }
 
-     /**
 
-      *
 
-      * render a single row of the element
 
-      *
 
-      * @param bool   $new
 
-      * @param string $value
 
-      *
 
-      * @return string
 
-      */
 
-     protected function _renderRow($new = true, $value = null)
 
-     {
 
-         $translate = $this->getTranslate();
 
-         $output = '<div class="field-row">';
 
-         $output .= ' <input type="text" name="' . $this->_name . '[]" '
 
-             . $this->renderAttributes()
 
-             . 'value="' . $value . '" '
 
-             . $this->_endTag
 
-             . (($new === true) ?
 
-                 ' <button class="add-field-row btn btn-default">' . $translate->_('Add') . '</button>' :
 
-                 ' <a class="btn-fld-move-up" href="#"><i class="fa fa-angle-up"></i></a><a class="btn-fld-move-down" href="#"><i class="fa fa-angle-down"></i></a>
 
-                   <button class="delete-field-row btn btn-default">' . $translate->_('Delete') . '</button>')
 
-             . '</div>';
 
-         return $output;
 
-     }
 
- }
 
 
  |