Attachment.js 133 KB

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