Attachment.js 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633
  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.control.allowEdit) && att.data.person !== user) {
  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.control.allowEdit) && 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. debugger;
  501. var hiddenGroup = this.options.toolbarGroupHidden;
  502. if (!hiddenGroup.contains("edit")) {
  503. this.min_uploadAction = this.createAction(this.minActionAreaNode, "upload", MWF.LP.widget.upload, function (e, node) {
  504. this.uploadAttachment(e, node);
  505. }.bind(this));
  506. this.min_deleteAction = this.createAction(this.minActionAreaNode, "delete", MWF.LP.widget["delete"], function (e, node) {
  507. this.deleteAttachment(e, node);
  508. }.bind(this));
  509. if (!this.options.isReplaceHidden) {
  510. this.min_replaceAction = this.createAction(this.minActionAreaNode, "replace", MWF.LP.widget.replace, function (e, node) {
  511. this.replaceAttachment(e, node);
  512. }.bind(this));
  513. }
  514. }
  515. if (!hiddenGroup.contains("read")) {
  516. this.min_downloadAction = this.createAction(this.minActionAreaNode, "download", MWF.LP.widget.download
  517. , function (e, node) {
  518. this.downloadAttachment(e, node);
  519. }.bind(this));
  520. }
  521. if (!hiddenGroup.contains("config")) {
  522. this.min_orderAction = this.createAction(this.minActionAreaNode, "order", MWF.LP.widget.order, function (e, node) {
  523. this.orderAttachment(e, node);
  524. }.bind(this));
  525. }
  526. if (this.module.json.isOpenInOffice && this.module.json.officeControlName) {
  527. this.min_closeOfficeAction = this.createAction(this.minActionAreaNode, "closeOffice", MWF.LP.widget.closeOffice, function (e, node) {
  528. this.closeAttachmentOffice(e, node);
  529. }.bind(this));
  530. if (this.min_closeOfficeAction) this.setActionDisabled(this.closeOfficeAction);
  531. }
  532. if (!hiddenGroup.contains("edit") || !hiddenGroup.contains("read")) {
  533. this.createSeparate(this.minActionAreaNode);
  534. }
  535. //this.createSeparate(this.configActionsGroupNode);
  536. if (this.options.isSizeChange) {
  537. //this.createSeparate(this.minActionAreaNode);
  538. if (!hiddenGroup.contains("view")) {
  539. this.sizeAction = this.createAction(this.minActionAreaNode, "max", MWF.LP.widget.min, function () {
  540. this.changeControllerSize();
  541. }.bind(this));
  542. }
  543. }
  544. },
  545. closeAttachmentOffice: function () {
  546. var office = this.module.form.all[this.module.json.officeControlName];
  547. if (office) {
  548. office.openFile();
  549. if (this.min_closeOfficeAction) this.setActionDisabled(this.min_closeOfficeAction);
  550. if (this.closeOfficeAction) this.setActionDisabled(this.closeOfficeAction);
  551. }
  552. },
  553. configAttachment: function () {
  554. //this.fireEvent("delete", [attachment.data]);
  555. var lp = MWF.xApplication.process.Xform.LP;
  556. var css = this.module.form.css;
  557. var node = new Element("div", { "styles": css.attachmentPermissionNode }).inject(this.node);
  558. var attNames = new Element("div", { "styles": css.attachmentPermissionNamesNode }).inject(node);
  559. var attNamesTitle = new Element("div", { "styles": css.attachmentPermissionNamesTitleNode, "text": lp.attachmentPermissionInfo }).inject(attNames);
  560. var attNamesArea = new Element("div", { "styles": css.attachmentPermissionNamesAreaNode }).inject(attNames);
  561. if (this.selectedAttachments.length) {
  562. this.selectedAttachments.each(function (att) {
  563. var attNode = new Element("div", { "styles": css.attachmentPermissionAttNode, "text": att.data.name }).inject(attNamesArea);
  564. }.bind(this));
  565. }
  566. var editArea = new Element("div", { "styles": css.attachmentPermissionEditAreaNode }).inject(node);
  567. var title = new Element("div", { "styles": css.attachmentPermissionTitleNode, "text": lp.attachmentRead }).inject(editArea);
  568. var readInput = new Element("div", { "styles": css.attachmentPermissionInputNode }).inject(editArea);
  569. title = new Element("div", { "styles": css.attachmentPermissionTitleNode, "text": lp.attachmentEdit }).inject(editArea);
  570. var editInput = new Element("div", { "styles": css.attachmentPermissionInputNode }).inject(editArea);
  571. title = new Element("div", { "styles": css.attachmentPermissionTitleNode, "text": lp.attachmentController }).inject(editArea);
  572. var controllerInput = new Element("div", { "styles": css.attachmentPermissionInputNode }).inject(editArea);
  573. var dlg = o2.DL.open(Object.merge({
  574. "title": lp.attachmentPermission,
  575. "style": this.module.form.json.dialogStyle || "user",
  576. "isResize": false,
  577. "content": node,
  578. "buttonList": [
  579. {
  580. "type": "ok",
  581. "text": MWF.LP.process.button.ok,
  582. "action": function () {
  583. this.setAttachmentConfig(readInput, editInput, controllerInput);
  584. dlg.close();
  585. }.bind(this)
  586. },
  587. {
  588. "type": "cancel",
  589. "text": MWF.LP.process.button.cancel,
  590. "action": function () { dlg.close(); }
  591. }
  592. ]
  593. }, (this.module.form.json.dialogOptions||{})));
  594. if (this.selectedAttachments.length === 1) {
  595. var data = this.selectedAttachments[0].data;
  596. var readUnitList = (data.readUnitList) || [];
  597. var readIdentityList = (data.readIdentityList) || [];
  598. var editUnitList = (data.editUnitList) || [];
  599. var editIdentityList = (data.editIdentityList) || [];
  600. var controllerUnitList = (data.controllerUnitList) || [];
  601. var controllerIdentityList = (data.controllerIdentityList) || [];
  602. readInput.setSelectPerson(this.module.form.app.content, Object.merge(Object.clone(this.module.form.json.selectorStyle || {}), {
  603. "types": ["unit", "identity"],
  604. "values": readUnitList.concat(readIdentityList).trim()
  605. }));
  606. editInput.setSelectPerson(this.module.form.app.content, Object.merge(Object.clone(this.module.form.json.selectorStyle || {}), {
  607. "types": ["unit", "identity"],
  608. "values": editUnitList.concat(editIdentityList).trim()
  609. }));
  610. controllerInput.setSelectPerson(this.module.form.app.content, Object.merge(Object.clone(this.module.form.json.selectorStyle || {}), {
  611. "types": ["unit", "identity"],
  612. "values": controllerUnitList.concat(controllerIdentityList).trim()
  613. }));
  614. } else {
  615. readInput.setSelectPerson(this.module.form.app.content, Object.merge(Object.clone(this.module.form.json.selectorStyle || {}), {
  616. "types": ["unit", "identity"]
  617. }));
  618. editInput.setSelectPerson(this.module.form.app.content, Object.merge(Object.clone(this.module.form.json.selectorStyle || {}), {
  619. "types": ["unit", "identity"]
  620. }));
  621. controllerInput.setSelectPerson(this.module.form.app.content, Object.merge(Object.clone(this.module.form.json.selectorStyle || {}), {
  622. "types": ["unit", "identity"]
  623. }));
  624. }
  625. },
  626. setAttachmentConfig: function (readInput, editInput, controllerInput) {
  627. if (this.selectedAttachments.length) {
  628. var readList = readInput.retrieve("data-value");
  629. var editList = editInput.retrieve("data-value");
  630. var controllerList = controllerInput.retrieve("data-value");
  631. var readUnitList = [];
  632. var readIdentityList = [];
  633. var editUnitList = [];
  634. var editIdentityList = [];
  635. var controllerUnitList = [];
  636. var controllerIdentityList = [];
  637. if (readList) {
  638. readList.each(function (v) {
  639. var vName = (typeOf(v) === "string") ? v : v.distinguishedName;
  640. var len = vName.length;
  641. var flag = vName.substring(len - 1, len);
  642. if (flag === "U") readUnitList.push(vName);
  643. if (flag === "I") readIdentityList.push(vName);
  644. });
  645. }
  646. if (editList) {
  647. editList.each(function (v) {
  648. var vName = (typeOf(v) === "string") ? v : v.distinguishedName;
  649. var len = vName.length;
  650. var flag = vName.substring(len - 1, len);
  651. if (flag === "U") editUnitList.push(vName);
  652. if (flag === "I") editIdentityList.push(vName);
  653. });
  654. }
  655. if (controllerList) {
  656. controllerList.each(function (v) {
  657. var vName = (typeOf(v) === "string") ? v : v.distinguishedName;
  658. var len = vName.length;
  659. var flag = vName.substring(len - 1, len);
  660. if (flag === "U") controllerUnitList.push(vName);
  661. if (flag === "I") controllerIdentityList.push(vName);
  662. });
  663. }
  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);
  672. }.bind(this));
  673. }
  674. },
  675. checkImageTex: function () {
  676. if (this.selectedAttachments.length && this.selectedAttachments.length == 1) {
  677. var att = this.selectedAttachments[0];
  678. var lp = MWF.xApplication.process.Xform.LP;
  679. var css = this.module.form.css;
  680. var node = new Element("div", { "styles": css.attachmentOCRNode }).inject(this.node);
  681. var previewNode = new Element("div", { "styles": css.attachmentOCRImageAreaNode }).inject(node);
  682. var imgNode = new Element("img", { "styles": css.attachmentOCRImageNode }).inject(previewNode);
  683. o2.Actions.get("x_processplatform_assemble_surface").getAttachmentUrl(att.data.id, this.module.form.businessData.work.id, function (url) {
  684. imgNode.set("src", url);
  685. });
  686. var areaNode = new Element("div", { "styles": css.attachmentOCRInputAreaNode }).inject(node);
  687. var inputNode = new Element("textarea", { "styles": css.attachmentOCRInputNode }).inject(areaNode);
  688. var dlg = o2.DL.open({
  689. "title": lp.attachmentOCRTitle,
  690. "style": this.module.form.json.dialogStyle || "user",
  691. "isResize": false,
  692. "content": node,
  693. "buttonList": [
  694. {
  695. "type": "ok",
  696. "text": MWF.LP.process.button.ok,
  697. "action": function () {
  698. this.setAttachmentOCR(inputNode, att);
  699. dlg.close();
  700. }.bind(this)
  701. },
  702. {
  703. "type": "cancel",
  704. "text": MWF.LP.process.button.cancel,
  705. "action": function () { dlg.close(); }
  706. }
  707. ]
  708. });
  709. if (att.data.ocr) {
  710. inputNode.set("text", att.data.ocr.text || "");
  711. } else {
  712. o2.Actions.get("x_processplatform_assemble_surface").getAttachmentOCR(att.data.id, this.module.form.businessData.work.id, function (json) {
  713. att.data.ocr = json.data;
  714. inputNode.set("text", json.data.text || "");
  715. }.bind(this))
  716. }
  717. }
  718. },
  719. setAttachmentOCR: function (inputNode, att) {
  720. var data = inputNode.get("text");
  721. if (!att.data.ocr) att.data.ocr = {};
  722. att.data.ocr.text = data;
  723. o2.Actions.get("x_processplatform_assemble_surface").setAttachmentOCR(att.data.id, this.module.form.businessData.work.id, {
  724. "text": data
  725. }, function () {
  726. this.module.form.app.notice("success", lp.attachmentOCR_saved, this.node);
  727. }.bind(this));
  728. },
  729. checkMoveAction: function (item) {
  730. if (item) {
  731. var actionArea = item.getFirst().getNext();
  732. var actionup = actionArea.getFirst().show();
  733. var actiondown = actionArea.getLast().show();
  734. tmp = item.getPrevious();
  735. if (!tmp) actionup.hide();
  736. tmp = item.getNext();
  737. if (!tmp) actiondown.hide();
  738. }
  739. },
  740. orderAttachment: function () {
  741. if (this.attachments.length) {
  742. this.attachments = this.attachments.sort(function (a1, a2) {
  743. if (!a2.data.orderNumber) return 1;
  744. if (!a1.data.orderNumber) return -1;
  745. return a1.data.orderNumber - a2.data.orderNumber;
  746. }.bind(this));
  747. var lp = MWF.xApplication.process.Xform.LP;
  748. var css = this.module.form.css;
  749. var node = new Element("div", { "styles": css.attachmentOrderNode });
  750. var infoNode = new Element("div", { "styles": css.attachmentOrderInforNode, "text": lp.attachmentOrderInfo }).inject(node);
  751. var attrchmentsNode = new Element("div", { "styles": css.attachmentOrderAreaNode }).inject(node);
  752. var iconUrl = "/x_component_File/$Main/icon.json";
  753. var icons = null;
  754. o2.getJSON(iconUrl, function (json) {
  755. icons = json;
  756. }.bind(this), false, false);
  757. this.attachments.each(function (att, idx) {
  758. var iconName = icons[att.data.extension.toLowerCase()] || icons.unknow;
  759. var iconFolderUrl = "/x_component_File/$Main/default/file/" + iconName;
  760. var itemNode = new Element("div", { "styles": css.attachmentOrderItemNode }).inject(attrchmentsNode);
  761. itemNode.store("att", att);
  762. var icon = new Element("div", { "styles": css.attachmentOrderItemIconNode }).inject(itemNode);
  763. icon.setStyle("background-image", "url('" + iconFolderUrl + "')");
  764. var actionArea = new Element("div", { "styles": css.attachmentOrderItemActionNode }).inject(itemNode);
  765. var text = new Element("div", { "styles": css.attachmentOrderItemTextNode, "text": att.data.name }).inject(itemNode);
  766. var actionUp = new Element("div", { "styles": css.attachmentOrderItemActionUpNode, "text": lp.attachmentOrderUp }).inject(actionArea);
  767. var actionDown = new Element("div", { "styles": css.attachmentOrderItemActionDownNode, "text": lp.attachmentOrderDown }).inject(actionArea);
  768. if (idx == 0) actionUp.hide();
  769. if (idx == this.attachments.length - 1) actionDown.hide();
  770. actionUp.addEvent("click", function (e) {
  771. var itemNode = e.target.getParent().getParent();
  772. var upNode = itemNode.getPrevious();
  773. if (upNode) {
  774. itemNode.inject(upNode, "before");
  775. this.checkMoveAction(upNode);
  776. }
  777. this.checkMoveAction(itemNode);
  778. itemNode.highlight();
  779. //itemNode.setStyle("background-color", "#faf9f1");
  780. }.bind(this));
  781. actionDown.addEvent("click", function (e) {
  782. var itemNode = e.target.getParent().getParent();
  783. var downNode = itemNode.getNext();
  784. if (downNode) {
  785. itemNode.inject(downNode, "after");
  786. this.checkMoveAction(downNode);
  787. }
  788. this.checkMoveAction(itemNode);
  789. itemNode.highlight();
  790. // /itemNode.setStyle("background-color", "#faf9f1");
  791. }.bind(this));
  792. itemNode.addEvents({
  793. "mouseover": function (e) { this.setStyle("background-color", "#f1f6fa"); },
  794. "mouseout": function (e) { this.setStyle("background-color", "#ffffff"); }
  795. });
  796. //var droppables = attrchmentsNode.getChildren();
  797. new Drag(itemNode, {
  798. "handle": icon,
  799. "snap": 5,
  800. "stopPropagation": true,
  801. "preventDefault": true,
  802. onStart: function (el, e) {
  803. var itemNode = el;
  804. itemNode.setStyle("background-color", "#f1f6fa");
  805. var moveNode = itemNode.clone(true).setStyles(css.attachmentOrderItemNode).setStyles({
  806. "background-color": "#faf9f1",
  807. "opacity": 0.8,
  808. "border": "1px dotted #333333"
  809. }).inject(node);
  810. moveNode.position({
  811. "relativeTo": itemNode,
  812. "position": 'upperLeft',
  813. "edge": 'upperLeft'
  814. });
  815. moveNode.owner = itemNode;
  816. var move = new Drag.Move(moveNode, {
  817. "container": node,
  818. "droppables": attrchmentsNode.getChildren(),
  819. "onEnter": function (el, drop) {
  820. moveNode.flagNode = new Element("div", { "styles": css.attachmentOrderFlagNode }).inject(drop, "before");
  821. },
  822. "onLeave": function (el, drop) {
  823. if (moveNode.flagNode) moveNode.flagNode.destroy();
  824. },
  825. "onDrop": function (el, drop) {
  826. if (moveNode.flagNode) {
  827. moveNode.owner.inject(moveNode.flagNode, "after");
  828. moveNode.flagNode.destroy();
  829. moveNode.owner.highlight();
  830. this.checkMoveAction(moveNode.owner);
  831. this.checkMoveAction(drop);
  832. this.checkMoveAction(attrchmentsNode.getLast());
  833. moveNode.destroy()
  834. }
  835. }.bind(this)
  836. });
  837. move.start(e);
  838. }.bind(this),
  839. enter: function (el) {
  840. el.removeClass('dragging');
  841. }
  842. });
  843. //itemNode.dragMove
  844. }.bind(this));
  845. var dlg = o2.DL.open(Object.merge({
  846. "title": lp.attachmentOrderTitle,
  847. "style": this.module.form.json.dialogStyle || "user",
  848. "isResize": false,
  849. "content": node,
  850. "width": "auto",
  851. "height": "auto",
  852. "buttonList": [
  853. {
  854. "type": "ok",
  855. "text": MWF.LP.process.button.ok,
  856. "action": function () {
  857. this.sortAttachment(attrchmentsNode);
  858. dlg.close();
  859. }.bind(this)
  860. },
  861. {
  862. "type": "cancel",
  863. "text": MWF.LP.process.button.cancel,
  864. "action": function () { dlg.close(); }
  865. }
  866. ],
  867. "onPostLoad": function () {
  868. var dlg = this;
  869. dlg.node.setStyle("display", "block");
  870. var size = {};
  871. if (css.attachmentOrderNode) {
  872. if (parseFloat(css.attachmentOrderNode.width).toString() !== "NaN") {
  873. size.x = parseInt(css.attachmentOrderNode.width)
  874. }
  875. if (parseFloat(css.attachmentOrderNode.height).toString() !== "NaN") {
  876. size.y = parseInt(css.attachmentOrderNode.height)
  877. }
  878. }
  879. node.show();
  880. var nodeSize = node.getSize();
  881. dlg.content.setStyles({
  882. "width": size.x || nodeSize.x,
  883. "height": size.y || nodeSize.y
  884. });
  885. dlg.setContentSize();
  886. }
  887. }, (this.module.form.json.dialogOptions||{})));
  888. }
  889. },
  890. sortAttachment: function (node) {
  891. var nodes = node.getChildren();
  892. nodes.each(function (item, idx) {
  893. var att = item.retrieve("att", null);
  894. if (att) {
  895. att.data.orderNumber = idx;
  896. o2.Actions.load("x_processplatform_assemble_surface").AttachmentAction.changeOrderNumber(att.data.id, this.module.form.businessData.work.id, idx);
  897. }
  898. }.bind(this));
  899. this.attachments = this.attachments.sort(function (a1, a2) {
  900. if (!a2.data.orderNumber) return 1;
  901. if (!a1.data.orderNumber) return -1;
  902. return a1.data.orderNumber - a2.data.orderNumber;
  903. }.bind(this));
  904. this.reloadAttachments();
  905. this.fireEvent("order");
  906. }
  907. });
  908. MWF.xApplication.process.Xform.Attachment = MWF.APPAttachment = new Class({
  909. Extends: MWF.APP$Module,
  910. options: {
  911. "moduleEvents": ["upload", "delete", "afterDelete", "load", "change"]
  912. },
  913. initialize: function (node, json, form, options) {
  914. this.node = $(node);
  915. this.node.store("module", this);
  916. this.json = json;
  917. this.form = form;
  918. this.field = true;
  919. },
  920. _loadUserInterface: function () {
  921. this.node.empty();
  922. if (this.form.businessData.activity && this.form.businessData.activity.id){
  923. this.loadAttachmentController();
  924. this.fireEvent("load");
  925. }
  926. },
  927. loadAttachmentController: function () {
  928. //MWF.require("MWF.widget.AttachmentController", function() {
  929. var options = {
  930. "style": this.json.style || "default",
  931. "title": "附件区域",
  932. "listStyle": this.json.listStyle || "icon",
  933. "size": this.json.size || "max",
  934. "resize": (this.json.resize === "y" || this.json.resize === "true"),
  935. "attachmentCount": this.json.attachmentCount || 0,
  936. "isUpload": (this.json.isUpload === "y" || this.json.isUpload === "true"),
  937. "isDelete": (this.json.isDelete === "y" || this.json.isDelete === "true"),
  938. "isReplace": (this.json.isReplace === "y" || this.json.isReplace === "true"),
  939. "isDownload": (this.json.isDownload === "y" || this.json.isDownload === "true"),
  940. "isSizeChange": (this.json.isSizeChange === "y" || this.json.isSizeChange === "true"),
  941. "readonly": (this.json.readonly === "y" || this.json.readonly === "true"),
  942. "availableListStyles": this.json.availableListStyles ? this.json.availableListStyles : ["list", "seq", "icon", "preview"],
  943. "isDeleteOption": this.json.isDelete,
  944. "isReplaceOption": this.json.isReplace,
  945. "toolbarGroupHidden": this.json.toolbarGroupHidden || [],
  946. "onOrder": function () {
  947. this.fireEvent("change");
  948. }.bind(this)
  949. };
  950. if (this.readonly) options.readonly = true;
  951. if (this.form.json.attachmentStyle) {
  952. options = Object.merge(options, this.form.json.attachmentStyle);
  953. }
  954. //this.attachmentController = new MWF.widget.ATTER(this.node, this, options);
  955. this.attachmentController = new MWF.xApplication.process.Xform.AttachmentController(this.node, this, options);
  956. this.attachmentController.load();
  957. this.form.businessData.attachmentList.each(function (att) {
  958. //if (att.site===this.json.id || (this.json.isOpenInOffice && this.json.officeControlName===att.site)) this.attachmentController.addAttachment(att);
  959. if (att.site === this.json.id) this.attachmentController.addAttachment(att);
  960. }.bind(this));
  961. this.setAttachmentBusinessData();
  962. //}.bind(this));
  963. },
  964. setAttachmentBusinessData: function () {
  965. if (this.attachmentController) {
  966. if (this.attachmentController.attachments.length) {
  967. var values = this.attachmentController.attachments.map(function (d) {
  968. return d.data.name;
  969. });
  970. this._setBusinessData(values);
  971. } else {
  972. this._setBusinessData([]);
  973. }
  974. }
  975. },
  976. _loadEvents: function (editorConfig) {
  977. Object.each(this.json.events, function (e, key) {
  978. if (e.code) {
  979. if (this.options.moduleEvents.indexOf(key) !== -1) {
  980. this.addEvent(key, function (event) {
  981. return this.form.Macro.fire(e.code, this, event);
  982. }.bind(this));
  983. } else {
  984. this.node.addEvent(key, function (event) {
  985. return this.form.Macro.fire(e.code, this, event);
  986. }.bind(this));
  987. }
  988. }
  989. }.bind(this));
  990. },
  991. getData: function () {
  992. return (this.attachmentController) ? this.attachmentController.getAttachmentNames() : null;
  993. },
  994. createUploadFileNode: function () {
  995. var accept = "*";
  996. if (!this.json.attachmentExtType || (this.json.attachmentExtType.indexOf("other") != -1 && !this.json.attachmentExtOtherType)) {
  997. } else {
  998. accepts = [];
  999. var otherType = this.json.attachmentExtOtherType;
  1000. this.json.attachmentExtType.each(function (v) {
  1001. switch (v) {
  1002. case "word":
  1003. accepts.push(".doc, .docx, .dot, .dotx");
  1004. break;
  1005. case "excel":
  1006. accepts.push(".xls, .xlsx, .xlsm, .xlt, .xltx");
  1007. break;
  1008. case "ppt":
  1009. accepts.push(".pptx, .ppt, .pot, .potx, .potm");
  1010. break;
  1011. case "txt":
  1012. accepts.push(".txt");
  1013. break;
  1014. case "pic":
  1015. accepts.push(".bmp, .gif, .psd, .jpeg, .jpg, .png");
  1016. break;
  1017. case "pdf":
  1018. accepts.push(".pdf");
  1019. break;
  1020. case "zip":
  1021. accepts.push(".zip, .rar");
  1022. break;
  1023. case "audio":
  1024. accepts.push(".mp3, .wav, .wma, .wmv, .flac, .ape");
  1025. break;
  1026. case "video":
  1027. accepts.push(".avi, .mkv, .mov, .ogg, .mp4, .mpeg");
  1028. break;
  1029. case "other":
  1030. if (this.json.attachmentExtOtherType) accepts.push(this.json.attachmentExtOtherType);
  1031. break;
  1032. }
  1033. }.bind(this));
  1034. accept = accepts.join(", ");
  1035. }
  1036. var size = 0;
  1037. if (this.json.attachmentSize) size = this.json.attachmentSize.toFloat();
  1038. this.attachmentController.doUploadAttachment({ "site": this.json.id }, this.form.workAction.action, "uploadAttachment", { "id": this.form.businessData.work.id }, null, function (o) {
  1039. if (o.id) {
  1040. this.form.workAction.getAttachment(o.id, this.form.businessData.work.id, function (json) {
  1041. if (json.data) {
  1042. if (!json.data.control) json.data.control = {};
  1043. this.attachmentController.addAttachment(json.data);
  1044. }
  1045. this.attachmentController.checkActions();
  1046. this.setAttachmentBusinessData();
  1047. this.fireEvent("upload", [json.data]);
  1048. this.fireEvent("change");
  1049. }.bind(this))
  1050. }
  1051. this.attachmentController.checkActions();
  1052. }.bind(this), function (files) {
  1053. if (files.length) {
  1054. if ((files.length + this.attachmentController.attachments.length > this.attachmentController.options.attachmentCount) && this.attachmentController.options.attachmentCount > 0) {
  1055. var content = MWF.xApplication.process.Xform.LP.uploadMore;
  1056. content = content.replace("{n}", this.attachmentController.options.attachmentCount);
  1057. this.form.notice(content, "error");
  1058. return false;
  1059. }
  1060. }
  1061. return true;
  1062. }.bind(this), true, accept, size);
  1063. // this.uploadFileAreaNode = new Element("div");
  1064. // var html = "<input name=\"file\" type=\"file\" multiple/>";
  1065. // this.uploadFileAreaNode.set("html", html);
  1066. //
  1067. // this.fileUploadNode = this.uploadFileAreaNode.getFirst();
  1068. // this.fileUploadNode.addEvent("change", function(){
  1069. //
  1070. // var files = this.fileUploadNode.files;
  1071. // if (files.length){
  1072. // if ((files.length+this.attachmentController.attachments.length > this.attachmentController.options.attachmentCount) && this.attachmentController.options.attachmentCount>0){
  1073. // var content = MWF.xApplication.process.Xform.LP.uploadMore;
  1074. // content = content.replace("{n}", this.attachmentController.options.attachmentCount);
  1075. // this.form.notice(content, "error");
  1076. // }else{
  1077. // for (var i = 0; i < files.length; i++) {
  1078. // var file = files.item(i);
  1079. //
  1080. // var formData = new FormData();
  1081. // formData.append('site', this.json.id);
  1082. // formData.append('file', file);
  1083. //
  1084. // //formData.append('folder', folderId);
  1085. //
  1086. // this.form.workAction.uploadAttachment(this.form.businessData.work.id ,function(o, text){
  1087. // if (o.id){
  1088. // this.form.workAction.getAttachment(o.id, this.form.businessData.work.id, function(json){
  1089. // if (json.data) this.attachmentController.addAttachment(json.data);
  1090. // this.attachmentController.checkActions();
  1091. //
  1092. // this.fireEvent("upload", [json.data]);
  1093. // }.bind(this))
  1094. // }
  1095. // this.attachmentController.checkActions();
  1096. // }.bind(this), null, formData, file);
  1097. // }
  1098. // }
  1099. // }
  1100. // }.bind(this));
  1101. },
  1102. uploadAttachment: function (e, node) {
  1103. if (window.o2android && window.o2android.uploadAttachment) {
  1104. window.o2android.uploadAttachment(this.json.id);
  1105. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.uploadAttachment) {
  1106. window.webkit.messageHandlers.uploadAttachment.postMessage({ "site": this.json.id });
  1107. } else {
  1108. // if (!this.uploadFileAreaNode){
  1109. this.createUploadFileNode();
  1110. // }
  1111. // this.fileUploadNode.click();
  1112. }
  1113. },
  1114. deleteAttachments: function (e, node, attachments) {
  1115. var names = [];
  1116. attachments.each(function (attachment) {
  1117. names.push(attachment.data.name);
  1118. }.bind(this));
  1119. // if ((window.o2 && window.o2.replaceAttachment) || (window.webkit && window.webkit.messageHandlers)){
  1120. // if (window.confirm(MWF.xApplication.process.Xform.LP.deleteAttachment+"( "+names.join(", ")+" )")){
  1121. // while (attachments.length){
  1122. // attachment = attachments.shift();
  1123. // this.deleteAttachment(attachment);
  1124. // }
  1125. // }
  1126. // }else {
  1127. // var tmpNode = new Element("div", {
  1128. // "styles": {
  1129. // "background-color": "#0000ff",
  1130. // "border-style": "solid",
  1131. // "border-color": "#fff",
  1132. // "border-width": "1",
  1133. // "box-shadow": "0px 0px 20px #999",
  1134. // "z-index": "20000",
  1135. // "overflow": "hidden",
  1136. // "font-size": "14px",
  1137. // "height": "160px",
  1138. // "padding": "0px",
  1139. // "width": "300px",
  1140. // "position": "absolute",
  1141. // "top": "50px",
  1142. // "left": "20px",
  1143. // "opacity": 1,
  1144. // "border-radius": "5px"
  1145. // }
  1146. // }).inject(this.form.app.content);
  1147. var _self = this;
  1148. this.form.confirm("warn", e, MWF.xApplication.process.Xform.LP.deleteAttachmentTitle, MWF.xApplication.process.Xform.LP.deleteAttachment + "( " + names.join(", ") + " )", 300, 120, function () {
  1149. while (attachments.length) {
  1150. var attachment = attachments.shift();
  1151. _self.deleteAttachment(attachment);
  1152. }
  1153. this.close();
  1154. }, function () {
  1155. this.close();
  1156. }, null, null, this.form.json.confirmStyle);
  1157. },
  1158. deleteAttachment: function (attachment) {
  1159. this.fireEvent("delete", [attachment.data]);
  1160. var id = attachment.data.id;
  1161. this.form.workAction.deleteAttachment(attachment.data.id, this.form.businessData.work.id, function (josn) {
  1162. this.attachmentController.removeAttachment(attachment);
  1163. this.attachmentController.checkActions();
  1164. if (this.form.officeList) {
  1165. this.form.officeList.each(function (office) {
  1166. if (office.openedAttachment) {
  1167. if (office.openedAttachment.id == id) {
  1168. office.loadOfficeEdit();
  1169. }
  1170. }
  1171. }.bind(this));
  1172. }
  1173. this.setAttachmentBusinessData();
  1174. this.fireEvent("afterDelete", [attachment.data]);
  1175. this.fireEvent("change");
  1176. }.bind(this));
  1177. },
  1178. replaceAttachment: function (e, node, attachment) {
  1179. if (window.o2android && window.o2android.replaceAttachment) {
  1180. window.o2android.replaceAttachment(attachment.data.id, this.json.id);
  1181. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.replaceAttachment) {
  1182. window.webkit.messageHandlers.replaceAttachment.postMessage({ "id": attachment.data.id, "site": this.json.id });
  1183. } else {
  1184. var _self = this;
  1185. this.form.confirm("warn", e, MWF.xApplication.process.Xform.LP.replaceAttachmentTitle, MWF.xApplication.process.Xform.LP.replaceAttachment + "( " + attachment.data.name + " )", 350, 120, function () {
  1186. _self.replaceAttachmentFile(attachment);
  1187. this.close();
  1188. }, function () {
  1189. this.close();
  1190. }, null, null, this.form.json.confirmStyle);
  1191. }
  1192. },
  1193. createReplaceFileNode: function (attachment) {
  1194. var accept = "*";
  1195. if (!this.json.attachmentExtType || this.json.attachmentExtType.indexOf("other") != -1 && !this.json.attachmentExtOtherType) {
  1196. } else {
  1197. accepts = [];
  1198. var otherType = this.json.attachmentExtOtherType;
  1199. this.json.attachmentExtType.each(function (v) {
  1200. switch (v) {
  1201. case "word":
  1202. accepts.push(".doc, .docx, .dot, .dotx");
  1203. break;
  1204. case "excel":
  1205. accepts.push(".xls, .xlsx, .xlsm, .xlt, .xltx");
  1206. break;
  1207. case "ppt":
  1208. accepts.push(".pptx, .ppt, .pot, .potx, .potm");
  1209. break;
  1210. case "txt":
  1211. accepts.push(".txt");
  1212. break;
  1213. case "pic":
  1214. accepts.push(".bmp, .gif, .psd, .jpeg, .jpg");
  1215. break;
  1216. case "pdf":
  1217. accepts.push(".pdf");
  1218. break;
  1219. case "zip":
  1220. accepts.push(".zip, .rar");
  1221. break;
  1222. case "audio":
  1223. accepts.push(".mp3, .wav, .wma, .wmv, .flac, .ape");
  1224. break;
  1225. case "video":
  1226. accepts.push(".avi, .mkv, .mov, .ogg, .mp4, .mpeg");
  1227. break;
  1228. case "other":
  1229. if (this.json.attachmentExtOtherType) accepts.push(this.json.attachmentExtOtherType);
  1230. break;
  1231. }
  1232. });
  1233. accept = accepts.join(", ");
  1234. }
  1235. var size = 0;
  1236. if (this.json.attachmentSize) size = this.json.attachmentSize.toFloat();
  1237. this.attachmentController.doUploadAttachment({ "site": this.json.id }, this.form.workAction.action, "replaceAttachment",
  1238. { "id": attachment.data.id, "workid": this.form.businessData.work.id }, null, function (o) {
  1239. this.form.workAction.getAttachment(attachment.data.id, this.form.businessData.work.id, function (json) {
  1240. attachment.data = json.data;
  1241. attachment.reload();
  1242. this.attachmentController.checkActions();
  1243. }.bind(this))
  1244. }.bind(this), null, true, accept, size);
  1245. // this.replaceFileAreaNode = new Element("div");
  1246. // var html = "<input name=\"file\" type=\"file\" multiple/>";
  1247. // this.replaceFileAreaNode.set("html", html);
  1248. //
  1249. // this.fileReplaceNode = this.replaceFileAreaNode.getFirst();
  1250. // this.fileReplaceNode.addEvent("change", function(){
  1251. //
  1252. // var files = this.fileReplaceNode.files;
  1253. // if (files.length){
  1254. // for (var i = 0; i < files.length; i++) {
  1255. // var file = files.item(i);
  1256. //
  1257. // var formData = new FormData();
  1258. // formData.append('file', file);
  1259. // // formData.append('site', this.json.id);
  1260. //
  1261. // this.form.workAction.replaceAttachment(attachment.data.id, this.form.businessData.work.id ,function(o, text){
  1262. // this.form.workAction.getAttachment(attachment.data.id, this.form.businessData.work.id, function(json){
  1263. // attachment.data = json.data;
  1264. // attachment.reload();
  1265. // this.attachmentController.checkActions();
  1266. // }.bind(this))
  1267. // }.bind(this), null, formData, file);
  1268. // }
  1269. // }
  1270. // }.bind(this));
  1271. },
  1272. replaceAttachmentFile: function (attachment) {
  1273. //if (!this.replaceFileAreaNode){
  1274. this.createReplaceFileNode(attachment);
  1275. // }
  1276. // this.fileReplaceNode.click();
  1277. },
  1278. downloadAttachment: function (e, node, attachments) {
  1279. if (this.form.businessData.work && !this.form.businessData.work.completedTime) {
  1280. attachments.each(function (att) {
  1281. if (window.o2android && window.o2android.downloadAttachment) {
  1282. window.o2android.downloadAttachment(att.data.id);
  1283. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.downloadAttachment) {
  1284. window.webkit.messageHandlers.downloadAttachment.postMessage({ "id": att.data.id, "site": this.json.id });
  1285. } else {
  1286. if (layout.mobile) {
  1287. //移动端 企业微信 钉钉 用本地打开 防止弹出自带浏览器 无权限问题
  1288. this.form.workAction.getAttachmentUrl(att.data.id, this.form.businessData.work.id, function (url) {
  1289. var xtoken = Cookie.read("x-token");
  1290. window.location = url + "?x-token=" + xtoken;
  1291. });
  1292. } else {
  1293. this.form.workAction.getAttachmentStream(att.data.id, this.form.businessData.work.id);
  1294. }
  1295. }
  1296. }.bind(this));
  1297. } else {
  1298. attachments.each(function (att) {
  1299. if (window.o2android && window.o2android.downloadAttachment) {
  1300. window.o2android.downloadAttachment(att.data.id);
  1301. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.downloadAttachment) {
  1302. window.webkit.messageHandlers.downloadAttachment.postMessage({ "id": att.data.id, "site": this.json.id });
  1303. } else {
  1304. if (layout.mobile) {
  1305. //移动端 企业微信 钉钉 用本地打开 防止弹出自带浏览器 无权限问题
  1306. this.form.workAction.getAttachmentWorkcompletedUrl(att.data.id, this.form.businessData.workCompleted.id, function (url) {
  1307. var xtoken = Cookie.read("x-token");
  1308. window.location = url + "?x-token=" + xtoken;
  1309. });
  1310. } else {
  1311. this.form.workAction.getWorkcompletedAttachmentStream(att.data.id, this.form.businessData.workCompleted.id);
  1312. }
  1313. }
  1314. }.bind(this));
  1315. }
  1316. },
  1317. openAttachment: function (e, node, attachments) {
  1318. if (this.form.businessData.work && !this.form.businessData.work.completedTime) {
  1319. attachments.each(function (att) {
  1320. if (window.o2android && window.o2android.downloadAttachment) {
  1321. window.o2android.downloadAttachment(att.data.id);
  1322. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.downloadAttachment) {
  1323. window.webkit.messageHandlers.downloadAttachment.postMessage({ "id": att.data.id, "site": this.json.id });
  1324. } else {
  1325. if (layout.mobile) {
  1326. //移动端 企业微信 钉钉 用本地打开 防止弹出自带浏览器 无权限问题
  1327. this.form.workAction.getAttachmentUrl(att.data.id, this.form.businessData.work.id, function (url) {
  1328. var xtoken = Cookie.read("x-token");
  1329. window.location = url + "?x-token=" + xtoken;
  1330. });
  1331. } else {
  1332. this.form.workAction.getAttachmentData(att.data.id, this.form.businessData.work.id);
  1333. }
  1334. }
  1335. }.bind(this));
  1336. } else {
  1337. attachments.each(function (att) {
  1338. if (window.o2android && window.o2android.downloadAttachment) {
  1339. window.o2android.downloadAttachment(att.data.id);
  1340. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.downloadAttachment) {
  1341. window.webkit.messageHandlers.downloadAttachment.postMessage(att.data.id, this.json.id);
  1342. } else {
  1343. if (layout.mobile) {
  1344. //移动端 企业微信 钉钉 用本地打开 防止弹出自带浏览器 无权限问题
  1345. this.form.workAction.getAttachmentWorkcompletedUrl(att.data.id, ((this.form.businessData.workCompleted) ? this.form.businessData.workCompleted.id : this.form.businessData.work.id), function (url) {
  1346. var xtoken = Cookie.read("x-token");
  1347. window.location = url + "?x-token=" + xtoken;
  1348. });
  1349. } else {
  1350. this.form.workAction.getWorkcompletedAttachmentData(att.data.id, ((this.form.businessData.workCompleted) ? this.form.businessData.workCompleted.id : this.form.businessData.work.id));
  1351. }
  1352. }
  1353. }.bind(this));
  1354. }
  1355. //this.downloadAttachment(e, node, attachment);
  1356. },
  1357. getAttachmentUrl: function (attachment, callback) {
  1358. if (this.form.businessData.work && !this.form.businessData.work.completedTime) {
  1359. this.form.workAction.getAttachmentUrl(attachment.data.id, this.form.businessData.work.id, callback);
  1360. } else {
  1361. this.form.workAction.getAttachmentWorkcompletedUrl(attachment.data.id, this.form.businessData.workCompleted.id, callback);
  1362. }
  1363. },
  1364. createErrorNode: function (text) {
  1365. var node = new Element("div");
  1366. var iconNode = new Element("div", {
  1367. "styles": {
  1368. "width": "20px",
  1369. "height": "20px",
  1370. "float": "left",
  1371. "background": "url(" + "/x_component_process_Xform/$Form/default/icon/error.png) center center no-repeat"
  1372. }
  1373. }).inject(node);
  1374. var textNode = new Element("div", {
  1375. "styles": {
  1376. "line-height": "20px",
  1377. "margin-left": "20px",
  1378. "color": "red",
  1379. "word-break": "keep-all"
  1380. },
  1381. "text": text
  1382. }).inject(node);
  1383. return node;
  1384. },
  1385. notValidationMode: function (text) {
  1386. if (!this.isNotValidationMode) {
  1387. this.isNotValidationMode = true;
  1388. this.node.store("borderStyle", this.node.getStyles("border-left", "border-right", "border-top", "border-bottom"));
  1389. this.node.setStyle("border", "1px solid red");
  1390. this.errNode = this.createErrorNode(text).inject(this.node, "after");
  1391. this.showNotValidationMode(this.node);
  1392. }
  1393. },
  1394. showNotValidationMode: function (node) {
  1395. var p = node.getParent("div");
  1396. if (p) {
  1397. if (p.get("MWFtype") == "tab$Content") {
  1398. if (p.getParent("div").getStyle("display") == "none") {
  1399. var contentAreaNode = p.getParent("div").getParent("div");
  1400. var tabAreaNode = contentAreaNode.getPrevious("div");
  1401. var idx = contentAreaNode.getChildren().indexOf(p.getParent("div"));
  1402. var tabNode = tabAreaNode.getLast().getFirst().getChildren()[idx];
  1403. tabNode.click();
  1404. p = tabAreaNode.getParent("div");
  1405. }
  1406. }
  1407. this.showNotValidationMode(p);
  1408. }
  1409. },
  1410. validationMode: function () {
  1411. if (this.isNotValidationMode) {
  1412. this.isNotValidationMode = false;
  1413. this.node.setStyles(this.node.retrieve("borderStyle"));
  1414. if (this.errNode) {
  1415. this.errNode.destroy();
  1416. this.errNode = null;
  1417. }
  1418. }
  1419. },
  1420. validationConfigItem: function (routeName, data) {
  1421. var flag = (data.status == "all") ? true : (routeName == data.decision);
  1422. if (flag) {
  1423. var n = this.getData();
  1424. var v = (data.valueType == "value") ? n : n.length;
  1425. switch (data.operateor) {
  1426. case "isnull":
  1427. if (!v) {
  1428. this.notValidationMode(data.prompt);
  1429. return false;
  1430. }
  1431. break;
  1432. case "notnull":
  1433. if (v) {
  1434. this.notValidationMode(data.prompt);
  1435. return false;
  1436. }
  1437. break;
  1438. case "gt":
  1439. if (v > data.value) {
  1440. this.notValidationMode(data.prompt);
  1441. return false;
  1442. }
  1443. break;
  1444. case "lt":
  1445. if (v < data.value) {
  1446. this.notValidationMode(data.prompt);
  1447. return false;
  1448. }
  1449. break;
  1450. case "equal":
  1451. if (v == data.value) {
  1452. this.notValidationMode(data.prompt);
  1453. return false;
  1454. }
  1455. break;
  1456. case "neq":
  1457. if (v != data.value) {
  1458. this.notValidationMode(data.prompt);
  1459. return false;
  1460. }
  1461. break;
  1462. case "contain":
  1463. if (v.indexOf(data.value) != -1) {
  1464. this.notValidationMode(data.prompt);
  1465. return false;
  1466. }
  1467. break;
  1468. case "notcontain":
  1469. if (v.indexOf(data.value) == -1) {
  1470. this.notValidationMode(data.prompt);
  1471. return false;
  1472. }
  1473. break;
  1474. }
  1475. }
  1476. return true;
  1477. },
  1478. validationConfig: function (routeName, opinion) {
  1479. if (this.json.validationConfig) {
  1480. if (this.json.validationConfig.length) {
  1481. for (var i = 0; i < this.json.validationConfig.length; i++) {
  1482. var data = this.json.validationConfig[i];
  1483. if (!this.validationConfigItem(routeName, data)) return false;
  1484. }
  1485. }
  1486. return true;
  1487. }
  1488. return true;
  1489. },
  1490. validation: function (routeName, opinion) {
  1491. if (!this.validationConfig(routeName, opinion)) return false;
  1492. if (!this.json.validation) return true;
  1493. if (!this.json.validation.code) return true;
  1494. var flag = this.form.Macro.exec(this.json.validation.code, this);
  1495. if (!flag) flag = MWF.xApplication.process.Xform.LP.notValidation;
  1496. if (flag.toString() != "true") {
  1497. this.notValidationMode(flag);
  1498. return false;
  1499. }
  1500. return true;
  1501. }
  1502. });