FormPanelController.js 4.2 KB

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