Attachment.js 38 KB

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