Attachment.js 135 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172
  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. "allowPreviewExtension" : ["zip","pdf", "ofd", "png", "jpg", "bmp", "jpeg", "gif", "js", "css", "java", "json", "xml", "php", "html", "htm", "xhtml", "log", "md", "txt"],
  8. "checkTextEnable": true
  9. },
  10. checkAttControl: function(att, currentUser){
  11. var attUser = att.data.person || att.data.creatorUid;
  12. switch (this.options.isDeleteOption){
  13. case "o":
  14. return attUser===currentUser;
  15. case "a":
  16. return att.data.activity===this.module.form.businessData.activity.id;
  17. case "ao":
  18. return (attUser===currentUser || att.data.activity===this.module.form.businessData.activity.id);
  19. default:
  20. return true;
  21. }
  22. },
  23. checkAttachmentDeleteAction: function () {
  24. if (this.options.readonly || this.options.isDeleteOption==="n" || this.options.isDeleteOption==="hidden" || !this.attachments.length) {
  25. this.setAttachmentsAction("delete", false);
  26. return false;
  27. }
  28. var currentUser = layout.session.user.distinguishedName;
  29. for (var i = 0; i < this.attachments.length; i++) {
  30. var att = this.attachments[i];
  31. this.setAttachmentAction(att, "delete", (att.data.control.allowEdit && this.checkAttControl(att, currentUser)));
  32. }
  33. },
  34. checkDeleteAction: function () {
  35. this.checkAttachmentDeleteAction();
  36. if (this.options.readonly) {
  37. if (this.options.isDeleteOption === "hidden") {
  38. this.setActionHidden(this.deleteAction);
  39. this.setActionHidden(this.min_deleteAction);
  40. } else {
  41. this.setActionDisabled(this.deleteAction);
  42. this.setActionDisabled(this.min_deleteAction);
  43. }
  44. return false;
  45. }
  46. if (this.options.isDeleteOption === "hidden") {
  47. this.setActionHidden(this.deleteAction);
  48. this.setActionHidden(this.min_deleteAction);
  49. }else if( this.options.isDeleteOption === "n" ){
  50. this.setActionDisabled(this.deleteAction);
  51. this.setActionDisabled(this.min_deleteAction);
  52. } else {
  53. if (this.selectedAttachments.length) {
  54. var user = layout.session.user.distinguishedName;
  55. var flag = true;
  56. if (this.options.isDeleteOption === "o") {
  57. for (var i = 0; i < this.selectedAttachments.length; i++) {
  58. var att = this.selectedAttachments[i];
  59. if (!att.data.person && att.data.creatorUid) att.data.person = att.data.creatorUid;
  60. if (!att.data.control.allowEdit && att.data.person !== user) {
  61. flag = false;
  62. break;
  63. }
  64. if (att.data.person !== layout.desktop.session.user.distinguishedName) {
  65. flag = false;
  66. break;
  67. }
  68. }
  69. } else if (this.options.isDeleteOption === "a") {
  70. for (var i = 0; i < this.selectedAttachments.length; i++) {
  71. var att = this.selectedAttachments[i];
  72. if (!att.data.person && att.data.creatorUid) att.data.person = att.data.creatorUid;
  73. if (!att.data.control.allowEdit && att.data.person !== user) {
  74. flag = false;
  75. break;
  76. }
  77. if (att.data.activity !== this.module.form.businessData.activity.id) {
  78. flag = false;
  79. break;
  80. }
  81. }
  82. } else if (this.options.isDeleteOption === "ao") {
  83. for (var i = 0; i < this.selectedAttachments.length; i++) {
  84. var att = this.selectedAttachments[i];
  85. if (!att.data.person && att.data.creatorUid) att.data.person = att.data.creatorUid;
  86. if (!att.data.control.allowEdit && att.data.person !== user) {
  87. flag = false;
  88. break;
  89. }
  90. if ((att.data.activity !== this.module.form.businessData.activity.id) || (att.data.person !== layout.desktop.session.user.distinguishedName)) {
  91. flag = false;
  92. break;
  93. }
  94. }
  95. } else {
  96. for (var i = 0; i < this.selectedAttachments.length; i++) {
  97. var att = this.selectedAttachments[i];
  98. if (!att.data.person && att.data.creatorUid) att.data.person = att.data.creatorUid;
  99. if (!att.data.control.allowEdit && att.data.person !== user) {
  100. flag = false;
  101. break;
  102. }
  103. }
  104. }
  105. if (flag) {
  106. this.setActionEnabled(this.deleteAction);
  107. this.setActionEnabled(this.min_deleteAction);
  108. } else {
  109. this.setActionDisabled(this.deleteAction);
  110. this.setActionDisabled(this.min_deleteAction);
  111. }
  112. } else {
  113. this.setActionDisabled(this.deleteAction);
  114. this.setActionDisabled(this.min_deleteAction);
  115. }
  116. }
  117. // else {
  118. // // if (!this.options.isDelete){
  119. // this.setActionDisabled(this.deleteAction);
  120. // this.setActionDisabled(this.min_deleteAction);
  121. // // }else{
  122. // // if (this.selectedAttachments.length){
  123. // // this.setActionEnabled(this.deleteAction);
  124. // // this.setActionEnabled(this.min_deleteAction);
  125. // // }else{
  126. // // this.setActionDisabled(this.deleteAction);
  127. // // this.setActionDisabled(this.min_deleteAction);
  128. // // }
  129. // // }
  130. // }
  131. },
  132. checkDownloadBatchAction: function(){
  133. if( this.options.isDownloadBatch === "hidden" ){
  134. this.setActionHidden(this.downloadBatchAction);
  135. this.setActionHidden(this.min_downloadBatchAction);
  136. this.setAttachmentsAction("downloadBatch", false );
  137. }else if (!this.options.isDownloadBatch){
  138. this.setActionDisabled(this.downloadBatchAction);
  139. this.setActionDisabled(this.min_downloadBatchAction);
  140. this.setAttachmentsAction("downloadBatch", false );
  141. }else{
  142. this.setActionEnabled(this.downloadBatchAction);
  143. this.setActionEnabled(this.min_downloadBatchAction);
  144. this.setAttachmentsAction("downloadBatch", true );
  145. }
  146. },
  147. checkEditAttAction: function () {
  148. if(layout.mobile){
  149. this.setActionDisabled(this.editAttAction);
  150. this.setActionDisabled(this.min_editAttAction);
  151. } else if (this.options.isEditAtt === "hidden" ){
  152. this.setActionHidden(this.editAttAction);
  153. this.setActionHidden(this.min_editAttAction);
  154. } else if (!this.options.isEditAtt || this.options.readonly){
  155. this.setActionDisabled(this.editAttAction);
  156. this.setActionDisabled(this.min_editAttAction);
  157. }else{
  158. if (this.selectedAttachments.length){
  159. var flag = false;
  160. for (var i = 0; i < this.selectedAttachments.length; i++) {
  161. var att = this.selectedAttachments[i];
  162. if (["doc","docx","xls","xlsx","ppt","pptx"].contains(att.data.extension)) {
  163. flag = true;
  164. break;
  165. }
  166. }
  167. if(flag){
  168. this.setActionEnabled(this.editAttAction);
  169. this.setActionEnabled(this.min_editAttAction);
  170. }
  171. }else{
  172. this.setActionDisabled(this.editAttAction);
  173. this.setActionDisabled(this.min_editAttAction);
  174. }
  175. }
  176. },
  177. checkPreviewAttAction: function () {
  178. // if(layout.mobile){
  179. // this.setActionDisabled(this.previewAttAction);
  180. // this.setActionDisabled(this.min_previewAttAction);
  181. // } else
  182. if (this.options.isPreviewAtt === "hidden" ){
  183. this.setActionHidden(this.previewAttAction);
  184. this.setActionHidden(this.min_previewAttAction);
  185. } else if (!this.options.isPreviewAtt){
  186. this.setActionDisabled(this.previewAttAction);
  187. this.setActionDisabled(this.min_previewAttAction);
  188. }else{
  189. if (this.selectedAttachments.length){
  190. var flag = false;
  191. for (var i = 0; i < this.selectedAttachments.length; i++) {
  192. var att = this.selectedAttachments[i];
  193. if (this.options.allowPreviewExtension.contains(att.data.extension)) {
  194. flag = true;
  195. break;
  196. }
  197. if (["doc","docx","xls","xlsx","ppt","pptx"].contains(att.data.extension)) {
  198. flag = true;
  199. break;
  200. }
  201. }
  202. if(flag){
  203. this.setActionEnabled(this.previewAttAction);
  204. this.setActionEnabled(this.min_previewAttAction);
  205. //this.setActionEnabled(this.min_downloadAction);
  206. }
  207. }else{
  208. this.setActionDisabled(this.previewAttAction);
  209. this.setActionDisabled(this.min_previewAttAction);
  210. }
  211. }
  212. },
  213. isAttDeleteAvailable: function (att) {
  214. if (this.options.readonly) return false;
  215. if (this.options.toolbarGroupHidden.contains("edit")) return false;
  216. if (this.options.isDeleteOption === "n" || this.options.isDeleteOption === "hidden") return false;
  217. var user = layout.session.user.distinguishedName;
  218. var flag = true;
  219. if (!att.data.person && att.data.creatorUid) att.data.person = att.data.creatorUid;
  220. if (this.options.isDeleteOption === "o") {
  221. if (!att.data.control.allowEdit && att.data.person !== user) flag = false;
  222. if (att.data.person !== layout.desktop.session.user.distinguishedName) flag = false;
  223. } else if (this.options.isDeleteOption === "a") {
  224. if (!att.data.control.allowEdit && att.data.person !== user) flag = false;
  225. if (att.data.activity !== this.module.form.businessData.activity.id) flag = false;
  226. } else if (this.options.isDeleteOption === "ao") {
  227. if (!att.data.control.allowEdit && att.data.person !== user) flag = false;
  228. if ((att.data.activity !== this.module.form.businessData.activity.id) || (att.data.person !== layout.desktop.session.user.distinguishedName)) flag = false;
  229. } else {
  230. if (!att.data.control.allowEdit && att.data.person !== user) flag = false;
  231. }
  232. return flag;
  233. },
  234. openInOfficeControl: function (att, office) {
  235. if (office) {
  236. if (!office.openedAttachment || office.openedAttachment.id !== att.id) {
  237. office.save();
  238. if (this.module.form.businessData.workCompleted) {
  239. MWF.Actions.get("x_processplatform_assemble_surface").getAttachmentWorkcompletedUrl(att.id, this.module.form.businessData.workCompleted.id, function (url) {
  240. office.openedAttachment = { "id": att.id, "site": this.module.json.name, "name": att.name };
  241. office.officeOCX.BeginOpenFromURL(url, true, this.readonly);
  242. }.bind(this));
  243. } else {
  244. MWF.Actions.get("x_processplatform_assemble_surface").getAttachmentUrl(att.id, this.module.form.businessData.work.id, function (url) {
  245. office.openedAttachment = { "id": att.id, "site": this.module.json.name, "name": att.name };
  246. office.officeOCX.BeginOpenFromURL(url, true, this.readonly);
  247. }.bind(this));
  248. }
  249. }
  250. }
  251. },
  252. checkReplaceAction: function () {
  253. if (this.options.isReplaceHidden) return;
  254. if (this.options.readonly) {
  255. if (this.options.isReplaceOption === "hidden") {
  256. this.setActionHidden(this.replaceAction);
  257. this.setActionHidden(this.min_replaceAction);
  258. }else{
  259. this.setActionDisabled(this.replaceAction);
  260. this.setActionDisabled(this.min_replaceAction);
  261. }
  262. return false;
  263. }
  264. if (this.options.isReplaceOption === "hidden") {
  265. this.setActionHidden(this.replaceAction);
  266. this.setActionHidden(this.min_replaceAction);
  267. }else if(this.options.isReplaceOption === "n"){
  268. this.setActionDisabled(this.replaceAction);
  269. this.setActionDisabled(this.min_replaceAction);
  270. } else {
  271. if (this.selectedAttachments.length && this.selectedAttachments.length === 1) {
  272. var att = this.selectedAttachments[0];
  273. if (!att.data.person && att.data.creatorUid) att.data.person = att.data.creatorUid;
  274. var user = layout.session.user.distinguishedName;
  275. var flag = true;
  276. if (this.options.isReplaceOption === "o") {
  277. flag = att.data.person === layout.desktop.session.user.distinguishedName;
  278. }
  279. if (this.options.isReplaceOption === "a") {
  280. flag = att.data.activity === this.module.form.businessData.activity.id;
  281. }
  282. if (this.options.isReplaceOption === "ao") {
  283. flag = (att.data.person === layout.desktop.session.user.distinguishedName && att.data.activity === this.module.form.businessData.activity.id);
  284. }
  285. if (flag && !att.data.control.allowEdit && att.data.person !== user) {
  286. flag = false;
  287. }
  288. if (flag) {
  289. this.setActionEnabled(this.replaceAction);
  290. this.setActionEnabled(this.min_replaceAction);
  291. } else {
  292. this.setActionDisabled(this.replaceAction);
  293. this.setActionDisabled(this.min_replaceAction);
  294. }
  295. } else {
  296. this.setActionDisabled(this.replaceAction);
  297. this.setActionDisabled(this.min_replaceAction);
  298. }
  299. }
  300. // else {
  301. // // if (!this.options.isReplace){
  302. // this.setActionDisabled(this.replaceAction);
  303. // this.setActionDisabled(this.min_replaceAction);
  304. // }
  305. },
  306. replaceAttachment: function (e, node) {
  307. var att = this.selectedAttachments[0].data;
  308. if (this.module.json.isOpenInOffice && this.module.json.officeControlName && (this.options.officeFiles.indexOf(att.extension) !== -1)) {
  309. var office = this.module.form.all[this.module.json.officeControlName];
  310. if (office) {
  311. if (this.min_closeOfficeAction) this.setActionEnabled(this.min_closeOfficeAction);
  312. if (this.closeOfficeAction) this.setActionEnabled(this.closeOfficeAction);
  313. this.openInOfficeControl(att, office);
  314. } else {
  315. if (this.selectedAttachments.length && this.selectedAttachments.length == 1) {
  316. if (this.module) this.module.replaceAttachment(e, node, this.selectedAttachments[0]);
  317. }
  318. }
  319. } else {
  320. if (this.selectedAttachments.length && this.selectedAttachments.length == 1) {
  321. if (this.module) this.module.replaceAttachment(e, node, this.selectedAttachments[0]);
  322. }
  323. }
  324. },
  325. isAttReplaceAvailable: function (att) {
  326. if (this.options.readonly) return false;
  327. if (this.options.toolbarGroupHidden.contains("edit")) return false;
  328. if (this.options.isReplaceOption === "n" || this.options.isReplaceOption === "hidden") return false;
  329. var user = layout.session.user.distinguishedName;
  330. var flag = true;
  331. if (!att.data.person && att.data.creatorUid) att.data.person = att.data.creatorUid;
  332. if (this.options.isReplaceOption === "o") {
  333. flag = att.data.person === layout.desktop.session.user.distinguishedName;
  334. }
  335. if (this.options.isReplaceOption === "a") {
  336. flag = att.data.activity === this.module.form.businessData.activity.id;
  337. }
  338. if (this.options.isReplaceOption === "ao") {
  339. flag = (att.data.person === layout.desktop.session.user.distinguishedName && att.data.activity === this.module.form.businessData.activity.id);
  340. }
  341. if (flag && !att.data.control.allowEdit && att.data.person !== user) {
  342. flag = false;
  343. }
  344. return flag;
  345. },
  346. //checkAttachmentOrderAction : function(){
  347. // if (this.options.readonly){
  348. // this.setAttachmentsAction("order", false );
  349. // return false;
  350. // }
  351. // if (this.attachments.length){
  352. // var user = layout.session.user.distinguishedName;
  353. // for (var i=0; i<this.attachments.length; i++){
  354. // var flag = true;
  355. //
  356. // var att = this.attachments[i];
  357. // if( !att.data.person && att.data.creatorUid )att.data.person = att.data.creatorUid;
  358. //
  359. // if ((!att.data.control.allowControl || !att.data.control.allowEdit) && att.data.person!==user){
  360. // flag = false;
  361. // }
  362. // if (flag){
  363. // this.setAttachmentAction(att, "order", true );
  364. // }else{
  365. // this.setAttachmentAction(att, "order", false );
  366. // }
  367. // }
  368. // }
  369. //},
  370. checkOrderAction: function () {
  371. //this.checkAttachmentOrderAction();
  372. if (this.options.readonly) {
  373. if( this.options.isOrder === "hidden" ){
  374. this.setActionHidden(this.orderAction);
  375. this.setActionHidden(this.min_orderAction);
  376. }else{
  377. this.setActionDisabled(this.orderAction);
  378. this.setActionDisabled(this.min_orderAction);
  379. }
  380. return false;
  381. }
  382. if( this.options.isOrder === "hidden" ){
  383. this.setActionHidden(this.orderAction);
  384. this.setActionHidden(this.min_orderAction);
  385. }else if( !this.options.isOrder ){
  386. this.setActionDisabled(this.orderAction);
  387. this.setActionDisabled(this.min_orderAction);
  388. }else{
  389. if (this.attachments.length && this.attachments.length > 1) {
  390. var flag = true;
  391. var user = layout.session.user.distinguishedName;
  392. for (var i = 0; i < this.attachments.length; i++) {
  393. var att = this.attachments[i];
  394. if (!att.data.person && att.data.creatorUid) att.data.person = att.data.creatorUid;
  395. if ((!att.data.control.allowControl && !att.data.control.allowEdit) && att.data.person !== user) { //|| !att.data.control.allowEdit
  396. flag = false;
  397. break;
  398. }
  399. }
  400. if (flag) {
  401. this.setActionEnabled(this.orderAction);
  402. this.setActionEnabled(this.min_orderAction);
  403. } else {
  404. this.setActionDisabled(this.orderAction);
  405. this.setActionDisabled(this.min_orderAction);
  406. }
  407. //this.setActionEnabled(this.min_deleteAction);
  408. } else {
  409. this.setActionDisabled(this.orderAction);
  410. this.setActionDisabled(this.min_orderAction);
  411. //this.setActionDisabled(this.min_deleteAction);
  412. }
  413. }
  414. },
  415. isAttOrderAvailable: function (att) {
  416. if (this.options.readonly) return false;
  417. if (this.options.toolbarGroupHidden.contains("config")) return false;
  418. var user = layout.session.user.distinguishedName;
  419. var flag = true;
  420. if (!att.data.person && att.data.creatorUid) att.data.person = att.data.creatorUid;
  421. if ((!att.data.control.allowControl || !att.data.control.allowEdit) && att.data.person !== user) {
  422. flag = false;
  423. }
  424. return flag;
  425. },
  426. createTopNode: function () {
  427. if (this.options.title) {
  428. if (!this.titleNode) this.titleNode = new Element("div", { "styles": this.css.titleNode, "text": this.options.title }).inject(this.node);
  429. }
  430. if (!this.topNode) {
  431. this.topNode = new Element("div", { "styles": this.css.topNode }).inject(this.node);
  432. } else {
  433. this.topNode.empty();
  434. this.editActionBoxNode = null;
  435. this.editActionsGroupNode = null;
  436. // this.topNode.setStyle("display", "");
  437. this.topNode.show();
  438. if (this.isHiddenTop) {
  439. //this.container.setStyle("height", this.container.getSize().y + 45 );
  440. //this.node.setStyle("height", this.node.getSize().y + 45 );
  441. if (this.oldContentScrollNodeHeight && this.contentScrollNode) {
  442. this.contentScrollNode.setStyle("min-height", this.oldContentScrollNodeHeight);
  443. this.oldContentScrollNodeHeight = null;
  444. }
  445. this.isHiddenTop = false;
  446. }
  447. }
  448. var hiddenGroup = this.options.toolbarGroupHidden;
  449. if (hiddenGroup.contains("edit") && hiddenGroup.contains("read") && hiddenGroup.contains("list") &&
  450. hiddenGroup.contains("view") && hiddenGroup.contains("config") &&
  451. !(this.module.json.isOpenInOffice && this.module.json.officeControlName)
  452. ) {
  453. if (this.contentScrollNode) {
  454. this.oldContentScrollNodeHeight = this.contentScrollNode.getStyle("min-height");
  455. this.contentScrollNode.setStyle("min-height", this.node.getStyle("min-height"));
  456. this.topNode.hide();
  457. }
  458. this.isHiddenTop = true;
  459. }
  460. if (!hiddenGroup.contains("edit")) this.createEditGroupActions();
  461. if (!hiddenGroup.contains("read")) this.createReadGroupActions();
  462. if (!hiddenGroup.contains("list")) this.createListGroupActions();
  463. if (this.module.json.isOpenInOffice && this.module.json.officeControlName) this.createOfficeGroupActions();
  464. if (!hiddenGroup.contains("config")) this.createConfigGroupActions();
  465. if (!hiddenGroup.contains("view")) this.createViewGroupActions();
  466. this.checkActions();
  467. if( layout.mobile && this.checkActionsZoom ){
  468. this.checkActionsZoom();
  469. }
  470. },
  471. createReadGroupActions: function(){
  472. //this.readActionBoxNode = new Element("div", {"styles": this.css.actionsBoxNode}).inject(this.topNode);
  473. //this.readActionsGroupNode = new Element("div", {"styles": this.css.actionsGroupNode}).inject(this.readActionBoxNode);
  474. if(!this.editActionBoxNode)this.editActionBoxNode = new Element("div", {"styles": this.css.actionsBoxNode}).inject(this.topNode);
  475. if(!this.editActionsGroupNode)this.editActionsGroupNode = new Element("div", {"styles": this.css.actionsGroupNode}).inject(this.editActionBoxNode);
  476. this.downloadAction = this.createAction(this.editActionsGroupNode, "download", o2.LP.widget.download, function(){
  477. this.downloadAttachment();
  478. }.bind(this));
  479. this.downloadBatchAction = this.createAction(this.editActionsGroupNode, "downloadBatch", o2.LP.widget.downloadBatch, function(){
  480. this.downloadBatchAttachment();
  481. }.bind(this));
  482. },
  483. checkActions: function () {
  484. // if (this.options.readonly){
  485. // this.setReadonly();
  486. // }else{
  487. this.checkUploadAction();
  488. this.checkDeleteAction();
  489. this.checkReplaceAction();
  490. this.checkPreviewAttAction();
  491. this.checkEditAttAction();
  492. //this.checkOfficeAction();
  493. this.checkDownloadAction();
  494. this.checkDownloadBatchAction();
  495. this.checkSizeAction();
  496. this.checkConfigAction();
  497. this.checkOrderAction();
  498. this.checkListStyleAction();
  499. if( this.options.size === "max" ){
  500. this.checkEditActionBox();
  501. this.checkConfigActionBox();
  502. }else if( this.options.size === "min" ){
  503. this.checkMinActionBox();
  504. }
  505. // }
  506. },
  507. checkEditActionBox: function(){
  508. var isShowEdit = false;
  509. ["isUpload", "isDelete", "isReplace", "isPreviewAtt", "isEditAtt"].each(function( key ){
  510. if( key === "isReplace" && this.options.isReplaceHidden )return;
  511. if( key === "isPreviewAtt" && layout.mobile )return;
  512. if( this.options[key] !== "hidden" )isShowEdit = true;
  513. }.bind(this));
  514. var isShowRead = false;
  515. ["isDownload","isDownloadBatch"].each(function( key ){
  516. if( this.options[key] !== "hidden" )isShowRead = true;
  517. }.bind(this));
  518. if(this.editActionSeparateNode)this.editActionSeparateNode.setStyle( "display", isShowEdit && isShowRead ? "" : "none" );
  519. if(this.editActionBoxNode )this.editActionBoxNode.setStyle( "display", isShowEdit || isShowRead ? "" : "none" );
  520. },
  521. checkConfigActionBox: function(){
  522. var isShowConfig = false;
  523. ["isConfig"].each(function( key ){
  524. if( this.options[key] !== "hidden" )isShowConfig = true;
  525. }.bind(this));
  526. var isShowOrder = false;
  527. ["isOrder"].each(function( key ){
  528. if( this.options[key] !== "hidden" )isShowOrder = true;
  529. }.bind(this));
  530. if(this.configActionSeparateNode)this.configActionSeparateNode.setStyle( "display", isShowConfig && isShowOrder ? "" : "none" );
  531. if(this.configActionBoxNode )this.configActionBoxNode.setStyle( "display", isShowConfig || isShowOrder ? "" : "none" );
  532. },
  533. checkMinActionBox: function(){
  534. var isShowLeft = false;
  535. var hiddenGroup = this.options.toolbarGroupHidden || [];
  536. if( this.min_closeOfficeAction ){
  537. isShowLeft = true;
  538. }else {
  539. ["isUpload", "isDelete", "isReplace", "isDownload", "isDownloadBatch", "isOrder"].each(function (key) {
  540. if (key === "isReplace" && this.options.isReplaceHidden) return;
  541. if (this.options[key] !== "hidden") isShowLeft = true;
  542. }.bind(this));
  543. if( isShowLeft ){
  544. if( hiddenGroup.contains("edit") && hiddenGroup.contains("read") && hiddenGroup.contains("config") ){
  545. isShowLeft = false;
  546. }
  547. }
  548. }
  549. var isShowRight = this.options.isSizeChange && !hiddenGroup.contains("view");
  550. if(this.minSeparateNode)this.minSeparateNode.setStyle( "display", isShowLeft && isShowRight ? "" : "none" );
  551. if(this.minActionAreaNode ){
  552. if (isShowLeft || isShowRight){
  553. this.minActionAreaNode.show();
  554. }else{
  555. this.minActionAreaNode.hide();
  556. }
  557. }
  558. },
  559. checkAttachmentConfigAction: function () {
  560. if (this.options.readonly || !this.attachments.length) {
  561. this.setAttachmentsAction("config", false);
  562. return false;
  563. }
  564. var currentUser = layout.session.user.distinguishedName;
  565. for (var i = 0; i < this.attachments.length; i++) {
  566. var att = this.attachments[i];
  567. var attUser = att.data.person || att.data.creatorUid;
  568. this.setAttachmentAction(att, "config", att.data.control.allowControl && attUser===currentUser);
  569. }
  570. },
  571. checkConfigAction: function () {
  572. if( this.options.isConfig === "hidden" ){
  573. this.setActionHidden(this.configAction);
  574. return;
  575. }
  576. if( !this.options.isConfig ){
  577. this.setActionDisabled(this.configAction);
  578. return;
  579. }
  580. this.checkAttachmentConfigAction();
  581. if (this.options.readonly) {
  582. this.setActionDisabled(this.configAction);
  583. if (this.checkTextAction) this.setActionDisabled(this.checkTextAction);
  584. return false;
  585. }
  586. if (this.selectedAttachments.length) {
  587. var flag = true;
  588. var user = layout.session.user.distinguishedName;
  589. for (var i = 0; i < this.selectedAttachments.length; i++) {
  590. var att = this.selectedAttachments[i];
  591. if (!att.data.person && att.data.creatorUid) att.data.person = att.data.creatorUid;
  592. if ((!att.data.control.allowControl) && att.data.person !== user) { //|| !att.data.control.allowEdit
  593. flag = false;
  594. break;
  595. }
  596. }
  597. if (flag) {
  598. this.setActionEnabled(this.configAction);
  599. } else {
  600. this.setActionDisabled(this.configAction);
  601. }
  602. //this.setActionEnabled(this.min_deleteAction);
  603. } else {
  604. this.setActionDisabled(this.configAction);
  605. //this.setActionDisabled(this.min_deleteAction);
  606. }
  607. if (this.checkTextAction) {
  608. this.setActionDisabled(this.checkTextAction);
  609. if (this.selectedAttachments.length && this.selectedAttachments.length === 1) {
  610. var att = this.selectedAttachments[0];
  611. if (this.options.images.indexOf(att.data.extension.toLowerCase()) !== -1) {
  612. this.setActionEnabled(this.checkTextAction);
  613. }
  614. }
  615. }
  616. },
  617. isAttConfigAvailable: function (att) {
  618. if (this.options.readonly) return false;
  619. if (this.options.isConfig === "hidden") return false;
  620. if (this.options.toolbarGroupHidden.contains("config")) return false;
  621. var user = layout.session.user.distinguishedName;
  622. var flag = true;
  623. if (!att.data.person && att.data.creatorUid) att.data.person = att.data.creatorUid;
  624. if (!att.data.control.allowControl && att.data.person !== user) {
  625. flag = false;
  626. }
  627. return flag;
  628. },
  629. createEditGroupActions: function () {
  630. if (!this.editActionBoxNode) this.editActionBoxNode = new Element("div", { "styles": this.css.actionsBoxNode }).inject(this.topNode);
  631. if (!this.editActionsGroupNode) this.editActionsGroupNode = new Element("div", { "styles": this.css.actionsGroupNode }).inject(this.editActionBoxNode);
  632. this.uploadAction = this.createAction(this.editActionsGroupNode, "upload", o2.LP.widget.upload, function (e, node) {
  633. this.uploadAttachment(e, node);
  634. }.bind(this));
  635. this.deleteAction = this.createAction(this.editActionsGroupNode, "delete", o2.LP.widget["delete"], function (e, node) {
  636. this.deleteAttachment(e, node);
  637. }.bind(this));
  638. //if(!layout.mobile){
  639. this.previewAttAction = this.createAction(this.editActionsGroupNode, "previewAtt", o2.LP.widget["previewAtt"], function (e, node) {
  640. this.previewAttachment(e, node);
  641. }.bind(this));
  642. //}
  643. if(!layout.mobile){
  644. this.editAttAction = this.createAction(this.editActionsGroupNode, "editAtt", o2.LP.widget["editAtt"], function (e, node) {
  645. this.editAttachment(e, node);
  646. }.bind(this));
  647. }
  648. if (!this.options.isReplaceHidden) {
  649. this.replaceAction = this.createAction(this.editActionsGroupNode, "replace", o2.LP.widget.replace, function (e, node) {
  650. this.replaceAttachment(e, node);
  651. }.bind(this));
  652. }
  653. // this.officeAction = this.createAction(this.editActionsGroupNode, "office", o2.LP.widget.office, function(e, node){
  654. // this.openInOfficeControl(e, node);
  655. // }.bind(this));
  656. if (!this.options.toolbarGroupHidden.contains("read")) this.editActionSeparateNode = this.createSeparate(this.editActionsGroupNode);
  657. },
  658. createConfigGroupActions: function () {
  659. this.configActionBoxNode = new Element("div", { "styles": this.css.actionsBoxNode }).inject(this.topNode);
  660. this.configActionsGroupNode = new Element("div", { "styles": this.css.actionsGroupNode }).inject(this.configActionBoxNode);
  661. this.configAction = this.createAction(this.configActionsGroupNode, "config", MWF.LP.widget.configAttachment, function (e, node) {
  662. this.configAttachment(e, node);
  663. }.bind(this));
  664. // if (this.options.checkTextEnable) {
  665. // this.checkTextAction = this.createAction(this.configActionsGroupNode, "check", MWF.LP.widget.checkOcrText, function (e, node) {
  666. // this.checkImageTex(e, node);
  667. // }.bind(this));
  668. // }
  669. this.configActionSeparateNode = this.createSeparate(this.configActionsGroupNode);
  670. this.orderAction = this.createAction(this.configActionsGroupNode, "order", MWF.LP.widget.order, function (e, node) {
  671. this.orderAttachment(e, node);
  672. }.bind(this));
  673. if (this.configAction) this.setActionDisabled(this.configAction);
  674. if (this.checkTextAction) this.setActionDisabled(this.checkTextAction);
  675. },
  676. createOfficeGroupActions: function () {
  677. this.officeActionBoxNode = new Element("div", { "styles": this.css.actionsBoxNode }).inject(this.topNode);
  678. this.officeActionsGroupNode = new Element("div", { "styles": this.css.actionsGroupNode }).inject(this.officeActionBoxNode);
  679. this.closeOfficeAction = this.createAction(this.officeActionsGroupNode, "closeOffice", MWF.LP.widget.closeOffice, function (e, node) {
  680. this.closeAttachmentOffice(e, node);
  681. }.bind(this));
  682. if (this.closeOfficeAction) this.setActionDisabled(this.closeOfficeAction);
  683. },
  684. loadMinActions: function () {
  685. var hiddenGroup = this.options.toolbarGroupHidden;
  686. if (!hiddenGroup.contains("edit")) {
  687. this.min_uploadAction = this.createAction(this.minActionAreaNode, "upload", MWF.LP.widget.upload, function (e, node) {
  688. this.uploadAttachment(e, node);
  689. }.bind(this));
  690. this.min_deleteAction = this.createAction(this.minActionAreaNode, "delete", MWF.LP.widget["delete"], function (e, node) {
  691. this.deleteAttachment(e, node);
  692. }.bind(this));
  693. if (!this.options.isReplaceHidden) {
  694. this.min_replaceAction = this.createAction(this.minActionAreaNode, "replace", MWF.LP.widget.replace, function (e, node) {
  695. this.replaceAttachment(e, node);
  696. }.bind(this));
  697. }
  698. if(!layout.mobile){
  699. this.min_editAttAction = this.createAction(this.minActionAreaNode, "editAtt", o2.LP.widget["editAtt"], function (e, node) {
  700. this.editAttachment(e, node);
  701. }.bind(this));
  702. }
  703. }
  704. if (!hiddenGroup.contains("read")) {
  705. this.min_downloadAction = this.createAction(this.minActionAreaNode, "download", MWF.LP.widget.download
  706. , function (e, node) {
  707. this.downloadAttachment(e, node);
  708. }.bind(this));
  709. this.min_downloadBatchAction = this.createAction(this.minActionAreaNode, "downloadBatch", MWF.LP.widget.downloadBatch
  710. , function (e, node) {
  711. this.downloadBatchAttachment(e, node);
  712. }.bind(this));
  713. //if(!layout.mobile){
  714. this.min_previewAttAction = this.createAction(this.minActionAreaNode, "previewAtt", o2.LP.widget["previewAtt"], function (e, node) {
  715. this.previewAttachment(e, node);
  716. }.bind(this));
  717. //}
  718. }
  719. if (!hiddenGroup.contains("config")) {
  720. this.min_orderAction = this.createAction(this.minActionAreaNode, "order", MWF.LP.widget.order, function (e, node) {
  721. this.orderAttachment(e, node);
  722. }.bind(this));
  723. }
  724. if (this.module.json.isOpenInOffice && this.module.json.officeControlName) {
  725. this.min_closeOfficeAction = this.createAction(this.minActionAreaNode, "closeOffice", MWF.LP.widget.closeOffice, function (e, node) {
  726. this.closeAttachmentOffice(e, node);
  727. }.bind(this));
  728. if (this.min_closeOfficeAction) this.setActionDisabled(this.closeOfficeAction);
  729. }
  730. if (!hiddenGroup.contains("edit") || !hiddenGroup.contains("read")) {
  731. this.minSeparateNode = this.createSeparate(this.minActionAreaNode);
  732. }
  733. //this.createSeparate(this.configActionsGroupNode);
  734. if (this.options.isSizeChange) {
  735. //this.createSeparate(this.minActionAreaNode);
  736. if (!hiddenGroup.contains("view")) {
  737. this.sizeAction = this.createAction(this.minActionAreaNode, "max", MWF.LP.widget.min, function () {
  738. this.changeControllerSize();
  739. }.bind(this));
  740. }
  741. }
  742. },
  743. closeAttachmentOffice: function () {
  744. var office = this.module.form.all[this.module.json.officeControlName];
  745. if (office) {
  746. office.openFile();
  747. if (this.min_closeOfficeAction) this.setActionDisabled(this.min_closeOfficeAction);
  748. if (this.closeOfficeAction) this.setActionDisabled(this.closeOfficeAction);
  749. }
  750. },
  751. configAttachment: function(){
  752. o2.Actions.load("x_general_assemble_control").SecurityClearanceAction["enable"]().then(function(json){
  753. if (json.data.enable){
  754. this.configAttachmentSecurity();
  755. }else{
  756. this.configAttachmentPower();
  757. }
  758. }.bind(this));
  759. },
  760. getSecurityDefaultLabelList: function(){
  761. if (this.securityLabelList) return Promise.resolve(this.securityLabelList);
  762. var _self = this
  763. return o2.Actions.load("x_general_assemble_control").SecurityClearanceAction["object"]().then(function(json){
  764. return _self.securityLabelList = json.data;
  765. });
  766. },
  767. getSecurityLabelList: function(){
  768. var _self = this;
  769. return this.getSecurityDefaultLabelList().then(function(list){
  770. var label = _self.module.form.businessData.data.objectSecurityClearance;
  771. label = (!label && label!==0) ? Infinity : label;
  772. var o = {};
  773. Object.keys(list).forEach(function(k){
  774. if (list[k]<=label){
  775. o[k] = list[k];
  776. }
  777. });
  778. return o;
  779. })
  780. },
  781. configAttachmentSecurity: function(){
  782. var lp = MWF.xApplication.process.Xform.LP;
  783. var css = this.module.form.css;
  784. var node = new Element("div", { "styles": (layout.mobile ? css.attachmentPermissionNode_mobile : css.attachmentPermissionNode) }).inject(this.node);
  785. var attNames = new Element("div", { "styles": css.attachmentPermissionNamesNode }).inject(node);
  786. var attNamesTitle = new Element("div", { "styles": css.attachmentPermissionNamesTitleNode, "text": lp.attachmentPermissionInfo }).inject(attNames);
  787. var attNamesArea = new Element("div", { "styles": css.attachmentPermissionNamesAreaNode }).inject(attNames);
  788. if (this.selectedAttachments.length) {
  789. this.selectedAttachments.each(function (att) {
  790. var attNode = new Element("div", { "styles": css.attachmentPermissionAttNode, "text": att.data.name }).inject(attNamesArea);
  791. }.bind(this));
  792. }
  793. var label = "";
  794. if (this.selectedAttachments.length){
  795. for (var i=0; i<this.selectedAttachments.length; i++){
  796. var attLabel = this.selectedAttachments[i].data.objectSecurityClearance;
  797. label = (!label || label===attLabel) ? attLabel : "";
  798. }
  799. }
  800. var editArea = new Element("div", { "styles": css.attachmentPermissionEditAreaNode }).inject(node);
  801. editArea.setStyle("display", "flex");
  802. var title = new Element("div", { "styles": css.attachmentPermissionTitleNode, "text": lp.attachmentSecurity }).inject(editArea);
  803. title.setStyle("margin-right", "15px");
  804. var select = new Element("select", { "styles": css.attachmentPermissionInputNode }).inject(editArea);
  805. new Element('option', {text: "", value: ""}).inject(select);
  806. this.getSecurityLabelList().then(function(labels){
  807. Object.keys(labels).forEach(function(key){
  808. var op = new Element('option', {text: key, value: labels[key]}).inject(select);
  809. if (label===labels[key]) op.selected = true;
  810. });
  811. });
  812. var options = Object.merge({
  813. "title": lp.attachmentPermission,
  814. "style": this.module.form.json.dialogStyle || "user",
  815. "isResize": false,
  816. "content": node,
  817. "container": this.module.form.app.content,
  818. "maskNode": this.module.form.app.content,
  819. "buttonList": [
  820. {
  821. "type": "ok",
  822. "text": MWF.LP.process.button.ok,
  823. "action": function () {
  824. this.setAttachmentSecurityConfig(select);
  825. dlg.close();
  826. }.bind(this)
  827. },
  828. {
  829. "type": "cancel",
  830. "text": MWF.LP.process.button.cancel,
  831. "action": function () { dlg.close(); }
  832. }
  833. ]
  834. }, (this.module.form.json.dialogOptions||{}));
  835. if( layout.mobile ){
  836. var size = $(document.body).getSize();
  837. options.width = size.x;
  838. options.height = size.y;
  839. }
  840. var dlg = o2.DL.open( options );
  841. },
  842. configAttachmentPower: function () {
  843. //this.fireEvent("delete", [attachment.data]);
  844. var lp = MWF.xApplication.process.Xform.LP;
  845. var css = this.module.form.css;
  846. var node = new Element("div.MWF_configAttachmentPower", { "styles": (layout.mobile ? css.attachmentPermissionNode_mobile : css.attachmentPermissionNode) }).inject(this.node);
  847. var attNames = new Element("div", { "styles": css.attachmentPermissionNamesNode }).inject(node);
  848. var attNamesTitle = new Element("div", { "styles": css.attachmentPermissionNamesTitleNode, "text": lp.attachmentPermissionInfo }).inject(attNames);
  849. var attNamesArea = new Element("div", { "styles": css.attachmentPermissionNamesAreaNode }).inject(attNames);
  850. if (this.selectedAttachments.length) {
  851. this.selectedAttachments.each(function (att) {
  852. var attNode = new Element("div", { "styles": css.attachmentPermissionAttNode, "text": att.data.name }).inject(attNamesArea);
  853. }.bind(this));
  854. }
  855. var editArea = new Element("div", { "styles": css.attachmentPermissionEditAreaNode }).inject(node);
  856. var title = new Element("div", { "styles": css.attachmentPermissionTitleNode, "text": lp.attachmentRead }).inject(editArea);
  857. var readInput = new Element("div", { "styles": css.attachmentPermissionInputNode }).inject(editArea);
  858. title = new Element("div", { "styles": css.attachmentPermissionTitleNode, "text": lp.attachmentEdit }).inject(editArea);
  859. var editInput = new Element("div", { "styles": css.attachmentPermissionInputNode }).inject(editArea);
  860. title = new Element("div", { "styles": css.attachmentPermissionTitleNode, "text": lp.attachmentController }).inject(editArea);
  861. var controllerInput = new Element("div", { "styles": css.attachmentPermissionInputNode }).inject(editArea);
  862. var options = Object.merge({
  863. "title": lp.attachmentPermission,
  864. "style": this.module.form.json.dialogStyle || "user",
  865. "isResize": false,
  866. "content": node,
  867. "container": this.module.form.app.content,
  868. "maskNode": this.module.form.app.content,
  869. "buttonList": [
  870. {
  871. "type": "ok",
  872. "text": MWF.LP.process.button.ok,
  873. "action": function () {
  874. this.setAttachmentConfig(readInput, editInput, controllerInput);
  875. dlg.close();
  876. }.bind(this)
  877. },
  878. {
  879. "type": "cancel",
  880. "text": MWF.LP.process.button.cancel,
  881. "action": function () { dlg.close(); }
  882. }
  883. ]
  884. }, (this.module.form.json.dialogOptions||{}));
  885. if( layout.mobile ){
  886. var size = $(document.body).getSize();
  887. options.width = size.x;
  888. options.height = size.y;
  889. }
  890. var dlg = o2.DL.open( options );
  891. if (this.selectedAttachments.length === 1) {
  892. var data = this.selectedAttachments[0].data;
  893. var readUnitList = (data.readUnitList) || [];
  894. var readIdentityList = (data.readIdentityList) || [];
  895. var editUnitList = (data.editUnitList) || [];
  896. var editIdentityList = (data.editIdentityList) || [];
  897. var controllerUnitList = (data.controllerUnitList) || [];
  898. var controllerIdentityList = (data.controllerIdentityList) || [];
  899. readInput.setSelectPerson(this.module.form.app.content, Object.merge(Object.clone(this.module.form.json.selectorStyle || {}), {
  900. "types": ["unit", "identity"],
  901. "values": readUnitList.concat(readIdentityList).trim()
  902. }));
  903. editInput.setSelectPerson(this.module.form.app.content, Object.merge(Object.clone(this.module.form.json.selectorStyle || {}), {
  904. "types": ["unit", "identity"],
  905. "values": editUnitList.concat(editIdentityList).trim()
  906. }));
  907. controllerInput.setSelectPerson(this.module.form.app.content, Object.merge(Object.clone(this.module.form.json.selectorStyle || {}), {
  908. "types": ["unit", "identity"],
  909. "values": controllerUnitList.concat(controllerIdentityList).trim()
  910. }));
  911. } else {
  912. readInput.setSelectPerson(this.module.form.app.content, Object.merge(Object.clone(this.module.form.json.selectorStyle || {}), {
  913. "types": ["unit", "identity"]
  914. }));
  915. editInput.setSelectPerson(this.module.form.app.content, Object.merge(Object.clone(this.module.form.json.selectorStyle || {}), {
  916. "types": ["unit", "identity"]
  917. }));
  918. controllerInput.setSelectPerson(this.module.form.app.content, Object.merge(Object.clone(this.module.form.json.selectorStyle || {}), {
  919. "types": ["unit", "identity"]
  920. }));
  921. }
  922. },
  923. setAttachmentSecurityConfig: function(select){
  924. if (this.selectedAttachments.length) {
  925. var security = select.options[select.selectedIndex].value;
  926. var loadedCount = 0;
  927. this.selectedAttachments.each(function (att) {
  928. att.data.objectSecurityClearance = security.toInt();
  929. o2.Actions.get("x_processplatform_assemble_surface").configAttachment(att.data.id, this.module.form.businessData.work.id, att.data, function () {
  930. //刷新附件权限,以后要加一个刷新附件的功能
  931. o2.Actions.load("x_processplatform_assemble_surface").AttachmentAction.getWithWorkOrWorkCompleted(att.data.id, this.module.form.businessData.work.id, function (json) {
  932. var attachment = this.getAttachmentById( att.data.id );
  933. if( attachment ){
  934. attachment.data = json.data;
  935. if( attachment.deleteAction && !this.isAttDeleteAvailable(attachment) ){
  936. attachment.deleteAction.setStyle("display","none");
  937. }
  938. if( attachment.configAction && !this.isAttConfigAvailable(attachment) ){
  939. attachment.configAction.setStyle("display","none");
  940. }
  941. }
  942. loadedCount++;
  943. if( loadedCount === this.selectedAttachments.length ){
  944. this.checkActions();
  945. }
  946. }.bind(this))
  947. }.bind(this));
  948. }.bind(this));
  949. }
  950. },
  951. setAttachmentConfig: function (readInput, editInput, controllerInput) {
  952. if (this.selectedAttachments.length) {
  953. var readList = readInput.retrieve("data-value");
  954. var editList = editInput.retrieve("data-value");
  955. var controllerList = controllerInput.retrieve("data-value");
  956. var readUnitList = [];
  957. var readIdentityList = [];
  958. var editUnitList = [];
  959. var editIdentityList = [];
  960. var controllerUnitList = [];
  961. var controllerIdentityList = [];
  962. if (readList) {
  963. readList.each(function (v) {
  964. var vName = (typeOf(v) === "string") ? v : v.distinguishedName;
  965. var len = vName.length;
  966. var flag = vName.substring(len - 1, len);
  967. if (flag === "U") readUnitList.push(vName);
  968. if (flag === "I") readIdentityList.push(vName);
  969. });
  970. }
  971. if (editList) {
  972. editList.each(function (v) {
  973. var vName = (typeOf(v) === "string") ? v : v.distinguishedName;
  974. var len = vName.length;
  975. var flag = vName.substring(len - 1, len);
  976. if (flag === "U") editUnitList.push(vName);
  977. if (flag === "I") editIdentityList.push(vName);
  978. });
  979. }
  980. if (controllerList) {
  981. controllerList.each(function (v) {
  982. var vName = (typeOf(v) === "string") ? v : v.distinguishedName;
  983. var len = vName.length;
  984. var flag = vName.substring(len - 1, len);
  985. if (flag === "U") controllerUnitList.push(vName);
  986. if (flag === "I") controllerIdentityList.push(vName);
  987. });
  988. }
  989. var loadedCount = 0;
  990. this.selectedAttachments.each(function (att) {
  991. att.data.readUnitList = readUnitList;
  992. att.data.readIdentityList = readIdentityList;
  993. att.data.editUnitList = editUnitList;
  994. att.data.editIdentityList = editIdentityList;
  995. att.data.controllerUnitList = controllerUnitList;
  996. att.data.controllerIdentityList = controllerIdentityList;
  997. o2.Actions.get("x_processplatform_assemble_surface").configAttachment(att.data.id, this.module.form.businessData.work.id, att.data, function () {
  998. //刷新附件权限,以后要加一个刷新附件的功能
  999. o2.Actions.load("x_processplatform_assemble_surface").AttachmentAction.getWithWorkOrWorkCompleted(att.data.id, this.module.form.businessData.work.id, function (json) {
  1000. var attachment = this.getAttachmentById( att.data.id );
  1001. if( attachment ){
  1002. attachment.data = json.data;
  1003. if( attachment.deleteAction && !this.isAttDeleteAvailable(attachment) ){
  1004. attachment.deleteAction.setStyle("display","none");
  1005. }
  1006. if( attachment.configAction && !this.isAttConfigAvailable(attachment) ){
  1007. attachment.configAction.setStyle("display","none");
  1008. }
  1009. }
  1010. loadedCount++;
  1011. if( loadedCount === this.selectedAttachments.length ){
  1012. this.checkActions();
  1013. }
  1014. }.bind(this))
  1015. }.bind(this));
  1016. }.bind(this));
  1017. }
  1018. },
  1019. checkImageTex: function () {
  1020. if (this.selectedAttachments.length && this.selectedAttachments.length == 1) {
  1021. var att = this.selectedAttachments[0];
  1022. var lp = MWF.xApplication.process.Xform.LP;
  1023. var css = this.module.form.css;
  1024. var node = new Element("div", { "styles": css.attachmentOCRNode }).inject(this.node);
  1025. var previewNode = new Element("div", { "styles": css.attachmentOCRImageAreaNode }).inject(node);
  1026. var imgNode = new Element("img", { "styles": css.attachmentOCRImageNode }).inject(previewNode);
  1027. o2.Actions.get("x_processplatform_assemble_surface").getAttachmentUrl(att.data.id, this.module.form.businessData.work.id, function (url) {
  1028. // imgNode.set("src", o2.filterUrl(url));
  1029. imgNode.set("src", url);
  1030. });
  1031. var areaNode = new Element("div", { "styles": css.attachmentOCRInputAreaNode }).inject(node);
  1032. var inputNode = new Element("textarea", { "styles": css.attachmentOCRInputNode }).inject(areaNode);
  1033. var dlg = o2.DL.open({
  1034. "title": lp.attachmentOCRTitle,
  1035. "style": this.module.form.json.dialogStyle || "user",
  1036. "isResize": false,
  1037. "content": node,
  1038. "buttonList": [
  1039. {
  1040. "type": "ok",
  1041. "text": MWF.LP.process.button.ok,
  1042. "action": function () {
  1043. this.setAttachmentOCR(inputNode, att);
  1044. dlg.close();
  1045. }.bind(this)
  1046. },
  1047. {
  1048. "type": "cancel",
  1049. "text": MWF.LP.process.button.cancel,
  1050. "action": function () { dlg.close(); }
  1051. }
  1052. ]
  1053. });
  1054. if (att.data.ocr) {
  1055. inputNode.set("text", att.data.ocr.text || "");
  1056. } else {
  1057. o2.Actions.get("x_processplatform_assemble_surface").getAttachmentOCR(att.data.id, this.module.form.businessData.work.id, function (json) {
  1058. att.data.ocr = json.data;
  1059. inputNode.set("text", json.data.text || "");
  1060. }.bind(this))
  1061. }
  1062. }
  1063. },
  1064. setAttachmentOCR: function (inputNode, att) {
  1065. var data = inputNode.get("text");
  1066. if (!att.data.ocr) att.data.ocr = {};
  1067. att.data.ocr.text = data;
  1068. o2.Actions.get("x_processplatform_assemble_surface").setAttachmentOCR(att.data.id, this.module.form.businessData.work.id, {
  1069. "text": data
  1070. }, function () {
  1071. this.module.form.app.notice("success", lp.attachmentOCR_saved, this.node);
  1072. }.bind(this));
  1073. },
  1074. checkMoveAction: function (item) {
  1075. if (item) {
  1076. var actionArea = item.getFirst().getNext();
  1077. var actionup = actionArea.getFirst().show();
  1078. var actiondown = actionArea.getLast().show();
  1079. tmp = item.getPrevious();
  1080. if (!tmp) actionup.hide();
  1081. tmp = item.getNext();
  1082. if (!tmp) actiondown.hide();
  1083. }
  1084. },
  1085. sortByNumber: function( attachments ){
  1086. return attachments.sort(function (a1, a2) {
  1087. if (!a2.data.orderNumber) return 1;
  1088. if (!a1.data.orderNumber) return -1;
  1089. return a1.data.orderNumber - a2.data.orderNumber;
  1090. }.bind(this));
  1091. },
  1092. orderAttachment: function () {
  1093. if (this.attachments.length) {
  1094. // this.attachments = this.attachments.sort(function (a1, a2) {
  1095. // if (!a2.data.orderNumber) return 1;
  1096. // if (!a1.data.orderNumber) return -1;
  1097. // return a1.data.orderNumber - a2.data.orderNumber;
  1098. // }.bind(this));
  1099. this.attachments = this.sortByNumber(this.attachments);
  1100. var lp = MWF.xApplication.process.Xform.LP;
  1101. var css = this.module.form.css;
  1102. var node = new Element("div", { "styles": (layout.mobile ? css.attachmentOrderNode_mobile : css.attachmentOrderNode) });
  1103. var infoNode = new Element("div", { "styles": css.attachmentOrderInforNode, "text": lp.attachmentOrderInfo }).inject(node);
  1104. var attrchmentsNode = new Element("div", { "styles": (layout.mobile ? css.attachmentOrderAreaNode_mobile : css.attachmentOrderAreaNode) }).inject(node);
  1105. var iconUrl = "../x_component_File/$Main/icon.json";
  1106. var icons = null;
  1107. o2.getJSON(iconUrl, function (json) {
  1108. icons = json;
  1109. }.bind(this), false, false);
  1110. this.attachments.each(function (att, idx) {
  1111. var iconName = icons[att.data.extension.toLowerCase()] || icons.unknow;
  1112. var iconFolderUrl = "../x_component_File/$Main/default/file/" + iconName;
  1113. var itemNode = new Element("div", { "styles": css.attachmentOrderItemNode }).inject(attrchmentsNode);
  1114. itemNode.store("att", att);
  1115. var icon = new Element("div", { "styles": css.attachmentOrderItemIconNode }).inject(itemNode);
  1116. icon.setStyle("background-image", "url('" + iconFolderUrl + "')");
  1117. var actionArea = new Element("div", { "styles": (layout.mobile ? css.attachmentOrderItemActionNode_mobile : css.attachmentOrderItemActionNode) }).inject(itemNode);
  1118. var text = new Element("div", { "styles": (layout.mobile ? css.attachmentOrderItemTextNode_mobile : css.attachmentOrderItemTextNode), "text": att.data.name }).inject(itemNode);
  1119. var actionUp = new Element("div", { "styles": css.attachmentOrderItemActionUpNode, "text": lp.attachmentOrderUp }).inject(actionArea);
  1120. var actionDown = new Element("div", { "styles": css.attachmentOrderItemActionDownNode, "text": lp.attachmentOrderDown }).inject(actionArea);
  1121. if (idx == 0) actionUp.hide();
  1122. if (idx == this.attachments.length - 1) actionDown.hide();
  1123. actionUp.addEvent("click", function (e) {
  1124. var itemNode = e.target.getParent().getParent();
  1125. var upNode = itemNode.getPrevious();
  1126. if (upNode) {
  1127. itemNode.inject(upNode, "before");
  1128. this.checkMoveAction(upNode);
  1129. }
  1130. this.checkMoveAction(itemNode);
  1131. itemNode.highlight();
  1132. //itemNode.setStyle("background-color", "#faf9f1");
  1133. }.bind(this));
  1134. actionDown.addEvent("click", function (e) {
  1135. var itemNode = e.target.getParent().getParent();
  1136. var downNode = itemNode.getNext();
  1137. if (downNode) {
  1138. itemNode.inject(downNode, "after");
  1139. this.checkMoveAction(downNode);
  1140. }
  1141. this.checkMoveAction(itemNode);
  1142. itemNode.highlight();
  1143. // /itemNode.setStyle("background-color", "#faf9f1");
  1144. }.bind(this));
  1145. itemNode.addEvents({
  1146. "mouseover": function (e) { this.setStyle("background-color", "#f1f6fa"); },
  1147. "mouseout": function (e) { this.setStyle("background-color", "#ffffff"); }
  1148. });
  1149. //var droppables = attrchmentsNode.getChildren();
  1150. new Drag(itemNode, {
  1151. "handle": icon,
  1152. "snap": 5,
  1153. "stopPropagation": true,
  1154. "preventDefault": true,
  1155. onStart: function (el, e) {
  1156. var itemNode = el;
  1157. itemNode.setStyle("background-color", "#f1f6fa");
  1158. var moveNode = itemNode.clone(true).setStyles(css.attachmentOrderItemNode).setStyles({
  1159. "background-color": "#faf9f1",
  1160. "opacity": 0.8,
  1161. "border": "1px dotted #333333"
  1162. }).inject(node);
  1163. moveNode.position({
  1164. "relativeTo": itemNode,
  1165. "position": 'upperLeft',
  1166. "edge": 'upperLeft'
  1167. });
  1168. moveNode.owner = itemNode;
  1169. var move = new Drag.Move(moveNode, {
  1170. "container": node,
  1171. "droppables": attrchmentsNode.getChildren(),
  1172. "onEnter": function (el, drop) {
  1173. moveNode.flagNode = new Element("div", { "styles": css.attachmentOrderFlagNode }).inject(drop, "before");
  1174. },
  1175. "onLeave": function (el, drop) {
  1176. if (moveNode.flagNode) moveNode.flagNode.destroy();
  1177. },
  1178. "onDrop": function (el, drop) {
  1179. if (moveNode.flagNode) {
  1180. moveNode.owner.inject(moveNode.flagNode, "after");
  1181. moveNode.flagNode.destroy();
  1182. moveNode.owner.highlight();
  1183. this.checkMoveAction(moveNode.owner);
  1184. this.checkMoveAction(drop);
  1185. this.checkMoveAction(attrchmentsNode.getLast());
  1186. moveNode.destroy()
  1187. }
  1188. }.bind(this)
  1189. });
  1190. move.start(e);
  1191. }.bind(this),
  1192. enter: function (el) {
  1193. el.removeClass('dragging');
  1194. }
  1195. });
  1196. //itemNode.dragMove
  1197. }.bind(this));
  1198. var options = Object.merge({
  1199. "title": lp.attachmentOrderTitle,
  1200. "style": this.module.form.json.dialogStyle || "user",
  1201. "isResize": false,
  1202. "content": node,
  1203. "width": "720",
  1204. "height": "740",
  1205. "container": this.module.form.app.content,
  1206. "maskNode": this.module.form.app.content,
  1207. "buttonList": [
  1208. {
  1209. "type": "ok",
  1210. "text": MWF.LP.process.button.ok,
  1211. "action": function () {
  1212. this.sortAttachment(attrchmentsNode);
  1213. dlg.close();
  1214. }.bind(this)
  1215. },
  1216. {
  1217. "type": "cancel",
  1218. "text": MWF.LP.process.button.cancel,
  1219. "action": function () { dlg.close(); }
  1220. }
  1221. ],
  1222. "onPostLoad": function () {
  1223. var dlg = this;
  1224. dlg.node.setStyle("display", "block");
  1225. var size = {};
  1226. if (css.attachmentOrderNode) {
  1227. if (parseFloat(css.attachmentOrderNode.width).toString() !== "NaN") {
  1228. size.x = parseInt(css.attachmentOrderNode.width)
  1229. }
  1230. if (parseFloat(css.attachmentOrderNode.height).toString() !== "NaN") {
  1231. size.y = parseInt(css.attachmentOrderNode.height)
  1232. }
  1233. }
  1234. node.show();
  1235. var nodeSize = node.getSize();
  1236. dlg.content.setStyles({
  1237. "width": size.x || nodeSize.x,
  1238. "height": size.y || nodeSize.y
  1239. });
  1240. dlg.setContentSize();
  1241. }
  1242. }, (this.module.form.json.dialogOptions||{}));
  1243. if( layout.mobile ){
  1244. var size = $(document.body).getSize();
  1245. options.width = size.x;
  1246. options.height = size.y;
  1247. }
  1248. var dlg = o2.DL.open( options );
  1249. }
  1250. },
  1251. sortAttachment: function (node) {
  1252. var nodes = node.getChildren();
  1253. nodes.each(function (item, idx) {
  1254. var att = item.retrieve("att", null);
  1255. if (att) {
  1256. att.data.orderNumber = idx;
  1257. o2.Actions.load("x_processplatform_assemble_surface").AttachmentAction.changeOrderNumber(att.data.id, this.module.form.businessData.work.id, idx);
  1258. }
  1259. }.bind(this));
  1260. this.attachments = this.attachments.sort(function (a1, a2) {
  1261. if (!a2.data.orderNumber) return 1;
  1262. if (!a1.data.orderNumber) return -1;
  1263. return a1.data.orderNumber - a2.data.orderNumber;
  1264. }.bind(this));
  1265. this.reloadAttachments();
  1266. this.fireEvent("order");
  1267. },
  1268. checkPreviewAttachment: function( e, node, attachments ){
  1269. if( !attachments.length )return;
  1270. var flag = false;
  1271. var att = attachments[0];
  1272. if (this.options.allowPreviewExtension.contains(att.data.extension)) {
  1273. flag = true;
  1274. }
  1275. if (["doc","docx","xls","xlsx","ppt","pptx"].contains(att.data.extension)) {
  1276. flag = true;
  1277. }
  1278. if( flag ){
  1279. this.module.previewAttachment([att])
  1280. }else{
  1281. this.module.openAttachment(e, node, [att])
  1282. }
  1283. },
  1284. addAttachment: function(data, messageId, isCheckPosition){
  1285. if (data.objectSecurityClearance){
  1286. data.objectSecurityPromise = this.getSecurityDefaultLabelList().then(function (list){
  1287. return Object.keys(list).find( function(key){
  1288. return list[key]===data.objectSecurityClearance;
  1289. });
  1290. });
  1291. }
  1292. if (this.options.size=="min"){
  1293. this.attachments.push(new o2.widget.AttachmentController.AttachmentMin(data, this, messageId, isCheckPosition));
  1294. }else{
  1295. this.attachments.push(new o2.widget.AttachmentController.Attachment(data, this, messageId, isCheckPosition));
  1296. }
  1297. this.checkActions();
  1298. },
  1299. downloadBatchAttachment : function () {
  1300. var job = this.module.form.businessData.work.job;
  1301. var site = this.module.json.id;
  1302. var url = "/x_processplatform_assemble_surface/jaxrs/attachment/batch/download/job/" + job + "/site/" + site;
  1303. url = o2.filterUrl(o2.Actions.getHost("x_processplatform_assemble_surface") + url);
  1304. if ((o2.thirdparty.isDingdingPC() || o2.thirdparty.isQywxPC())) {
  1305. url += "&" + o2.tokenName + "=" + layout.session.token;
  1306. window.location = url;
  1307. } else {
  1308. window.open(url);
  1309. }
  1310. }
  1311. });
  1312. /** @class Attachment 附件组件。
  1313. * @o2cn 附件
  1314. * @example
  1315. * //可以在脚本中获取该组件
  1316. * //方法1:
  1317. * var attachment = this.form.get("name"); //获取组件
  1318. * //方法2
  1319. * var attachment = this.target; //在组件事件脚本中获取
  1320. * @extends MWF.xApplication.process.Xform.$Module
  1321. * @o2category FormComponents
  1322. * @o2range {Process|CMS}
  1323. * @hideconstructor
  1324. */
  1325. MWF.xApplication.process.Xform.Attachment = MWF.APPAttachment = new Class(
  1326. /** @lends MWF.xApplication.process.Xform.Attachment# */
  1327. {
  1328. Extends: MWF.APP$Module,
  1329. options: {
  1330. /**
  1331. * @event MWF.xApplication.process.Xform.Attachment#postLoad
  1332. * @ignore
  1333. */
  1334. "moduleEvents": [
  1335. /**附件组件(this.target)加载前触发。
  1336. * @event MWF.xApplication.process.Xform.Attachment#queryLoad
  1337. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  1338. */
  1339. "queryLoad",
  1340. /**附件容器(this.target.attachmentController)初始化之前触发,可以通过this.event获取附件容器的选项。
  1341. * @event MWF.xApplication.process.Xform.Attachment#queryLoadController
  1342. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  1343. */
  1344. "queryLoadController",
  1345. /**附件容器(this.target.attachmentController)初始化之后,加载之前触发。
  1346. * @event MWF.xApplication.process.Xform.Attachment#loadController
  1347. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  1348. */
  1349. "loadController",
  1350. /**附件容器(this.target.attachmentController)加载之后触发,但这时还未加载具体的附件。
  1351. * @event MWF.xApplication.process.Xform.Attachment#postLoadController
  1352. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  1353. */
  1354. "postLoadController",
  1355. /**
  1356. * 附件组件(this.target)加载完成后触发。这时候附件容器和每个附件都已加载完成。
  1357. * @event MWF.xApplication.process.Xform.Attachment#load
  1358. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  1359. */
  1360. "load",
  1361. /**
  1362. * 附件组件(this.target)加载完成后触发。这时候附件容器和每个附件都已加载完成。
  1363. * @event MWF.xApplication.process.Xform.Attachment#afterLoad
  1364. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  1365. */
  1366. "afterLoad",
  1367. /**
  1368. * 加载每个附件前触发。本事件中可以通过this.event获取加载的附件对象
  1369. * @event MWF.xApplication.process.Xform.Attachment#beforeLoadAttachment
  1370. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  1371. */
  1372. "beforeLoadAttachment",
  1373. /**
  1374. * 加载每个附件后触发。本事件中可以通过this.event获取加载的附件对象
  1375. * @event MWF.xApplication.process.Xform.Attachment#loadAttachment
  1376. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  1377. */
  1378. "loadAttachment",
  1379. /**
  1380. * 附件上传前触发。本事件中可以通过this.event获取上传的文件数组
  1381. * @event MWF.xApplication.process.Xform.Attachment#beforeUpload
  1382. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  1383. */
  1384. "beforeUpload",
  1385. /**
  1386. * 附件上传后触发。本事件中可以通过this.event获取上传附件的数据
  1387. * @event MWF.xApplication.process.Xform.Attachment#upload
  1388. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  1389. */
  1390. "upload",
  1391. /**
  1392. * 删除附件前触发。本事件中可以通过this.event获取被删附件的数据
  1393. * @event MWF.xApplication.process.Xform.Attachment#delete
  1394. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  1395. */
  1396. "delete",
  1397. /**
  1398. * 删除附件后触发。本事件中可以通过this.event获取被删附件的数据
  1399. * @event MWF.xApplication.process.Xform.Attachment#afterDelete
  1400. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  1401. */
  1402. "afterDelete",
  1403. /**
  1404. * 附件有变化的时候会被触发,包括上传、替换、删除、排序
  1405. * @event MWF.xApplication.process.Xform.Attachment#change
  1406. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  1407. */
  1408. "change",
  1409. /**
  1410. * 下载附件后触发。本事件中可以通过this.event获取被下载附件对象
  1411. * @event MWF.xApplication.process.Xform.Attachment#download
  1412. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  1413. */
  1414. "download",
  1415. /**
  1416. * 打开附件后触发。本事件中可以通过this.event获取被打开附件对象
  1417. * @event MWF.xApplication.process.Xform.Attachment#open
  1418. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  1419. */
  1420. "open",
  1421. /**
  1422. * 选中附件后触发。本事件中可以通过this.event获取被选中的附件对象
  1423. * @event MWF.xApplication.process.Xform.Attachment#select
  1424. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  1425. */
  1426. "select",
  1427. /**
  1428. * 取消选中附件后触发。本事件中可以通过this.event获取被取消选中的附件对象
  1429. * @event MWF.xApplication.process.Xform.Attachment#unselect
  1430. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  1431. */
  1432. "unselect"
  1433. ]
  1434. },
  1435. initialize: function (node, json, form, options) {
  1436. this.node = $(node);
  1437. this.node.store("module", this);
  1438. this.json = json;
  1439. this.form = form;
  1440. this.field = true;
  1441. this.fieldModuleLoaded = false;
  1442. },
  1443. _loadUserInterface: function () {
  1444. this.node.empty();
  1445. if (this.form.businessData.work.startTime){
  1446. this.loadAttachmentController();
  1447. this.fireEvent("afterLoad");
  1448. }
  1449. this.fieldModuleLoaded = true;
  1450. },
  1451. /** @summary 重新加载附件。会触发queryLoadController、loadController和postLoadController事件。
  1452. * @memberof MWF.xApplication.process.Xform.Attachment
  1453. * @param refresh {Boolean} 是否重新从后台获取附件列表.
  1454. * @example
  1455. * this.form.get("fieldId").reload(); //重新加载
  1456. * @example
  1457. * this.form.get("fieldId").reload( true ); //重新从后台获取附件并重新加载
  1458. */
  1459. reload: function( refresh ){
  1460. this.node.empty();
  1461. if (this.form.businessData.work.startTime){
  1462. if( refresh ){
  1463. var job = (this.form.businessData.work || this.form.businessData.workCompleted ).job;
  1464. o2.Actions.load("x_processplatform_assemble_surface").AttachmentAction.
  1465. listWithJob(job, function(json){
  1466. this.form.businessData.attachmentList = json.data;
  1467. this.loadAttachmentController();
  1468. }.bind(this));
  1469. }else{
  1470. this.loadAttachmentController();
  1471. }
  1472. }
  1473. },
  1474. getFlagDefaultFalse: function( key ){
  1475. if( this.json[key] === "y" || this.json[key] === "true" )return true;
  1476. if( this.json[key] === "hidden" )return "hidden";
  1477. return false;
  1478. },
  1479. getFlagDefaultTrue: function( key ){
  1480. if( this.json[key] === "n" || this.json[key] === "false" )return false;
  1481. if( this.json[key] === "hidden" )return "hidden";
  1482. return true;
  1483. },
  1484. loadAttachmentController: function () {
  1485. //MWF.require("MWF.widget.AttachmentController", function() {
  1486. var options = {
  1487. "style": this.json.style || "default",
  1488. "title": MWF.xApplication.process.Xform.LP.attachmentArea,
  1489. "listStyle": this.json.listStyle || "icon",
  1490. "size": this.json.size || "max",
  1491. "resize": this.getFlagDefaultFalse("resize"),
  1492. "attachmentCount": this.json.attachmentCount || 0,
  1493. "isUpload": this.getFlagDefaultFalse("isUpload"),
  1494. "isDelete": this.getFlagDefaultFalse("isDelete"),
  1495. "isReplace": this.getFlagDefaultFalse("isReplace"),
  1496. "isDownload": this.getFlagDefaultFalse("isDownload"),
  1497. "isDownloadBatch": this.getFlagDefaultFalse("isDownloadBatch"),
  1498. "isPreviewAtt": this.getFlagDefaultFalse("isPreviewAtt"),
  1499. "isEditAtt": this.getFlagDefaultFalse("isEditAtt"),
  1500. "isSizeChange": this.getFlagDefaultFalse("isSizeChange"),
  1501. "isConfig": this.getFlagDefaultTrue("isConfig"),
  1502. "isOrder": this.getFlagDefaultTrue("isOrder"),
  1503. "dblclick": this.json.dblclick,
  1504. "readonly": (this.json.readonly === "y" || this.json.readonly === "true" || this.json.isReadonly || this.form.json.isReadonly),
  1505. "availableListStyles": this.json.availableListStyles ? this.json.availableListStyles : ["list", "seq", "icon", "preview"],
  1506. "isDeleteOption": this.json.isDelete,
  1507. "isReplaceOption": this.json.isReplace,
  1508. "toolbarGroupHidden": this.json.toolbarGroupHidden || [],
  1509. "onOrder": function () {
  1510. this.fireEvent("change");
  1511. this.save();
  1512. }.bind(this)
  1513. };
  1514. if (this.readonly) options.readonly = true;
  1515. if (this.form.json.attachmentStyle) {
  1516. options = Object.merge(options, this.form.json.attachmentStyle);
  1517. }
  1518. //this.attachmentController = new MWF.widget.ATTER(this.node, this, options);
  1519. this.fireEvent("queryLoadController", [options]);
  1520. /**
  1521. * @summary 附件容器.
  1522. * @member {MWF.xApplication.process.Xform.AttachmentController}
  1523. * @example
  1524. * var attachmentController = this.form.get("fieldId").attachmentController; //获取附件容器
  1525. * var attachmentList = attachmentController.attachments; //获取所有的附件
  1526. * var attachmentData = attachmentList[0].data; //获取第一个附件的数据
  1527. */
  1528. this.attachmentController = new MWF.xApplication.process.Xform.AttachmentController(this.node, this, options);
  1529. this.fireEvent("loadController");
  1530. this.attachmentController.load();
  1531. this.fireEvent("postLoadController");
  1532. this.form.businessData.attachmentList.each(function (att) {
  1533. //if (att.site===this.json.id || (this.json.isOpenInOffice && this.json.officeControlName===att.site)) this.attachmentController.addAttachment(att);
  1534. if (att.site === (this.json.site || this.json.id)) this.attachmentController.addAttachment(att);
  1535. }.bind(this));
  1536. this.setAttachmentBusinessData();
  1537. this.addEvent("change", function () {
  1538. if(this.validationMode)this.validationMode();
  1539. }.bind(this))
  1540. //}.bind(this));
  1541. },
  1542. setAttachmentBusinessData: function () {
  1543. if (this.attachmentController) {
  1544. if (this.attachmentController.attachments.length) {
  1545. var values = this.attachmentController.attachments.map(function (d) {
  1546. return d.data.name;
  1547. });
  1548. this._setBusinessData(values);
  1549. } else {
  1550. this._setBusinessData([]);
  1551. }
  1552. }
  1553. },
  1554. save: function(){
  1555. if( this.json.id.indexOf("..") > 0 )return;
  1556. if (this.attachmentController) {
  1557. var values = [];
  1558. if (this.attachmentController.attachments.length) {
  1559. values = this.attachmentController.attachments.map(function (d) {
  1560. return d.data.name;
  1561. });
  1562. }
  1563. var modifedData = {};
  1564. modifedData[ this.json.id ] = values;
  1565. this.form.workAction.saveData(function () {
  1566. if(this.form.businessData.originalData)this.form.businessData.originalData[this.json.id] = values;
  1567. }.bind(this), function(){
  1568. return true;
  1569. }, this.form.businessData.work.id, modifedData, false);
  1570. }
  1571. },
  1572. _loadEvents: function (editorConfig) {
  1573. Object.each(this.json.events, function (e, key) {
  1574. if (e.code) {
  1575. if (this.options.moduleEvents.indexOf(key) !== -1) {
  1576. this.addEvent(key, function (event) {
  1577. return this.form.Macro.fire(e.code, this, event);
  1578. }.bind(this));
  1579. } else {
  1580. this.node.addEvent(key, function (event) {
  1581. return this.form.Macro.fire(e.code, this, event);
  1582. }.bind(this));
  1583. }
  1584. }
  1585. }.bind(this));
  1586. },
  1587. isEmpty : function(){
  1588. var data = this.getData();
  1589. if( typeOf(data) === "array" ){
  1590. return data.length == 0
  1591. }else{
  1592. return !data;
  1593. }
  1594. },
  1595. /**
  1596. * @summary 获取当前组件所有附件的标题.如果没有附件返回null
  1597. * @example
  1598. * var getAttachmentNames = this.form.get("name").getData();
  1599. * @return {StringArray|Null} 附件标题.
  1600. */
  1601. getData: function () {
  1602. return (this.attachmentController) ? this.attachmentController.getAttachmentNames() : null;
  1603. },
  1604. createUploadFileNode: function (files) {
  1605. var accept = "*";
  1606. if (!this.json.attachmentExtType || (this.json.attachmentExtType.indexOf("other") != -1 && !this.json.attachmentExtOtherType)) {
  1607. } else {
  1608. accepts = [];
  1609. var otherType = this.json.attachmentExtOtherType;
  1610. this.json.attachmentExtType.each(function (v) {
  1611. switch (v) {
  1612. case "word":
  1613. accepts.push(".doc, .docx, .dot, .dotx");
  1614. break;
  1615. case "excel":
  1616. accepts.push(".xls, .xlsx, .xlsm, .xlt, .xltx");
  1617. break;
  1618. case "ppt":
  1619. accepts.push(".pptx, .ppt, .pot, .potx, .potm");
  1620. break;
  1621. case "txt":
  1622. accepts.push(".txt");
  1623. break;
  1624. case "pic":
  1625. accepts.push(".bmp, .gif, .psd, .jpeg, .jpg, .png");
  1626. break;
  1627. case "pdf":
  1628. accepts.push(".pdf");
  1629. break;
  1630. case "zip":
  1631. accepts.push(".zip, .rar");
  1632. break;
  1633. case "audio":
  1634. accepts.push(".mp3, .wav, .wma, .wmv, .flac, .ape");
  1635. break;
  1636. case "video":
  1637. accepts.push(".avi, .mkv, .mov, .ogg, .mp4, .mpeg");
  1638. break;
  1639. case "other":
  1640. if (this.json.attachmentExtOtherType) accepts.push(this.json.attachmentExtOtherType);
  1641. break;
  1642. }
  1643. }.bind(this));
  1644. accept = accepts.join(", ");
  1645. }
  1646. var size = 0;
  1647. if (this.json.attachmentSize) size = this.json.attachmentSize.toFloat();
  1648. this.attachmentController.doUploadAttachment({ "site": (this.json.site || this.json.id) }, this.form.workAction.action, "uploadAttachment", { "id": this.form.businessData.work.id }, null, function (o) {
  1649. if (o.id) {
  1650. this.form.workAction.getAttachment(o.id, this.form.businessData.work.id, function (json) {
  1651. if (json.data) {
  1652. if (!json.data.control) json.data.control = {};
  1653. this.form.businessData.attachmentList.push(json.data);
  1654. this.attachmentController.addAttachment(json.data, o.messageId);
  1655. }
  1656. this.attachmentController.checkActions();
  1657. this.setAttachmentBusinessData();
  1658. this.fireEvent("upload", [json.data]);
  1659. this.fireEvent("change");
  1660. this.save();
  1661. }.bind(this))
  1662. }
  1663. this.attachmentController.checkActions();
  1664. }.bind(this), function (files) {
  1665. if (files.length) {
  1666. if ((files.length + this.attachmentController.attachments.length > this.attachmentController.options.attachmentCount) && this.attachmentController.options.attachmentCount > 0) {
  1667. var content = MWF.xApplication.process.Xform.LP.uploadMore;
  1668. content = content.replace("{n}", this.attachmentController.options.attachmentCount);
  1669. this.form.notice(content, "error");
  1670. return false;
  1671. }
  1672. }
  1673. this.uploadingFiles = files;
  1674. if (this.json.uploadValidation && this.json.uploadValidation.code) {
  1675. var flag = this.form.Macro.exec(this.json.uploadValidation.code, this);
  1676. if (!flag) flag = MWF.xApplication.process.Xform.LP.notAttachmentValidation;
  1677. if (flag.toString()!="true"){
  1678. this.form.notice(flag, "error");
  1679. return false;
  1680. }
  1681. }
  1682. this.fireEvent("beforeUpload", [files]);
  1683. return true;
  1684. }.bind(this), true, accept, size, function (o) { //错误的回调
  1685. if (o.messageId && this.attachmentController.messageItemList) {
  1686. var message = this.attachmentController.messageItemList[o.messageId];
  1687. if( message && message.node )message.node.destroy();
  1688. }
  1689. }.bind(this), files);
  1690. },
  1691. uploadAttachment: function (e, node, files) {
  1692. if (window.o2android && window.o2android.postMessage) {
  1693. var body = {
  1694. type: "uploadAttachment",
  1695. data: {
  1696. site: this.json.site || this.json.id
  1697. }
  1698. };
  1699. window.o2android.postMessage(JSON.stringify(body));
  1700. } else if (window.o2android && window.o2android.uploadAttachment) {
  1701. window.o2android.uploadAttachment((this.json.site || this.json.id));
  1702. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.uploadAttachment) {
  1703. window.webkit.messageHandlers.uploadAttachment.postMessage({ "site": (this.json.site || this.json.id) });
  1704. } else {
  1705. // if (!this.uploadFileAreaNode){
  1706. this.createUploadFileNode(files);
  1707. // }
  1708. // this.fileUploadNode.click();
  1709. }
  1710. },
  1711. deleteAttachments: function (e, node, attachments) {
  1712. var names = [];
  1713. attachments.each(function (attachment) {
  1714. names.push(attachment.data.name);
  1715. }.bind(this));
  1716. // if ((window.o2 && window.o2.replaceAttachment) || (window.webkit && window.webkit.messageHandlers)){
  1717. // if (window.confirm(MWF.xApplication.process.Xform.LP.deleteAttachment+"( "+names.join(", ")+" )")){
  1718. // while (attachments.length){
  1719. // attachment = attachments.shift();
  1720. // this.deleteAttachment(attachment);
  1721. // }
  1722. // }
  1723. // }else {
  1724. // var tmpNode = new Element("div", {
  1725. // "styles": {
  1726. // "background-color": "#0000ff",
  1727. // "border-style": "solid",
  1728. // "border-color": "#fff",
  1729. // "border-width": "1",
  1730. // "box-shadow": "0px 0px 20px #999",
  1731. // "z-index": "20000",
  1732. // "overflow": "hidden",
  1733. // "font-size": "14px",
  1734. // "height": "160px",
  1735. // "padding": "0px",
  1736. // "width": "300px",
  1737. // "position": "absolute",
  1738. // "top": "50px",
  1739. // "left": "20px",
  1740. // "opacity": 1,
  1741. // "border-radius": "5px"
  1742. // }
  1743. // }).inject(this.form.app.content);
  1744. var _self = this;
  1745. this.form.confirm("warn", e, MWF.xApplication.process.Xform.LP.deleteAttachmentTitle, MWF.xApplication.process.Xform.LP.deleteAttachment + "( " + o2.txt(names.join(", ")) + " )", 300, 120, function () {
  1746. while (attachments.length) {
  1747. var attachment = attachments.shift();
  1748. _self.deleteAttachment(attachment);
  1749. }
  1750. this.close();
  1751. }, function () {
  1752. this.close();
  1753. }, null, null, this.form.json.confirmStyle);
  1754. },
  1755. editAttachment: function (attachments) {
  1756. var att = attachments[0];
  1757. switch (this.json.officeTool) {
  1758. case "LibreOffice":
  1759. this.editLibreOffice(att);
  1760. break;
  1761. case "OfficeOnline":
  1762. this.editOfficeOnline(att);
  1763. break;
  1764. case "OnlyOffice":
  1765. this.editOnlyOffice(att);
  1766. break;
  1767. case "YozoOffice":
  1768. this.editYozoOffice(att);
  1769. break;
  1770. case "WpsOffice":
  1771. this.editWpsOffice(att);
  1772. break;
  1773. default :
  1774. this.editLibreOffice(att);
  1775. }
  1776. },
  1777. editYozoOffice : function (att){
  1778. var jars ;
  1779. if(att.data.activity){
  1780. jars = "x_processplatform_assemble_surface";
  1781. }
  1782. if(att.data.categoryId){
  1783. jars = "x_cms_assemble_control";
  1784. }
  1785. var options = {
  1786. "documentId": att.data.id,
  1787. "mode":"write",
  1788. "jars" : jars,
  1789. "appId": "YozoOfficeEditor" + att.data.id
  1790. };
  1791. layout.openApplication(null, "YozoOfficeEditor", options);
  1792. },
  1793. editOfficeOnline : function (att){
  1794. var jars ;
  1795. if(att.data.activity){
  1796. jars = "x_processplatform_assemble_surface";
  1797. }
  1798. if(att.data.categoryId){
  1799. jars = "x_cms_assemble_control";
  1800. }
  1801. var options = {
  1802. "documentId": att.data.id,
  1803. "mode":"write",
  1804. "jars" : jars,
  1805. "appId": "OfficeOnlineEditor" + att.data.id
  1806. };
  1807. layout.openApplication(null, "OfficeOnlineEditor", options);
  1808. },
  1809. editOnlyOffice : function (att){
  1810. var jars ;
  1811. if(att.data.activity){
  1812. jars = "x_processplatform_assemble_surface";
  1813. }
  1814. if(att.data.categoryId){
  1815. jars = "x_cms_assemble_control";
  1816. }
  1817. var options = {
  1818. "documentId": att.data.id,
  1819. "mode":"edit",
  1820. "jars" : jars,
  1821. "appId": "OnlyOfficeEditor" + att.data.id
  1822. };
  1823. layout.openApplication(null, "OnlyOfficeEditor", options);
  1824. },
  1825. editWpsOffice : function (att){
  1826. var jars ;
  1827. if(att.data.activity){
  1828. jars = "x_processplatform_assemble_surface";
  1829. }
  1830. if(att.data.categoryId){
  1831. jars = "x_cms_assemble_control";
  1832. }
  1833. var options = {
  1834. "documentId": att.data.id,
  1835. "mode":"write",
  1836. "jars" : jars,
  1837. "appId": "WpsOfficeEditor" + att.data.id
  1838. };
  1839. layout.openApplication(null, "WpsOfficeEditor", options);
  1840. },
  1841. editLibreOffice : function (att){
  1842. this.form.notice("not support");
  1843. },
  1844. previewAttachment: function (attachments) {
  1845. var att = attachments[0];
  1846. new MWF.xApplication.process.Xform.AttachmenPreview(att,this);
  1847. },
  1848. deleteAttachment: function (attachment) {
  1849. this.fireEvent("delete", [attachment.data]);
  1850. var id = attachment.data.id;
  1851. this.form.workAction.deleteAttachment(attachment.data.id, this.form.businessData.work.id, function (josn) {
  1852. this.attachmentController.removeAttachment(attachment);
  1853. this.attachmentController.checkActions();
  1854. for( var i=0; i<this.form.businessData.attachmentList.length; i++ ){
  1855. var attData = this.form.businessData.attachmentList[i];
  1856. if( attData.id === id ){
  1857. this.form.businessData.attachmentList.erase(attData);
  1858. break;
  1859. }
  1860. }
  1861. if (this.form.officeList) {
  1862. this.form.officeList.each(function (office) {
  1863. if (office.openedAttachment) {
  1864. if (office.openedAttachment.id == id) {
  1865. office.loadOfficeEdit();
  1866. }
  1867. }
  1868. }.bind(this));
  1869. }
  1870. this.setAttachmentBusinessData();
  1871. this.fireEvent("afterDelete", [attachment.data]);
  1872. this.fireEvent("change");
  1873. this.save();
  1874. }.bind(this));
  1875. },
  1876. replaceAttachment: function (e, node, attachment) {
  1877. if (window.o2android && window.o2android.postMessage) {
  1878. var body = {
  1879. type: "replaceAttachment",
  1880. data: {
  1881. attachmentId: attachment.data.id,
  1882. site: this.json.site || this.json.id
  1883. }
  1884. };
  1885. window.o2android.postMessage(JSON.stringify(body));
  1886. } else if (window.o2android && window.o2android.replaceAttachment) {
  1887. window.o2android.replaceAttachment(attachment.data.id, (this.json.site || this.json.id));
  1888. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.replaceAttachment) {
  1889. window.webkit.messageHandlers.replaceAttachment.postMessage({ "id": attachment.data.id, "site": (this.json.site || this.json.id) });
  1890. } else {
  1891. var _self = this;
  1892. this.form.confirm("warn", e, MWF.xApplication.process.Xform.LP.replaceAttachmentTitle, MWF.xApplication.process.Xform.LP.replaceAttachment + "( " + attachment.data.name + " )", 350, 120, function () {
  1893. _self.replaceAttachmentFile(attachment);
  1894. this.close();
  1895. }, function () {
  1896. this.close();
  1897. }, null, null, this.form.json.confirmStyle);
  1898. }
  1899. },
  1900. createReplaceFileNode: function (attachment) {
  1901. var accept = "*";
  1902. if (!this.json.attachmentExtType || this.json.attachmentExtType.indexOf("other") != -1 && !this.json.attachmentExtOtherType) {
  1903. } else {
  1904. accepts = [];
  1905. var otherType = this.json.attachmentExtOtherType;
  1906. this.json.attachmentExtType.each(function (v) {
  1907. switch (v) {
  1908. case "word":
  1909. accepts.push(".doc, .docx, .dot, .dotx");
  1910. break;
  1911. case "excel":
  1912. accepts.push(".xls, .xlsx, .xlsm, .xlt, .xltx");
  1913. break;
  1914. case "ppt":
  1915. accepts.push(".pptx, .ppt, .pot, .potx, .potm");
  1916. break;
  1917. case "txt":
  1918. accepts.push(".txt");
  1919. break;
  1920. case "pic":
  1921. accepts.push(".bmp, .gif, .psd, .jpeg, .jpg");
  1922. break;
  1923. case "pdf":
  1924. accepts.push(".pdf");
  1925. break;
  1926. case "zip":
  1927. accepts.push(".zip, .rar");
  1928. break;
  1929. case "audio":
  1930. accepts.push(".mp3, .wav, .wma, .wmv, .flac, .ape");
  1931. break;
  1932. case "video":
  1933. accepts.push(".avi, .mkv, .mov, .ogg, .mp4, .mpeg");
  1934. break;
  1935. case "other":
  1936. if (this.json.attachmentExtOtherType) accepts.push(this.json.attachmentExtOtherType);
  1937. break;
  1938. }
  1939. });
  1940. accept = accepts.join(", ");
  1941. }
  1942. var size = 0;
  1943. if (this.json.attachmentSize) size = this.json.attachmentSize.toFloat();
  1944. this.attachmentController.doUploadAttachment({ "site": (this.json.site || this.json.id) }, this.form.workAction.action, "replaceAttachment",
  1945. { "id": attachment.data.id, "workid": this.form.businessData.work.id }, null, function (o) {
  1946. this.form.workAction.getAttachment(attachment.data.id, this.form.businessData.work.id, function (json) {
  1947. attachment.data = json.data;
  1948. attachment.reload();
  1949. this.fireEvent("change");
  1950. if (o.messageId && this.attachmentController.messageItemList) {
  1951. var message = this.attachmentController.messageItemList[o.messageId];
  1952. if( message && message.node )message.node.destroy();
  1953. }
  1954. this.attachmentController.checkActions();
  1955. this.save();
  1956. }.bind(this))
  1957. }.bind(this), null, true, accept, size, function (o) { //错误的回调
  1958. if (o.messageId && this.attachmentController.messageItemList) {
  1959. var message = this.attachmentController.messageItemList[o.messageId];
  1960. if( message && message.node )message.node.destroy();
  1961. }
  1962. }.bind(this));
  1963. // this.replaceFileAreaNode = new Element("div");
  1964. // var html = "<input name=\"file\" type=\"file\" multiple/>";
  1965. // this.replaceFileAreaNode.set("html", html);
  1966. //
  1967. // this.fileReplaceNode = this.replaceFileAreaNode.getFirst();
  1968. // this.fileReplaceNode.addEvent("change", function(){
  1969. //
  1970. // var files = this.fileReplaceNode.files;
  1971. // if (files.length){
  1972. // for (var i = 0; i < files.length; i++) {
  1973. // var file = files.item(i);
  1974. //
  1975. // var formData = new FormData();
  1976. // formData.append('file', file);
  1977. // // formData.append('site', this.json.id);
  1978. //
  1979. // this.form.workAction.replaceAttachment(attachment.data.id, this.form.businessData.work.id ,function(o, text){
  1980. // this.form.workAction.getAttachment(attachment.data.id, this.form.businessData.work.id, function(json){
  1981. // attachment.data = json.data;
  1982. // attachment.reload();
  1983. // this.attachmentController.checkActions();
  1984. // }.bind(this))
  1985. // }.bind(this), null, formData, file);
  1986. // }
  1987. // }
  1988. // }.bind(this));
  1989. },
  1990. replaceAttachmentFile: function (attachment) {
  1991. //if (!this.replaceFileAreaNode){
  1992. this.createReplaceFileNode(attachment);
  1993. // }
  1994. // this.fileReplaceNode.click();
  1995. },
  1996. queryDownload : function( att ){
  1997. if( this.json.events && this.json.events.queryDownload && this.json.events.queryDownload.code ){
  1998. var flag = this.form.Macro.exec(this.json.events.queryDownload.code, att );
  1999. if( flag === false ){
  2000. return false
  2001. }else{
  2002. return true;
  2003. }
  2004. }else{
  2005. return true;
  2006. }
  2007. },
  2008. queryOpen : function( att ){
  2009. if( this.json.events && this.json.events.queryOpen && this.json.events.queryOpen.code ){
  2010. var flag = this.form.Macro.exec(this.json.events.queryOpen.code, att );
  2011. if( flag === false ){
  2012. return false
  2013. }else{
  2014. return true;
  2015. }
  2016. }else{
  2017. return true;
  2018. }
  2019. },
  2020. //小程序文件是否支持打开
  2021. checkMiniProgramFile: function(ext) {
  2022. var exts = ["doc", "docx", "xls", "xlsx", "ppt", "pptx", "pdf"];
  2023. for(var i = 0; i < exts.length; i++){
  2024. if(ext === exts[i]){
  2025. return true;
  2026. }
  2027. }
  2028. return false;
  2029. },
  2030. addMessage: function(data) {
  2031. if (layout.desktop.message) {
  2032. var msg = {
  2033. "subject": MWF.xApplication.process.Xform.LP.taskProcessed,
  2034. "content": data
  2035. };
  2036. layout.desktop.message.addTooltip(msg);
  2037. return layout.desktop.message.addMessage(msg);
  2038. } else {
  2039. if (this.app.inBrowser) {
  2040. this.inBrowserDkg(data);
  2041. }
  2042. }
  2043. },
  2044. downloadAttachment: function (e, node, attachments) {
  2045. var data = this.form.businessData;
  2046. var isWorkCompleted = data.work && data.work.completedTime;
  2047. var workId = data.work.id;
  2048. var actionUrl = "getAttachmentUrl";
  2049. var actionData = "getAttachmentStream";
  2050. var urlWorkKey = "work";
  2051. if (isWorkCompleted){
  2052. workId = (data.workCompleted) ? data.workCompleted.id : workId;
  2053. actionUrl = "getAttachmentWorkcompletedUrl";
  2054. actionData = "getWorkcompletedAttachmentStream";
  2055. urlWorkKey = "workCompleted";
  2056. }
  2057. var client = this.getDownloadAttachmentClientType();
  2058. console.log(client+" 客户端");
  2059. attachments.each(function (att) {
  2060. if( !this.queryDownload( att ) )return;
  2061. switch (client){
  2062. case "flutter":
  2063. var body = {
  2064. type: "downloadAttachment",
  2065. data: {
  2066. attachmentId: att.data.id
  2067. }
  2068. };
  2069. window.o2android.postMessage(JSON.stringify(body));
  2070. break
  2071. case "android":
  2072. window.o2android.downloadAttachment(att.data.id);
  2073. break;
  2074. case "ios":
  2075. window.webkit.messageHandlers.downloadAttachment.postMessage({ "id": att.data.id, "site": (this.json.site || this.json.id) });
  2076. break;
  2077. case "wx":
  2078. if(this.checkMiniProgramFile(att.data.extension)) {
  2079. wx.miniProgram.navigateTo({
  2080. url: '../file/download?attId=' + att.data.id + '&type=work&'+urlWorkKey+'=' + workId
  2081. });
  2082. }
  2083. break;
  2084. case "mobile":
  2085. this.form.workAction[actionUrl](att.data.id, workId, function (url) {
  2086. var xtoken = layout.session.token;
  2087. // window.location = o2.filterUrl(url + "?"+o2.tokenName+"=" + xtoken);
  2088. window.location = url + "?"+o2.tokenName+"=" + xtoken;
  2089. });
  2090. break;
  2091. case "pcClient":
  2092. this.form.workAction[actionUrl](att.data.id, workId, function (url) {
  2093. var xtoken = layout.session.token;
  2094. // window.location = o2.filterUrl(url + "?"+o2.tokenName+"=" + xtoken);
  2095. window.location = url + "?"+o2.tokenName+"=" + xtoken;
  2096. });
  2097. break;
  2098. default:
  2099. this.form.workAction[actionData](att.data.id, workId);
  2100. }
  2101. this.fireEvent("download",[att]);
  2102. }.bind(this));
  2103. },
  2104. getDownloadAttachmentClientType: function(){
  2105. if (window.o2android && window.o2android.postMessage) {
  2106. return "flutter";
  2107. }
  2108. if (window.o2android && window.o2android.downloadAttachment){
  2109. return "android";
  2110. }
  2111. if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.downloadAttachment){
  2112. return "ios";
  2113. }
  2114. if (window.wx && window.__wxjs_environment === 'miniprogram'){
  2115. return "wx";
  2116. }
  2117. if (layout.mobile){
  2118. return "mobile";
  2119. }
  2120. if (o2.thirdparty.isDingdingPC() || o2.thirdparty.isQywxPC()){
  2121. return "pcClient";
  2122. }
  2123. return "pc";
  2124. },
  2125. openAttachment: function (e, node, attachments) {
  2126. var data = this.form.businessData;
  2127. var isWorkCompleted = data.work && data.work.completedTime;
  2128. var workId = data.work.id;
  2129. var actionUrl = "getAttachmentUrl";
  2130. var actionData = "getAttachmentData";
  2131. var urlWorkKey = "work";
  2132. if (isWorkCompleted){
  2133. workId = (data.workCompleted) ? data.workCompleted.id : workId;
  2134. actionUrl = "getAttachmentWorkcompletedUrl";
  2135. actionData = "getWorkcompletedAttachmentData";
  2136. urlWorkKey = "workCompleted";
  2137. }
  2138. var client = this.getDownloadAttachmentClientType();
  2139. console.log(client+" 客户端");
  2140. attachments.each(function (att) {
  2141. if( !this.queryOpen( att ) )return;
  2142. switch (client){
  2143. case "flutter":
  2144. var body = {
  2145. type: "downloadAttachment",
  2146. data: {
  2147. attachmentId: att.data.id
  2148. }
  2149. };
  2150. window.o2android.postMessage(JSON.stringify(body));
  2151. break
  2152. case "android":
  2153. window.o2android.downloadAttachment(att.data.id);
  2154. break;
  2155. case "ios":
  2156. window.webkit.messageHandlers.downloadAttachment.postMessage({ "id": att.data.id, "site": (this.json.site || this.json.id) });
  2157. break;
  2158. case "wx":
  2159. if(this.checkMiniProgramFile(att.data.extension)) {
  2160. wx.miniProgram.navigateTo({
  2161. url: '../file/download?attId=' + att.data.id + '&type=work&'+urlWorkKey+'=' + workId
  2162. });
  2163. }
  2164. break;
  2165. case "mobile":
  2166. this.form.workAction[actionUrl](att.data.id, workId, function (url) {
  2167. var xtoken = layout.session.token;
  2168. // window.location = o2.filterUrl(url + "?"+o2.tokenName+"=" + xtoken);
  2169. window.location = url + "?"+o2.tokenName+"=" + xtoken;
  2170. });
  2171. break;
  2172. case "pcClient":
  2173. this.form.workAction[actionUrl](att.data.id, workId, function (url) {
  2174. var xtoken = layout.session.token;
  2175. // window.location = o2.filterUrl(url + "?"+o2.tokenName+"=" + xtoken);
  2176. window.location = url + "?"+o2.tokenName+"=" + xtoken;
  2177. });
  2178. break;
  2179. default:
  2180. this.form.workAction[actionData](att.data.id, workId);
  2181. }
  2182. this.fireEvent("open",[att]);
  2183. }.bind(this));
  2184. },
  2185. getAttachmentUrl: function (attachment, callback) {
  2186. if (this.form.businessData.work && !this.form.businessData.work.completedTime) {
  2187. this.form.workAction.getAttachmentUrl(attachment.data.id, this.form.businessData.work.id, callback);
  2188. } else {
  2189. this.form.workAction.getAttachmentWorkcompletedUrl(attachment.data.id, this.form.businessData.workCompleted.id, callback);
  2190. }
  2191. },
  2192. getTextData: function(){
  2193. var data = [];
  2194. this.attachmentController.attachments.each(function(att){
  2195. var o = {
  2196. "id": att.data.id,
  2197. "person": att.data.person,
  2198. "creatorUid": att.data.creatorUid,
  2199. "name": att.data.name,
  2200. "orderNumber": att.data.orderNumber,
  2201. "length": att.data.length,
  2202. "extension": att.data.extension,
  2203. "lastUpdateTime": att.data.lastUpdateTime,
  2204. "activityName": att.data.activityName,
  2205. "control" : att.data.control
  2206. }
  2207. data.push(o);
  2208. });
  2209. return data;
  2210. },
  2211. /**
  2212. * @summary 为组件重新设置附件,该附件必须已经上传。
  2213. * @param data {Array}.
  2214. * <pre><code class='language-js'>[{
  2215. * "id": "56c4e86f-a4c8-4cc2-a150-1a0d2c5febcb", //附件ID
  2216. * "name": "133203a2-92e6-4653-9954-161b72ddb7f9.png", //附件名称
  2217. * "extension": "png", //附件扩展名
  2218. * "length": 43864, //附件大小
  2219. * "person": "xx@huqi@P", //附件上传人
  2220. * "lastUpdateTime": "2018-09-27 15:50:34", //最后的修改时间
  2221. * "lastUpdatePerson": "xx@huqi@P", //最后的修改人
  2222. * "activity": "e31ad938-c495-45a6-8d77-b8a9b61a165b", //附件上传的活动ID
  2223. * "activityName": "申请人", //附件上传的活动名称
  2224. * "activityType": "manual", //附件上传的活动类型
  2225. * "site": "$mediaOpinion", //附件存储位置(一般用于区分附件在哪个表单元素中显示)
  2226. * "type": "image/png", //附件类型(contentType)
  2227. * "control": {}
  2228. * }]</code></pre>
  2229. */
  2230. setData: function(data){
  2231. this.attachmentController.clear();
  2232. ( data || [] ).each(function (att) {
  2233. var attachment = this.form.businessData.attachmentList.find(function(a){
  2234. return a.id==att.id;
  2235. });
  2236. var attData = attachment || att;
  2237. this.attachmentController.addAttachment(attData);
  2238. }.bind(this));
  2239. this.setAttachmentBusinessData();
  2240. },
  2241. createErrorNode: function (text) {
  2242. var node = new Element("div");
  2243. var iconNode = new Element("div", {
  2244. "styles": {
  2245. "width": "20px",
  2246. "height": "20px",
  2247. "float": "left",
  2248. "background": "url(" + "../x_component_process_Xform/$Form/default/icon/error.png) center center no-repeat"
  2249. }
  2250. }).inject(node);
  2251. var textNode = new Element("div", {
  2252. "styles": {
  2253. "line-height": "20px",
  2254. "margin-left": "20px",
  2255. "color": "red",
  2256. "word-break": "keep-all"
  2257. },
  2258. "text": text
  2259. }).inject(node);
  2260. return node;
  2261. },
  2262. notValidationMode: function (text) {
  2263. if (!this.isNotValidationMode) {
  2264. this.isNotValidationMode = true;
  2265. this.node.store("borderStyle", this.node.getStyles("border-left", "border-right", "border-top", "border-bottom"));
  2266. this.node.setStyle("border", "1px solid red");
  2267. this.errNode = this.createErrorNode(text).inject(this.node, "after");
  2268. this.showNotValidationMode(this.node);
  2269. var parentNode = this.errNode;
  2270. while( parentNode && parentNode.offsetParent === null ){
  2271. parentNode = parentNode.getParent();
  2272. }
  2273. if ( parentNode && !parentNode.isIntoView()) parentNode.scrollIntoView(false);
  2274. }
  2275. },
  2276. showNotValidationMode: function (node) {
  2277. var p = node.getParent("div");
  2278. if (p) {
  2279. if (p.get("MWFtype") == "tab$Content") {
  2280. if (p.getParent("div").getStyle("display") == "none") {
  2281. var contentAreaNode = p.getParent("div").getParent("div");
  2282. var tabAreaNode = contentAreaNode.getPrevious("div");
  2283. var idx = contentAreaNode.getChildren().indexOf(p.getParent("div"));
  2284. var tabNode = tabAreaNode.getLast().getFirst().getChildren()[idx];
  2285. tabNode.click();
  2286. p = tabAreaNode.getParent("div");
  2287. }
  2288. }
  2289. this.showNotValidationMode(p);
  2290. }
  2291. },
  2292. validationMode: function () {
  2293. if (this.isNotValidationMode) {
  2294. this.isNotValidationMode = false;
  2295. this.node.setStyles(this.node.retrieve("borderStyle"));
  2296. if (this.errNode) {
  2297. this.errNode.destroy();
  2298. this.errNode = null;
  2299. }
  2300. }
  2301. },
  2302. validationConfigItem: function (routeName, data) {
  2303. var flag = (data.status == "all") ? true : (routeName == data.decision);
  2304. if (flag) {
  2305. var n = this.getData() || [];
  2306. var v = (data.valueType == "value") ? n : n.length;
  2307. switch (data.operateor) {
  2308. case "isnull":
  2309. if (!v) {
  2310. this.notValidationMode(data.prompt);
  2311. return false;
  2312. }
  2313. break;
  2314. case "notnull":
  2315. if (v) {
  2316. this.notValidationMode(data.prompt);
  2317. return false;
  2318. }
  2319. break;
  2320. case "gt":
  2321. if (v > data.value) {
  2322. this.notValidationMode(data.prompt);
  2323. return false;
  2324. }
  2325. break;
  2326. case "lt":
  2327. if (v < data.value) {
  2328. this.notValidationMode(data.prompt);
  2329. return false;
  2330. }
  2331. break;
  2332. case "equal":
  2333. if (v == data.value) {
  2334. this.notValidationMode(data.prompt);
  2335. return false;
  2336. }
  2337. break;
  2338. case "neq":
  2339. if (v != data.value) {
  2340. this.notValidationMode(data.prompt);
  2341. return false;
  2342. }
  2343. break;
  2344. case "contain":
  2345. if (v.indexOf(data.value) != -1) {
  2346. this.notValidationMode(data.prompt);
  2347. return false;
  2348. }
  2349. break;
  2350. case "notcontain":
  2351. if (v.indexOf(data.value) == -1) {
  2352. this.notValidationMode(data.prompt);
  2353. return false;
  2354. }
  2355. break;
  2356. }
  2357. }
  2358. return true;
  2359. },
  2360. validationConfig: function (routeName, opinion) {
  2361. if (this.json.validationConfig) {
  2362. if (this.json.validationConfig.length) {
  2363. for (var i = 0; i < this.json.validationConfig.length; i++) {
  2364. var data = this.json.validationConfig[i];
  2365. if (!this.validationConfigItem(routeName, data)) return false;
  2366. }
  2367. }
  2368. return true;
  2369. }
  2370. return true;
  2371. },
  2372. getExcelData: function(){
  2373. return "";
  2374. },
  2375. setExcelData: function(data){
  2376. },
  2377. });
  2378. MWF.xApplication.process.Xform.AttachmenPreview = new Class({
  2379. Implements: [Options, Events],
  2380. initialize : function(att,app ){
  2381. this.att = att;
  2382. this.app = app;
  2383. this.load();
  2384. },
  2385. load:function(){
  2386. var extension = this.att.data.extension;
  2387. if(extension === "ofd"){
  2388. //ofd预览暂时屏蔽ie,等兼容性改好了开启
  2389. if(Browser.name!=="ie"){
  2390. this.previewOfd();
  2391. }
  2392. }
  2393. if(extension === "zip"){
  2394. this.previewZip();
  2395. }
  2396. if(extension === "pdf"){
  2397. this.previewPdf();
  2398. }
  2399. if(["doc","docx","xls","xlsx","ppt","pptx"].contains(extension)){
  2400. this.previewOffice();
  2401. }
  2402. if(["png","jpg","bmp","jpeg","gif"].contains(extension)){
  2403. this.previewImage();
  2404. }
  2405. if(extension === "js"){
  2406. this.previewAce("javascript");
  2407. }
  2408. if(extension === "css"){
  2409. this.previewAce("css");
  2410. }
  2411. if(extension === "java"){
  2412. this.previewAce("java");
  2413. }
  2414. if(extension === "json"){
  2415. this.previewAce("json");
  2416. }
  2417. if(extension === "xml"){
  2418. this.previewAce("xml");
  2419. }
  2420. if(extension === "php"){
  2421. this.previewAce("php");
  2422. }
  2423. if(["html","htm","xhtml"].contains(extension)){
  2424. this.previewAce("html");
  2425. }
  2426. if(["log","md","txt"].contains(extension)){
  2427. this.previewAce("text");
  2428. }
  2429. },
  2430. previewZip: function () {
  2431. //zip压缩包预览
  2432. var _self = this;
  2433. var zipViewNode = new Element("div",{"text":"loadding..."});
  2434. o2.load(["../o2_lib/jszip/jszip.min.js", "../o2_lib/jszip/jszip-utils.min.js"], function () {
  2435. this.app.getAttachmentUrl(this.att, function (url) {
  2436. var width, height;
  2437. if( layout.mobile ){
  2438. var size = $(document.body).getSize();
  2439. width = size.x+"px";
  2440. height = size.y+"px";
  2441. }else{
  2442. width = "660px";
  2443. height = "510px";
  2444. }
  2445. o2.require("MWF.widget.Tree", function(){
  2446. var dlg = o2.DL.open({
  2447. "title": _self.att.data.name,
  2448. "width": width,
  2449. "height": height,
  2450. "mask": true,
  2451. "content": zipViewNode,
  2452. "container": null,
  2453. "positionNode": document.body,
  2454. "onQueryClose": function () {
  2455. zipViewNode.destroy();
  2456. },
  2457. "buttonList": [
  2458. {
  2459. "text": "关闭",
  2460. "action": function () {
  2461. dlg.close();
  2462. }
  2463. }
  2464. ],
  2465. "onPostShow": function () {
  2466. dlg.reCenter();
  2467. },
  2468. "onPostLoad" : function(){
  2469. }
  2470. });
  2471. }.bind(this));
  2472. zipViewNode.empty();
  2473. JSZipUtils.getBinaryContent(url, function (err, data) {
  2474. JSZip.loadAsync(data).then(function (zip) {
  2475. var nodeList = [];
  2476. zip.forEach(function (relativePath, zipEntry) {
  2477. nodeList.push(zipEntry.name);
  2478. });
  2479. var tree = new MWF.widget.Tree(zipViewNode, {"style":"form"});
  2480. var treeData = _pathToTree(nodeList);
  2481. tree.load(treeData);
  2482. });
  2483. });
  2484. }.bind(this));
  2485. }.bind(this));
  2486. function _pathToTree(pathList) {
  2487. var pathJsonList = [];
  2488. for (var i = 0; i < pathList.length; i++) {
  2489. var chain = pathList[i].split("/");
  2490. var currentNode = pathJsonList;
  2491. for (var j = 0; j < chain.length; j++) {
  2492. if (chain[j] === "") {
  2493. break;
  2494. }
  2495. var wantedNode = chain[j];
  2496. var lastNode = currentNode;
  2497. for (var k = 0; k < currentNode.length; k++) {
  2498. if (currentNode[k].name == wantedNode) {
  2499. currentNode = currentNode[k].sub;
  2500. break;
  2501. }
  2502. }
  2503. if (lastNode == currentNode) {
  2504. var obj = {
  2505. key: pathList[i],
  2506. name: wantedNode,
  2507. title:wantedNode,
  2508. text:wantedNode,
  2509. sub: []
  2510. };
  2511. var newNode = (currentNode[k] = obj);
  2512. if (wantedNode.indexOf(".") > -1) {
  2513. obj.dir = false;
  2514. obj.icon = "file.png";
  2515. delete obj.sub;
  2516. } else {
  2517. obj.dir = true;
  2518. obj.expand = false;
  2519. currentNode = newNode.sub;
  2520. //delete obj.sub;
  2521. }
  2522. } else {
  2523. delete currentNode.sub;
  2524. }
  2525. }
  2526. }
  2527. var nodes = [];
  2528. var folder = {
  2529. "title" : _self.att.name,
  2530. "text" : _self.att.name,
  2531. "sub" : []
  2532. };
  2533. pathJsonList.each(function(path){
  2534. folder.sub.push(path);
  2535. })
  2536. _sortPath(folder, nodes);
  2537. return nodes;
  2538. }
  2539. function _sortPath(pathJsonList, nodes) {
  2540. var folderList = [];
  2541. pathJsonList.sub.each(function (file) {
  2542. if (file.dir) {
  2543. folderList.push(file);
  2544. }
  2545. });
  2546. pathJsonList.sub.each(function (file) {
  2547. if (!file.dir) {
  2548. folderList.push(file);
  2549. }
  2550. });
  2551. folderList.each(function (file) {
  2552. var node = {
  2553. text: file.name,
  2554. title: file.name,
  2555. expand : false
  2556. };
  2557. if (!file.dir) {
  2558. node.icon = "file.png";
  2559. }
  2560. nodes.push(node);
  2561. if(file.sub && file.sub.length>0){
  2562. node.sub = [];
  2563. _sortPath(file,node.sub);
  2564. }
  2565. })
  2566. }
  2567. },
  2568. previewPdf : function(){
  2569. this.app.getAttachmentUrl(this.att, function (url) {
  2570. if(layout.mobile){
  2571. location.href = "../o2_lib/pdfjs/web/viewer.html?file=" + url;
  2572. }else{
  2573. window.open("../o2_lib/pdfjs/web/viewer.html?file=" + url);
  2574. } });
  2575. },
  2576. previewOffice : function(){
  2577. switch (this.app.json.officeTool) {
  2578. case "LibreOffice":
  2579. this.previewLibreOffice();
  2580. break;
  2581. case "OfficeOnline":
  2582. this.previewOfficeOnline();
  2583. break;
  2584. case "OnlyOffice":
  2585. this.previewOnlyOffice();
  2586. break;
  2587. case "YozoOffice":
  2588. this.previewYozoOffice();
  2589. break;
  2590. case "WpsOffice":
  2591. this.previewWpsOffice();
  2592. break;
  2593. default :
  2594. this.previewLibreOffice();
  2595. }
  2596. },
  2597. previewOfficeOnline : function (){
  2598. var att = this.att;
  2599. var jars ;
  2600. if(att.data.activity){
  2601. jars = "x_processplatform_assemble_surface";
  2602. }
  2603. if(att.data.categoryId){
  2604. jars = "x_cms_assemble_control";
  2605. }
  2606. var options = {
  2607. "documentId": att.data.id,
  2608. "mode":"view",
  2609. "jars" : jars,
  2610. "appId": "OfficeOnlineEditor" + att.data.id
  2611. };
  2612. layout.openApplication(null, "OfficeOnlineEditor", options);
  2613. },
  2614. previewOnlyOffice : function (){
  2615. var att = this.att;
  2616. var jars ;
  2617. if(att.data.activity){
  2618. jars = "x_processplatform_assemble_surface";
  2619. }
  2620. if(att.data.categoryId){
  2621. jars = "x_cms_assemble_control";
  2622. }
  2623. var options = {
  2624. "documentId": att.data.id,
  2625. "mode":"view",
  2626. "jars" : jars,
  2627. "appId": "OnlyOfficeEditor" + att.data.id
  2628. };
  2629. layout.openApplication(null, "OnlyOfficeEditor", options);
  2630. },
  2631. previewYozoOffice : function (){
  2632. var att = this.att;
  2633. var jars ;
  2634. if(att.data.activity){
  2635. jars = "x_processplatform_assemble_surface";
  2636. }
  2637. if(att.data.categoryId){
  2638. jars = "x_cms_assemble_control";
  2639. }
  2640. var options = {
  2641. "documentId": att.data.id,
  2642. "mode":"view",
  2643. "jars" : jars,
  2644. "appId": "YozoOfficeEditor" + att.data.id
  2645. };
  2646. layout.openApplication(null, "YozoOfficeEditor", options);
  2647. },
  2648. previewWpsOffice : function (){
  2649. var att = this.att;
  2650. var jars ;
  2651. if(att.data.activity){
  2652. jars = "x_processplatform_assemble_surface";
  2653. }
  2654. if(att.data.categoryId){
  2655. jars = "x_cms_assemble_control";
  2656. }
  2657. var options = {
  2658. "documentId": att.data.id,
  2659. "mode":"view",
  2660. "jars" : jars,
  2661. "appId": "WpsOfficeEditor" + att.data.id
  2662. };
  2663. layout.openApplication(null, "WpsOfficeEditor", options);
  2664. },
  2665. previewLibreOffice : function (){
  2666. if(!layout.serviceAddressList["x_libreoffice_assemble_control"]){
  2667. this.app.form.notice("Please Install LibreOffice");
  2668. return;
  2669. }
  2670. var srv = layout.serviceAddressList["x_libreoffice_assemble_control"];
  2671. var module;
  2672. if(this.att.data.activity){
  2673. module = "processPlatform";
  2674. }
  2675. if(this.att.data.categoryId){
  2676. module = "cms";
  2677. }
  2678. var defaultPort = layout.config.app_protocol === 'https' ? "443" : "80";
  2679. var appPort = srv.port || window.location.port;
  2680. var protocol = layout.config.app_protocol || window.location.protocol;
  2681. var hostname = srv.host || window.location.hostname;
  2682. var context = srv.context || '';
  2683. var url = protocol + "//" + hostname + (appPort && appPort.toString() !== defaultPort ? ":" + appPort : "") + context + "/jaxrs/office/doc/to/pdf/" + module + "/" + this.att.data.id;
  2684. window.open("../o2_lib/pdfjs/web/viewer.html?file=" + encodeURIComponent(url));
  2685. },
  2686. previewOfd : function(){
  2687. this.app.getAttachmentUrl(this.att, function (url) {
  2688. window.open("../o2_lib/ofdjs/index.html?file=" + url)
  2689. });
  2690. },
  2691. previewImage : function(){
  2692. this.app.getAttachmentUrl(this.att, function (url) {
  2693. var imgNode = new Element("img",{"src":url,"alt":this.att.name}).inject(document.body).hide();
  2694. o2.loadCss("../o2_lib/viewer/viewer.css", document.body,function(){
  2695. o2.load("../o2_lib/viewer/viewer.js", function(){
  2696. this.viewer = new Viewer(imgNode,{
  2697. navbar : false,
  2698. toolbar : true,
  2699. hidden : function(){
  2700. imgNode.destroy();
  2701. this.viewer.destroy();
  2702. }.bind(this)
  2703. });
  2704. this.viewer.show();
  2705. }.bind(this));
  2706. }.bind(this));
  2707. }.bind(this));
  2708. },
  2709. previewAce:function(type){
  2710. this.app.getAttachmentUrl(this.att, function (url) {
  2711. o2.require("o2.widget.ace", null, false);
  2712. var fileRequest = new Request({
  2713. url: url,
  2714. method: 'get',
  2715. withCredentials: true,
  2716. onSuccess: function(responseText){
  2717. var editorNode = new Element("div",{"style":"padding:10px"});
  2718. editorNode.set("text",responseText);
  2719. o2.widget.ace.load(function(){
  2720. o2.load("../o2_lib/ace/src-min-noconflict/ext-static_highlight.js", function(){
  2721. var highlight = ace.require("ace/ext/static_highlight");
  2722. highlight(editorNode, {mode: "ace/mode/"+ type , theme: "ace/theme/tomorrow", "fontSize": 30,"showLineNumbers":true});
  2723. }.bind(this));
  2724. }.bind(this));
  2725. var width, height;
  2726. if( layout.mobile ){
  2727. var size = $(document.body).getSize();
  2728. width = size.x+"px";
  2729. height = size.y+"px";
  2730. }else{
  2731. width = "960px";
  2732. height = "610px";
  2733. }
  2734. var dlg = o2.DL.open({
  2735. "title": this.att.data.name,
  2736. "width": width,
  2737. "height": height,
  2738. "mask": true,
  2739. "content": editorNode,
  2740. "container": null,
  2741. "positionNode": document.body,
  2742. "onQueryClose": function () {
  2743. editorNode.destroy();
  2744. }.bind(this),
  2745. "buttonList": [
  2746. {
  2747. "text": "关闭",
  2748. "action": function () {
  2749. dlg.close();
  2750. }.bind(this)
  2751. }
  2752. ],
  2753. "onPostShow": function () {
  2754. dlg.reCenter();
  2755. }.bind(this)
  2756. });
  2757. }.bind(this),
  2758. onFailure: function(){
  2759. console.log('text', 'Sorry, your request failed :(');
  2760. }
  2761. });
  2762. fileRequest.send();
  2763. }.bind(this));
  2764. },
  2765. });
  2766. MWF.xApplication.process.Xform.AttachmentDg = MWF.APPAttachmentDg = new Class({
  2767. Extends: MWF.APPAttachment,
  2768. loadAttachmentController: function () {
  2769. //MWF.require("MWF.widget.AttachmentController", function() {
  2770. var options = {
  2771. "style": this.json.style || "default",
  2772. "title": MWF.xApplication.process.Xform.LP.attachmentArea,
  2773. "listStyle": this.json.listStyle || "icon",
  2774. "size": this.json.size || "max",
  2775. "resize": this.getFlagDefaultFalse("resize"),
  2776. "attachmentCount": this.json.attachmentCount || 0,
  2777. "isUpload": this.getFlagDefaultFalse("isUpload"),
  2778. "isDelete": this.getFlagDefaultFalse("isDelete"),
  2779. "isReplace": this.getFlagDefaultFalse("isReplace"),
  2780. "isDownload": this.getFlagDefaultFalse("isDownload"),
  2781. "isDownloadBatch": "hidden", //this.getFlagDefaultFalse("isDownloadBatch"),
  2782. "isPreviewAtt": this.getFlagDefaultFalse("isPreviewAtt"),
  2783. "isEditAtt": this.getFlagDefaultFalse("isEditAtt"),
  2784. "isSizeChange": this.getFlagDefaultFalse("isSizeChange"),
  2785. "isConfig": this.getFlagDefaultTrue("isConfig"),
  2786. "isOrder": this.getFlagDefaultTrue("isOrder"),
  2787. "dblclick": this.json.dblclick,
  2788. "readonly": (this.json.readonly === "y" || this.json.readonly === "true" || this.json.isReadonly || this.form.json.isReadonly),
  2789. "availableListStyles": this.json.availableListStyles ? this.json.availableListStyles : ["list", "seq", "icon", "preview"],
  2790. "isDeleteOption": this.json.isDelete,
  2791. "isReplaceOption": this.json.isReplace,
  2792. "toolbarGroupHidden": this.json.toolbarGroupHidden || [],
  2793. "ignoreSite": this.json.ignoreSite,
  2794. "onOrder": function () {
  2795. this.fireEvent("change");
  2796. }.bind(this)
  2797. };
  2798. if (this.readonly) options.readonly = true;
  2799. if (this.form.json.attachmentStyle) {
  2800. options = Object.merge(options, this.form.json.attachmentStyle);
  2801. }
  2802. this.fireEvent("queryLoadController", [options]);
  2803. this.attachmentController = new MWF.xApplication.process.Xform.AttachmentController(this.node, this, options);
  2804. this.fireEvent("loadController");
  2805. this.attachmentController.load();
  2806. this.fireEvent("postLoadController");
  2807. // var d = this._getBusinessData();
  2808. // if (d) d.each(function (att) {
  2809. // this.attachmentController.addAttachment(att);
  2810. // }.bind(this));
  2811. if(this.json.ignoreSite) {
  2812. ( this._getBusinessData() || [] ).each(function (att) {
  2813. var flag = this.form.businessData.attachmentList.some(function (attData) {
  2814. return (att.businessId && att.businessId === attData.businessId) || att.id === attData.id;
  2815. }.bind(this));
  2816. if(flag)this.attachmentController.addAttachment(att);
  2817. }.bind(this));
  2818. }else{
  2819. this.form.businessData.attachmentList.each(function (att) {
  2820. if (att.site === (this.json.site || this.json.id)) this.attachmentController.addAttachment(att);
  2821. }.bind(this));
  2822. }
  2823. this.setAttachmentBusinessData();
  2824. },
  2825. setAttachmentBusinessData: function(){
  2826. if (this.attachmentController) {
  2827. if (this.attachmentController.attachments.length) {
  2828. var values = this.attachmentController.attachments.map(function (d) {
  2829. return {
  2830. "control": d.data.control,
  2831. "name": d.data.name,
  2832. "id": d.data.id,
  2833. "businessId": d.data.businessId,
  2834. "person": d.data.person,
  2835. "creatorUid": d.data.creatorUid,
  2836. "orderNumber": d.data.orderNumber,
  2837. "length": d.data.length,
  2838. "extension": d.data.extension,
  2839. "lastUpdateTime": d.data.lastUpdateTime,
  2840. "activityName": d.data.activityName
  2841. };
  2842. });
  2843. this._setBusinessData(values);
  2844. } else {
  2845. this._setBusinessData([]);
  2846. }
  2847. }
  2848. },
  2849. uploadAttachment: function (e, node, files) {
  2850. if (window.o2android && window.o2android.postMessage) {
  2851. var body = {
  2852. type: "uploadAttachmentForDatagrid",
  2853. data: {
  2854. param: this.json.id,
  2855. site: this.json.site || this.json.id
  2856. }
  2857. };
  2858. window.o2android.postMessage(JSON.stringify(body));
  2859. } else if (window.o2android && window.o2android.uploadAttachmentForDatagrid) {
  2860. window.o2android.uploadAttachmentForDatagrid((this.json.site || this.json.id), this.json.id);
  2861. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.uploadAttachmentForDatagrid) {
  2862. window.webkit.messageHandlers.uploadAttachmentForDatagrid.postMessage({ "site": (this.json.site || this.json.id) , "param":this.json.id});
  2863. } else {
  2864. // if (!this.uploadFileAreaNode){
  2865. this.createUploadFileNode(files);
  2866. // }
  2867. // this.fileUploadNode.click();
  2868. }
  2869. },
  2870. replaceAttachment: function (e, node, attachment) {
  2871. if (window.o2android && window.o2android.postMessage) {
  2872. var body = {
  2873. type: "replaceAttachmentForDatagrid",
  2874. data: {
  2875. attachmentId: attachment.data.id,
  2876. param: this.json.id,
  2877. site: this.json.site || this.json.id,
  2878. businessId: attachment.data.businessId
  2879. }
  2880. };
  2881. window.o2android.postMessage(JSON.stringify(body));
  2882. } else if (window.o2android && window.o2android.replaceAttachmentForDatagrid) {
  2883. window.o2android.replaceAttachmentForDatagrid(attachment.data.id, (this.json.site || this.json.id), this.json.id);
  2884. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.replaceAttachmentForDatagrid) {
  2885. window.webkit.messageHandlers.replaceAttachmentForDatagrid.postMessage({ "id": attachment.data.id, "site": (this.json.site || this.json.id) , "param":this.json.id});
  2886. } else {
  2887. var _self = this;
  2888. this.form.confirm("warn", e, MWF.xApplication.process.Xform.LP.replaceAttachmentTitle, MWF.xApplication.process.Xform.LP.replaceAttachment + "( " + attachment.data.name + " )", 350, 120, function () {
  2889. _self.replaceAttachmentFile(attachment);
  2890. this.close();
  2891. }, function () {
  2892. this.close();
  2893. }, null, null, this.form.json.confirmStyle);
  2894. }
  2895. }
  2896. });