<p>These tasks belong to this role.</p> <?php $csrfData = json_encode(array(Yii::app()->request->csrfTokenName => Yii::app()->request->csrfToken)); $ajax = CHtml::ajax(array("url" => array("setTasks", "slug" => $model->slug), "type" => "POST", "data" => 'js:(function(){ var data = ' . $csrfData . '; data.tasks = $("#selectedTasks").sortable("toArray"); return data; }())', "success" => "function(res){\r\n\t\t\t\t\t\t\t\t\t\$('#unselectedTasks li.ui-state-highlight').\r\n\t\t\t\t\t\t\t\t\t\tremoveClass('ui-state-highlight').\r\n\t\t\t\t\t\t\t\t\t\taddClass('ui-state-default');\r\n\t\t\t\t\t\t\t\t\t\$('#selectedTasks li.ui-state-default').\r\n\t\t\t\t\t\t\t\t\t\tremoveClass('ui-state-default').\r\n\t\t\t\t\t\t\t\t\t\taddClass('ui-state-highlight');\r\n\t\t\t\t\t\t\t\t}")); $selectedTasks = array(); foreach ($model->getChildren(AAuthItem::AUTH_TASK) as $item) { $item = AAuthItem::model()->findByPk($item->name); $selectedTasks[$item->name] = $item->createLink(null, null, array("title" => $item->description)); } $unselectedTasks = array(); foreach (AAuthTask::model()->findAll() as $item) { if (isset($selectedTasks[$item->name])) { continue; } $unselectedTasks[$item->name] = $item->createLink(null, null, array("title" => $item->description)); } $this->widget('zii.widgets.jui.CJuiSortable', array('id' => "selectedTasks", 'itemTemplate' => '<li id="{id}" class="ui-state-highlight"><span class="ui-icon ui-icon-arrowthick-2-e-w left"></span> {content}</li>', 'items' => $selectedTasks, 'options' => array('connectWith' => '#unselectedTasks', 'update' => 'js:function(event,ui){ ' . $ajax . ' }', 'delay' => 300))); ?> </div> <div class='grid_6 omega'> <h4>Unselected Tasks</h4> <p>These tasks do not belong to this role.</p> <?php $this->widget('zii.widgets.jui.CJuiSortable', array('id' => "unselectedTasks", 'itemTemplate' => '<li id="{id}" class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-e-w left"></span> {content}</li>', 'items' => $unselectedTasks, 'options' => array('connectWith' => '#selectedTasks', 'delay' => 300))); ?>
/** * Loads a particular task * @throws CHttpException if the model doesn't exist * @param $slug the name of the task to load * @return AAuthTask */ public function loadModel($slug) { $model = AAuthTask::model()->findBySlug($slug); if (!is_object($model)) { throw new CHttpException(404, "No such task"); } return $model; }