Attachment.js 79 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721
  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. 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, function () {
  672. //刷新附件权限,以后要加一个刷新附件的功能
  673. o2.Actions.load("x_processplatform_assemble_surface").AttachmentAction.getWithWorkOrWorkCompleted(att.data.id, this.module.form.businessData.work.id, function (json) {
  674. debugger;
  675. var attachment = this.getAttachmentById( att.data.id );
  676. if( attachment ){
  677. attachment.data = json.data;
  678. if( attachment.deleteAction && !this.isAttDeleteAvailable(attachment) ){
  679. attachment.deleteAction.setStyle("display","none");
  680. }
  681. if( attachment.configAction && !this.isAttConfigAvailable(attachment) ){
  682. attachment.configAction.setStyle("display","none");
  683. }
  684. }
  685. }.bind(this))
  686. }.bind(this));
  687. }.bind(this));
  688. }
  689. },
  690. checkImageTex: function () {
  691. if (this.selectedAttachments.length && this.selectedAttachments.length == 1) {
  692. var att = this.selectedAttachments[0];
  693. var lp = MWF.xApplication.process.Xform.LP;
  694. var css = this.module.form.css;
  695. var node = new Element("div", { "styles": css.attachmentOCRNode }).inject(this.node);
  696. var previewNode = new Element("div", { "styles": css.attachmentOCRImageAreaNode }).inject(node);
  697. var imgNode = new Element("img", { "styles": css.attachmentOCRImageNode }).inject(previewNode);
  698. o2.Actions.get("x_processplatform_assemble_surface").getAttachmentUrl(att.data.id, this.module.form.businessData.work.id, function (url) {
  699. imgNode.set("src", o2.filterUrl(url));
  700. });
  701. var areaNode = new Element("div", { "styles": css.attachmentOCRInputAreaNode }).inject(node);
  702. var inputNode = new Element("textarea", { "styles": css.attachmentOCRInputNode }).inject(areaNode);
  703. var dlg = o2.DL.open({
  704. "title": lp.attachmentOCRTitle,
  705. "style": this.module.form.json.dialogStyle || "user",
  706. "isResize": false,
  707. "content": node,
  708. "buttonList": [
  709. {
  710. "type": "ok",
  711. "text": MWF.LP.process.button.ok,
  712. "action": function () {
  713. this.setAttachmentOCR(inputNode, att);
  714. dlg.close();
  715. }.bind(this)
  716. },
  717. {
  718. "type": "cancel",
  719. "text": MWF.LP.process.button.cancel,
  720. "action": function () { dlg.close(); }
  721. }
  722. ]
  723. });
  724. if (att.data.ocr) {
  725. inputNode.set("text", att.data.ocr.text || "");
  726. } else {
  727. o2.Actions.get("x_processplatform_assemble_surface").getAttachmentOCR(att.data.id, this.module.form.businessData.work.id, function (json) {
  728. att.data.ocr = json.data;
  729. inputNode.set("text", json.data.text || "");
  730. }.bind(this))
  731. }
  732. }
  733. },
  734. setAttachmentOCR: function (inputNode, att) {
  735. var data = inputNode.get("text");
  736. if (!att.data.ocr) att.data.ocr = {};
  737. att.data.ocr.text = data;
  738. o2.Actions.get("x_processplatform_assemble_surface").setAttachmentOCR(att.data.id, this.module.form.businessData.work.id, {
  739. "text": data
  740. }, function () {
  741. this.module.form.app.notice("success", lp.attachmentOCR_saved, this.node);
  742. }.bind(this));
  743. },
  744. checkMoveAction: function (item) {
  745. if (item) {
  746. var actionArea = item.getFirst().getNext();
  747. var actionup = actionArea.getFirst().show();
  748. var actiondown = actionArea.getLast().show();
  749. tmp = item.getPrevious();
  750. if (!tmp) actionup.hide();
  751. tmp = item.getNext();
  752. if (!tmp) actiondown.hide();
  753. }
  754. },
  755. orderAttachment: function () {
  756. if (this.attachments.length) {
  757. this.attachments = this.attachments.sort(function (a1, a2) {
  758. if (!a2.data.orderNumber) return 1;
  759. if (!a1.data.orderNumber) return -1;
  760. return a1.data.orderNumber - a2.data.orderNumber;
  761. }.bind(this));
  762. var lp = MWF.xApplication.process.Xform.LP;
  763. var css = this.module.form.css;
  764. var node = new Element("div", { "styles": css.attachmentOrderNode });
  765. var infoNode = new Element("div", { "styles": css.attachmentOrderInforNode, "text": lp.attachmentOrderInfo }).inject(node);
  766. var attrchmentsNode = new Element("div", { "styles": css.attachmentOrderAreaNode }).inject(node);
  767. var iconUrl = "../x_component_File/$Main/icon.json";
  768. var icons = null;
  769. o2.getJSON(iconUrl, function (json) {
  770. icons = json;
  771. }.bind(this), false, false);
  772. this.attachments.each(function (att, idx) {
  773. var iconName = icons[att.data.extension.toLowerCase()] || icons.unknow;
  774. var iconFolderUrl = "../x_component_File/$Main/default/file/" + iconName;
  775. var itemNode = new Element("div", { "styles": css.attachmentOrderItemNode }).inject(attrchmentsNode);
  776. itemNode.store("att", att);
  777. var icon = new Element("div", { "styles": css.attachmentOrderItemIconNode }).inject(itemNode);
  778. icon.setStyle("background-image", "url('" + iconFolderUrl + "')");
  779. var actionArea = new Element("div", { "styles": css.attachmentOrderItemActionNode }).inject(itemNode);
  780. var text = new Element("div", { "styles": css.attachmentOrderItemTextNode, "text": att.data.name }).inject(itemNode);
  781. var actionUp = new Element("div", { "styles": css.attachmentOrderItemActionUpNode, "text": lp.attachmentOrderUp }).inject(actionArea);
  782. var actionDown = new Element("div", { "styles": css.attachmentOrderItemActionDownNode, "text": lp.attachmentOrderDown }).inject(actionArea);
  783. if (idx == 0) actionUp.hide();
  784. if (idx == this.attachments.length - 1) actionDown.hide();
  785. actionUp.addEvent("click", function (e) {
  786. var itemNode = e.target.getParent().getParent();
  787. var upNode = itemNode.getPrevious();
  788. if (upNode) {
  789. itemNode.inject(upNode, "before");
  790. this.checkMoveAction(upNode);
  791. }
  792. this.checkMoveAction(itemNode);
  793. itemNode.highlight();
  794. //itemNode.setStyle("background-color", "#faf9f1");
  795. }.bind(this));
  796. actionDown.addEvent("click", function (e) {
  797. var itemNode = e.target.getParent().getParent();
  798. var downNode = itemNode.getNext();
  799. if (downNode) {
  800. itemNode.inject(downNode, "after");
  801. this.checkMoveAction(downNode);
  802. }
  803. this.checkMoveAction(itemNode);
  804. itemNode.highlight();
  805. // /itemNode.setStyle("background-color", "#faf9f1");
  806. }.bind(this));
  807. itemNode.addEvents({
  808. "mouseover": function (e) { this.setStyle("background-color", "#f1f6fa"); },
  809. "mouseout": function (e) { this.setStyle("background-color", "#ffffff"); }
  810. });
  811. //var droppables = attrchmentsNode.getChildren();
  812. new Drag(itemNode, {
  813. "handle": icon,
  814. "snap": 5,
  815. "stopPropagation": true,
  816. "preventDefault": true,
  817. onStart: function (el, e) {
  818. var itemNode = el;
  819. itemNode.setStyle("background-color", "#f1f6fa");
  820. var moveNode = itemNode.clone(true).setStyles(css.attachmentOrderItemNode).setStyles({
  821. "background-color": "#faf9f1",
  822. "opacity": 0.8,
  823. "border": "1px dotted #333333"
  824. }).inject(node);
  825. moveNode.position({
  826. "relativeTo": itemNode,
  827. "position": 'upperLeft',
  828. "edge": 'upperLeft'
  829. });
  830. moveNode.owner = itemNode;
  831. var move = new Drag.Move(moveNode, {
  832. "container": node,
  833. "droppables": attrchmentsNode.getChildren(),
  834. "onEnter": function (el, drop) {
  835. moveNode.flagNode = new Element("div", { "styles": css.attachmentOrderFlagNode }).inject(drop, "before");
  836. },
  837. "onLeave": function (el, drop) {
  838. if (moveNode.flagNode) moveNode.flagNode.destroy();
  839. },
  840. "onDrop": function (el, drop) {
  841. if (moveNode.flagNode) {
  842. moveNode.owner.inject(moveNode.flagNode, "after");
  843. moveNode.flagNode.destroy();
  844. moveNode.owner.highlight();
  845. this.checkMoveAction(moveNode.owner);
  846. this.checkMoveAction(drop);
  847. this.checkMoveAction(attrchmentsNode.getLast());
  848. moveNode.destroy()
  849. }
  850. }.bind(this)
  851. });
  852. move.start(e);
  853. }.bind(this),
  854. enter: function (el) {
  855. el.removeClass('dragging');
  856. }
  857. });
  858. //itemNode.dragMove
  859. }.bind(this));
  860. var dlg = o2.DL.open(Object.merge({
  861. "title": lp.attachmentOrderTitle,
  862. "style": this.module.form.json.dialogStyle || "user",
  863. "isResize": false,
  864. "content": node,
  865. "width": "auto",
  866. "height": "auto",
  867. "buttonList": [
  868. {
  869. "type": "ok",
  870. "text": MWF.LP.process.button.ok,
  871. "action": function () {
  872. this.sortAttachment(attrchmentsNode);
  873. dlg.close();
  874. }.bind(this)
  875. },
  876. {
  877. "type": "cancel",
  878. "text": MWF.LP.process.button.cancel,
  879. "action": function () { dlg.close(); }
  880. }
  881. ],
  882. "onPostLoad": function () {
  883. var dlg = this;
  884. dlg.node.setStyle("display", "block");
  885. var size = {};
  886. if (css.attachmentOrderNode) {
  887. if (parseFloat(css.attachmentOrderNode.width).toString() !== "NaN") {
  888. size.x = parseInt(css.attachmentOrderNode.width)
  889. }
  890. if (parseFloat(css.attachmentOrderNode.height).toString() !== "NaN") {
  891. size.y = parseInt(css.attachmentOrderNode.height)
  892. }
  893. }
  894. node.show();
  895. var nodeSize = node.getSize();
  896. dlg.content.setStyles({
  897. "width": size.x || nodeSize.x,
  898. "height": size.y || nodeSize.y
  899. });
  900. dlg.setContentSize();
  901. }
  902. }, (this.module.form.json.dialogOptions||{})));
  903. }
  904. },
  905. sortAttachment: function (node) {
  906. var nodes = node.getChildren();
  907. nodes.each(function (item, idx) {
  908. var att = item.retrieve("att", null);
  909. if (att) {
  910. att.data.orderNumber = idx;
  911. o2.Actions.load("x_processplatform_assemble_surface").AttachmentAction.changeOrderNumber(att.data.id, this.module.form.businessData.work.id, idx);
  912. }
  913. }.bind(this));
  914. this.attachments = this.attachments.sort(function (a1, a2) {
  915. if (!a2.data.orderNumber) return 1;
  916. if (!a1.data.orderNumber) return -1;
  917. return a1.data.orderNumber - a2.data.orderNumber;
  918. }.bind(this));
  919. this.reloadAttachments();
  920. this.fireEvent("order");
  921. }
  922. });
  923. MWF.xApplication.process.Xform.Attachment = MWF.APPAttachment = new Class({
  924. Extends: MWF.APP$Module,
  925. options: {
  926. "moduleEvents": ["upload", "delete", "afterDelete", "load", "change","download","open"]
  927. },
  928. initialize: function (node, json, form, options) {
  929. this.node = $(node);
  930. this.node.store("module", this);
  931. this.json = json;
  932. this.form = form;
  933. this.field = true;
  934. },
  935. _loadUserInterface: function () {
  936. this.node.empty();
  937. if (this.form.businessData.work.startTime){
  938. this.loadAttachmentController();
  939. this.fireEvent("load");
  940. }
  941. },
  942. loadAttachmentController: function () {
  943. //MWF.require("MWF.widget.AttachmentController", function() {
  944. var options = {
  945. "style": this.json.style || "default",
  946. "title": "附件区域",
  947. "listStyle": this.json.listStyle || "icon",
  948. "size": this.json.size || "max",
  949. "resize": (this.json.resize === "y" || this.json.resize === "true"),
  950. "attachmentCount": this.json.attachmentCount || 0,
  951. "isUpload": (this.json.isUpload === "y" || this.json.isUpload === "true"),
  952. "isDelete": (this.json.isDelete === "y" || this.json.isDelete === "true"),
  953. "isReplace": (this.json.isReplace === "y" || this.json.isReplace === "true"),
  954. "isDownload": (this.json.isDownload === "y" || this.json.isDownload === "true"),
  955. "isSizeChange": (this.json.isSizeChange === "y" || this.json.isSizeChange === "true"),
  956. "readonly": (this.json.readonly === "y" || this.json.readonly === "true"),
  957. "availableListStyles": this.json.availableListStyles ? this.json.availableListStyles : ["list", "seq", "icon", "preview"],
  958. "isDeleteOption": this.json.isDelete,
  959. "isReplaceOption": this.json.isReplace,
  960. "toolbarGroupHidden": this.json.toolbarGroupHidden || [],
  961. "onOrder": function () {
  962. this.fireEvent("change");
  963. }.bind(this)
  964. };
  965. if (this.readonly) options.readonly = true;
  966. if (this.form.json.attachmentStyle) {
  967. options = Object.merge(options, this.form.json.attachmentStyle);
  968. }
  969. //this.attachmentController = new MWF.widget.ATTER(this.node, this, options);
  970. this.attachmentController = new MWF.xApplication.process.Xform.AttachmentController(this.node, this, options);
  971. this.attachmentController.load();
  972. this.form.businessData.attachmentList.each(function (att) {
  973. //if (att.site===this.json.id || (this.json.isOpenInOffice && this.json.officeControlName===att.site)) this.attachmentController.addAttachment(att);
  974. if (att.site === this.json.id) this.attachmentController.addAttachment(att);
  975. }.bind(this));
  976. this.setAttachmentBusinessData();
  977. //}.bind(this));
  978. },
  979. setAttachmentBusinessData: function () {
  980. if (this.attachmentController) {
  981. if (this.attachmentController.attachments.length) {
  982. var values = this.attachmentController.attachments.map(function (d) {
  983. return d.data.name;
  984. });
  985. this._setBusinessData(values);
  986. } else {
  987. this._setBusinessData([]);
  988. }
  989. }
  990. },
  991. _loadEvents: function (editorConfig) {
  992. debugger;
  993. Object.each(this.json.events, function (e, key) {
  994. if (e.code) {
  995. if (this.options.moduleEvents.indexOf(key) !== -1) {
  996. this.addEvent(key, function (event) {
  997. return this.form.Macro.fire(e.code, this, event);
  998. }.bind(this));
  999. } else {
  1000. this.node.addEvent(key, function (event) {
  1001. return this.form.Macro.fire(e.code, this, event);
  1002. }.bind(this));
  1003. }
  1004. }
  1005. }.bind(this));
  1006. },
  1007. isEmpty : function(){
  1008. var data = this.getData();
  1009. if( typeOf(data) === "array" ){
  1010. return data.length == 0
  1011. }else{
  1012. return !data;
  1013. }
  1014. },
  1015. getData: function () {
  1016. return (this.attachmentController) ? this.attachmentController.getAttachmentNames() : null;
  1017. },
  1018. createUploadFileNode: function () {
  1019. var accept = "*";
  1020. if (!this.json.attachmentExtType || (this.json.attachmentExtType.indexOf("other") != -1 && !this.json.attachmentExtOtherType)) {
  1021. } else {
  1022. accepts = [];
  1023. var otherType = this.json.attachmentExtOtherType;
  1024. this.json.attachmentExtType.each(function (v) {
  1025. switch (v) {
  1026. case "word":
  1027. accepts.push(".doc, .docx, .dot, .dotx");
  1028. break;
  1029. case "excel":
  1030. accepts.push(".xls, .xlsx, .xlsm, .xlt, .xltx");
  1031. break;
  1032. case "ppt":
  1033. accepts.push(".pptx, .ppt, .pot, .potx, .potm");
  1034. break;
  1035. case "txt":
  1036. accepts.push(".txt");
  1037. break;
  1038. case "pic":
  1039. accepts.push(".bmp, .gif, .psd, .jpeg, .jpg, .png");
  1040. break;
  1041. case "pdf":
  1042. accepts.push(".pdf");
  1043. break;
  1044. case "zip":
  1045. accepts.push(".zip, .rar");
  1046. break;
  1047. case "audio":
  1048. accepts.push(".mp3, .wav, .wma, .wmv, .flac, .ape");
  1049. break;
  1050. case "video":
  1051. accepts.push(".avi, .mkv, .mov, .ogg, .mp4, .mpeg");
  1052. break;
  1053. case "other":
  1054. if (this.json.attachmentExtOtherType) accepts.push(this.json.attachmentExtOtherType);
  1055. break;
  1056. }
  1057. }.bind(this));
  1058. accept = accepts.join(", ");
  1059. }
  1060. var size = 0;
  1061. if (this.json.attachmentSize) size = this.json.attachmentSize.toFloat();
  1062. this.attachmentController.doUploadAttachment({ "site": this.json.id }, this.form.workAction.action, "uploadAttachment", { "id": this.form.businessData.work.id }, null, function (o) {
  1063. if (o.id) {
  1064. this.form.workAction.getAttachment(o.id, this.form.businessData.work.id, function (json) {
  1065. if (json.data) {
  1066. if (!json.data.control) json.data.control = {};
  1067. this.attachmentController.addAttachment(json.data, o.messageId);
  1068. }
  1069. this.attachmentController.checkActions();
  1070. this.setAttachmentBusinessData();
  1071. this.fireEvent("upload", [json.data]);
  1072. this.fireEvent("change");
  1073. }.bind(this))
  1074. }
  1075. this.attachmentController.checkActions();
  1076. }.bind(this), function (files) {
  1077. if (files.length) {
  1078. if ((files.length + this.attachmentController.attachments.length > this.attachmentController.options.attachmentCount) && this.attachmentController.options.attachmentCount > 0) {
  1079. var content = MWF.xApplication.process.Xform.LP.uploadMore;
  1080. content = content.replace("{n}", this.attachmentController.options.attachmentCount);
  1081. this.form.notice(content, "error");
  1082. return false;
  1083. }
  1084. }
  1085. return true;
  1086. }.bind(this), true, accept, size);
  1087. // this.uploadFileAreaNode = new Element("div");
  1088. // var html = "<input name=\"file\" type=\"file\" multiple/>";
  1089. // this.uploadFileAreaNode.set("html", html);
  1090. //
  1091. // this.fileUploadNode = this.uploadFileAreaNode.getFirst();
  1092. // this.fileUploadNode.addEvent("change", function(){
  1093. //
  1094. // var files = this.fileUploadNode.files;
  1095. // if (files.length){
  1096. // if ((files.length+this.attachmentController.attachments.length > this.attachmentController.options.attachmentCount) && this.attachmentController.options.attachmentCount>0){
  1097. // var content = MWF.xApplication.process.Xform.LP.uploadMore;
  1098. // content = content.replace("{n}", this.attachmentController.options.attachmentCount);
  1099. // this.form.notice(content, "error");
  1100. // }else{
  1101. // for (var i = 0; i < files.length; i++) {
  1102. // var file = files.item(i);
  1103. //
  1104. // var formData = new FormData();
  1105. // formData.append('site', this.json.id);
  1106. // formData.append('file', file);
  1107. //
  1108. // //formData.append('folder', folderId);
  1109. //
  1110. // this.form.workAction.uploadAttachment(this.form.businessData.work.id ,function(o, text){
  1111. // if (o.id){
  1112. // this.form.workAction.getAttachment(o.id, this.form.businessData.work.id, function(json){
  1113. // if (json.data) this.attachmentController.addAttachment(json.data);
  1114. // this.attachmentController.checkActions();
  1115. //
  1116. // this.fireEvent("upload", [json.data]);
  1117. // }.bind(this))
  1118. // }
  1119. // this.attachmentController.checkActions();
  1120. // }.bind(this), null, formData, file);
  1121. // }
  1122. // }
  1123. // }
  1124. // }.bind(this));
  1125. },
  1126. uploadAttachment: function (e, node) {
  1127. if (window.o2android && window.o2android.uploadAttachment) {
  1128. window.o2android.uploadAttachment(this.json.id);
  1129. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.uploadAttachment) {
  1130. window.webkit.messageHandlers.uploadAttachment.postMessage({ "site": this.json.id });
  1131. } else {
  1132. // if (!this.uploadFileAreaNode){
  1133. this.createUploadFileNode();
  1134. // }
  1135. // this.fileUploadNode.click();
  1136. }
  1137. },
  1138. deleteAttachments: function (e, node, attachments) {
  1139. var names = [];
  1140. attachments.each(function (attachment) {
  1141. names.push(attachment.data.name);
  1142. }.bind(this));
  1143. // if ((window.o2 && window.o2.replaceAttachment) || (window.webkit && window.webkit.messageHandlers)){
  1144. // if (window.confirm(MWF.xApplication.process.Xform.LP.deleteAttachment+"( "+names.join(", ")+" )")){
  1145. // while (attachments.length){
  1146. // attachment = attachments.shift();
  1147. // this.deleteAttachment(attachment);
  1148. // }
  1149. // }
  1150. // }else {
  1151. // var tmpNode = new Element("div", {
  1152. // "styles": {
  1153. // "background-color": "#0000ff",
  1154. // "border-style": "solid",
  1155. // "border-color": "#fff",
  1156. // "border-width": "1",
  1157. // "box-shadow": "0px 0px 20px #999",
  1158. // "z-index": "20000",
  1159. // "overflow": "hidden",
  1160. // "font-size": "14px",
  1161. // "height": "160px",
  1162. // "padding": "0px",
  1163. // "width": "300px",
  1164. // "position": "absolute",
  1165. // "top": "50px",
  1166. // "left": "20px",
  1167. // "opacity": 1,
  1168. // "border-radius": "5px"
  1169. // }
  1170. // }).inject(this.form.app.content);
  1171. var _self = this;
  1172. this.form.confirm("warn", e, MWF.xApplication.process.Xform.LP.deleteAttachmentTitle, MWF.xApplication.process.Xform.LP.deleteAttachment + "( " + names.join(", ") + " )", 300, 120, function () {
  1173. while (attachments.length) {
  1174. var attachment = attachments.shift();
  1175. _self.deleteAttachment(attachment);
  1176. }
  1177. this.close();
  1178. }, function () {
  1179. this.close();
  1180. }, null, null, this.form.json.confirmStyle);
  1181. },
  1182. deleteAttachment: function (attachment) {
  1183. this.fireEvent("delete", [attachment.data]);
  1184. var id = attachment.data.id;
  1185. this.form.workAction.deleteAttachment(attachment.data.id, this.form.businessData.work.id, function (josn) {
  1186. this.attachmentController.removeAttachment(attachment);
  1187. this.attachmentController.checkActions();
  1188. if (this.form.officeList) {
  1189. this.form.officeList.each(function (office) {
  1190. if (office.openedAttachment) {
  1191. if (office.openedAttachment.id == id) {
  1192. office.loadOfficeEdit();
  1193. }
  1194. }
  1195. }.bind(this));
  1196. }
  1197. this.setAttachmentBusinessData();
  1198. this.fireEvent("afterDelete", [attachment.data]);
  1199. this.fireEvent("change");
  1200. }.bind(this));
  1201. },
  1202. replaceAttachment: function (e, node, attachment) {
  1203. if (window.o2android && window.o2android.replaceAttachment) {
  1204. window.o2android.replaceAttachment(attachment.data.id, this.json.id);
  1205. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.replaceAttachment) {
  1206. window.webkit.messageHandlers.replaceAttachment.postMessage({ "id": attachment.data.id, "site": this.json.id });
  1207. } else {
  1208. var _self = this;
  1209. this.form.confirm("warn", e, MWF.xApplication.process.Xform.LP.replaceAttachmentTitle, MWF.xApplication.process.Xform.LP.replaceAttachment + "( " + attachment.data.name + " )", 350, 120, function () {
  1210. _self.replaceAttachmentFile(attachment);
  1211. this.close();
  1212. }, function () {
  1213. this.close();
  1214. }, null, null, this.form.json.confirmStyle);
  1215. }
  1216. },
  1217. createReplaceFileNode: function (attachment) {
  1218. var accept = "*";
  1219. if (!this.json.attachmentExtType || this.json.attachmentExtType.indexOf("other") != -1 && !this.json.attachmentExtOtherType) {
  1220. } else {
  1221. accepts = [];
  1222. var otherType = this.json.attachmentExtOtherType;
  1223. this.json.attachmentExtType.each(function (v) {
  1224. switch (v) {
  1225. case "word":
  1226. accepts.push(".doc, .docx, .dot, .dotx");
  1227. break;
  1228. case "excel":
  1229. accepts.push(".xls, .xlsx, .xlsm, .xlt, .xltx");
  1230. break;
  1231. case "ppt":
  1232. accepts.push(".pptx, .ppt, .pot, .potx, .potm");
  1233. break;
  1234. case "txt":
  1235. accepts.push(".txt");
  1236. break;
  1237. case "pic":
  1238. accepts.push(".bmp, .gif, .psd, .jpeg, .jpg");
  1239. break;
  1240. case "pdf":
  1241. accepts.push(".pdf");
  1242. break;
  1243. case "zip":
  1244. accepts.push(".zip, .rar");
  1245. break;
  1246. case "audio":
  1247. accepts.push(".mp3, .wav, .wma, .wmv, .flac, .ape");
  1248. break;
  1249. case "video":
  1250. accepts.push(".avi, .mkv, .mov, .ogg, .mp4, .mpeg");
  1251. break;
  1252. case "other":
  1253. if (this.json.attachmentExtOtherType) accepts.push(this.json.attachmentExtOtherType);
  1254. break;
  1255. }
  1256. });
  1257. accept = accepts.join(", ");
  1258. }
  1259. var size = 0;
  1260. if (this.json.attachmentSize) size = this.json.attachmentSize.toFloat();
  1261. this.attachmentController.doUploadAttachment({ "site": this.json.id }, this.form.workAction.action, "replaceAttachment",
  1262. { "id": attachment.data.id, "workid": this.form.businessData.work.id }, null, function (o) {
  1263. this.form.workAction.getAttachment(attachment.data.id, this.form.businessData.work.id, function (json) {
  1264. attachment.data = json.data;
  1265. attachment.reload();
  1266. this.attachmentController.checkActions();
  1267. }.bind(this))
  1268. }.bind(this), null, true, accept, size);
  1269. // this.replaceFileAreaNode = new Element("div");
  1270. // var html = "<input name=\"file\" type=\"file\" multiple/>";
  1271. // this.replaceFileAreaNode.set("html", html);
  1272. //
  1273. // this.fileReplaceNode = this.replaceFileAreaNode.getFirst();
  1274. // this.fileReplaceNode.addEvent("change", function(){
  1275. //
  1276. // var files = this.fileReplaceNode.files;
  1277. // if (files.length){
  1278. // for (var i = 0; i < files.length; i++) {
  1279. // var file = files.item(i);
  1280. //
  1281. // var formData = new FormData();
  1282. // formData.append('file', file);
  1283. // // formData.append('site', this.json.id);
  1284. //
  1285. // this.form.workAction.replaceAttachment(attachment.data.id, this.form.businessData.work.id ,function(o, text){
  1286. // this.form.workAction.getAttachment(attachment.data.id, this.form.businessData.work.id, function(json){
  1287. // attachment.data = json.data;
  1288. // attachment.reload();
  1289. // this.attachmentController.checkActions();
  1290. // }.bind(this))
  1291. // }.bind(this), null, formData, file);
  1292. // }
  1293. // }
  1294. // }.bind(this));
  1295. },
  1296. replaceAttachmentFile: function (attachment) {
  1297. //if (!this.replaceFileAreaNode){
  1298. this.createReplaceFileNode(attachment);
  1299. // }
  1300. // this.fileReplaceNode.click();
  1301. },
  1302. queryDownload : function( att ){
  1303. if( this.json.events && this.json.events.queryDownload && this.json.events.queryDownload.code ){
  1304. var flag = this.form.Macro.exec(this.json.events.queryDownload.code, att );
  1305. if( flag === false ){
  1306. return false
  1307. }else{
  1308. return true;
  1309. }
  1310. }else{
  1311. return true;
  1312. }
  1313. },
  1314. queryOpen : function( att ){
  1315. if( this.json.events && this.json.events.queryOpen && this.json.events.queryOpen.code ){
  1316. var flag = this.form.Macro.exec(this.json.events.queryOpen.code, att );
  1317. if( flag === false ){
  1318. return false
  1319. }else{
  1320. return true;
  1321. }
  1322. }else{
  1323. return true;
  1324. }
  1325. },
  1326. //小程序文件是否支持打开
  1327. checkMiniProgramFile: function(ext) {
  1328. var exts = ["doc", "docx", "xls", "xlsx", "ppt", "pptx", "pdf"];
  1329. for(var i = 0; i < exts.length; i++){
  1330. if(ext === exts[i]){
  1331. return true;
  1332. }
  1333. }
  1334. return false;
  1335. },
  1336. downloadAttachment: function (e, node, attachments) {
  1337. if (this.form.businessData.work && !this.form.businessData.work.completedTime) {
  1338. attachments.each(function (att) {
  1339. if( !this.queryDownload( att ) )return;
  1340. if (window.o2android && window.o2android.downloadAttachment) {
  1341. window.o2android.downloadAttachment(att.data.id);
  1342. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.downloadAttachment) {
  1343. window.webkit.messageHandlers.downloadAttachment.postMessage({ "id": att.data.id, "site": this.json.id });
  1344. } else if (window.wx && window.__wxjs_environment === 'miniprogram' && this.checkMiniProgramFile(att.data.extension)) { //微信小程序
  1345. wx.miniProgram.navigateTo({
  1346. url: '../file/download?attId=' + att.data.id + '&type=work&work=' + this.form.businessData.work.id
  1347. });
  1348. } else {
  1349. if (layout.mobile) {
  1350. //移动端 企业微信 钉钉 用本地打开 防止弹出自带浏览器 无权限问题
  1351. this.form.workAction.getAttachmentUrl(att.data.id, this.form.businessData.work.id, function (url) {
  1352. var xtoken = Cookie.read("x-token");
  1353. window.location = o2.filterUrl(url + "?x-token=" + xtoken);
  1354. });
  1355. } else {
  1356. this.form.workAction.getAttachmentStream(att.data.id, this.form.businessData.work.id);
  1357. }
  1358. }
  1359. this.fireEvent("download",[att])
  1360. }.bind(this));
  1361. } else {
  1362. attachments.each(function (att) {
  1363. if( !this.queryDownload( att ) )return;
  1364. if (window.o2android && window.o2android.downloadAttachment) {
  1365. window.o2android.downloadAttachment(att.data.id);
  1366. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.downloadAttachment) {
  1367. window.webkit.messageHandlers.downloadAttachment.postMessage({ "id": att.data.id, "site": this.json.id });
  1368. } else if (window.wx && window.__wxjs_environment === 'miniprogram' && this.checkMiniProgramFile(att.data.extension)) { //微信小程序
  1369. wx.miniProgram.navigateTo({
  1370. url: '../file/download?attId=' + att.data.id + '&type=work&workCompleted=' + this.form.businessData.workCompleted.id
  1371. });
  1372. } else {
  1373. if (layout.mobile) {
  1374. //移动端 企业微信 钉钉 用本地打开 防止弹出自带浏览器 无权限问题
  1375. this.form.workAction.getAttachmentWorkcompletedUrl(att.data.id, this.form.businessData.workCompleted.id, function (url) {
  1376. var xtoken = Cookie.read("x-token");
  1377. window.location = o2.filterUrl(url + "?x-token=" + xtoken);
  1378. });
  1379. } else {
  1380. this.form.workAction.getWorkcompletedAttachmentStream(att.data.id, this.form.businessData.workCompleted.id);
  1381. }
  1382. }
  1383. this.fireEvent("download",[att])
  1384. }.bind(this));
  1385. }
  1386. },
  1387. openAttachment: function (e, node, attachments) {
  1388. if (this.form.businessData.work && !this.form.businessData.work.completedTime) {
  1389. attachments.each(function (att) {
  1390. if( !this.queryOpen( att ) )return;
  1391. if (window.o2android && window.o2android.downloadAttachment) {
  1392. window.o2android.downloadAttachment(att.data.id);
  1393. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.downloadAttachment) {
  1394. window.webkit.messageHandlers.downloadAttachment.postMessage({ "id": att.data.id, "site": this.json.id });
  1395. } else if (window.wx && window.__wxjs_environment === 'miniprogram' && this.checkMiniProgramFile(att.data.extension)) { //微信小程序
  1396. wx.miniProgram.navigateTo({
  1397. url: '../file/download?attId=' + att.data.id + '&type=work&work=' + this.form.businessData.work.id
  1398. });
  1399. } else {
  1400. if (layout.mobile) {
  1401. //移动端 企业微信 钉钉 用本地打开 防止弹出自带浏览器 无权限问题
  1402. this.form.workAction.getAttachmentUrl(att.data.id, this.form.businessData.work.id, function (url) {
  1403. var xtoken = Cookie.read("x-token");
  1404. window.location = o2.filterUrl(url + "?x-token=" + xtoken);
  1405. });
  1406. } else {
  1407. this.form.workAction.getAttachmentData(att.data.id, this.form.businessData.work.id);
  1408. }
  1409. }
  1410. this.fireEvent("open",[att])
  1411. }.bind(this));
  1412. } else {
  1413. attachments.each(function (att) {
  1414. if( !this.queryOpen( att ) )return;
  1415. if (window.o2android && window.o2android.downloadAttachment) {
  1416. window.o2android.downloadAttachment(att.data.id);
  1417. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.downloadAttachment) {
  1418. window.webkit.messageHandlers.downloadAttachment.postMessage({ "id": att.data.id, "site": this.json.id });
  1419. } else if (window.wx && window.__wxjs_environment === 'miniprogram' && this.checkMiniProgramFile(att.data.extension)) { //微信小程序
  1420. wx.miniProgram.navigateTo({
  1421. url: '../file/download?attId=' + att.data.id + '&type=work&workCompleted=' + this.form.businessData.workCompleted.id
  1422. });
  1423. } else {
  1424. if (layout.mobile) {
  1425. //移动端 企业微信 钉钉 用本地打开 防止弹出自带浏览器 无权限问题
  1426. this.form.workAction.getAttachmentWorkcompletedUrl(att.data.id, ((this.form.businessData.workCompleted) ? this.form.businessData.workCompleted.id : this.form.businessData.work.id), function (url) {
  1427. var xtoken = Cookie.read("x-token");
  1428. window.location = o2.filterUrl(url + "?x-token=" + xtoken);
  1429. });
  1430. } else {
  1431. this.form.workAction.getWorkcompletedAttachmentData(att.data.id, ((this.form.businessData.workCompleted) ? this.form.businessData.workCompleted.id : this.form.businessData.work.id));
  1432. }
  1433. }
  1434. this.fireEvent("open",[att])
  1435. }.bind(this));
  1436. }
  1437. //this.downloadAttachment(e, node, attachment);
  1438. },
  1439. getAttachmentUrl: function (attachment, callback) {
  1440. if (this.form.businessData.work && !this.form.businessData.work.completedTime) {
  1441. this.form.workAction.getAttachmentUrl(attachment.data.id, this.form.businessData.work.id, callback);
  1442. } else {
  1443. this.form.workAction.getAttachmentWorkcompletedUrl(attachment.data.id, this.form.businessData.workCompleted.id, callback);
  1444. }
  1445. },
  1446. createErrorNode: function (text) {
  1447. var node = new Element("div");
  1448. var iconNode = new Element("div", {
  1449. "styles": {
  1450. "width": "20px",
  1451. "height": "20px",
  1452. "float": "left",
  1453. "background": "url(" + "../x_component_process_Xform/$Form/default/icon/error.png) center center no-repeat"
  1454. }
  1455. }).inject(node);
  1456. var textNode = new Element("div", {
  1457. "styles": {
  1458. "line-height": "20px",
  1459. "margin-left": "20px",
  1460. "color": "red",
  1461. "word-break": "keep-all"
  1462. },
  1463. "text": text
  1464. }).inject(node);
  1465. return node;
  1466. },
  1467. notValidationMode: function (text) {
  1468. if (!this.isNotValidationMode) {
  1469. this.isNotValidationMode = true;
  1470. this.node.store("borderStyle", this.node.getStyles("border-left", "border-right", "border-top", "border-bottom"));
  1471. this.node.setStyle("border", "1px solid red");
  1472. this.errNode = this.createErrorNode(text).inject(this.node, "after");
  1473. this.showNotValidationMode(this.node);
  1474. }
  1475. },
  1476. showNotValidationMode: function (node) {
  1477. var p = node.getParent("div");
  1478. if (p) {
  1479. if (p.get("MWFtype") == "tab$Content") {
  1480. if (p.getParent("div").getStyle("display") == "none") {
  1481. var contentAreaNode = p.getParent("div").getParent("div");
  1482. var tabAreaNode = contentAreaNode.getPrevious("div");
  1483. var idx = contentAreaNode.getChildren().indexOf(p.getParent("div"));
  1484. var tabNode = tabAreaNode.getLast().getFirst().getChildren()[idx];
  1485. tabNode.click();
  1486. p = tabAreaNode.getParent("div");
  1487. }
  1488. }
  1489. this.showNotValidationMode(p);
  1490. }
  1491. },
  1492. validationMode: function () {
  1493. if (this.isNotValidationMode) {
  1494. this.isNotValidationMode = false;
  1495. this.node.setStyles(this.node.retrieve("borderStyle"));
  1496. if (this.errNode) {
  1497. this.errNode.destroy();
  1498. this.errNode = null;
  1499. }
  1500. }
  1501. },
  1502. validationConfigItem: function (routeName, data) {
  1503. var flag = (data.status == "all") ? true : (routeName == data.decision);
  1504. if (flag) {
  1505. var n = this.getData();
  1506. var v = (data.valueType == "value") ? n : n.length;
  1507. switch (data.operateor) {
  1508. case "isnull":
  1509. if (!v) {
  1510. this.notValidationMode(data.prompt);
  1511. return false;
  1512. }
  1513. break;
  1514. case "notnull":
  1515. if (v) {
  1516. this.notValidationMode(data.prompt);
  1517. return false;
  1518. }
  1519. break;
  1520. case "gt":
  1521. if (v > data.value) {
  1522. this.notValidationMode(data.prompt);
  1523. return false;
  1524. }
  1525. break;
  1526. case "lt":
  1527. if (v < data.value) {
  1528. this.notValidationMode(data.prompt);
  1529. return false;
  1530. }
  1531. break;
  1532. case "equal":
  1533. if (v == data.value) {
  1534. this.notValidationMode(data.prompt);
  1535. return false;
  1536. }
  1537. break;
  1538. case "neq":
  1539. if (v != data.value) {
  1540. this.notValidationMode(data.prompt);
  1541. return false;
  1542. }
  1543. break;
  1544. case "contain":
  1545. if (v.indexOf(data.value) != -1) {
  1546. this.notValidationMode(data.prompt);
  1547. return false;
  1548. }
  1549. break;
  1550. case "notcontain":
  1551. if (v.indexOf(data.value) == -1) {
  1552. this.notValidationMode(data.prompt);
  1553. return false;
  1554. }
  1555. break;
  1556. }
  1557. }
  1558. return true;
  1559. },
  1560. validationConfig: function (routeName, opinion) {
  1561. if (this.json.validationConfig) {
  1562. if (this.json.validationConfig.length) {
  1563. for (var i = 0; i < this.json.validationConfig.length; i++) {
  1564. var data = this.json.validationConfig[i];
  1565. if (!this.validationConfigItem(routeName, data)) return false;
  1566. }
  1567. }
  1568. return true;
  1569. }
  1570. return true;
  1571. },
  1572. validation: function (routeName, opinion) {
  1573. if (!this.validationConfig(routeName, opinion)) return false;
  1574. if (!this.json.validation) return true;
  1575. if (!this.json.validation.code) return true;
  1576. this.currentRouteName = routeName;
  1577. var flag = this.form.Macro.exec(this.json.validation.code, this);
  1578. this.currentRouteName = "";
  1579. if (!flag) flag = MWF.xApplication.process.Xform.LP.notValidation;
  1580. if (flag.toString() != "true") {
  1581. this.notValidationMode(flag);
  1582. return false;
  1583. }
  1584. return true;
  1585. }
  1586. });