From 10044c266f5f3609bc0449d36ec66ab178d7736c Mon Sep 17 00:00:00 2001 From: GrandMaster Date: Mon, 2 Sep 2013 15:41:03 +0300 Subject: [PATCH 1/5] added page and content editing in admin --- protected/config/main.php | 102 +-------- protected/models/Page.php | 91 ++++++++ protected/models/Pages.php | 75 +++++++ .../admin/controllers/PagesController.php | 117 ++++++++++ .../modules/admin/views/layouts/main.php | 11 +- protected/modules/admin/views/page/_grid.php | 207 ++++++++++++++++++ protected/modules/admin/views/page/create.php | 99 +++++++++ protected/modules/admin/views/page/index.php | 22 ++ protected/modules/admin/views/page/update.php | 119 ++++++++++ protected/modules/admin/views/pages/_grid.php | 207 ++++++++++++++++++ .../modules/admin/views/pages/create.php | 52 +++++ protected/modules/admin/views/pages/index.php | 22 ++ .../modules/admin/views/pages/update.php | 81 +++++++ .../modules/admin/views/partner/index.php | 4 +- protected/modules/admin/views/user/index.php | 2 +- protected/views/layouts/main.php | 13 -- protected/yiic.bat | 2 +- static/app/js/main.js | 6 + static/app/js/router.js | 3 +- static/css/form.css | 4 + 20 files changed, 1119 insertions(+), 120 deletions(-) create mode 100644 protected/models/Page.php create mode 100644 protected/models/Pages.php create mode 100644 protected/modules/admin/controllers/PagesController.php create mode 100644 protected/modules/admin/views/page/_grid.php create mode 100644 protected/modules/admin/views/page/create.php create mode 100644 protected/modules/admin/views/page/index.php create mode 100644 protected/modules/admin/views/page/update.php create mode 100644 protected/modules/admin/views/pages/_grid.php create mode 100644 protected/modules/admin/views/pages/create.php create mode 100644 protected/modules/admin/views/pages/index.php create mode 100644 protected/modules/admin/views/pages/update.php diff --git a/protected/config/main.php b/protected/config/main.php index 968933d..4a2adf3 100644 --- a/protected/config/main.php +++ b/protected/config/main.php @@ -15,13 +15,9 @@ 'application.extensions.sweekit.Sweeml', 'application.extensions.MobileDetect.Mobile_Detect', 'application.extensions.calc.eqEOS', - 'ext.eoauth.*', - 'ext.eoauth.lib.*', - 'ext.lightopenid.*', - 'ext.eauth.*', - 'ext.eauth.services.*', 'application.vendors', 'ext.yii-mail.YiiMailMessage', + 'ext.imperavi-redactor-widget.ImperaviRedactorWidget', ), 'modules' => array( 'gii' => array( @@ -35,9 +31,6 @@ 'admin' => array( 'defaultController' =>'user', ), - 'exel' => array( - 'defaultController' =>'index', - ), 'mailingList'=>array( 'defaultController'=>'email', ), @@ -68,7 +61,7 @@ ), //'session' => array( //'timeout' => 86400, - //), + //), 'request' => array( 'class' => 'HttpRequest', 'enableCsrfValidation' => true, @@ -158,9 +151,6 @@ 'class' => 'ext.image.ImageComponent', 'driver' => 'Gd', ), - 'loid' => array( - 'class' => 'ext.lightopenid.loid', - ), 'mail' => array( 'class' => 'ext.yii-mail.YiiMail', 'transportType' => 'php', @@ -168,94 +158,6 @@ 'logging' => false, 'dryRun' => false ), - 'eauth' => array( - 'class' => 'ext.eauth.EAuth', - 'popup' => true, // Use the popup window instead of redirecting. - 'cache' => false, // Cache component name or false to disable cache. Defaults to 'cache'. - 'cacheExpire' => 0, // Cache lifetime. Defaults to 0 - means unlimited. - 'services' => array(// You can change the providers and their classes. -// 'google' => array( -// 'class' => 'GoogleOpenIDService', -// ), -// 'yandex' => array( -// 'class' => 'YandexOpenIDService', -// ), -// 'twitter' => array( - // register your app here: https://dev.twitter.com/apps/new -// 'class' => 'TwitterOAuthService', -// 'key' => '...', -// 'secret' => '...', -// ), - 'google_oauth' => array( - // register your app here: https://code.google.com/apis/console/ - 'class' => 'CustomGoogleService', - 'client_id' => '121482514649-7orl2mum6mco54pe33rvl743j9bp2353.apps.googleusercontent.com', - 'client_secret' => 's19p91oTKTLJvvMKGVEi_kebs', - 'title' => 'Google (OAuth)', - ), -// 'yandex_oauth' => array( - // register your app here: https://oauth.yandex.ru/client/my -// 'class' => 'YandexOAuthService', -// 'client_id' => '...', -// 'client_secret' => '...', -// 'title' => 'Yandex (OAuth)', -// ), - 'facebook' => array( - // register your app here: https://developers.facebook.com/apps/ - 'class' => 'CustomFacebookService', - 'client_id' => '689556884392541', - 'client_secret' => '5af00ac919412ac2dcaa416e29adeec3', - ), -// 'linkedin' => array( - // register your app here: https://www.linkedin.com/secure/developer -// 'class' => 'LinkedinOAuthService', -// 'key' => '...', -// 'secret' => '...', -// ), -// 'github' => array( - // register your app here: https://github.com/settings/applications -// 'class' => 'GitHubOAuthService', -// 'client_id' => '...', -// 'client_secret' => '...', -// ), -// 'live' => array( - // register your app here: https://manage.dev.live.com/Applications/Index -// 'class' => 'LiveOAuthService', -// 'client_id' => '...', -// 'client_secret' => '...', -// ), - 'vkontakte' => array( - // register your app here: https://vk.com/editapp?act=create&site=1 - 'class' => 'CustomVKontakteService', - 'client_id' => '3792586', - 'client_secret' => 'VY2T0rp0SMkHtyRmrTSJ', - ), -// 'mailru' => array( - // register your app here: http://api.mail.ru/sites/my/add -// 'class' => 'MailruOAuthService', -// 'client_id' => '...', -// 'client_secret' => '...', -// ), -// 'moikrug' => array( - // register your app here: https://oauth.yandex.ru/client/my -// 'class' => 'MoikrugOAuthService', -// 'client_id' => '...', -// 'client_secret' => '...', -// ), -// 'odnoklassniki' => array( - // register your app here: http://dev.odnoklassniki.ru/wiki/pages/viewpage.action?pageId=13992188 - // ... or here: http://www.odnoklassniki.ru/dk?st.cmd=appsInfoMyDevList&st._aid=Apps_Info_MyDev -// 'class' => 'OdnoklassnikiOAuthService', -// 'client_id' => '...', -// 'client_public' => '...', -// 'client_secret' => '...', -// 'title' => 'Odnokl.', -// ), - ), - ), - 'excel'=>array( - 'class'=>'application.extensions.PHPExcel', - ), ), 'params' => array( 'adminEmail' => 'dobrynina@astrafit.com', diff --git a/protected/models/Page.php b/protected/models/Page.php new file mode 100644 index 0000000..24c8f1a --- /dev/null +++ b/protected/models/Page.php @@ -0,0 +1,91 @@ + Yii::t('page', 'Имя'), + 'info' => Yii::t('page', 'Информация'), + 'body' => Yii::t('page', 'Контент'), + 'weight' => Yii::t('page', 'Позиция'), + 'pages_id'=> Yii::t('page', 'Где отображать'), + 'create_time'=>Yii::t('page', 'Дата создания'), + ); + } + + public function scopes() { + return array( + 'notBlocked' => array( + 'condition' => 'is_blocked=0', + ), + ); + } + + public function getPages() { + return self::model()->findAll(); + } + + public function rules() { + return array( + array('title', 'required', 'on' => 'insert,update'), + array('info', 'required', 'on' => 'insert,update'), + //array('pages_id', 'required', 'on' => 'insert,update'), + array('weight', 'required', 'on' => 'insert,update'), + array('body', 'required', 'on' => 'insert,update'), + array('name,info,body,weight', 'safe', 'on' => 'search,insert,update'), + ); + //$charset = Yii::app()->charset; + } + + public function getId() { + return $this->_id; + } + + public function getName() { + return $this->name; + } + + public function getIsBlocked() { + return $this->is_blocked; + } + + public function getInfo() { + return $this->info; + } + + public function getWeight() { + return $this->weight; + } + + public function getBody() { + return $this->body; + } + + public function getPagesId() { + return $this->pages_id; + } + +} diff --git a/protected/models/Pages.php b/protected/models/Pages.php new file mode 100644 index 0000000..9a275ad --- /dev/null +++ b/protected/models/Pages.php @@ -0,0 +1,75 @@ + Yii::t('pages', 'Имя'), + 'info' => Yii::t('pages', 'Информация'), + 'weight' => Yii::t('pages', 'Позиция'), + ); + } + + public function scopes() { + return array( + 'notBlocked' => array( + 'condition' => 'is_blocked=0', + ), + ); + } + + public function getPages() { + return self::model()->findAll(); + } + + public function rules() { + return array( + array('name', 'required', 'on' => 'insert,update'), + array('info', 'required', 'on' => 'insert,update'), + array('name,info,weight', 'safe', 'on' => 'search,insert,update'), + ); + //$charset = Yii::app()->charset; + } + + public function getId() { + return $this->_id; + } + + public function getName() { + return $this->name; + } + + public function getVisible() { + return $this->visible; + } + + public function getInfo() { + return $this->info; + } + + public function getWeight() { + return $this->weight; + } + + +} diff --git a/protected/modules/admin/controllers/PagesController.php b/protected/modules/admin/controllers/PagesController.php new file mode 100644 index 0000000..5264192 --- /dev/null +++ b/protected/modules/admin/controllers/PagesController.php @@ -0,0 +1,117 @@ + array( + 'class' => 'application.modules.admin.components.actions.BlockAction', + 'modelClass' => 'Pages', + 'message_block' => Yii::t('infoMessages', 'Страница разблокирован!'), + 'errorMessage_block' => Yii::t('infoMessages', 'Произошла ошибка при разблокировании страницы!'), + 'message_unBlock' => Yii::t('infoMessages', 'Страница заблокирован!'), + 'errorMessage_unBlock' => Yii::t('infoMessages', 'Произошла ошибка при блокировании страницы!'), + ), + 'markAsDeleted' => array( + 'class' => 'application.modules.admin.components.actions.MarkAsDeletedAction', + 'modelClass' => 'Pages', + 'message_mark' => Yii::t('infoMessages', 'Страница удалена!'), + 'errorMessage_mark' => Yii::t('infoMessages', 'Произошла ошибка при удалении страницы!'), + ) + ); + } + + public function actionIndex() { + $search = new Pages('search'); + $search->unsetAttributes(); + + if (!is_null(Yii::app()->request->getQuery('Pages'))) + $search->attributes = Yii::app()->request->getQuery('Pages'); + + $criteria = new CDbCriteria; + $criteria->compare('t.name', $search->name, true); + $criteria->compare('t.is_blocked', array('0' => 0, '1' => 1)); + + $dataProvider = new ActiveDataProvider('Pages', array( + 'criteria' => $criteria, + 'sort' => array( + 'defaultOrder' => array('weight' => true), + 'sortVar' => 'sort', + ), + 'pagination' => array( + 'pageVar' => 'page', + 'sizeVar' => 'size', + 'pageSize' => Yii::app()->params['defaultPageSize'], + 'sizeOptions' => Yii::app()->params['sizeOptions'], + ), + )); + $this->render('index', + array('dataProvider'=>$dataProvider,'search'=>$search) + ); + } + + public function actionCreate() { + $model = new Pages; + + if (!is_null(Yii::app()->request->getPost('ajax')) && Yii::app()->request->getPost('ajax') === 'create-user-form') + $this->performAjaxValidation($model); + + if (!is_null(Yii::app()->request->getPost('Pages'))) { + $model->attributes = Yii::app()->request->getPost('Pages'); + $model->is_blocked = 0; + if(!$model->weight) + $model->weight = 1; + //var_dump($model);die; + if ($model->save()) { + //save client role for user + $this->setFlashSuccess(Yii::t('infoMessages', 'Новая страница добавлена!')); + $this->redirect(array('index')); + } + } + + $this->render('create', array( + 'model' => $model + )); + } + + public function actionUpdate() { + $model = $this->loadModel(); + + if (!is_null(Yii::app()->request->getPost('ajax')) && Yii::app()->request->getPost('ajax') === 'update-user-form') { + $this->performAjaxValidation($model); + } + + if ($model === null) + throw new CHttpException(404); + + if (!is_null(Yii::app()->request->getPost('Pages'))) { + $model->attributes = Yii::app()->request->getPost('Pages'); + + if ($model->save()) { + $this->setFlashSuccess(Yii::t('infoMessages', 'Данные обновлены!')); + $this->redirect(array('index')); + } + } + + $this->render('update', array( + 'model' => $model, + 'uid' => $model->id + )); + } +} diff --git a/protected/modules/admin/views/layouts/main.php b/protected/modules/admin/views/layouts/main.php index 3d81f51..f52d2ba 100644 --- a/protected/modules/admin/views/layouts/main.php +++ b/protected/modules/admin/views/layouts/main.php @@ -58,8 +58,15 @@ -
  • - +
  • + +