Attachment.js 90 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957
  1. MWF.xDesktop.requireApp("process.Xform", "$Module", null, false);
  2. MWF.require("MWF.widget.AttachmentController", null, false);
  3. MWF.xApplication.process.Xform.AttachmentController = new Class({
  4. Extends: MWF.widget.ATTER,
  5. "options": {
  6. "officeFiles": ["doc", "docx", "dotx", "dot", "xls", "xlsx", "xlsm", "xlt", "xltx", "pptx", "ppt", "pot", "potx", "potm", "pdf"],
  7. "checkTextEnable": true
  8. },
  9. checkAttachmentDeleteAction: function () {
  10. if (this.options.readonly) {
  11. this.setAttachmentsAction("delete", false);
  12. return false;
  13. }
  14. if (this.options.isDeleteOption !== "n") {
  15. if (this.attachments.length) {
  16. var user = layout.session.user.distinguishedName;
  17. for (var i = 0; i < this.attachments.length; i++) {
  18. var flag = true;
  19. var att = this.attachments[i];
  20. if (!att.data.person && att.data.creatorUid) att.data.person = att.data.creatorUid;
  21. if (this.options.isDeleteOption === "o") {
  22. if (!att.data.control.allowEdit && att.data.person !== user) flag = false;
  23. if (att.data.person !== layout.desktop.session.user.distinguishedName) flag = false;
  24. } else if (this.options.isDeleteOption === "a") {
  25. if (!att.data.control.allowEdit && att.data.person !== user) flag = false;
  26. if (att.data.activity !== this.module.form.businessData.activity.id) flag = false;
  27. } else if (this.options.isDeleteOption === "ao") {
  28. if (!att.data.control.allowEdit && att.data.person !== user) flag = false;
  29. if ((att.data.activity !== this.module.form.businessData.activity.id) || (att.data.person !== layout.desktop.session.user.distinguishedName)) flag = false;
  30. } else {
  31. if (!att.data.control.allowEdit && att.data.person !== user) flag = false;
  32. }
  33. if (flag) {
  34. this.setAttachmentAction(att, "delete", true);
  35. } else {
  36. this.setAttachmentAction(att, "delete", false);
  37. }
  38. }
  39. }
  40. } else {
  41. this.setAttachmentsAction("delete", false);
  42. }
  43. },
  44. checkDeleteAction: function () {
  45. this.checkAttachmentDeleteAction();
  46. if (this.options.readonly) {
  47. this.setActionDisabled(this.deleteAction);
  48. this.setActionDisabled(this.min_deleteAction);
  49. return false;
  50. }
  51. if (this.options.isDeleteOption !== "n") {
  52. if (this.selectedAttachments.length) {
  53. var user = layout.session.user.distinguishedName;
  54. var flag = true;
  55. if (this.options.isDeleteOption === "o") {
  56. for (var i = 0; i < this.selectedAttachments.length; i++) {
  57. var att = this.selectedAttachments[i];
  58. if (!att.data.person && att.data.creatorUid) att.data.person = att.data.creatorUid;
  59. if (!att.data.control.allowEdit && att.data.person !== user) {
  60. flag = false;
  61. break;
  62. }
  63. if (att.data.person !== layout.desktop.session.user.distinguishedName) {
  64. flag = false;
  65. break;
  66. }
  67. }
  68. } else if (this.options.isDeleteOption === "a") {
  69. for (var i = 0; i < this.selectedAttachments.length; i++) {
  70. var att = this.selectedAttachments[i];
  71. if (!att.data.person && att.data.creatorUid) att.data.person = att.data.creatorUid;
  72. if (!att.data.control.allowEdit && att.data.person !== user) {
  73. flag = false;
  74. break;
  75. }
  76. if (att.data.activity !== this.module.form.businessData.activity.id) {
  77. flag = false;
  78. break;
  79. }
  80. }
  81. } else if (this.options.isDeleteOption === "ao") {
  82. for (var i = 0; i < this.selectedAttachments.length; i++) {
  83. var att = this.selectedAttachments[i];
  84. if (!att.data.person && att.data.creatorUid) att.data.person = att.data.creatorUid;
  85. if (!att.data.control.allowEdit && att.data.person !== user) {
  86. flag = false;
  87. break;
  88. }
  89. if ((att.data.activity !== this.module.form.businessData.activity.id) || (att.data.person !== layout.desktop.session.user.distinguishedName)) {
  90. flag = false;
  91. break;
  92. }
  93. }
  94. } else {
  95. for (var i = 0; i < this.selectedAttachments.length; i++) {
  96. var att = this.selectedAttachments[i];
  97. if (!att.data.person && att.data.creatorUid) att.data.person = att.data.creatorUid;
  98. if (!att.data.control.allowEdit && att.data.person !== user) {
  99. flag = false;
  100. break;
  101. }
  102. }
  103. }
  104. if (flag) {
  105. this.setActionEnabled(this.deleteAction);
  106. this.setActionEnabled(this.min_deleteAction);
  107. } else {
  108. this.setActionDisabled(this.deleteAction);
  109. this.setActionDisabled(this.min_deleteAction);
  110. }
  111. } else {
  112. this.setActionDisabled(this.deleteAction);
  113. this.setActionDisabled(this.min_deleteAction);
  114. }
  115. } else {
  116. // if (!this.options.isDelete){
  117. this.setActionDisabled(this.deleteAction);
  118. this.setActionDisabled(this.min_deleteAction);
  119. // }else{
  120. // if (this.selectedAttachments.length){
  121. // this.setActionEnabled(this.deleteAction);
  122. // this.setActionEnabled(this.min_deleteAction);
  123. // }else{
  124. // this.setActionDisabled(this.deleteAction);
  125. // this.setActionDisabled(this.min_deleteAction);
  126. // }
  127. // }
  128. }
  129. },
  130. isAttDeleteAvailable: function (att) {
  131. if (this.options.readonly) return false;
  132. if (this.options.toolbarGroupHidden.contains("edit")) return false;
  133. if (this.options.isDeleteOption === "n") return false;
  134. var user = layout.session.user.distinguishedName;
  135. var flag = true;
  136. if (!att.data.person && att.data.creatorUid) att.data.person = att.data.creatorUid;
  137. if (this.options.isDeleteOption === "o") {
  138. if (!att.data.control.allowEdit && att.data.person !== user) flag = false;
  139. if (att.data.person !== layout.desktop.session.user.distinguishedName) flag = false;
  140. } else if (this.options.isDeleteOption === "a") {
  141. if (!att.data.control.allowEdit && att.data.person !== user) flag = false;
  142. if (att.data.activity !== this.module.form.businessData.activity.id) flag = false;
  143. } else if (this.options.isDeleteOption === "ao") {
  144. if (!att.data.control.allowEdit && att.data.person !== user) flag = false;
  145. if ((att.data.activity !== this.module.form.businessData.activity.id) || (att.data.person !== layout.desktop.session.user.distinguishedName)) flag = false;
  146. } else {
  147. if (!att.data.control.allowEdit && att.data.person !== user) flag = false;
  148. }
  149. return flag;
  150. },
  151. openInOfficeControl: function (att, office) {
  152. if (office) {
  153. if (!office.openedAttachment || office.openedAttachment.id !== att.id) {
  154. office.save();
  155. if (this.module.form.businessData.workCompleted) {
  156. MWF.Actions.get("x_processplatform_assemble_surface").getAttachmentWorkcompletedUrl(att.id, this.module.form.businessData.workCompleted.id, function (url) {
  157. office.openedAttachment = { "id": att.id, "site": this.module.json.name, "name": att.name };
  158. office.officeOCX.BeginOpenFromURL(url, true, this.readonly);
  159. }.bind(this));
  160. } else {
  161. MWF.Actions.get("x_processplatform_assemble_surface").getAttachmentUrl(att.id, this.module.form.businessData.work.id, function (url) {
  162. office.openedAttachment = { "id": att.id, "site": this.module.json.name, "name": att.name };
  163. office.officeOCX.BeginOpenFromURL(url, true, this.readonly);
  164. }.bind(this));
  165. }
  166. }
  167. }
  168. },
  169. checkReplaceAction: function () {
  170. if (this.options.isReplaceHidden) return;
  171. if (this.options.readonly) {
  172. this.setActionDisabled(this.replaceAction);
  173. this.setActionDisabled(this.min_replaceAction);
  174. return false;
  175. }
  176. if (this.options.isReplaceOption !== "n") {
  177. if (this.selectedAttachments.length && this.selectedAttachments.length === 1) {
  178. var att = this.selectedAttachments[0];
  179. if (!att.data.person && att.data.creatorUid) att.data.person = att.data.creatorUid;
  180. var user = layout.session.user.distinguishedName;
  181. var flag = true;
  182. if (this.options.isReplaceOption === "o") {
  183. flag = att.data.person === layout.desktop.session.user.distinguishedName;
  184. }
  185. if (this.options.isReplaceOption === "a") {
  186. flag = att.data.activity === this.module.form.businessData.activity.id;
  187. }
  188. if (this.options.isReplaceOption === "ao") {
  189. flag = (att.data.person === layout.desktop.session.user.distinguishedName && att.data.activity === this.module.form.businessData.activity.id);
  190. }
  191. if (flag && !att.data.control.allowEdit && att.data.person !== user) {
  192. flag = false;
  193. }
  194. if (flag) {
  195. this.setActionEnabled(this.replaceAction);
  196. this.setActionEnabled(this.min_replaceAction);
  197. } else {
  198. this.setActionDisabled(this.replaceAction);
  199. this.setActionDisabled(this.min_replaceAction);
  200. }
  201. } else {
  202. this.setActionDisabled(this.replaceAction);
  203. this.setActionDisabled(this.min_replaceAction);
  204. }
  205. } else {
  206. // if (!this.options.isReplace){
  207. this.setActionDisabled(this.replaceAction);
  208. this.setActionDisabled(this.min_replaceAction);
  209. // }else{
  210. // if (this.selectedAttachments.length && this.selectedAttachments.length===1){
  211. // this.setActionEnabled(this.replaceAction);
  212. // this.setActionEnabled(this.min_replaceAction);
  213. // }else{
  214. // this.setActionDisabled(this.replaceAction);
  215. // this.setActionDisabled(this.min_replaceAction);
  216. // }
  217. // }
  218. }
  219. },
  220. replaceAttachment: function (e, node) {
  221. var att = this.selectedAttachments[0].data;
  222. if (this.module.json.isOpenInOffice && this.module.json.officeControlName && (this.options.officeFiles.indexOf(att.extension) !== -1)) {
  223. var office = this.module.form.all[this.module.json.officeControlName];
  224. if (office) {
  225. if (this.min_closeOfficeAction) this.setActionEnabled(this.min_closeOfficeAction);
  226. if (this.closeOfficeAction) this.setActionEnabled(this.closeOfficeAction);
  227. this.openInOfficeControl(att, office);
  228. } else {
  229. if (this.selectedAttachments.length && this.selectedAttachments.length == 1) {
  230. if (this.module) this.module.replaceAttachment(e, node, this.selectedAttachments[0]);
  231. }
  232. }
  233. } else {
  234. if (this.selectedAttachments.length && this.selectedAttachments.length == 1) {
  235. if (this.module) this.module.replaceAttachment(e, node, this.selectedAttachments[0]);
  236. }
  237. }
  238. },
  239. isAttReplaceAvailable: function (att) {
  240. if (this.options.readonly) return false;
  241. if (this.options.toolbarGroupHidden.contains("edit")) return false;
  242. if (this.options.isReplaceOption === "n") return false;
  243. var user = layout.session.user.distinguishedName;
  244. var flag = true;
  245. if (!att.data.person && att.data.creatorUid) att.data.person = att.data.creatorUid;
  246. if (this.options.isReplaceOption === "o") {
  247. flag = att.data.person === layout.desktop.session.user.distinguishedName;
  248. }
  249. if (this.options.isReplaceOption === "a") {
  250. flag = att.data.activity === this.module.form.businessData.activity.id;
  251. }
  252. if (this.options.isReplaceOption === "ao") {
  253. flag = (att.data.person === layout.desktop.session.user.distinguishedName && att.data.activity === this.module.form.businessData.activity.id);
  254. }
  255. if (flag && !att.data.control.allowEdit && att.data.person !== user) {
  256. flag = false;
  257. }
  258. return flag;
  259. },
  260. //checkAttachmentOrderAction : function(){
  261. // if (this.options.readonly){
  262. // this.setAttachmentsAction("order", false );
  263. // return false;
  264. // }
  265. // if (this.attachments.length){
  266. // var user = layout.session.user.distinguishedName;
  267. // for (var i=0; i<this.attachments.length; i++){
  268. // var flag = true;
  269. //
  270. // var att = this.attachments[i];
  271. // if( !att.data.person && att.data.creatorUid )att.data.person = att.data.creatorUid;
  272. //
  273. // if ((!att.data.control.allowControl || !att.data.control.allowEdit) && att.data.person!==user){
  274. // flag = false;
  275. // }
  276. // if (flag){
  277. // this.setAttachmentAction(att, "order", true );
  278. // }else{
  279. // this.setAttachmentAction(att, "order", false );
  280. // }
  281. // }
  282. // }
  283. //},
  284. checkOrderAction: function () {
  285. //this.checkAttachmentOrderAction();
  286. if (this.options.readonly) {
  287. this.setActionDisabled(this.orderAction);
  288. this.setActionDisabled(this.min_orderAction);
  289. return false;
  290. }
  291. if (this.attachments.length && this.attachments.length > 1) {
  292. var flag = true;
  293. var user = layout.session.user.distinguishedName;
  294. for (var i = 0; i < this.attachments.length; i++) {
  295. var att = this.attachments[i];
  296. if (!att.data.person && att.data.creatorUid) att.data.person = att.data.creatorUid;
  297. if ((!att.data.control.allowControl && !att.data.control.allowEdit) && att.data.person !== user) { //|| !att.data.control.allowEdit
  298. flag = false;
  299. break;
  300. }
  301. }
  302. if (flag) {
  303. this.setActionEnabled(this.orderAction);
  304. this.setActionEnabled(this.min_orderAction);
  305. } else {
  306. this.setActionDisabled(this.orderAction);
  307. this.setActionDisabled(this.min_orderAction);
  308. }
  309. //this.setActionEnabled(this.min_deleteAction);
  310. } else {
  311. this.setActionDisabled(this.orderAction);
  312. this.setActionDisabled(this.min_orderAction);
  313. //this.setActionDisabled(this.min_deleteAction);
  314. }
  315. },
  316. isAttOrderAvailable: function (att) {
  317. if (this.options.readonly) return false;
  318. if (this.options.toolbarGroupHidden.contains("config")) return false;
  319. var user = layout.session.user.distinguishedName;
  320. var flag = true;
  321. if (!att.data.person && att.data.creatorUid) att.data.person = att.data.creatorUid;
  322. if ((!att.data.control.allowControl || !att.data.control.allowEdit) && att.data.person !== user) {
  323. flag = false;
  324. }
  325. return flag;
  326. },
  327. createTopNode: function () {
  328. if (this.options.title) {
  329. if (!this.titleNode) this.titleNode = new Element("div", { "styles": this.css.titleNode, "text": this.options.title }).inject(this.node);
  330. }
  331. if (!this.topNode) {
  332. this.topNode = new Element("div", { "styles": this.css.topNode }).inject(this.node);
  333. } else {
  334. this.topNode.empty();
  335. this.editActionBoxNode = null;
  336. this.editActionsGroupNode = null;
  337. this.topNode.setStyle("display", "");
  338. if (this.isHiddenTop) {
  339. //this.container.setStyle("height", this.container.getSize().y + 45 );
  340. //this.node.setStyle("height", this.node.getSize().y + 45 );
  341. if (this.oldContentScrollNodeHeight && this.contentScrollNode) {
  342. this.contentScrollNode.setStyle("min-height", this.oldContentScrollNodeHeight);
  343. this.oldContentScrollNodeHeight = null;
  344. }
  345. this.isHiddenTop = false;
  346. }
  347. }
  348. var hiddenGroup = this.options.toolbarGroupHidden;
  349. if (hiddenGroup.contains("edit") && hiddenGroup.contains("read") && hiddenGroup.contains("list") &&
  350. hiddenGroup.contains("view") && hiddenGroup.contains("config") &&
  351. !(this.module.json.isOpenInOffice && this.module.json.officeControlName)
  352. ) {
  353. if (this.contentScrollNode) {
  354. this.oldContentScrollNodeHeight = this.contentScrollNode.getStyle("min-height");
  355. this.contentScrollNode.setStyle("min-height", this.node.getStyle("min-height"));
  356. this.topNode.setStyle("display", "none");
  357. }
  358. this.isHiddenTop = true;
  359. }
  360. if (!hiddenGroup.contains("edit")) this.createEditGroupActions();
  361. if (!hiddenGroup.contains("read")) this.createReadGroupActions();
  362. if (!hiddenGroup.contains("list")) this.createListGroupActions();
  363. if (this.module.json.isOpenInOffice && this.module.json.officeControlName) this.createOfficeGroupActions();
  364. if (!hiddenGroup.contains("config")) this.createConfigGroupActions();
  365. if (!hiddenGroup.contains("view")) this.createViewGroupActions();
  366. this.checkActions();
  367. },
  368. checkActions: function () {
  369. // if (this.options.readonly){
  370. // this.setReadonly();
  371. // }else{
  372. this.checkUploadAction();
  373. this.checkDeleteAction();
  374. this.checkReplaceAction();
  375. //this.checkOfficeAction();
  376. this.checkDownloadAction();
  377. this.checkSizeAction();
  378. this.checkConfigAction();
  379. this.checkOrderAction();
  380. this.checkListStyleAction();
  381. // }
  382. },
  383. checkAttachmentConfigAction: function () {
  384. if (this.options.readonly) {
  385. this.setAttachmentsAction("config", false);
  386. return false;
  387. }
  388. if (this.attachments.length) {
  389. var user = layout.session.user.distinguishedName;
  390. for (var i = 0; i < this.attachments.length; i++) {
  391. var flag = true;
  392. var att = this.attachments[i];
  393. if (!att.data.person && att.data.creatorUid) att.data.person = att.data.creatorUid;
  394. if ((!att.data.control.allowControl) && att.data.person !== user) { // || !att.data.control.allowEdit
  395. flag = false;
  396. }
  397. if (flag) {
  398. this.setAttachmentAction(att, "config", true);
  399. } else {
  400. this.setAttachmentAction(att, "config", false);
  401. }
  402. }
  403. }
  404. },
  405. checkConfigAction: function () {
  406. this.checkAttachmentConfigAction();
  407. if (this.options.readonly) {
  408. this.setActionDisabled(this.configAction);
  409. if (this.checkTextAction) this.setActionDisabled(this.checkTextAction);
  410. return false;
  411. }
  412. if (this.selectedAttachments.length) {
  413. var flag = true;
  414. var user = layout.session.user.distinguishedName;
  415. for (var i = 0; i < this.selectedAttachments.length; i++) {
  416. var att = this.selectedAttachments[i];
  417. if (!att.data.person && att.data.creatorUid) att.data.person = att.data.creatorUid;
  418. if ((!att.data.control.allowControl) && att.data.person !== user) { //|| !att.data.control.allowEdit
  419. flag = false;
  420. break;
  421. }
  422. }
  423. if (flag) {
  424. this.setActionEnabled(this.configAction);
  425. } else {
  426. this.setActionDisabled(this.configAction);
  427. }
  428. //this.setActionEnabled(this.min_deleteAction);
  429. } else {
  430. this.setActionDisabled(this.configAction);
  431. //this.setActionDisabled(this.min_deleteAction);
  432. }
  433. if (this.checkTextAction) {
  434. this.setActionDisabled(this.checkTextAction);
  435. if (this.selectedAttachments.length && this.selectedAttachments.length === 1) {
  436. var att = this.selectedAttachments[0];
  437. if (this.options.images.indexOf(att.data.extension.toLowerCase()) !== -1) {
  438. this.setActionEnabled(this.checkTextAction);
  439. }
  440. }
  441. }
  442. },
  443. isAttConfigAvailable: function (att) {
  444. if (this.options.readonly) return false;
  445. if (this.options.toolbarGroupHidden.contains("config")) return false;
  446. var user = layout.session.user.distinguishedName;
  447. var flag = true;
  448. if (!att.data.person && att.data.creatorUid) att.data.person = att.data.creatorUid;
  449. if (!att.data.control.allowControl && att.data.person !== user) {
  450. flag = false;
  451. }
  452. return flag;
  453. },
  454. createEditGroupActions: function () {
  455. if (!this.editActionBoxNode) this.editActionBoxNode = new Element("div", { "styles": this.css.actionsBoxNode }).inject(this.topNode);
  456. if (!this.editActionsGroupNode) this.editActionsGroupNode = new Element("div", { "styles": this.css.actionsGroupNode }).inject(this.editActionBoxNode);
  457. this.uploadAction = this.createAction(this.editActionsGroupNode, "upload", o2.LP.widget.upload, function (e, node) {
  458. this.uploadAttachment(e, node);
  459. }.bind(this));
  460. this.deleteAction = this.createAction(this.editActionsGroupNode, "delete", o2.LP.widget["delete"], function (e, node) {
  461. this.deleteAttachment(e, node);
  462. }.bind(this));
  463. if (!this.options.isReplaceHidden) {
  464. this.replaceAction = this.createAction(this.editActionsGroupNode, "replace", o2.LP.widget.replace, function (e, node) {
  465. this.replaceAttachment(e, node);
  466. }.bind(this));
  467. }
  468. // this.officeAction = this.createAction(this.editActionsGroupNode, "office", o2.LP.widget.office, function(e, node){
  469. // this.openInOfficeControl(e, node);
  470. // }.bind(this));
  471. if (!this.options.toolbarGroupHidden.contains("read")) this.editActionSeparateNode = this.createSeparate(this.editActionsGroupNode);
  472. },
  473. createConfigGroupActions: function () {
  474. this.configActionBoxNode = new Element("div", { "styles": this.css.actionsBoxNode }).inject(this.topNode);
  475. this.configActionsGroupNode = new Element("div", { "styles": this.css.actionsGroupNode }).inject(this.configActionBoxNode);
  476. this.configAction = this.createAction(this.configActionsGroupNode, "config", MWF.LP.widget.configAttachment, function (e, node) {
  477. this.configAttachment(e, node);
  478. }.bind(this));
  479. if (this.options.checkTextEnable) {
  480. this.checkTextAction = this.createAction(this.configActionsGroupNode, "check", MWF.LP.widget.checkOcrText, function (e, node) {
  481. this.checkImageTex(e, node);
  482. }.bind(this));
  483. }
  484. this.createSeparate(this.configActionsGroupNode);
  485. this.orderAction = this.createAction(this.configActionsGroupNode, "order", MWF.LP.widget.order, function (e, node) {
  486. this.orderAttachment(e, node);
  487. }.bind(this));
  488. if (this.configAction) this.setActionDisabled(this.configAction);
  489. if (this.checkTextAction) this.setActionDisabled(this.checkTextAction);
  490. },
  491. createOfficeGroupActions: function () {
  492. this.officeActionBoxNode = new Element("div", { "styles": this.css.actionsBoxNode }).inject(this.topNode);
  493. this.officeActionsGroupNode = new Element("div", { "styles": this.css.actionsGroupNode }).inject(this.officeActionBoxNode);
  494. this.closeOfficeAction = this.createAction(this.officeActionsGroupNode, "closeOffice", MWF.LP.widget.closeOffice, function (e, node) {
  495. this.closeAttachmentOffice(e, node);
  496. }.bind(this));
  497. if (this.closeOfficeAction) this.setActionDisabled(this.closeOfficeAction);
  498. },
  499. loadMinActions: function () {
  500. var hiddenGroup = this.options.toolbarGroupHidden;
  501. if (!hiddenGroup.contains("edit")) {
  502. this.min_uploadAction = this.createAction(this.minActionAreaNode, "upload", MWF.LP.widget.upload, function (e, node) {
  503. this.uploadAttachment(e, node);
  504. }.bind(this));
  505. this.min_deleteAction = this.createAction(this.minActionAreaNode, "delete", MWF.LP.widget["delete"], function (e, node) {
  506. this.deleteAttachment(e, node);
  507. }.bind(this));
  508. if (!this.options.isReplaceHidden) {
  509. this.min_replaceAction = this.createAction(this.minActionAreaNode, "replace", MWF.LP.widget.replace, function (e, node) {
  510. this.replaceAttachment(e, node);
  511. }.bind(this));
  512. }
  513. }
  514. if (!hiddenGroup.contains("read")) {
  515. this.min_downloadAction = this.createAction(this.minActionAreaNode, "download", MWF.LP.widget.download
  516. , function (e, node) {
  517. this.downloadAttachment(e, node);
  518. }.bind(this));
  519. }
  520. if (!hiddenGroup.contains("config")) {
  521. this.min_orderAction = this.createAction(this.minActionAreaNode, "order", MWF.LP.widget.order, function (e, node) {
  522. this.orderAttachment(e, node);
  523. }.bind(this));
  524. }
  525. if (this.module.json.isOpenInOffice && this.module.json.officeControlName) {
  526. this.min_closeOfficeAction = this.createAction(this.minActionAreaNode, "closeOffice", MWF.LP.widget.closeOffice, function (e, node) {
  527. this.closeAttachmentOffice(e, node);
  528. }.bind(this));
  529. if (this.min_closeOfficeAction) this.setActionDisabled(this.closeOfficeAction);
  530. }
  531. if (!hiddenGroup.contains("edit") || !hiddenGroup.contains("read")) {
  532. this.createSeparate(this.minActionAreaNode);
  533. }
  534. //this.createSeparate(this.configActionsGroupNode);
  535. if (this.options.isSizeChange) {
  536. //this.createSeparate(this.minActionAreaNode);
  537. if (!hiddenGroup.contains("view")) {
  538. this.sizeAction = this.createAction(this.minActionAreaNode, "max", MWF.LP.widget.min, function () {
  539. this.changeControllerSize();
  540. }.bind(this));
  541. }
  542. }
  543. },
  544. closeAttachmentOffice: function () {
  545. var office = this.module.form.all[this.module.json.officeControlName];
  546. if (office) {
  547. office.openFile();
  548. if (this.min_closeOfficeAction) this.setActionDisabled(this.min_closeOfficeAction);
  549. if (this.closeOfficeAction) this.setActionDisabled(this.closeOfficeAction);
  550. }
  551. },
  552. configAttachment: function () {
  553. //this.fireEvent("delete", [attachment.data]);
  554. var lp = MWF.xApplication.process.Xform.LP;
  555. var css = this.module.form.css;
  556. var node = new Element("div", { "styles": css.attachmentPermissionNode }).inject(this.node);
  557. var attNames = new Element("div", { "styles": css.attachmentPermissionNamesNode }).inject(node);
  558. var attNamesTitle = new Element("div", { "styles": css.attachmentPermissionNamesTitleNode, "text": lp.attachmentPermissionInfo }).inject(attNames);
  559. var attNamesArea = new Element("div", { "styles": css.attachmentPermissionNamesAreaNode }).inject(attNames);
  560. if (this.selectedAttachments.length) {
  561. this.selectedAttachments.each(function (att) {
  562. var attNode = new Element("div", { "styles": css.attachmentPermissionAttNode, "text": att.data.name }).inject(attNamesArea);
  563. }.bind(this));
  564. }
  565. var editArea = new Element("div", { "styles": css.attachmentPermissionEditAreaNode }).inject(node);
  566. var title = new Element("div", { "styles": css.attachmentPermissionTitleNode, "text": lp.attachmentRead }).inject(editArea);
  567. var readInput = new Element("div", { "styles": css.attachmentPermissionInputNode }).inject(editArea);
  568. title = new Element("div", { "styles": css.attachmentPermissionTitleNode, "text": lp.attachmentEdit }).inject(editArea);
  569. var editInput = new Element("div", { "styles": css.attachmentPermissionInputNode }).inject(editArea);
  570. title = new Element("div", { "styles": css.attachmentPermissionTitleNode, "text": lp.attachmentController }).inject(editArea);
  571. var controllerInput = new Element("div", { "styles": css.attachmentPermissionInputNode }).inject(editArea);
  572. var dlg = o2.DL.open(Object.merge({
  573. "title": lp.attachmentPermission,
  574. "style": this.module.form.json.dialogStyle || "user",
  575. "isResize": false,
  576. "content": node,
  577. "buttonList": [
  578. {
  579. "type": "ok",
  580. "text": MWF.LP.process.button.ok,
  581. "action": function () {
  582. this.setAttachmentConfig(readInput, editInput, controllerInput);
  583. dlg.close();
  584. }.bind(this)
  585. },
  586. {
  587. "type": "cancel",
  588. "text": MWF.LP.process.button.cancel,
  589. "action": function () { dlg.close(); }
  590. }
  591. ]
  592. }, (this.module.form.json.dialogOptions||{})));
  593. if (this.selectedAttachments.length === 1) {
  594. var data = this.selectedAttachments[0].data;
  595. var readUnitList = (data.readUnitList) || [];
  596. var readIdentityList = (data.readIdentityList) || [];
  597. var editUnitList = (data.editUnitList) || [];
  598. var editIdentityList = (data.editIdentityList) || [];
  599. var controllerUnitList = (data.controllerUnitList) || [];
  600. var controllerIdentityList = (data.controllerIdentityList) || [];
  601. readInput.setSelectPerson(this.module.form.app.content, Object.merge(Object.clone(this.module.form.json.selectorStyle || {}), {
  602. "types": ["unit", "identity"],
  603. "values": readUnitList.concat(readIdentityList).trim()
  604. }));
  605. editInput.setSelectPerson(this.module.form.app.content, Object.merge(Object.clone(this.module.form.json.selectorStyle || {}), {
  606. "types": ["unit", "identity"],
  607. "values": editUnitList.concat(editIdentityList).trim()
  608. }));
  609. controllerInput.setSelectPerson(this.module.form.app.content, Object.merge(Object.clone(this.module.form.json.selectorStyle || {}), {
  610. "types": ["unit", "identity"],
  611. "values": controllerUnitList.concat(controllerIdentityList).trim()
  612. }));
  613. } else {
  614. readInput.setSelectPerson(this.module.form.app.content, Object.merge(Object.clone(this.module.form.json.selectorStyle || {}), {
  615. "types": ["unit", "identity"]
  616. }));
  617. editInput.setSelectPerson(this.module.form.app.content, Object.merge(Object.clone(this.module.form.json.selectorStyle || {}), {
  618. "types": ["unit", "identity"]
  619. }));
  620. controllerInput.setSelectPerson(this.module.form.app.content, Object.merge(Object.clone(this.module.form.json.selectorStyle || {}), {
  621. "types": ["unit", "identity"]
  622. }));
  623. }
  624. },
  625. setAttachmentConfig: function (readInput, editInput, controllerInput) {
  626. if (this.selectedAttachments.length) {
  627. var readList = readInput.retrieve("data-value");
  628. var editList = editInput.retrieve("data-value");
  629. var controllerList = controllerInput.retrieve("data-value");
  630. var readUnitList = [];
  631. var readIdentityList = [];
  632. var editUnitList = [];
  633. var editIdentityList = [];
  634. var controllerUnitList = [];
  635. var controllerIdentityList = [];
  636. if (readList) {
  637. readList.each(function (v) {
  638. var vName = (typeOf(v) === "string") ? v : v.distinguishedName;
  639. var len = vName.length;
  640. var flag = vName.substring(len - 1, len);
  641. if (flag === "U") readUnitList.push(vName);
  642. if (flag === "I") readIdentityList.push(vName);
  643. });
  644. }
  645. if (editList) {
  646. editList.each(function (v) {
  647. var vName = (typeOf(v) === "string") ? v : v.distinguishedName;
  648. var len = vName.length;
  649. var flag = vName.substring(len - 1, len);
  650. if (flag === "U") editUnitList.push(vName);
  651. if (flag === "I") editIdentityList.push(vName);
  652. });
  653. }
  654. if (controllerList) {
  655. controllerList.each(function (v) {
  656. var vName = (typeOf(v) === "string") ? v : v.distinguishedName;
  657. var len = vName.length;
  658. var flag = vName.substring(len - 1, len);
  659. if (flag === "U") controllerUnitList.push(vName);
  660. if (flag === "I") controllerIdentityList.push(vName);
  661. });
  662. }
  663. var loadedCount = 0;
  664. this.selectedAttachments.each(function (att) {
  665. att.data.readUnitList = readUnitList;
  666. att.data.readIdentityList = readIdentityList;
  667. att.data.editUnitList = editUnitList;
  668. att.data.editIdentityList = editIdentityList;
  669. att.data.controllerUnitList = controllerUnitList;
  670. att.data.controllerIdentityList = controllerIdentityList;
  671. o2.Actions.get("x_processplatform_assemble_surface").configAttachment(att.data.id, this.module.form.businessData.work.id, att.data, function () {
  672. //刷新附件权限,以后要加一个刷新附件的功能
  673. o2.Actions.load("x_processplatform_assemble_surface").AttachmentAction.getWithWorkOrWorkCompleted(att.data.id, this.module.form.businessData.work.id, function (json) {
  674. var attachment = this.getAttachmentById( att.data.id );
  675. if( attachment ){
  676. attachment.data = json.data;
  677. if( attachment.deleteAction && !this.isAttDeleteAvailable(attachment) ){
  678. attachment.deleteAction.setStyle("display","none");
  679. }
  680. if( attachment.configAction && !this.isAttConfigAvailable(attachment) ){
  681. attachment.configAction.setStyle("display","none");
  682. }
  683. }
  684. loadedCount++;
  685. if( loadedCount === this.selectedAttachments.length ){
  686. this.checkActions();
  687. }
  688. }.bind(this))
  689. }.bind(this));
  690. }.bind(this));
  691. }
  692. },
  693. checkImageTex: function () {
  694. if (this.selectedAttachments.length && this.selectedAttachments.length == 1) {
  695. var att = this.selectedAttachments[0];
  696. var lp = MWF.xApplication.process.Xform.LP;
  697. var css = this.module.form.css;
  698. var node = new Element("div", { "styles": css.attachmentOCRNode }).inject(this.node);
  699. var previewNode = new Element("div", { "styles": css.attachmentOCRImageAreaNode }).inject(node);
  700. var imgNode = new Element("img", { "styles": css.attachmentOCRImageNode }).inject(previewNode);
  701. o2.Actions.get("x_processplatform_assemble_surface").getAttachmentUrl(att.data.id, this.module.form.businessData.work.id, function (url) {
  702. imgNode.set("src", o2.filterUrl(url));
  703. });
  704. var areaNode = new Element("div", { "styles": css.attachmentOCRInputAreaNode }).inject(node);
  705. var inputNode = new Element("textarea", { "styles": css.attachmentOCRInputNode }).inject(areaNode);
  706. var dlg = o2.DL.open({
  707. "title": lp.attachmentOCRTitle,
  708. "style": this.module.form.json.dialogStyle || "user",
  709. "isResize": false,
  710. "content": node,
  711. "buttonList": [
  712. {
  713. "type": "ok",
  714. "text": MWF.LP.process.button.ok,
  715. "action": function () {
  716. this.setAttachmentOCR(inputNode, att);
  717. dlg.close();
  718. }.bind(this)
  719. },
  720. {
  721. "type": "cancel",
  722. "text": MWF.LP.process.button.cancel,
  723. "action": function () { dlg.close(); }
  724. }
  725. ]
  726. });
  727. if (att.data.ocr) {
  728. inputNode.set("text", att.data.ocr.text || "");
  729. } else {
  730. o2.Actions.get("x_processplatform_assemble_surface").getAttachmentOCR(att.data.id, this.module.form.businessData.work.id, function (json) {
  731. att.data.ocr = json.data;
  732. inputNode.set("text", json.data.text || "");
  733. }.bind(this))
  734. }
  735. }
  736. },
  737. setAttachmentOCR: function (inputNode, att) {
  738. var data = inputNode.get("text");
  739. if (!att.data.ocr) att.data.ocr = {};
  740. att.data.ocr.text = data;
  741. o2.Actions.get("x_processplatform_assemble_surface").setAttachmentOCR(att.data.id, this.module.form.businessData.work.id, {
  742. "text": data
  743. }, function () {
  744. this.module.form.app.notice("success", lp.attachmentOCR_saved, this.node);
  745. }.bind(this));
  746. },
  747. checkMoveAction: function (item) {
  748. if (item) {
  749. var actionArea = item.getFirst().getNext();
  750. var actionup = actionArea.getFirst().show();
  751. var actiondown = actionArea.getLast().show();
  752. tmp = item.getPrevious();
  753. if (!tmp) actionup.hide();
  754. tmp = item.getNext();
  755. if (!tmp) actiondown.hide();
  756. }
  757. },
  758. orderAttachment: function () {
  759. if (this.attachments.length) {
  760. this.attachments = this.attachments.sort(function (a1, a2) {
  761. if (!a2.data.orderNumber) return 1;
  762. if (!a1.data.orderNumber) return -1;
  763. return a1.data.orderNumber - a2.data.orderNumber;
  764. }.bind(this));
  765. var lp = MWF.xApplication.process.Xform.LP;
  766. var css = this.module.form.css;
  767. var node = new Element("div", { "styles": css.attachmentOrderNode });
  768. var infoNode = new Element("div", { "styles": css.attachmentOrderInforNode, "text": lp.attachmentOrderInfo }).inject(node);
  769. var attrchmentsNode = new Element("div", { "styles": css.attachmentOrderAreaNode }).inject(node);
  770. var iconUrl = "../x_component_File/$Main/icon.json";
  771. var icons = null;
  772. o2.getJSON(iconUrl, function (json) {
  773. icons = json;
  774. }.bind(this), false, false);
  775. this.attachments.each(function (att, idx) {
  776. var iconName = icons[att.data.extension.toLowerCase()] || icons.unknow;
  777. var iconFolderUrl = "../x_component_File/$Main/default/file/" + iconName;
  778. var itemNode = new Element("div", { "styles": css.attachmentOrderItemNode }).inject(attrchmentsNode);
  779. itemNode.store("att", att);
  780. var icon = new Element("div", { "styles": css.attachmentOrderItemIconNode }).inject(itemNode);
  781. icon.setStyle("background-image", "url('" + iconFolderUrl + "')");
  782. var actionArea = new Element("div", { "styles": css.attachmentOrderItemActionNode }).inject(itemNode);
  783. var text = new Element("div", { "styles": css.attachmentOrderItemTextNode, "text": att.data.name }).inject(itemNode);
  784. var actionUp = new Element("div", { "styles": css.attachmentOrderItemActionUpNode, "text": lp.attachmentOrderUp }).inject(actionArea);
  785. var actionDown = new Element("div", { "styles": css.attachmentOrderItemActionDownNode, "text": lp.attachmentOrderDown }).inject(actionArea);
  786. if (idx == 0) actionUp.hide();
  787. if (idx == this.attachments.length - 1) actionDown.hide();
  788. actionUp.addEvent("click", function (e) {
  789. var itemNode = e.target.getParent().getParent();
  790. var upNode = itemNode.getPrevious();
  791. if (upNode) {
  792. itemNode.inject(upNode, "before");
  793. this.checkMoveAction(upNode);
  794. }
  795. this.checkMoveAction(itemNode);
  796. itemNode.highlight();
  797. //itemNode.setStyle("background-color", "#faf9f1");
  798. }.bind(this));
  799. actionDown.addEvent("click", function (e) {
  800. var itemNode = e.target.getParent().getParent();
  801. var downNode = itemNode.getNext();
  802. if (downNode) {
  803. itemNode.inject(downNode, "after");
  804. this.checkMoveAction(downNode);
  805. }
  806. this.checkMoveAction(itemNode);
  807. itemNode.highlight();
  808. // /itemNode.setStyle("background-color", "#faf9f1");
  809. }.bind(this));
  810. itemNode.addEvents({
  811. "mouseover": function (e) { this.setStyle("background-color", "#f1f6fa"); },
  812. "mouseout": function (e) { this.setStyle("background-color", "#ffffff"); }
  813. });
  814. //var droppables = attrchmentsNode.getChildren();
  815. new Drag(itemNode, {
  816. "handle": icon,
  817. "snap": 5,
  818. "stopPropagation": true,
  819. "preventDefault": true,
  820. onStart: function (el, e) {
  821. var itemNode = el;
  822. itemNode.setStyle("background-color", "#f1f6fa");
  823. var moveNode = itemNode.clone(true).setStyles(css.attachmentOrderItemNode).setStyles({
  824. "background-color": "#faf9f1",
  825. "opacity": 0.8,
  826. "border": "1px dotted #333333"
  827. }).inject(node);
  828. moveNode.position({
  829. "relativeTo": itemNode,
  830. "position": 'upperLeft',
  831. "edge": 'upperLeft'
  832. });
  833. moveNode.owner = itemNode;
  834. var move = new Drag.Move(moveNode, {
  835. "container": node,
  836. "droppables": attrchmentsNode.getChildren(),
  837. "onEnter": function (el, drop) {
  838. moveNode.flagNode = new Element("div", { "styles": css.attachmentOrderFlagNode }).inject(drop, "before");
  839. },
  840. "onLeave": function (el, drop) {
  841. if (moveNode.flagNode) moveNode.flagNode.destroy();
  842. },
  843. "onDrop": function (el, drop) {
  844. if (moveNode.flagNode) {
  845. moveNode.owner.inject(moveNode.flagNode, "after");
  846. moveNode.flagNode.destroy();
  847. moveNode.owner.highlight();
  848. this.checkMoveAction(moveNode.owner);
  849. this.checkMoveAction(drop);
  850. this.checkMoveAction(attrchmentsNode.getLast());
  851. moveNode.destroy()
  852. }
  853. }.bind(this)
  854. });
  855. move.start(e);
  856. }.bind(this),
  857. enter: function (el) {
  858. el.removeClass('dragging');
  859. }
  860. });
  861. //itemNode.dragMove
  862. }.bind(this));
  863. var dlg = o2.DL.open(Object.merge({
  864. "title": lp.attachmentOrderTitle,
  865. "style": this.module.form.json.dialogStyle || "user",
  866. "isResize": false,
  867. "content": node,
  868. "width": "auto",
  869. "height": "auto",
  870. "buttonList": [
  871. {
  872. "type": "ok",
  873. "text": MWF.LP.process.button.ok,
  874. "action": function () {
  875. this.sortAttachment(attrchmentsNode);
  876. dlg.close();
  877. }.bind(this)
  878. },
  879. {
  880. "type": "cancel",
  881. "text": MWF.LP.process.button.cancel,
  882. "action": function () { dlg.close(); }
  883. }
  884. ],
  885. "onPostLoad": function () {
  886. var dlg = this;
  887. dlg.node.setStyle("display", "block");
  888. var size = {};
  889. if (css.attachmentOrderNode) {
  890. if (parseFloat(css.attachmentOrderNode.width).toString() !== "NaN") {
  891. size.x = parseInt(css.attachmentOrderNode.width)
  892. }
  893. if (parseFloat(css.attachmentOrderNode.height).toString() !== "NaN") {
  894. size.y = parseInt(css.attachmentOrderNode.height)
  895. }
  896. }
  897. node.show();
  898. var nodeSize = node.getSize();
  899. dlg.content.setStyles({
  900. "width": size.x || nodeSize.x,
  901. "height": size.y || nodeSize.y
  902. });
  903. dlg.setContentSize();
  904. }
  905. }, (this.module.form.json.dialogOptions||{})));
  906. }
  907. },
  908. sortAttachment: function (node) {
  909. var nodes = node.getChildren();
  910. nodes.each(function (item, idx) {
  911. var att = item.retrieve("att", null);
  912. if (att) {
  913. att.data.orderNumber = idx;
  914. o2.Actions.load("x_processplatform_assemble_surface").AttachmentAction.changeOrderNumber(att.data.id, this.module.form.businessData.work.id, idx);
  915. }
  916. }.bind(this));
  917. this.attachments = this.attachments.sort(function (a1, a2) {
  918. if (!a2.data.orderNumber) return 1;
  919. if (!a1.data.orderNumber) return -1;
  920. return a1.data.orderNumber - a2.data.orderNumber;
  921. }.bind(this));
  922. this.reloadAttachments();
  923. this.fireEvent("order");
  924. }
  925. });
  926. /**
  927. * 流程实例的附件数据结构.
  928. * @typedef {Object} WorkAttachmentData
  929. * @property {String} id - 附件id.
  930. * @property {String} name - 附件标题.
  931. * @property {String} person - 上传人.
  932. * @property {Number} orderNumber - 排序号.
  933. * @property {String} activityName - 上传的节点.
  934. * @property {Object} control - 当前登录人员对附件拥有的权限.
  935. * @property {Boolean} control.allowRead - 是否允许阅读.
  936. * @property {Boolean} control.allowEdit - 是否允许编辑.
  937. * @property {Boolean} control.allowControl - 是否允许设置.
  938. * @property {Number} length - 附件大小.
  939. * @property {String} createTime - 创建时间.
  940. * @property {String} updateTime - 修改时间.
  941. * @property {String} extension - 附件扩展名.
  942. * @example
  943. * {
  944. "id": "56c4e86f-a4c8-4cc2-a150-1a0d2c5febcb", //附件ID
  945. "name": "133203a2-92e6-4653-9954-161b72ddb7f9.png", //附件名称
  946. "extension": "png", //附件扩展名
  947. "length": 43864, //附件大小
  948. "person": "xx@huqi@P", //附件上传人
  949. "lastUpdateTime": "2018-09-27 15:50:34", //最后的修改时间
  950. "lastUpdatePerson": "xx@huqi@P", //最后的修改人
  951. "activity": "e31ad938-c495-45a6-8d77-b8a9b61a165b", //附件上传的活动ID
  952. "activityName": "申请人", //附件上传的活动名称
  953. "activityType": "manual", //附件上传的活动类型
  954. "site": "$mediaOpinion", //附件存储位置(一般用于区分附件在哪个表单元素中显示)
  955. "type": "image/png" //附件类型(contentType)
  956. }
  957. */
  958. /** @class Attachment 附件组件。
  959. * @example
  960. * //可以在脚本中获取该组件
  961. * //方法1:
  962. * var attachment = this.form.get("name"); //获取组件
  963. * //方法2
  964. * var attachment = this.target; //在组件事件脚本中获取
  965. * @extends MWF.xApplication.process.Xform.$Module
  966. * @category FormComponents
  967. * @hideconstructor
  968. */
  969. MWF.xApplication.process.Xform.Attachment = MWF.APPAttachment = new Class(
  970. /** @lends MWF.xApplication.process.Xform.Attachment# */
  971. {
  972. Extends: MWF.APP$Module,
  973. options: {
  974. /**
  975. * @event MWF.xApplication.process.Xform.Attachment#queryLoad
  976. * @ignore
  977. */
  978. /**
  979. * @event MWF.xApplication.process.Xform.Attachment#postLoad
  980. * @ignore
  981. */
  982. /**
  983. * 附件上传后触发。本事件中可以通过this.event获取上传附件的数据
  984. * @event MWF.xApplication.process.Xform.Attachment#upload
  985. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  986. */
  987. /**
  988. * 删除附件前触发。本事件中可以通过this.event获取被删附件的数据
  989. * @event MWF.xApplication.process.Xform.Attachment#delete
  990. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  991. */
  992. /**
  993. * 删除附件后触发。本事件中可以通过this.event获取被删附件的数据
  994. * @event MWF.xApplication.process.Xform.Attachment#afterDelete
  995. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  996. */
  997. /**
  998. * 附件容器加载时触发。
  999. * @event MWF.xApplication.process.Xform.Attachment#load
  1000. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  1001. */
  1002. /**
  1003. * 附件有变化的时候会被触发,包括上传、删除、排序
  1004. * @event MWF.xApplication.process.Xform.Attachment#change
  1005. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  1006. */
  1007. /**
  1008. * 下载附件后触发。本事件中可以通过this.event获取被下载附件对象
  1009. * @event MWF.xApplication.process.Xform.Attachment#download
  1010. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  1011. */
  1012. /**
  1013. * 打开附件后触发。本事件中可以通过this.event获取被打开附件对象
  1014. * @event MWF.xApplication.process.Xform.Attachment#open
  1015. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  1016. */
  1017. "moduleEvents": ["upload", "delete", "afterDelete", "load", "change","download","open"]
  1018. },
  1019. initialize: function (node, json, form, options) {
  1020. this.node = $(node);
  1021. this.node.store("module", this);
  1022. this.json = json;
  1023. this.form = form;
  1024. this.field = true;
  1025. },
  1026. _loadUserInterface: function () {
  1027. this.node.empty();
  1028. if (this.form.businessData.work.startTime){
  1029. this.loadAttachmentController();
  1030. this.fireEvent("load");
  1031. }
  1032. },
  1033. reload: function(){
  1034. this.node.empty();
  1035. if (this.form.businessData.work.startTime){
  1036. this.loadAttachmentController();
  1037. }
  1038. },
  1039. loadAttachmentController: function () {
  1040. //MWF.require("MWF.widget.AttachmentController", function() {
  1041. var options = {
  1042. "style": this.json.style || "default",
  1043. "title": "附件区域",
  1044. "listStyle": this.json.listStyle || "icon",
  1045. "size": this.json.size || "max",
  1046. "resize": (this.json.resize === "y" || this.json.resize === "true"),
  1047. "attachmentCount": this.json.attachmentCount || 0,
  1048. "isUpload": (this.json.isUpload === "y" || this.json.isUpload === "true"),
  1049. "isDelete": (this.json.isDelete === "y" || this.json.isDelete === "true"),
  1050. "isReplace": (this.json.isReplace === "y" || this.json.isReplace === "true"),
  1051. "isDownload": (this.json.isDownload === "y" || this.json.isDownload === "true"),
  1052. "isSizeChange": (this.json.isSizeChange === "y" || this.json.isSizeChange === "true"),
  1053. "readonly": (this.json.readonly === "y" || this.json.readonly === "true"),
  1054. "availableListStyles": this.json.availableListStyles ? this.json.availableListStyles : ["list", "seq", "icon", "preview"],
  1055. "isDeleteOption": this.json.isDelete,
  1056. "isReplaceOption": this.json.isReplace,
  1057. "toolbarGroupHidden": this.json.toolbarGroupHidden || [],
  1058. "onOrder": function () {
  1059. this.fireEvent("change");
  1060. }.bind(this)
  1061. };
  1062. if (this.readonly) options.readonly = true;
  1063. if (this.form.json.attachmentStyle) {
  1064. options = Object.merge(options, this.form.json.attachmentStyle);
  1065. }
  1066. //this.attachmentController = new MWF.widget.ATTER(this.node, this, options);
  1067. /**
  1068. * @summary 附件容器.
  1069. * @member {MWF.xApplication.process.Xform.AttachmentController}
  1070. * @example
  1071. * var attachmentController = this.form.get("fieldId").AttachmentController; //获取附件容器
  1072. * var attachmentList = attachmentController.attachments; //获取所有的附件
  1073. * var attachmentData = attachment[0].data; //获取第一个附件的数据
  1074. */
  1075. this.attachmentController = new MWF.xApplication.process.Xform.AttachmentController(this.node, this, options);
  1076. this.attachmentController.load();
  1077. this.form.businessData.attachmentList.each(function (att) {
  1078. //if (att.site===this.json.id || (this.json.isOpenInOffice && this.json.officeControlName===att.site)) this.attachmentController.addAttachment(att);
  1079. if (att.site === (this.json.site || this.json.id)) this.attachmentController.addAttachment(att);
  1080. }.bind(this));
  1081. this.setAttachmentBusinessData();
  1082. //}.bind(this));
  1083. },
  1084. setAttachmentBusinessData: function () {
  1085. if (this.attachmentController) {
  1086. if (this.attachmentController.attachments.length) {
  1087. var values = this.attachmentController.attachments.map(function (d) {
  1088. return d.data.name;
  1089. });
  1090. this._setBusinessData(values);
  1091. } else {
  1092. this._setBusinessData([]);
  1093. }
  1094. }
  1095. },
  1096. _loadEvents: function (editorConfig) {
  1097. Object.each(this.json.events, function (e, key) {
  1098. if (e.code) {
  1099. if (this.options.moduleEvents.indexOf(key) !== -1) {
  1100. this.addEvent(key, function (event) {
  1101. return this.form.Macro.fire(e.code, this, event);
  1102. }.bind(this));
  1103. } else {
  1104. this.node.addEvent(key, function (event) {
  1105. return this.form.Macro.fire(e.code, this, event);
  1106. }.bind(this));
  1107. }
  1108. }
  1109. }.bind(this));
  1110. },
  1111. isEmpty : function(){
  1112. var data = this.getData();
  1113. if( typeOf(data) === "array" ){
  1114. return data.length == 0
  1115. }else{
  1116. return !data;
  1117. }
  1118. },
  1119. /**
  1120. * @summary 获取当前组件所有附件的标题.如果没有附件返回null
  1121. * @example
  1122. * var getAttachmentNames = this.form.get("name").getData();
  1123. * @return {StringArray|Null} 附件标题.
  1124. */
  1125. getData: function () {
  1126. return (this.attachmentController) ? this.attachmentController.getAttachmentNames() : null;
  1127. },
  1128. createUploadFileNode: function () {
  1129. var accept = "*";
  1130. if (!this.json.attachmentExtType || (this.json.attachmentExtType.indexOf("other") != -1 && !this.json.attachmentExtOtherType)) {
  1131. } else {
  1132. accepts = [];
  1133. var otherType = this.json.attachmentExtOtherType;
  1134. this.json.attachmentExtType.each(function (v) {
  1135. switch (v) {
  1136. case "word":
  1137. accepts.push(".doc, .docx, .dot, .dotx");
  1138. break;
  1139. case "excel":
  1140. accepts.push(".xls, .xlsx, .xlsm, .xlt, .xltx");
  1141. break;
  1142. case "ppt":
  1143. accepts.push(".pptx, .ppt, .pot, .potx, .potm");
  1144. break;
  1145. case "txt":
  1146. accepts.push(".txt");
  1147. break;
  1148. case "pic":
  1149. accepts.push(".bmp, .gif, .psd, .jpeg, .jpg, .png");
  1150. break;
  1151. case "pdf":
  1152. accepts.push(".pdf");
  1153. break;
  1154. case "zip":
  1155. accepts.push(".zip, .rar");
  1156. break;
  1157. case "audio":
  1158. accepts.push(".mp3, .wav, .wma, .wmv, .flac, .ape");
  1159. break;
  1160. case "video":
  1161. accepts.push(".avi, .mkv, .mov, .ogg, .mp4, .mpeg");
  1162. break;
  1163. case "other":
  1164. if (this.json.attachmentExtOtherType) accepts.push(this.json.attachmentExtOtherType);
  1165. break;
  1166. }
  1167. }.bind(this));
  1168. accept = accepts.join(", ");
  1169. }
  1170. var size = 0;
  1171. if (this.json.attachmentSize) size = this.json.attachmentSize.toFloat();
  1172. this.attachmentController.doUploadAttachment({ "site": (this.json.site || this.json.id) }, this.form.workAction.action, "uploadAttachment", { "id": this.form.businessData.work.id }, null, function (o) {
  1173. if (o.id) {
  1174. this.form.workAction.getAttachment(o.id, this.form.businessData.work.id, function (json) {
  1175. if (json.data) {
  1176. if (!json.data.control) json.data.control = {};
  1177. this.attachmentController.addAttachment(json.data, o.messageId);
  1178. }
  1179. this.attachmentController.checkActions();
  1180. this.setAttachmentBusinessData();
  1181. this.fireEvent("upload", [json.data]);
  1182. this.fireEvent("change");
  1183. }.bind(this))
  1184. }
  1185. this.attachmentController.checkActions();
  1186. }.bind(this), function (files) {
  1187. if (files.length) {
  1188. if ((files.length + this.attachmentController.attachments.length > this.attachmentController.options.attachmentCount) && this.attachmentController.options.attachmentCount > 0) {
  1189. var content = MWF.xApplication.process.Xform.LP.uploadMore;
  1190. content = content.replace("{n}", this.attachmentController.options.attachmentCount);
  1191. this.form.notice(content, "error");
  1192. return false;
  1193. }
  1194. }
  1195. return true;
  1196. }.bind(this), true, accept, size, function (o) { //错误的回调
  1197. if (o.messageId && this.attachmentController.messageItemList) {
  1198. var message = this.attachmentController.messageItemList[o.messageId];
  1199. if( message && message.node )message.node.destroy();
  1200. }
  1201. }.bind(this));
  1202. // this.uploadFileAreaNode = new Element("div");
  1203. // var html = "<input name=\"file\" type=\"file\" multiple/>";
  1204. // this.uploadFileAreaNode.set("html", html);
  1205. //
  1206. // this.fileUploadNode = this.uploadFileAreaNode.getFirst();
  1207. // this.fileUploadNode.addEvent("change", function(){
  1208. //
  1209. // var files = this.fileUploadNode.files;
  1210. // if (files.length){
  1211. // if ((files.length+this.attachmentController.attachments.length > this.attachmentController.options.attachmentCount) && this.attachmentController.options.attachmentCount>0){
  1212. // var content = MWF.xApplication.process.Xform.LP.uploadMore;
  1213. // content = content.replace("{n}", this.attachmentController.options.attachmentCount);
  1214. // this.form.notice(content, "error");
  1215. // }else{
  1216. // for (var i = 0; i < files.length; i++) {
  1217. // var file = files.item(i);
  1218. //
  1219. // var formData = new FormData();
  1220. // formData.append('site', this.json.id);
  1221. // formData.append('file', file);
  1222. //
  1223. // //formData.append('folder', folderId);
  1224. //
  1225. // this.form.workAction.uploadAttachment(this.form.businessData.work.id ,function(o, text){
  1226. // if (o.id){
  1227. // this.form.workAction.getAttachment(o.id, this.form.businessData.work.id, function(json){
  1228. // if (json.data) this.attachmentController.addAttachment(json.data);
  1229. // this.attachmentController.checkActions();
  1230. //
  1231. // this.fireEvent("upload", [json.data]);
  1232. // }.bind(this))
  1233. // }
  1234. // this.attachmentController.checkActions();
  1235. // }.bind(this), null, formData, file);
  1236. // }
  1237. // }
  1238. // }
  1239. // }.bind(this));
  1240. },
  1241. uploadAttachment: function (e, node) {
  1242. if (window.o2android && window.o2android.uploadAttachment) {
  1243. window.o2android.uploadAttachment((this.json.site || this.json.id));
  1244. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.uploadAttachment) {
  1245. window.webkit.messageHandlers.uploadAttachment.postMessage({ "site": (this.json.site || this.json.id) });
  1246. } else {
  1247. // if (!this.uploadFileAreaNode){
  1248. this.createUploadFileNode();
  1249. // }
  1250. // this.fileUploadNode.click();
  1251. }
  1252. },
  1253. deleteAttachments: function (e, node, attachments) {
  1254. var names = [];
  1255. attachments.each(function (attachment) {
  1256. names.push(attachment.data.name);
  1257. }.bind(this));
  1258. // if ((window.o2 && window.o2.replaceAttachment) || (window.webkit && window.webkit.messageHandlers)){
  1259. // if (window.confirm(MWF.xApplication.process.Xform.LP.deleteAttachment+"( "+names.join(", ")+" )")){
  1260. // while (attachments.length){
  1261. // attachment = attachments.shift();
  1262. // this.deleteAttachment(attachment);
  1263. // }
  1264. // }
  1265. // }else {
  1266. // var tmpNode = new Element("div", {
  1267. // "styles": {
  1268. // "background-color": "#0000ff",
  1269. // "border-style": "solid",
  1270. // "border-color": "#fff",
  1271. // "border-width": "1",
  1272. // "box-shadow": "0px 0px 20px #999",
  1273. // "z-index": "20000",
  1274. // "overflow": "hidden",
  1275. // "font-size": "14px",
  1276. // "height": "160px",
  1277. // "padding": "0px",
  1278. // "width": "300px",
  1279. // "position": "absolute",
  1280. // "top": "50px",
  1281. // "left": "20px",
  1282. // "opacity": 1,
  1283. // "border-radius": "5px"
  1284. // }
  1285. // }).inject(this.form.app.content);
  1286. var _self = this;
  1287. this.form.confirm("warn", e, MWF.xApplication.process.Xform.LP.deleteAttachmentTitle, MWF.xApplication.process.Xform.LP.deleteAttachment + "( " + names.join(", ") + " )", 300, 120, function () {
  1288. while (attachments.length) {
  1289. var attachment = attachments.shift();
  1290. _self.deleteAttachment(attachment);
  1291. }
  1292. this.close();
  1293. }, function () {
  1294. this.close();
  1295. }, null, null, this.form.json.confirmStyle);
  1296. },
  1297. deleteAttachment: function (attachment) {
  1298. this.fireEvent("delete", [attachment.data]);
  1299. var id = attachment.data.id;
  1300. this.form.workAction.deleteAttachment(attachment.data.id, this.form.businessData.work.id, function (josn) {
  1301. this.attachmentController.removeAttachment(attachment);
  1302. this.attachmentController.checkActions();
  1303. if (this.form.officeList) {
  1304. this.form.officeList.each(function (office) {
  1305. if (office.openedAttachment) {
  1306. if (office.openedAttachment.id == id) {
  1307. office.loadOfficeEdit();
  1308. }
  1309. }
  1310. }.bind(this));
  1311. }
  1312. this.setAttachmentBusinessData();
  1313. this.fireEvent("afterDelete", [attachment.data]);
  1314. this.fireEvent("change");
  1315. }.bind(this));
  1316. },
  1317. replaceAttachment: function (e, node, attachment) {
  1318. if (window.o2android && window.o2android.replaceAttachment) {
  1319. window.o2android.replaceAttachment(attachment.data.id, (this.json.site || this.json.id));
  1320. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.replaceAttachment) {
  1321. window.webkit.messageHandlers.replaceAttachment.postMessage({ "id": attachment.data.id, "site": (this.json.site || this.json.id) });
  1322. } else {
  1323. var _self = this;
  1324. this.form.confirm("warn", e, MWF.xApplication.process.Xform.LP.replaceAttachmentTitle, MWF.xApplication.process.Xform.LP.replaceAttachment + "( " + attachment.data.name + " )", 350, 120, function () {
  1325. _self.replaceAttachmentFile(attachment);
  1326. this.close();
  1327. }, function () {
  1328. this.close();
  1329. }, null, null, this.form.json.confirmStyle);
  1330. }
  1331. },
  1332. createReplaceFileNode: function (attachment) {
  1333. var accept = "*";
  1334. if (!this.json.attachmentExtType || this.json.attachmentExtType.indexOf("other") != -1 && !this.json.attachmentExtOtherType) {
  1335. } else {
  1336. accepts = [];
  1337. var otherType = this.json.attachmentExtOtherType;
  1338. this.json.attachmentExtType.each(function (v) {
  1339. switch (v) {
  1340. case "word":
  1341. accepts.push(".doc, .docx, .dot, .dotx");
  1342. break;
  1343. case "excel":
  1344. accepts.push(".xls, .xlsx, .xlsm, .xlt, .xltx");
  1345. break;
  1346. case "ppt":
  1347. accepts.push(".pptx, .ppt, .pot, .potx, .potm");
  1348. break;
  1349. case "txt":
  1350. accepts.push(".txt");
  1351. break;
  1352. case "pic":
  1353. accepts.push(".bmp, .gif, .psd, .jpeg, .jpg");
  1354. break;
  1355. case "pdf":
  1356. accepts.push(".pdf");
  1357. break;
  1358. case "zip":
  1359. accepts.push(".zip, .rar");
  1360. break;
  1361. case "audio":
  1362. accepts.push(".mp3, .wav, .wma, .wmv, .flac, .ape");
  1363. break;
  1364. case "video":
  1365. accepts.push(".avi, .mkv, .mov, .ogg, .mp4, .mpeg");
  1366. break;
  1367. case "other":
  1368. if (this.json.attachmentExtOtherType) accepts.push(this.json.attachmentExtOtherType);
  1369. break;
  1370. }
  1371. });
  1372. accept = accepts.join(", ");
  1373. }
  1374. var size = 0;
  1375. if (this.json.attachmentSize) size = this.json.attachmentSize.toFloat();
  1376. this.attachmentController.doUploadAttachment({ "site": (this.json.site || this.json.id) }, this.form.workAction.action, "replaceAttachment",
  1377. { "id": attachment.data.id, "workid": this.form.businessData.work.id }, null, function (o) {
  1378. this.form.workAction.getAttachment(attachment.data.id, this.form.businessData.work.id, function (json) {
  1379. attachment.data = json.data;
  1380. attachment.reload();
  1381. if (o.messageId && this.attachmentController.messageItemList) {
  1382. var message = this.attachmentController.messageItemList[o.messageId];
  1383. if( message && message.node )message.node.destroy();
  1384. }
  1385. this.attachmentController.checkActions();
  1386. }.bind(this))
  1387. }.bind(this), null, true, accept, size, function (o) { //错误的回调
  1388. if (o.messageId && this.attachmentController.messageItemList) {
  1389. var message = this.attachmentController.messageItemList[o.messageId];
  1390. if( message && message.node )message.node.destroy();
  1391. }
  1392. }.bind(this));
  1393. // this.replaceFileAreaNode = new Element("div");
  1394. // var html = "<input name=\"file\" type=\"file\" multiple/>";
  1395. // this.replaceFileAreaNode.set("html", html);
  1396. //
  1397. // this.fileReplaceNode = this.replaceFileAreaNode.getFirst();
  1398. // this.fileReplaceNode.addEvent("change", function(){
  1399. //
  1400. // var files = this.fileReplaceNode.files;
  1401. // if (files.length){
  1402. // for (var i = 0; i < files.length; i++) {
  1403. // var file = files.item(i);
  1404. //
  1405. // var formData = new FormData();
  1406. // formData.append('file', file);
  1407. // // formData.append('site', this.json.id);
  1408. //
  1409. // this.form.workAction.replaceAttachment(attachment.data.id, this.form.businessData.work.id ,function(o, text){
  1410. // this.form.workAction.getAttachment(attachment.data.id, this.form.businessData.work.id, function(json){
  1411. // attachment.data = json.data;
  1412. // attachment.reload();
  1413. // this.attachmentController.checkActions();
  1414. // }.bind(this))
  1415. // }.bind(this), null, formData, file);
  1416. // }
  1417. // }
  1418. // }.bind(this));
  1419. },
  1420. replaceAttachmentFile: function (attachment) {
  1421. //if (!this.replaceFileAreaNode){
  1422. this.createReplaceFileNode(attachment);
  1423. // }
  1424. // this.fileReplaceNode.click();
  1425. },
  1426. queryDownload : function( att ){
  1427. if( this.json.events && this.json.events.queryDownload && this.json.events.queryDownload.code ){
  1428. var flag = this.form.Macro.exec(this.json.events.queryDownload.code, att );
  1429. if( flag === false ){
  1430. return false
  1431. }else{
  1432. return true;
  1433. }
  1434. }else{
  1435. return true;
  1436. }
  1437. },
  1438. queryOpen : function( att ){
  1439. if( this.json.events && this.json.events.queryOpen && this.json.events.queryOpen.code ){
  1440. var flag = this.form.Macro.exec(this.json.events.queryOpen.code, att );
  1441. if( flag === false ){
  1442. return false
  1443. }else{
  1444. return true;
  1445. }
  1446. }else{
  1447. return true;
  1448. }
  1449. },
  1450. //小程序文件是否支持打开
  1451. checkMiniProgramFile: function(ext) {
  1452. var exts = ["doc", "docx", "xls", "xlsx", "ppt", "pptx", "pdf"];
  1453. for(var i = 0; i < exts.length; i++){
  1454. if(ext === exts[i]){
  1455. return true;
  1456. }
  1457. }
  1458. return false;
  1459. },
  1460. downloadAttachment: function (e, node, attachments) {
  1461. if (this.form.businessData.work && !this.form.businessData.work.completedTime) {
  1462. attachments.each(function (att) {
  1463. if( !this.queryDownload( att ) )return;
  1464. if (window.o2android && window.o2android.downloadAttachment) {
  1465. window.o2android.downloadAttachment(att.data.id);
  1466. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.downloadAttachment) {
  1467. window.webkit.messageHandlers.downloadAttachment.postMessage({ "id": att.data.id, "site": (this.json.site || this.json.id) });
  1468. } else if (window.wx && window.__wxjs_environment === 'miniprogram' && this.checkMiniProgramFile(att.data.extension)) { //微信小程序
  1469. wx.miniProgram.navigateTo({
  1470. url: '../file/download?attId=' + att.data.id + '&type=work&work=' + this.form.businessData.work.id
  1471. });
  1472. } else {
  1473. if (layout.mobile) {
  1474. //移动端 企业微信 钉钉 用本地打开 防止弹出自带浏览器 无权限问题
  1475. this.form.workAction.getAttachmentUrl(att.data.id, this.form.businessData.work.id, function (url) {
  1476. var xtoken = Cookie.read("x-token");
  1477. window.location = o2.filterUrl(url + "?x-token=" + xtoken);
  1478. });
  1479. } else {
  1480. this.form.workAction.getAttachmentStream(att.data.id, this.form.businessData.work.id);
  1481. }
  1482. }
  1483. this.fireEvent("download",[att])
  1484. }.bind(this));
  1485. } else {
  1486. attachments.each(function (att) {
  1487. if( !this.queryDownload( att ) )return;
  1488. if (window.o2android && window.o2android.downloadAttachment) {
  1489. window.o2android.downloadAttachment(att.data.id);
  1490. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.downloadAttachment) {
  1491. window.webkit.messageHandlers.downloadAttachment.postMessage({ "id": att.data.id, "site": (this.json.site || this.json.id) });
  1492. } else if (window.wx && window.__wxjs_environment === 'miniprogram' && this.checkMiniProgramFile(att.data.extension)) { //微信小程序
  1493. wx.miniProgram.navigateTo({
  1494. url: '../file/download?attId=' + att.data.id + '&type=work&workCompleted=' + this.form.businessData.workCompleted.id
  1495. });
  1496. } else {
  1497. if (layout.mobile) {
  1498. //移动端 企业微信 钉钉 用本地打开 防止弹出自带浏览器 无权限问题
  1499. this.form.workAction.getAttachmentWorkcompletedUrl(att.data.id, this.form.businessData.workCompleted.id, function (url) {
  1500. var xtoken = Cookie.read("x-token");
  1501. window.location = o2.filterUrl(url + "?x-token=" + xtoken);
  1502. });
  1503. } else {
  1504. this.form.workAction.getWorkcompletedAttachmentStream(att.data.id, this.form.businessData.workCompleted.id);
  1505. }
  1506. }
  1507. this.fireEvent("download",[att])
  1508. }.bind(this));
  1509. }
  1510. },
  1511. openAttachment: function (e, node, attachments) {
  1512. if (this.form.businessData.work && !this.form.businessData.work.completedTime) {
  1513. attachments.each(function (att) {
  1514. if( !this.queryOpen( att ) )return;
  1515. if (window.o2android && window.o2android.downloadAttachment) {
  1516. window.o2android.downloadAttachment(att.data.id);
  1517. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.downloadAttachment) {
  1518. window.webkit.messageHandlers.downloadAttachment.postMessage({ "id": att.data.id, "site": (this.json.site || this.json.id) });
  1519. } else if (window.wx && window.__wxjs_environment === 'miniprogram' && this.checkMiniProgramFile(att.data.extension)) { //微信小程序
  1520. wx.miniProgram.navigateTo({
  1521. url: '../file/download?attId=' + att.data.id + '&type=work&work=' + this.form.businessData.work.id
  1522. });
  1523. } else {
  1524. if (layout.mobile) {
  1525. //移动端 企业微信 钉钉 用本地打开 防止弹出自带浏览器 无权限问题
  1526. this.form.workAction.getAttachmentUrl(att.data.id, this.form.businessData.work.id, function (url) {
  1527. var xtoken = Cookie.read("x-token");
  1528. window.location = o2.filterUrl(url + "?x-token=" + xtoken);
  1529. });
  1530. } else {
  1531. this.form.workAction.getAttachmentData(att.data.id, this.form.businessData.work.id);
  1532. }
  1533. }
  1534. this.fireEvent("open",[att])
  1535. }.bind(this));
  1536. } else {
  1537. attachments.each(function (att) {
  1538. if( !this.queryOpen( att ) )return;
  1539. if (window.o2android && window.o2android.downloadAttachment) {
  1540. window.o2android.downloadAttachment(att.data.id);
  1541. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.downloadAttachment) {
  1542. window.webkit.messageHandlers.downloadAttachment.postMessage({ "id": att.data.id, "site": (this.json.site || this.json.id) });
  1543. } else if (window.wx && window.__wxjs_environment === 'miniprogram' && this.checkMiniProgramFile(att.data.extension)) { //微信小程序
  1544. wx.miniProgram.navigateTo({
  1545. url: '../file/download?attId=' + att.data.id + '&type=work&workCompleted=' + this.form.businessData.workCompleted.id
  1546. });
  1547. } else {
  1548. if (layout.mobile) {
  1549. //移动端 企业微信 钉钉 用本地打开 防止弹出自带浏览器 无权限问题
  1550. this.form.workAction.getAttachmentWorkcompletedUrl(att.data.id, ((this.form.businessData.workCompleted) ? this.form.businessData.workCompleted.id : this.form.businessData.work.id), function (url) {
  1551. var xtoken = Cookie.read("x-token");
  1552. window.location = o2.filterUrl(url + "?x-token=" + xtoken);
  1553. });
  1554. } else {
  1555. this.form.workAction.getWorkcompletedAttachmentData(att.data.id, ((this.form.businessData.workCompleted) ? this.form.businessData.workCompleted.id : this.form.businessData.work.id));
  1556. }
  1557. }
  1558. this.fireEvent("open",[att])
  1559. }.bind(this));
  1560. }
  1561. //this.downloadAttachment(e, node, attachment);
  1562. },
  1563. getAttachmentUrl: function (attachment, callback) {
  1564. if (this.form.businessData.work && !this.form.businessData.work.completedTime) {
  1565. this.form.workAction.getAttachmentUrl(attachment.data.id, this.form.businessData.work.id, callback);
  1566. } else {
  1567. this.form.workAction.getAttachmentWorkcompletedUrl(attachment.data.id, this.form.businessData.workCompleted.id, callback);
  1568. }
  1569. },
  1570. getTextData: function(){
  1571. var data = [];
  1572. this.attachmentController.attachments.each(function(att){
  1573. var o = {
  1574. "id": att.data.id,
  1575. "person": att.data.person,
  1576. "creatorUid": att.data.creatorUid,
  1577. "name": att.data.name,
  1578. "orderNumber": att.data.orderNumber,
  1579. "length": att.data.length,
  1580. "extension": att.data.extension,
  1581. "lastUpdateTime": att.data.lastUpdateTime,
  1582. "activityName": att.data.activityName
  1583. }
  1584. data.push(o);
  1585. });
  1586. return data;
  1587. },
  1588. /**
  1589. * @summary 为组件重新设置附件,该附件必须已经上传。
  1590. * @param data{WorkAttachmentData} .
  1591. */
  1592. setData: function(data){
  1593. this.attachmentController.clear();
  1594. data.each(function (att) {
  1595. var attachment = this.form.businessData.attachmentList.find(function(a){
  1596. return a.id==att.id;
  1597. });
  1598. var attData = attachment || att;
  1599. this.attachmentController.addAttachment(attData);
  1600. }.bind(this));
  1601. this.setAttachmentBusinessData();
  1602. },
  1603. createErrorNode: function (text) {
  1604. var node = new Element("div");
  1605. var iconNode = new Element("div", {
  1606. "styles": {
  1607. "width": "20px",
  1608. "height": "20px",
  1609. "float": "left",
  1610. "background": "url(" + "../x_component_process_Xform/$Form/default/icon/error.png) center center no-repeat"
  1611. }
  1612. }).inject(node);
  1613. var textNode = new Element("div", {
  1614. "styles": {
  1615. "line-height": "20px",
  1616. "margin-left": "20px",
  1617. "color": "red",
  1618. "word-break": "keep-all"
  1619. },
  1620. "text": text
  1621. }).inject(node);
  1622. return node;
  1623. },
  1624. notValidationMode: function (text) {
  1625. if (!this.isNotValidationMode) {
  1626. this.isNotValidationMode = true;
  1627. this.node.store("borderStyle", this.node.getStyles("border-left", "border-right", "border-top", "border-bottom"));
  1628. this.node.setStyle("border", "1px solid red");
  1629. this.errNode = this.createErrorNode(text).inject(this.node, "after");
  1630. this.showNotValidationMode(this.node);
  1631. }
  1632. },
  1633. showNotValidationMode: function (node) {
  1634. var p = node.getParent("div");
  1635. if (p) {
  1636. if (p.get("MWFtype") == "tab$Content") {
  1637. if (p.getParent("div").getStyle("display") == "none") {
  1638. var contentAreaNode = p.getParent("div").getParent("div");
  1639. var tabAreaNode = contentAreaNode.getPrevious("div");
  1640. var idx = contentAreaNode.getChildren().indexOf(p.getParent("div"));
  1641. var tabNode = tabAreaNode.getLast().getFirst().getChildren()[idx];
  1642. tabNode.click();
  1643. p = tabAreaNode.getParent("div");
  1644. }
  1645. }
  1646. this.showNotValidationMode(p);
  1647. }
  1648. },
  1649. validationMode: function () {
  1650. if (this.isNotValidationMode) {
  1651. this.isNotValidationMode = false;
  1652. this.node.setStyles(this.node.retrieve("borderStyle"));
  1653. if (this.errNode) {
  1654. this.errNode.destroy();
  1655. this.errNode = null;
  1656. }
  1657. }
  1658. },
  1659. validationConfigItem: function (routeName, data) {
  1660. var flag = (data.status == "all") ? true : (routeName == data.decision);
  1661. if (flag) {
  1662. var n = this.getData();
  1663. var v = (data.valueType == "value") ? n : n.length;
  1664. switch (data.operateor) {
  1665. case "isnull":
  1666. if (!v) {
  1667. this.notValidationMode(data.prompt);
  1668. return false;
  1669. }
  1670. break;
  1671. case "notnull":
  1672. if (v) {
  1673. this.notValidationMode(data.prompt);
  1674. return false;
  1675. }
  1676. break;
  1677. case "gt":
  1678. if (v > data.value) {
  1679. this.notValidationMode(data.prompt);
  1680. return false;
  1681. }
  1682. break;
  1683. case "lt":
  1684. if (v < data.value) {
  1685. this.notValidationMode(data.prompt);
  1686. return false;
  1687. }
  1688. break;
  1689. case "equal":
  1690. if (v == data.value) {
  1691. this.notValidationMode(data.prompt);
  1692. return false;
  1693. }
  1694. break;
  1695. case "neq":
  1696. if (v != data.value) {
  1697. this.notValidationMode(data.prompt);
  1698. return false;
  1699. }
  1700. break;
  1701. case "contain":
  1702. if (v.indexOf(data.value) != -1) {
  1703. this.notValidationMode(data.prompt);
  1704. return false;
  1705. }
  1706. break;
  1707. case "notcontain":
  1708. if (v.indexOf(data.value) == -1) {
  1709. this.notValidationMode(data.prompt);
  1710. return false;
  1711. }
  1712. break;
  1713. }
  1714. }
  1715. return true;
  1716. },
  1717. validationConfig: function (routeName, opinion) {
  1718. if (this.json.validationConfig) {
  1719. if (this.json.validationConfig.length) {
  1720. for (var i = 0; i < this.json.validationConfig.length; i++) {
  1721. var data = this.json.validationConfig[i];
  1722. if (!this.validationConfigItem(routeName, data)) return false;
  1723. }
  1724. }
  1725. return true;
  1726. }
  1727. return true;
  1728. },
  1729. /**
  1730. * @summary 根据组件的校验设置进行校验。
  1731. * @param {String} [routeName] - 可选,路由名称.
  1732. * @example
  1733. * if( !this.form.get('fieldId').validation() ){
  1734. * return false;
  1735. * }
  1736. * @return {Boolean} 是否通过校验
  1737. */
  1738. validation: function (routeName, opinion) {
  1739. if (!this.validationConfig(routeName, opinion)) return false;
  1740. if (!this.json.validation) return true;
  1741. if (!this.json.validation.code) return true;
  1742. this.currentRouteName = routeName;
  1743. var flag = this.form.Macro.exec(this.json.validation.code, this);
  1744. this.currentRouteName = "";
  1745. if (!flag) flag = MWF.xApplication.process.Xform.LP.notValidation;
  1746. if (flag.toString() != "true") {
  1747. this.notValidationMode(flag);
  1748. return false;
  1749. }
  1750. return true;
  1751. }
  1752. });
  1753. MWF.xApplication.process.Xform.AttachmentDg = MWF.APPAttachmentDg = new Class({
  1754. Extends: MWF.APPAttachment,
  1755. loadAttachmentController: function () {
  1756. //MWF.require("MWF.widget.AttachmentController", function() {
  1757. var options = {
  1758. "style": this.json.style || "default",
  1759. "title": "附件区域DG",
  1760. "listStyle": this.json.listStyle || "icon",
  1761. "size": this.json.size || "max",
  1762. "resize": (this.json.resize === "y" || this.json.resize === "true"),
  1763. "attachmentCount": this.json.attachmentCount || 0,
  1764. "isUpload": (this.json.isUpload === "y" || this.json.isUpload === "true"),
  1765. "isDelete": (this.json.isDelete === "y" || this.json.isDelete === "true"),
  1766. "isReplace": (this.json.isReplace === "y" || this.json.isReplace === "true"),
  1767. "isDownload": (this.json.isDownload === "y" || this.json.isDownload === "true"),
  1768. "isSizeChange": (this.json.isSizeChange === "y" || this.json.isSizeChange === "true"),
  1769. "readonly": (this.json.readonly === "y" || this.json.readonly === "true"),
  1770. "availableListStyles": this.json.availableListStyles ? this.json.availableListStyles : ["list", "seq", "icon", "preview"],
  1771. "isDeleteOption": this.json.isDelete,
  1772. "isReplaceOption": this.json.isReplace,
  1773. "toolbarGroupHidden": this.json.toolbarGroupHidden || [],
  1774. "onOrder": function () {
  1775. this.fireEvent("change");
  1776. }.bind(this)
  1777. };
  1778. if (this.readonly) options.readonly = true;
  1779. if (this.form.json.attachmentStyle) {
  1780. options = Object.merge(options, this.form.json.attachmentStyle);
  1781. }
  1782. this.attachmentController = new MWF.xApplication.process.Xform.AttachmentController(this.node, this, options);
  1783. this.attachmentController.load();
  1784. // var d = this._getBusinessData();
  1785. // if (d) d.each(function (att) {
  1786. // this.attachmentController.addAttachment(att);
  1787. // }.bind(this));
  1788. this.form.businessData.attachmentList.each(function (att) {
  1789. if (att.site === (this.json.site || this.json.id)) this.attachmentController.addAttachment(att);
  1790. }.bind(this));
  1791. this.setAttachmentBusinessData();
  1792. },
  1793. setAttachmentBusinessData: function(){
  1794. if (this.attachmentController) {
  1795. if (this.attachmentController.attachments.length) {
  1796. var values = this.attachmentController.attachments.map(function (d) {
  1797. return {
  1798. "control": d.data.control,
  1799. "name": d.data.name,
  1800. "id": d.data.id,
  1801. "person": d.data.person,
  1802. "creatorUid": d.data.creatorUid,
  1803. "orderNumber": d.data.orderNumber,
  1804. "length": d.data.length,
  1805. "extension": d.data.extension,
  1806. "lastUpdateTime": d.data.lastUpdateTime,
  1807. "activityName": d.data.activityName
  1808. };
  1809. });
  1810. this._setBusinessData(values);
  1811. } else {
  1812. this._setBusinessData([]);
  1813. }
  1814. }
  1815. }
  1816. });