123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257 |
- Ext.ux.buildChildGrid = function(conf) {
- var windowName = conf.windowName;
- var gridName = conf.gridName;
- var fields = conf.fields;
- var queryUrl = conf.queryUrl;
- var authUrl = conf.authUrl;
- for (var i = 0; i < fields.length; i++) {
- fields[i].dataIndex = fields[i].name;
- }
- if (this.getSelections().length <= 0){
- Ext.Msg.alert('提示', '请选择需要操作的记录!');
- return;
- }
- if (this.getSelections().length > 1){
- Ext.Msg.alert('提示', '不能选择多行记录!');
- return;
- }
- var parentId = this.getSelections()[0].get('id');
- if (!this[windowName]) {
- // 建一个角色数据映射数组
- var r = Ext.data.Record.create(fields);
- //设置数据仓库
- var ds = new Ext.data.Store({
- proxy: new Ext.data.HttpProxy({url: queryUrl}),
- reader: new Ext.data.JsonReader({
- root: '',
- totalProperty: 'totalCount'
- }, r),
- // 远端排序开关
- remoteSort: false
- });
- //创建表格头格式
- var cm = new Ext.grid.ColumnModel(fields);
- var parentGrid = this;
- var grid = new Ext.grid.GridPanel( {
- ds: ds,
- cm: cm,
- selModel: new Ext.grid.RowSelectionModel({singleSelect:true}),
- enableColLock:false,
- loadMask: false,
- viewConfig: {
- forceFit: true
- },
- bbar: new Ext.Toolbar([{
- pressed: true,
- enableToggle:true,
- text: '授权',
- toggleHandler: function(){
- //授权事件
- var childModel = grid.getSelections();
- var parentModel = parentGrid.getSelections();
- if (childModel.length <= 0) {
- Ext.Msg.alert('提示', '请选择至少一条记录!');
- return;
- } else if(childModel.length == 1) {
- var parentId = parentModel[0].get('id');
- var childId = childModel[0].get('id');
- Ext.Ajax.request({
- url: authUrl,
- success: function(response) {
- var o = Ext.decode(response.responseText);
- if (o.success) {
- Ext.Msg.alert('提示', '操作成功!');
- ds.reload();
- } else {
- Ext.Msg.alert('提示', o.msg);
- }
- },
- params: 'auth=true&parentId=' + ds.baseParams.id + '&childId=' + childId
- });
- } else {
- for(var i = 0, len = childModel.length; i < len; i++){
- var parentId = parentModel[0].get('id');
- var childId = childModel[i].get('id');
- Ext.Ajax.request({
- url: authUrl,
- success: function(response) {
- var o = Ext.decode(response.responseText);
- if (o.success) {
- Ext.Msg.alert('提示', '操作成功!');
- ds.reload();
- } else {
- Ext.Msg.alert('提示', o.msg);
- }
- },
- params: 'auth=true&parentId=' + ds.baseParams.id + '&childId=' + childId
- });
- }
- }
- }
- }, '-', {
- pressed: true,
- enableToggle: true,
- text: '取消授权',
- toggleHandler: function() {
- //授权事件
- var childModel = grid.getSelections();
- var parentModel = parentGrid.getSelections();
- if (childModel.length <= 0) {
- Ext.Msg.alert('提示', '请选择至少一条记录!');
- return;
- } else if(childModel.length == 1) {
- var parentId = parentModel[0].get('id');
- var childId = childModel[0].get('id');
- Ext.Ajax.request({
- url: authUrl,
- success: function(response) {
- var o = Ext.decode(response.responseText);
- if (o.success) {
- Ext.Msg.alert('提示', '操作成功!');
- ds.reload();
- } else {
- Ext.Msg.alert('提示', o.msg);
- }
- },
- params: 'auth=false&parentId=' + ds.baseParams.id + '&childId=' + childId
- });
- } else {
- for(var i = 0, len = childModel.length; i < len; i++){
- var parentId = parentModel[0].get('id');
- var childId = childModel[i].get('id');
- Ext.Ajax.request({
- url: authUrl,
- success: function(response) {
- var o = Ext.decode(response.responseText);
- if (o.success) {
- Ext.Msg.alert('提示', '操作成功!');
- ds.reload();
- } else {
- Ext.Msg.alert('提示', o.msg);
- }
- },
- params: 'auth=false&parentId=' + ds.baseParams.id + '&childId=' + childId
- });
- }
- }
- }
- }])
- });
- this[gridName] = grid;
- this[windowName] = new Ext.Window({
- layout: 'fit',
- height: 300,
- width: 400,
- closeAction: 'hide',
- items: [grid]
- });
- }
- this[windowName].show();
- this[gridName].getStore().baseParams.id = parentId;
- this[gridName].getStore().reload();
- };
- //
- Ext.ux.buildChildGridForTree = function(conf) {
- var windowName = conf.windowName;
- var gridName = conf.gridName;
- var fields = conf.fields;
- var queryUrl = conf.queryUrl;
- var authUrl = conf.authUrl;
- for (var i = 0; i < fields.length; i++) {
- fields[i].dataIndex = fields[i].name;
- }
- var node = this.getSelectionModel().getSelectedNode();
- if (node == null) {
- Ext.Msg.alert('提示', '请选择需要操作的记录!');
- return;
- }
- var parentId = node.id;
- if (!this[windowName]) {
- // 建一个角色数据映射数组
- var r = Ext.data.Record.create(fields);
- //设置数据仓库
- var ds = new Ext.data.Store({
- proxy: new Ext.data.HttpProxy({url: queryUrl}),
- reader: new Ext.data.JsonReader({
- root: '',
- totalProperty: 'totalCount'
- }, r),
- // 远端排序开关
- remoteSort: false
- });
- //创建表格头格式
- var cm = new Ext.grid.ColumnModel(fields);
- var grid = new Ext.grid.GridPanel( {
- ds: ds,
- cm: cm,
- selModel: new Ext.grid.RowSelectionModel({singleSelect:true}),
- enableColLock:false,
- loadMask: false,
- viewConfig: {
- forceFit: true
- },
- bbar: new Ext.Toolbar([{
- pressed: true,
- enableToggle:true,
- text: '授权',
- toggleHandler: function(){
- //授权事件
- var childModel = grid.getSelections();
- if (childModel.length <= 0) {
- Ext.Msg.alert('提示', '请选择至少一条记录!');
- return;
- } else {
- var childId = childModel[0].get('id');
- Ext.Ajax.request({
- url: authUrl,
- success: function() {
- Ext.Msg.alert('提示', '操作成功!');
- ds.reload();
- },
- params: 'auth=true&parentId=' + ds.baseParams.id + '&childId=' + childId
- });
- }
- }
- }, '-', {
- pressed: true,
- enableToggle: true,
- text: '取消授权',
- toggleHandler: function() {
- //授权事件
- var childModel = grid.getSelections();
- if (childModel.length <= 0) {
- Ext.Msg.alert('提示', '请选择至少一条记录!');
- return;
- } else {
- var childId = childModel[0].get('id');
- Ext.Ajax.request({
- url: authUrl,
- success: function() {
- Ext.Msg.alert('提示', '操作成功!');
- ds.reload();
- },
- params: 'auth=false&parentId=' + ds.baseParams.id + '&childId=' + childId
- });
- }
- }
- }])
- });
- this[gridName] = grid;
- this[windowName] = new Ext.Window({
- layout: 'fit',
- height: 300,
- width: 400,
- closeAction: 'hide',
- items: [grid]
- });
- }
- this[windowName].show();
- this[gridName].getStore().baseParams.id = parentId;
- this[gridName].getStore().reload();
- };
|