/** * [[@doctodo method_description:renderItem]]. * * @param [[@doctodo param_type:storageEngine]] $storageEngine [[@doctodo param_description:storageEngine]] * * @return [[@doctodo return_type:renderItem]] [[@doctodo return_description:renderItem]] */ public function renderItem($storageEngine) { $item = $this->prepareItem($storageEngine); $rendered = $storageEngine->storageHandler->object->generate($item); if (!$rendered) { return false; } $hiddenItem = clone $item; $hiddenItem->attribute = Html::changeAttribute($hiddenItem->attribute, 'storageEngine'); $item->model->storageEngine = $storageEngine->primaryKey; $rendered .= Html::activeHiddenInput($item->model, $hiddenItem->attribute, $item->inputOptions); return $rendered; }
/** * [[@doctodo method_description:generateRelationField]]. * * @param array $initialSettings [[@doctodo param_description:initialSettings]] [optional] * * @return [[@doctodo return_type:generateRelationField]] [[@doctodo return_description:generateRelationField]] */ protected function generateRelationField($initialSettings = []) { $model = $this->model; $field = $this->getRelationModelField(); $parts = []; $r = $initialSettings; $r['title'] = $this->modelField->label; $r['context'] = []; $r['selector'] = ['browse' => [], 'search' => ['data' => []]]; if ($this->modelField->relationship->temporal && empty($this->model->start)) { $this->model->start = date("m/d/Y"); } $r['context']['relationship'] = $this->modelField->relationship->package(); if ($this->modelField->baseModel && !$this->modelField->baseModel->isNewRecord) { $r['context']['object'] = ['id' => $this->modelField->baseModel->primaryKey, 'descriptor' => $this->modelField->baseModel->descriptor]; } $r['context']['role'] = $role = $this->modelField->relationship->companionRole($this->modelField->modelRole); $companionType = $this->modelField->relationship->companionRoleType($this->modelField->modelRole); $r['selector']['inputLabel'] = 'Select ' . $companionType->title->upperSingular; //\d($r);exit; if ($modelTypeItem = $this->modelField->relationship->{$role}->collectorItem) { $typeBundle = BrowserResponse::handleInstructions(['handler' => 'types', 'relationshipRole' => $role, 'relationship' => $this->modelField->relationship->systemId, 'typeFilters' => ['hasDashboard']]); $r['selector']['browse']['root'] = $typeBundle->package(); } $r['model'] = ['prefix' => $this->model->formName() . $this->model->tabularPrefix, 'attributes' => array_merge($this->model->attributes, ['taxonomy_id' => $this->model->taxonomy_id])]; if (!empty($this->modelField->value->primaryKey)) { $r['select'] = ['id' => $this->modelField->value->primaryKey, 'descriptor' => $this->modelField->value->descriptor, 'subdescriptor' => $this->modelField->value->primarySubdescriptor]; } if (!empty($r['model']['attributes']['start'])) { $r['model']['attributes']['start'] = Yii::$app->formatter->asDate($r['model']['attributes']['start']); } if (!empty($r['model']['attributes']['end'])) { $r['model']['attributes']['end'] = Yii::$app->formatter->asDate($r['model']['attributes']['end']); } $r['lockFields'] = isset($this->relationSettings['lockFields']) ? array_merge($this->relationSettings['lockFields'], $this->lockFields) : $this->lockFields; $r['multiple'] = $this->linkMultiple; // && $this->modelField->relationship->multiple; $this->htmlOptions['data-relationship'] = json_encode($r, JSON_FORCE_OBJECT); Html::addCssClass($this->htmlOptions, 'relationship'); //$model->_moduleHandler = $this->modelField->relationship->companionRole($this->modelField->modelRole) .':'. $this->modelField->relationship->companionRoleType($this->modelField->modelRole)->systemId; $parts[] = Html::activeHiddenInput($model, $this->model->tabularPrefix . '_moduleHandler'); $parts[] = Html::activeHiddenInput($model, $field, $this->htmlOptions); return implode($parts); }
<?php use canis\helpers\Html; echo Html::beginForm('', 'post', ['class' => 'ajax']); echo Html::beginTag('div', ['class' => 'form']); $model->confirm = 1; echo Html::activeHiddenInput($model, 'confirm'); if (count($model->possibleTargets) === 1) { $label = $model->labels[$model->possibleTargets[0]]; echo '<div class="confirm">Are you sure you want with ' . $label['long'] . '?</div>'; } else { $parts = []; $parts[] = 'the ' . $model->object->objectType->title->getSingular(false) . ' <em>' . $model->object->descriptor . '</em>'; if ($model->hasRelationshipTargets()) { $parts[] = 'its relationship with the ' . $model->relationshipWith->objectType->title->getSingular(false) . ' <em>' . $model->relationshipWith->descriptor . '</em>'; } echo '<div class="confirm">What would you like to do to ' . implode($parts, ' and ') . '?</div>'; echo '<div class="btn-group" data-toggle="buttons">'; $itemOptions = ['container' => false]; foreach ($model->possibleTargets as $target) { $label = $model->labels[$target]; $labelOptions = isset($label['options']) ? $label['options'] : []; if (!isset($labelOptions['class'])) { Html::addCssClass($labelOptions, 'btn btn-default'); } else { Html::addCssClass($labelOptions, 'btn'); } if ($model->target === $target) { Html::addCssClass($labelOptions, 'active'); } $labelOptions['title'] = ucfirst(strip_tags($label['long']));
/** * [[@doctodo method_description:generate]]. * * @throws Exception [[@doctodo exception_description:Exception]] * @return unknown * */ public function generate() { $model = $this->model; if (!$this->generator) { throw new Exception("Unable to find generator."); } if (!$this->generator->form) { throw new Exception("Unable to find generator form."); } $form = $this->generator->form; $pre = $post = null; $field = $this->getModelFieldName(); $fieldConfig = $this->fieldConfig; $templatePrefix = ''; if ($this->showLabel) { $templatePrefix = "{label}\n"; $fieldConfig['template'] = $templatePrefix . $fieldConfig['template']; } $item = $form->field($model, $field, $fieldConfig); $item->inputOptions =& $this->htmlOptions; $item->inputOptions['value'] = $fieldConfig['value'] = $this->modelField->format->formValue; Html::addCssClass($this->htmlOptions, 'form-control'); if (substr($this->type, 0, 5) === 'smart') { $this->type = lcfirst(substr($this->type, 5)); if (isset($this->smartOptions['watchField'])) { $watchFieldId = $this->neightborFieldId($this->smartOptions['watchField']); if (!$watchFieldId) { unset($this->smartOptions['watchField']); } else { $this->smartOptions['watchField'] = '#' . $watchFieldId; } } $this->htmlOptions['data-value'] = $fieldConfig['value']; //Html::getAttributeValue($model, $field) $this->htmlOptions['data-smart'] = json_encode($this->smartOptions); } switch ($this->type) { case 'checkBox': $item->checkbox(); break; case 'radioButton': $item->radio(); break; case 'checkBoxList': $item->checkboxList($this->options); break; case 'radioButtonList': case 'boolean': if ($this->type === 'boolean') { $this->showLabel = false; if (!isset($this->options)) { $this->showLabel = true; $this->options = [1 => 'Yes', 0 => 'No']; } Html::addCssClass($this->htmlOptions, 'btn-group'); Html::removeCssClass($this->htmlOptions, 'form-control'); $this->htmlOptions['data-toggle'] = 'buttons'; $encode = !isset($this->htmlOptions['encode']) || $this->htmlOptions['encode']; $this->htmlOptions['item'] = function ($index, $label, $name, $checked, $value) use($encode) { $itemOptions = ['container' => false, 'labelOptions' => ['class' => 'btn-primary btn']]; if ($checked) { Html::addCssClass($itemOptions['labelOptions'], 'active'); } return Html::radio($name, $checked, array_merge($itemOptions, ['value' => $value, 'label' => $encode ? Html::encode($label) : $label])); }; } $item->radioList($this->options); break; case 'dropDownList': case 'smartDropDownList': $item->dropDownList($this->options); break; case 'listBox': $item->listBox($this->options); break; case 'file': // $item->fileInput(); Html::removeCssClass($this->htmlOptions, 'form-control'); $fileStorageWidgetClass = $this->fileStorageWidgetClass; $item = $fileStorageWidgetClass::widget(['item' => $item]); break; case 'hidden': $this->showLabel = false; $item = Html::activeHiddenInput($model, $field, $this->htmlOptions); break; case 'password': $item->password(); break; case 'date': //$item->template = $templatePrefix . "<div class=\"input-group date\">{input}<span class=\"input-group-addon\"></span></div>\n<div class=\"\">{error}</div>"; if (!$item->inputGroupPostfix) { $item->inputGroupPostfix = "<i class=\"fa fa-calendar\"></i>"; } Html::addCssClass($item->inputGroupHtmlOptions, 'date'); break; case 'textarea': $item->textarea(); break; case 'rich': Html::addCssClass($this->htmlOptions, 'rich'); $editorSettings = []; $this->htmlOptions['data-editor'] = Json::encode($editorSettings); $item = Html::activeTextArea($model, $field, $this->htmlOptions); break; } if (!empty($item)) { return $pre . $item . $post; } return false; }