Example #1
0
    public function init()
    {
        if (is_array($this->copyFrom)) {
            $id = Html::getInputId($this->model, $this->attribute);
            $buttonId = $id . '-copyButton';
            $this->addon['append'] = ['content' => Html::button(Icon::show('code'), ['class' => 'btn btn-primary', 'id' => $buttonId]), 'asButton' => true];
            $encodedFrom = Json::encode($this->copyFrom);
            $encodedTo = Json::encode('#' . $id);
            $js = <<<EOT
\$("#{$buttonId}").click(function(){
Admin.copyFrom(
    {$encodedFrom},
    {$encodedTo}
);
});
EOT;
            $this->form->getView()->registerJs($js);
        } elseif (is_array($this->makeSlug)) {
            $id = Html::getInputId($this->model, $this->attribute);
            $buttonId = $id . '-slugButton';
            $this->addon['append'] = ['content' => Html::button(Icon::show('code'), ['class' => 'btn btn-primary', 'id' => $buttonId]), 'asButton' => true];
            $encodedFrom = Json::encode($this->makeSlug);
            $encodedTo = Json::encode('#' . $id);
            $js = <<<EOT
\$("#{$buttonId}").click(function(){
Admin.makeSlug(
    {$encodedFrom},
    {$encodedTo}
);
});
EOT;
            $this->form->getView()->registerJs($js);
        }
        parent::init();
    }
Example #2
0
 /**
  * Initializes the form configuration array
  * and parameters for the form.
  */
 protected function initForm()
 {
     if (!isset($this->type) || strlen($this->type) == 0) {
         $this->type = self::TYPE_VERTICAL;
     }
     $this->formConfig = array_replace_recursive($this->_config[$this->type], $this->formConfig);
     if (!isset($this->fieldConfig['class'])) {
         $this->fieldConfig['class'] = ActiveField::className();
     }
     $this->_inputCss = self::NOT_SET;
     $this->_offsetCss = self::NOT_SET;
     $class = 'form-' . $this->type;
     /* Fixes the button alignment for inline forms containing error block */
     if ($this->type === self::TYPE_INLINE && $this->formConfig['showErrors']) {
         $class .= ' ' . $class . '-block';
     }
     if ($this->type === self::TYPE_HORIZONTAL) {
         $class .= ' kv-form-horizontal';
     }
     Html::addCssClass($this->options, $class);
 }
Example #3
0
 /**
  * Parses and returns addon content
  *
  * @param string|array $addon the addon parameter
  * @param string $type type of addon append or prepend
  * @param boolean $devTidy [optional] should debug tidy up be performed
  * @param boolean $hasInputGroup [optional] if $type = 'icon' does addon also have prepend and/or append
  * @return string
  */
 public function getLocalAddonContent($addon, $type = '', $devTidy = false, $hasInputGroup = false)
 {
     if (is_array($addon) && $type != '') {
         $content = ArrayHelper::getValue($addon, 'content', '');
         $asButton = ArrayHelper::getValue($addon, 'asButton', false);
         if ($asButton) {
             $options = ArrayHelper::getValue($addon, 'options', []);
             $tag = ArrayHelper::getValue($options, 'tag', 'span');
             unset($options['tag']);
             if ($type == 'prepend') {
                 Html::addCssClass($options, 'input-group-addon');
             } else {
                 Html::addCssClass($options, 'input-group-btn');
             }
             $content = Html::tag($tag, "\n\t\t\t\t" . $content . "\n\t\t\t", $options);
         } elseif ($type == 'prepend') {
             $options = ArrayHelper::getValue($addon, 'options', []);
             $tag = ArrayHelper::getValue($options, 'tag', 'span');
             unset($options['tag']);
             Html::addCssClass($options, 'input-group-addon');
             $content = Html::tag($tag, "\n\t\t\t\t" . $content . "\n\t\t\t", $options);
         }
         if ($devTidy) {
             if ($content != '' && ArrayHelper::getValue($addon, 'tidy', true)) {
                 if ($type == 'append') {
                     $content = "\n\t\t\t" . $content;
                 } elseif ($type == 'icon' && $hasInputGroup) {
                     $content = "\n\t\t\t\t" . $content . "\n\t\t\t\t";
                 } else {
                     $content = "\n\t\t\t" . $content . "\n\t\t\t";
                 }
             }
         }
         return $content;
     }
     return parent::getAddonContent($addon);
 }
Example #4
-1
    public function init()
    {
        $fields = ['copyFrom' => ['buttonIdSuffix' => '-copyButton', 'buttonIcon' => 'code', 'jsMethodName' => 'Admin.copyFrom'], 'makeSlug' => ['buttonIdSuffix' => '-slugButton', 'buttonIcon' => 'code', 'jsMethodName' => 'Admin.makeSlug'], 'makeKey' => ['buttonIdSuffix' => '-keyButton', 'buttonIcon' => 'code', 'jsMethodName' => 'Admin.makeKey']];
        foreach ($fields as $fieldName => $params) {
            if (true === is_array($this->{$fieldName})) {
                $id = Html::getInputId($this->model, $this->attribute);
                $buttonId = $id . $params['buttonIdSuffix'];
                $this->addon['append'] = ['content' => Html::button(Icon::show($params['buttonIcon']), ['class' => 'btn btn-primary', 'id' => $buttonId]), 'asButton' => true];
                $encodedFrom = Json::encode($this->{$fieldName});
                $encodedTo = Json::encode('#' . $id);
                $js = <<<EOT
\$("#{$buttonId}").click(function() {
    {$params['jsMethodName']}({$encodedFrom}, {$encodedTo});
});
EOT;
                $this->form->getView()->registerJs($js);
            }
        }
        parent::init();
    }