ux.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. Ext.ux.buildChildGrid = function(conf) {
  2. var windowName = conf.windowName;
  3. var gridName = conf.gridName;
  4. var fields = conf.fields;
  5. var queryUrl = conf.queryUrl;
  6. var authUrl = conf.authUrl;
  7. for (var i = 0; i < fields.length; i++) {
  8. fields[i].dataIndex = fields[i].name;
  9. }
  10. if (this.getSelections().length <= 0){
  11. Ext.Msg.alert('提示', '请选择需要操作的记录!');
  12. return;
  13. }
  14. if (this.getSelections().length > 1){
  15. Ext.Msg.alert('提示', '不能选择多行记录!');
  16. return;
  17. }
  18. var parentId = this.getSelections()[0].get('id');
  19. if (!this[windowName]) {
  20. // 建一个角色数据映射数组
  21. var r = Ext.data.Record.create(fields);
  22. //设置数据仓库
  23. var ds = new Ext.data.Store({
  24. proxy: new Ext.data.HttpProxy({url: queryUrl}),
  25. reader: new Ext.data.JsonReader({
  26. root: '',
  27. totalProperty: 'totalCount'
  28. }, r),
  29. // 远端排序开关
  30. remoteSort: false
  31. });
  32. //创建表格头格式
  33. var cm = new Ext.grid.ColumnModel(fields);
  34. var parentGrid = this;
  35. var grid = new Ext.grid.GridPanel( {
  36. ds: ds,
  37. cm: cm,
  38. selModel: new Ext.grid.RowSelectionModel({singleSelect:true}),
  39. enableColLock:false,
  40. loadMask: false,
  41. viewConfig: {
  42. forceFit: true
  43. },
  44. bbar: new Ext.Toolbar([{
  45. pressed: true,
  46. enableToggle:true,
  47. text: '授权',
  48. toggleHandler: function(){
  49. //授权事件
  50. var childModel = grid.getSelections();
  51. var parentModel = parentGrid.getSelections();
  52. if (childModel.length <= 0) {
  53. Ext.Msg.alert('提示', '请选择至少一条记录!');
  54. return;
  55. } else if(childModel.length == 1) {
  56. var parentId = parentModel[0].get('id');
  57. var childId = childModel[0].get('id');
  58. Ext.Ajax.request({
  59. url: authUrl,
  60. success: function(response) {
  61. var o = Ext.decode(response.responseText);
  62. if (o.success) {
  63. Ext.Msg.alert('提示', '操作成功!');
  64. ds.reload();
  65. } else {
  66. Ext.Msg.alert('提示', o.msg);
  67. }
  68. },
  69. params: 'auth=true&parentId=' + ds.baseParams.id + '&childId=' + childId
  70. });
  71. } else {
  72. for(var i = 0, len = childModel.length; i < len; i++){
  73. var parentId = parentModel[0].get('id');
  74. var childId = childModel[i].get('id');
  75. Ext.Ajax.request({
  76. url: authUrl,
  77. success: function(response) {
  78. var o = Ext.decode(response.responseText);
  79. if (o.success) {
  80. Ext.Msg.alert('提示', '操作成功!');
  81. ds.reload();
  82. } else {
  83. Ext.Msg.alert('提示', o.msg);
  84. }
  85. },
  86. params: 'auth=true&parentId=' + ds.baseParams.id + '&childId=' + childId
  87. });
  88. }
  89. }
  90. }
  91. }, '-', {
  92. pressed: true,
  93. enableToggle: true,
  94. text: '取消授权',
  95. toggleHandler: function() {
  96. //授权事件
  97. var childModel = grid.getSelections();
  98. var parentModel = parentGrid.getSelections();
  99. if (childModel.length <= 0) {
  100. Ext.Msg.alert('提示', '请选择至少一条记录!');
  101. return;
  102. } else if(childModel.length == 1) {
  103. var parentId = parentModel[0].get('id');
  104. var childId = childModel[0].get('id');
  105. Ext.Ajax.request({
  106. url: authUrl,
  107. success: function(response) {
  108. var o = Ext.decode(response.responseText);
  109. if (o.success) {
  110. Ext.Msg.alert('提示', '操作成功!');
  111. ds.reload();
  112. } else {
  113. Ext.Msg.alert('提示', o.msg);
  114. }
  115. },
  116. params: 'auth=false&parentId=' + ds.baseParams.id + '&childId=' + childId
  117. });
  118. } else {
  119. for(var i = 0, len = childModel.length; i < len; i++){
  120. var parentId = parentModel[0].get('id');
  121. var childId = childModel[i].get('id');
  122. Ext.Ajax.request({
  123. url: authUrl,
  124. success: function(response) {
  125. var o = Ext.decode(response.responseText);
  126. if (o.success) {
  127. Ext.Msg.alert('提示', '操作成功!');
  128. ds.reload();
  129. } else {
  130. Ext.Msg.alert('提示', o.msg);
  131. }
  132. },
  133. params: 'auth=false&parentId=' + ds.baseParams.id + '&childId=' + childId
  134. });
  135. }
  136. }
  137. }
  138. }])
  139. });
  140. this[gridName] = grid;
  141. this[windowName] = new Ext.Window({
  142. layout: 'fit',
  143. height: 300,
  144. width: 400,
  145. closeAction: 'hide',
  146. items: [grid]
  147. });
  148. }
  149. this[windowName].show();
  150. this[gridName].getStore().baseParams.id = parentId;
  151. this[gridName].getStore().reload();
  152. };
  153. //
  154. Ext.ux.buildChildGridForTree = function(conf) {
  155. var windowName = conf.windowName;
  156. var gridName = conf.gridName;
  157. var fields = conf.fields;
  158. var queryUrl = conf.queryUrl;
  159. var authUrl = conf.authUrl;
  160. for (var i = 0; i < fields.length; i++) {
  161. fields[i].dataIndex = fields[i].name;
  162. }
  163. var node = this.getSelectionModel().getSelectedNode();
  164. if (node == null) {
  165. Ext.Msg.alert('提示', '请选择需要操作的记录!');
  166. return;
  167. }
  168. var parentId = node.id;
  169. if (!this[windowName]) {
  170. // 建一个角色数据映射数组
  171. var r = Ext.data.Record.create(fields);
  172. //设置数据仓库
  173. var ds = new Ext.data.Store({
  174. proxy: new Ext.data.HttpProxy({url: queryUrl}),
  175. reader: new Ext.data.JsonReader({
  176. root: '',
  177. totalProperty: 'totalCount'
  178. }, r),
  179. // 远端排序开关
  180. remoteSort: false
  181. });
  182. //创建表格头格式
  183. var cm = new Ext.grid.ColumnModel(fields);
  184. var grid = new Ext.grid.GridPanel( {
  185. ds: ds,
  186. cm: cm,
  187. selModel: new Ext.grid.RowSelectionModel({singleSelect:true}),
  188. enableColLock:false,
  189. loadMask: false,
  190. viewConfig: {
  191. forceFit: true
  192. },
  193. bbar: new Ext.Toolbar([{
  194. pressed: true,
  195. enableToggle:true,
  196. text: '授权',
  197. toggleHandler: function(){
  198. //授权事件
  199. var childModel = grid.getSelections();
  200. if (childModel.length <= 0) {
  201. Ext.Msg.alert('提示', '请选择至少一条记录!');
  202. return;
  203. } else {
  204. var childId = childModel[0].get('id');
  205. Ext.Ajax.request({
  206. url: authUrl,
  207. success: function() {
  208. Ext.Msg.alert('提示', '操作成功!');
  209. ds.reload();
  210. },
  211. params: 'auth=true&parentId=' + ds.baseParams.id + '&childId=' + childId
  212. });
  213. }
  214. }
  215. }, '-', {
  216. pressed: true,
  217. enableToggle: true,
  218. text: '取消授权',
  219. toggleHandler: function() {
  220. //授权事件
  221. var childModel = grid.getSelections();
  222. if (childModel.length <= 0) {
  223. Ext.Msg.alert('提示', '请选择至少一条记录!');
  224. return;
  225. } else {
  226. var childId = childModel[0].get('id');
  227. Ext.Ajax.request({
  228. url: authUrl,
  229. success: function() {
  230. Ext.Msg.alert('提示', '操作成功!');
  231. ds.reload();
  232. },
  233. params: 'auth=false&parentId=' + ds.baseParams.id + '&childId=' + childId
  234. });
  235. }
  236. }
  237. }])
  238. });
  239. this[gridName] = grid;
  240. this[windowName] = new Ext.Window({
  241. layout: 'fit',
  242. height: 300,
  243. width: 400,
  244. closeAction: 'hide',
  245. items: [grid]
  246. });
  247. }
  248. this[windowName].show();
  249. this[gridName].getStore().baseParams.id = parentId;
  250. this[gridName].getStore().reload();
  251. };