Attachment.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  1. MWF.xDesktop.requireApp("process.Xform", "Attachment", null, false);
  2. MWF.xDesktop.requireApp("cms.FormDesigner", "widget.AttachmentController", null, false);
  3. MWF.xApplication.cms.Xform.AttachmentController = new Class({
  4. Extends: MWF.xApplication.cms.FormDesigner.widget.AttachmentController,
  5. "options": {
  6. "officeFiles": ["doc","docx","dotx","dot","xls","xlsx","xlsm","xlt","xltx","pptx","ppt","pot","potx","potm","pdf"]
  7. },
  8. checkDeleteAction: function(){
  9. if (this.options.readonly){
  10. this.setActionDisabled(this.deleteAction);
  11. this.setActionDisabled(this.min_deleteAction);
  12. return false;
  13. }
  14. if (this.options.isDeleteOption!=="y" && this.options.isDeleteOption!=="n"){
  15. if (this.selectedAttachments.length && this.selectedAttachments.length==1){
  16. var flag = true;
  17. if (this.options.isDeleteOption==="o"){
  18. for (var i=0; i<this.selectedAttachments.length; i++){
  19. if (this.selectedAttachments[i].data.person!==layout.desktop.session.user.distinguishedName){
  20. flag = false;
  21. break;
  22. }
  23. }
  24. }else if (this.options.isDeleteOption==="a"){
  25. for (var i=0; i<this.selectedAttachments.length; i++){
  26. if (this.selectedAttachments[i].data.activity!==this.module.form.businessData.activity.id){
  27. flag = false;
  28. break;
  29. }
  30. }
  31. }else if (this.options.isDeleteOption==="ao"){
  32. for (var i=0; i<this.selectedAttachments.length; i++){
  33. if ((this.selectedAttachments[i].data.activity!==this.module.form.businessData.activity.id) || (this.selectedAttachments[i].data.person!==layout.desktop.session.user.distinguishedName)){
  34. flag = false;
  35. break;
  36. }
  37. }
  38. }
  39. if (flag){
  40. this.setActionEnabled(this.deleteAction);
  41. this.setActionEnabled(this.min_deleteAction);
  42. }else{
  43. this.setActionDisabled(this.deleteAction);
  44. this.setActionDisabled(this.min_deleteAction);
  45. }
  46. }else{
  47. this.setActionDisabled(this.deleteAction);
  48. this.setActionDisabled(this.min_deleteAction);
  49. }
  50. }else{
  51. if (!this.options.isDelete){
  52. this.setActionDisabled(this.deleteAction);
  53. this.setActionDisabled(this.min_deleteAction);
  54. }else{
  55. if (this.selectedAttachments.length){
  56. this.setActionEnabled(this.deleteAction);
  57. this.setActionEnabled(this.min_deleteAction);
  58. }else{
  59. this.setActionDisabled(this.deleteAction);
  60. this.setActionDisabled(this.min_deleteAction);
  61. }
  62. }
  63. }
  64. },
  65. openInOfficeControl: function(att, office){
  66. if (office){
  67. if (!office.openedAttachment || office.openedAttachment.id!==att.id){
  68. office.save();
  69. MWF.Actions.get("x_cms_assemble_control").getAttachmentUrl(att.id, this.module.form.businessData.document.id, function(url){
  70. office.openedAttachment = {"id": att.id, "site": this.module.json.name, "name": att.name};
  71. office.officeOCX.BeginOpenFromURL(url, true, this.readonly);
  72. }.bind(this));
  73. }
  74. }
  75. },
  76. checkReplaceAction: function(){
  77. if (this.options.readonly){
  78. this.setActionDisabled(this.replaceAction);
  79. this.setActionDisabled(this.min_replaceAction);
  80. return false;
  81. }
  82. if (this.options.isReplaceOption!=="y" && this.options.isReplaceOption!=="n") {
  83. if (this.selectedAttachments.length && this.selectedAttachments.length===1){
  84. var flag;
  85. if (this.options.isReplaceOption==="o"){
  86. flag = this.selectedAttachments[0].data.person === layout.desktop.session.user.distinguishedName;
  87. }
  88. if (this.options.isReplaceOption==="a"){
  89. flag = this.selectedAttachments[0].data.activity===this.module.form.businessData.activity.id;
  90. }
  91. if (this.options.isReplaceOption==="ao"){
  92. flag = (this.selectedAttachments[0].data.person === layout.desktop.session.user.distinguishedName && this.selectedAttachments[0].data.activity===this.module.form.businessData.activity.id);
  93. }
  94. if (flag) {
  95. this.setActionEnabled(this.replaceAction);
  96. this.setActionEnabled(this.min_replaceAction);
  97. }else{
  98. this.setActionDisabled(this.replaceAction);
  99. this.setActionDisabled(this.min_replaceAction);
  100. }
  101. } else {
  102. this.setActionDisabled(this.replaceAction);
  103. this.setActionDisabled(this.min_replaceAction);
  104. }
  105. }else{
  106. if (!this.options.isReplace){
  107. this.setActionDisabled(this.replaceAction);
  108. this.setActionDisabled(this.min_replaceAction);
  109. }else{
  110. if (this.selectedAttachments.length && this.selectedAttachments.length===1){
  111. this.setActionEnabled(this.replaceAction);
  112. this.setActionEnabled(this.min_replaceAction);
  113. }else{
  114. this.setActionDisabled(this.replaceAction);
  115. this.setActionDisabled(this.min_replaceAction);
  116. }
  117. }
  118. }
  119. },
  120. replaceAttachment: function(e, node){
  121. var att = this.selectedAttachments[0].data;
  122. if (this.module.json.isOpenInOffice && this.module.json.officeControlName && (this.options.officeFiles.indexOf(att.extension)!==-1)){
  123. var office = this.module.form.all[this.module.json.officeControlName];
  124. if (office){
  125. if (this.min_closeOfficeAction) this.setActionEnabled(this.min_closeOfficeAction);
  126. if (this.closeOfficeAction) this.setActionEnabled(this.closeOfficeAction);
  127. this.openInOfficeControl(att, office);
  128. }else{
  129. if (this.selectedAttachments.length && this.selectedAttachments.length==1){
  130. if (this.module) this.module.replaceAttachment(e, node, this.selectedAttachments[0]);
  131. }
  132. }
  133. }else{
  134. if (this.selectedAttachments.length && this.selectedAttachments.length==1){
  135. if (this.module) this.module.replaceAttachment(e, node, this.selectedAttachments[0]);
  136. }
  137. }
  138. },
  139. //createTopNode: function(){
  140. // if (this.options.title){
  141. // if (!this.titleNode) this.titleNode = new Element("div", {"styles": this.css.titleNode, "text": this.options.title}).inject(this.node);
  142. // }
  143. // this.topNode = new Element("div", {"styles": this.css.topNode}).inject(this.node);
  144. // this.createEditGroupActions();
  145. // this.createReadGroupActions();
  146. // this.createListGroupActions();
  147. // if (this.module.json.isOpenInOffice && this.module.json.officeControlName) this.createOfficeGroupActions();
  148. // this.createViewGroupActions();
  149. //},
  150. createTopNode: function(){
  151. if (this.options.title){
  152. if (!this.titleNode) this.titleNode = new Element("div", {"styles": this.css.titleNode, "text": this.options.title}).inject(this.node);
  153. }
  154. if( !this.topNode ){
  155. this.topNode = new Element("div", {"styles": this.css.topNode}).inject(this.node);
  156. }else{
  157. this.topNode.empty();
  158. this.editActionBoxNode = null;
  159. this.editActionsGroupNode=null;
  160. this.topNode.setStyle("display","");
  161. if( this.isHiddenTop ){
  162. //this.container.setStyle("height", this.container.getSize().y + 45 );
  163. //this.node.setStyle("height", this.node.getSize().y + 45 );
  164. if( this.oldContentScrollNodeHeight ){
  165. this.contentScrollNode.setStyle("min-height",this.oldContentScrollNodeHeight);
  166. this.oldContentScrollNodeHeight = null;
  167. }
  168. this.isHiddenTop = false;
  169. }
  170. }
  171. var hiddenGroup = this.options.toolbarGroupHidden;
  172. if( hiddenGroup.contains("edit") && hiddenGroup.contains("read") && hiddenGroup.contains("list") && hiddenGroup.contains("view")){
  173. this.oldContentScrollNodeHeight = this.contentScrollNode.getStyle("min-height");
  174. this.contentScrollNode.setStyle("min-height",this.node.getStyle("min-height"));
  175. this.topNode.setStyle("display","none");
  176. this.isHiddenTop = true;
  177. return;
  178. }
  179. if( !hiddenGroup.contains("edit") )this.createEditGroupActions();
  180. if( !hiddenGroup.contains("read") )this.createReadGroupActions();
  181. if( !hiddenGroup.contains("list") )this.createListGroupActions();
  182. if( !hiddenGroup.contains("view") )this.createViewGroupActions();
  183. this.checkActions();
  184. },
  185. createOfficeGroupActions: function(){
  186. this.officeActionBoxNode = new Element("div", {"styles": this.css.actionsBoxNode}).inject(this.topNode);
  187. this.officeActionsGroupNode = new Element("div", {"styles": this.css.actionsGroupNode}).inject(this.officeActionBoxNode);
  188. this.closeOfficeAction = this.createAction(this.officeActionsGroupNode, "closeOffice", MWF.LP.widget.closeOffice, function(e, node){
  189. this.closeAttachmentOffice(e, node);
  190. }.bind(this));
  191. if (this.closeOfficeAction) this.setActionDisabled(this.closeOfficeAction);
  192. },
  193. loadMinActions: function(){
  194. this.min_uploadAction = this.createAction(this.minActionAreaNode, "upload", MWF.LP.widget.upload, function(e, node){
  195. this.uploadAttachment(e, node);
  196. }.bind(this));
  197. this.min_deleteAction = this.createAction(this.minActionAreaNode, "delete", MWF.LP.widget["delete"], function(e, node){
  198. this.deleteAttachment(e, node);
  199. }.bind(this));
  200. this.min_replaceAction = this.createAction(this.minActionAreaNode, "replace", MWF.LP.widget.replace, function(e, node){
  201. this.replaceAttachment(e, node);
  202. }.bind(this));
  203. this.min_downloadAction = this.createAction(this.minActionAreaNode, "download", MWF.LP.widget.download, function(e, node){
  204. this.downloadAttachment(e, node);
  205. }.bind(this));
  206. if (this.module.json.isOpenInOffice && this.module.json.officeControlName){
  207. this.min_closeOfficeAction = this.createAction(this.minActionAreaNode, "closeOffice", MWF.LP.widget.closeOffice, function(e, node){
  208. this.closeAttachmentOffice(e, node);
  209. }.bind(this));
  210. if (this.min_closeOfficeAction) this.setActionDisabled(this.closeOfficeAction);
  211. }
  212. this.createSeparate(this.minActionAreaNode);
  213. this.sizeAction = this.createAction(this.minActionAreaNode, "max", MWF.LP.widget.min, function(){
  214. this.changeControllerSize();
  215. }.bind(this));
  216. },
  217. closeAttachmentOffice: function(){
  218. var office = this.module.form.all[this.module.json.officeControlName];
  219. if (office){
  220. office.openFile();
  221. if (this.min_closeOfficeAction) this.setActionDisabled(this.min_closeOfficeAction);
  222. if (this.closeOfficeAction) this.setActionDisabled(this.closeOfficeAction);
  223. }
  224. }
  225. });
  226. MWF.xApplication.cms.Xform.Attachment = MWF.CMSAttachment = new Class({
  227. Extends: MWF.APPAttachment,
  228. options: {
  229. "moduleEvents": ["upload", "delete", "afterDelete", "load","queryLoad","postLoad"]
  230. },
  231. initialize: function(node, json, form, options){
  232. this.node = $(node);
  233. this.node.store("module", this);
  234. this.json = json;
  235. this.form = form;
  236. this.field = true;
  237. },
  238. _loadUserInterface: function(){
  239. this.node.empty();
  240. this.loadAttachmentController();
  241. this.fireEvent("load");
  242. },
  243. loadAttachmentController: function(){
  244. //MWF.require("MWF.widget.AttachmentController", function() {
  245. var options = {
  246. //"style" : "cms",
  247. "title": "附件区域",
  248. "listStyle": this.json.listStyle || "icon",
  249. "size": this.json.size || "max",
  250. "resize": (this.json.size=="true") ? true : false,
  251. "attachmentCount": this.json.attachmentCount || 0,
  252. "isUpload": (this.json.isUpload==="y" || this.json.isUpload==="true"),
  253. "isDelete": (this.json.isDelete==="y" || this.json.isDelete==="true"),
  254. "isReplace": (this.json.isReplace==="y" || this.json.isReplace==="true"),
  255. "isDownload": (this.json.isDownload==="y" || this.json.isDownload==="true"),
  256. "isSizeChange": (this.json.isSizeChange==="y" || this.json.isSizeChange==="true"),
  257. "readonly": (this.json.readonly==="y" || this.json.readonly==="true"),
  258. "availableListStyles" : this.json.availableListStyles ? this.json.availableListStyles : ["list","seq","icon","preview"],
  259. "isDeleteOption": this.json.isDelete,
  260. "isReplaceOption": this.json.isReplace,
  261. "toolbarGroupHidden" : this.json.toolbarGroupHidden || []
  262. //"downloadEvent" : this.json.downloadEvent
  263. };
  264. if (this.readonly) options.readonly = true;
  265. this.attachmentController = new MWF.xApplication.cms.Xform.AttachmentController(this.node, this, options);
  266. this.attachmentController.load();
  267. this.form.businessData.attachmentList.each(function (att) {
  268. if (att.site==this.json.id) this.attachmentController.addAttachment(att);
  269. //if (att.fileType.toLowerCase()==this.json.id.toLowerCase()) this.attachmentController.addAttachment(att);
  270. }.bind(this));
  271. //}.bind(this));
  272. },
  273. loadAttachmentSelecter: function( option, callback ){
  274. MWF.require("MWF.widget.AttachmentSelector", function() {
  275. var options = {
  276. //"style" : "cms",
  277. "title": "选择附件",
  278. "listStyle": "icon",
  279. "selectType" : "all",
  280. "size": "max",
  281. "attachmentCount": 0,
  282. "isUpload": true,
  283. "isDelete": true,
  284. "isReplace": true,
  285. "isDownload": true,
  286. "toBase64" : true,
  287. "base64MaxSize" : 800,
  288. "readonly": false
  289. };
  290. options = Object.merge( options, option );
  291. if (this.readonly) options.readonly = true;
  292. this.attachmentController = new MWF.widget.AttachmentSelector(this.node, this, options);
  293. this.attachmentController.load();
  294. this.postSelect = callback;
  295. this.form.businessData.attachmentList.each(function (att) {
  296. this.attachmentController.addAttachment(att);
  297. }.bind(this));
  298. }.bind(this));
  299. },
  300. selectAttachment: function(e, node, attachments){
  301. //if( attachments.length > 0 ){
  302. // this.form.documentAction.getAttachmentUrl(attachments[attachments.length-1].data.id, this.form.businessData.document.id, function(url){
  303. // if(this.postSelect)this.postSelect( url )
  304. // }.bind(this))
  305. //}
  306. if( attachments.length > 0 ){
  307. var data = attachments[attachments.length-1].data;
  308. this.form.documentAction.getAttachmentUrl( data.id, this.form.businessData.document.id, function(url){
  309. if( this.attachmentController.options.toBase64 ){
  310. this.form.documentAction.getSubjectAttachmentBase64( data.id, this.attachmentController.options.base64MaxSize, function( json ){
  311. var base64Code = json.data ? "data:image/png;base64,"+json.data.value : null;
  312. if(this.postSelect)this.postSelect( url , data, base64Code )
  313. }.bind(this) )
  314. }else{
  315. if(this.postSelect)this.postSelect( url , data )
  316. }
  317. }.bind(this))
  318. }
  319. },
  320. createUploadFileNode: function(){
  321. this.attachmentController.doUploadAttachment({"site": this.json.id}, this.form.documentAction.action, "uploadAttachment", {"id": this.form.businessData.document.id}, null, function(o){
  322. if (o.id){
  323. this.form.documentAction.getAttachment(o.id, this.form.businessData.document.id, function(json){
  324. if (json.data){
  325. this.attachmentController.addAttachment(json.data);
  326. this.form.businessData.attachmentList.push(json.data);
  327. }
  328. this.attachmentController.checkActions();
  329. this.fireEvent("upload", [json.data]);
  330. }.bind(this))
  331. }
  332. this.attachmentController.checkActions();
  333. }.bind(this), function(files){
  334. if (files.length){
  335. if ((files.length+this.attachmentController.attachments.length > this.attachmentController.options.attachmentCount) && this.attachmentController.options.attachmentCount>0){
  336. var content = MWF.xApplication.cms.Xform.LP.uploadMore;
  337. content = content.replace("{n}", this.attachmentController.options.attachmentCount);
  338. this.form.notice(content, "error");
  339. return false;
  340. }
  341. }
  342. return true;
  343. }.bind(this));
  344. // this.uploadFileAreaNode = new Element("div");
  345. // var html = "<input name=\"file\" type=\"file\" multiple/>";
  346. // this.uploadFileAreaNode.set("html", html);
  347. //
  348. // this.fileUploadNode = this.uploadFileAreaNode.getFirst();
  349. // this.fileUploadNode.addEvent("change", function(){
  350. // this.validationMode();
  351. // var files = this.fileUploadNode.files;
  352. // if (files.length){
  353. // if ((files.length+this.attachmentController.attachments.length > this.attachmentController.options.attachmentCount) && this.attachmentController.options.attachmentCount>0){
  354. // var content = MWF.xApplication.cms.Xform.LP.uploadMore;
  355. // content = content.replace("{n}", this.attachmentController.options.attachmentCount);
  356. // this.form.notice(content, "error");
  357. // }else{
  358. // for (var i = 0; i < files.length; i++) {
  359. // var file = files.item(i);
  360. //
  361. // var formData = new FormData();
  362. // formData.append('file', file);
  363. // formData.append('site', this.json.id);
  364. // //formData.append('folder', folderId);
  365. //
  366. // this.form.documentAction.uploadAttachment(this.form.businessData.document.id ,function(o, text){
  367. // if (o.id){
  368. // this.form.documentAction.getAttachment(o.id, this.form.businessData.document.id, function(json){
  369. // if (json.data){
  370. // this.attachmentController.addAttachment(json.data);
  371. // this.form.businessData.attachmentList.push(json.data);
  372. // }
  373. // this.attachmentController.checkActions();
  374. //
  375. // this.fireEvent("upload", [json.data]);
  376. // }.bind(this))
  377. // }
  378. // this.attachmentController.checkActions();
  379. // }.bind(this), null, formData, file);
  380. // }
  381. // }
  382. // }
  383. // }.bind(this));
  384. },
  385. uploadAttachment: function(e, node){
  386. if (window.o2android && window.o2android.uploadAttachment){
  387. window.o2android.uploadAttachment(this.json.id);
  388. }else if(window.webkit && window.webkit.messageHandlers) {
  389. window.webkit.messageHandlers.uploadAttachment.postMessage({"site": this.json.id});
  390. }else{
  391. // if (!this.uploadFileAreaNode){
  392. this.createUploadFileNode();
  393. // }
  394. // this.fileUploadNode.click();
  395. }
  396. },
  397. getData: function(){
  398. return this.attachmentController.getAttachmentNames();
  399. },
  400. //getInputData : function(){
  401. // return this.getData();
  402. //},
  403. deleteAttachments: function(e, node, attachments){
  404. var names = [];
  405. attachments.each(function(attachment){
  406. names.push(attachment.data.name);
  407. }.bind(this));
  408. var _self = this;
  409. this.form.confirm("warn", e, MWF.xApplication.cms.Xform.LP.deleteAttachmentTitle, MWF.xApplication.cms.Xform.LP.deleteAttachment+"( "+names.join(", ")+" )", 300, 120, function(){
  410. while (attachments.length){
  411. var attachment = attachments.shift();
  412. _self.deleteAttachment(attachment);
  413. }
  414. this.close();
  415. }, function(){
  416. this.close();
  417. }, null);
  418. },
  419. deleteAttachment: function(attachment){
  420. this.fireEvent("delete", [attachment.data]);
  421. this.form.documentAction.deleteAttachment(attachment.data.id, function(json ){
  422. this.attachmentController.removeAttachment(attachment);
  423. //this.form.businessData.attachmentList.erase( attachment.data )
  424. this.attachmentController.checkActions();
  425. this.fireEvent("afterDelete", [attachment.data]);
  426. }.bind(this));
  427. },
  428. replaceAttachment: function(e, node, attachment){
  429. if (window.o2android && window.o2android.replaceAttachment){
  430. window.o2android.replaceAttachment(attachment.data.id, this.json.id);
  431. }else if(window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.replaceAttachment) {
  432. window.webkit.messageHandlers.replaceAttachment.postMessage({"id": attachment.data.id, "site": this.json.id});
  433. }else {
  434. var _self = this;
  435. this.form.confirm("warn", e, MWF.xApplication.process.Xform.LP.replaceAttachmentTitle, MWF.xApplication.process.Xform.LP.replaceAttachment+"( "+attachment.data.name+" )", 350, 120, function(){
  436. _self.replaceAttachmentFile(attachment);
  437. this.close();
  438. }, function(){
  439. this.close();
  440. }, null);
  441. }
  442. },
  443. createReplaceFileNode: function(attachment){
  444. this.attachmentController.doUploadAttachment({"site": this.json.id}, this.form.documentAction.action, "replaceAttachment",
  445. {"id": attachment.data.id, "documentid": this.form.businessData.document.id}, null, function(o){
  446. this.form.documentAction.getAttachment(attachment.data.id, this.form.businessData.document.id, function(json){
  447. attachment.data = json.data;
  448. attachment.reload();
  449. this.attachmentController.checkActions();
  450. }.bind(this))
  451. }.bind(this), null);
  452. // this.replaceFileAreaNode = new Element("div");
  453. // var html = "<input name=\"file\" type=\"file\" multiple/>";
  454. // this.replaceFileAreaNode.set("html", html);
  455. //
  456. // this.fileReplaceNode = this.replaceFileAreaNode.getFirst();
  457. // this.fileReplaceNode.addEvent("change", function(){
  458. // var files = this.fileReplaceNode.files;
  459. // if (files.length){
  460. // for (var i = 0; i < files.length; i++) {
  461. // var file = files.item(i);
  462. //
  463. // var formData = new FormData();
  464. // formData.append('file', file);
  465. // // formData.append('site', this.json.id);
  466. //
  467. // this.form.documentAction.replaceAttachment(attachment.data.id, this.form.businessData.document.id ,function(o, text){
  468. // this.form.documentAction.getAttachment(attachment.data.id, this.form.businessData.document.id, function(json){
  469. // attachment.data = json.data;
  470. // attachment.reload();
  471. // this.attachmentController.checkActions();
  472. // }.bind(this))
  473. // }.bind(this), null, formData, file);
  474. // }
  475. // }
  476. // }.bind(this));
  477. },
  478. replaceAttachmentFile: function(attachment){
  479. //if (!this.replaceFileAreaNode){
  480. this.createReplaceFileNode(attachment);
  481. // }
  482. // this.fileReplaceNode.click();
  483. },
  484. downloadAttachment: function(e, node, attachments){
  485. if (this.form.businessData.document){
  486. attachments.each(function(att){
  487. if (window.o2android && window.o2android.downloadAttachment){
  488. window.o2android.downloadAttachment(att.data.id);
  489. }else if(window.webkit && window.webkit.messageHandlers) {
  490. window.webkit.messageHandlers.downloadAttachment.postMessage({"id": att.data.id, "site": this.json.id});
  491. }else{
  492. this.form.documentAction.getAttachmentStream(att.data.id, this.form.businessData.document.id);
  493. }
  494. }.bind(this));
  495. }
  496. },
  497. openAttachment: function(e, node, attachments){
  498. if (this.form.businessData.document){
  499. attachments.each(function(att){
  500. if (window.o2android && window.o2android.downloadAttachment){
  501. window.o2android.downloadAttachment(att.data.id);
  502. }else if(window.webkit && window.webkit.messageHandlers) {
  503. window.webkit.messageHandlers.downloadAttachment.postMessage({"id": att.data.id, "site": this.json.id});
  504. }else {
  505. this.form.documentAction.getAttachmentData(att.data.id, this.form.businessData.document.id);
  506. }
  507. }.bind(this));
  508. }
  509. //this.downloadAttachment(e, node, attachment);
  510. },
  511. getAttachmentUrl: function(attachment, callback){
  512. if (this.form.businessData.document){
  513. this.form.documentAction.getAttachmentUrl(attachment.data.id, this.form.businessData.document.id, callback);
  514. }
  515. },
  516. createErrorNode: function(text){
  517. var node = new Element("div");
  518. var iconNode = new Element("div", {
  519. "styles": {
  520. "width": "20px",
  521. "height": "20px",
  522. "float": "left",
  523. "background": "url("+"/x_component_process_Xform/$Form/default/icon/error.png) center center no-repeat"
  524. }
  525. }).inject(node);
  526. var textNode = new Element("div", {
  527. "styles": {
  528. "line-height": "20px",
  529. "margin-left": "20px",
  530. "color": "red",
  531. "word-break": "keep-all"
  532. },
  533. "text": text
  534. }).inject(node);
  535. return node;
  536. },
  537. notValidationMode: function(text){
  538. if (!this.isNotValidationMode){
  539. this.isNotValidationMode = true;
  540. this.node.store("borderStyle", this.node.getStyles("border-left", "border-right", "border-top", "border-bottom"));
  541. this.node.setStyle("border", "1px solid red");
  542. this.errNode = this.createErrorNode(text).inject(this.node, "after");
  543. this.showNotValidationMode(this.node);
  544. }
  545. },
  546. showNotValidationMode: function(node){
  547. var p = node.getParent("div");
  548. if (p){
  549. if (p.get("MWFtype") == "tab$Content"){
  550. if (p.getParent("div").getStyle("display")=="none"){
  551. var contentAreaNode = p.getParent("div").getParent("div");
  552. var tabAreaNode = contentAreaNode.getPrevious("div");
  553. var idx = contentAreaNode.getChildren().indexOf(p.getParent("div"));
  554. var tabNode = tabAreaNode.getChildren()[idx];
  555. tabNode.click();
  556. p = tabAreaNode.getParent("div");
  557. }
  558. }
  559. this.showNotValidationMode(p);
  560. }
  561. },
  562. validationMode: function(){
  563. if (this.isNotValidationMode){
  564. this.isNotValidationMode = false;
  565. this.node.setStyles(this.node.retrieve("borderStyle"));
  566. if (this.errNode){
  567. this.errNode.destroy();
  568. this.errNode = null;
  569. }
  570. }
  571. },
  572. validationConfigItem: function(routeName, data){
  573. var flag = (data.status=="all") ? true: (routeName == "publish");
  574. if (flag){
  575. var n = this.getData();
  576. var v = (data.valueType=="value") ? n : n.length;
  577. switch (data.operateor){
  578. case "isnull":
  579. if (!v){
  580. this.notValidationMode(data.prompt);
  581. return false;
  582. }
  583. break;
  584. case "notnull":
  585. if (v){
  586. this.notValidationMode(data.prompt);
  587. return false;
  588. }
  589. break;
  590. case "gt":
  591. if (v>data.value){
  592. this.notValidationMode(data.prompt);
  593. return false;
  594. }
  595. break;
  596. case "lt":
  597. if (v<data.value){
  598. this.notValidationMode(data.prompt);
  599. return false;
  600. }
  601. break;
  602. case "equal":
  603. if (v==data.value){
  604. this.notValidationMode(data.prompt);
  605. return false;
  606. }
  607. break;
  608. case "neq":
  609. if (v!=data.value){
  610. this.notValidationMode(data.prompt);
  611. return false;
  612. }
  613. break;
  614. case "contain":
  615. if (v.indexOf(data.value)!=-1){
  616. this.notValidationMode(data.prompt);
  617. return false;
  618. }
  619. break;
  620. case "notcontain":
  621. if (v.indexOf(data.value)==-1){
  622. this.notValidationMode(data.prompt);
  623. return false;
  624. }
  625. break;
  626. }
  627. }
  628. return true;
  629. },
  630. validationConfig: function(routeName, opinion){
  631. if (this.json.validationConfig){
  632. if (this.json.validationConfig.length){
  633. for (var i=0; i<this.json.validationConfig.length; i++) {
  634. var data = this.json.validationConfig[i];
  635. if (!this.validationConfigItem(routeName, data)) return false;
  636. }
  637. }
  638. return true;
  639. }
  640. return true;
  641. },
  642. validation: function(routeName, opinion){
  643. if (!this.validationConfig(routeName, opinion)) return false;
  644. if (!this.json.validation) return true;
  645. if (!this.json.validation.code) return true;
  646. var flag = this.form.Macro.exec(this.json.validation.code, this);
  647. if (!flag) flag = MWF.xApplication.process.Xform.LP.notValidation;
  648. if (flag.toString()!="true"){
  649. this.notValidationMode(flag);
  650. return false;
  651. }
  652. return true;
  653. }
  654. });