Attachment.js 85 KB

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