ModifyForm.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.pm.make.ModifyForm', {
  3. extend: 'Ext.app.Controller',
  4. requires: ['erp.util.FormUtil', 'erp.util.GridUtil', 'erp.util.BaseUtil'],
  5. views:[
  6. 'core.form.Panel','pm.make.MakeCommon','core.grid.Panel2','core.toolbar.Toolbar','core.form.YnField',
  7. 'core.button.Save','core.button.Add','core.button.Close','core.button.Delete','core.button.Update',
  8. 'core.trigger.DbfindTrigger'
  9. ],
  10. init:function(){
  11. var me = this;
  12. me.FormUtil = Ext.create('erp.util.FormUtil');
  13. me.GridUtil = Ext.create('erp.util.GridUtil');
  14. me.BaseUtil = Ext.create('erp.util.BaseUtil');
  15. this.control({
  16. 'erpGridPanel2': {
  17. afterrender: function(grid){
  18. grid.setReadOnly(true);
  19. },
  20. itemclick:me.ItemClick
  21. },
  22. 'dbfindtrigger[name=mm_prodcode]': {
  23. beforerender:function(trigger){
  24. trigger.autoDbfind=false;
  25. }
  26. /*focus: function(t){
  27. var grid = parent.Ext.getCmp('grid');
  28. var c = null;
  29. Ext.each(grid.store.data.items, function(item){
  30. if(item.data['mm_prodcode'] != null && item.data['mm_prodcode'] != ''){
  31. if(c == null){
  32. c = "(pr_code<>'" + item.data['mm_prodcode'] + "'";
  33. } else {
  34. c += " and pr_code<>'" + item.data['mm_prodcode'] + "'";
  35. }
  36. }
  37. });
  38. if(c != null){
  39. t.dbBaseCondition = c + ")";
  40. }
  41. }*/
  42. },
  43. 'erpSaveButton' :{
  44. click:function(btn){
  45. //this.FormUtil.beforeSave(this);
  46. var form=me.getForm(btn);
  47. var r = form.getValues();
  48. var keys = Ext.Object.getKeys(r), f;
  49. Ext.each(keys, function(k){
  50. f = form.down('#' + k);
  51. if(f && f.logic == 'ignore') {
  52. delete r[k];
  53. }
  54. });
  55. me.FormUtil.setLoading(true);
  56. Ext.Ajax.request({
  57. url : basePath + form.saveUrl,
  58. params : {
  59. formStore: unescape(Ext.JSON.encode(r).replace(/\\/g,"%")),
  60. _noc:1
  61. },
  62. method : 'post',
  63. callback : function(options,success,response){
  64. me.FormUtil.setLoading(false);
  65. var localJson = new Ext.decode(response.responseText);
  66. if(localJson.success){
  67. saveSuccess(function(){
  68. //add成功后刷新页面进入可编辑的页面
  69. var value = localJson.Id;
  70. var formCondition = "mm_id IS" + value ;
  71. if(me.FormUtil.contains(window.location.href, '?', true)){
  72. var href=window.location.href;
  73. window.location.href = href.substring(0,href.lastIndexOf('&')) + '&whoami=&formCondition=' +
  74. formCondition;
  75. } else {
  76. window.location.href = window.location.href + '?formCondition=' +
  77. formCondition;
  78. }
  79. });
  80. } else if(localJson.exceptionInfo){
  81. var str = localJson.exceptionInfo;
  82. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  83. str = str.replace('AFTERSUCCESS', '');
  84. saveSuccess(function(){
  85. //add成功后刷新页面进入可编辑的页面
  86. var value = r[form.keyField];
  87. var formCondition = form.keyField + "IS" + value ;
  88. if(me.contains(window.location.href, '?', true)){
  89. window.location.href = window.location.href + '&formCondition=' +
  90. formCondition ;
  91. } else {
  92. window.location.href = window.location.href + '?formCondition=' +
  93. formCondition;
  94. }
  95. });
  96. showError(str);
  97. } else {
  98. showError(str);
  99. return;
  100. }
  101. } else{
  102. saveFailure();//@i18n/i18n.js
  103. }
  104. }
  105. });
  106. }
  107. },
  108. 'erpDeleteButton': {
  109. click: function(btn){
  110. //me.GridUtil.deleteDetailForEditGrid(btn);
  111. var grid = parent.Ext.getCmp('grid');
  112. var records = grid.selModel.getSelection();
  113. Ext.Ajax.request({
  114. url : basePath + "pm/make/deleteModifyMaterial.action",
  115. params: {
  116. id: records[0].data[grid.keyField]
  117. },
  118. method : 'post',
  119. callback : function(options,success,response){
  120. grid.BaseUtil.getActiveTab().setLoading(false);
  121. var localJson = new Ext.decode(response.responseText);
  122. if(localJson.exceptionInfo){
  123. showError(localJson.exceptionInfo);return;
  124. }
  125. if(localJson.success){
  126. grid.store.remove(records[0]);
  127. delSuccess(function(){
  128. });//@i18n/i18n.js
  129. parent.Ext.getCmp('win').close();
  130. } else {
  131. delFailure();
  132. }
  133. }
  134. });
  135. },
  136. },
  137. 'erpCloseButton':{
  138. click:function(btn){
  139. parent.Ext.getCmp('win').close();
  140. }
  141. },
  142. 'erpAddButton': {
  143. click: function(btn){
  144. var form= me.getForm(btn);
  145. //form.getForm().reset(); 不行
  146. Ext.Array.each(form.items.items,function(item){
  147. if(item.name!='mm_maid'){
  148. item.setValue(null);
  149. }
  150. });
  151. }
  152. },
  153. 'field[name=mm_oneuseqty]': {
  154. change: function(f) {
  155. var v = f.value || 0,
  156. q = parent.Ext.getCmp('ma_qty');
  157. Ext.getCmp('mm_qty').setValue(v * q.value);
  158. }
  159. }
  160. });
  161. },
  162. getForm: function(btn){
  163. return btn.ownerCt.ownerCt;
  164. },
  165. ItemClick:function(view ,record){
  166. if(caller=='MakeBase!Sub'){
  167. Ext.getCmp('deletebutton').setDisabled(false);
  168. var form=view.ownerCt.ownerCt.items.items[0];
  169. form.getForm().setValues(record.data);
  170. }
  171. }
  172. });