send.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.oa.mail.send', {
  3. extend: 'Ext.app.Controller',
  4. BaseUtil: Ext.create('erp.util.BaseUtil'),
  5. FormUtil: Ext.create('erp.util.FormUtil'),
  6. views:[
  7. 'oa.mail.send','oa.mail.MailForm','oa.mail.TreePanel'
  8. ],
  9. init:function(){
  10. var me = this;
  11. me.attachcount = 0;
  12. me.files = new Array();
  13. this.control({
  14. 'erpMailTreePanel': {
  15. itemmousedown: function(selModel, record){
  16. if(record.get('leaf')){//不是根节点
  17. var value = Ext.getCmp('receAddr').value;
  18. if(value == null || value == ''){
  19. Ext.getCmp('receAddr').setValue(record.get('qtip'));
  20. }
  21. else if(me.BaseUtil.contains(Ext.getCmp('receAddr').value, record.get('qtip'), true)){
  22. return;
  23. }
  24. else{
  25. Ext.getCmp('receAddr').setValue(value + ';' + record.get('qtip'));
  26. }
  27. }
  28. selModel.deselect(record);
  29. }
  30. },
  31. 'displayfield[id=attachs]': {
  32. afterrender: function(field){
  33. field.hide();
  34. }
  35. },
  36. 'filefield[id=attach]': {
  37. change: function(field){
  38. if(field.value != null){
  39. var container = Ext.create('Ext.form.FieldContainer', {
  40. layout: 'hbox',
  41. fieldLabel: "附件" + (me.attachcount + 1),
  42. items: [{
  43. xtype: 'textfield',
  44. id: 'attach' + me.attachcount,
  45. flex: 1
  46. },{
  47. xtype: 'button',
  48. text: '上传',
  49. id: 'upload' + me.attachcount,
  50. handler: function(btn){
  51. var form = btn.ownerCt.ownerCt;
  52. var f = Ext.getCmp(btn.id.replace('upload', 'attach'));
  53. if(f.value != null && f.value != ''){
  54. //field.value = f.value;
  55. form.getForm().submit({
  56. url: basePath + 'common/upload.action?em_code=' + em_code,
  57. waitMsg: "正在上传:" + f.value,
  58. success: function(fp, o){
  59. if(o.result.error){
  60. showError(o.result.error);
  61. } else {
  62. Ext.Msg.alert("恭喜", f.value + " 上传成功!");
  63. btn.setText("上传成功(" + Ext.util.Format.fileSize(o.result.size) + ")");
  64. btn.disable(true);
  65. //field.button.disable(false);
  66. me.files[Number(btn.id.replace('upload', ''))] = o.result.filepath;
  67. }
  68. }
  69. });
  70. }
  71. },
  72. flex: 1
  73. }, {
  74. xtype: 'button',
  75. text: '删除',
  76. id: 'delete' + me.attachcount,
  77. handler: function(btn){
  78. var f = Ext.getCmp(btn.id.replace('delete', 'attach'));
  79. if(f.value != null && f.value != ''){
  80. me.files[Number(btn.id.replace('delete', ''))] = '';
  81. }
  82. btn.ownerCt.destroy(true);
  83. me.attachcount--;
  84. },
  85. flex: 1
  86. }]
  87. });
  88. if(me.FormUtil.contains(field.value, "\\", true)){
  89. Ext.getCmp('attach' + me.attachcount).setValue(field.value.substring(field.value.lastIndexOf('\\') + 1));
  90. } else {
  91. Ext.getCmp('attach' + me.attachcount).setValue(field.value.substring(field.value.lastIndexOf('/') + 1));
  92. }
  93. Ext.getCmp('form').insert(3, container);
  94. me.attachcount++;
  95. //field.reset();
  96. //field.button.disable(true);
  97. field.button.setText("继续...");
  98. }
  99. }
  100. },
  101. 'button[id=close]': {
  102. click: function(){
  103. me.FormUtil.onClose();
  104. }
  105. },
  106. 'button[id=post]': {
  107. click: function(){
  108. var form = Ext.getCmp('form').getForm();
  109. me.FormUtil.getActiveTab().setLoading(true);
  110. Ext.Ajax.request({
  111. url : basePath + 'oa/mail/send.action',
  112. params: {
  113. receAddr: Ext.getCmp('receAddr').value,
  114. subject: Ext.getCmp('subject').value,
  115. files: me.files,
  116. context: unescape(Ext.getCmp('context').getValue().replace(/\\u/g,"%u"))
  117. },
  118. method : 'post',
  119. callback : function(options,success,response){
  120. me.FormUtil.getActiveTab().setLoading(false);
  121. var localJson = new Ext.decode(response.responseText);
  122. if(localJson.exceptionInfo){
  123. showError(localJson.exceptionInfo);
  124. }
  125. if(localJson.success){
  126. Ext.Msg.alert("提示","邮件发送成功!", function(){
  127. window.location.href = window.location.href;
  128. });
  129. }
  130. }
  131. });
  132. }
  133. },
  134. 'button[id=save]': {
  135. click: function(){
  136. me.FormUtil.getActiveTab().setLoading(true);
  137. Ext.Ajax.request({
  138. url : basePath + 'oa/mail/save.action',
  139. params: {
  140. receAddr: Ext.getCmp('receAddr').value,
  141. subject: Ext.getCmp('subject').value,
  142. context: unescape(Ext.getCmp('context').getValue().replace(/\\u/g,"%u"))
  143. },
  144. method : 'post',
  145. callback : function(options,success,response){
  146. me.FormUtil.getActiveTab().setLoading(false);
  147. var localJson = new Ext.decode(response.responseText);
  148. if(localJson.exceptionInfo){
  149. showError(localJson.exceptionInfo);
  150. }
  151. if(localJson.success){
  152. Ext.Msg.alert("提示","邮件保存成功!");
  153. }
  154. }
  155. });
  156. }
  157. }
  158. });
  159. }
  160. });