/** * Renders a text field with typeahead functionality based on the specified * data. * @param CModel $model the model * @param string $attribute the attribute name * @param array $htmlOptions options to pass to the control group * @return string the HTML for the input */ public function movieNameFieldControlGroup($model, $attribute, $htmlOptions = array()) { // Generate a unique ID for this element CHtml::resolveNameID($model, $attribute, $htmlOptions); $id = $htmlOptions['id']; Yii::app()->clientScript->registerScript($id, $this->getMovieNameTypeaheadScript($id, $htmlOptions), CClientScript::POS_READY); return $this->textFieldControlGroup($model, $attribute, $htmlOptions); }
function registerScript() { CHtml::resolveNameID($this->model, $this->attribute, $this->htmlOptions); $nameId = $this->htmlOptions['id']; $js = "\$('#{$this->attribute}').typeahead({\n source: function(query, process) {\n objects = [];\n map = {};\n \$.get('{$this->url}', {query: query}, function(data){\n for(var i=0; i<data.length; i++){\n map[data[i].value] = data[i].id;\n objects.push(data[i].value);\n }\n process(objects);\n }, 'json'); \n },\n updater: function(item) {\n \$('#{$nameId}').val(map[item]);\n return item;\n }\n });"; list(, $id) = $this->resolveNameID(); Yii::app()->getClientScript()->registerScript(__CLASS__ . '#' . $id, $js); }
public function init() { parent::init(); $attrs = array(); CHtml::resolveNameID($this->model, $this->source, $attrs); $options = CJavaScript::encode(array('source' => $attrs['id'], 'destination' => $this->id, 'urlSeparator' => $this->divider)); Yii::app()->clientScript->registerScriptFile($this->assets . '/jquery.synctranslit.js')->registerScriptFile($this->assets . '/alias.js')->registerScript($this->id . '_alias', "\$('#{$this->id}').alias({$options});"); }
/** * Renders a text field with typeahead functionality based on the specified * data. * @param CModel $model the model * @param string $attribute the attribute name * @param string $data JavaScript-encoded array containing the data for the * typeahead * @param array $htmlOptions options to pass to the control group * @return string the HTML for the input */ public function typeaheadFieldControlGroup($model, $attribute, $data, $htmlOptions = array()) { // Generate a unique ID for this element CHtml::resolveNameID($model, $attribute, $htmlOptions); TbHtml::addCssClass('twitter-typeahead-input', $htmlOptions); $id = $htmlOptions['id']; Yii::app()->clientScript->registerScript($id, "\n\t\t\t\$('#{$id}').typeahead({name: '{$id}',local: {$data},limit: 10});\n\t\t", CClientScript::POS_READY); return $this->textFieldControlGroup($model, $attribute, $htmlOptions); }
public function ueditor($model, $attribute, $htmlOptions = array()) { //得到这个插件的name CHtml::resolveNameID($model, $attribute, $htmlOptions); $attr = 'name="' . $htmlOptions['name'] . '" style="' . $htmlOptions['style'] . '"'; $content = $model->content ? $model->content : ''; $str = '<script type="text/javascript" src="/themes/abound/js/ueditor/ueditor.config.js"></script>'; $str .= '<script type="text/javascript" src="/themes/abound/js/ueditor/ueditor.all.min.js"></script>'; $str .= '<script type="text/javascript" src="/themes/abound/js/ueditor/lang/zh-cn/zh-cn.js"></script>'; $str .= '<script id="editor" type="text/plain" ' . $attr . '>' . html_entity_decode($content) . '</script>'; $str .= '<script type="text/javascript">var ue = UE.getEditor(\'editor\');</script>'; return $str; }
public static function getModelAttributes($modelClass, array $attributes = array()) { /** @var CModel $model */ $model = new $modelClass(); $labels = $model->attributeLabels(); $adapterAttributes = array(); foreach ($labels as $name => $label) { if (!empty($attributes) && !in_array($name, $attributes)) { continue; } $tmp = array(); CHtml::resolveNameID($model, $name, $tmp); $adapterAttributes[] = array('name' => $tmp['id'], 'map' => $name, 'label' => $label); } return $adapterAttributes; }
public static function activeRadioButtonList($model, $attribute, $data, $htmlOptions = array()) { CHtml::resolveNameID($model, $attribute, $htmlOptions); $selection = CHtml::resolveValue($model, $attribute); if ($model->hasErrors($attribute)) { CHtml::addErrorCss($htmlOptions); } $name = $htmlOptions['name']; unset($htmlOptions['name']); if (array_key_exists('uncheckValue', $htmlOptions)) { $uncheck = $htmlOptions['uncheckValue']; unset($htmlOptions['uncheckValue']); } else { $uncheck = ''; } $hiddenOptions = isset($htmlOptions['id']) ? array('id' => CHtml::ID_PREFIX . $htmlOptions['id']) : array('id' => false); $hidden = $uncheck !== null ? CHtml::hiddenField($name, $uncheck, $hiddenOptions) : ''; return $hidden . self::radioButtonList($name, $selection, $data, $htmlOptions); }
/** * Add a field into form * * @param CModel $model * @param string $attribute * @param string $inputType */ public function addActiveField($model, $attribute, $inputType, $htmlOptions = array(), $scenario = null) { CHtml::resolveNameID($model, $attribute, $htmlOptions); $label = $model->getAttributeLabel($attribute); $value = $model->{$attribute}; if (!isset($htmlOptions['data-source'])) { $htmlOptions['data-source'] = $attribute; } $this->fields[$htmlOptions['id']] = array('label' => $label, 'type' => $inputType, 'id' => $htmlOptions['id'], 'name' => $htmlOptions['name'], 'value' => $value, 'htmlOptions' => $htmlOptions); /** validators */ $this->rules[$htmlOptions['id']] = array(); $validators = $model->getValidators($attribute); foreach ($validators as $validator) { $valType = get_class($validator); $validator = get_class_vars($valType); $valType = str_replace('Validator', '', substr($valType, 1)); $validator['type'] = $valType; unset($validator['builtInValidators']); $validator['message'] = $this->getErrorMessage($valType, $attribute, $label); $this->rules[$htmlOptions['id']][] = $validator; } }
function run() { if ($this->hasModel()) { // required! $this->htmlOptions['autocomplete'] = 'off'; echo CHtml::textField($this->attribute, $this->value, $this->htmlOptions); echo '<span class="help-block">' . Yii::t('common', '(Autocomplete)') . '</span>'; CHtml::resolveNameID($this->model, $this->attribute, $this->htmlOptions); $this->_containerId = $this->htmlOptions['id'] . "_container"; $this->_nameId = $this->htmlOptions['name']; echo "<div id='{$this->_containerId}' class='well scrollbox'>"; if (count($this->model->attributes[$this->attribute]) > 0) { $elements = $this->model->attributes[$this->attribute]; foreach ($elements as $id => $name) { echo "<div>{$name}<i class=\"icon-remove\"></i><input type=\"hidden\" value=\"{$id}\" name=\"{$this->_nameId}[]\"></div>"; } } echo "</div>"; $this->registerScript(); } else { // TODO: extend widget to support non-active input throw new CException(Yii::t('errors', 'TypeaheadMultiple doesn\'t support non-active records. Please add a model attribute to the widget to use.')); } }
/** * Renders an input list. * @param boolean $checkbox flag that indicates if the list is a checkbox-list. * @param CModel $model the data model * @param string $attribute the attribute * @param array $data value-label pairs used to generate the input list. * @param array $htmlOptions additional HTML options. * @return string the generated input list. * @since 0.9.5 */ protected function inputsList($checkbox, $model, $attribute, $data, $htmlOptions = array()) { CHtml::resolveNameID($model, $attribute, $htmlOptions); $select = CHtml::resolveValue($model, $attribute); if ($model->hasErrors($attribute)) { if (isset($htmlOptions['class'])) { $htmlOptions['class'] .= ' ' . CHtml::$errorCss; } else { $htmlOptions['class'] = CHtml::$errorCss; } } $name = $htmlOptions['name']; unset($htmlOptions['name']); if (array_key_exists('uncheckValue', $htmlOptions)) { $uncheck = $htmlOptions['uncheckValue']; unset($htmlOptions['uncheckValue']); } else { $uncheck = ''; } $hiddenOptions = isset($htmlOptions['id']) ? array('id' => CHtml::ID_PREFIX . $htmlOptions['id']) : array('id' => false); $hidden = $uncheck !== null ? CHtml::hiddenField($name, $uncheck, $hiddenOptions) : ''; if (isset($htmlOptions['template'])) { $template = $htmlOptions['template']; } else { $template = '<label class="{labelCssClass}">{input}{label}</label>'; } unset($htmlOptions['template'], $htmlOptions['separator'], $htmlOptions['hint']); if ($checkbox && substr($name, -2) !== '[]') { $name .= '[]'; } unset($htmlOptions['checkAll'], $htmlOptions['checkAllLast']); $labelOptions = isset($htmlOptions['labelOptions']) ? $htmlOptions['labelOptions'] : array(); unset($htmlOptions['labelOptions']); $items = array(); $baseID = CHtml::getIdByName($name); $id = 0; $method = $checkbox ? 'checkBox' : 'radioButton'; $labelCssClass = $checkbox ? 'checkbox' : 'radio'; if (isset($htmlOptions['inline'])) { $labelCssClass .= '-inline'; unset($htmlOptions['inline']); } foreach ($data as $value => $label) { $checked = !is_array($select) && !strcmp($value, $select) || is_array($select) && in_array($value, $select); $htmlOptions['value'] = $value; $htmlOptions['id'] = $baseID . '_' . $id++; $option = CHtml::$method($name, $checked, $htmlOptions); $label = CHtml::label($label, $htmlOptions['id'], $labelOptions); $items[] = strtr($template, array('{labelCssClass}' => $labelCssClass, '{input}' => $option, '{label}' => $label)); } return $hidden . implode('', $items); }
public static function activeDateField($model, $attribute, $htmlOptions = array()) { // SET UP ARRAYS OF OPTIONS FOR DAY, MONTH, YEAR $x = 1; $dayOptions = array('00' => ' - '); while ($x < 31) { $dayOptions[($x < 10 ? '0' : '') . $x] = $x; $x++; } $monthOptions = array('00' => ' - ', '01' => UserModule::t('January'), '02' => UserModule::t('February'), '03' => UserModule::t('March'), '04' => UserModule::t('April'), '05' => UserModule::t('May'), '06' => UserModule::t('June'), '07' => UserModule::t('July'), '08' => UserModule::t('August'), '09' => UserModule::t('September'), '10' => UserModule::t('October'), '11' => UserModule::t('November'), '12' => UserModule::t('December')); $yearOptions = array('0000' => ' - '); $x = 1901; while ($x < 2030) { $yearOptions[$x] = $x; $x++; } parent::resolveNameID($model, $attribute, $htmlOptions); if ($model->{$attribute} != '0000-00-00' && isset($model->{$attribute})) { if (is_array($model->{$attribute})) { $new = $model->{$attribute}; $day = $new['day']; $month = $new['month']; $year = $new['year']; } else { $new = explode('-', $model->{$attribute}); // intval removes leading zero $day = $new[2]; $month = $new[1]; $year = $new[0]; } } else { // DEFAULT TO 0 IF THERE IS NO DATE SET $day = '00'; $month = '00'; $year = '0000'; } //echo "<pre>"; print_r(array($day,$month,$year)); die(); $return = parent::dropDownList($htmlOptions['name'] . '[day]', $day, $dayOptions); $return .= parent::dropDownList($htmlOptions['name'] . '[month]', $month, $monthOptions); $return .= parent::dropDownList($htmlOptions['name'] . '[year]', $year, $yearOptions); return $return; }
/** * Generates an input HTML tag for a model attribute. * This method generates an input HTML tag based on the given input name and value. * @param string $type the input type. * @param CModel $model the data model. * @param string $attribute the attribute. * @param array $htmlOptions additional HTML attributes. * @return string the generated input tag. */ protected static function activeTextInputField($type, $model, $attribute, $htmlOptions) { parent::resolveNameID($model, $attribute, $htmlOptions); parent::clientChange('change', $htmlOptions); $htmlOptions = self::normalizeInputOptions($htmlOptions); $addOnClasses = self::getAddOnClasses($htmlOptions); $addOnOptions = TbArray::popValue('addOnOptions', $htmlOptions, array()); self::addCssClass($addOnClasses, $addOnOptions); $prepend = TbArray::popValue('prepend', $htmlOptions, ''); $prependOptions = TbArray::popValue('prependOptions', $htmlOptions, array()); if (!empty($prepend)) { $prepend = self::inputAddOn($prepend, $prependOptions); } $append = TbArray::popValue('append', $htmlOptions, ''); $appendOptions = TbArray::popValue('appendOptions', $htmlOptions, array()); if (!empty($append)) { $append = self::inputAddOn($append, $appendOptions); } $output = ''; if (!empty($addOnClasses)) { $output .= self::openTag('div', $addOnOptions); } $output .= $prepend . parent::activeInputField($type, $model, $attribute, $htmlOptions) . $append; if (!empty($addOnClasses)) { $output .= '</div>'; } return $output; }
/** * Generates an uneditable input for a model attribute. * @param CModel $model the data model. * @param string $attribute the attribute. * @param array $htmlOptions additional HTML attributes. * @return string the generated input. */ public static function activeUneditableField($model, $attribute, $htmlOptions = array()) { parent::resolveNameID($model, $attribute, $htmlOptions); $value = parent::resolveValue($model, $attribute); BsArray::removeValues(array('name', 'id'), $htmlOptions); return self::uneditableField($value, $htmlOptions); }
public function init() { parent::init(); // ensure necessary assets are loaded // JJD 8/3/11 make EJuiAutoCompleteFkField work for child rows where attribute like [$i]FieldName // get the ID which will be created for the actual field when it is rendered. // don't let resolveNameID() change $this->attribute which is needed to generate the actual field $attr = $this->attribute; $tempHtmlOpts = array(); CHtml::resolveNameID($this->model, $attr, $tempHtmlOpts); $id = $tempHtmlOpts['id']; $this->_fieldID = $id; $this->_saveID = $id . '_save'; $this->_lookupID = $id . '_lookup'; $related = $this->model->{$this->relName}; // get the related record $value = CHtml::resolveValue($this->model, $this->attribute); $this->_display = !empty($value) ? $related->{$this->displayAttr} : ''; // $this->_display=($value!==null ? $related->{$this->displayAttr} : ''); // nineinchnick comment #6809 handle zero as valid FK value. not sure works in all cases if (!isset($this->options['minLength'])) { $this->options['minLength'] = 2; } if (!isset($this->options['maxHeight'])) { $this->options['maxHeight'] = '100'; } $this->htmlOptions['size'] = $this->autoCompleteLength; // fix problem with Chrome 10 validating maxLength for the auto-complete field $this->htmlOptions['maxlength'] = $this->autoCompleteLength; // setup javascript to do the work $this->options['create'] = "js:function(event, ui){\$(this).val('" . addslashes($this->_display) . "');}"; // show initial display value // after user picks from list, save the ID in model/attr field, and Value in _save field for redisplay $this->options['select'] = "js:function(event, ui){\$('#" . $this->_fieldID . "').val(ui.item.id);\$('#" . $this->_saveID . "').val(ui.item.value);}"; // when the autoComplete field loses focus, refresh the field with current value of _save // this is either the previous value if user didn't pick anything; or the new value if they did $this->htmlOptions['onblur'] = "\$(this).val(\$('#" . $this->_saveID . "').val());"; }
public function run() { // REGISTER JS SCRIPT $cs = Yii::app()->clientScript; $cs->registerScriptFile($this->_baseUrl . '/jquery.tipsy.js'); // REGISTER CSS $cs->registerCssFile($this->_baseUrl . '/css/tipsy.css'); // LOOP THROUGH ITEMS $items = $this->items; $scriptList = array(); foreach ($items as $item) { $params = array(); $htmlOptions = isset($item['htmlOptions']) ? $item['htmlOptions'] : array(); if (is_array($item['id'])) { $model = $item['id']['model']; $attribute = $item['id']['attribute']; CHtml::resolveNameID($model, $attribute, $htmlOptions); $tipsyID = '[name="' . $htmlOptions['name'] . '"]'; } else { $tipsyID = $item['id']; } // OPTION: delayIn if (isset($this->delayIn)) { $params['delayIn'] = $this->delayIn; } else { $params['delayIn'] = 50; //DEFAULT } if (isset($item['delayIn'])) { $params['delayIn'] = $item['delayIn']; } // OPTION: delayOut if (isset($this->delayOut)) { $params['delayOut'] = $this->delayOut; } else { $params['delayOut'] = 50; //DEFAULT } if (isset($item['delayOut'])) { $params['delayOut'] = $item['delayOut']; } // OPTION: fade if (isset($this->fade)) { $params['fade'] = $this->fade; } if (isset($item['fade'])) { $params['fade'] = $item['fade']; } // OPTION: fallback if (isset($this->fallback)) { $params['fallback'] = $this->fallback; } if (isset($item['fallback'])) { $params['fallback'] = $item['fallback']; } // OPTION: gravity if (isset($this->gravity)) { $params['gravity'] = $this->gravity; } if (isset($item['gravity'])) { $params['gravity'] = $item['gravity']; } // OPTION: html if (isset($this->html)) { $params['html'] = $this->html; } if (isset($item['html'])) { $params['html'] = $item['html']; } // OPTION: offset if (isset($this->offset)) { $params['offset'] = $this->offset; } if (isset($item['offset'])) { $params['offset'] = $item['offset']; } // OPTION: opacity if (isset($this->opacity)) { $params['opacity'] = $this->opacity; } else { $params['opacity'] = '0.8'; //DEFAULT } if (isset($item['opacity'])) { $params['opacity'] = $item['opacity']; } // OPTION: title if (isset($this->title)) { $params['title'] = $this->title; } if (isset($item['title'])) { $params['title'] = $item['title']; } // OPTION: trigger if (isset($this->trigger)) { $params['trigger'] = $this->trigger; } else { $params['trigger'] = 'hover'; //DEFAULT } if (isset($item['trigger'])) { $params['trigger'] = $item['trigger']; } //GENERATE JS CODE if (!empty($tipsyID)) { $jsCode = "\$('" . $tipsyID . "').tipsy(" . CJavaScript::encode($params) . ");"; $scriptList[] = $jsCode; } } //END foreach($items as $item) if (!empty($scriptList)) { $tipsyID = $this->getId(); // GENERATE INIT FUNCTION $jsCode = "\nfunction initTipsy(){\n" . "\$(\".tipsy-inner, .tipsy\").remove(); \n" . implode('', $scriptList) . "\n}\n"; $cs->registerScript(__CLASS__ . '#' . $tipsyID, $jsCode, CClientScript::POS_END); // RUN INIT FUNCTION $cs->registerScript(__CLASS__ . '#' . $tipsyID, "initTipsy();", CClientScript::POS_READY); } }
/** * Generates an input HTML tag for a model attribute. * This method generates an input HTML tag based on the given input name and value. * @param string $type the input type. * @param CModel $model the data model. * @param string $attribute the attribute. * @param array $htmlOptions additional HTML attributes. * @return string the generated input tag. */ protected static function activeTextInputField($type, $model, $attribute, $htmlOptions) { parent::resolveNameID($model, $attribute, $htmlOptions); parent::clientChange('change', $htmlOptions); // In case we do need to create a div container for the input element (i.e. has addon or defined col) $containerOptions = array(); // Get the intended input width before the rest of the options are normalized self::addSpanClass($htmlOptions); self::addColClass($htmlOptions); $col = self::popColClasses($htmlOptions); $htmlOptions = self::normalizeInputOptions($htmlOptions); self::addCssClass('form-control', $htmlOptions); $addOnClass = self::getAddOnClasses($htmlOptions); $addOnOptions = TbArray::popValue('addOnOptions', $htmlOptions, array()); self::addCssClass($addOnClass, $addOnOptions); $prepend = TbArray::popValue('prepend', $htmlOptions, ''); $prependOptions = TbArray::popValue('prependOptions', $htmlOptions, array()); if (!empty($prepend)) { $prepend = self::inputAddOn($prepend, $prependOptions); } $append = TbArray::popValue('append', $htmlOptions, ''); $appendOptions = TbArray::popValue('appendOptions', $htmlOptions, array()); if (!empty($append)) { $append = self::inputAddOn($append, $appendOptions); } if (!empty($addOnClass)) { $containerOptions = $addOnOptions; } if (!empty($col)) { self::addCssClass($col, $containerOptions); } $output = ''; if (!empty($containerOptions)) { $output .= self::openTag('div', $containerOptions); } $output .= $prepend . parent::activeInputField($type, $model, $attribute, $htmlOptions) . $append; if (!empty($containerOptions)) { $output .= '</div>'; } return $output; }
/** * Generates a radio button list for a model attribute. * The model attribute value is used as the selection. * If the attribute has input error, the input field's CSS class will * be appended with {@link errorCss}. * @param CModel $model the data model * @param string $attribute the attribute * @param array $data value-label pairs used to generate the radio button list. * Note, the values will be automatically HTML-encoded, while the labels will not. * @param array $htmlOptions addtional HTML options. The options will be applied to * each radio button input. The following special options are recognized: * <ul> * <li>template: string, specifies how each radio button is rendered. Defaults * to "{input} {label}", where "{input}" will be replaced by the generated * radio button input tag while "{label}" will be replaced by the corresponding radio button label.</li> * <li>separator: string, specifies the string that separates the generated radio buttons. Defaults to new line (<br/>).</li> * <li>encode: boolean, specifies whether to encode HTML-encode tag attributes and values. Defaults to true.</li> * </ul> * Since version 1.1.7, a special option named 'uncheckValue' is available that can be used to specify the value * returned when the radio button is not checked. By default, this value is ''. Internally, a hidden field is * rendered so that when the radio button is not checked, we can still obtain the posted uncheck value. * If 'uncheckValue' is set as NULL, the hidden field will not be rendered. * @return string the generated radio button list * @see radioButtonList */ public static function activeInlineRadioButtonList($model, $attribute, $data, $htmlOptions = array()) { CHtml::resolveNameID($model, $attribute, $htmlOptions); $selection = CHtml::resolveValue($model, $attribute); if ($model->hasErrors($attribute)) { CHtml::addErrorCss($htmlOptions); } $name = self::popOption('name', $htmlOptions); $unCheck = self::popOption('uncheckValue', $htmlOptions, ''); $hiddenOptions = isset($htmlOptions['id']) ? array('id' => CHtml::ID_PREFIX . $htmlOptions['id']) : array('id' => false); $hidden = $unCheck !== null ? CHtml::hiddenField($name, $unCheck, $hiddenOptions) : ''; return $hidden . self::inlineRadioButtonList($name, $selection, $data, $htmlOptions); }
/** * @return array the name and the ID of the drop-down element. */ protected function resolveDropDownNameID() { $nameID = array(); if (!empty($this->name)) { $name = $this->name; } else { if ($this->hasModel()) { $name = CHtml::activeName($this->model, $this->attribute); CHtml::resolveNameID($this->model, $this->attribute, $nameID); } else { throw new CException('"model" and "attribute" or "name" have to be set'); } } if (isset($this->htmlOptions['id'])) { $id = $this->htmlOptions['id']; } else { if (!empty($nameID['id'])) { $id = $nameID['id']; } else { $id = CHtml::getIdByName($name); } } return array($name, $id); }
/** * Generates an input HTML tag for a model attribute. * This method generates an input HTML tag based on the given input name and value. * @param string $type the input type. * @param CModel $model the data model. * @param string $attribute the attribute. * @param array $htmlOptions additional HTML attributes. * @return string the generated input tag. */ protected static function activeTextInputField($type, $model, $attribute, $htmlOptions) { CHtml::resolveNameID($model, $attribute, $htmlOptions); CHtml::clientChange('change', $htmlOptions); $htmlOptions = self::normalizeInputOptions($htmlOptions); $addOnClasses = self::getAddOnClasses($htmlOptions); $addOnOptions = self::popOption('addOnOptions', $htmlOptions, array()); $addOnOptions = self::addClassName($addOnClasses, $addOnOptions); $prepend = self::popOption('prepend', $htmlOptions, ''); $prependOptions = self::popOption('prependOptions', $htmlOptions, array()); if (!empty($prepend)) { $prepend = self::inputAddOn($prepend, $prependOptions); } $append = self::popOption('append', $htmlOptions, ''); $appendOptions = self::popOption('appendOptions', $htmlOptions, array()); if (!empty($append)) { $append = self::inputAddOn($append, $appendOptions); } ob_start(); if (!empty($addOnClasses)) { echo self::openTag('div', $addOnOptions); } echo $prepend . CHtml::activeInputField($type, $model, $attribute, $htmlOptions) . $append; if (!empty($addOnClasses)) { echo '</div>'; } return ob_get_clean(); }
* Section 5 of the GNU Affero General Public License version 3. * * In accordance with Section 7(b) of the GNU Affero General Public License version 3, * these Appropriate Legal Notices must retain the display of the "Powered by * X2Engine" logo. If the display of the logo is not reasonably feasible for * technical reasons, the Appropriate Legal Notices must display the words * "Powered by X2Engine". *****************************************************************************************/ //Yii::app()->clientScript->registerCssFile( // Yii::app()->controller->assetsUrl.'/css/recordIndex.css'); //Yii::app()->clientScript->registerCssFile( // Yii::app()->controller->assetsUrl.'/css/activityFeed.css'); Yii::app()->clientScript->registerScriptFile(Yii::app()->controller->assetsUrl . '/js/EventPublisherController.js'); $attr = 'photo'; $htmlOptions = array(); CHtml::resolveNameID($model, $attr, $htmlOptions); $this->onPageLoad("function () {\n x2.main.controllers['{$this->pageId}'] = new x2.EventPublisherController ({\n photoAttrName: " . CJSON::encode($htmlOptions['name']) . "\n });\n}", CClientScript::POS_END); ?> <div class='refresh-content' data-refresh-selector='.header-content-right'> <div class='header-content-right'> <div class='post-event-button disabled'> <?php echo CHtml::encode(Yii::t('mobile', 'Post')); ?> </div> </div> </div> <div class='event-publisher'>
/** * Renders an input list. * @param string $type the input type. Valid types are 'checkbox' and 'radio'. * @param CModel $model the data model * @param string $attribute the attribute * @param array $data value-label pairs used to generate the radio button list. * @param array $htmlOptions additional HTML options. * @return string the generated input list. * @since 0.9.5 */ protected function inputsList($type, $model, $attribute, $data, $htmlOptions = array()) { CHtml::resolveNameID($model, $attribute, $htmlOptions); $selection = CHtml::resolveValue($model, $attribute); if ($model->hasErrors($attribute)) { if (isset($htmlOptions['class'])) { $htmlOptions['class'] .= ' ' . CHtml::$errorCss; } else { $htmlOptions['class'] = CHtml::$errorCss; } } $name = $htmlOptions['name']; unset($htmlOptions['name']); if (array_key_exists('uncheckValue', $htmlOptions)) { $uncheck = $htmlOptions['uncheckValue']; unset($htmlOptions['uncheckValue']); } else { $uncheck = ''; } $hiddenOptions = isset($htmlOptions['id']) ? array('id' => CHtml::ID_PREFIX . $htmlOptions['id']) : array('id' => false); $hidden = $uncheck !== null ? CHtml::hiddenField($name, $uncheck, $hiddenOptions) : ''; unset($htmlOptions['template'], $htmlOptions['separator'], $htmlOptions['labelOptions']); $items = array(); $baseID = CHtml::getIdByName($name); $id = 0; $method = $type === 'checkbox' ? 'checkBox' : 'radioButton'; foreach ($data as $value => $label) { $checked = !strcmp($value, $selection); $htmlOptions['value'] = $value; $htmlOptions['id'] = $baseID . '_' . $id++; $option = CHtml::$method($name, $checked, $htmlOptions); $items[] = '<label>' . $option . '<span>' . $label . '</span></label>'; } return $hidden . '<ul class="inputs-list"><li>' . implode('</li><li>', $items) . '</li></ul>'; }
/** * @return array the name and the ID of the drop-down element. */ protected function resolveDropDownNameID() { $ni = array(); if (!empty($this->name)) { $dname = $this->name; } else { if ($this->hasModel()) { $dname = CHtml::activeName($this->model, $this->dropDownAttribute); CHtml::resolveNameID($this->model, $this->dropDownAttribute, $ni); } else { throw new CException(Yii::t('EchMultiSelect.EchMultiSelect', '{class} must specify "model" and "dropDownAttribute" or "name" property values.', array('{class}' => get_class($this)))); } } if (isset($this->dropDownHtmlOptions['id'])) { $id = $this->dropDownHtmlOptions['id']; } else { if (!empty($ni['id'])) { $id = $ni['id']; } else { $id = CHtml::getIdByName($dname); } } return array($dname, $id); }
/** * Renders an input list. * * @param boolean $checkbox flag that indicates if the list is a checkbox-list. * @param CModel $model the data model * @param string $attribute the attribute * @param array $data value-label pairs used to generate the input list. * @param array $htmlOptions additional HTML options. * @return string the generated input list. * * @since 0.9.5 */ protected function inputsList($checkbox, $model, $attribute, $data, $htmlOptions = array()) { CHtml::resolveNameID($model, $attribute, $htmlOptions); $select = CHtml::resolveValue($model, $attribute); if ($model->hasErrors($attribute)) { if (isset($htmlOptions['class'])) { $htmlOptions['class'] .= ' ' . CHtml::$errorCss; } else { $htmlOptions['class'] = CHtml::$errorCss; } } $name = $htmlOptions['name']; unset($htmlOptions['name']); if (array_key_exists('uncheckValue', $htmlOptions)) { $uncheck = $htmlOptions['uncheckValue']; unset($htmlOptions['uncheckValue']); } else { $uncheck = ''; } $hiddenOptions = isset($htmlOptions['id']) ? array('id' => CHtml::ID_PREFIX . $htmlOptions['id']) : array('id' => false); $hidden = $uncheck !== null ? CHtml::hiddenField($name, $uncheck, $hiddenOptions) : ''; $template = isset($htmlOptions['template']) ? $htmlOptions['template'] : '<label class="{labelCssClass}">{input}{label}</label>'; $container = isset($htmlOptions['container']) ? $htmlOptions['container'] : ''; unset($htmlOptions['template'], $htmlOptions['separator'], $htmlOptions['hint']); if ($checkbox && substr($name, -2) !== '[]') { $name .= '[]'; } $checkAllLast = ''; if (isset($htmlOptions['checkAll'])) { $checkAllLabel = $htmlOptions['checkAll']; $checkAllLast = isset($htmlOptions['checkAllLast']) && $htmlOptions['checkAllLast']; } unset($htmlOptions['checkAll'], $htmlOptions['checkAllLast']); $labelOptions = isset($htmlOptions['labelOptions']) ? $htmlOptions['labelOptions'] : array(); unset($htmlOptions['labelOptions']); $items = array(); $baseID = isset($htmlOptions['baseID']) ? $htmlOptions['baseID'] : CHtml::getIdByName($name); unset($htmlOptions['baseID']); $id = 0; $checkAll = true; $method = $checkbox ? 'checkBox' : 'radioButton'; $labelCssClass = $checkbox ? 'checkbox' : 'radio'; if (isset($htmlOptions['inline'])) { $labelCssClass .= ' inline'; unset($htmlOptions['inline']); } foreach ($data as $value => $label) { $checked = !is_array($select) && !strcmp($value, $select) || is_array($select) && in_array($value, $select); $checkAll = $checkAll && $checked; $htmlOptions['value'] = $value; $htmlOptions['id'] = $baseID . '_' . $id++; $option = CHtml::$method($name, $checked, $htmlOptions); $label = CHtml::label($label, $htmlOptions['id'], $labelOptions); $items[] = strtr($template, array('{labelCssClass}' => $labelCssClass, '{input}' => $option, '{label}' => $label)); } if (isset($checkAllLabel)) { $htmlOptions['value'] = 1; $htmlOptions['id'] = $id = $baseID . '_all'; $option = CHtml::$method($id, $checkAll, $htmlOptions); $label = CHtml::label($checkAllLabel, $id, $labelOptions); $item = strtr($template, array('{labelCssClass}' => $labelCssClass, '{input}' => $option, '{label}' => $label)); if ($checkAllLast) { $items[] = $item; } else { array_unshift($items, $item); } $name = strtr($name, array('[' => '\\[', ']' => '\\]')); $js = <<<EOD jQuery('#{$id}').click(function() { \t\$("input[name='{$name}']").prop('checked', this.checked); }); jQuery("input[name='{$name}']").click(function() { \t\$('#{$id}').prop('checked', !jQuery("input[name='{$name}']:not(:checked)").length); }); jQuery('#{$id}').prop('checked', !jQuery("input[name='{$name}']:not(:checked)").length); EOD; /** @var $cs CClientScript */ $cs = Yii::app()->getClientScript(); $cs->registerCoreScript('jquery'); $cs->registerScript($id, $js); } if (empty($container)) { return $hidden . implode('', $items); } else { return $hidden . CHtml::tag($container, array('id' => $baseID), implode('', $items)); } }
public function resolveHtmlOptions(CModel $model, $attribute, array $htmlOptions = array()) { CHtml::resolveNameID($model, $attribute, $htmlOptions); $htmlOptions['id'] = $this->resolveId($htmlOptions['id']); return $htmlOptions; }