Attachment.js 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631
  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. this.loadAttachmentController();
  923. this.fireEvent("load");
  924. },
  925. loadAttachmentController: function () {
  926. //MWF.require("MWF.widget.AttachmentController", function() {
  927. var options = {
  928. "style": this.json.style || "default",
  929. "title": "附件区域",
  930. "listStyle": this.json.listStyle || "icon",
  931. "size": this.json.size || "max",
  932. "resize": (this.json.resize === "y" || this.json.resize === "true"),
  933. "attachmentCount": this.json.attachmentCount || 0,
  934. "isUpload": (this.json.isUpload === "y" || this.json.isUpload === "true"),
  935. "isDelete": (this.json.isDelete === "y" || this.json.isDelete === "true"),
  936. "isReplace": (this.json.isReplace === "y" || this.json.isReplace === "true"),
  937. "isDownload": (this.json.isDownload === "y" || this.json.isDownload === "true"),
  938. "isSizeChange": (this.json.isSizeChange === "y" || this.json.isSizeChange === "true"),
  939. "readonly": (this.json.readonly === "y" || this.json.readonly === "true"),
  940. "availableListStyles": this.json.availableListStyles ? this.json.availableListStyles : ["list", "seq", "icon", "preview"],
  941. "isDeleteOption": this.json.isDelete,
  942. "isReplaceOption": this.json.isReplace,
  943. "toolbarGroupHidden": this.json.toolbarGroupHidden || [],
  944. "onOrder": function () {
  945. this.fireEvent("change");
  946. }.bind(this)
  947. };
  948. if (this.readonly) options.readonly = true;
  949. if (this.form.json.attachmentStyle) {
  950. options = Object.merge(options, this.form.json.attachmentStyle);
  951. }
  952. //this.attachmentController = new MWF.widget.ATTER(this.node, this, options);
  953. this.attachmentController = new MWF.xApplication.process.Xform.AttachmentController(this.node, this, options);
  954. this.attachmentController.load();
  955. this.form.businessData.attachmentList.each(function (att) {
  956. //if (att.site===this.json.id || (this.json.isOpenInOffice && this.json.officeControlName===att.site)) this.attachmentController.addAttachment(att);
  957. if (att.site === this.json.id) this.attachmentController.addAttachment(att);
  958. }.bind(this));
  959. this.setAttachmentBusinessData();
  960. //}.bind(this));
  961. },
  962. setAttachmentBusinessData: function () {
  963. if (this.attachmentController) {
  964. if (this.attachmentController.attachments.length) {
  965. var values = this.attachmentController.attachments.map(function (d) {
  966. return d.data.name;
  967. });
  968. this._setBusinessData(values);
  969. } else {
  970. this._setBusinessData([]);
  971. }
  972. }
  973. },
  974. _loadEvents: function (editorConfig) {
  975. Object.each(this.json.events, function (e, key) {
  976. if (e.code) {
  977. if (this.options.moduleEvents.indexOf(key) !== -1) {
  978. this.addEvent(key, function (event) {
  979. return this.form.Macro.fire(e.code, this, event);
  980. }.bind(this));
  981. } else {
  982. this.node.addEvent(key, function (event) {
  983. return this.form.Macro.fire(e.code, this, event);
  984. }.bind(this));
  985. }
  986. }
  987. }.bind(this));
  988. },
  989. getData: function () {
  990. return this.attachmentController.getAttachmentNames();
  991. },
  992. createUploadFileNode: function () {
  993. var accept = "*";
  994. if (!this.json.attachmentExtType || (this.json.attachmentExtType.indexOf("other") != -1 && !this.json.attachmentExtOtherType)) {
  995. } else {
  996. accepts = [];
  997. var otherType = this.json.attachmentExtOtherType;
  998. this.json.attachmentExtType.each(function (v) {
  999. switch (v) {
  1000. case "word":
  1001. accepts.push(".doc, .docx, .dot, .dotx");
  1002. break;
  1003. case "excel":
  1004. accepts.push(".xls, .xlsx, .xlsm, .xlt, .xltx");
  1005. break;
  1006. case "ppt":
  1007. accepts.push(".pptx, .ppt, .pot, .potx, .potm");
  1008. break;
  1009. case "txt":
  1010. accepts.push(".txt");
  1011. break;
  1012. case "pic":
  1013. accepts.push(".bmp, .gif, .psd, .jpeg, .jpg, .png");
  1014. break;
  1015. case "pdf":
  1016. accepts.push(".pdf");
  1017. break;
  1018. case "zip":
  1019. accepts.push(".zip, .rar");
  1020. break;
  1021. case "audio":
  1022. accepts.push(".mp3, .wav, .wma, .wmv, .flac, .ape");
  1023. break;
  1024. case "video":
  1025. accepts.push(".avi, .mkv, .mov, .ogg, .mp4, .mpeg");
  1026. break;
  1027. case "other":
  1028. if (this.json.attachmentExtOtherType) accepts.push(this.json.attachmentExtOtherType);
  1029. break;
  1030. }
  1031. });
  1032. accept = accepts.join(", ");
  1033. }
  1034. var size = 0;
  1035. if (this.json.attachmentSize) size = this.json.attachmentSize.toFloat();
  1036. this.attachmentController.doUploadAttachment({ "site": this.json.id }, this.form.workAction.action, "uploadAttachment", { "id": this.form.businessData.work.id }, null, function (o) {
  1037. if (o.id) {
  1038. this.form.workAction.getAttachment(o.id, this.form.businessData.work.id, function (json) {
  1039. if (json.data) {
  1040. if (!json.data.control) json.data.control = {};
  1041. this.attachmentController.addAttachment(json.data);
  1042. }
  1043. this.attachmentController.checkActions();
  1044. this.setAttachmentBusinessData();
  1045. this.fireEvent("upload", [json.data]);
  1046. this.fireEvent("change");
  1047. }.bind(this))
  1048. }
  1049. this.attachmentController.checkActions();
  1050. }.bind(this), function (files) {
  1051. if (files.length) {
  1052. if ((files.length + this.attachmentController.attachments.length > this.attachmentController.options.attachmentCount) && this.attachmentController.options.attachmentCount > 0) {
  1053. var content = MWF.xApplication.process.Xform.LP.uploadMore;
  1054. content = content.replace("{n}", this.attachmentController.options.attachmentCount);
  1055. this.form.notice(content, "error");
  1056. return false;
  1057. }
  1058. }
  1059. return true;
  1060. }.bind(this), true, accept, size);
  1061. // this.uploadFileAreaNode = new Element("div");
  1062. // var html = "<input name=\"file\" type=\"file\" multiple/>";
  1063. // this.uploadFileAreaNode.set("html", html);
  1064. //
  1065. // this.fileUploadNode = this.uploadFileAreaNode.getFirst();
  1066. // this.fileUploadNode.addEvent("change", function(){
  1067. //
  1068. // var files = this.fileUploadNode.files;
  1069. // if (files.length){
  1070. // if ((files.length+this.attachmentController.attachments.length > this.attachmentController.options.attachmentCount) && this.attachmentController.options.attachmentCount>0){
  1071. // var content = MWF.xApplication.process.Xform.LP.uploadMore;
  1072. // content = content.replace("{n}", this.attachmentController.options.attachmentCount);
  1073. // this.form.notice(content, "error");
  1074. // }else{
  1075. // for (var i = 0; i < files.length; i++) {
  1076. // var file = files.item(i);
  1077. //
  1078. // var formData = new FormData();
  1079. // formData.append('site', this.json.id);
  1080. // formData.append('file', file);
  1081. //
  1082. // //formData.append('folder', folderId);
  1083. //
  1084. // this.form.workAction.uploadAttachment(this.form.businessData.work.id ,function(o, text){
  1085. // if (o.id){
  1086. // this.form.workAction.getAttachment(o.id, this.form.businessData.work.id, function(json){
  1087. // if (json.data) this.attachmentController.addAttachment(json.data);
  1088. // this.attachmentController.checkActions();
  1089. //
  1090. // this.fireEvent("upload", [json.data]);
  1091. // }.bind(this))
  1092. // }
  1093. // this.attachmentController.checkActions();
  1094. // }.bind(this), null, formData, file);
  1095. // }
  1096. // }
  1097. // }
  1098. // }.bind(this));
  1099. },
  1100. uploadAttachment: function (e, node) {
  1101. if (window.o2android && window.o2android.uploadAttachment) {
  1102. window.o2android.uploadAttachment(this.json.id);
  1103. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.uploadAttachment) {
  1104. window.webkit.messageHandlers.uploadAttachment.postMessage({ "site": this.json.id });
  1105. } else {
  1106. // if (!this.uploadFileAreaNode){
  1107. this.createUploadFileNode();
  1108. // }
  1109. // this.fileUploadNode.click();
  1110. }
  1111. },
  1112. deleteAttachments: function (e, node, attachments) {
  1113. var names = [];
  1114. attachments.each(function (attachment) {
  1115. names.push(attachment.data.name);
  1116. }.bind(this));
  1117. // if ((window.o2 && window.o2.replaceAttachment) || (window.webkit && window.webkit.messageHandlers)){
  1118. // if (window.confirm(MWF.xApplication.process.Xform.LP.deleteAttachment+"( "+names.join(", ")+" )")){
  1119. // while (attachments.length){
  1120. // attachment = attachments.shift();
  1121. // this.deleteAttachment(attachment);
  1122. // }
  1123. // }
  1124. // }else {
  1125. // var tmpNode = new Element("div", {
  1126. // "styles": {
  1127. // "background-color": "#0000ff",
  1128. // "border-style": "solid",
  1129. // "border-color": "#fff",
  1130. // "border-width": "1",
  1131. // "box-shadow": "0px 0px 20px #999",
  1132. // "z-index": "20000",
  1133. // "overflow": "hidden",
  1134. // "font-size": "14px",
  1135. // "height": "160px",
  1136. // "padding": "0px",
  1137. // "width": "300px",
  1138. // "position": "absolute",
  1139. // "top": "50px",
  1140. // "left": "20px",
  1141. // "opacity": 1,
  1142. // "border-radius": "5px"
  1143. // }
  1144. // }).inject(this.form.app.content);
  1145. var _self = this;
  1146. this.form.confirm("warn", e, MWF.xApplication.process.Xform.LP.deleteAttachmentTitle, MWF.xApplication.process.Xform.LP.deleteAttachment + "( " + names.join(", ") + " )", 300, 120, function () {
  1147. while (attachments.length) {
  1148. var attachment = attachments.shift();
  1149. _self.deleteAttachment(attachment);
  1150. }
  1151. this.close();
  1152. }, function () {
  1153. this.close();
  1154. }, null, null, this.form.json.confirmStyle);
  1155. },
  1156. deleteAttachment: function (attachment) {
  1157. this.fireEvent("delete", [attachment.data]);
  1158. var id = attachment.data.id;
  1159. this.form.workAction.deleteAttachment(attachment.data.id, this.form.businessData.work.id, function (josn) {
  1160. this.attachmentController.removeAttachment(attachment);
  1161. this.attachmentController.checkActions();
  1162. if (this.form.officeList) {
  1163. this.form.officeList.each(function (office) {
  1164. if (office.openedAttachment) {
  1165. if (office.openedAttachment.id == id) {
  1166. office.loadOfficeEdit();
  1167. }
  1168. }
  1169. }.bind(this));
  1170. }
  1171. this.setAttachmentBusinessData();
  1172. this.fireEvent("afterDelete", [attachment.data]);
  1173. this.fireEvent("change");
  1174. }.bind(this));
  1175. },
  1176. replaceAttachment: function (e, node, attachment) {
  1177. if (window.o2android && window.o2android.replaceAttachment) {
  1178. window.o2android.replaceAttachment(attachment.data.id, this.json.id);
  1179. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.replaceAttachment) {
  1180. window.webkit.messageHandlers.replaceAttachment.postMessage({ "id": attachment.data.id, "site": this.json.id });
  1181. } else {
  1182. var _self = this;
  1183. this.form.confirm("warn", e, MWF.xApplication.process.Xform.LP.replaceAttachmentTitle, MWF.xApplication.process.Xform.LP.replaceAttachment + "( " + attachment.data.name + " )", 350, 120, function () {
  1184. _self.replaceAttachmentFile(attachment);
  1185. this.close();
  1186. }, function () {
  1187. this.close();
  1188. }, null, null, this.form.json.confirmStyle);
  1189. }
  1190. },
  1191. createReplaceFileNode: function (attachment) {
  1192. var accept = "*";
  1193. if (!this.json.attachmentExtType || this.json.attachmentExtType.indexOf("other") != -1 && !this.json.attachmentExtOtherType) {
  1194. } else {
  1195. accepts = [];
  1196. var otherType = this.json.attachmentExtOtherType;
  1197. this.json.attachmentExtType.each(function (v) {
  1198. switch (v) {
  1199. case "word":
  1200. accepts.push(".doc, .docx, .dot, .dotx");
  1201. break;
  1202. case "excel":
  1203. accepts.push(".xls, .xlsx, .xlsm, .xlt, .xltx");
  1204. break;
  1205. case "ppt":
  1206. accepts.push(".pptx, .ppt, .pot, .potx, .potm");
  1207. break;
  1208. case "txt":
  1209. accepts.push(".txt");
  1210. break;
  1211. case "pic":
  1212. accepts.push(".bmp, .gif, .psd, .jpeg, .jpg");
  1213. break;
  1214. case "pdf":
  1215. accepts.push(".pdf");
  1216. break;
  1217. case "zip":
  1218. accepts.push(".zip, .rar");
  1219. break;
  1220. case "audio":
  1221. accepts.push(".mp3, .wav, .wma, .wmv, .flac, .ape");
  1222. break;
  1223. case "video":
  1224. accepts.push(".avi, .mkv, .mov, .ogg, .mp4, .mpeg");
  1225. break;
  1226. case "other":
  1227. if (this.json.attachmentExtOtherType) accepts.push(this.json.attachmentExtOtherType);
  1228. break;
  1229. }
  1230. });
  1231. accept = accepts.join(", ");
  1232. }
  1233. var size = 0;
  1234. if (this.json.attachmentSize) size = this.json.attachmentSize.toFloat();
  1235. this.attachmentController.doUploadAttachment({ "site": this.json.id }, this.form.workAction.action, "replaceAttachment",
  1236. { "id": attachment.data.id, "workid": this.form.businessData.work.id }, null, function (o) {
  1237. this.form.workAction.getAttachment(attachment.data.id, this.form.businessData.work.id, function (json) {
  1238. attachment.data = json.data;
  1239. attachment.reload();
  1240. this.attachmentController.checkActions();
  1241. }.bind(this))
  1242. }.bind(this), null, true, accept, size);
  1243. // this.replaceFileAreaNode = new Element("div");
  1244. // var html = "<input name=\"file\" type=\"file\" multiple/>";
  1245. // this.replaceFileAreaNode.set("html", html);
  1246. //
  1247. // this.fileReplaceNode = this.replaceFileAreaNode.getFirst();
  1248. // this.fileReplaceNode.addEvent("change", function(){
  1249. //
  1250. // var files = this.fileReplaceNode.files;
  1251. // if (files.length){
  1252. // for (var i = 0; i < files.length; i++) {
  1253. // var file = files.item(i);
  1254. //
  1255. // var formData = new FormData();
  1256. // formData.append('file', file);
  1257. // // formData.append('site', this.json.id);
  1258. //
  1259. // this.form.workAction.replaceAttachment(attachment.data.id, this.form.businessData.work.id ,function(o, text){
  1260. // this.form.workAction.getAttachment(attachment.data.id, this.form.businessData.work.id, function(json){
  1261. // attachment.data = json.data;
  1262. // attachment.reload();
  1263. // this.attachmentController.checkActions();
  1264. // }.bind(this))
  1265. // }.bind(this), null, formData, file);
  1266. // }
  1267. // }
  1268. // }.bind(this));
  1269. },
  1270. replaceAttachmentFile: function (attachment) {
  1271. //if (!this.replaceFileAreaNode){
  1272. this.createReplaceFileNode(attachment);
  1273. // }
  1274. // this.fileReplaceNode.click();
  1275. },
  1276. downloadAttachment: function (e, node, attachments) {
  1277. if (this.form.businessData.work && !this.form.businessData.work.completedTime) {
  1278. attachments.each(function (att) {
  1279. if (window.o2android && window.o2android.downloadAttachment) {
  1280. window.o2android.downloadAttachment(att.data.id);
  1281. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.downloadAttachment) {
  1282. window.webkit.messageHandlers.downloadAttachment.postMessage({ "id": att.data.id, "site": this.json.id });
  1283. } else {
  1284. if (layout.mobile) {
  1285. //移动端 企业微信 钉钉 用本地打开 防止弹出自带浏览器 无权限问题
  1286. this.form.workAction.getAttachmentUrl(att.data.id, this.form.businessData.work.id, function (url) {
  1287. var xtoken = Cookie.read("x-token");
  1288. window.location = url + "?x-token=" + xtoken;
  1289. });
  1290. } else {
  1291. this.form.workAction.getAttachmentStream(att.data.id, this.form.businessData.work.id);
  1292. }
  1293. }
  1294. }.bind(this));
  1295. } else {
  1296. attachments.each(function (att) {
  1297. if (window.o2android && window.o2android.downloadAttachment) {
  1298. window.o2android.downloadAttachment(att.data.id);
  1299. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.downloadAttachment) {
  1300. window.webkit.messageHandlers.downloadAttachment.postMessage({ "id": att.data.id, "site": this.json.id });
  1301. } else {
  1302. if (layout.mobile) {
  1303. //移动端 企业微信 钉钉 用本地打开 防止弹出自带浏览器 无权限问题
  1304. this.form.workAction.getAttachmentWorkcompletedUrl(att.data.id, this.form.businessData.workCompleted.id, function (url) {
  1305. var xtoken = Cookie.read("x-token");
  1306. window.location = url + "?x-token=" + xtoken;
  1307. });
  1308. } else {
  1309. this.form.workAction.getWorkcompletedAttachmentStream(att.data.id, this.form.businessData.workCompleted.id);
  1310. }
  1311. }
  1312. }.bind(this));
  1313. }
  1314. },
  1315. openAttachment: function (e, node, attachments) {
  1316. if (this.form.businessData.work && !this.form.businessData.work.completedTime) {
  1317. attachments.each(function (att) {
  1318. if (window.o2android && window.o2android.downloadAttachment) {
  1319. window.o2android.downloadAttachment(att.data.id);
  1320. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.downloadAttachment) {
  1321. window.webkit.messageHandlers.downloadAttachment.postMessage({ "id": att.data.id, "site": this.json.id });
  1322. } else {
  1323. if (layout.mobile) {
  1324. //移动端 企业微信 钉钉 用本地打开 防止弹出自带浏览器 无权限问题
  1325. this.form.workAction.getAttachmentUrl(att.data.id, this.form.businessData.work.id, function (url) {
  1326. var xtoken = Cookie.read("x-token");
  1327. window.location = url + "?x-token=" + xtoken;
  1328. });
  1329. } else {
  1330. this.form.workAction.getAttachmentData(att.data.id, this.form.businessData.work.id);
  1331. }
  1332. }
  1333. }.bind(this));
  1334. } else {
  1335. attachments.each(function (att) {
  1336. if (window.o2android && window.o2android.downloadAttachment) {
  1337. window.o2android.downloadAttachment(att.data.id);
  1338. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.downloadAttachment) {
  1339. window.webkit.messageHandlers.downloadAttachment.postMessage(att.data.id, this.json.id);
  1340. } else {
  1341. if (layout.mobile) {
  1342. //移动端 企业微信 钉钉 用本地打开 防止弹出自带浏览器 无权限问题
  1343. this.form.workAction.getAttachmentWorkcompletedUrl(att.data.id, ((this.form.businessData.workCompleted) ? this.form.businessData.workCompleted.id : this.form.businessData.work.id), function (url) {
  1344. var xtoken = Cookie.read("x-token");
  1345. window.location = url + "?x-token=" + xtoken;
  1346. });
  1347. } else {
  1348. this.form.workAction.getWorkcompletedAttachmentData(att.data.id, ((this.form.businessData.workCompleted) ? this.form.businessData.workCompleted.id : this.form.businessData.work.id));
  1349. }
  1350. }
  1351. }.bind(this));
  1352. }
  1353. //this.downloadAttachment(e, node, attachment);
  1354. },
  1355. getAttachmentUrl: function (attachment, callback) {
  1356. if (this.form.businessData.work && !this.form.businessData.work.completedTime) {
  1357. this.form.workAction.getAttachmentUrl(attachment.data.id, this.form.businessData.work.id, callback);
  1358. } else {
  1359. this.form.workAction.getAttachmentWorkcompletedUrl(attachment.data.id, this.form.businessData.workCompleted.id, callback);
  1360. }
  1361. },
  1362. createErrorNode: function (text) {
  1363. var node = new Element("div");
  1364. var iconNode = new Element("div", {
  1365. "styles": {
  1366. "width": "20px",
  1367. "height": "20px",
  1368. "float": "left",
  1369. "background": "url(" + "/x_component_process_Xform/$Form/default/icon/error.png) center center no-repeat"
  1370. }
  1371. }).inject(node);
  1372. var textNode = new Element("div", {
  1373. "styles": {
  1374. "line-height": "20px",
  1375. "margin-left": "20px",
  1376. "color": "red",
  1377. "word-break": "keep-all"
  1378. },
  1379. "text": text
  1380. }).inject(node);
  1381. return node;
  1382. },
  1383. notValidationMode: function (text) {
  1384. if (!this.isNotValidationMode) {
  1385. this.isNotValidationMode = true;
  1386. this.node.store("borderStyle", this.node.getStyles("border-left", "border-right", "border-top", "border-bottom"));
  1387. this.node.setStyle("border", "1px solid red");
  1388. this.errNode = this.createErrorNode(text).inject(this.node, "after");
  1389. this.showNotValidationMode(this.node);
  1390. }
  1391. },
  1392. showNotValidationMode: function (node) {
  1393. var p = node.getParent("div");
  1394. if (p) {
  1395. if (p.get("MWFtype") == "tab$Content") {
  1396. if (p.getParent("div").getStyle("display") == "none") {
  1397. var contentAreaNode = p.getParent("div").getParent("div");
  1398. var tabAreaNode = contentAreaNode.getPrevious("div");
  1399. var idx = contentAreaNode.getChildren().indexOf(p.getParent("div"));
  1400. var tabNode = tabAreaNode.getLast().getFirst().getChildren()[idx];
  1401. tabNode.click();
  1402. p = tabAreaNode.getParent("div");
  1403. }
  1404. }
  1405. this.showNotValidationMode(p);
  1406. }
  1407. },
  1408. validationMode: function () {
  1409. if (this.isNotValidationMode) {
  1410. this.isNotValidationMode = false;
  1411. this.node.setStyles(this.node.retrieve("borderStyle"));
  1412. if (this.errNode) {
  1413. this.errNode.destroy();
  1414. this.errNode = null;
  1415. }
  1416. }
  1417. },
  1418. validationConfigItem: function (routeName, data) {
  1419. var flag = (data.status == "all") ? true : (routeName == data.decision);
  1420. if (flag) {
  1421. var n = this.getData();
  1422. var v = (data.valueType == "value") ? n : n.length;
  1423. switch (data.operateor) {
  1424. case "isnull":
  1425. if (!v) {
  1426. this.notValidationMode(data.prompt);
  1427. return false;
  1428. }
  1429. break;
  1430. case "notnull":
  1431. if (v) {
  1432. this.notValidationMode(data.prompt);
  1433. return false;
  1434. }
  1435. break;
  1436. case "gt":
  1437. if (v > data.value) {
  1438. this.notValidationMode(data.prompt);
  1439. return false;
  1440. }
  1441. break;
  1442. case "lt":
  1443. if (v < data.value) {
  1444. this.notValidationMode(data.prompt);
  1445. return false;
  1446. }
  1447. break;
  1448. case "equal":
  1449. if (v == data.value) {
  1450. this.notValidationMode(data.prompt);
  1451. return false;
  1452. }
  1453. break;
  1454. case "neq":
  1455. if (v != data.value) {
  1456. this.notValidationMode(data.prompt);
  1457. return false;
  1458. }
  1459. break;
  1460. case "contain":
  1461. if (v.indexOf(data.value) != -1) {
  1462. this.notValidationMode(data.prompt);
  1463. return false;
  1464. }
  1465. break;
  1466. case "notcontain":
  1467. if (v.indexOf(data.value) == -1) {
  1468. this.notValidationMode(data.prompt);
  1469. return false;
  1470. }
  1471. break;
  1472. }
  1473. }
  1474. return true;
  1475. },
  1476. validationConfig: function (routeName, opinion) {
  1477. if (this.json.validationConfig) {
  1478. if (this.json.validationConfig.length) {
  1479. for (var i = 0; i < this.json.validationConfig.length; i++) {
  1480. var data = this.json.validationConfig[i];
  1481. if (!this.validationConfigItem(routeName, data)) return false;
  1482. }
  1483. }
  1484. return true;
  1485. }
  1486. return true;
  1487. },
  1488. validation: function (routeName, opinion) {
  1489. if (!this.validationConfig(routeName, opinion)) return false;
  1490. if (!this.json.validation) return true;
  1491. if (!this.json.validation.code) return true;
  1492. var flag = this.form.Macro.exec(this.json.validation.code, this);
  1493. if (!flag) flag = MWF.xApplication.process.Xform.LP.notValidation;
  1494. if (flag.toString() != "true") {
  1495. this.notValidationMode(flag);
  1496. return false;
  1497. }
  1498. return true;
  1499. }
  1500. });