Изменена струкрута данных

1 parent 001a2435
......@@ -19,7 +19,8 @@ Ext.define('MyMA.controller.Transports', {
click: this.onActionColumn
},
'transports > grid': {
edit: this.onEditAction
edit: this.onEditAction,
afterrender: this.onGridRender
}
});
},
......@@ -77,7 +78,9 @@ Ext.define('MyMA.controller.Transports', {
* Search action
*/
onSearch: function(Button) {
this.getTransportsList().getStore().reload({ params: Button.up('toolbar').getValues() });
var store = this.getTransportsList().getStore();
store.getProxy().extraParams = Ext.apply({}, Button.up('toolbar').getValues());
store.reload();
},
......@@ -93,5 +96,13 @@ Ext.define('MyMA.controller.Transports', {
this.store.reload();
}
});
},
/**
* Fires when widget is shown
*/
onGridRender: function(grid) {
grid.getStore().reload();
}
});
Ext.define('MyMA.controller.User', {
extend: 'Ext.app.Controller',
views: ['User'],
stores: ['UserTransport'],
refs: [{
selector: 'user',
ref: 'userWindow'
......@@ -26,9 +27,11 @@ Ext.define('MyMA.controller.User', {
url: Ext.Ajax.getRestUrl('api','user', id),
clientValidation: true,
method: id > 0 ? 'PUT' : 'POST',
params: Ext.applyIf(Ext.copyTo({}, form.getValues(), 'smtp,imap,manager'), {
params: Ext.applyIf(Ext.copyTo({}, form.getValues(), 'smtp,imap,pop3,sieve,manager'), {
smtp: 0,
imap: 0,
pop3: 0,
sieve: 0,
manager: 0
}),
scope: {
......
......@@ -20,6 +20,9 @@ Ext.define('MyMA.controller.Users', {
},
'users actioncolumn': {
click: this.onActionColumn
},
'users > grid': {
afterrender: this.onGridRender
}
});
},
......@@ -82,6 +85,16 @@ Ext.define('MyMA.controller.Users', {
* Search action
*/
onSearch: function(Button) {
this.getUsersList().getStore().reload({ params: Button.up('toolbar').getValues() });
var store = this.getUsersList().getStore();
store.getProxy().extraParams = Ext.apply({}, Button.up('toolbar').getValues());
store.reload();
},
/**
* Fires when widget is shown
*/
onGridRender: function(grid) {
grid.getStore().reload();
}
});
......@@ -7,6 +7,9 @@ Ext.define('MyMA.model.Transports', {
name: 'domain',
type: 'string'
}, {
name: 'rootdir',
type: 'string'
}, {
name: 'transport',
type: 'string'
}],
......
......@@ -3,33 +3,30 @@ Ext.define('MyMA.model.Users', {
fields: [{
name: 'id',
type: 'int'
}, {
name: 'name',
type: 'string'
}, {
name: 'login',
type: 'string'
}, {
name: 'passwd',
type: 'string'
}, {
}, 'name', 'login', 'passwd', {
name: 'uid',
type: 'int',
defaultValue: 8
}, {
name: 'domid',
type: 'int'
}, {
name: 'gid',
type: 'int',
defaultValue: 12
}, {
name: 'maildir',
type: 'string'
}, {
name: 'smtp',
type: 'int'
}, {
name: 'imap',
type: 'int'
}, {
name: 'pop3',
type: 'int'
}, {
name: 'sieve',
type: 'int'
}, {
name: 'quota',
type: 'int',
defaultValue: 10000000
......@@ -42,12 +39,7 @@ Ext.define('MyMA.model.Users', {
}, {
name: 'backup_last',
type: 'date'
}],
validations: [{
type: 'format',
field: 'maildir',
matcher: /^\/[a-z]\.ru\/[a-z_0-9]\/Maildir\/$/
}],
}, 'domain' ],
proxy: {
type: 'rest',
url: Ext.Ajax.getRestUrl('api/user'),
......
Ext.define('MyMA.store.UserTransport', {
extend: 'Ext.data.Store',
requires: 'MyMA.model.Transports',
model: 'MyMA.model.Transports',
autoLoad: true,
remoteSort: true,
pageSize: 100
});
......@@ -52,7 +52,15 @@ Ext.define('MyMA.view.Transports', {
xtype: 'textfield',
allowBlank: false
},
flex: 1
flex: 2
}, {
header: 'Root direcotry for the users',
dataIndex: 'rootdir',
flex: 1,
editor: {
xtype: 'textfield',
allowBlank: false
}
}, {
header: 'Transport',
dataIndex: 'transport'
......
......@@ -40,12 +40,41 @@ Ext.define('MyMA.view.User', {
name: 'imap',
inputValue: 1
}, {
xtype: 'checkbox',
fieldLabel: 'POP3',
name: 'pop3',
inputValue: 1
}, {
xtype: 'checkbox',
fieldLabel: 'Sieve',
name: 'sieve',
inputValue: 1
}, {
fieldLabel: 'Name',
name: 'name'
}, {
xtype: 'fieldcontainer',
layout: 'hbox',
fieldLabel: 'Login',
items: [{
xtype: 'textfield',
name: 'login',
vtype: 'email'
width: 100,
allowBlank: false
}, {
xtype: 'tbspacer',
width: 5
}, {
xtype: 'combo',
name: 'domid',
allowBlank: false,
valueField: 'id',
displayField: 'domain',
store: 'UserTransport',
editable: false,
queryMode: 'local',
flex: 1
}]
}, {
fieldLabel: 'Password',
name: 'passwd'
......@@ -64,9 +93,6 @@ Ext.define('MyMA.view.User', {
anchor: '50%',
value: 12
}, {
fieldLabel: 'Mail directory',
name: 'maildir'
}, {
xtype: 'numberfield',
name: 'quota',
allowDecimal: false,
......
......@@ -104,7 +104,10 @@ Ext.define('MyMA.view.Users', {
}, {
header: 'Login',
dataIndex: 'login',
width: 120
width: 120,
renderer: function(value, meta, record) {
return value + '@' + record.get('domain');
}
}, {
header: 'Password',
hidden: true,
......@@ -120,9 +123,6 @@ Ext.define('MyMA.view.Users', {
hidden: true,
width: 40
}, {
header: 'Mail directory',
dataIndex: 'maildir'
}, {
header: 'SMTP',
dataIndex: 'smtp',
width: 55,
......@@ -159,6 +159,42 @@ Ext.define('MyMA.view.Users', {
return 'No';
}
}, {
header: 'POP3',
dataIndex: 'pop3',
width: 55,
editor: {
xtype: 'combo',
valueField: 'id',
displayField: 'name',
triggerAction: 'all',
editable: false,
store: 'Choice'
},
renderer: function(value) {
if(value==1) {
return 'Yes';
}
return 'No';
}
}, {
header: 'Sieve',
dataIndex: 'sieve',
width: 55,
editor: {
xtype: 'combo',
valueField: 'id',
displayField: 'name',
triggerAction: 'all',
editable: false,
store: 'Choice'
},
renderer: function(value) {
if(value==1) {
return 'Yes';
}
return 'No';
}
}, {
header: 'Quota',
dataIndex: 'quota',
editor: {
......
......@@ -309,10 +309,12 @@ Ext.define('MyMA.view.Users', {
}, {
header: 'uid',
dataIndex: 'uid',
hidden: true,
width: 40
}, {
header: 'gid',
dataIndex: 'gid',
hidden: true,
width: 40
}, {
header: 'Mail directory',
......@@ -320,6 +322,7 @@ Ext.define('MyMA.view.Users', {
}, {
header: 'SMTP',
dataIndex: 'smtp',
width: 55,
editor: {
xtype: 'combo',
valueField: 'id',
......@@ -337,6 +340,7 @@ Ext.define('MyMA.view.Users', {
}, {
header: 'IMAP',
dataIndex: 'imap',
width: 55,
editor: {
xtype: 'combo',
valueField: 'id',
......@@ -359,6 +363,16 @@ Ext.define('MyMA.view.Users', {
allowDecimal: false
}
}, {
header: 'Backup (days)',
dataIndex: 'backup',
renderer: function(value) {
return value == 0 ? 'Off' : value;
}
}, {
header: 'Last Backup',
dataIndex: 'backup_last',
renderer: Ext.util.Format.dateRenderer('d.m.Y H:i')
}, {
xtype: 'actioncolumn',
width: 30,
items: [{
......@@ -445,6 +459,14 @@ Ext.define('MyMA.view.User', {
fieldLabel: 'Quota',
anchor: '60%',
value: 100000000
}, {
xtype: 'numberfield',
name: 'backup',
allowDecimal: false,
fieldLabel: 'Backup (day)',
anchor: '60%',
maxValue: 7,
minValue: 0
}]
}]
});
......
......@@ -29,16 +29,18 @@ class UserIdentity extends CUserIdentity
return !$this->errorCode;
}
$manager = Manager::model()->find(array(
"select" => array("`id`", "`name`", "`login`"),
$manager = Manager::model()->with('access')->find(array(
"select" => array("id", "name", "login"),
"condition" => implode(" AND ", array(
"`manager` = :manager",
"`login` = :login",
"`passwd` = :pass"
"manager = :manager",
"login = :login",
"access.domain = :transport",
"passwd = :pass"
)),
"params" => array(
":manager" => 1,
":login" => $this->username,
":login" => $this->getPartOfName($this->username, 'name'),
":transport" => $this->getPartOfName($this->username, 'domain'),
":pass" => $this->password
)
));
......@@ -62,4 +64,25 @@ class UserIdentity extends CUserIdentity
{
return $this->_id;
}
/**
* Returns part of email name
*/
private function getPartOfName( $param = "", $name = "name")
{
$param = trim($param);
$param = explode("@", $param);
if(count($param) > 2) {
$param = array_slice($param, 0, 2);
}
switch($name) {
case 'name': return $param[0];
case 'domain': return $param[1];
default: return implode("@", $params);
}
}
}
\ No newline at end of file
......@@ -18,22 +18,6 @@ class UserController extends WRestController
public function actions()
{
return array(
'list' => array(
'class' => 'WRestListAction',
'filterBy' => array(
'compare' => array(
'column' => array(
'name' => 'query',
'login' => 'query'
),
'partial' => true,
'operator' => 'OR'
)
),
'limit' => 'limit',
'page' => 'page',
'order' => 'order'
),
'delete' => 'WRestDeleteAction',
'get' => 'WRestGetAction',
'create' => 'WRestCreateAction',
......@@ -43,4 +27,45 @@ class UserController extends WRestController
)
);
}
public function actionList()
{
$criteria = new CDbCriteria();
$model = $this->getModel();
$criteria->alias = 'user';
$criteria->limit = (int)(($limit = Yii::app()->request->getParam('limit')) ? $limit : -1);
$page = (int)Yii::app()->request->getParam('page') - 1;
$criteria->offset = ($offset = $limit * $page) ? $offset : 0;
if(($order = Yii::app()->request->getParam("sort")) ? $order : null) {
$order = json_decode($order);
$sort = array();
foreach($order as $item) {
$sort[] = sprintf("user.%s %s", $item->property, $item->direction);
}
$criteria->order = implode(", ", $sort);
}
$models = $model->with('transport')->findAll($criteria);
if ($models) {
foreach ($models as $item) {
$result[] = array_merge($item->getAllAttributes(), array("domain" => $item->transport->domain));
}
}
$result = array_merge($result, array(
'total' => $model->count($criteria)
));
$this->sendResponse(200, $result);
}
}
......@@ -32,4 +32,16 @@ class Manager extends CActiveRecord
{
return 'id';
}
public function relations()
{
return array(
"access" => array(
self::HAS_ONE,
"Transport",
array( "id" => "domid" ),
"joinType" => "LEFT JOIN"
)
);
}
}
......@@ -50,8 +50,8 @@ class Transport extends ActiveRecord
*/
public function rules(){
return array(
array('domain, transport', 'required', 'on' => 'insert'),
array('domain, transport', 'required', 'on' => 'update')
array('domain, transport, rootdir', 'required', 'on' => 'insert'),
array('domain, transport, rootdir', 'required', 'on' => 'update')
);
}
}
......@@ -47,19 +47,33 @@ class User extends ActiveRecord
/**
* Transport relation
*/
public function relations()
{
return array(
"transport" => array(
self::HAS_ONE,
"Transport",
array( "id" => "domid" ),
"joinType" => "LEFT JOIN"
)
);
}
/**
* Model rules
*/
public function rules()
{
return array(
array('name, login, passwd, uid, gid, maildir, smtp, imap, quota, manager, backup', 'default', 'on' => 'update'),
array('login, passwd, maildir', 'required', 'on' => 'update'),
array('smtp, imap, manager', 'numerical', 'on' => 'update', 'allowEmpty' => false, 'integerOnly' => true),
array('login', 'email', 'on' => 'update'),
array('name, login, passwd, uid, gid, maildir, smtp, imap, quota, manager', 'default', 'on' => 'insert'),
array('login, passwd, maildir', 'required', 'on' => 'insert'),
array('smtp, imap, manager', 'numerical', 'on' => 'insert', 'allowEmpty' => false, 'integerOnly' => true),
array('login', 'email', 'on' => 'insert')
array('name, login, passwd, uid, gid, domid, smtp, imap, pop3, sieve, quota, manager, backup', 'default', 'on' => 'update'),
array('login, passwd, domid', 'required', 'on' => 'update'),
array('smtp, imap, pop3, sieve, manager', 'numerical', 'on' => 'update', 'allowEmpty' => false, 'integerOnly' => true),
array('name, login, passwd, uid, gid, domid, smtp, imap, pop3, sieve, quota, manager', 'default', 'on' => 'insert'),
array('login, passwd, domid', 'required', 'on' => 'insert'),
array('smtp, imap, pop3, sieve, domid, manager', 'numerical', 'on' => 'insert', 'allowEmpty' => false, 'integerOnly' => true)
);
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!