Attachment.js 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  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.process.Xform.AttachmentController,
  5. "options": {
  6. "checkTextEnable": false
  7. },
  8. openInOfficeControl: function (att, office) {
  9. if (office) {
  10. if (!office.openedAttachment || office.openedAttachment.id !== att.id) {
  11. office.save();
  12. MWF.Actions.get("x_cms_assemble_control").getAttachmentUrl(att.id, this.module.form.businessData.document.id, function (url) {
  13. office.openedAttachment = { "id": att.id, "site": this.module.json.name, "name": att.name };
  14. office.officeOCX.BeginOpenFromURL(url, true, this.readonly);
  15. }.bind(this));
  16. }
  17. }
  18. },
  19. setAttachmentConfig: function (readInput, editInput, controllerInput) {
  20. if (this.selectedAttachments.length) {
  21. var readList = readInput.retrieve("data-value");
  22. var editList = editInput.retrieve("data-value");
  23. var controllerList = controllerInput.retrieve("data-value");
  24. var readUnitList = [];
  25. var readIdentityList = [];
  26. var editUnitList = [];
  27. var editIdentityList = [];
  28. var controllerUnitList = [];
  29. var controllerIdentityList = [];
  30. if (readList) {
  31. readList.each(function (v) {
  32. var vName = (typeOf(v) === "string") ? v : v.distinguishedName;
  33. var len = vName.length;
  34. var flag = vName.substring(len - 1, len);
  35. if (flag === "U") readUnitList.push(vName);
  36. if (flag === "I") readIdentityList.push(vName);
  37. });
  38. }
  39. if (editList) {
  40. editList.each(function (v) {
  41. var vName = (typeOf(v) === "string") ? v : v.distinguishedName;
  42. var len = vName.length;
  43. var flag = vName.substring(len - 1, len);
  44. if (flag === "U") editUnitList.push(vName);
  45. if (flag === "I") editIdentityList.push(vName);
  46. });
  47. }
  48. if (controllerList) {
  49. controllerList.each(function (v) {
  50. var vName = (typeOf(v) === "string") ? v : v.distinguishedName;
  51. var len = vName.length;
  52. var flag = vName.substring(len - 1, len);
  53. if (flag === "U") controllerUnitList.push(vName);
  54. if (flag === "I") controllerIdentityList.push(vName);
  55. });
  56. }
  57. this.selectedAttachments.each(function (att) {
  58. att.data.readUnitList = readUnitList;
  59. att.data.readIdentityList = readIdentityList;
  60. att.data.editUnitList = editUnitList;
  61. att.data.editIdentityList = editIdentityList;
  62. att.data.controllerUnitList = controllerUnitList;
  63. att.data.controllerIdentityList = controllerIdentityList;
  64. o2.Actions.get("x_cms_assemble_control").configAttachment(att.data.id, this.module.form.businessData.document.id, att.data);
  65. }.bind(this));
  66. }
  67. },
  68. sortByNumber: function( attachments ){
  69. return attachments.sort(function (a1, a2) {
  70. if (!a2.data.seqNumber) return 1;
  71. if (!a1.data.seqNumber) return -1;
  72. return a1.data.seqNumber - a2.data.seqNumber;
  73. }.bind(this));
  74. },
  75. sortAttachment: function (node) {
  76. var nodes = node.getChildren();
  77. nodes.each(function (item, idx) {
  78. var att = item.retrieve("att", null);
  79. if (att) {
  80. att.data.seqNumber = idx;
  81. o2.Actions.load("x_cms_assemble_control").FileInfoAction.changeSeqNumber(att.data.id, this.module.form.businessData.document.id, idx);
  82. }
  83. }.bind(this));
  84. this.attachments = this.attachments.sort(function (a1, a2) {
  85. if (!a2.data.seqNumber) return 1;
  86. if (!a1.data.seqNumber) return -1;
  87. return a1.data.seqNumber - a2.data.seqNumber;
  88. }.bind(this));
  89. this.reloadAttachments();
  90. this.fireEvent("order");
  91. }
  92. });
  93. MWF.xApplication.cms.Xform.Attachment = MWF.CMSAttachment = new Class({
  94. Extends: MWF.APPAttachment,
  95. _loadUserInterface: function () {
  96. this.node.empty();
  97. this.loadAttachmentController();
  98. this.fireEvent("load");
  99. },
  100. loadAttachmentController: function () {
  101. //MWF.require("MWF.widget.AttachmentController", function() {
  102. var options = {
  103. "style": this.json.style || "default",
  104. "title": MWF.xApplication.cms.Xform.LP.attachmentArea,
  105. "listStyle": this.json.listStyle || "icon",
  106. "size": this.json.size || "max",
  107. "resize": this.getFlagDefaultFalse("resize"),
  108. "attachmentCount": this.json.attachmentCount || 0,
  109. "isUpload": this.getFlagDefaultFalse("isUpload"),
  110. "isDelete": this.getFlagDefaultFalse("isDelete"),
  111. "isReplace": this.getFlagDefaultFalse("isReplace"),
  112. "isDownload": this.getFlagDefaultFalse("isDownload"),
  113. "isPreviewAtt": this.getFlagDefaultFalse("isPreviewAtt"),
  114. "isEditAtt": this.getFlagDefaultFalse("isEditAtt"),
  115. "isSizeChange": this.getFlagDefaultFalse("isSizeChange"),
  116. "isConfig": this.getFlagDefaultTrue("isConfig"),
  117. "isOrder": this.getFlagDefaultTrue("isOrder"),
  118. "dblclick": this.json.dblclick,
  119. "readonly": (this.json.readonly === "y" || this.json.readonly === "true" || this.json.isReadonly || this.form.json.isReadonly),
  120. "availableListStyles": this.json.availableListStyles ? this.json.availableListStyles : ["list", "seq", "icon", "preview"],
  121. "isDeleteOption": this.json.isDelete,
  122. "isReplaceOption": this.json.isReplace,
  123. "toolbarGroupHidden": this.json.toolbarGroupHidden || [],
  124. "onOrder": function () {
  125. this.fireEvent("change");
  126. }.bind(this)
  127. //"downloadEvent" : this.json.downloadEvent
  128. };
  129. if (this.readonly) options.readonly = true;
  130. if (this.form.json && this.form.json.attachmentStyle) {
  131. options = Object.merge(options, this.form.json.attachmentStyle);
  132. }
  133. this.fireEvent("queryLoadController", [options]);
  134. this.attachmentController = new MWF.xApplication.cms.Xform.AttachmentController(this.node, this, options);
  135. this.fireEvent("loadController");
  136. this.attachmentController.load();
  137. this.fireEvent("postLoadController");
  138. this.form.businessData.attachmentList.each(function (att) {
  139. if (att.site === (this.json.site || this.json.id)) this.attachmentController.addAttachment(att);
  140. //if (att.fileType.toLowerCase()==this.json.id.toLowerCase()) this.attachmentController.addAttachment(att);
  141. }.bind(this));
  142. this.setAttachmentBusinessData();
  143. //}.bind(this));
  144. },
  145. loadAttachmentSelecter: function (option, callback) {
  146. MWF.require("MWF.widget.AttachmentSelector", function () {
  147. var options = {
  148. //"style" : "cms",
  149. "title": MWF.xApplication.cms.Xform.LP.selectAttachment, //"选择附件",
  150. "listStyle": "icon",
  151. "selectType": "all",
  152. "size": "max",
  153. "attachmentCount": 0,
  154. "isUpload": true,
  155. "isDelete": true,
  156. "isReplace": true,
  157. "isDownload": true,
  158. "toBase64": true,
  159. "base64MaxSize": 800,
  160. "readonly": false
  161. };
  162. options = Object.merge(options, option);
  163. if (this.readonly) options.readonly = true;
  164. this.attachmentController = new MWF.widget.AttachmentSelector(this.node, this, options);
  165. this.attachmentController.load();
  166. this.postSelect = callback;
  167. this.form.businessData.attachmentList.each(function (att) {
  168. this.attachmentController.addAttachment(att);
  169. }.bind(this));
  170. }.bind(this));
  171. },
  172. selectAttachment: function (e, node, attachments) {
  173. //if( attachments.length > 0 ){
  174. // this.form.documentAction.getAttachmentUrl(attachments[attachments.length-1].data.id, this.form.businessData.document.id, function(url){
  175. // if(this.postSelect)this.postSelect( url )
  176. // }.bind(this))
  177. //}
  178. if (attachments.length > 0) {
  179. var data = attachments[attachments.length - 1].data;
  180. this.form.documentAction.getAttachmentUrl(data.id, this.form.businessData.document.id, function (url) {
  181. if (this.attachmentController.options.toBase64) {
  182. this.form.documentAction.getSubjectAttachmentBase64(data.id, this.attachmentController.options.base64MaxSize, function (json) {
  183. var base64Code = json.data ? "data:image/png;base64," + json.data.value : null;
  184. if (this.postSelect) this.postSelect(url, data, base64Code)
  185. }.bind(this))
  186. } else {
  187. if (this.postSelect) this.postSelect(url, data)
  188. }
  189. }.bind(this))
  190. }
  191. },
  192. createUploadFileNode: function (files) {
  193. var accept = "*";
  194. if (!this.json.attachmentExtType || (this.json.attachmentExtType.indexOf("other") != -1 && !this.json.attachmentExtOtherType)) {
  195. } else {
  196. accepts = [];
  197. var otherType = this.json.attachmentExtOtherType;
  198. this.json.attachmentExtType.each(function (v) {
  199. switch (v) {
  200. case "word":
  201. accepts.push(".doc, .docx, .dot, .dotx");
  202. break;
  203. case "excel":
  204. accepts.push(".xls, .xlsx, .xlsm, .xlt, .xltx");
  205. break;
  206. case "ppt":
  207. accepts.push(".pptx, .ppt, .pot, .potx, .potm");
  208. break;
  209. case "txt":
  210. accepts.push(".txt");
  211. break;
  212. case "pic":
  213. accepts.push(".bmp, .gif, .psd, .jpeg, .jpg, .png");
  214. break;
  215. case "pdf":
  216. accepts.push(".pdf");
  217. break;
  218. case "zip":
  219. accepts.push(".zip, .rar");
  220. break;
  221. case "audio":
  222. accepts.push(".mp3, .wav, .wma, .wmv, .flac, .ape");
  223. break;
  224. case "video":
  225. accepts.push(".avi, .mkv, .mov, .ogg, .mp4, .mpeg");
  226. break;
  227. case "other":
  228. if (this.json.attachmentExtOtherType) accepts.push(this.json.attachmentExtOtherType);
  229. break;
  230. }
  231. }.bind(this));
  232. accept = accepts.join(", ");
  233. }
  234. var size = 0;
  235. if (this.json.attachmentSize) size = this.json.attachmentSize.toFloat();
  236. debugger;
  237. this.attachmentController.doUploadAttachment({ "site": this.json.id }, this.form.documentAction.action, "uploadAttachment", { "id": this.form.businessData.document.id }, null, function (o) {
  238. if (o.id) {
  239. this.form.documentAction.getAttachment(o.id, this.form.businessData.document.id, function (json) {
  240. if (json.data) {
  241. if (!json.data.control) json.data.control = {};
  242. this.attachmentController.addAttachment(json.data, o.messageId);
  243. this.form.businessData.attachmentList.push(json.data);
  244. }
  245. this.attachmentController.checkActions();
  246. this.setAttachmentBusinessData();
  247. this.fireEvent("upload", [json.data]);
  248. this.fireEvent("change");
  249. }.bind(this))
  250. }
  251. this.attachmentController.checkActions();
  252. }.bind(this), function (files) {
  253. if (files.length) {
  254. if ((files.length + this.attachmentController.attachments.length > this.attachmentController.options.attachmentCount) && this.attachmentController.options.attachmentCount > 0) {
  255. var content = MWF.xApplication.cms.Xform.LP.uploadMore;
  256. content = content.replace("{n}", this.attachmentController.options.attachmentCount);
  257. this.form.notice(content, "error");
  258. return false;
  259. }
  260. }
  261. this.fireEvent("beforeUpload", [files]);
  262. return true;
  263. }.bind(this), true, accept, size, function (o) { //错误的回调
  264. if (o.messageId && this.attachmentController.messageItemList) {
  265. var message = this.attachmentController.messageItemList[o.messageId];
  266. if( message && message.node )message.node.destroy();
  267. }
  268. }.bind(this), files);
  269. // this.uploadFileAreaNode = new Element("div");
  270. // var html = "<input name=\"file\" type=\"file\" multiple/>";
  271. // this.uploadFileAreaNode.set("html", html);
  272. //
  273. // this.fileUploadNode = this.uploadFileAreaNode.getFirst();
  274. // this.fileUploadNode.addEvent("change", function(){
  275. // this.validationMode();
  276. // var files = this.fileUploadNode.files;
  277. // if (files.length){
  278. // if ((files.length+this.attachmentController.attachments.length > this.attachmentController.options.attachmentCount) && this.attachmentController.options.attachmentCount>0){
  279. // var content = MWF.xApplication.cms.Xform.LP.uploadMore;
  280. // content = content.replace("{n}", this.attachmentController.options.attachmentCount);
  281. // this.form.notice(content, "error");
  282. // }else{
  283. // for (var i = 0; i < files.length; i++) {
  284. // var file = files.item(i);
  285. //
  286. // var formData = new FormData();
  287. // formData.append('file', file);
  288. // formData.append('site', this.json.id);
  289. // //formData.append('folder', folderId);
  290. //
  291. // this.form.documentAction.uploadAttachment(this.form.businessData.document.id ,function(o, text){
  292. // if (o.id){
  293. // this.form.documentAction.getAttachment(o.id, this.form.businessData.document.id, function(json){
  294. // if (json.data){
  295. // this.attachmentController.addAttachment(json.data);
  296. // this.form.businessData.attachmentList.push(json.data);
  297. // }
  298. // this.attachmentController.checkActions();
  299. //
  300. // this.fireEvent("upload", [json.data]);
  301. // }.bind(this))
  302. // }
  303. // this.attachmentController.checkActions();
  304. // }.bind(this), null, formData, file);
  305. // }
  306. // }
  307. // }
  308. // }.bind(this));
  309. },
  310. deleteAttachments: function (e, node, attachments) {
  311. var names = [];
  312. attachments.each(function (attachment) {
  313. names.push(attachment.data.name);
  314. }.bind(this));
  315. var _self = this;
  316. this.form.confirm("warn", e, MWF.xApplication.cms.Xform.LP.deleteAttachmentTitle, MWF.xApplication.cms.Xform.LP.deleteAttachment + "( " + names.join(", ") + " )", 300, 120, function () {
  317. while (attachments.length) {
  318. var attachment = attachments.shift();
  319. _self.deleteAttachment(attachment);
  320. }
  321. this.close();
  322. }, function () {
  323. this.close();
  324. }, null, null, this.form.json.confirmStyle);
  325. },
  326. deleteAttachment: function (attachment) {
  327. this.fireEvent("delete", [attachment.data]);
  328. var id = attachment.data.id;
  329. this.form.documentAction.deleteAttachment(attachment.data.id, function (json) {
  330. this.attachmentController.removeAttachment(attachment);
  331. //this.form.businessData.attachmentList.erase( attachment.data )
  332. this.attachmentController.checkActions();
  333. for( var i=0; i<this.form.businessData.attachmentList.length; i++ ){
  334. var attData = this.form.businessData.attachmentList[i];
  335. if( attData.id === id ){
  336. this.form.businessData.attachmentList.erase(attData);
  337. break;
  338. }
  339. }
  340. if (this.form.officeList) {
  341. this.form.officeList.each(function (office) {
  342. if (office.openedAttachment) {
  343. if (office.openedAttachment.id == id) {
  344. office.loadOfficeEdit();
  345. }
  346. }
  347. }.bind(this));
  348. }
  349. this.setAttachmentBusinessData();
  350. this.fireEvent("afterDelete", [attachment.data]);
  351. this.fireEvent("change");
  352. }.bind(this));
  353. },
  354. createReplaceFileNode: function (attachment) {
  355. var accept = "*";
  356. if (!this.json.attachmentExtType || this.json.attachmentExtType.indexOf("other") != -1 && !this.json.attachmentExtOtherType) {
  357. } else {
  358. accepts = [];
  359. var otherType = this.json.attachmentExtOtherType;
  360. this.json.attachmentExtType.each(function (v) {
  361. switch (v) {
  362. case "word":
  363. accepts.push(".doc, .docx, .dot, .dotx");
  364. break;
  365. case "excel":
  366. accepts.push(".xls, .xlsx, .xlsm, .xlt, .xltx");
  367. break;
  368. case "ppt":
  369. accepts.push(".pptx, .ppt, .pot, .potx, .potm");
  370. break;
  371. case "txt":
  372. accepts.push(".txt");
  373. break;
  374. case "pic":
  375. accepts.push(".bmp, .gif, .psd, .jpeg, .jpg");
  376. break;
  377. case "pdf":
  378. accepts.push(".pdf");
  379. break;
  380. case "zip":
  381. accepts.push(".zip, .rar");
  382. break;
  383. case "audio":
  384. accepts.push(".mp3, .wav, .wma, .wmv, .flac, .ape");
  385. break;
  386. case "video":
  387. accepts.push(".avi, .mkv, .mov, .ogg, .mp4, .mpeg");
  388. break;
  389. case "other":
  390. if (this.json.attachmentExtOtherType) accepts.push(this.json.attachmentExtOtherType);
  391. break;
  392. }
  393. });
  394. accept = accepts.join(", ");
  395. }
  396. var size = 0;
  397. if (this.json.attachmentSize) size = this.json.attachmentSize.toFloat();
  398. this.attachmentController.doUploadAttachment({ "site": (this.json.site || this.json.id) }, this.form.documentAction.action, "replaceAttachment",
  399. { "id": attachment.data.id, "documentid": this.form.businessData.document.id }, null, function (o) {
  400. this.form.documentAction.getAttachment(attachment.data.id, this.form.businessData.document.id, function (json) {
  401. if (!json.data.control) json.data.control = {};
  402. attachment.data = json.data;
  403. attachment.reload();
  404. this.fireEvent("change");
  405. if (o.messageId && this.attachmentController.messageItemList) {
  406. var message = this.attachmentController.messageItemList[o.messageId];
  407. if( message && message.node )message.node.destroy();
  408. }
  409. this.attachmentController.checkActions();
  410. }.bind(this))
  411. }.bind(this), null, true, accept, size, function (o) { //错误的回调
  412. if (o.messageId && this.attachmentController.messageItemList) {
  413. var message = this.attachmentController.messageItemList[o.messageId];
  414. if( message && message.node )message.node.destroy();
  415. }
  416. }.bind(this));
  417. // this.replaceFileAreaNode = new Element("div");
  418. // var html = "<input name=\"file\" type=\"file\" multiple/>";
  419. // this.replaceFileAreaNode.set("html", html);
  420. //
  421. // this.fileReplaceNode = this.replaceFileAreaNode.getFirst();
  422. // this.fileReplaceNode.addEvent("change", function(){
  423. // var files = this.fileReplaceNode.files;
  424. // if (files.length){
  425. // for (var i = 0; i < files.length; i++) {
  426. // var file = files.item(i);
  427. //
  428. // var formData = new FormData();
  429. // formData.append('file', file);
  430. // // formData.append('site', this.json.id);
  431. //
  432. // this.form.documentAction.replaceAttachment(attachment.data.id, this.form.businessData.document.id ,function(o, text){
  433. // this.form.documentAction.getAttachment(attachment.data.id, this.form.businessData.document.id, function(json){
  434. // attachment.data = json.data;
  435. // attachment.reload();
  436. // this.attachmentController.checkActions();
  437. // }.bind(this))
  438. // }.bind(this), null, formData, file);
  439. // }
  440. // }
  441. // }.bind(this));
  442. },
  443. //小程序文件是否支持打开
  444. checkMiniProgramFile: function(ext) {
  445. var exts = ["doc", "docx", "xls", "xlsx", "ppt", "pptx", "pdf"];
  446. for(var i = 0; i < exts.length; i++){
  447. if(ext === exts[i]){
  448. return true;
  449. }
  450. }
  451. return false;
  452. },
  453. downloadAttachment: function (e, node, attachments) {
  454. if (this.form.businessData.document) {
  455. attachments.each(function (att) {
  456. if (window.o2android && window.o2android.postMessage) {
  457. var body = {
  458. type: "downloadAttachment",
  459. data: {
  460. attachmentId: att.data.id
  461. }
  462. };
  463. window.o2android.postMessage(JSON.stringify(body))
  464. } else if (window.o2android && window.o2android.downloadAttachment) {
  465. window.o2android.downloadAttachment(att.data.id);
  466. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.downloadAttachment) {
  467. window.webkit.messageHandlers.downloadAttachment.postMessage({ "id": att.data.id, "site": this.json.id });
  468. } else if (window.wx && window.__wxjs_environment === 'miniprogram' && this.checkMiniProgramFile(att.data.extension)) { //微信小程序
  469. wx.miniProgram.navigateTo({
  470. url: '../file/download?attId=' + att.data.id + '&type=cms&documentId=' + this.form.businessData.document.id
  471. });
  472. } else {
  473. if (layout.mobile) {
  474. //移动端 企业微信 钉钉 用本地打开 防止弹出自带浏览器 无权限问题
  475. this.form.documentAction.getAttachmentUrl(att.data.id, this.form.businessData.document.id, function (url) {
  476. var xtoken = Cookie.read(o2.tokenName);
  477. window.location = o2.filterUrl(url + "?"+o2.tokenName+"=" + xtoken);
  478. });
  479. } else {
  480. this.form.documentAction.getAttachmentStream(att.data.id, this.form.businessData.document.id);
  481. }
  482. }
  483. this.fireEvent("download",[att])
  484. }.bind(this));
  485. }
  486. },
  487. openAttachment: function (e, node, attachments) {
  488. if (this.form.businessData.document) {
  489. attachments.each(function (att) {
  490. if (window.o2android && window.o2android.downloadAttachment) {
  491. window.o2android.downloadAttachment(att.data.id);
  492. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.downloadAttachment) {
  493. window.webkit.messageHandlers.downloadAttachment.postMessage({ "id": att.data.id, "site": this.json.id });
  494. } else if (window.wx && window.__wxjs_environment === 'miniprogram' && this.checkMiniProgramFile(att.data.extension)) { //微信小程序
  495. wx.miniProgram.navigateTo({
  496. url: '../file/download?attId=' + att.data.id + '&type=cms&documentId=' + this.form.businessData.document.id
  497. });
  498. } else {
  499. if (layout.mobile) {
  500. //移动端 企业微信 钉钉 用本地打开 防止弹出自带浏览器 无权限问题
  501. this.form.documentAction.getAttachmentUrl(att.data.id, this.form.businessData.document.id, function (url) {
  502. var xtoken = Cookie.read(o2.tokenName);
  503. window.location = o2.filterUrl(url + "?"+o2.tokenName+"=" + xtoken);
  504. });
  505. } else {
  506. this.form.documentAction.getAttachmentData(att.data.id, this.form.businessData.document.id);
  507. }
  508. }
  509. this.fireEvent("open",[att])
  510. }.bind(this));
  511. }
  512. //this.downloadAttachment(e, node, attachment);
  513. },
  514. getAttachmentUrl: function (attachment, callback) {
  515. if (this.form.businessData.document) {
  516. this.form.documentAction.getAttachmentUrl(attachment.data.id, this.form.businessData.document.id, callback);
  517. }
  518. },
  519. getTextData: function(){
  520. var data = [];
  521. this.attachmentController.attachments.each(function(att){
  522. var o = {
  523. "id": att.data.id,
  524. "person": att.data.person,
  525. "creatorUid": att.data.creatorUid,
  526. "name": att.data.name,
  527. "seqNumber": att.data.seqNumber,
  528. "length": att.data.length,
  529. "extension": att.data.extension,
  530. "lastUpdateTime": att.data.lastUpdateTime,
  531. "activityName": att.data.activityName,
  532. "control" : att.data.control
  533. }
  534. data.push(o);
  535. });
  536. return data;
  537. },
  538. validationConfigItem: function (routeName, data) {
  539. var flag = (data.status == "all") ? true : (routeName == "publish");
  540. if (flag) {
  541. var n = this.getData() || [];
  542. var v = (data.valueType == "value") ? n : n.length;
  543. switch (data.operateor) {
  544. case "isnull":
  545. if (!v) {
  546. this.notValidationMode(data.prompt);
  547. return false;
  548. }
  549. break;
  550. case "notnull":
  551. if (v) {
  552. this.notValidationMode(data.prompt);
  553. return false;
  554. }
  555. break;
  556. case "gt":
  557. if (v > data.value) {
  558. this.notValidationMode(data.prompt);
  559. return false;
  560. }
  561. break;
  562. case "lt":
  563. if (v < data.value) {
  564. this.notValidationMode(data.prompt);
  565. return false;
  566. }
  567. break;
  568. case "equal":
  569. if (v == data.value) {
  570. this.notValidationMode(data.prompt);
  571. return false;
  572. }
  573. break;
  574. case "neq":
  575. if (v != data.value) {
  576. this.notValidationMode(data.prompt);
  577. return false;
  578. }
  579. break;
  580. case "contain":
  581. if (v.indexOf(data.value) != -1) {
  582. this.notValidationMode(data.prompt);
  583. return false;
  584. }
  585. break;
  586. case "notcontain":
  587. if (v.indexOf(data.value) == -1) {
  588. this.notValidationMode(data.prompt);
  589. return false;
  590. }
  591. break;
  592. }
  593. }
  594. return true;
  595. }
  596. });
  597. MWF.xApplication.cms.Xform.AttachmentDg = MWF.CMSAttachmentDg = new Class({
  598. Extends: MWF.CMSAttachment,
  599. loadAttachmentController: function () {
  600. //MWF.require("MWF.widget.AttachmentController", function() {
  601. var options = {
  602. "style": this.json.style || "default",
  603. "title": MWF.xApplication.process.Xform.LP.attachmentArea,
  604. "listStyle": this.json.listStyle || "icon",
  605. "size": this.json.size || "max",
  606. "resize": this.getFlagDefaultFalse("resize"),
  607. "attachmentCount": this.json.attachmentCount || 0,
  608. "isUpload": this.getFlagDefaultFalse("isUpload"),
  609. "isDelete": this.getFlagDefaultFalse("isDelete"),
  610. "isReplace": this.getFlagDefaultFalse("isReplace"),
  611. "isDownload": this.getFlagDefaultFalse("isDownload"),
  612. "isPreviewAtt": this.getFlagDefaultFalse("isPreviewAtt"),
  613. "isEditAtt": this.getFlagDefaultFalse("isEditAtt"),
  614. "isSizeChange": this.getFlagDefaultFalse("isSizeChange"),
  615. "isConfig": this.getFlagDefaultTrue("isConfig"),
  616. "isOrder": this.getFlagDefaultTrue("isOrder"),
  617. "dblclick": this.json.dblclick,
  618. "readonly": (this.json.readonly === "y" || this.json.readonly === "true" || this.json.isReadonly || this.form.json.isReadonly),
  619. "availableListStyles": this.json.availableListStyles ? this.json.availableListStyles : ["list", "seq", "icon", "preview"],
  620. "isDeleteOption": this.json.isDelete,
  621. "isReplaceOption": this.json.isReplace,
  622. "toolbarGroupHidden": this.json.toolbarGroupHidden || [],
  623. "ignoreSite": this.json.ignoreSite,
  624. "onOrder": function () {
  625. this.fireEvent("change");
  626. }.bind(this)
  627. };
  628. if (this.readonly) options.readonly = true;
  629. if (this.form.json.attachmentStyle) {
  630. options = Object.merge(options, this.form.json.attachmentStyle);
  631. }
  632. this.fireEvent("queryLoadController", [options]);
  633. this.attachmentController = new MWF.xApplication.process.Xform.AttachmentController(this.node, this, options);
  634. this.fireEvent("loadController");
  635. this.attachmentController.load();
  636. this.fireEvent("postLoadController");
  637. // var d = this._getBusinessData();
  638. // if (d) d.each(function (att) {
  639. // this.attachmentController.addAttachment(att);
  640. // }.bind(this));
  641. if(this.json.ignoreSite) {
  642. ( this._getBusinessData() || [] ).each(function (att) {
  643. var flag = this.form.businessData.attachmentList.some(function (attData) {
  644. return att.id === attData.id;
  645. }.bind(this));
  646. if(flag)this.attachmentController.addAttachment(att);
  647. }.bind(this));
  648. }else{
  649. this.form.businessData.attachmentList.each(function (att) {
  650. if (att.site === (this.json.site || this.json.id)) this.attachmentController.addAttachment(att);
  651. }.bind(this));
  652. }
  653. this.setAttachmentBusinessData();
  654. },
  655. setAttachmentBusinessData: function(){
  656. if (this.attachmentController) {
  657. if (this.attachmentController.attachments.length) {
  658. var values = this.attachmentController.attachments.map(function (d) {
  659. return {
  660. "control": d.data.control,
  661. "name": d.data.name,
  662. "id": d.data.id,
  663. "person": d.data.person,
  664. "creatorUid": d.data.creatorUid,
  665. "seqNumber": d.data.seqNumber,
  666. "length": d.data.length,
  667. "extension": d.data.extension,
  668. "lastUpdateTime": d.data.lastUpdateTime,
  669. "activityName": d.data.activityName
  670. };
  671. });
  672. this._setBusinessData(values);
  673. } else {
  674. this._setBusinessData([]);
  675. }
  676. }
  677. },
  678. uploadAttachment: function (e, node, files) {
  679. debugger;
  680. if (window.o2android && window.o2android.postMessage) {
  681. var body = {
  682. type: "uploadAttachmentForDatagrid",
  683. data: {
  684. param: this.json.id,
  685. site: this.json.site || this.json.id
  686. }
  687. };
  688. window.o2android.postMessage(JSON.stringify(body));
  689. } else if (window.o2android && window.o2android.uploadAttachmentForDatagrid) {
  690. window.o2android.uploadAttachmentForDatagrid((this.json.site || this.json.id), this.json.id);
  691. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.uploadAttachmentForDatagrid) {
  692. window.webkit.messageHandlers.uploadAttachmentForDatagrid.postMessage({ "site": (this.json.site || this.json.id) , "param":this.json.id});
  693. } else {
  694. // if (!this.uploadFileAreaNode){
  695. this.createUploadFileNode(files);
  696. // }
  697. // this.fileUploadNode.click();
  698. }
  699. },
  700. replaceAttachment: function (e, node, attachment) {
  701. if (window.o2android && window.o2android.postMessage) {
  702. var body = {
  703. type: "replaceAttachmentForDatagrid",
  704. data: {
  705. attachmentId: attachment.data.id,
  706. param: this.json.id,
  707. site: this.json.site || this.json.id
  708. }
  709. };
  710. window.o2android.postMessage(JSON.stringify(body));
  711. } else if (window.o2android && window.o2android.replaceAttachmentForDatagrid) {
  712. window.o2android.replaceAttachmentForDatagrid(attachment.data.id, (this.json.site || this.json.id), this.json.id);
  713. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.replaceAttachmentForDatagrid) {
  714. window.webkit.messageHandlers.replaceAttachmentForDatagrid.postMessage({ "id": attachment.data.id, "site": (this.json.site || this.json.id) , "param":this.json.id});
  715. } else {
  716. var _self = this;
  717. this.form.confirm("warn", e, MWF.xApplication.process.Xform.LP.replaceAttachmentTitle, MWF.xApplication.process.Xform.LP.replaceAttachment + "( " + attachment.data.name + " )", 350, 120, function () {
  718. _self.replaceAttachmentFile(attachment);
  719. this.close();
  720. }, function () {
  721. this.close();
  722. }, null, null, this.form.json.confirmStyle);
  723. }
  724. }
  725. });