Exemplo n.º 1
2
 /**
  * @inheritdoc
  */
 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->type == static::TYPE_TEXT) {
         if ($this->hasModel()) {
             echo \CHtml::activeTextField($this->model, $this->attribute, $this->htmlOptions);
         } else {
             echo \CHtml::textField($name, $this->value, $this->htmlOptions);
         }
     } elseif ($this->type == static::TYPE_SELECT) {
         if ($this->hasModel()) {
             echo \CHtml::activeDropDownList($this->model, $this->attribute, $this->data, $this->htmlOptions);
         } else {
             echo \CHtml::dropDownList($name, $this->value, $this->data, $this->htmlOptions);
         }
     } else {
         throw new \CException("Invalid field type '{$this->type}'");
     }
     $options = !empty($this->options) ? \CJavaScript::encode($this->options) : '';
     $script = "jQuery('#{$id}').select2({$options})";
     foreach ($this->events as $event => $handler) {
         $script .= ".on('{$event}'," . \CJavaScript::encode($handler) . ")";
     }
     $script .= ';';
     \Yii::app()->clientScript->registerScript(__CLASS__ . '#' . $this->getId(), $script);
     $this->registerAssets();
 }
Exemplo n.º 2
1
 public function textField($model, $attribute, $htmlOptions = array())
 {
     if (empty($htmlOptions['class'])) {
         $htmlOptions['class'] = 't_input';
     }
     return CHtml::activeTextField($model, $attribute, $htmlOptions);
 }
Exemplo n.º 3
1
 /**
  * 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()) {
         echo CHtml::activeTextField($this->model, $this->attribute, $this->htmlOptions);
     } else {
         echo CHtml::textField($name, $this->value, $this->htmlOptions);
     }
     $options = CJavaScript::encode($this->options);
     $js = "jQuery('#{$id}').datepicker({$options});";
     if (isset($this->language)) {
         $this->registerScriptFile($this->i18nScriptFile);
         $js = "jQuery('#{$id}').datepicker(jQuery.extend({showMonthAfterYear:false}, jQuery.datepicker.regional['{$this->language}'], {$options}));";
     }
     $cs = Yii::app()->getClientScript();
     $cs->registerScript(__CLASS__, $this->defaultOptions ? 'jQuery.datepicker.setDefaults(' . CJavaScript::encode($this->defaultOptions) . ');' : '');
     $cs->registerScript(__CLASS__ . '#' . $id, $js);
 }
Exemplo n.º 4
0
 /**
  * Run this widget.
  * This method registers necessary CSS and JS files and renders the needed JS and 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->hasModel()) {
         echo CHtml::activeTextField($this->model, $this->attribute, $this->htmlOptions);
     } else {
         echo CHtml::textField($name, $this->value, $this->htmlOptions);
     }
     $options = CJavaScript::encode($this->options);
     $js = "jQuery('#{$id}').tagit({$options});";
     $assets = CHtml::asset(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'assets');
     $cs = Yii::app()->getClientScript();
     $cs->registerCssFile($assets . '/jquery.tagit.css');
     $cs->registerScriptFile($assets . '/tag-it.js', CClientScript::POS_END);
     // Position is important here!
     $cs->registerScript(__CLASS__ . '#' . $id, $js);
 }
Exemplo n.º 5
0
 public function renderLink($field, array $htmlOptions = array())
 {
     $fieldName = $field->fieldName;
     $linkId = '';
     $name = '';
     $linkSource = null;
     // TODO: move this code and duplicate code in X2Model::renderModelInput into a helper
     // method. Might be able to use X2Model::getLinkedModel.
     if (class_exists($field->linkType)) {
         if (!empty($this->owner->{$fieldName})) {
             list($name, $linkId) = Fields::nameAndId($this->owner->{$fieldName});
             $linkModel = X2Model::getLinkedModelMock($field->linkType, $name, $linkId, true);
         } else {
             $linkModel = X2Model::model($field->linkType);
         }
         if ($linkModel instanceof X2Model && $linkModel->asa('X2LinkableBehavior') instanceof X2LinkableBehavior) {
             $linkSource = Yii::app()->controller->createAbsoluteUrl($linkModel->autoCompleteSource);
             $linkId = $linkModel->id;
             $oldLinkFieldVal = $this->owner->{$fieldName};
             $this->owner->{$fieldName} = $name;
         }
     }
     $input = CHtml::hiddenField($field->modelName . '[' . $fieldName . '_id]', $linkId, array());
     $input .= CHtml::activeTextField($this->owner, $field->fieldName, array_merge(array('title' => $field->attributeLabel, 'data-x2-link-source' => $linkSource, 'class' => 'x2-mobile-autocomplete', 'autocomplete' => 'off'), $htmlOptions));
     return $input;
 }
Exemplo n.º 6
0
 /**
  *### .run()
  *
  * Runs the widget.
  */
 public function run()
 {
     if ($this->selector) {
         Yii::app()->bootstrap->registerDateRangePlugin($this->selector, $this->options, $this->callback);
     } else {
         list($name, $id) = $this->resolveNameID();
         if ($this->hasModel()) {
             if ($this->form) {
                 echo $this->form->textField($this->model, $this->attribute, $this->htmlOptions);
             } else {
                 echo CHtml::activeTextField($this->model, $this->attribute, $this->htmlOptions);
             }
         } else {
             echo CHtml::textField($name, $this->value, $this->htmlOptions);
         }
         if (!isset($this->options['format'])) {
             $this->options['format'] = 'yyyy-MM-dd';
         }
         if (!isset($this->options['locale']['applyLabel'])) {
             $this->options['locale']['applyLabel'] = '应用';
         }
         if (!isset($this->options['locale']['clearLabel'])) {
             $this->options['locale']['clearLabel'] = '清空';
         }
         if (!isset($this->options['locale']['fromLabel'])) {
             $this->options['locale']['fromLabel'] = '从';
         }
         if (!isset($this->options['locale']['toLabel'])) {
             $this->options['locale']['toLabel'] = '至';
         }
         $this->setLocaleSettings();
         Yii::app()->bootstrap->registerDateRangePlugin('#' . $id, $this->options, $this->callback);
     }
 }
 /**
  * @inheritdoc
  */
 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->hasModel()) {
         echo \CHtml::activeTextField($this->model, $this->attribute, $this->htmlOptions);
     } else {
         echo \CHtml::textField($name, $this->value, $this->htmlOptions);
     }
     $options = !empty($this->options) ? \CJavaScript::encode($this->options) : '';
     $script = "jQuery('#{$id}').datetimepicker({$options})";
     foreach ($this->events as $event => $handler) {
         $script .= ".on('{$event}'," . \CJavaScript::encode($handler) . ")";
     }
     $script .= ';';
     \Yii::app()->clientScript->registerScript(__CLASS__ . '#' . $this->getId(), $script);
     $this->registerAssets();
 }
Exemplo n.º 8
0
 /**
  * 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()) {
         echo CHtml::activeTextField($this->model, $this->attribute, $this->htmlOptions);
     } else {
         echo CHtml::textField($name, $this->value, $this->htmlOptions);
     }
     $options = CJavaScript::encode($this->options);
     $js = "jQuery('#{$id}').datepicker({$options});";
     if (isset($this->language)) {
         $this->registerScriptFile($this->i18nScriptFile);
         $js .= "\njQuery('#{$id}').datepicker('option', jQuery.datepicker.regional['{$this->language}']);";
     }
     Yii::app()->getClientScript()->registerScript(__CLASS__ . '#' . $id, $js);
 }
Exemplo n.º 9
0
 /**
  * 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);}');
 }
Exemplo n.º 10
0
 /**
  * @param $model - profile model
  * @param $field - profile fields model item
  * @param $params - htmlOptions
  * @return string
  */
 public function editAttribute($model, $field, $htmlOptions = array())
 {
     if (!isset($htmlOptions['size'])) {
         $htmlOptions['size'] = 60;
     }
     if (!isset($htmlOptions['maxlength'])) {
         $htmlOptions['maxlength'] = $field->FIELD_SIZE ? $field->FIELD_SIZE : 10;
     }
     if (!isset($htmlOptions['id'])) {
         $htmlOptions['id'] = get_class($model) . '_' . $field->VARNAME;
     }
     if (!isset($htmlOptions['class'])) {
         $htmlOptions['class'] = 'datepicker';
     }
     $id = $htmlOptions['id'];
     $options['autoclose'] = true;
     $options['format'] = 'yyyy-mm-dd';
     $options = CJavaScript::encode($options);
     $basePath = Yii::getPathOfAlias('fm.views.asset');
     $baseUrl = Yii::app()->getAssetManager()->publish($basePath);
     $cs = Yii::app()->getClientScript();
     $cs->registerCssFile($baseUrl . '/css/datepicker.css');
     $cs->registerScriptFile($baseUrl . '/js/bootstrap-datepicker.js');
     //$js = "$('#{$id}').datepicker({$options});";
     $js = "\$('.datepicker').datepicker({$options});";
     $cs->registerScript('FormFieldController' . '#' . $id, $js);
     return CHtml::activeTextField($model, $field->VARNAME, $htmlOptions);
 }
Exemplo n.º 11
0
 /**
  * Renders the filter cell content. Here we can provide HTML options for actual filter input
  */
 protected function renderFilterCellContent()
 {
     if (is_string($this->filter)) {
         echo $this->filter;
     } else {
         if ($this->filter !== false && $this->grid->filter !== null && $this->name !== null && strpos($this->name, '.') === false) {
             if ($this->filterInputOptions) {
                 $filterInputOptions = $this->filterInputOptions;
                 if (empty($filterInputOptions['id'])) {
                     $filterInputOptions['id'] = false;
                 }
             } else {
                 $filterInputOptions = array();
             }
             if (is_array($this->filter)) {
                 $filterInputOptions['prompt'] = '';
                 echo CHtml::activeDropDownList($this->grid->filter, $this->name, $this->filter, $filterInputOptions);
             } else {
                 if ($this->filter === null) {
                     echo CHtml::activeTextField($this->grid->filter, $this->name, $filterInputOptions);
                 }
             }
         } else {
             parent::renderFilterCellContent();
         }
     }
 }
Exemplo n.º 12
0
 /**
  * Runs the widget.
  */
 public function run()
 {
     // print_r($this->htmlOptions); //typeahead
     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->hasModel()) {
         echo CHtml::activeTextField($this->model, $this->attribute, $this->htmlOptions);
     } else {
         echo CHtml::textField($name, $this->value, $this->htmlOptions);
     }
     $this->datasets['source'] = 'js:substringMatcher(_' . $this->id . '_source_list)';
     $options = CJavaScript::encode($this->options);
     $datasets = CJavaScript::encode($this->datasets);
     $eventsScript = array();
     foreach ($this->events as $event => $expression) {
         $eventsScript[] = ".on('typeahead:{$event}',{$expression})";
     }
     $eventsScript = implode("\n", $eventsScript);
     Yii::app()->clientScript->registerScript(__CLASS__ . '#' . $id, "jQuery('#{$id}').typeahead({$options}, {$datasets})\n{$eventsScript};");
 }
Exemplo n.º 13
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);
        echo CHtml::openTag('div', $this->htmlOptions);
        echo CHtml::openTag('div', array('class' => 'input-prepend bfh-timepicker-toggle', 'data-toggle' => 'bfh-timepicker'));
        echo CHtml::tag('span', array('class' => 'add-on'), TbHtml::icon(TbHtml::ICON_TIME));
        if ($this->hasModel()) {
            echo CHtml::activeTextField($this->model, $this->attribute, $this->inputOptions);
        } else {
            echo CHtml::textField($name, $this->value, $this->inputOptions);
        }
        echo CHtml::closeTag('div');
        echo '<div class="bfh-timepicker-popover">
				<table class="table">
				<tbody>
					<tr>
						<td class="hour">
						<a class="next" href="#"><i class="icon-chevron-up"></i></a><br>
						<input type="text" class="input-mini" readonly><br>
						<a class="previous" href="#"><i class="icon-chevron-down"></i></a>
						</td>
						<td class="separator">:</td>
						<td class="minute">
						<a class="next" href="#"><i class="icon-chevron-up"></i></a><br>
						<input type="text" class="input-mini" readonly><br>
						<a class="previous" href="#"><i class="icon-chevron-down"></i></a>
						</td>
					</tr>
				</tbody>
				</table>
			</div>';
        echo CHtml::closeTag('div');
    }
Exemplo n.º 14
0
 public function run()
 {
     echo CHtml::hiddenField($this->name, '', array('id' => $this->id . '_hidden'));
     //beckause disabled elements no serialize
     echo CHtml::activeTextField($this->model, $this->attribute, array('class' => 'text'));
     echo '<div class="alias_preloader" ></div>';
 }
Exemplo n.º 15
0
 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()) {
         echo CHtml::activeTextField($this->model, $this->attribute, $this->htmlOptions);
     } else {
         echo CHtml::textField($this->name, $this->value, $this->htmlOptions);
     }
     if (isset($this->htmlOptions['id'])) {
         $id = $this->htmlOptions['id'];
     } else {
         $this->htmlOptions['id'] = $id;
     }
     $options = CJavaScript::encode($this->options);
     $cs = Yii::app()->getClientScript();
     $assetUrl = Yii::app()->assetManager->publish(Yii::getPathOfAlias('ext.YiiDateTimePicker.assets'));
     Yii::app()->clientScript->registerScriptFile($assetUrl . '/jquery.datetimepicker.js');
     Yii::app()->clientScript->registerCssFile($assetUrl . '/jquery.datetimepicker.css');
     $js = "\$('#{$id}').datetimepicker({$options});";
     $cs->registerScript(__CLASS__ . '#' . $id, $js);
 }
 /**
  * Prints input and register assigned scripts on it
  *
  * @throws \CException
  */
 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->htmlOptions['name'])) {
         $name = $this->htmlOptions['name'];
     } else {
         $this->htmlOptions['name'] = $name;
     }
     if ($this->hasModel()) {
         echo \CHtml::activeTextField($this->model, $this->attribute, $this->htmlOptions);
     } else {
         echo \CHtml::textField($name, $this->value, $this->htmlOptions);
     }
     $options = \CJavaScript::encode($this->options);
     $js = "jQuery('#{$id}').datetimepicker({$options});";
     \Yii::app()->getClientScript()->registerScript(__CLASS__ . '#' . $id, $js);
 }
 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()) {
         echo CHtml::activeTextField($this->model, $this->attribute, $this->htmlOptions);
     } else {
         echo CHtml::textField($name, $this->value, $this->htmlOptions);
     }
     $options = CJavaScript::encode($this->options);
     $js = "jQuery('#{$id}').{$this->mode}picker({$options});";
     if (isset($this->language)) {
         $this->registerScriptFile($this->i18nScriptFile);
         $js = "jQuery('#{$id}').{$this->mode}picker(jQuery.extend({showMonthAfterYear:false}, jQuery.datepicker.regional['{$this->language}'], {$options}));";
     }
     $cs = Yii::app()->getClientScript();
     $assets = Yii::app()->getAssetManager()->publish(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'assets');
     $cs->registerCssFile($assets . self::ASSETS_NAME . '.css');
     $cs->registerScriptFile($assets . self::ASSETS_NAME . '.js', CClientScript::POS_END);
     $cs->registerScript(__CLASS__, $this->defaultOptions ? 'jQuery.{$this->mode}picker.setDefaults(' . CJavaScript::encode($this->defaultOptions) . ');' : '');
     $cs->registerScript(__CLASS__ . '#' . $id, $js);
 }
Exemplo n.º 18
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>';
 }
Exemplo n.º 19
0
 /**
  * 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()) {
         echo CHtml::activeTextField($this->model, $this->attribute, $this->htmlOptions);
     } else {
         echo CHtml::textField($name, $this->value, $this->htmlOptions);
     }
     $options = CJavaScript::encode($this->options);
     $js = "jQuery('#{$id}').daterangepicker({$options});";
     $cs = Yii::app()->getClientScript();
     if ($this->language != '' && $this->language != 'en') {
         $this->registerScriptFile($this->i18nScriptFile);
         $js .= "setTimeout(function(){jQuery('.range-start, .range-end').datepicker('option', jQuery.datepicker.regional['{$this->language}']);},500);";
     }
     $cs->registerScript(__CLASS__ . '#' . $id, $js, CClientScript::POS_READY);
 }
Exemplo n.º 20
0
 /**
  * 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->hasModel()) {
         echo CHtml::activeTextField($this->model, $this->attribute, $this->htmlOptions);
     } else {
         echo CHtml::textField($name, $this->value, $this->htmlOptions);
     }
     if ($this->sourceUrl !== null) {
         $this->options['source'] = CHtml::normalizeUrl($this->sourceUrl);
     } else {
         $this->options['source'] = $this->source;
     }
     $options = CJavaScript::encode($this->options);
     $js = "jQuery('#{$id}').autocomplete({$options}){$this->methodChain};";
     $cs = Yii::app()->getClientScript();
     $cs->registerScript(__CLASS__ . '#' . $id, $js);
 }
Exemplo n.º 21
0
 /**
  * @param $model - profile model
  * @param $field - profile fields model item
  * @param $params - htmlOptions
  * @return string
  */
 public function editAttribute($model, $field, $htmlOptions = array())
 {
     if (!isset($htmlOptions['size'])) {
         $htmlOptions['size'] = 60;
     }
     if (!isset($htmlOptions['maxlength'])) {
         $htmlOptions['maxlength'] = $field->field_size ? $field->field_size : 10;
     }
     if (!isset($htmlOptions['id'])) {
         $htmlOptions['id'] = get_class($model) . '_' . $field->varname;
     }
     $id = $htmlOptions['id'];
     $options['dateFormat'] = 'yy-mm-dd';
     $options = CJavaScript::encode($options);
     $basePath = Yii::getPathOfAlias('admin.views.asset');
     $baseUrl = Yii::app()->getAssetManager()->publish($basePath);
     $cs = Yii::app()->getClientScript();
     $cs->registerCssFile($baseUrl . '/css/' . $this->params['ui-theme'] . '/jquery-ui.css');
     $cs->registerScriptFile($baseUrl . '/js/jquery-ui.min.js');
     $language = $this->params['language'];
     if ($language != 'en') {
         $js = "jQuery('#{$id}').datepicker(jQuery.extend({showMonthAfterYear:false}, jQuery.datepicker.regional['{$language}'], {$options}));";
         $cs->registerScriptFile($baseUrl . '/js/jquery-ui-i18n.min.js');
     } else {
         $js = "jQuery('#{$id}').datepicker({$options});";
     }
     $cs->registerScript('ProfileFieldController' . '#' . $id, $js);
     return CHtml::activeTextField($model, $field->varname, $htmlOptions);
 }
Exemplo n.º 22
0
 /**
  * Runs the widget.
  */
 public function run()
 {
     list($name, $id) = $this->resolveNameID();
     // Add a class of no-user-select to widget
     $this->htmlOptions['class'] = empty($this->htmlOptions['class']) ? 'no-user-select' : 'no-user-select ' . $this->htmlOptions['class'];
     // We are overriding the result of $this->resolveNameID() here, because $id which it emits is not unique through the page.
     if (empty($this->htmlOptions['id'])) {
         $this->htmlOptions['id'] = $this->getId(true) . '-' . $id;
     }
     // Adding essential class for timepicker to work.
     $this->wrapperHtmlOptions = $this->injectClass($this->wrapperHtmlOptions, 'bootstrap-timepicker');
     if (!$this->noAppend) {
         $this->wrapperHtmlOptions = $this->injectClass($this->wrapperHtmlOptions, 'input-append');
     }
     echo CHtml::openTag('div', $this->wrapperHtmlOptions);
     if ($this->hasModel()) {
         if ($this->form) {
             echo $this->form->textField($this->model, $this->attribute, $this->htmlOptions);
         } else {
             echo CHtml::activeTextField($this->model, $this->attribute, $this->htmlOptions);
         }
     } else {
         echo CHtml::textField($name, $this->value, $this->htmlOptions);
     }
     if (!$this->noAppend) {
         $this->echoAppend();
     }
     echo CHtml::closeTag('div');
     $this->registerClientScript($this->htmlOptions['id']);
 }
Exemplo n.º 23
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);
    }
Exemplo n.º 24
0
 /**
  * Renders field
  */
 public function renderField()
 {
     if ($this->hasModel()) {
         echo \CHtml::activeTextField($this->model, $this->attribute, $this->options);
     } else {
         echo \CHtml::textField($this->options['name'], $this->value, $this->options);
     }
 }
 /**
  * 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);
     }
 }
Exemplo n.º 26
0
 function run()
 {
     if ($this->hasModel()) {
         echo CHtml::activeTextField($this->model, $this->htmlOptions);
     } else {
         echo CHtml::textField($this->name, $this->value, $this->htmlOptions);
     }
 }
Exemplo n.º 27
0
 /**
  * Execute the widget
  * This method registers necessary javascript and renders the needed HTML code.
  */
 public function run()
 {
     $this->registerClientScripts();
     if ($this->_calButton == false) {
         echo CHtml::activeTextField($this->_model, $this->_attribute, array('id' => $this->_inputField, 'onclick' => 'displayCalendar(' . $this->_inputField . ',"' . $this->_daFormat . '",this,false)'));
     } else {
         echo CHtml::activeTextField($this->_model, $this->_attribute, array('id' => $this->_inputField, 'readonly' => 'readonly'));
         echo CHtml::button('Calendar', array('onclick' => 'displayCalendar(' . $this->_inputField . ',"' . $this->_daFormat . '",this,false)'));
     }
 }
Exemplo n.º 28
0
 /**
  * Renders the TypeAhead field. If [[model]] has been specified then it will render an active field.
  * If [[model]] is null or not from an [[Model]] instance, then the field will be rendered according to
  * the [[name]] attribute.
  * @return string the rendering result
  * @throws \CException when none of the required attributes are set to render the textInput.
  * That is, if [[model]] and [[attribute]] are not set, then [[name]] is required.
  */
 public function renderField()
 {
     if ($this->model instanceof \CModel && $this->attribute !== null) {
         return \CHtml::activeTextField($this->model, $this->attribute, $this->options);
     } elseif ($this->name !== null) {
         return \CHtml::textField($this->name, $this->value, $this->options);
     } else {
         throw new \CException("Either 'name' or 'model' and 'attribute' properties must be specified.");
     }
 }
Exemplo n.º 29
0
 public function run()
 {
     if (!$this->readOnly) {
         echo $this->hasModel() ? CHtml::activeTextField($this->model, $this->attribute, $this->htmlOptions) : CHtml::textField($this->name, $this->value, $this->htmlOptions);
     } else {
         $this->htmlOptions['data-number'] = $this->hasModel() ? $this->model->{$this->attribute} : $this->value;
         echo CHtml::tag('span', $this->htmlOptions, '');
     }
     $this->registerPlugin('bfhphone');
 }
Exemplo n.º 30
0
 /**
  * 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);
 }