Attachment.js 90 KB

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