Draft.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.oa.officialDocument.instruction.Draft', {
  3. extend: 'Ext.app.Controller',
  4. FormUtil: Ext.create('erp.util.FormUtil'),
  5. BaseUtil: Ext.create('erp.util.BaseUtil'),
  6. views:[
  7. 'oa.officialDocument.instruction.Draft','core.form.Panel','core.form.WordSizeField',
  8. 'core.button.Add','core.button.Save','core.button.Close','core.button.File','core.button.Transmit',
  9. 'core.button.Update','core.button.Delete','core.button.Submit','core.button.Over','core.form.FileField',
  10. 'core.trigger.TextAreaTrigger','core.trigger.DbfindTrigger','core.trigger.MultiDbfindTrigger'
  11. ],
  12. init:function(){
  13. var me = this;
  14. me.attachcount = 0;
  15. me.files = new Array();
  16. me.attach = '';
  17. this.control({
  18. 'erpSaveButton': {
  19. click: function(btn){
  20. var mm = this.FormUtil;
  21. var form = Ext.getCmp('form');
  22. if(! mm.checkForm()){
  23. return;
  24. }
  25. if(Ext.getCmp(form.keyField).value == null || Ext.getCmp(form.keyField).value == ''){
  26. mm.getSeqId(form);
  27. }
  28. console.log(form);
  29. if(form.getForm().isValid()){
  30. //form里面数据
  31. Ext.each(form.items.items, function(item){
  32. if(item.xtype == 'numberfield'){
  33. //number类型赋默认值,不然sql无法执行
  34. if(item.value == null || item.value == ''){
  35. item.setValue(0);
  36. }
  37. }
  38. });
  39. var r = form.getValues();
  40. var keys = Ext.Object.getKeys(r);
  41. var values = Ext.Object.getValues(r);
  42. var o = new Object();
  43. Ext.each(keys, function(key, index){
  44. if(!contains(key, 'ext-', true)){
  45. o[key] = values[index];
  46. }
  47. });
  48. o.in_attach = '';
  49. Ext.each(me.files, function(){
  50. o.in_attach += this + ",";
  51. });
  52. // console.log(o);
  53. o.in_attach = o.in_attach.substring(0, o.in_attach.lastIndexOf(','));
  54. if(!mm.contains(form.saveUrl, '?caller=', true)){
  55. form.saveUrl = form.saveUrl + "?caller=" + caller;
  56. }
  57. // console.log(o);
  58. mm.save(o, []);
  59. }else{
  60. mm.checkForm();
  61. }
  62. }
  63. },
  64. 'erpCloseButton': {
  65. click: function(btn){
  66. this.FormUtil.onClose(this);
  67. }
  68. },
  69. 'erpUpdateButton': {
  70. click: function(btn){
  71. this.FormUtil.onUpdate(this);
  72. }
  73. },
  74. 'erpDeleteButton': {
  75. click: function(btn){
  76. me.FormUtil.onDelete(Ext.getCmp('in_id').value);
  77. }
  78. },
  79. 'erpSubmitButton': {
  80. click: function(btn){
  81. this.FormUtil.onSubmit(Ext.getCmp('in_id').value);
  82. alert('提交成功');
  83. var main = parent.Ext.getCmp("content-panel");
  84. main.getActiveTab().close();
  85. }
  86. },
  87. 'erpOverButton': {
  88. click: function(btn){
  89. Ext.getCmp('in_status').setValue('已结束');
  90. Ext.getCmp('in_statuscode').setValue('OVERED');
  91. this.FormUtil.onUpdate(this);
  92. alert('提交成功');
  93. var main = parent.Ext.getCmp("content-panel");
  94. main.getActiveTab().close();
  95. }
  96. },
  97. // 'erpAddButton': {
  98. // click: function(){
  99. // me.FormUtil.onAdd('addDraft', '新增发文拟稿', 'jsps/oa/officialDocument/sendODManagement/draft.jsp');
  100. // }
  101. // },
  102. 'textfield[id=in_dept]': {
  103. render: function(field){
  104. Ext.Ajax.request({//拿到grid的columns
  105. url : basePath + "hr/employee/getHrOrg.action",
  106. params: {
  107. em_id: em_uu
  108. },
  109. method : 'post',
  110. async: false,
  111. callback : function(options, success, response){
  112. parent.Ext.getCmp("content-panel").getActiveTab().setLoading(false);
  113. console.log(response);
  114. var res = new Ext.decode(response.responseText);
  115. if(res.exceptionInfo){
  116. showError(res.exceptionInfo);return;
  117. }
  118. if(res.hrOrg){
  119. field.setValue(res.hrOrg.or_name);
  120. field.setReadOnly(true);
  121. }
  122. }
  123. });
  124. }
  125. },
  126. 'htmleditor[id=in_context]': {
  127. afterrender: function(f){
  128. f.setHeight(400);
  129. }
  130. },
  131. 'filefield[id=file]': {
  132. change: function(field){
  133. var mm = this.FormUtil;
  134. var fo = Ext.getCmp('form');
  135. if(field.value != null){
  136. var container = Ext.create('Ext.form.FieldContainer', {
  137. layout: 'hbox',
  138. fieldLabel: "附件" + (me.attachcount + 1),
  139. columnWidth: 1,
  140. items: [{
  141. xtype: 'textfield',
  142. id: 'attach' + me.attachcount,
  143. flex: 1
  144. },{
  145. xtype: 'button',
  146. text: '上传',
  147. id: 'upload' + me.attachcount,
  148. handler: function(btn){
  149. var form = btn.ownerCt.ownerCt;
  150. var f = Ext.getCmp(btn.id.replace('upload', 'attach'));
  151. if(Ext.getCmp(fo.keyField).value == null || Ext.getCmp(fo.keyField).value == ''){
  152. mm.getSeqId(fo);
  153. }
  154. if(f.value != null && f.value != ''){
  155. //field.value = f.value;
  156. if(form.getForm().isValid()){
  157. form.getForm().submit({
  158. url: basePath + 'oa/officialDocument/upload.action?em_code=' + em_code +
  159. '&number=QS_' + Ext.getCmp('in_id').getValue(),
  160. waitMsg: "正在上传:" + f.value,
  161. success: function(fp, o){
  162. console.log(o);
  163. if(o.result.error){
  164. showError(o.result.error);
  165. } else {
  166. Ext.Msg.alert("恭喜", f.value + " 上传成功!");
  167. btn.setText("上传成功(" + Ext.util.Format.fileSize(o.result.size) + ")");
  168. btn.disable(true);
  169. me.files[Number(btn.id.replace('upload', ''))] = o.result.filepath;
  170. }
  171. }
  172. });
  173. } else {
  174. me.FormUtil.checkForm();
  175. }
  176. }
  177. },
  178. flex: 1
  179. }, {
  180. xtype: 'button',
  181. text: '删除',
  182. id: 'delete' + me.attachcount,
  183. handler: function(btn){
  184. var f = Ext.getCmp(btn.id.replace('delete', 'attach'));
  185. if(f.value != null && f.value != ''){
  186. me.files[Number(btn.id.replace('delete', ''))] = '';
  187. }
  188. btn.ownerCt.destroy(true);
  189. me.attachcount--;
  190. },
  191. flex: 1
  192. }]
  193. });
  194. if(me.FormUtil.contains(field.value, "\\", true)){
  195. Ext.getCmp('attach' + me.attachcount).setValue(field.value.substring(field.value.lastIndexOf('\\') + 1));
  196. } else {
  197. Ext.getCmp('attach' + me.attachcount).setValue(field.value.substring(field.value.lastIndexOf('/') + 1));
  198. }
  199. Ext.getCmp('form').insert(9, container);
  200. me.attachcount++;
  201. field.button.setText("继续...");
  202. }
  203. }
  204. }
  205. });
  206. },
  207. getForm: function(btn){
  208. return btn.ownerCt.ownerCt;
  209. }
  210. });