예제 #1
0
 /**
  * Generates the TabularInputWidget and the javascript that drives the blocs.
  */
 public function run()
 {
     // Preparing variables.
     $layouts = array();
     $layoutSelect = array();
     $afterAddItem = '';
     $beforeAddItem = '';
     $afterInit = '';
     $sortableStart = '';
     $sortableStop = '';
     $beforeDeleteItem = '';
     $afterDeleteItem = '';
     foreach (Yii::app()->params['blocs'] as $bloc) {
         $modelClassName = 'Bloc' . ucfirst($bloc);
         $newBlocModel = new $modelClassName();
         $newBlocModel->title_anchor = true;
         $newBlocModel->title_page = true;
         $layouts['application.components.blocs.' . $bloc . '.views.admin'] = $newBlocModel;
         $layoutSelect['application.components.blocs.' . $bloc . '.views.admin'] = Yii::t('admin', 'bloc_' . $bloc);
         $afterAddItem .= Yii::app()->cms->blocs[$bloc]->afterAddItem() . "\n";
         $beforeAddItem .= Yii::app()->cms->blocs[$bloc]->beforeAddItem() . "\n";
         $afterInit .= Yii::app()->cms->blocs[$bloc]->afterInit() . "\n";
         $sortableStart .= Yii::app()->cms->blocs[$bloc]->sortableStart() . "\n";
         $sortableStop .= Yii::app()->cms->blocs[$bloc]->sortableStop() . "\n";
         $beforeDeleteItem .= Yii::app()->cms->blocs[$bloc]->beforeDeleteItem() . "\n";
         $afterDeleteItem .= Yii::app()->cms->blocs[$bloc]->afterDeleteItem() . "\n";
     }
     $renderData = array();
     foreach ($this->models as $key => $models) {
         if ($key !== 0) {
             $renderData[$key] = $models;
         }
     }
     // Instanciating widget.
     $this->widget('application.components.widgets.TabularInput.TabularInputWidget', array('id' => $this->id, 'form' => isset($this->form) ? $this->form : null, 'models' => $this->models[0], 'layoutExpression' => "'application.components.blocs.'.lcfirst(mb_substr(get_class(\$model), 4)).'.views.admin'", 'layout' => $layouts, 'layoutSelect' => $layoutSelect, 'itemTitleExpression' => "Yii::t('admin', \$model->tableName())", 'orderAttribute' => 'rank', 'nestedWidgets' => array('{formId}-{itemId}-blocDocumentDocumentForm', '{formId}-{itemId}-blocPeoplePeopleForm', '{formId}-{itemId}-blocCitationCitationForm', '{formId}-{itemId}-blocFeatureFeatureForm'), 'renderData' => $renderData, 'sortable' => array('start' => "js:function(event, ui){\n\t\t\t\t\t" . AdminHelper::tabularInputCkEditorSortableStart() . "\n\t\t\t\t\t" . $sortableStart . "\n\t\t\t\t}", 'stop' => "js:function(event, ui){\n\t\t\t\t\t" . AdminHelper::tabularInputCkEditorSortableStop() . "\n\t\t\t\t\t" . $sortableStop . "\n\t\t\t\t}"), 'beforeDeleteItem' => "function(id, itemId){\n\t\t\t\t" . AdminHelper::tabularInputCkEditorBeforeDeleteItem() . "\n\t\t\t\t" . $beforeDeleteItem . "\n\t\t\t}", 'afterDeleteItem' => "function(id, itemId){\n\t\t\t\t" . $afterDeleteItem . "\n\t\t\t}", 'beforeAddItem' => "function(id, itemId){\n\t\t\t\t" . $beforeAddItem . "\n\t\t\t}", 'afterAddItem' => "function(id, itemId){\n\t\t\t\t" . AdminHelper::tabularInputAfterAddItemDatetimePicker() . "\n\t\t\t\t" . $afterAddItem . "\n\t\t\t}", 'afterInit' => "function(id){\n\t\t\t\t" . $afterInit . "\n\t\t\t}"));
 }