public function render($attributes = array())
 {
     $id = $this->getSerialId();
     $html = parent::render($attributes);
     $recordClass = $this->record_class;
     $record = new $recordClass();
     $deleteAction = $record->getRecordActionClass('Delete');
     $env = kernel()->twig->env;
     $html .= $env->render('@CRUD/widgets/quick_crud_widget.html', array('deleteAction' => str_replace('\\', '::', $deleteAction), 'selectInputId' => $id, 'dataLabelField' => $record->getDataLabelField(), 'dataValueField' => $record->getDataValueField(), 'dialogPath' => $this->dialog_path, 'self' => $this));
     return $html;
 }
예제 #2
0
    public function render($attributes = array())
    {
        $this->setAttributes($attributes);
        $selfId = $this->getSerialId();
        $this->setId($selfId);
        // @var array[string]string formatIds array contains the format charactor and corresponding
        // element ID.
        $formatIds = array();
        $nodes = array();
        for ($i = 0; $i < strlen($this->format); $i++) {
            $c = $this->format[$i];
            if (isset($this->formatOptions[$c])) {
                $value = null;
                if ($this->dateObject) {
                    $value = $this->dateObject->format($c);
                } else {
                    if ($this->value) {
                        $value = $this->value;
                    }
                }
                $select = new SelectInput(array('options' => $this->formatOptions[$c], 'value' => $value, 'allow_empty' => $this->allow_empty, 'class' => '+=form-control'));
                $id = $select->getSerialId();
                // $select->setId($id);
                $formatIds[$c] = $id;
                $nodes[] = $select;
            } else {
                $nodes[] = $c;
            }
        }
        $ids = array_values($formatIds);
        ob_start();
        ?>
<script>
// when changing selector values
// update date string by the format
$(function() {
    var s = document.getElementById('<?php 
        echo $selfId;
        ?>
');
    var columns = <?php 
        echo json_encode($formatIds);
        ?>
;
    var format = '<?php 
        echo $this->storageFormat;
        ?>
';
    function updater() {
        var datestr = '';
        for ( var i = 0; i < format.length ; i++ ) {
            var c = format[i];
            var sid = columns[c];
            if (sid) {
                datestr += document.getElementById(sid).value;
            } else {
                datestr += c;
            }
        }

        // format date string
<?php 
        if ($this->convert_format) {
            ?>
        // parse datestring
        var d = new Date(datestr);
        // get timestamp and add timezone
        // <?php 
            // d = new Date( d.getTime() + <?=$this->timezone->getOffset( $this->dateObject )
            ?>
 ); ?>
        // use built-in date formatter
        s.value = d.getFullYear() 
            + '-' + (d.getMonth() + 1)
            + '-' + (d.getDate());
        if( d.getHours() && d.getMinutes() )
            s.value += ' ' + d.getHours() + ':' + d.getMinutes();

<?php 
        } else {
            ?>
        s.value = datestr;
<?php 
        }
        ?>
        // console.log('debug date', s.value);
    }
    for (var c in columns) {
        var id = columns[c];
        if( typeof jQuery !== 'undefined' ) {
            $('#' + id).bind('change',updater);
        } else {
            document.getElementById(id).addEventListener('change',updater,false);
        }
    }
});
</script>
<?php 
        $script = ob_get_contents();
        ob_end_clean();
        return '<div class="form-inline">' . parent::render() . $this->_renderNodes($nodes) . $script . '</div>';
    }
예제 #3
0
 /**
  * HTML structure
  *
  * <div class="formkit-widget formkit-widget-thumbimagefile formkit-image-wrapper">
  *    <div class="formkit-image-cover">
  *      <img src="...."/>
  *    </div>
  *    <input type="file"...>
  * </div>
  *
  */
 public function init($attributes)
 {
     $this->autoresize_types = array(_('Fit to Width') => 'max_width', _('Fit to Height') => 'max_height', _('Scale') => 'scale', _('Crop and Scale') => 'crop_and_scale');
     parent::init($attributes);
     $this->fileInput = new FileInput($this->name, $attributes);
     $this->imageCover = new Div(array('class' => 'formkit-image-cover'));
     $this->imageCover->setAttributeValue('data-width', $this->dataWidth ?: 200);
     $this->imageCover->setAttributeValue('data-height', $this->dataHeight);
     $this->inputWrapper = new Div();
     $this->inputWrapper->addClass('formkit-widget-thumbimagefile')->addClass('formkit-image-wrapper');
     // if it has a value, generate img
     if ($this->renderImageTag && $this->value) {
         $this->image = new Element('img', array('src' => $this->prefix . $this->value));
         $this->imageCover->append($this->image);
     }
     if ($this->value) {
         $this->fileInput->setAttributeValue('data-image-src', $this->prefix . $this->value);
     }
     if ($this->exif) {
         $this->fileInput->setAttributeValue('data-exif', 'true');
     }
     if ($this->autoresize) {
         $this->fileInput->setAttributeValue('data-autoresize', 'true');
     }
     if ($this->droppreview) {
         $this->fileInput->setAttributeValue('data-droppreview', 'true');
     }
     if ($this->dropupload) {
         $this->fileInput->setAttributeValue('data-dropupload', 'true');
     }
     $this->fileInput->setAttributeValue('data-width', $this->dataWidth);
     $this->fileInput->setAttributeValue('data-height', $this->dataHeight);
     $this->inputWrapper->append($this->imageCover);
     $this->inputWrapper->append($this->fileInput);
     if ($this->autoresize && $this->autoresize_input) {
         $this->fileInput->setAttributeValue('data-autoresize-input', 'true');
         $checkbox = new CheckboxInput($this->name . '_autoresize');
         $checkbox->addClass('autoresize-checkbox');
         if ($this->autoresize_input_check) {
             $checkbox->check();
         }
         $checkboxId = $checkbox->getSerialId();
         $label = new Label(_("Use auto-resize"));
         $label->for($checkboxId);
         $resizeWrapper = new Div();
         $resizeWrapper->append($checkbox);
         $resizeWrapper->append($label);
         $resizeWrapper->addClass("autoresize");
         $this->inputWrapper->append($resizeWrapper);
         if ($this->autoresize_type_input) {
             $resizeTypeWrapper = new Div();
             $resizeTypeWrapper->addClass('autoresize-type');
             $typeSelector = new SelectInput($this->name . '_autoresize_type', ['options' => $this->autoresize_types, 'value' => $this->autoresize_type]);
             $typeSelector->addClass('autoresize-type-selector');
             $resizeTypeWrapper->append($typeSelector);
             $this->inputWrapper->append($resizeTypeWrapper);
         }
     }
 }