/** * Generates a default layout from the desktop layout if available, or from the model's * fields otherwise. * @param string $type 'form' or 'view' * @param string $modelName * @return array */ public static function generateDefaultLayout($type, $modelName) { if ($type === 'form') { $layout = FormLayout::model()->findByAttributes(array('model' => ucfirst($modelName), 'defaultForm' => 1, 'scenario' => 'Default')); } else { $layout = FormLayout::model()->findByAttributes(array('model' => ucfirst($modelName), 'defaultView' => 1, 'scenario' => 'Default')); } $layoutData = array(); if ($layout) { $layout = CJSON::decode($layout->layout); if (isset($layout['sections'])) { foreach ($layout['sections'] as $section) { foreach ($section['rows'] as $row) { foreach ($row['cols'] as $col) { foreach ($col['items'] as $item) { if (isset($item['name'])) { $fieldName = preg_replace('/^formItem_/u', '', $item['name']); $layoutData[] = $fieldName; } } } } } } } elseif (is_subclass_of($modelName, 'X2Model')) { $layoutData = Yii::app()->db->createCommand()->select('fieldName')->from('x2_fields')->where('modelName=:modelName', array(':modelName' => $modelName))->andWhere($type === 'view' ? 'readOnly' : 'true')->queryColumn(); } return $layoutData; }
/** * Delete a form layout. * * @param int $id The ID of the layout to be deleted. */ public function actionDeleteFormLayout($id) { $layout = FormLayout::model()->findByPk($id); if (isset($layout)) { $modelName = $layout->model; $defaultView = $layout->defaultView; $defaultForm = $layout->defaultForm; $layout->delete(); // if we just deleted the default, find the next layout and make it the default if ($defaultView) { $newDefaultView = FormLayout::model()->findByAttributes(array('model' => $modelName)); if (isset($newDefaultView)) { $newDefaultView->defaultView = true; $newDefaultView->save(); } } if ($defaultForm) { $newDefaultForm = FormLayout::model()->findByAttributes(array('model' => $modelName)); if (isset($newDefaultForm)) { $newDefaultForm->defaultForm = true; $newDefaultForm->save(); } } $this->redirect(array('editor', 'model' => $modelName)); } else { $this->redirect('editor'); } }
public function getLayoutData() { $layoutData = Yii::app()->cache->get('form_' . $this->modelName . '_' . $this->scenario); if ($layoutData) { return $layoutData; } $layout = FormLayout::model()->findByAttributes(array('model' => ucfirst($this->modelName), 'defaultView' => 1, 'scenario' => $this->scenario)); if (!$layout && $this->scenario === 'Inline') { $layout = FormLayout::model()->findByAttributes(array('model' => ucfirst($this->modelName), 'defaultView' => 1, 'scenario' => 'Default')); } if (isset($layout)) { $layoutData = json_decode($layout->layout, true); Yii::app()->cache->set('form_' . $this->modelName . '_' . $this->scenario, $this->layoutData, 0); // cache the data } return $layoutData; }
* IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. ********************************************************************************/ $attributeLabels = $model->attributeLabels(); $showSocialMedia = Yii::app()->params->profile->showSocialMedia; $showWorkflow = Yii::app()->params->profile->showWorkflow; if ($modelName == 'contacts' || $modelName == 'sales') { Yii::app()->clientScript->registerScript('toggleWorkflow', "\nfunction showWorkflow() {\n\t\$('tr#workflow-row').show();\n\t\$('tr#workflow-toggle').hide();\n}\nfunction hideWorkflow() {\n\t\$('tr#workflow-row').hide();\n\t\$('tr#workflow-toggle').show();\n}\n\$(function() {\n" . ($showWorkflow ? "showWorkflow();\n" : "hideWorkflow()\n") . "});", CClientScript::POS_HEAD); Yii::app()->clientScript->registerScript('setFormName', "\nwindow.formName = '{$modelName}';\n", CClientScript::POS_HEAD); } $layout = FormLayout::model()->findByAttributes(array('model' => ucfirst($modelName), 'defaultView' => 1)); if (isset($layout)) { echo '<div class="x2-layout">'; $fields = array(); // remove this later, once all models extend X2Models if (method_exists($model, 'getFields')) { foreach ($model->fields as $fieldModel) { $fields[$fieldModel->fieldName] = $fieldModel; } } else { foreach (Fields::model()->findAllByAttributes(array('modelName' => ucfirst($modelName))) as $fieldModel) { $fields[$fieldModel->fieldName] = $fieldModel; } } $layoutData = json_decode($layout->layout, true); $formSettings = ProfileChild::getFormSettings($modelName);
public function actionQuickView($id) { $model = $this->loadModel($id); if (!FormLayout::model()->findByAttributes(array('model' => get_class($model)))) { echo Yii::t('app', 'Quick view not supported'); } if ($this->checkPermissions($model, 'view')) { $this->widget('DetailView', array_merge(array('model' => $model, 'scenario' => 'Inline', 'nameLink' => true)), false, true); // $this->renderPartial( // 'application.components.views.@DETAILVIEW', // array_merge( array( // 'model' => $model, // 'modelName' => get_class ($model), // 'scenario'=>'Inline', // 'nameLink' => true, // ), $options) // , false, true); return; } throw new CHttpException(403); }
/** * Helper method to unset all defaultView or defaultForm flags * @param string $type Form type, either 'view' or 'form', or both if argument is omitted * @param string Model type to unset flags for */ public static function clearDefaultFormLayouts($type = null, $model = null, $scenario = null) { // Construct attributes to select form layouts $attr = array('model' => $model); if ($scenario) { $attr['scenario'] = $scenario; } if ($type === 'view') { $attr['defaultView'] = 1; } else { if ($type === 'form') { $attr['defaultForm'] = 1; } } $layouts = FormLayout::model()->findAllByAttributes($attr); foreach ($layouts as &$layout) { if ($type === 'view') { $layout->defaultView = false; } else { if ($type === 'form') { $layout->defaultForm = false; } else { $layout->defaultView = $layout->defaultForm = false; } } $layout->save(); } }
public function getLayout() { return FormLayout::model()->findByAttributes(array('model' => ucfirst($this->modelName), 'defaultForm' => 1, 'scenario' => 'Default')); }
public function actionQuickView($id) { $model = $this->loadModel($id); if (!FormLayout::model()->findByAttributes(array('model' => get_class($model)))) { echo Yii::t('app', 'Quick view not supported'); } if ($this->checkPermissions($model, 'view')) { $that = $this; X2Widget::ajaxRender(function () use($model, $that) { $that->widget('DetailView', array_merge(array('model' => $model, 'scenario' => 'Inline', 'nameLink' => true))); }); return; } throw new CHttpException(403); }
return $("<li>").data("item.autocomplete",item).append( x2.forms.renderContactLookup(item)).appendTo(ul); }; }'), 'htmlOptions' => array('style' => 'max-width:200px;')), true) . CHtml::tag('span', array('class' => 'x2-hint', 'style' => 'display:inline-block; margin-left:5px;', 'title' => Yii::t('marketing', 'The {contact} you enter here will be used for variable replacement, ' . 'i.e. for "John Doe" the token {firstName} will get replaced with ' . '"John"', array('{contact}' => Modules::displayName(false, "Contacts")))), '[?]') . '</div>')); if ($model->type === 'Email') { ?> <?php if ($model->launchDate && $model->active && !$model->complete) { $this->widget('EmailProgressControl', array('campaign' => $model)); } ?> <?php // find out if attachments are minimized $showAttachments = true; $formSettings = Profile::getFormSettings('campaign'); $layout = FormLayout::model()->findByAttributes(array('model' => 'Campaign', 'defaultView' => 1)); if (isset($layout)) { $layoutData = json_decode($layout->layout, true); $count = count($layoutData['sections']); if (isset($formSettings[$count])) { $showAttachments = $formSettings[$count]; } } ?> <div id="campaign-attachments-wrapper" class="x2-layout form-view"> <div class="formSection collapsible <?php echo $showAttachments ? 'showSection' : ''; ?> "> <div class="formSectionHeader">
* technical reasons, the Appropriate Legal Notices must display the words * "Powered by X2Engine". *****************************************************************************************/ /** * @params bool $suppressQuickCreate if true, does not display quick create buttons for lookup * type fields * @param bool $suppressForm if true, does not wrap html in an active form widget * @param array $defaultsByRelatedModelType (<model type> => <array of default arguments>). Used * as arguments to RelationshipsManager JS prototype for each of the quick create buttons. */ // Construct criteria for finding the right form layout. $attributes = array('model' => ucfirst($modelName), 'defaultForm' => 1); // If the $scenario variable is set in the rendering context, a special // different form should be retrieved. $attributes['scenario'] = isset($scenario) ? $scenario : 'Default'; $layout = FormLayout::model()->findByAttributes($attributes); if (isset($layout)) { $layoutData = json_decode($layout->layout, true); } if (isset($layoutData['version']) && version_compare($layoutData['version'], '5.2') >= 0) { $this->widget('FormView', array('model' => $model)); } else { Yii::app()->clientScript->registerScript('formUIScripts', "\n\$('.x2-layout.form-view :input').change(function() {\n \$('#save-button, #save-button1, #save-button2, h2 a.x2-button').addClass('highlight');\n});\n", CClientScript::POS_READY); Yii::app()->clientScript->registerScript('datePickerDefault', "\n \$.datepicker.setDefaults (\$.datepicker.regional['']);\n", CClientScript::POS_READY); Yii::app()->clientScript->registerCssFile(Yii::app()->theme->baseUrl . '/css/recordEdit.css'); Yii::app()->clientScript->registerScript('setFormName', "\nwindow.formName = '{$modelName}';\n", CClientScript::POS_HEAD); $renderFormTags = !isset($form); if (isset($suppressForm) && !$suppressForm || !isset($suppressForm)) { if ($renderFormTags) { $form = $this->beginWidget('CActiveForm', array('id' => $modelName . '-form', 'enableAjaxValidation' => false)); }
public function getLayoutData() { $attributes = array('model' => ucfirst($this->modelName), 'defaultForm' => 1, 'scenario' => $this->scenario); $layout = FormLayout::model()->findByAttributes($attributes); return CJSON::decode($layout->layout); }