Attachment.js 90 KB

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