public function actionUpdate($catPk, $pk = null, $otherParams = array())
	{
		$model = $this->loadModel($catPk, $pk, 'update');

        if (Y::isAjaxRequest()) {
            //ajax validation
            $this->performAjaxValidation($model);

            if (isset($_POST[get_class($model)])) {
                $model->attributes = $_POST[get_class($model)];

                if ($model->save())
                    Y::hooks()->cmsDataTypeUpdateSuccess($this, array('model'=>$model));
                else
                    Y::hooks()->cmsDataTypeUpdateError($this, array('model'=>$model));
            }
            Y::end();
        }

        $opts = CMap::mergeArray($otherParams, array(
			'model' => $model
		));
		if (!isset($opts['cat']) && isset($model->category))
			$opts['cat'] = $model->category;

		$this->render('update', $opts);
	}
Пример #2
0
 /**
  * This is the action to handle external exceptions.
  */
 public function actionError()
 {
     if ($error = Yii::app()->errorHandler->error){
         if (Y::isAjaxRequest()){
             echo $error['message'];
         }
         else {
             echo CHtml::tag('h2', array(), 'Error ' . $error['code']);
             echo CHtml::tag('div', array(), CHtml::encode($error['message']));
         }
     }
 }
Пример #3
0
    public function ajaxExclude($names)
    {
        if (Y::isAjaxRequest()) {
            $files = array();
            foreach ((array)$names as $name)
                $files[$name] = false;

            Y::clientScript()->scriptMap = CMap::mergeArray(
                Y::clientScript()->scriptMap,
                $files
            );
        }
    }
	public function renderContent()
	{
        if (Y::isAjaxRequest()) {
            $this->$_GET['do'];
            Y::end();
        }
        $route = isset($_GET['users']) ? urldecode($_GET['users']) : '';

        if (Y::isGuest()) {
            Yii::app()->runController('users/'.$route);
        } else {
            //cabinet
            $model = $this->module->user();
            $this->render('user-info',array(
                'model'=>$model,
                'profile'=>$model->profile,
            ));
        }
	}
Пример #5
0
    /**
     * set $model->$field in next value, using $values array
     * @param string $query_id
     * @param model $model
     * @param string $field
     * @param array $values
     */
    protected function ajaxSetNextValue($query_id, $model, $field, $values)
    {
        if (Y::isAjaxRequest() && isset($_GET[$query_id])){
            $model->scenario = $query_id;
            $model = $model->find(array('condition' => $model->idAttr . '=' . (int)$_GET['model_id']));

            //cycle shift
            while ($model->$field != ($values[] = array_shift($values))) {}

            //set next value
            $model->$field = array_shift($values);

            if ($model->save())
                echo $model->$field;
            else
                print_r($model->getErrors());

            Y::end();
        }
    }
	public function actionGetRelevantCategories()
	{
		if (!Y::isAjaxRequest())
            Y::end();
        
		if(!isset($_POST['catId']))
			throw new CException("Не найден параметр catId");

		if(!isset($_POST['action']))
			throw new CException("Не найден параметр catId");
		
		$cat = Category::model()->findByPk($_POST['catId']);
		
		$name = ModelFactory::t($cat->type);
		if (ModelFactory::isAllowCopy($cat->type)) {
			echo "<p>Категория имеет тип '$name', поэтому все '$name' могут быть скопированы в одну из следующих категорий.</p>".
					"<hr/><p>Все шаблоны с одинаковыми алиасами будут утеряны</p>";
		} else {
			echo "Категория имеет тип '$name', данные такого типа не могут быть сохранены в другой категории.";
			Y::end();
		}	
		
		$cats = Category::model()->findAll("type='".$cat->type."' AND id!=".$cat->pk);
		
		$res = '<ul>';
		foreach ($cats as $target) {
			if ($_POST['action'] == 'copy')
				$res .= '<li>'.$cat->getCopyDataLink($target).'</li>';
			elseif ($_POST['action'] == 'cut')
				$res .= '<li>'.$cat->getCutDataLink($target).'</li>';
		}
		echo $res.'</ul>';	 
	}
	public function actionDelete($catPk, $pk)
	{
		// we only allow deletion via POST request
		$model = $this->loadModel($catPk, $pk);

		//save admin url for redirect
		if (isset($model->adminUrl))
			$adminUrl = $model->adminUrl;
			
		$model->delete();

		// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
		if(!Y::isAjaxRequest()) {
        	if(isset($_POST['returnUrl'])) 
        		$this->redirect($_POST['returnUrl']);
        	else
        		$this->redirect($adminUrl);
		}
	}