Attachment.js 37 KB

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