Beispiel #1
0
 /**
  * ### .run()
  *
  * Widget's run function
  */
 public function run()
 {
     list($name, $id) = $this->resolveNameID();
     $this->registerClientScript($id);
     $this->htmlOptions['id'] = $id;
     $this->htmlOptions['readonly'] = "readonly";
     $radius = $this->displayInput ? "" : "border-radius:4px;";
     // Do we have a model?
     echo '<div class="input-append color"  data-color="' . $this->value . '" data-color-format="rgb" id="' . $id . '_color">';
     if ($this->hasModel()) {
         if ($this->form) {
             if ($this->displayInput) {
                 echo $this->form->textField($this->model, $this->attribute, $this->htmlOptions);
             } else {
                 echo $this->form->hiddenField($this->model, $this->attribute, $this->htmlOptions);
             }
         } else {
             if ($this->displayInput) {
                 echo CHtml::activeTextField($this->model, $this->attribute, $this->htmlOptions);
             } else {
                 echo CHtml::activeHiddenField($this->model, $this->attribute, $this->htmlOptions);
             }
         }
     } else {
         if ($this->displayInput) {
             echo CHtml::textField($name, $this->value, $this->htmlOptions);
         } else {
             echo CHtml::hiddenField($name, $this->value, $this->htmlOptions);
         }
     }
     echo '<span class="add-on" style="' . $radius . '"><i style="background-color: ' . $this->value . '"></i></span></div>';
 }
 /**
  * Capture the latitude and longitude of the marker to a model.
  * 
  * @param CModel $model Model object
  * @param string $lat Attribute name for latitude
  * @param string $lng Attribute name for longitude
  * @param array $options Options to set :<ul>
  * <li>'visible' - show the input fields
  * <li>'nocallback' - do not update on callback
  * <li>'nodragend' - do not update on dragend
  * <li>'drag' - update on drag
  * </ul>
  */
 public function capturePosition(CModel $model, $lat, $lng, array $options = array())
 {
     // field options
     if (in_array('visible', $options)) {
         echo CHtml::activeLabelEx($model, $lat), CHtml::activeTextField($model, $lat);
         echo '<br>';
         echo CHtml::activeLabelEx($model, $lng), CHtml::activeTextField($model, $lng);
     } else {
         echo CHtml::activeHiddenField($model, $lat), CHtml::activeHiddenField($model, $lng);
     }
     $latId = CHtml::activeId($model, $lat);
     $lngId = CHtml::activeId($model, $lng);
     // update function
     $jsFunction = "function captureMarkerPosition(marker){\$('#{$latId}').val(marker.getPosition().lat());\$('#{$lngId}').val(marker.getPosition().lng());}";
     Yii::app()->getClientScript()->registerScript(__CLASS__ . '#capturePosition', $jsFunction, CClientScript::POS_END);
     // event options
     if (!in_array('nocallback', $options)) {
         $this->addCallback('function(result){captureMarkerPosition(result);}');
     }
     if (!in_array('nodragend', $options)) {
         $this->addEvent('dragend', 'function(result){captureMarkerPosition(result);}');
     }
     if (in_array('drag', $options)) {
         $this->addEvent('drag', 'function(result){captureMarkerPosition(result);}');
     }
     $this->addEvent('position_changed', 'function(result){captureMarkerPosition(result);}');
 }
Beispiel #3
0
 /**
  * Renders the input file field
  */
 public function renderField()
 {
     list($name, $id) = $this->resolveNameID();
     TbArray::defaultValue('id', $id, $this->htmlOptions);
     TbArray::defaultValue('name', $name, $this->htmlOptions);
     TbHtml::addCssClass('bfh-selectbox', $this->wrapperOptions);
     echo CHtml::openTag('div', $this->wrapperOptions);
     if ($this->hasModel()) {
         echo CHtml::activeHiddenField($this->model, $this->attribute, $this->htmlOptions);
         $value = $this->model->{$this->attribute};
         $valueText = $value && isset($this->data[$value]) ? $this->data[$value] : '&nbsp;';
     } else {
         echo CHtml::hiddenField($name, $this->value, $this->htmlOptions);
         $value = $this->value;
         $valueText = $value && isset($this->data[$value]) ? $this->data[$value] : '&nbsp;';
     }
     echo CHtml::openTag('a', array('class' => 'bfh-selectbox-toggle', 'role' => 'button', 'data-toggle' => 'bfh-selectbox', 'href' => '#'));
     echo CHtml::tag('span', array('class' => 'bfh-selectbox-option ' . $this->size, 'data-option' => $value), $valueText);
     echo CHtml::tag('b', array('class' => 'caret'), '&nbsp;');
     echo CHtml::closeTag('a');
     echo CHtml::openTag('div', array('class' => 'bfh-selectbox-options'));
     if ($this->displayFilter) {
         echo '<input type="text" class="bfh-selectbox-filter">';
     }
     $items = array();
     foreach ($this->data as $key => $item) {
         $items[] = CHtml::tag('a', array('tabindex' => '-1', 'href' => '#', 'data-option' => $key), $item);
     }
     echo CHtml::tag('ul', array('role' => 'options'), '<li>' . implode('</li><li>', $items) . '</li>');
     echo CHtml::closeTag('div');
     echo CHtml::closeTag('div');
 }
 /**
  * Run this widget.
  * This method registers necessary javascript and renders the needed HTML code.
  */
 public function run()
 {
     list($name, $id) = $this->resolveNameID();
     if (isset($this->htmlOptions['id'])) {
         $id = $this->htmlOptions['id'];
     } else {
         $this->htmlOptions['id'] = $id;
     }
     if (isset($this->htmlOptions['name'])) {
         $name = $this->htmlOptions['name'];
     } else {
         $this->htmlOptions['name'] = $name;
     }
     if ($this->hasModel() === false && $this->value !== null) {
         $this->options['value'] = $this->value;
     }
     if ($this->hasModel()) {
         echo CHtml::activeHiddenField($this->model, $this->attribute, $this->htmlOptions);
     } else {
         echo CHtml::hiddenField($name, $this->value, $this->htmlOptions);
     }
     $idHidden = $this->htmlOptions['id'];
     $nameHidden = $this->htmlOptions['name'];
     $this->htmlOptions['id'] = $idHidden . '_slider';
     $this->htmlOptions['name'] = $nameHidden . '_slider';
     echo CHtml::openTag($this->tagName, $this->htmlOptions);
     echo CHtml::closeTag($this->tagName);
     $this->options[$this->event] = 'js:function(event, ui) { jQuery(\'#' . $idHidden . '\').val(ui.value); }';
     $options = empty($this->options) ? '' : CJavaScript::encode($this->options);
     $js = "jQuery('#{$id}_slider').slider({$options});\n";
     Yii::app()->getClientScript()->registerScript(__CLASS__ . '#' . $id, $js);
 }
Beispiel #5
0
 public function showLangModal()
 {
     $language = Yii::app()->params['language'];
     $this->beginWidget('bootstrap.widgets.TbModal', array('id' => $this->modalId, 'htmlOptions' => array('style' => 'margin-top:-200px;', 'backdrop' => 'static')));
     echo "<div class=\"modal-header\">\n                <h4 style=\"width:30%;display: inline-block;\">翻译</h4> \n                <span id='" . $this->modalId . "message' style=\"margin-left:30px;color:red;\"></span>\n            </div>";
     echo "<div id='" . $this->modalId . "ModalBody' class=\"modal-body\" style=\"text-align:center\">";
     $tableName = $this->model->tableName();
     $attribute = $this->attribute;
     echo CHtml::hiddenField('tableName', $tableName);
     echo CHtml::hiddenField('attribute', $attribute);
     $pk = $this->model->primaryKey;
     echo CHtml::activeHiddenField($this->model, $this->model->pk, array('name' => 'pk'));
     $result = Translation::model()->find('model=:tableName and pk=:pk and attribute=:attribute', array(':tableName' => $tableName, ':pk' => $pk, ':attribute' => $attribute));
     $data = json_decode($result->data);
     foreach ($language as $key => $value) {
         if (strtolower($key) == 'zh_cn') {
             continue;
         }
         echo "<div><span style='width:80px !important;display: inline-block;'>" . $value . '</span>' . CHtml::textField($key, $data->{$key}) . "</div>";
     }
     echo "</div>";
     echo "<div class=\"modal-footer\" style=\"text-align: center;\">";
     $this->widget('bootstrap.widgets.TbButton', array('buttonType' => 'button', 'type' => 'info', 'label' => '保存', 'htmlOptions' => array('id' => $this->modalId . 'save')));
     echo "&nbsp;";
     $this->widget('bootstrap.widgets.TbButton', array('buttonType' => 'button', 'label' => '取消', 'htmlOptions' => array("data-dismiss" => "modal", 'id' => $this->modalId . 'back')));
     echo "</div>";
     $this->endWidget();
 }
Beispiel #6
0
    public function run()
    {
        list($name, $id) = $this->resolveNameID();
        if (isset($this->htmlOptions['id'])) {
            $id = $this->htmlOptions['id'];
        } else {
            $this->htmlOptions['id'] = $id;
        }
        if (isset($this->htmlOptions['name'])) {
            $name = $this->htmlOptions['name'];
        }
        if ($this->flat === false) {
            if ($this->hasModel()) {
                echo CHtml::activeTextField($this->model, $this->attribute, $this->htmlOptions);
            } else {
                echo CHtml::textField($name, $this->value, $this->htmlOptions);
            }
        } else {
            if ($this->hasModel()) {
                echo CHtml::activeHiddenField($this->model, $this->attribute, $this->htmlOptions);
                $attribute = $this->attribute;
                $this->options['defaultDate'] = $this->model->{$attribute};
            } else {
                echo CHtml::hiddenField($name, $this->value, $this->htmlOptions);
                $this->options['defaultDate'] = $this->value;
            }
            if (!isset($this->options['onSelect'])) {
                $this->options['onSelect'] = "js:function( selectedDate ) { jQuery('#{$id}').val(selectedDate);}";
            }
            $id = $this->htmlOptions['id'] = $id . '_container';
            $this->htmlOptions['name'] = $name . '_container';
            echo CHtml::tag('div', $this->htmlOptions, '');
        }
        $this->options['beforeShowDay'] = <<<EOD
js:function(date){
\tif (typeof reservedDays !== 'undefined') {
\t\tfor (i = 0; i < reservedDays.length; i++) {
\t\t\tif (date.getFullYear() == reservedDays[i][0] && date.getMonth() == reservedDays[i][1] - 1 && date.getDate() == reservedDays[i][2])
\t\t\t{
\t\t\t\treturn [false, "datepicker-calendarDescriptionReserved"];
\t\t\t}
\t\t}
\t\treturn [true,""];
\t}
}
EOD;
        $options = CJavaScript::encode($this->options);
        $js = "jQuery('#{$id}').datepicker({$options});";
        if ($this->language != '' && $this->language != 'en') {
            $this->registerScriptFile($this->i18nScriptFile);
            $js = "jQuery('#{$id}').datepicker(jQuery.extend({showMonthAfterYear:false}, jQuery.datepicker.regional['{$this->language}'], {$options}));";
        }
        $cs = Yii::app()->getClientScript();
        if (isset($this->defaultOptions)) {
            $this->registerScriptFile($this->i18nScriptFile);
            $cs->registerScript(__CLASS__, $this->defaultOptions !== null ? 'jQuery.datepicker.setDefaults(' . CJavaScript::encode($this->defaultOptions) . ');' : '');
        }
        $cs->registerScript(__CLASS__ . '#' . $id, $js);
    }
Beispiel #7
0
 /**
  * Renders the select2 field
  */
 public function renderField()
 {
     if ($this->hasModel()) {
         echo $this->asDropDownList ? \CHtml::activeDropDownList($this->model, $this->attribute, $this->data, $this->options) : \CHtml::activeHiddenField($this->model, $this->attribute);
     } else {
         echo $this->asDropDownList ? \CHtml::dropDownList($this->options['name'], $this->value, $this->data, $this->options) : \CHtml::hiddenField($this->options['name'], $this->value);
     }
 }
Beispiel #8
0
 /**
  * Capture the map's zoom level to a field
  * 
  * @param CModel $model Model containing the attribute
  * @param string $attribute Name of the model's attribute
  * @param boolean $generate Whether to generate the field
  * @param array $htmlOptions HTML options for the field
  */
 public function captureZoom(CModel $model, $attribute, $generate = true, array $htmlOptions = array())
 {
     if ($generate) {
         echo CHtml::activeHiddenField($model, $attribute, $htmlOptions);
     }
     $attId = CHtml::activeId($model, $attribute);
     $this->addEvent('zoom_changed', "function(map){\$('#{$attId}').val(map.getZoom());}");
 }
 /**
  * Renders the widget.
  * @return void
  */
 public function run()
 {
     if ($this->hidden) {
         echo CHtml::activeHiddenField($this->model, $this->attribute, $this->htmlOptions);
     } else {
         echo CHtml::activeTextField($this->model, $this->attribute, $this->htmlOptions);
     }
 }
 public function display(array $attr = null)
 {
     if ($this->_value != "") {
         CHtml::hiddenField($this->_name, $this->_value);
     } else {
         CHtml::activeHiddenField($this->_name, $this->_model);
     }
 }
    public function run()
    {
        list($name, $id) = $this->resolveNameID();
        if (isset($this->htmlOptions['id'])) {
            $id = $this->htmlOptions['id'];
        } else {
            $this->htmlOptions['id'] = $id;
        }
        if (isset($this->htmlOptions['name'])) {
            $name = $this->htmlOptions['name'];
        } else {
            $this->htmlOptions['name'] = $name;
        }
        $contHtmlOptions = $this->htmlOptions;
        $contHtmlOptions['id'] = $id . 'container';
        echo CHtml::openTag('div', $contHtmlOptions);
        $inputOptions = array('id' => $id);
        if ($this->hasModel()) {
            echo CHtml::activeHiddenField($this->model, $this->attribute, $inputOptions);
            $imgPath = $this->model->{$this->attribute};
        } else {
            echo CHtml::hiddenField($name, $this->value, $inputOptions);
            $imgPath = $this->value;
        }
        if (!@getimagesize($imgPath)) {
            $imgPath = $this->assetsDir . '/images/no-photo.gif';
        }
        echo CHtml::image($imgPath, 'preview', array('id' => 'image-preview-' . $id, 'style' => 'max-width: 120px; max-height: 120px; display: block; margin-bottom: 10px;'));
        echo CHtml::button('Browse', array('id' => $id . 'browse', 'class' => 'btn'));
        echo CHtml::closeTag('div');
        $settings = array_merge(array('places' => "", 'rememberLastDir' => false), $this->settings);
        $settings['dialog'] = array('zIndex' => 400001, 'width' => 900, 'modal' => true, 'title' => "Files");
        $settings['editorCallback'] = 'js:function(url) {
        $(\'#\'+aFieldId).attr(\'value\',url);
        $(\'#image-preview-\'+aFieldId).attr(\'src\',url);
        }';
        $settings['closeOnEditorCallback'] = true;
        $connectorUrl = CJavaScript::encode($this->settings['url']);
        $settings = CJavaScript::encode($settings);
        $script = <<<EOD
        window.elfinderBrowse = function(field_id, connector) {
            var aFieldId = field_id, aWin = this;
            if(\$("#elFinderBrowser").length == 0) {
                \$("body").append(\$("<div/>").attr("id", "elFinderBrowser"));
                var settings = {$settings};
                settings["url"] = connector;
                \$("#elFinderBrowser").elfinder(settings);
            }
            else {
                \$("#elFinderBrowser").elfinder("open", connector);
            }
        }
EOD;
        $cs = Yii::app()->getClientScript();
        $cs->registerScript('ServerFileInput#global', $script);
        $js = '$("#' . $id . 'browse").click(function(){window.elfinderBrowse("' . $id . '", ' . $connectorUrl . ')});';
        $cs->registerScript('ServerFileInput#' . $id, $js);
    }
Beispiel #12
0
    public function run()
    {
        if ($this->selector == null) {
            list($this->name, $this->id) = $this->resolveNameId();
            $this->selector = '#' . $this->id;
            if (isset($this->htmlOptions['placeholder'])) {
                $this->options['placeholder'] = $this->htmlOptions['placeholder'];
            }
            if (!isset($this->htmlOptions['multiple'])) {
                $data = array();
                if (isset($this->options['placeholder'])) {
                    $data[''] = '';
                }
                $this->data = $data + $this->data;
            }
            if ($this->hasModel()) {
                if (isset($this->options['ajax'])) {
                    echo CHtml::activeHiddenField($this->model, $this->attribute, $this->htmlOptions);
                } else {
                    echo CHtml::activeDropDownList($this->model, $this->attribute, $this->data, $this->htmlOptions);
                }
            } elseif (!isset($this->options['ajax'])) {
                $this->htmlOptions['id'] = $this->id;
                echo CHtml::dropDownList($this->name, $this->value, $this->data, $this->htmlOptions);
            } else {
                echo CHtml::hiddenField($this->name, $this->value, $this->htmlOptions);
            }
        }
        $bu = Yii::app()->assetManager->publish(dirname(__FILE__) . '/assets/');
        $cs = Yii::app()->clientScript;
        //$cs->registerCssFile($bu . '/select2.css');
        if (YII_DEBUG) {
            $cs->registerScriptFile($bu . '/select2.js');
        } else {
            $cs->registerScriptFile($bu . '/select2.min.js');
        }
        if ($this->sortable) {
            $cs->registerCoreScript('jquery.ui');
        }
        $options = CJavaScript::encode(CMap::mergeArray($this->defaultOptions, $this->options));
        ob_start();
        echo "jQuery('{$this->selector}').select2({$options})";
        foreach ($this->events as $event => $handler) {
            echo ".on('{$event}', " . CJavaScript::encode($handler) . ")";
        }
        echo ';';
        if ($this->sortable) {
            echo <<<JavaScript
jQuery('{$this->selector}').select2("container").find("ul.select2-choices").sortable({
\tcontainment: 'parent',
\tstart: function() { jQuery('{$this->selector}').select2("onSortStart"); },
\tupdate: function() { jQuery('{$this->selector}').select2("onSortEnd"); }
});
JavaScript;
        }
        $cs->registerScript(__CLASS__ . '#' . $this->id, ob_get_clean());
    }
Beispiel #13
0
 public function run()
 {
     parent::run();
     echo CHtml::activeHiddenField($this->model, $this->attributeLat, $this->htmlOptions);
     echo CHtml::activeHiddenField($this->model, $this->attributeLon, $this->htmlOptions);
     echo CHtml::activeHiddenField($this->model, $this->attributeZoom, $this->htmlOptions);
     //        echo CHtml::activeTextField($this->model, $this->attributeLat, $this->htmlOptions);
     //        echo CHtml::activeTextField($this->model, $this->attributeLon, $this->htmlOptions);
     //        echo CHtml::activeTextField($this->model, $this->attributeZoom, $this->htmlOptions);
 }
 /**
  * Run this widget.
  * This method registers necessary javascript and renders the needed HTML code.
  */
 public function run()
 {
     list($name, $id) = $this->resolveNameID();
     if (isset($this->htmlOptions['id'])) {
         $id = $this->htmlOptions['id'];
     } else {
         $this->htmlOptions['id'] = $id;
     }
     if (isset($this->htmlOptions['name'])) {
         $name = $this->htmlOptions['name'];
     }
     if ($this->flat === false) {
         if ($this->hasModel()) {
             echo CHtml::activeTextField($this->model, $this->attribute, $this->htmlOptions);
         } else {
             echo CHtml::textField($name, $this->value, $this->htmlOptions);
         }
     } else {
         if ($this->hasModel()) {
             echo CHtml::activeHiddenField($this->model, $this->attribute, $this->htmlOptions);
             $attribute = $this->attribute;
             $this->options['defaultDate'] = $this->model->{$attribute};
         } else {
             echo CHtml::hiddenField($name, $this->value, $this->htmlOptions);
             $this->options['defaultDate'] = $this->value;
         }
         $this->options['altField'] = '#' . $id;
         $id = $this->htmlOptions['id'] = $id . '_container';
         $this->htmlOptions['name'] = $name . '_container';
         echo CHtml::tag('div', $this->htmlOptions, '');
     }
     $options = CJavaScript::encode($this->options);
     $js = "jQuery('#{$id}').datetimepicker({$options});";
     $assetsDir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'assets';
     $assets = Yii::app()->assetManager->publish($assetsDir);
     $i18nScriptFile = 'jquery-ui-timepicker-' . $this->language . '.js';
     $i18nScriptPath = $assetsDir . DIRECTORY_SEPARATOR . 'localization' . DIRECTORY_SEPARATOR . $i18nScriptFile;
     $cs = Yii::app()->clientScript;
     $cs->registerScriptFile($assets . '/jquery-ui-timepicker-addon.js', CClientScript::POS_END);
     if ($this->language != '' && $this->language != 'en') {
         $this->registerScriptFile($this->i18nScriptFile);
         if (file_exists($i18nScriptPath)) {
             $cs->registerScriptFile($assets . '/localization/' . $i18nScriptFile, CClientScript::POS_END);
         }
         $js = "jQuery('#{$id}').datetimepicker(jQuery.extend(jQuery.datepicker.regional['{$this->language}'], {$options}));";
     }
     if (isset($this->defaultOptions)) {
         $this->registerScriptFile($this->i18nScriptFile);
         if (file_exists($i18nScriptPath)) {
             $cs->registerScriptFile($assets . '/localization/' . $i18nScriptFile, CClientScript::POS_END);
         }
         $cs->registerScript(__CLASS__, $this->defaultOptions !== null ? 'jQuery.datetimepicker.setDefaults(' . CJavaScript::encode($this->defaultOptions) . ');' : '');
     }
     $cs->registerScript(__CLASS__ . '#' . $id, $js);
 }
Beispiel #15
0
 /**
  * Renders the select2 field
  */
 public function renderField()
 {
     list($name, $id) = $this->resolveNameID();
     TbArray::defaultValue('id', $id, $this->htmlOptions);
     TbArray::defaultValue('name', $name, $this->htmlOptions);
     if ($this->hasModel()) {
         echo $this->asDropDownList ? CHtml::activeDropDownList($this->model, $this->attribute, $this->data, $this->htmlOptions) : CHtml::activeHiddenField($this->model, $this->attribute);
     } else {
         echo $this->asDropDownList ? CHtml::dropDownList($this->name, $this->value, $this->data, $this->htmlOptions) : CHtml::hiddenField($this->name, $this->value);
     }
 }
 /**
  *### .run()
  *
  * Runs the widget.
  */
 public function run()
 {
     list($name, $id) = $this->resolveNameID();
     //start buffering the input field
     ob_start();
     if ($this->hasModel()) {
         if ($this->form) {
             if ($this->hidden) {
                 echo $this->form->hiddenField($this->model, $this->attribute, $this->htmlOptions);
             } else {
                 echo $this->form->textField($this->model, $this->attribute, $this->htmlOptions);
             }
         } else {
             if ($this->hidden) {
                 echo CHtml::activeHiddenField($this->model, $this->attribute, $this->htmlOptions);
             } else {
                 echo CHtml::activeTextField($this->model, $this->attribute, $this->htmlOptions);
             }
         }
     } else {
         if ($this->hidden) {
             echo CHtml::hiddenField($name, $this->value, $this->htmlOptions);
         } else {
             echo CHtml::textField($name, $this->value, $this->htmlOptions);
         }
     }
     $field = ob_get_clean();
     //checks the inline option
     if ($this->inline) {
         //sets the default inline options
         $inlineOptions = array('linkField' => $id, 'linkFormat' => 'yyyy-mm-dd hh:ii');
         if (empty($this->options)) {
             $this->options = $inlineOptions;
         } else {
             //merge the options if we have one
             $this->options = CMap::mergeArray($this->options, $inlineOptions);
         }
         //sets the id to another element, so the widget will be rendered on this element instead of the input field
         $id = 'inline-' . $id;
         //creates the date time picker container to be rendered and passes in the input field as a child
         echo CHtml::tag('div', array('id' => $id), $field, true);
     } else {
         echo $field;
     }
     $this->registerClientScript();
     $this->registerLanguageScript();
     $options = !empty($this->options) ? CJavaScript::encode($this->options) : '';
     ob_start();
     echo "jQuery('#{$id}').datetimepicker({$options})";
     foreach ($this->events as $event => $handler) {
         echo ".on('{$event}', " . CJavaScript::encode($handler) . ")";
     }
     Yii::app()->getClientScript()->registerScript(__CLASS__ . '#' . $this->getId(), ob_get_clean() . ';');
 }
 public function getField($widgetId, $rowGroupName = '', $rowIndex, $model, $attribute, $name, $value = '', $fieldClassName = '', $htmlOptions = array(), $hasError = false, $data = '', $params = '')
 {
     if ($hasError) {
         $fieldClassName = $fieldClassName . ' ' . CHtml::$errorCss;
     }
     $htmlOptions = ClonnableFields::addClass($htmlOptions, $fieldClassName);
     $htmlOptions['style'] = 'display:none';
     if (ClonnableFields::isModel($model)) {
         return CHtml::activeHiddenField($model, $attribute, $htmlOptions);
     } else {
         return CHtml::hiddenField($name, $value, $htmlOptions);
     }
 }
Beispiel #18
0
 public function getField($widgetId, $rowGroupName = '', $rowIndex, $model, $attribute, $name, $value = '', $fieldClassName = '', $htmlOptions = array(), $hasError = false, $data = '', $params = '')
 {
     if ($hasError) {
         $fieldClassName = $fieldClassName . ' ' . CHtml::$errorCss;
     }
     $htmlOptions = ClonnableFields::addClass($htmlOptions, $fieldClassName);
     $asDropDownList = isset($params['asDropDownList']) && $params['asDropDownList'] ? true : false;
     if (ClonnableFields::isModel($model)) {
         return $asDropDownList ? CHtml::activeDropDownList($model, $attribute, $data, $htmlOptions) : CHtml::activeHiddenField($model, $attribute, $htmlOptions);
     } else {
         return $asDropDownList ? CHtml::dropDownList($name, $value, $data, $htmlOptions) : CHtml::hiddenField($name, $value, $htmlOptions);
     }
 }
Beispiel #19
0
 /**
  * Runs the widget.
  */
 public function run()
 {
     list($name, $id) = $this->resolveNameID();
     if ($this->hasModel()) {
         if ($this->form) {
             echo $this->asDropDownList ? $this->form->dropDownList($this->model, $this->attribute, $this->data, $this->htmlOptions) : $this->form->hiddenField($this->model, $this->attribute);
         } else {
             echo $this->asDropDownList ? CHtml::activeDropDownList($this->model, $this->attribute, $this->data, $this->htmlOptions) : CHtml::activeHiddenField($this->model, $this->attribute);
         }
     } else {
         echo $this->asDropDownList ? CHtml::dropDownList($name, $this->value, $this->data, $this->htmlOptions) : CHtml::hiddenField($name, $this->value);
     }
     $this->registerClientScript($id);
 }
Beispiel #20
0
 function run()
 {
     if ($this->hasModel()) {
         // required!
         $this->htmlOptions['autocomplete'] = 'off';
         echo CHtml::textField($this->attribute, $this->value, $this->htmlOptions);
         echo CHtml::activeHiddenField($this->model, $this->attribute);
         echo '<span class="help-block">' . Yii::t('common', '(Autocomplete)') . '</span>';
         $this->registerScript();
     } else {
         // TODO: extend widget to support non-active input
         throw new CException(Yii::t('errors', 'TypeaheadSingle doesn\'t support non-active records. Please add a model attribute to the widget to use.'));
     }
 }
    public function actionCrop()
    {

        print_r($_POST);
        exit;

        $name = $_POST['nameFull'];
        $fullImagePath = Yii::getPathOfAlias('webroot.uploads.news.full').DIRECTORY_SEPARATOR.$name;
        $quality = 100;

        $fullImg = getimagesize($fullImagePath);
        switch(strtolower($fullImg['mime']))
        {
            case 'image/png':
                $source_image = imagecreatefrompng($fullImagePath);
                $type = 'png';
                $quality = 0;
                break;
            case 'image/jpeg':
                $source_image = imagecreatefromjpeg($fullImagePath);
                $type = 'jpeg';
                break;
            case 'image/gif':
                $source_image = imagecreatefromgif($fullImagePath);
                $type = 'gif';
                break;
            default: die('image type not supported');
        }
        $function = 'image'.$type;

        $resizeImage = imagecreatetruecolor(324, 230); //$_POST['h'], $_POST['h']

        $src_x = $_POST['x'];
        $src_y = $_POST['y'];
        $dst_y = 0;
        $dst_x = 0;
        $dst_w = $_POST['w'];
        $dst_h = $_POST['h'];

        imagecopyresampled($resizeImage,$source_image, 0, 0, $src_x, $src_y,
            324, 230, $dst_w, $dst_h);

        $function($resizeImage, Yii::getPathOfAlias('webroot.uploads.news.thumb').DIRECTORY_SEPARATOR.$name, $quality);
        $model = new News();
        echo CHtml::image(Yii::app()->baseUrl.'/uploads/news/full/'.$name);
        echo CHtml::image(Yii::app()->baseUrl.'/uploads/news/thumb/'.$name);
        echo CHtml::activeHiddenField($model, 'image', array('value'=>$name));


    }
 public function run()
 {
     list($name, $id) = $this->resolveNameID();
     if (isset($this->htmlOptions['id'])) {
         $id = $this->htmlOptions['id'];
     } else {
         $this->htmlOptions['id'] = $id;
     }
     if (isset($this->htmlOptions['name'])) {
         $name = $this->htmlOptions['name'];
     } else {
         $this->htmlOptions['name'] = $name;
     }
     $this->options['maxDate'] = date('d') . "-" . date('m') . "-" . date('Y');
     if ($this->flat === false) {
         if ($this->hasModel()) {
             echo CHtml::activeTextField($this->model, $this->attribute, $this->htmlOptions);
         } else {
             echo CHtml::textField($name, $this->value, $this->htmlOptions);
         }
     } else {
         if ($this->hasModel()) {
             echo CHtml::activeHiddenField($this->model, $this->attribute, $this->htmlOptions);
             $attribute = $this->attribute;
             $this->options['defaultDate'] = $this->model->{$attribute};
         } else {
             echo CHtml::hiddenField($name, $this->value, $this->htmlOptions);
             $this->options['defaultDate'] = $this->value;
         }
         if (!isset($this->options['onSelect'])) {
             $this->options['onSelect'] = "js:function( selectedDate ) { jQuery('#{$id}').val(selectedDate);}";
         }
         $id = $this->htmlOptions['id'] = $this->htmlOptions['id'] . '_container';
         $this->htmlOptions['name'] = $this->htmlOptions['name'] . '_container';
         echo CHtml::tag('div', $this->htmlOptions, '');
     }
     $options = CJavaScript::encode($this->options);
     $js = "jQuery('#{$id}').datepicker({$options});";
     if ($this->language != '' && $this->language != 'en') {
         $this->registerScriptFile($this->i18nScriptFile);
         $js = "jQuery('#{$id}').datepicker(jQuery.extend({showMonthAfterYear:false}, jQuery.datepicker.regional['{$this->language}'], {$options}));";
     }
     $cs = Yii::app()->getClientScript();
     if (isset($this->defaultOptions)) {
         $this->registerScriptFile($this->i18nScriptFile);
         $cs->registerScript(__CLASS__, $this->defaultOptions !== null ? 'jQuery.datepicker.setDefaults(' . CJavaScript::encode($this->defaultOptions) . ');' : '');
     }
     $cs->registerScript(__CLASS__ . '#' . $id, $js);
 }
Beispiel #23
0
    public function run()
    {
        $this->name = get_class($this->model) . '[' . $this->attribute . ']';
        $ok = $this->attribute;
        $this->value = $this->model->{$ok};
        $session = new CHttpSession();
        $session->open();
        $session['KCFINDER'] = array('disabled' => false, 'uploadURL' => "/userfiles/editor/", 'uploadDir' => $_SERVER['DOCUMENT_ROOT'] . "/userfiles/editor/");
        ?>
	 
        <div class="image" id="image_<?php 
        echo $this->attribute;
        ?>
" onclick="openKCFinder(this,'<?php 
        echo $this->kcFinderPath;
        ?>
','<?php 
        echo $this->attribute;
        ?>
')">
            <?php 
        if (empty($this->value)) {
            ?>
                <div style="margin:2px"><i>Кликните для выбора изображения</i></div>
            <?php 
        } else {
            ?>
                <img id="img_<?php 
            echo $this->attribute;
            ?>
" class="saved" src="/userfiles/small/<?php 
            echo $this->value;
            ?>
" />
                <?php 
        }
        ?>
        </div>
        <a href="#" onclick="return dellPhoto('<?php 
        echo $this->attribute;
        ?>
');">удалить фото</a>
   	<?php 
        echo CHtml::activeHiddenField($this->model, $this->attribute, array('id' => 'imghiddenfield_' . $this->attribute));
    }
Beispiel #24
0
 /**
  * Run this widget.
  * This method registers necessary javascript and renders the needed HTML code.
  */
 public function run()
 {
     list($name, $id) = $this->resolveNameID();
     // Get ID Attribute of actual hidden field containing selected value
     $attr_id = get_class($this->model) . '_' . $this->attribute;
     if (isset($this->htmlOptions['id'])) {
         $id = $this->htmlOptions['id'];
     } else {
         $this->htmlOptions['id'] = $id;
     }
     if (isset($this->htmlOptions['name'])) {
         $name = $this->htmlOptions['name'];
     }
     if ($this->hasModel()) {
         echo CHtml::textField($name, $this->value, $this->htmlOptions);
         echo CHtml::activeHiddenField($this->model, $this->attribute);
     } else {
         echo CHtml::textField($name, $this->value, $this->htmlOptions);
         CHtml::hiddenField($name, $this->value, $this->htmlOptions);
     }
     if ($this->sourceUrl !== null) {
         $this->options['source'] = CHtml::normalizeUrl($this->sourceUrl);
     } else {
         $this->options['source'] = $this->source;
     }
     // Modify Focus Event to show label in text field instead of value
     if (!isset($this->options['focus'])) {
         $this->options['focus'] = 'js:function(event, ui) {
       $("#' . $id . '").val(ui.item.label);
       return false;
     }';
     }
     if (!isset($this->options['select'])) {
         $this->options['select'] = 'js:function(event, ui) {
         $("#' . $id . '").val(ui.item.label);
         $("#' . $attr_id . '").val(ui.item.id);
     }';
     }
     $options = CJavaScript::encode($this->options);
     //$options = $this->options;
     $js = "jQuery('#{$id}').autocomplete({$options});";
     $cs = Yii::app()->getClientScript();
     $cs->registerScript(__CLASS__ . '#' . $id, $js);
 }
 /**
  * inherit in CJuiDatePicker concept
  */
 public function run()
 {
     list($name, $id) = $this->resolveNameID();
     if (isset($this->htmlOptions['id'])) {
         $id = $this->htmlOptions['id'];
     } else {
         $this->htmlOptions['id'] = $id;
     }
     if (isset($this->htmlOptions['name'])) {
         $name = $this->htmlOptions['name'];
     }
     if ($this->flat === false) {
         if ($this->hasModel()) {
             echo CHtml::activeTextField($this->model, $this->attribute, $this->htmlOptions);
             $attribute = $this->attribute;
         } else {
             echo CHtml::textField($name, $this->value, $this->htmlOptions);
         }
     } else {
         if ($this->hasModel()) {
             echo CHtml::activeHiddenField($this->model, $this->attribute, $this->htmlOptions);
             $attribute = $this->attribute;
             $this->options['defaultValue'] = $this->model->{$attribute};
         } else {
             echo CHtml::hiddenField($name, $this->value, $this->htmlOptions);
             $this->options['defaultValue'] = $this->value;
         }
         if (!isset($this->options['onSelect'])) {
             $this->options['onSelect'] = new CJavaScriptExpression("function( selectedDateTime ) { jQuery('#{$id}').val(selectedDateTime);}");
         }
         $id = $this->htmlOptions['id'] = $id . '_container';
         $this->htmlOptions['name'] = $name . '_container';
         echo CHtml::tag('div', $this->htmlOptions, '');
     }
     $this->registerSliderAccess();
     $options = CJavaScript::encode($this->options);
     $js = "jQuery('#{$id}').{$this->type}picker({$options});";
     $this->registeri18nFile();
     $cs = Yii::app()->getClientScript();
     $cs->registerScript(__CLASS__ . '#' . $id, $js);
 }
Beispiel #26
0
 /**
  * Executes the widget.
  * This method registers all needed client scripts and renders
  * the text field.
  */
 public function run()
 {
     list($name, $id) = $this->resolveNameID();
     if (!isset($this->htmlOptions['id'])) {
         $this->htmlOptions['id'] = $id;
     }
     if (!isset($this->htmlOptions['name'])) {
         $this->htmlOptions['name'] = $name;
     }
     $this->registerClientScript();
     if ($this->hasModel()) {
         $value = $this->model->{$this->attribute};
         echo CHtml::activeHiddenField($this->model, $this->attribute);
     } else {
         $value = $this->value;
         echo CHtml::hiddenField($this->htmlOptions['name'], $this->value);
     }
     $htmlOptions = $this->htmlOptions;
     unset($htmlOptions['id'], $htmlOptions['name']);
     echo CHtml::textField('intl-phone-input', $value, $htmlOptions);
 }
Beispiel #27
0
 public function run()
 {
     list($name, $id) = $this->resolveNameID();
     if (isset($this->htmlOptions['id'])) {
         $id = $this->htmlOptions['id'];
     } else {
         $this->htmlOptions['id'] = $id;
     }
     if (isset($this->htmlOptions['name'])) {
         $name = $this->htmlOptions['name'];
     } else {
         $this->htmlOptions['name'] = $name;
     }
     if (isset($this->size)) {
         $this->htmlOptions['size'] = $this->size;
     }
     $this->registerClientScript();
     if ($this->hasModel()) {
         echo CHtml::activeHiddenField($this->model, $this->attribute, $this->htmlOptions);
     } else {
         echo CHtml::hiddenField($name, $this->value, $this->htmlOptions);
     }
     $value = $this->hasModel() ? $this->model->{$this->attribute} : $this->value;
     $title = $value == 0 ? '' : Page::model()->findByPk($value)->title;
     $options = $this->htmlOptions;
     $options['id'] .= '_title';
     $options['readonly'] = true;
     unset($options['name']);
     echo '<div style="white-space:nowrap;">';
     if (!$this->multiple) {
         if ($this->hasModel() && $this->model->id == 1 && $this->attribute == 'parent_id') {
             echo Yii::t('cms', 'this is a home page');
         } else {
             echo CHtml::textField('', $title, $options);
         }
     }
     //echo $this->render('application.views.page.tree', array('tree' => Page::model()->getTree($this->model->id)), true);
     echo "</div><div style='border:1px solid gray;background:white;width:{$this->width}px;height:{$this->height}px;overflow:scroll;" . (!$this->multiple ? "position:absolute;display:none;" : "") . "' id='" . $this->htmlOptions['id'] . "_dialog'></div>";
 }
 /**
  * Runs the widget.
  */
 public function run()
 {
     list($name, $id) = $this->resolveNameID();
     $required = false;
     foreach ($this->model->getValidators($this->attribute) as $validator) {
         if ($validator instanceof CRequiredValidator && in_array($this->attribute, $validator->attributes)) {
             $required = true;
             break;
         }
     }
     if ($this->type == 'embedded') {
         $idEmbeddedContainer = $this->id . '_container';
         echo CHtml::tag('div', ['id' => $idEmbeddedContainer], false, false);
         echo CHtml::activeHiddenField($this->model, $this->attribute);
         if (array_key_exists('changeDate', $this->events)) {
             $this->events['changeDate'] = substr($this->events['changeDate'], 0, -1);
         } else {
             $this->events['changeDate'] = 'js:function(e)  {';
         }
         $this->events['changeDate'] .= 'dates = $("#' . $idEmbeddedContainer . '").datepicker(\'getFormattedDate\', \'' . $this->options['format'] . '\');';
         $this->events['changeDate'] .= '$("#' . $id . '").val(dates);';
         $this->events['changeDate'] .= '}';
         echo CHtml::closeTag('div');
         $this->registerClientScript($idEmbeddedContainer);
     } else {
         // default 'text'
         $classErrorDiv = ($error = $this->model->getError($this->attribute)) ? 'has-error' : '';
         echo CHtml::tag('div', ['class' => 'form-group ' . $classErrorDiv], false, false);
         echo CHtml::activeLabel($this->model, $this->attribute, ['class' => 'control-label', 'required' => $required]);
         echo CHtml::tag('div', [], false, false);
         echo CHtml::activeTextField($this->model, $this->attribute, ['class' => 'form-control', 'placeholder' => isset($this->htmlOptions['placeholder']) ? $this->htmlOptions['placeholder'] : $this->model->getAttributeLabel($this->attribute), 'name' => $name, 'id' => $id]);
         if (!empty($classErrorDiv)) {
             echo CHtml::tag('p', ['class' => 'help-block'], $error);
         }
         echo CHtml::closeTag('div');
         echo CHtml::closeTag('div');
         $this->registerClientScript($id);
     }
 }
 public function run()
 {
     list($name, $id) = $this->resolveNameID();
     if (!isset($this->htmlOptions['id'])) {
         $this->htmlOptions['id'] = $id;
     }
     if (!isset($this->htmlOptions['name'])) {
         $this->htmlOptions['name'] = $name;
     }
     $this->registerClientScript();
     $value = $this->hasModel() ? $this->model->{$this->attribute} : $this->value;
     $dateTimeFormat = $this->dateFormat . (empty($this->timeFormat) ? '' : $this->separator . $this->timeFormat);
     if (empty($value) || $value == preg_replace('/\\w/', '0', $dateTimeFormat)) {
         $date = $this->dateFormat;
         empty($this->timeFormat) or $time = $this->timeFormat;
         $value = null;
     } else {
         $timestamp = CDateTimeParser::parse($value, $dateTimeFormat) or $timestamp = 0;
         $formatter = Yii::app()->getDateFormatter();
         $value = $formatter->format($dateTimeFormat, $timestamp);
         $date = $formatter->format($this->dateFormat, $timestamp);
         empty($this->timeFormat) or $time = $formatter->format($this->timeFormat, $timestamp);
     }
     $divOptions = $this->htmlOptions;
     unset($divOptions['name']);
     echo CHtml::openTag('div', $divOptions);
     if ($this->hasModel()) {
         $this->model->{$this->attribute} = $value;
         echo CHtml::activeHiddenField($this->model, $this->attribute);
     } else {
         echo CHtml::hiddenField($this->attribute, $value);
     }
     echo CHtml::textField($this->attribute, $date, array('size' => strlen($this->dateFormat), 'maxlength' => strlen($this->dateFormat)));
     if (!empty($this->timeFormat)) {
         echo CHtml::textField($this->attribute, $time, array('size' => strlen($this->timeFormat), 'maxlength' => strlen($this->timeFormat)));
     }
     echo CHtml::closeTag('div');
 }
 /**
  * Runs the widget.
  */
 public function run()
 {
     if (!isset($this->uploadFolder) || !isset($this->uploadActionUrl) || !isset($this->cropActionUrl)) {
         throw new CException("uploadFolder, uploadActionUrl, and cropActionUrl are required.");
     }
     list($name, $id) = $this->resolveNameID();
     $imagePath = $this->value;
     $imageTag = '';
     if ($this->hasModel()) {
         if ($this->form) {
             $content = $this->form->hiddenField($this->model, $this->attribute, $this->htmlOptions);
         } else {
             $content = CHtml::activeHiddenField($this->model, $this->attribute, $this->htmlOptions);
         }
         $imagePath = CHtml::resolveValue($this->model, $this->attribute);
         if (isset($this->model->attributes[$this->existingFileAttribute])) {
             if ($this->model->attributes[$this->existingFileAttribute] != '') {
                 if (isset($this->existingFileAttribute)) {
                     $imagePath = CHtml::resolveValue($this->model, $this->existingFileAttribute);
                 }
                 if (isset($this->existingFileFolder) && ($imagePath != null && $imagePath != '')) {
                     $imagePath = $this->existingFileFolder . '/' . $imagePath;
                 }
             }
         }
     } else {
         $content = CHtml::hiddenField($name, $this->value, $this->htmlOptions);
     }
     if ($imagePath != null && $imagePath != '') {
         $imageTag = CHtml::image($imagePath . '?_=' . time());
     }
     $content .= CHtml::tag('div', array('id' => $id . $this->uploadIdPostFix), '', true);
     $content .= CHtml::tag('div', array('id' => $id . $this->imageIdPostFix), $imageTag, true);
     echo CHtml::tag($this->tag, $this->tagHtmlOptions, $content, true);
     $this->registerClientScript($id);
 }