FormPanelController.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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.showToast('保存成功');
  51. viewModel.data.powergrid.load();
  52. }
  53. })
  54. .catch(function(res) {
  55. console.error(res);
  56. saas.util.BaseUtil.showToast('保存失败: ' + res.message);
  57. });
  58. }else{
  59. saas.util.BaseUtil.showToast('没有修改数据,请修改后保存');
  60. }
  61. },
  62. getBaseField:function(modified,groupId,data){
  63. var powerSetList = [];
  64. if((typeof modified.add) == 'boolean'){
  65. powerSetList.push({
  66. groupId:groupId,
  67. classify:'add',
  68. checked:data['add']
  69. })
  70. }
  71. if((typeof modified.query) == 'boolean'){
  72. powerSetList.push({
  73. groupId:groupId,
  74. classify:'query',
  75. checked:data['query']
  76. })
  77. }
  78. if((typeof modified.delete) == 'boolean'){
  79. powerSetList.push({
  80. groupId:groupId,
  81. classify:'delete',
  82. checked:data['delete']
  83. })
  84. }
  85. if((typeof modified.audit) == 'boolean'){
  86. powerSetList.push({
  87. groupId:groupId,
  88. classify:'audit',
  89. checked:data['audit']
  90. })
  91. }
  92. if((typeof modified.unAudit) == 'boolean'){
  93. powerSetList.push({
  94. groupId:groupId,
  95. classify:'unAudit',
  96. checked:data['unAudit']
  97. })
  98. }
  99. if((typeof modified.fileExport) == 'boolean'){
  100. powerSetList.push({
  101. groupId:groupId,
  102. classify:'fileExport',
  103. checked:data['fileExport']
  104. })
  105. }
  106. if((typeof modified.fileImport) == 'boolean'){
  107. powerSetList.push({
  108. groupId:groupId,
  109. classify:'fileImport',
  110. checked:data['fileImport']
  111. })
  112. }
  113. if((typeof modified.print) == 'boolean'){
  114. powerSetList.push({
  115. groupId:groupId,
  116. classify:'print',
  117. checked:data['print']
  118. })
  119. }
  120. return powerSetList;
  121. }
  122. });