ReportFilesG.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.fa.fp.ReportFilesG', {
  3. extend : 'Ext.app.Controller',
  4. GridUtil : Ext.create('erp.util.GridUtil'),
  5. BaseUtil : Ext.create('erp.util.BaseUtil'),
  6. views : ['fa.fp.ReportFilesG.Viewport','fa.fp.ReportFilesG.ReportFilesGGrid','core.toolbar.Toolbar', 'core.button.Save', 'core.button.Add',
  7. 'core.button.Close', 'core.button.Update','core.button.DeleteDetail', 'core.button.Delete','core.trigger.DbfindTrigger', 'core.trigger.TextAreaTrigger',
  8. 'core.form.YnField','core.grid.detailAttach'],
  9. init : function() {
  10. var me = this;
  11. this.control({
  12. 'erpReportFilesGGrid' : {
  13. select : function(selModel, record, index) {
  14. var grid = Ext.getCmp('grid');
  15. if (index == grid.store.data.items.length - 1) {// 如果选择了最后一行
  16. me.add10EmptyData(grid);
  17. }
  18. me.itemclick(grid);
  19. }
  20. },
  21. 'erpSaveButton' : {
  22. click : function(btn) {
  23. var grid = Ext.getCmp('grid');
  24. var params = grid.getGridStore();
  25. if (params.length == 0) {
  26. showError("没有需要保存的数据!");
  27. return;
  28. }
  29. Ext.Ajax.request({
  30. url : basePath
  31. + 'fa/fp/saveReportFilesG.action',
  32. params : {
  33. param : params,
  34. caller : caller
  35. },
  36. method : 'post',
  37. callback : function(options, success, response) {
  38. // me.getActiveTab().setLoading(false);
  39. var res = new Ext.decode(response.responseText);
  40. if (res && res.exceptionInfo) {
  41. showError(res.exceptionInfo);
  42. return;
  43. } else {
  44. gridCondition = (gridCondition == null) ? "":gridCondition.replace(/IS/g,"=");
  45. grid.GridUtil.loadNewStore(grid, {caller : caller,condition : gridCondition});
  46. }
  47. }
  48. });
  49. }
  50. },
  51. 'erpCloseButton' : {
  52. click : function(btn) {
  53. me.FormUtil.beforeClose(me);
  54. }
  55. },
  56. 'erpDeleteButton' : {
  57. click : function(btn) {
  58. var grid = Ext.getCmp('grid');
  59. var s = grid.getStore().data.items;
  60. var bool = false;
  61. Ext.each(s,function (item,index){
  62. if(this.data['id'] != ''&& this.data['id'] != '0' && this.data['id'] != 0){
  63. bool = true;
  64. }
  65. });
  66. if(!bool){
  67. showError("没有需要删除的数据!");
  68. return;
  69. }
  70. warnMsg($I18N.common.msg.ask_del_main, function(btn){
  71. if(btn == 'yes'){
  72. Ext.Ajax.request({
  73. url : basePath+ 'fa/fp/deleteReportFilesG.action',
  74. params : {
  75. id : id,
  76. caller : caller
  77. },
  78. method : 'post',
  79. callback : function(options, success, response) {
  80. // me.getActiveTab().setLoading(false);
  81. var res = new Ext.decode(response.responseText);
  82. if (res && res.exceptionInfo) {
  83. showError(res.exceptionInfo);return;
  84. } else {
  85. delSuccess(function(){
  86. this.onClose();
  87. });//
  88. gridCondition = (gridCondition == null)? "": gridCondition.replace(/IS/g,"=");
  89. grid.getGridColumnsAndStore({caller :caller,condition : gridCondition});}
  90. }
  91. });
  92. }
  93. });
  94. }
  95. },
  96. 'erpDeleteDetailButton': {
  97. afterrender: function(btn){
  98. btn.ownerCt.add({
  99. id:'fileform',
  100. xtype:'form',
  101. layout:'column',
  102. bodyStyle: 'background: transparent no-repeat 0 0;border: none;',
  103. items: [{
  104. xtype : 'filefield',
  105. name : 'file',
  106. buttonOnly : true,
  107. hideLabel : true,
  108. disabled : false,
  109. width : 90,
  110. height : 17,
  111. id : 'file',
  112. buttonConfig : {
  113. iconCls : 'x-button-icon-pic',
  114. text : '上传附件'
  115. },
  116. listeners : {
  117. change : function(field) {
  118. var filename = '';
  119. if (contains(field.value, "\\", true)) {
  120. filename = field.value.substring(field.value
  121. .lastIndexOf('\\')
  122. + 1);
  123. } else {
  124. filename = field.value.substring(field.value
  125. .lastIndexOf('/')
  126. + 1);
  127. }
  128. field.ownerCt.getForm().submit({
  129. url : basePath + 'common/upload.action?em_code=' + em_code,
  130. waitMsg : "正在解析文件信息",
  131. success : function(fp, o) {
  132. if (o.result.error) {
  133. showError(o.result.error);
  134. } else {
  135. Ext.Msg.alert("恭喜", filename + " 上传成功!");
  136. field.setDisabled(true);
  137. var record = Ext.getCmp('grid').selModel.lastSelected;
  138. if (record) {
  139. record.set('1detailAttach',filename+";"+o.result.filepath);
  140. }
  141. }
  142. }
  143. });
  144. }
  145. }
  146. }]
  147. });
  148. }
  149. }
  150. });
  151. },
  152. add10EmptyData : function(grid) {
  153. var data = new Array();
  154. var items = grid.store.data.items;
  155. for (var i = 0; i < 10; i++) {
  156. var o = new Object();
  157. o.caller = null;
  158. o.id = null;
  159. o.condition = null;
  160. o.title = null;
  161. o.file_name = null;
  162. o.file_path = null;
  163. data.push(o);
  164. }
  165. grid.store.insert(items.length, data);
  166. },
  167. itemclick : function(grid) {
  168. var btn = grid.down('erpDeleteDetailButton');
  169. if (btn)
  170. btn.setDisabled(false);
  171. btn = grid.down('erpAddDetailButton');
  172. if (btn)
  173. btn.setDisabled(false);
  174. btn = grid.down('copydetail');
  175. if (btn)
  176. btn.setDisabled(false);
  177. btn = grid.down('pastedetail');
  178. if (btn)
  179. btn.setDisabled(false);
  180. btn = grid.down('updetail');
  181. if (btn)
  182. btn.setDisabled(false);
  183. btn = grid.down('downdetail');
  184. if (btn)
  185. btn.setDisabled(false);
  186. btn = grid.down('erpdetailAttach');
  187. if (btn)
  188. btn.setDisabled(false);
  189. }
  190. });