Skip to content

Commit

Permalink
Issue#7, мелкие исправления
Browse files Browse the repository at this point in the history
Создана админ панель, внесены небольшие правки.
  • Loading branch information
quot;brussens committed Feb 6, 2015
1 parent 1f4c2ef commit d71705b
Show file tree
Hide file tree
Showing 13 changed files with 727 additions and 59 deletions.
24 changes: 24 additions & 0 deletions assets/less/message.less
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
font-size:12px;
position:relative;

table {
td {
height:50px;
}
}

&:hover, &:focus, &:active {
border:1px solid #efefef;
cursor:pointer;
Expand Down Expand Up @@ -74,6 +80,24 @@
.message-preview-body {
padding:5px 15px;
border-radius:7px;
overflow:hidden;
max-height:100%;
&:before,
&:after {
content: " "; /* 1 */
display: table; /* 2 */
}

&:after {
clear: both;
}
.hide-image {
color: #ffffff;
background:#67809f;
font-size:12px;
padding:3px 6px;
border-radius:3px;
}
}

&.hot {
Expand Down
2 changes: 1 addition & 1 deletion assets/web/css/message.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

169 changes: 169 additions & 0 deletions controllers/MessageBackendController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
<?php
/**
* Class MessageBackendController - backend message manipulation controller.
*
* @author BrusSENS (Dmitry Brusenskiy) <[email protected]>
* @link http://hoswac.ru
* @copyright 2014 Hoswac ltd.
* @package yupe.modules.message.controllers
* @since 0.2-α
*
*/

class MessageBackendController extends \yupe\components\controllers\BackController
{
public function accessRules()
{
return [
['allow', 'roles' => ['admin']],
['allow', 'actions' => ['create'], 'roles' => ['Message.MessageBackend.Create']],
['allow', 'actions' => ['delete'], 'roles' => ['Message.MessageBackend.Delete']],
['allow', 'actions' => ['index'], 'roles' => ['Message.MessageBackend.Index']],
['allow', 'actions' => ['inlineEdit'], 'roles' => ['Message.MessageBackend.Update']],
['allow', 'actions' => ['update'], 'roles' => ['Message.MessageBackend.Update']],
['allow', 'actions' => ['view'], 'roles' => ['Message.MessageBackend.View']],
['deny']
];
}

public function actions()
{
return [
'inline' => [
'class' => 'yupe\components\actions\YInLineEditAction',
'model' => 'Message',
'validAttributes' => ['is_read']
]
];
}

public function actionIndex()
{
$model = new Message('search');
$model->unsetAttributes(); // clear any default values

$model->setAttributes(
Yii::app()->getRequest()->getParam(
'Message',
[]
)
);

$this->render('index', [
'model' => $model
]);
}

public function actionView($id)
{
$model = Message::model()->findByPk($id)->with(['sender', 'recipient']);
$this->render('view', ['model' => $model]);
}

public function actionCreate()
{
$model = new Message;

if (($data = Yii::app()->getRequest()->getPost('Message')) !== null) {

$model->setAttributes($data);

$model->setAttributes(
[
'is_read' => Message::STATUS_NEW,
'sender_del' => 1,
'recipient_del' => 1
]
);

if ($model->save()) {

Yii::app()->user->setFlash(
yupe\widgets\YFlashMessages::SUCCESS_MESSAGE,
Yii::t('MessageModule.message', 'Message has been sent')
);

$this->redirect(
(array)Yii::app()->getRequest()->getPost(
'submit-type',
['create']
)
);
}
}

$this->render('create',[
'model' => $model
]);
}

public function actionUpdate($id)
{
$model = Message::model()->findByPk($id);

if(!$model) {
throw new CHttpException(404, Yii::t('MessageModule.message', 'Such a message does not exist'));
}

if (($data = Yii::app()->getRequest()->getPost('Message')) !== null) {

$model->setAttributes($data);

$model->setAttributes(
[
'is_read' => Message::STATUS_NEW,
'sender_del' => 1,
'recipient_del' => 1
]
);

if ($model->save()) {

Yii::app()->user->setFlash(
yupe\widgets\YFlashMessages::SUCCESS_MESSAGE,
Yii::t('MessageModule.message', 'Message has been changed')
);

$this->redirect(
(array)Yii::app()->getRequest()->getPost(
'submit-type',
['update']
)
);
}
}

$this->render('update',[
'model' => $model
]);
}

public function actionDelete($id)
{
if (Yii::app()->getRequest()->getIsPostRequest()) {

// we only allow deletion via POST request
if (Message::model()->findByPk($id)->delete()) {
Yii::app()->user->setFlash(
yupe\widgets\YFlashMessages::SUCCESS_MESSAGE,
Yii::t('MessageModule.message', 'Message has been removed')
);
} else {
Yii::app()->user->setFlash(
yupe\widgets\YFlashMessages::ERROR_MESSAGE,
Yii::t('MessageModule.message', 'You can\'t make this changes')
);
}

// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
Yii::app()->getRequest()->getParam('ajax') !== null || $this->redirect(
(array)Yii::app()->getRequest()->getPost('returnUrl', 'index')
);
} else {
throw new CHttpException(
400,
Yii::t('MessageModule.message', 'Bad request. Please don\'t use similar requests anymore')
);
}
}
}
38 changes: 38 additions & 0 deletions messages/ru/message.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
'Message can not be empty' => 'Сообщение не должно быть пустым',
'Recipient can not be empty' => 'Получатель не должен быть пустым',
'Check a recipient' => 'Выберите получателя',
'Check a sender' => 'Выберите отправителя',
'Enter your message text' => 'Введите текст вашего сообщения',
'Send' => 'Отправить',
'Your message has been sent successfully' => 'Ваше сообщение успешно отправлено',
Expand All @@ -28,4 +29,41 @@
'Services' => 'Сервисы',
'Messages list' => 'Список сообщений',
'Create message' => 'Создать сообщение',
'management' => 'управление',
'Management' => 'Управление',
'Find messages' => 'Поиск сообщений',
'Sent date' => 'Дата отправки',
'Recipient' => 'Получатель',
'Sender' => 'Отправитель',
'Body' => 'Содержание',
'ID' => '',
'Private messages - management' => 'Приватные сообщения - управление',
'Private messages - show' => 'Приватные сообщения - просмотр',
'Read' => 'Прочитано',
'Not read' => 'Не прочитано',
'Yes' => 'Да',
'No' => 'Нет',
'Show message' => 'Просмотр сообщения',
'Manage messages' => 'Управление сообщениями',
'Message' => 'Сообщение',
'Edit message' => 'Редактировать сообщение',
'Remove message' => 'Удалить сообщение',
'Do you really want to remove this message?' => 'Вы действительно хотите удалить это сообщение?',
'Create message and continue' => 'Создать сообщение и продолжить',
'Save message and continue' => 'Сохранить сообщение и продолжить',
'Create message and close' => 'Создать сообщение и закрыть',
'Save message and close' => 'Сохранить сообщение и закрыть',
'Fields with' => 'Поля, отмеченные',
'are required' => 'обязательны',
'Create' => 'Создать',
'Edit' => 'Редактирование',
'Private messages - edit message' => 'Приватные сообщения - редактирование сообщения',
'Private messages - create message' => 'Приватные сообщения - создание сообщения',
'Find message' => 'Искать сообщение',
'Reset' => 'Очистить форму',
'Message has been sent' => 'Сообщение отправлено',
'Message has been changed' => 'Сообщение сохранено',
'Message has been removed' => 'Сообщение удалено',
'You can\'t make this changes' => 'Невозможно применить изменения',
'Bad request. Please don\'t use similar requests anymore' => 'Неверный запрос. Пожалуйста, не используйте подобные запросы'
];
55 changes: 55 additions & 0 deletions models/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,27 @@ public function tableName()
return '{{message_message}}';
}

public function attributeLabels()
{
return[
'id' => Yii::t('MessageModule.message', 'ID'),
'sent_at' => Yii::t('MessageModule.message', 'Sent date'),
'recipient_id' => Yii::t('MessageModule.message', 'Recipient'),
'sender_id' => Yii::t('MessageModule.message', 'Sender'),
'body' => Yii::t('MessageModule.message', 'Body'),
'is_read' => Yii::t('MessageModule.message', 'Read'),
];
}

public function rules()
{
return [
['sender_id, recipient_id, body', 'required'],
['sent_at, is_read', 'safe'],
['sender_id, recipient_id', 'safe', 'on' => 'search'],
];
}

/**
* @return array
*/
Expand Down Expand Up @@ -67,4 +88,38 @@ public function getHasAccess()
}
return false;
}

public function getStatusList()
{
return [
self::STATUS_NEW => Yii::t('MessageModule.message', 'No'),
self::STATUS_READ => Yii::t('MessageModule.message', 'Yes'),
];
}

public function getStatus()
{
return $this->getStatusList()[$this->is_read];
}

public function search($pageSize = 10)
{
$criteria = new CDbCriteria();

$criteria->compare('t.id', $this->id);
$criteria->compare('t.sent_at', $this->sent_at, true);
$criteria->compare('t.sender_id', $this->sender_id, true);
$criteria->compare('t.recipient_id', $this->recipient_id, true);
$criteria->with = ['sender', 'recipient'];

return new CActiveDataProvider(get_class($this), array(
'criteria' => $criteria,
'pagination' => array(
'pageSize' => $pageSize,
),
'sort' => array(
'defaultOrder' => 'sent_at DESC',
)
));
}
}
7 changes: 7 additions & 0 deletions views/message/inbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
*
*/
?>
<script>
/*$(document).ready(function(){
$('.message-preview-item').on('hover', function(){
alert($(this).css('height'));
});
});*/
</script>
<div class="row">
<?php
$this->widget('zii.widgets.CListView', [
Expand Down
Loading

0 comments on commit d71705b

Please sign in to comment.