예제 #1
0
    /**
     * Registers the needed client assets
     */
    public function registerAssets()
    {
        $view = $this->getView();
        MomentAsset::register($view);
        $input = 'jQuery("#' . $this->options['id'] . '")';
        $id = $input;
        if ($this->hideInput) {
            $id = 'jQuery("#' . $this->containerOptions['id'] . '")';
        }
        if (!empty($this->_langFile)) {
            LanguageAsset::register($view)->js[] = $this->_langFile;
        }
        DateRangePickerAsset::register($view);
        if (empty($this->callback)) {
            if ($this->hideInput) {
                $this->callback = <<<JS
function(start, end) {
    var val = start.format('{$this->_format}') + '{$this->_separator}' + end.format('{$this->_format}');
    {$id}.find('.range-value').html(val);
    {$input}.val(val);
    {$input}.trigger('change');
}
JS;
            } elseif ($this->useWithAddon) {
                $id = "{$input}.closest('.input-group')";
                $this->callback = <<<JS
function(start, end) {
    var val = start.format('{$this->_format}') + '{$this->_separator}' + end.format('{$this->_format}');
    {$input}.val(val);
    {$input}.trigger('change');
}
JS;
            } else {
                $this->registerPlugin($this->_pluginName, $id);
                return;
            }
        }
        $this->registerPlugin($this->_pluginName, $id, null, $this->callback);
    }
예제 #2
0
    /**
     * Registers the needed client assets
     */
    public function registerAssets()
    {
        $view = $this->getView();
        MomentAsset::register($view);
        $input = 'jQuery("#' . $this->options['id'] . '")';
        $id = $input;
        if ($this->hideInput) {
            $id = 'jQuery("#' . $this->containerOptions['id'] . '")';
        }
        if (!empty($this->_langFile)) {
            LanguageAsset::register($view)->js[] = $this->_langFile;
        }
        DateRangePickerAsset::register($view);
        $rangeJs = '';
        if (empty($this->callback)) {
            $val = "start.format('{$this->_format}') + '{$this->_separator}' + end.format('{$this->_format}')";
            if (ArrayHelper::getValue($this->pluginOptions, 'singleDatePicker', false)) {
                $val = "start.format('{$this->_format}')";
            }
            $rangeJs = $this->getRangeJs('start') . $this->getRangeJs('end');
            $change = $rangeJs . "{$input}.val(val).trigger('change');";
            if ($this->hideInput) {
                $script = "var val={$val};{$id}.find('.range-value').html(val);{$change}";
            } elseif ($this->useWithAddon) {
                $id = "{$input}.closest('.input-group')";
                $script = "var val={$val};{$change}";
            } elseif (!$this->autoUpdateOnInit) {
                $script = "var val={$val};{$change}";
            } else {
                $this->registerPlugin($this->pluginName, $id);
                return;
            }
            $this->callback = "function(start,end,label){{$script}}";
        }
        // parse input change correctly when range input value is cleared
        $js = <<<JS
{$input}.off('change.kvdrp').on('change.kvdrp', function() {
    var drp = {$id}.data('{$this->pluginName}'), now;
    if (\$(this).val() || !drp) {
        return;
    }
    now = moment().format('{$this->_format}') || '';
    drp.setStartDate(now);
    drp.setEndDate(now);
    {$rangeJs}
});
JS;
        $view->registerJs($js);
        $this->registerPlugin($this->pluginName, $id, null, $this->callback);
    }
예제 #3
0
 /**
  * Registers the needed client assets
  */
 public function registerAssets()
 {
     $view = $this->getView();
     MomentAsset::register($view);
     $input = 'jQuery("#' . $this->options['id'] . '")';
     $id = $input;
     if ($this->hideInput) {
         $id = 'jQuery("#' . $this->containerOptions['id'] . '")';
     }
     if (!empty($this->_langFile)) {
         LanguageAsset::register($view)->js[] = $this->_langFile;
     }
     DateRangePickerAsset::register($view);
     if (empty($this->callback)) {
         $val = "start.format('{$this->_format}') + '{$this->_separator}' + end.format('{$this->_format}')";
         if (ArrayHelper::getValue($this->pluginOptions, 'singleDatePicker', false)) {
             $val = "start.format('{$this->_format}')";
         }
         $change = $this->getRangeJs('start') . $this->getRangeJs('end') . "{$input}.val(val).trigger('change');";
         if ($this->hideInput) {
             $script = "var val={$val};{$id}.find('.range-value').html(val);{$change}";
         } elseif ($this->useWithAddon) {
             $id = "{$input}.closest('.input-group')";
             $script = "var val={$val};{$change}";
         } elseif (!$this->autoUpdateOnInit) {
             $script = "var val={$val};{$change}";
         } else {
             $this->registerPlugin($this->pluginName, $id);
             return;
         }
         $this->callback = "function(start,end,label){{$script}}";
     }
     $this->registerPlugin($this->pluginName, $id, null, $this->callback);
 }