FormPanelController.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. Ext.define('saas.view.sys.power.FormPanelController', {
  2. extend: 'Ext.app.ViewController',
  3. alias: 'controller.sys-power-formpanel',
  4. init: function (form) {
  5. var me = this;
  6. this.control({
  7. 'button[name=savepower]':{
  8. click:function(b){
  9. me.onSave(b);
  10. }
  11. }
  12. });
  13. },
  14. onSave: function(b) {
  15. var me = this,
  16. form = me.getView(),
  17. viewModel = me.getViewModel(),
  18. updateRecs = viewModel.data.powergrid.getUpdatedRecords();
  19. if(updateRecs.length>0){
  20. var params = {};
  21. var roleId = b.ownerCt.ownerCt.initId;//角色ID
  22. params.roleId = roleId;
  23. var datas = [];
  24. Ext.Array.each(updateRecs,function(rec){
  25. var modified = rec.modified;
  26. if(modified){
  27. var modifyDatas = me.getBaseField(modified,rec.get('groupId'),rec.data);
  28. datas = datas.concat(modifyDatas);
  29. }
  30. //收集other
  31. var other = rec.get('other');
  32. if(other&&other!=null){
  33. Ext.Array.each(other,function(o){
  34. datas.push({
  35. classify:'other',
  36. checked:o.checked,
  37. resourceId:o.resourceId
  38. });
  39. });
  40. }
  41. })
  42. params.powerSetList = datas;
  43. saas.util.BaseUtil.request({
  44. url: form.saveUrl,
  45. params: JSON.stringify(params),
  46. method: 'POST',
  47. })
  48. .then(function(localJson) {
  49. if(localJson.success){
  50. saas.util.BaseUtil.showSuccessToast('保存成功');
  51. viewModel.data.powergrid.load();
  52. }
  53. })
  54. .catch(function(e) {
  55. saas.util.BaseUtil.showErrorToast('保存失败: ' + e.message);
  56. });
  57. }else{
  58. saas.util.BaseUtil.showErrorToast('没有修改数据,请修改后保存');
  59. }
  60. },
  61. getBaseField:function(modified,groupId,data){
  62. var powerSetList = [];
  63. if((typeof modified.add) == 'boolean'){
  64. powerSetList.push({
  65. groupId:groupId,
  66. classify:'add',
  67. checked:data['add']
  68. })
  69. }
  70. if((typeof modified.query) == 'boolean'){
  71. powerSetList.push({
  72. groupId:groupId,
  73. classify:'query',
  74. checked:data['query']
  75. })
  76. }
  77. if((typeof modified.delete) == 'boolean'){
  78. powerSetList.push({
  79. groupId:groupId,
  80. classify:'delete',
  81. checked:data['delete']
  82. })
  83. }
  84. if((typeof modified.audit) == 'boolean'){
  85. powerSetList.push({
  86. groupId:groupId,
  87. classify:'audit',
  88. checked:data['audit']
  89. })
  90. }
  91. if((typeof modified.update) == 'boolean'){
  92. powerSetList.push({
  93. groupId:groupId,
  94. classify:'update',
  95. checked:data['update']
  96. })
  97. }
  98. if((typeof modified.unAudit) == 'boolean'){
  99. powerSetList.push({
  100. groupId:groupId,
  101. classify:'unAudit',
  102. checked:data['unAudit']
  103. })
  104. }
  105. if((typeof modified.fileExport) == 'boolean'){
  106. powerSetList.push({
  107. groupId:groupId,
  108. classify:'export',
  109. checked:data['fileExport']
  110. })
  111. }
  112. if((typeof modified.fileImport) == 'boolean'){
  113. powerSetList.push({
  114. groupId:groupId,
  115. classify:'import',
  116. checked:data['fileImport']
  117. })
  118. }
  119. if((typeof modified.print) == 'boolean'){
  120. powerSetList.push({
  121. groupId:groupId,
  122. classify:'print',
  123. checked:data['print']
  124. })
  125. }
  126. return powerSetList;
  127. }
  128. });