DataLimit.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.ma.DataLimit', {
  3. extend : 'Ext.app.Controller',
  4. stores: ['ma.DataLimitStore'],
  5. views : [ 'ma.datalimit.DataLimit', 'ma.datalimit.LimitDetail', 'ma.datalimit.LimitForm','core.form.MultiField','core.trigger.DbfindTrigger','ma.datalimit.SourceWindow',
  6. 'core.form.FtField','core.form.FtDateField','core.form.FtFindField','core.form.FtNumberField', 'core.form.MonthDateField','common.batchDeal.Form','common.batchDeal.GridPanel',
  7. 'core.trigger.AddDbfindTrigger',
  8. 'core.trigger.DbfindTrigger','core.form.FtField','core.form.FtFindField','core.form.ConDateField','core.button.TurnMeetingButton',
  9. 'core.trigger.TextAreaTrigger','core.form.YnField', 'core.form.MonthDateField','core.form.ConMonthDateField','core.trigger.SchedulerTrigger',
  10. 'core.grid.YnColumn','core.form.DateHourMinuteField','core.form.SeparNumber'],
  11. FormUtil: Ext.create('erp.util.FormUtil'),
  12. BaseUtil: Ext.create('erp.util.BaseUtil'),
  13. GridUtil: Ext.create('erp.util.GridUtil'),
  14. flag:true,
  15. init : function() {
  16. var me = this;
  17. this.control({
  18. 'button[itemId=copy]': {
  19. click: function(btn) {
  20. var instanceid_=Ext.getCmp('instanceid_');
  21. if(instanceid_.value) me.CopyPower();
  22. else showError('请选择有效的人员和数据类型复制权限!');
  23. }
  24. },
  25. 'button[itemId=delete]':{//清除权限
  26. click:function(btn){
  27. var me = this, grid = Ext.getCmp('limitdetail'),instanceid_=Ext.getCmp('instanceid_');
  28. var items = grid.selModel.getSelection(),dItems=new Array(),rItems=new Array();
  29. if(items.length<1) showError("没有需要处理的数据!");
  30. Ext.each(items, function(item, index){
  31. if(this.data[grid.keyField] != null && this.data[grid.keyField] != ''
  32. && this.data[grid.keyField] != '0' && this.data[grid.keyField] != 0){
  33. dItems.push({
  34. id_:item.data.id_
  35. });
  36. }else rItems.push(item);
  37. });
  38. grid.getStore().remove(rItems);
  39. if(dItems.length>0){
  40. me.FormUtil.setLoading(true);
  41. Ext.Ajax.request({
  42. url:basePath+'ma/datalimit/deleteLimitPower.action',
  43. method:'POST',
  44. params:{
  45. data:unescape(Ext.JSON.encode(dItems))
  46. },
  47. callback:function(options, success, response){
  48. me.FormUtil.setLoading(false);
  49. var res = new Ext.decode(response.responseText);
  50. if(res.success){
  51. Ext.Msg.alert('提示','删除成功!',function(){
  52. Ext.getCmp('limitdetail').getStore().load({
  53. params:{
  54. InstanceId_:instanceid_
  55. }
  56. })
  57. });
  58. }
  59. }
  60. });
  61. }
  62. }
  63. },
  64. 'erpVastDealButton': {
  65. click: function(btn){
  66. var url=btn.ownerCt.ownerCt.dealUrl,instanceid_=Ext.getCmp('instanceid_');
  67. warnMsg("复制权限将选中人员对应数据类型权限全部覆盖?", function(btn){
  68. if(btn == 'yes'){
  69. me.vastDeal(url, instanceid_.value);
  70. } else {
  71. return;
  72. }
  73. });
  74. }
  75. },
  76. 'combo[name=limit_id_]':{
  77. change:function(field,newvalue,oldvalue){
  78. var empid_=Ext.getCmp('empid_');
  79. if(empid_.value){
  80. me.getDataLimitInstance(newvalue,empid_.value);
  81. }
  82. }
  83. },
  84. 'hidden[name=empid_]':{
  85. change:function(field,newvalue,oldvalue){
  86. var limitid_=Ext.getCmp('limit_id_');
  87. if(limitid_.value){
  88. me.getDataLimitInstance(limitid_.value,newvalue);
  89. }
  90. }
  91. },
  92. 'checkbox[name=nolimit_]':{
  93. change:function(field,newvalue,oldvalue){
  94. var querys=Ext.ComponentQuery.query('button[itemId=select]'),noaddlimit_=Ext.getCmp('noaddlimit_'),
  95. usereport_=Ext.getCmp('usereport_');
  96. if(querys.length>0) {
  97. querys[0].setDisabled(newvalue==1);
  98. }
  99. noaddlimit_.setDisabled(newvalue==1);
  100. usereport_.setDisabled(newvalue==1);
  101. if(newvalue==1){
  102. noaddlimit_.setValue(0);
  103. usereport_.setValue(0);
  104. }
  105. if(me.flag){
  106. if(newvalue){
  107. warnMsg('是否将分配全部权限信息?', function(btn){
  108. if(btn != 'yes' && btn != 'ok'){
  109. me.flag=false;
  110. field.setValue(0);
  111. }else {
  112. var noaddlimit_=Ext.getCmp('noaddlimit_'),usereport_=Ext.getCmp('usereport_');
  113. noaddlimit_.setDisabled(true);
  114. usereport_.setDisabled(true);
  115. var querys=Ext.ComponentQuery.query('button[itemId=select]');
  116. if(querys.length>0) querys[0].setDisabled(true);
  117. }
  118. });
  119. }else{
  120. warnMsg('是否将已有全部权限信息清除?', function(btn){
  121. if(btn != 'yes' && btn != 'ok'){
  122. me.flag=false;
  123. field.setValue(1);
  124. }else {
  125. var noaddlimit_=Ext.getCmp('noaddlimit_'),usereport_=Ext.getCmp('usereport_');
  126. noaddlimit_.setDisabled(false);
  127. usereport_.setDisabled(false);
  128. var querys=Ext.ComponentQuery.query('button[itemId=select]');
  129. if(querys.length>0) querys[0].setDisabled(false);
  130. }
  131. });
  132. }
  133. }else me.flag=true;
  134. }
  135. },
  136. 'radiogroup':{
  137. change:function(field,newvalue,oldvalue){
  138. var c=Ext.getCmp('condition_');
  139. if(c.hidden && newvalue.limittype_=='condition'){
  140. c.show();
  141. }else if(!c.hidden)c.hide();
  142. }
  143. },
  144. 'button[itemId=select]':{
  145. click:function(btn){
  146. var limitid_=Ext.getCmp('limit_id_'),empid_=Ext.getCmp('empid_'),record=limitid_.findRecordByValue(limitid_.value),limittype_=Ext.getCmp('limittype_').getValue().limittype_;
  147. if(!limitid_.value) showError('未选择相应的数据类型!');
  148. else if(!empid_.value) showError('未选择相应的人员!');
  149. else {
  150. Ext.widget('sourcewindow',{
  151. limitId_:limitid_.value,
  152. table:record.get('table_'),
  153. LimitType:limittype_,
  154. modal:true,
  155. title:'<div align="center">设置权限('+(limittype_=='detail'?'按明细数据':'按条件')+')</div>'
  156. }).show();
  157. }
  158. }
  159. },
  160. 'button[itemId=createSql]':{
  161. click:function(btn){
  162. var w=btn.ownerCt.ownerCt,g=w.down('#querygrid'),_c=g.getCondition();
  163. if(_c){
  164. Ext.getCmp('condition_').setValue(_c);
  165. w.close();
  166. }else {
  167. showError('未设置任何条件');
  168. }
  169. }
  170. },
  171. 'button[itemId=query]':{
  172. click:function(btn){
  173. var w=btn.ownerCt.ownerCt,g=w.down('#querygrid'),dg=w.down('#datagrid'),con=g.getCondition();
  174. if(con!=""){
  175. dg.getStore().load({
  176. params:{
  177. condition:con
  178. }
  179. });
  180. }
  181. }
  182. },
  183. 'button[itemId=selectdata]':{
  184. click:function(btn){
  185. var w=btn.ownerCt.ownerCt,g=w.down('#datagrid'),selects=g.getSelectionModel().getSelection();
  186. var limitdetail=Ext.getCmp('limitdetail');
  187. if(selects.length>0){
  188. limitdetail.insertRecords(selects);
  189. }else showError('请选择需要分配的数据!');
  190. w.close();
  191. }
  192. },
  193. 'button[itemId=save]':{
  194. click:function(btn){
  195. var form=btn.ownerCt.ownerCt,grid=Ext.getCmp('limitdetail'),params=new Object();
  196. var r=form.getValues();
  197. delete r['emcode_'];
  198. delete r['emname_'];
  199. params.formData=unescape(escape(Ext.JSON.encode(r)));
  200. var changes=grid.getChange();
  201. if(changes.added.length>0){
  202. params.inserts=unescape(changes.added.toString());
  203. }
  204. if(changes.updated.length>0){
  205. params.updates=unescape(changes.updated.toString());
  206. }
  207. me.FormUtil.setLoading(true);
  208. Ext.Ajax.request({
  209. url:basePath+'ma/datalimit/InstanceDataLimit.action',
  210. method:'post',
  211. params:params,
  212. callback:function(options, success, response){
  213. me.FormUtil.setLoading(false);
  214. var res = new Ext.decode(response.responseText);
  215. if(res.success){
  216. Ext.Msg.alert('提示','保存成功!',function(){
  217. Ext.getCmp('limitdetail').getStore().load({
  218. params:{
  219. InstanceId_:res.id ||-1
  220. }
  221. })
  222. });
  223. }
  224. }
  225. });
  226. }
  227. }
  228. });
  229. },
  230. getDataLimitInstance:function(limitid_,emid){
  231. var me=this;
  232. me.FormUtil.setLoading(true);
  233. Ext.Ajax.request({
  234. url:basePath+'ma/datalimit/getDataLimitInstance.action',
  235. method:'get',
  236. params:{
  237. empid_:emid,
  238. limitid_:limitid_
  239. },
  240. callback : function(options, success, response){
  241. me.FormUtil.setLoading(false);
  242. var res={nolimit_:1};
  243. if (response.responseText) res = new Ext.decode(response.responseText);
  244. me.refreshLimits(res);
  245. }
  246. });
  247. },
  248. refreshLimits:function(data){
  249. var me=this,nolimit_=Ext.getCmp('nolimit_'),instanceid_=Ext.getCmp('instanceid_'),noaddlimit_=Ext.getCmp('noaddlimit_'),usereport_=Ext.getCmp('usereport_'),condition_=Ext.getCmp('condition_'),limittype_=Ext.getCmp('limittype_');
  250. nolimit_.setDisabled(false);
  251. if(data){
  252. instanceid_.setValue(data['instanceid_']);
  253. noaddlimit_.setValue(data['noaddlimit_']);
  254. usereport_.setValue(data['usereport_']);
  255. condition_.setValue(data['condition_']);
  256. limittype_.setValue({limittype_:data['limittype_']});
  257. me.flag=false;
  258. nolimit_.setValue(data['nolimit_']);
  259. Ext.getCmp('limitdetail').getStore().load({
  260. params:{
  261. InstanceId_:data['instanceid_'] ||-1
  262. }
  263. })
  264. }
  265. },
  266. CopyPower:function(){
  267. var win=Ext.getCmp('emp_select');
  268. if(!win){
  269. win=new Ext.window.Window({
  270. id:'emp_select',
  271. width:'90%',
  272. height:'95%',
  273. title:'复制权限',
  274. closeAction:'hide',
  275. layout:'anchor',
  276. items:[{
  277. anchor:'100% 20%',
  278. xtype:'erpBatchDealFormPanel',
  279. caller:'EmployeeCopyPower'
  280. },{
  281. anchor:'100% 80%',
  282. xtype:'erpBatchDealGridPanel',
  283. caller:'EmployeeCopyPower'
  284. }]
  285. });
  286. }
  287. win.show();
  288. },
  289. vastDeal: function(url,instanceId){
  290. var me = this, grid = Ext.getCmp('batchDealGridPanel');
  291. var items = grid.selModel.getSelection();
  292. Ext.each(items, function(item, index){
  293. if(this.data[grid.keyField] != null && this.data[grid.keyField] != ''
  294. && this.data[grid.keyField] != '0' && this.data[grid.keyField] != 0){
  295. item.index = this.data[grid.keyField];
  296. grid.multiselected.push(item);
  297. }
  298. });
  299. var form = Ext.getCmp('dealform'),params=new Object();
  300. var records = Ext.Array.unique(grid.multiselected);
  301. if(records.length > 0){
  302. var data=new Array();
  303. Ext.each(records,function (item){
  304. data.push({
  305. em_id:item.data[grid.keyField],
  306. InstanceId_:instanceId
  307. })
  308. });
  309. if(!me.dealing){
  310. params.data = unescape(Ext.JSON.encode(data).replace(/\\/g,"%"));
  311. me.dealing = true;
  312. var main = parent.Ext.getCmp("content-panel");
  313. main.getActiveTab().setLoading(true);//loading...
  314. Ext.Ajax.request({
  315. url : basePath + url,
  316. params: params,
  317. method : 'post',
  318. timeout: 6000000,
  319. callback : function(options,success,response){
  320. main.getActiveTab().setLoading(false);
  321. me.dealing = false;
  322. var localJson = new Ext.decode(response.responseText);
  323. if(localJson.exceptionInfo){
  324. var str = localJson.exceptionInfo;
  325. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){
  326. str = str.replace('AFTERSUCCESS', '');
  327. grid.multiselected = new Array();
  328. }
  329. showError(str);return;
  330. }
  331. if(localJson.success){
  332. if(localJson.log){
  333. showMessage("提示", localJson.log);
  334. }
  335. grid.multiselected = new Array();
  336. grid.ownerCt.close();
  337. }
  338. }
  339. });
  340. } else {
  341. showError("没有需要处理的数据!");
  342. }
  343. } else {
  344. showError("请勾选需要的明细!");
  345. }
  346. }
  347. });