var MODULE = this;
return {
xtype: 'GridPanel',
- xns: Roo
+ xns: Roo,
+ listeners : {
+ activate : function() {
+ _this.panel = this;
+ if (_this.grid) {
+ _this.grid.footer.onClick('first');
+ }
+ }
+ },
+ autoScroll : true,
+ background : true,
+ fitContainer : true,
+ fitToframe : true,
+ region : 'center',
+ tableName : 'Person',
+ title : "Rights",
+ grid : {
+ xtype: 'Grid',
+ xns: Roo.grid,
+ listeners : {
+ render : function()
+ {
+ _this.grid = this;
+ if (!_this.dialog) {
+ _this.dialog = Pman.Dialog.PersonEdit;
+
+ }
+ //_this.dialog = Pman.Dialog.FILL_IN
+ if (_this.panel.active) {
+ this.footer.onClick('first');
+ }
+ },
+ rowdblclick : function (_self, rowIndex, e)
+ {
+ if (!_this.dialog) return;
+ _this.dialog.show( this.getDataSource().getAt(rowIndex), function() {
+ _this.grid.footer.onClick('first');
+ });
+ },
+ cellclick : function (_self, rowIndex, columnIndex, e)
+ {
+ _this.dataUpdate = typeof(_this.dataUpdate) =='undefined' ? {} : _this.dataUpdate;
+
+ var di = this.colModel.getDataIndex(columnIndex);
+ var i = di.split('_').shift();
+ var k = di.split('_').pop();
+ if (i != 'accessmask') {
+ return;
+ }
+ var rec = _this.grid.ds.getAt(rowIndex);
+ if(k == 'AA'){
+ var fm = rec.data.FullMask.split('');
+ Roo.each(fm, function(e){
+ rec.set(i+'_'+e, rec.data[i+'_'+k] ? 0 : 1);
+ });
+ }
+ rec.set(i+'_'+k, rec.data[i+'_'+k] ? 0 : 1);
+ //rec.data.accessmask = rec.data.accessmask + rec
+ //Roo.log(rec);
+ _this.dataUpdate[rec.data.id] = rec.data.accessmask;
+
+ //rec.commit();
+
+
+ }
+ },
+ ddGroup : 'groupDD',
+ enableDrag : true,
+ loadMask : true,
+ dataSource : {
+ xtype: 'Store',
+ xns: Roo.data,
+ listeners : {
+ beforeload : function (_self, o)
+ {
+ if (!o.params) {
+ o.params = {}
+ }
+ var s = Pman.Tab.AdminContactsGroup.grid.getSelectionModel().getSelections();
+ if (!s.length) {
+ o.params.group_id = -1;
+ } else {
+ o.params.group_id = s[0].data.id;
+ }
+ if (o.params.group_id < 0) {
+ _this.grid.getView().el.mask("You can not set permissions for that group");
+ return false;
+ }
+ _this.grid.getView().el.unmask();
+ return true;
+
+ },
+ update : function (_self, record, operation)
+ {
+ if (operation != 'commit') {
+ return;
+ }
+ // only used to change active status.
+
+ new Pman.Request({
+ url : baseURL + '/Roo/GroupRights.php',
+ method :'POST',
+ params : {
+ id : record.data.id,
+ active: record.data.active
+
+ },
+ success : function() {
+ // do nothing
+
+ _this.grid.ds.remove(record);
+
+ },
+ failure : function()
+ {
+ Roo.MessageBox.alert("Error", "saving failed", function() {
+ _this.grid.footer.onClick('first');
+ });
+ }
+ });
+ },
+ load : function (_self, records, options)
+ {
+ Roo.each(records, function(e){
+ var k = e.data.accessmask.split('');
+ Roo.each(k, function(ee){
+ e.set('accessmask_'+ee, 1);
+ });
+ if(e.data.accessmask == e.data.FullMask){
+ e.set('accessmask_AA', 1);
+ }
+ });
+ }
+ },
+ remoteSort : true,
+ sortInfo : { field : 'id', direction: 'ASC' },
+ proxy : {
+ xtype: 'HttpProxy',
+ xns: Roo.data,
+ method : 'GET',
+ url : baseURL + '/Admin/GroupRights.php'
+ },
+ reader : {
+ xtype: 'JsonReader',
+ xns: Roo.data,
+ id : 'id',
+ root : 'data',
+ totalProperty : 'total',
+ fields : [
+ {
+ 'name': 'id',
+ 'type': 'int'
+ },
+ {
+ 'name': 'rightname',
+ 'type': 'string'
+ },
+ {
+ 'name': 'descript',
+ 'type': 'string'
+ },
+ {
+ 'name': 'accessmask',
+ 'type': 'string'
+ },
+ {
+ 'name': 'FullMask',
+ 'type': 'string'
+ },
+ {
+ 'name': 'group_id',
+ 'type': 'int'
+ }
+ ]
+ }
+ },
+ footer : {
+ xtype: 'PagingToolbar',
+ xns: Roo,
+ pageSize : 25,
+ displayInfo : true,
+ displayMsg : "Displaying Person{0} - {1} of {2}",
+ emptyMsg : "No Person found",
+ items : [
+ {
+ xtype: 'TextItem',
+ xns: Roo.Toolbar,
+ text : "Drag person to add or remove from group"
+ }
+ ]
+ },
+ toolbar : {
+ xtype: 'Toolbar',
+ xns: Roo,
+ items : [
+ {
+ xtype: 'Button',
+ xns: Roo.Toolbar,
+ listeners : {
+ click : function (_self, e)
+ {
+
+ new Pman.Request({
+ url : baseURL + '/Roo/GroupRights.php',
+ method :'POST',
+ params : _this.dataUpdate,
+ success : function() {
+ // do nothing
+
+ //_this.grid.ds.remove(record);
+
+ },
+ failure : function()
+ {
+ Roo.MessageBox.alert("Error", "saving failed", function() {
+ _this.grid.footer.onClick('first');
+ });
+ }
+ });
+ }
+ },
+ text : "Save"
+ }
+ ]
+ },
+ colModel : [
+ {
+ xtype: 'ColumnModel',
+ xns: Roo.grid,
+ dataIndex : 'accessmask_AA',
+ header : 'All',
+ sortable : false,
+ width : 50,
+ renderer : function(v,x,r) {
+
+ var state = v> 0 ? '-checked' : '';
+
+ return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
+ }
+ },
+ {
+ xtype: 'ColumnModel',
+ xns: Roo.grid,
+ dataIndex : 'rightname',
+ header : 'Module',
+ sortable : false,
+ width : 150,
+ renderer : function(v,x,r) {
+ if(!v){
+ return;
+ }
+ return String.format('<span qtip="{1}">{0}</span>', v.split('.').shift(), v);
+ }
+ },
+ {
+ xtype: 'ColumnModel',
+ xns: Roo.grid,
+ dataIndex : 'descript',
+ header : 'Permission',
+ sortable : false,
+ width : 300,
+ renderer : function(v,x,r)
+ {
+ if (r.json.descript && r.json.descript.length) {
+ return String.format('{0}',r.json.descript);
+ }
+
+ return '???' + v;
+ }
+ },
+ {
+ xtype: 'ColumnModel',
+ xns: Roo.grid,
+ dataIndex : 'accessmask_A',
+ header : 'Add',
+ width : 75,
+ renderer : function(v) {
+ var state = v> 0 ? '-checked' : '';
+
+ return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
+
+ }
+ },
+ {
+ xtype: 'ColumnModel',
+ xns: Roo.grid,
+ dataIndex : 'accessmask_E',
+ header : 'Edit',
+ width : 75,
+ renderer : function(v) {
+ var state = v> 0 ? '-checked' : '';
+
+ return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
+
+ }
+ },
+ {
+ xtype: 'ColumnModel',
+ xns: Roo.grid,
+ dataIndex : 'accessmask_D',
+ header : 'Delete',
+ width : 75,
+ renderer : function(v) {
+ var state = v> 0 ? '-checked' : '';
+
+ return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
+
+ }
+ },
+ {
+ xtype: 'ColumnModel',
+ xns: Roo.grid,
+ dataIndex : 'accessmask_S',
+ header : 'List/View',
+ width : 75,
+ renderer : function(v) {
+ var state = v> 0 ? '-checked' : '';
+
+ return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
+
+ }
+ },
+ {
+ xtype: 'ColumnModel',
+ xns: Roo.grid,
+ dataIndex : 'accessmask_P',
+ header : 'Print/Export',
+ width : 75,
+ renderer : function(v,x,r) {
+
+ var state = v> 0 ? '-checked' : '';
+
+ return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
+
+ }
+ }
+ ]
+ }
};
}
});