Documenteditor.js 189 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155
  1. MWF.xDesktop.requireApp("process.Xform", "$Module", null, false);
  2. /** @class Documenteditor 公文编辑器。
  3. * @o2cn 公文编辑器
  4. * @example
  5. * //可以在脚本中获取该组件
  6. * //方法1:
  7. * var documenteditor = this.form.get("fieldId"); //获取组件
  8. * //方法2
  9. * var documenteditor = this.target; //在组件事件脚本中获取
  10. * @extends MWF.xApplication.process.Xform.$Module
  11. * @o2category FormComponents
  12. * @o2range {Process}
  13. * @hideconstructor
  14. */
  15. MWF.xApplication.process.Xform.Documenteditor = MWF.APPDocumenteditor = new Class(
  16. /** @lends MWF.xApplication.process.Xform.Documenteditor# */
  17. {
  18. Extends: MWF.APP$Module,
  19. options: {
  20. /**
  21. * 当公文编辑器内容每次被渲染的时候都会触发。
  22. * @event MWF.xApplication.process.Xform.Documenteditor#loadPage
  23. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  24. */
  25. "moduleEvents": ["load", "queryLoad", "beforeLoad", "postLoad", "afterLoad", "loadPage", "fullScreen", "returnScreen", "pagePosition"],
  26. "docPageHeight": 850.4,
  27. "docPageFullWidth": 794,
  28. "pageShow": "single"
  29. },
  30. initialize: function(node, json, form, options){
  31. this.node = $(node);
  32. this.node.store("module", this);
  33. this.json = json;
  34. this.form = form;
  35. this.field = true;
  36. this.fieldModuleLoaded = false;
  37. },
  38. _loadCss: function(reload){
  39. var key = encodeURIComponent(this.cssPath);
  40. if (!reload && o2.widget.css[key]){
  41. this.css = o2.widget.css[key];
  42. }else{
  43. this.cssPath = (this.cssPath.indexOf("?")!=-1) ? this.cssPath+"&v="+o2.version.v : this.cssPath+"?v="+o2.version.v;
  44. var r = new Request.JSON({
  45. url: this.cssPath,
  46. secure: false,
  47. async: false,
  48. method: "get",
  49. noCache: false,
  50. onSuccess: function(responseJSON, responseText){
  51. this.css = responseJSON;
  52. o2.widget.css[key] = responseJSON;
  53. }.bind(this),
  54. onError: function(text, error){
  55. console.log(error + text);
  56. }
  57. });
  58. r.send();
  59. }
  60. },
  61. load: function(){
  62. if (!this.json.isDelay){
  63. this.active();
  64. }
  65. },
  66. /**
  67. * 激活公文编辑器编辑。设置了延迟加载的时候,可以通过这个方法来激活
  68. * @example
  69. * this.form.get("fieldId").active();
  70. */
  71. active: function(){
  72. this._loadModuleEvents();
  73. if (this.fireEvent("queryLoad")){
  74. this.fireEvent("beforeLoad");
  75. this.cssPath = this.form.path+this.form.options.style+"/doc.wcss";
  76. this._loadCss();
  77. this._queryLoaded();
  78. this._loadUserInterface(function(){
  79. this.fieldModuleLoaded = true;
  80. this.fireEvent("postLoad");
  81. this.fireEvent("afterLoad");
  82. this.fireEvent("load");
  83. this.form.app.addEvent("resize", function(){
  84. // if (this.options.pageShow!=="double"){
  85. // this._doublePage();
  86. // }else{
  87. this._singlePage();
  88. // }
  89. // this.scaleTo(this.scale);
  90. // this._checkScale();
  91. }.bind(this));
  92. o2.UD.getDataJson("documenteditorScale", function(json){
  93. if (json){
  94. this.scaleTo(json.scale);
  95. this.documenteditorScale = json.scale
  96. }
  97. // if (this.documenteditorScale) this.scaleTo(this.documenteditorScale);
  98. // this.addEvent("loadPage", function(){
  99. // if (this.documenteditorScale) this.scaleTo(this.documenteditorScale);
  100. // }.bind(this));
  101. this._checkScale();
  102. }.bind(this));
  103. }.bind(this));
  104. this._loadStyles();
  105. this._afterLoaded();
  106. }
  107. },
  108. _createNewPage: function(){
  109. var pageNode = new Element("div.doc_layout_page", {"styles": this.css.doc_page}).inject(this.contentNode);
  110. var pageContentNode = new Element("div.doc_layout_page_content", {"styles": this.css.doc_layout_page_content}).inject(pageNode);
  111. pageNode.set("data-pagecount", this.pages.length+1);
  112. this.pages.push(pageNode);
  113. return pageNode;
  114. },
  115. _getShow: function(name, typeItem, scriptItem){
  116. switch (this.json[typeItem]) {
  117. case "y":
  118. return true;
  119. case "n":
  120. return false;
  121. case "a":
  122. if (["copies", "secret", "priority", "attachment", "annotation"].indexOf(name!=-1)){
  123. if (o2.typeOf(this.data[name])=="string"){
  124. var v = this.data[name].trim();
  125. return !!v && (!!v.length);
  126. }else{
  127. return !!this.data[name] && (!!this.data[name].length);
  128. }
  129. }
  130. return true;
  131. case "s":
  132. if (this.json[scriptItem] && this.json[scriptItem].code){
  133. return !!this.form.Macro.exec(this.json[scriptItem].code, this);
  134. }
  135. return true;
  136. default:
  137. return true;
  138. }
  139. },
  140. _loadCssStyle: function(){
  141. if (this.json.css && this.json.css.code && !this.styleNode){
  142. var cssText = this.form.parseCSS(this.json.css.code);
  143. cssText = cssText.replace(/documenteditor_table/g, 'documenteditor_table'+this.form.json.id+this.json.id);
  144. var styleNode = document.createElement("style");
  145. styleNode.setAttribute("type", "text/css");
  146. styleNode.id="style"+this.json.id;
  147. styleNode.inject(this.node, "top");
  148. if(styleNode.styleSheet){
  149. var setFunc = function(){
  150. if(styleNode.styleSheet.disabled){
  151. setTimeout(setFunc, 100);
  152. }else{
  153. styleNode.styleSheet.cssText = cssText;
  154. }
  155. };
  156. setFunc();
  157. }else{
  158. var cssTextNode = document.createTextNode(cssText);
  159. styleNode.appendChild(cssTextNode);
  160. }
  161. this.styleNode = styleNode;
  162. }
  163. },
  164. _createPage: function(callback, callbackAftreLoad){
  165. var control = this.getShowControl();
  166. this.json.fileup = !!(control.signer);
  167. this._loadCssStyle();
  168. var url = (this.json.documentTempleteType==="cus") ?
  169. this.json.documentTempleteUrl :
  170. "../x_component_process_FormDesigner/Module/Documenteditor/templete/"+(this.json.documentTempleteName || "standard")+".html";
  171. url = url+((url.indexOf("?")!==-1) ? "&" : "?")+"v="+o2.version.v;
  172. this._clearCopytoTrs();
  173. fetch(o2.filterUrl(url)).then(function(res){
  174. return res.text();
  175. }).then(function(html){
  176. this.contentNode.empty();
  177. if (this.filetextEditor) this.filetextEditor.destroy();
  178. if (this.attachmentTextEditor) this.attachmentTextEditor.destroy();
  179. this.editMode = false;
  180. // this.historyMode = false;
  181. var pageContentNode = this._createNewPage().getFirst();
  182. pageContentNode.set("html", html);
  183. if (this.attachmentTemplete){
  184. var attNode = pageContentNode.getElement(".doc_layout_attachment_content");
  185. if (attNode) attNode.empty();
  186. }
  187. if (callback) callback(control);
  188. this.fireEvent("loadPage");
  189. if (callbackAftreLoad) callbackAftreLoad(control);
  190. }.bind(this));
  191. },
  192. _clearCopytoTrs: function(){
  193. if (this.layout_copytoContentTr){
  194. this.layout_copytoContentTr.destroy();
  195. this.layout_copytoContentTr = null;
  196. }
  197. if (this.layout_copytoContentTrP){
  198. this.layout_copytoContentTrP.destroy();
  199. this.layout_copytoContentTrP = null;
  200. }
  201. if (this.layout_copyto2ContentTr){
  202. this.layout_copyto2ContentTr.destroy();
  203. this.layout_copyto2ContentTr = null;
  204. }
  205. if (this.layout_copyto2ContentTrP){
  206. this.layout_copyto2ContentTrP.destroy();
  207. this.layout_copyto2ContentTrP = null;
  208. }
  209. },
  210. getTempleteJson: function(callback){
  211. if (this.templeteJson){
  212. if (callback) callback();
  213. }else{
  214. o2.getJSON(o2.filterUrl("../x_component_process_FormDesigner/Module/Documenteditor/templete/templete.json"), function(json){
  215. this.templeteJson = json;
  216. if (callback) callback();
  217. }.bind(this));
  218. }
  219. },
  220. getShowControl: function(){
  221. var control = {};
  222. control.copiesSecretPriority = this._getShow("copiesSecretPriority", "copiesSecretPriorityShow", "copiesSecretPriorityShowScript");
  223. control.copies = this._getShow("copies", "copiesShow", "copiesShowScript");
  224. control.secret = this._getShow("secret", "secretShow", "secretShowScript");
  225. control.priority = this._getShow("priority", "priorityShow", "priorityShowScript");
  226. control.redHeader = this._getShow("redHeader", "redHeaderShow", "redHeaderShowScript");
  227. control.redLine = this._getShow("redLine", "redLineShow", "redLineShowScript");
  228. control.signer = this._getShow("signer", "signerShow", "signerShowScript");
  229. control.fileno = this._getShow("fileno", "filenoShow", "filenoShowScript");
  230. control.subject = this._getShow("subject", "subjectShow", "subjectShowScript");
  231. control.mainSend = this._getShow("mainSend", "mainSendShow", "mainSendShowScript");
  232. control.attachment = this._getShow("attachment", "attachmentShow", "attachmentShowScript");
  233. control.issuanceUnit = this._getShow("issuanceUnit", "issuanceUnitShow", "issuanceUnitShowScript");
  234. control.issuanceDate = this._getShow("issuanceDate", "issuanceDateShow", "issuanceDateShowScript");
  235. control.annotation = this._getShow("annotation", "annotationShow", "annotationShowScript");
  236. control.copyto = this._getShow("copyto", "copytoShow", "copytoShowScript");
  237. control.copyto2 = this._getShow("copyto2", "copyto2Show", "copyto2ShowScript");
  238. control.editionUnit = this._getShow("editionUnit", "editionUnitShow", "editionUnitShowScript");
  239. control.editionDate = this._getShow("editionDate", "editionDateShow", "editionDateShowScript");
  240. control.meetingAttend = this._getShow("meetingAttend", "meetingAttendShow", "meetingAttendShowScript");
  241. control.meetingLeave = this._getShow("meetingLeave", "meetingLeaveShow", "meetingLeaveShowScript");
  242. control.meetingSit = this._getShow("meetingSit", "meetingSitShow", "meetingSitShowScript");
  243. control.meetingRecord = this._getShow("meetingRecord", "meetingRecordShow", "meetingRecordShowScript");
  244. this.json.fileup = !!(control.signer);
  245. return control;
  246. },
  247. getEditControl: function(){
  248. var control = {};
  249. control.copies = this._getEdit("copies", "copiesEdit", "copiesEditScript");
  250. control.secret = this._getEdit("secret", "secretEdit", "secretEditScript");
  251. control.priority = this._getEdit("priority", "priorityEdit", "priorityEditScript");
  252. control.redHeader = this._getEdit("redHeader", "redHeaderEdit", "redHeaderEditScript");
  253. control.signer = this._getEdit("signer", "signerEdit", "signerEditScript");
  254. control.fileno = this._getEdit("fileno", "filenoEdit", "filenoEditScript");
  255. control.subject = this._getEdit("subject", "subjectEdit", "subjectEditScript");
  256. control.mainSend = this._getEdit("mainSend", "mainSendEdit", "mainSendEditScript");
  257. control.attachment = this._getEdit("attachment", "attachmentEdit", "attachmentEditScript");
  258. control.attachmentText = this._getEdit("attachmentText", "attachmentTextEdit", "attachmentTextEditScript");
  259. control.issuanceUnit = this._getEdit("issuanceUnit", "issuanceUnitEdit", "issuanceUnitEditScript");
  260. control.issuanceDate = this._getEdit("issuanceDate", "issuanceDateEdit", "issuanceDateEditScript");
  261. control.annotation = this._getEdit("annotation", "annotationEdit", "annotationEditScript");
  262. control.copyto = this._getEdit("copyto", "copytoEdit", "copytoEditScript");
  263. control.copyto2 = this._getEdit("copyto2", "copyto2Edit", "copyto2EditScript");
  264. control.editionUnit = this._getEdit("editionUnit", "editionUnitEdit", "editionUnitEditScript");
  265. control.editionDate = this._getEdit("editionDate", "editionDateEdit", "editionDateEditScript");
  266. control.meetingAttend = this._getShow("meetingAttend", "meetingAttendEdit", "meetingAttendEditScript");
  267. control.meetingLeave = this._getShow("meetingLeave", "meetingLeaveEdit", "meetingLeaveEditScript");
  268. control.meetingSit = this._getShow("meetingSit", "meetingSitEdit", "meetingSitEditScript");
  269. control.meetingRecord = this._getShow("meetingRecord", "meetingRecordEdit", "meetingRecordEditScript");
  270. return control;
  271. },
  272. //份数 密级 紧急程度
  273. _loadCopiesSecretPriority: function(){
  274. this.layout_copiesSecretPriority = this.contentNode.getElement(".doc_layout_copiesSecretPriority");
  275. if (this.layout_copiesSecretPriority) this.layout_copiesSecretPriority.setStyles(this.css.doc_layout_copiesSecretPriority);
  276. /**
  277. * @summary 份数的dom对象.
  278. * @member {MWF.xApplication.process.Xform.Documenteditor}
  279. */
  280. this.layout_copies = this.contentNode.getElement(".doc_layout_copies");
  281. if (this.layout_copies) this.layout_copies.setStyles(this.css.doc_layout_copies);
  282. /**
  283. * @summary 密级的dom对象.
  284. * @member {MWF.xApplication.process.Xform.Documenteditor}
  285. */
  286. this.layout_secret = this.contentNode.getElement(".doc_layout_secret");
  287. if (this.layout_secret) this.layout_secret.setStyles(this.css.doc_layout_secret);
  288. /**
  289. * @summary 紧急度的dom对象.
  290. * @member {MWF.xApplication.process.Xform.Documenteditor}
  291. */
  292. this.layout_priority = this.contentNode.getElement(".doc_layout_priority");
  293. if (this.layout_priority) this.layout_priority.setStyles(this.css.doc_layout_priority);
  294. this.layout_copiesSecretPriority_blank = this.contentNode.getElement(".doc_layout_copiesSecretPriority_blank");
  295. },
  296. //红头
  297. _loadRedHeader: function(){
  298. /**
  299. * @summary 红头的dom对象.
  300. * @member {MWF.xApplication.process.Xform.Documenteditor}
  301. */
  302. this.layout_redHeader = this.contentNode.getElement(".doc_layout_redHeader");
  303. if (this.layout_redHeader) this.layout_redHeader.setStyles(this.css.doc_layout_redHeader);
  304. },
  305. //文号签发人(上行文)
  306. _loadFileNoUp: function(){
  307. this.layout_filenoArea = this.contentNode.getElement(".doc_layout_fileno_area");
  308. this.layout_fileNoUpTable = this.contentNode.getElement(".doc_layout_filenoup");
  309. if (this.layout_fileNoUpTable) this.layout_fileNoUpTable.setStyles(this.css.doc_layout_filenoup);
  310. var td = this.contentNode.getElement(".doc_layout_filenoup_fileno_td");
  311. if (td) td.setStyles(this.css.doc_layout_filenoup_fileno_td);
  312. /**
  313. * @summary 文号的dom对象.
  314. * @member {MWF.xApplication.process.Xform.Documenteditor}
  315. */
  316. this.layout_fileno = this.contentNode.getElement(".doc_layout_filenoup_fileno");
  317. if (this.layout_fileno) this.layout_fileno.setStyles(this.css.doc_layout_filenoup_fileno);
  318. td = this.contentNode.getElement(".doc_layout_filenoup_signer_td");
  319. if (td) td.setStyles(this.css.doc_layout_filenoup_signer_td);
  320. var node = this.contentNode.getElement(".doc_layout_filenoup_signer_table");
  321. if (node) node.setStyles(this.css.doc_layout_filenoup_signer_table);
  322. node = this.contentNode.getElement(".doc_layout_filenoup_signerTitle_td");
  323. if (node) node.setStyles(this.css.doc_layout_filenoup_signerTitle_td);
  324. this.layout_signerTitle = this.contentNode.getElement(".doc_layout_filenoup_signer");
  325. if (this.layout_signerTitle) this.layout_signerTitle.setStyles(this.css.doc_layout_filenoup_signer);
  326. node = this.contentNode.getElement(".doc_layout_filenoup_signerContent_td");
  327. if (node) node.setStyles(this.css.doc_layout_filenoup_signerContent_td);
  328. /**
  329. * @summary 签发人的dom对象.
  330. * @member {MWF.xApplication.process.Xform.Documenteditor}
  331. */
  332. this.layout_signer = this.contentNode.getElement(".doc_layout_filenoup_signerContent");
  333. if (this.layout_signer) this.layout_signer.setStyles(this.css.doc_layout_filenoup_signerContent);
  334. if (!this.layout_fileno){
  335. this.layout_fileNoUpTable = this.contentNode.getElement(".doc_layout_filenoup");
  336. this.layout_filenoArea = this.contentNode.getElement(".doc_layout_fileno_area");
  337. this.layout_fileno = this.contentNode.getElement(".doc_layout_fileno");
  338. if (this.layout_fileno) this.layout_fileno.setStyles(this.css.doc_layout_fileno);
  339. }
  340. },
  341. //文号
  342. _loadFileNo: function(){
  343. this.layout_fileNoUpTable = this.contentNode.getElement(".doc_layout_filenoup");
  344. this.layout_filenoArea = this.contentNode.getElement(".doc_layout_fileno_area");
  345. this.layout_fileno = this.contentNode.getElement(".doc_layout_fileno");
  346. if (this.layout_fileno) this.layout_fileno.setStyles(this.css.doc_layout_fileno);
  347. td = this.contentNode.getElement(".doc_layout_filenoup_signer_td");
  348. if (td) td.setStyles(this.css.doc_layout_filenoup_signer_td);
  349. var node = this.contentNode.getElement(".doc_layout_filenoup_signer_table");
  350. if (node) node.setStyles(this.css.doc_layout_filenoup_signer_table);
  351. node = this.contentNode.getElement(".doc_layout_filenoup_signerTitle_td");
  352. if (node) node.setStyles(this.css.doc_layout_filenoup_signerTitle_td);
  353. this.layout_signerTitle = this.contentNode.getElement(".doc_layout_filenoup_signer");
  354. if (this.layout_signerTitle) this.layout_signerTitle.setStyles(this.css.doc_layout_filenoup_signer);
  355. node = this.contentNode.getElement(".doc_layout_filenoup_signerContent_td");
  356. if (node) node.setStyles(this.css.doc_layout_filenoup_signerContent_td);
  357. this.layout_signer = this.contentNode.getElement(".doc_layout_filenoup_signerContent");
  358. if (this.layout_signer) this.layout_signer.setStyles(this.css.doc_layout_filenoup_signerContent);
  359. if (!this.layout_fileno){
  360. this.layout_filenoArea = this.contentNode.getElement(".doc_layout_fileno_area");
  361. this.layout_fileNoUpTable = this.contentNode.getElement(".doc_layout_filenoup");
  362. if (this.layout_fileNoUpTable) this.layout_fileNoUpTable.setStyles(this.css.doc_layout_filenoup);
  363. var td = this.contentNode.getElement(".doc_layout_filenoup_fileno_td");
  364. if (td) td.setStyles(this.css.doc_layout_filenoup_fileno_td);
  365. this.layout_fileno = this.contentNode.getElement(".doc_layout_filenoup_fileno");
  366. if (this.layout_fileno) this.layout_fileno.setStyles(this.css.doc_layout_filenoup_fileno);
  367. }
  368. },
  369. //红线
  370. _loadRedLine: function(){
  371. this.layout_redLine = this.contentNode.getElement(".doc_layout_redline");
  372. if (this.layout_redLine) this.layout_redLine.setStyles(this.css.doc_layout_redline);
  373. },
  374. //标题
  375. _loadSubject:function(){
  376. /**
  377. * @summary 标题的dom对象.
  378. * @member {MWF.xApplication.process.Xform.Documenteditor}
  379. */
  380. this.layout_subject = this.contentNode.getElement(".doc_layout_subject");
  381. if (this.layout_subject) this.layout_subject.setStyles(this.css.doc_layout_subject);
  382. if (this.json.subjectFontFamily){
  383. if (this.layout_subject) this.layout_subject.setStyle("font-family", this.json.subjectFontFamily);
  384. }
  385. },
  386. //主送
  387. _loadMainSend: function(){
  388. /**
  389. * @summary 主送的dom对象.
  390. * @member {MWF.xApplication.process.Xform.Documenteditor}
  391. */
  392. this.layout_mainSend = this.contentNode.getElement(".doc_layout_mainSend");
  393. if (this.layout_mainSend) this.layout_mainSend.setStyles(this.css.doc_layout_mainSend);
  394. },
  395. //正文
  396. // _createFiletext: function(filetextNode, node, where){
  397. // if (!filetextNode){
  398. // var filetextNode = new Element("div.doc_layout_filetext").inject(node, where);
  399. // filetextNode.addClass("doc_block");
  400. // filetextNode.setAttribute('contenteditable', true);
  401. // }
  402. // CKEDITOR.disableAutoInline = true;
  403. // var filetextEditor = CKEDITOR.inline(filetextNode, this._getEditorConfig());
  404. // filetextNode.store("editor", filetextEditor);
  405. // if (!this.filetextEditors) this.filetextEditors = [];
  406. // this.filetextEditors.push(filetextEditor);
  407. //
  408. // filetextEditor.on( 'blur', function(e) {
  409. // // var filetextNode = e.editor.container.$;
  410. // // var pageNode = filetextNode.getParent(".doc_layout_page");
  411. // // this._checkSplitPage(pageNode);
  412. // // this._repage();
  413. // }.bind(this));
  414. //
  415. // return filetextNode;
  416. // },
  417. _loadFiletext: function(){
  418. /**
  419. * @summary 正文区域的dom对象.
  420. * @member {MWF.xApplication.process.Xform.Documenteditor}
  421. */
  422. this.layout_filetext = this.contentNode.getElement(".doc_layout_filetext");
  423. this.layout_filetext.addClass("css"+this.form.json.id+this.json.id);
  424. this.layout_filetext.setStyles(this.css.doc_layout_filetext);
  425. //this.layout_filetext = this.contentNode.getElement(".doc_layout_filetext");
  426. // if (this.layout_filetexts.length){
  427. // this.layout_filetexts.each(function(layout_filetext){
  428. // layout_filetext.setStyles(this.css.doc_layout_filetext);
  429. // }.bind(this));
  430. // }
  431. },
  432. //附件
  433. _loadAttachment: function(){
  434. this.layout_attachmentTable = this.contentNode.getElement(".doc_layout_attachment");
  435. if (this.layout_attachmentTable) this.layout_attachmentTable.setStyles(this.css.doc_layout_attachment);
  436. var node = this.contentNode.getElement(".doc_layout_attachment_title_td");
  437. if (node) node.setStyles(this.css.doc_layout_attachment_title_td);
  438. this.layout_attachmentTitle = this.contentNode.getElement(".doc_layout_attachment_title");
  439. if (node) node.setStyles(this.css.doc_layout_attachment_title);
  440. node = this.contentNode.getElement(".doc_layout_attachment_content_td");
  441. if (node) node.setStyles(this.css.doc_layout_attachment_content_td);
  442. /**
  443. * @summary 附件区域的dom对象.
  444. * @member {MWF.xApplication.process.Xform.Documenteditor}
  445. */
  446. this.layout_attachment = this.contentNode.getElement(".doc_layout_attachment_content");
  447. if (this.layout_attachment) this.layout_attachment.setStyles(this.css.doc_layout_attachment_content);
  448. },
  449. //发布单位
  450. _loadIssuance: function(){
  451. this.layout_issuanceTable = this.contentNode.getElement(".doc_layout_issuance");
  452. /**
  453. * @summary 发文单位的dom对象.
  454. * @member {MWF.xApplication.process.Xform.Documenteditor}
  455. */
  456. this.layout_issuanceUnit = this.contentNode.getElement(".doc_layout_issuanceUnit");
  457. /**
  458. * @summary 发文时间的dom对象.
  459. * @member {MWF.xApplication.process.Xform.Documenteditor}
  460. */
  461. this.layout_issuanceDate = this.contentNode.getElement(".doc_layout_issuanceDate");
  462. if (this.layout_issuanceTable) this.layout_issuanceTable.setStyles(this.css.doc_layout_issuance);
  463. if (this.layout_issuanceUnit) this.layout_issuanceUnit.setStyles(this.css.doc_layout_issuanceUnit);
  464. if (this.layout_issuanceDate) this.layout_issuanceDate.setStyles(this.css.doc_layout_issuanceDate);
  465. },
  466. //附注
  467. _loadAnnotation: function(){
  468. /**
  469. * @summary 附注的dom对象.
  470. * @member {MWF.xApplication.process.Xform.Documenteditor}
  471. */
  472. this.layout_annotation = this.contentNode.getElement(".doc_layout_annotation");
  473. if (this.layout_annotation) this.layout_annotation.setStyles(this.css.doc_layout_annotation);
  474. },
  475. //附件文本
  476. _loadAttachmentText: function(){
  477. this.layout_attachmentText = this.contentNode.getElement(".doc_layout_attachment_text");
  478. },
  479. //版记
  480. _loadEdition: function(){
  481. this.layout_editionArea = this.contentNode.getElement(".doc_layout_editionArea");
  482. this.layout_edition = this.contentNode.getElement(".doc_layout_edition");
  483. if (this.layout_edition) this.layout_edition.setStyles(this.css.doc_layout_edition);
  484. var node = this.contentNode.getElement(".doc_layout_edition_copyto");
  485. if (node) node.setStyles(this.css.doc_layout_edition_copyto);
  486. node = this.contentNode.getElement(".doc_layout_edition_copyto_table");
  487. if (node) node.setStyles(this.css.doc_layout_edition_copyto_table);
  488. var node = this.contentNode.getElement(".doc_layout_edition_copyto2");
  489. if (node) node.setStyles(this.css.doc_layout_edition_copyto);
  490. node = this.contentNode.getElement(".doc_layout_edition_copyto2_table");
  491. if (node) node.setStyles(this.css.doc_layout_edition_copyto_table);
  492. this.layout_copytoTitle = this.contentNode.getElement(".doc_layout_edition_copyto_title");
  493. if (this.layout_copytoTitle) this.layout_copytoTitle.setStyles(this.css.doc_layout_edition_copyto_title);
  494. /**
  495. * @summary 抄送的dom对象.
  496. * @member {MWF.xApplication.process.Xform.Documenteditor}
  497. */
  498. this.layout_copytoContent = this.contentNode.getElement(".doc_layout_edition_copyto_content");
  499. if (this.layout_copytoContent) this.layout_copytoContent.setStyles(this.css.doc_layout_edition_copyto_content);
  500. this.layout_copyto2Title = this.contentNode.getElement(".doc_layout_edition_copyto2_title");
  501. if (this.layout_copyto2Title) this.layout_copyto2Title.setStyles(this.css.doc_layout_edition_copyto_title);
  502. this.layout_copyto2Content = this.contentNode.getElement(".doc_layout_edition_copyto2_content");
  503. if (this.layout_copyto2Content) this.layout_copyto2Content.setStyles(this.css.doc_layout_edition_copyto_content);
  504. var issuance = this.contentNode.getElement(".doc_layout_edition_issuance");
  505. if (issuance) issuance.setStyles(this.css.doc_layout_edition_issuance);
  506. var issuance_table = this.contentNode.getElement(".doc_layout_edition_issuance_table");
  507. if (issuance_table) issuance_table.setStyles(this.css.doc_layout_edition_issuance_table);
  508. /**
  509. * @summary 印发单位的dom对象.
  510. * @member {MWF.xApplication.process.Xform.Documenteditor}
  511. */
  512. this.layout_edition_issuance_unit = this.contentNode.getElement(".doc_layout_edition_issuance_unit");
  513. if (this.layout_edition_issuance_unit) this.layout_edition_issuance_unit.setStyles(this.css.doc_layout_edition_issuance_unit);
  514. /**
  515. * @summary 印发时间的dom对象.
  516. * @member {MWF.xApplication.process.Xform.Documenteditor}
  517. */
  518. this.layout_edition_issuance_date = this.contentNode.getElement(".doc_layout_edition_issuance_date");
  519. if (this.layout_edition_issuance_date) this.layout_edition_issuance_date.setStyles(this.css.doc_layout_edition_issuance_date);
  520. },
  521. loadSeal: function(){
  522. /**
  523. * @summary 模拟盖章的dom对象.
  524. * @member {MWF.xApplication.process.Xform.Documenteditor}
  525. */
  526. this.layout_seals = this.contentNode.getElements(".doc_layout_seal");
  527. this.layout_seals.each(function(node){
  528. // if (!node.get("src")){
  529. node.hide();
  530. // }else{
  531. // node.show();
  532. // node.setStyles({
  533. // "border": "0",
  534. // "border-radius": "0"
  535. // });
  536. // }
  537. });
  538. },
  539. /**对正文进行模拟盖章(模板中必须有class为“doc_layout_seal”的img对象)
  540. * @summary 对正文进行模拟盖章,此方法只是进行模拟盖章,通过图片显示,并非专业盖章,不具备法律效应。
  541. * * @param src{String} 盖章图片的url.
  542. * @param position{integer} 要盖章的位置, 默认为0.
  543. * @example
  544. * this.form.get("documenteditor").seal("../custom/img/seal.png", 0); //在第一个盖章位置进行模拟盖章
  545. */
  546. seal: function(src, position){
  547. var p = position || 0;
  548. if (this.layout_seals && this.layout_seals.length){
  549. if (this.layout_seals[p]){
  550. this.layout_seals[p].src = src;
  551. this.layout_seals[p].show();
  552. this.layout_seals[p].setStyles({
  553. "border": "0",
  554. "border-radius": "0",
  555. "z-index": -1
  556. });
  557. }
  558. this.getSealData();
  559. }
  560. },
  561. _loadMeeting: function(){
  562. this.layout_meetingAttendArea = this.contentNode.getElement(".doc_layout_meeting_attend");
  563. this.layout_meetingAttendTitle = this.contentNode.getElement(".doc_layout_meeting_attend_title");
  564. this.layout_meetingAttendContent = this.contentNode.getElement(".doc_layout_meeting_attend_content");
  565. this.layout_meetingLeaveArea = this.contentNode.getElement(".doc_layout_meeting_leave");
  566. this.layout_meetingLeaveTitle = this.contentNode.getElement(".doc_layout_meeting_leave_title");
  567. this.layout_meetingLeaveContent = this.contentNode.getElement(".doc_layout_meeting_leave_content");
  568. this.layout_meetingSitArea = this.contentNode.getElement(".doc_layout_meeting_sit");
  569. this.layout_meetingSitTitle = this.contentNode.getElement(".doc_layout_meeting_sit_title");
  570. this.layout_meetingSitContent = this.contentNode.getElement(".doc_layout_meeting_sit_content");
  571. this.layout_meetingRecordArea = this.contentNode.getElement(".doc_layout_meeting_record");
  572. this.layout_meetingRecordTitle = this.contentNode.getElement(".doc_layout_meeting_record_title");
  573. this.layout_meetingRecordContent = this.contentNode.getElement(".doc_layout_meeting_record_content");
  574. },
  575. _loadCustom: function(){
  576. var nodes = this.contentNode.getElements(".doc_layout");
  577. nodes.each(function(node){
  578. var name = node.get("data-doc-layout");
  579. if (!this.customLayouts) this.customLayouts = [];
  580. this.customLayouts.push({
  581. "name": name,
  582. "node": node,
  583. });
  584. this[name] = node;
  585. }.bind(this));
  586. },
  587. _loadPageLayout: function(control){
  588. this._loadCopiesSecretPriority();
  589. this._loadRedHeader();
  590. if (this.json.fileup){
  591. this._loadFileNoUp();
  592. }else{
  593. this._loadFileNo();
  594. }
  595. if (!this.layout_fileno) this._loadFileNo();
  596. this._loadRedLine();
  597. this._loadSubject();
  598. this._loadMainSend();
  599. this._loadFiletext();
  600. this._loadAttachment();
  601. this._loadIssuance();
  602. this._loadAnnotation();
  603. this._loadAttachmentText()
  604. this._loadEdition();
  605. this.loadSeal();
  606. //会议纪要
  607. this._loadMeeting();
  608. //自定义
  609. this._loadCustom();
  610. this.reSetShow(control);
  611. this.reSetEdit();
  612. // 份数: this.layout_copies
  613. // 密级: this.layout_secret
  614. // 紧急程度: this.layout_priority
  615. // 红头: this.layout_redHeader
  616. // 上行文编号签发: this.layout_fileNoUpTable
  617. // 文号: this.layout_fileno
  618. // 签发: this.layout_signerTitle
  619. // 签发人: this.layout_signer
  620. // 文号: this.layout_fileno
  621. // 红线: this.layout_redLine
  622. // 标题: this.layout_subject
  623. // 主送单位: this.layout_mainSend
  624. // 正文: this.layout_filetexts
  625. // 附件: this.layout_attachmentTitle
  626. // 附件: this.layout_attachment
  627. // 单位: this.layout_issuanceUnit
  628. // 签发时间: this.layout_issuanceDate
  629. // 附注: this.layout_annotation
  630. // 抄送: this.layout_copytoTitle
  631. // 抄送: this.layout_copytoContent
  632. // 版记单位 this.layout_edition_issuance_unit
  633. // 版记日期 this.layout_edition_issuance_date
  634. },
  635. reSetShow: function(control){
  636. if (!control) control = this.getShowControl();
  637. var m = function(s){ return (control[s]) ? "show" : "hide"; }
  638. if (this.layout_copiesSecretPriority) this.layout_copiesSecretPriority[m("copiesSecretPriority")]();
  639. // control.copies = this._getShow("copies", "copiesShow", "copiesShowScript");
  640. // control.secret = this._getShow("secret", "secretShow", "secretShowScript");
  641. // control.priority = this._getShow("priority", "priorityShow", "priorityShowScript");
  642. var n = 0;
  643. if (!control.copies) n++;
  644. if (!control.secret) n++;
  645. if (!control.priority) n++;
  646. if (this.layout_copiesSecretPriority_blank){
  647. this.layout_copiesSecretPriority_blank.empty();
  648. while (n>0){
  649. this.layout_copiesSecretPriority_blank.appendHTML("<p class=\"MsoNormal\"><span style='font-size:16.0pt'>&nbsp;</span></p>");
  650. n--;
  651. }
  652. }
  653. if (this.layout_copies) this.layout_copies[m("copies")]();
  654. if (this.layout_secret) this.layout_secret[m("secret")]();
  655. if (this.layout_priority) this.layout_priority[m("priority")]();
  656. if (this.layout_redHeader) this.layout_redHeader[m("redHeader")]();
  657. if (this.layout_redLine) this.layout_redLine[m("redLine")]();
  658. if (this.layout_fileNoUpTable) this.layout_fileNoUpTable[m("signer")]();
  659. if (this.layout_filenoArea) this.layout_filenoArea[(!control.signer) ? "show" : "hide"]();
  660. if (this.json.fileup){
  661. this._loadFileNoUp();
  662. }else{
  663. this._loadFileNo();
  664. }
  665. if (this.layout_fileno) this.layout_fileno.set("text", this.data.fileno || " ");
  666. if (this.layout_signerTitle) this.layout_signerTitle[m("signer")]();
  667. if (this.layout_signer) this.layout_signer[m("signer")]();
  668. if (this.layout_fileno) this.layout_fileno[m("fileno")]();
  669. if (this.layout_subject) this.layout_subject[m("subject")]();
  670. if (this.layout_mainSend) this.layout_mainSend[m("mainSend")]();
  671. if (this.layout_attachmentTable) this.layout_attachmentTable[m("attachment")]();
  672. if (this.layout_issuanceUnit) this.layout_issuanceUnit[m("issuanceUnit")]();
  673. if (this.layout_issuanceDate) this.layout_issuanceDate[m("issuanceDate")]();
  674. if (this.layout_issuanceUnit && this.layout_issuanceDate){
  675. var table = this.layout_issuanceUnit.getParent("table")
  676. if (table && !table.hasClass("doc_layout_headIssuance")) {
  677. var unitWidth = o2.getTextSize(this.layout_issuanceUnit.get("text"), {
  678. "font-size": "16pt",
  679. "font-family": "'Times New Roman',仿宋_GB2312",
  680. "letter-spacing": "-0.4pt"
  681. }).x;
  682. var dateWidth = o2.getTextSize(this.layout_issuanceDate.get("text"), {
  683. "font-size": "16pt",
  684. "font-family": "'Times New Roman',仿宋_GB2312",
  685. "letter-spacing": "-0.4pt"
  686. }).x;
  687. if (table.hasClass("doc_layout_issuanceV2")){
  688. if (unitWidth<=dateWidth){
  689. //日期右空四字,单位相对与日期居中
  690. var flagTd = this.layout_issuanceUnit.getParent("td").getNext("td");
  691. if (flagTd) flagTd.setStyle("width", "64pt");
  692. flagTd = this.layout_issuanceDate.getParent("td").getNext("td");
  693. if (flagTd) flagTd.setStyle("width", "64pt");
  694. var dateP = this.layout_issuanceDate.getParent("p");
  695. if (dateP){
  696. dateP.setStyle("text-align", "right");
  697. var span = dateP.getElement("span.space");
  698. if (span) span.destroy();
  699. }
  700. }else{
  701. var flagTd = this.layout_issuanceUnit.getParent("td").getNext("td");
  702. if (flagTd) flagTd.setStyle("width", "32pt");
  703. flagTd = this.layout_issuanceDate.getParent("td").getNext("td");
  704. if (flagTd) flagTd.setStyle("width", "32pt");
  705. var dateP = this.layout_issuanceDate.getParent("p");
  706. var dateP = this.layout_issuanceDate.getParent("p");
  707. if (dateP){
  708. dateP.setStyle("text-align", "left");
  709. var span = dateP.getElement("span.space");
  710. if (!span) new Element("span.space", { "html": "&#x3000;&#x3000;" }).inject(dateP, "top");
  711. }
  712. }
  713. }else{
  714. if (unitWidth <= dateWidth) {
  715. //日期右空四字,单位相对与日期居中
  716. var flagTd = this.layout_issuanceDate.getParent("td").getNext("td");
  717. if (flagTd) {
  718. var pt = 16*4; //空四字
  719. flagTd.setStyle("width", "" + pt + "pt");
  720. flagTd = this.layout_issuanceUnit.getParent("td").getNext("td");
  721. if (flagTd) flagTd.setStyle("width", "" + pt + "pt");
  722. }
  723. //var dateTd = this.layout_issuanceDate.getParent("td");
  724. var unitTd = this.layout_issuanceUnit.getParent("td");
  725. unitTd.setStyle("width", dateWidth);
  726. var p = this.layout_issuanceUnit.getParent("p");
  727. if (p) p.setStyle("text-align", "center");
  728. } else {
  729. var flagTd = this.layout_issuanceUnit.getParent("td").getNext("td");
  730. if (flagTd) flagTd.setStyle("width", "32pt");
  731. var unitTd = this.layout_issuanceUnit.getParent("td");
  732. unitTd.setStyle("width", "auto");
  733. flagTd = this.layout_issuanceDate.getParent("td").getNext("td");
  734. if (flagTd) flagTd.setStyle("width", "64pt");
  735. var p = this.layout_issuanceDate.getParent("p");
  736. if (p) p.setStyle("text-align", "right");
  737. }
  738. }
  739. }
  740. }
  741. if (this.layout_annotation) this.layout_annotation[m("annotation")]();
  742. if ((!control.copyto || !this.layout_copytoContent) && (!control.copyto2 || !this.layout_copyto2Content) && (!control.editionUnit || !this.layout_edition_issuance_unit) && (!control.editionDate || !this.layout_edition_issuance_date)){
  743. if (this.layout_editionArea) this.layout_editionArea.hide();
  744. }else{
  745. if (this.layout_copytoContent){
  746. if (!this.layout_copytoContentTr) this.layout_copytoContentTr = this.layout_copytoContent.getParent("tr");
  747. if (!this.layout_copytoContentTrP) this.layout_copytoContentTrP = this.layout_copytoContentTr.getParent();
  748. }
  749. if (this.layout_copyto2Content){
  750. if (!this.layout_copyto2ContentTr) this.layout_copyto2ContentTr = this.layout_copyto2Content.getParent("tr");
  751. if (!this.layout_copyto2ContentTrP) this.layout_copyto2ContentTrP = this.layout_copyto2ContentTr.getParent();
  752. }
  753. if (!this.copyToOrder){
  754. this.copyToOrder = "unknow"
  755. if (this.layout_copytoContentTr && this.layout_copyto2ContentTr){ //需要知道顺序
  756. if (this.layout_copytoContentTrP && this.layout_copyto2ContentTrP && this.layout_copytoContentTrP==this.layout_copyto2ContentTrP){
  757. var n = this.layout_copytoContentTrP.getFirst();
  758. while (n && n!=this.layout_copytoContentTr && n!=this.layout_copyto2ContentTr){
  759. n = n.getNext();
  760. }
  761. if (n==this.layout_copytoContentTr){
  762. this.copyToOrder = "copyto";
  763. }
  764. if (n==this.layout_copyto2ContentTr){
  765. this.copyToOrder = "copyto2";
  766. }
  767. }
  768. }
  769. }
  770. if ((!control.copyto || !this.layout_copytoContent) && (!control.copyto2 || !this.layout_copyto2Content) ){
  771. if (this.layout_edition){
  772. if (this.layout_copytoContentTr) this.layout_copytoContentTr.dispose();
  773. if (this.layout_copyto2ContentTr) this.layout_copyto2ContentTr.dispose();
  774. // if (this.layout_edition) this.layout_edition.getElement("tr").getElements("td")[0].setStyles({
  775. // "border-top": "solid windowtext 1.5pt",
  776. // "mso-border-top-alt": "solid windowtext 1pt"
  777. // });
  778. }
  779. }else if (!control.copyto || !this.layout_copytoContent){
  780. if (this.layout_copytoContentTr) this.layout_copytoContentTr.dispose();
  781. if (this.layout_copyto2ContentTr){
  782. try{
  783. this.layout_copyto2ContentTr.inject(this.layout_copyto2ContentTrP, "top");
  784. }catch (e){
  785. this.layout_copyto2ContentTrP.appendHTML(this.layout_copyto2ContentTr.outerHTML, "top");
  786. }
  787. }
  788. //if (this.layout_copyto2Content) this.layout_edition.getElement("tr").destroy();
  789. // if (this.layout_edition) this.layout_edition.getElement("tr").getElements("td").setStyles({
  790. // "border-top": "solid windowtext 1.5pt",
  791. // "mso-border-top-alt": "solid windowtext 1pt"
  792. // });
  793. }else if (!control.copyto2 || !this.layout_copyto2Content) {
  794. if (this.layout_copyto2ContentTr) this.layout_copyto2ContentTr.dispose();
  795. // if (this.layout_copytoContentTr) this.layout_copytoContentTr.inject(this.layout_copytoContentTrP, "top");
  796. if (this.layout_copytoContentTr){
  797. try{
  798. this.layout_copytoContentTr.inject(this.layout_copytoContentTrP, "top");
  799. }catch (e){
  800. this.layout_copytoContentTrP.appendHTML(this.layout_copytoContentTr.outerHTML, "top");
  801. }
  802. }
  803. // if (this.layout_edition) this.layout_edition.getElement("tr").getElements("td").setStyles({
  804. // "border-bottom": "solid windowtext 0.75pt",
  805. // "mso-border-bottom-alt": "solid windowtext 0.75pt"
  806. // });
  807. }else{
  808. if (this.copyToOrder == "copyto2"){
  809. // if (this.layout_copytoContentTr) this.layout_copytoContentTr.inject(this.layout_copytoContentTrP, "top");
  810. // if (this.layout_copyto2ContentTr) this.layout_copyto2ContentTr.inject(this.layout_copyto2ContentTrP, "top");
  811. if (this.layout_copytoContentTr){
  812. try{
  813. this.layout_copytoContentTr.inject(this.layout_copytoContentTrP, "top");
  814. }catch (e){
  815. this.layout_copytoContentTrP.appendHTML(this.layout_copytoContentTr.outerHTML, "top");
  816. }
  817. }
  818. if (this.layout_copyto2ContentTr){
  819. try{
  820. this.layout_copyto2ContentTr.inject(this.layout_copyto2ContentTrP, "top");
  821. }catch (e){
  822. this.layout_copyto2ContentTrP.appendHTML(this.layout_copyto2ContentTr.outerHTML, "top");
  823. }
  824. }
  825. }else{
  826. // if (this.layout_copyto2ContentTr) this.layout_copyto2ContentTr.inject(this.layout_copyto2ContentTrP, "top");
  827. // if (this.layout_copytoContentTr) this.layout_copytoContentTr.inject(this.layout_copytoContentTrP, "top");
  828. if (this.layout_copyto2ContentTr){
  829. try{
  830. this.layout_copyto2ContentTr.inject(this.layout_copyto2ContentTrP, "top");
  831. }catch (e){
  832. this.layout_copyto2ContentTrP.appendHTML(this.layout_copyto2ContentTr.outerHTML, "top");
  833. }
  834. }
  835. if (this.layout_copytoContentTr){
  836. try{
  837. this.layout_copytoContentTr.inject(this.layout_copytoContentTrP, "top");
  838. }catch (e){
  839. this.layout_copytoContentTrP.appendHTML(this.layout_copytoContentTr.outerHTML, "top");
  840. }
  841. }
  842. }
  843. }
  844. if ((!control.editionUnit || !this.layout_edition_issuance_unit) && (!control.editionDate || !this.layout_edition_issuance_date)){
  845. if (this.layout_editionArea && (this.contentNode.getElement(".doc_layout_edition_issuance_date") || this.contentNode.getElement(".doc_layout_edition_issuance_unit"))){
  846. var trs = this.layout_editionArea.getElement("table").rows;
  847. trs.item(trs.length-1).destroy();
  848. // trs = this.layout_editionArea.getElement("table").rows;
  849. // var tr = trs.item(trs.length-1);
  850. // if (tr){
  851. // tr.getElements("td").setStyles({
  852. // "border-bottom": "solid windowtext 1.5pt",
  853. // "mso-border-bottom-alt": "solid windowtext 1pt"
  854. // });
  855. // }
  856. }
  857. }
  858. if (this.layout_editionArea && (this.layout_edition_issuance_date || this.layout_edition_issuance_unit)){
  859. trs = this.layout_editionArea.getElement("table").rows;
  860. for (var i=0; i<trs.length; i++){
  861. var tds = trs.item(i).cells;
  862. for (var n=0; n<tds.length; n++){
  863. var td = tds.item(n);
  864. var tdClass = td.get("class");
  865. var tdClassList = (tdClass) ? tdClass.split(/\s+/g) : [];
  866. if (tdClassList.indexOf("line_top_thin_bottom_thick") != -1) tdClassList = tdClassList.erase("line_top_thin_bottom_thick");
  867. if (tdClassList.indexOf("line_top_thick_bottom_thin") != -1) tdClassList = tdClassList.erase("line_top_thick_bottom_thin");
  868. if (tdClassList.indexOf("line_top_thick_bottom_thick") != -1) tdClassList = tdClassList.erase("line_top_thick_bottom_thick");
  869. if (tdClassList.indexOf("line_top_thin_bottom_thin") == -1) tdClassList.unshift("line_top_thin_bottom_thin");
  870. // td.setStyles({
  871. // "border-top": "solid windowtext 0.75pt",
  872. // "mso-border-top-alt": "solid windowtext 0.75pt",
  873. // "border-bottom": "solid windowtext 0.75pt",
  874. // "mso-border-bottom-alt": "solid windowtext 0.75pt",
  875. // });
  876. if (i==0 && i!=(trs.length-1)){
  877. if (tdClassList.indexOf("line_top_thin_bottom_thin") != -1) tdClassList = tdClassList.erase("line_top_thin_bottom_thin");
  878. tdClassList.unshift("line_top_thick_bottom_thin");
  879. // td.setStyles({
  880. // "border-top": "solid windowtext 1.5pt",
  881. // "mso-border-top-alt": "solid windowtext 1pt"
  882. // });
  883. }else if (i==0 && i==(trs.length-1)){
  884. if (tdClassList.indexOf("line_top_thin_bottom_thin") != -1) tdClassList = tdClassList.erase("line_top_thin_bottom_thin");
  885. tdClassList.unshift("line_top_thick_bottom_thick");
  886. }else if (i!=0 && i==(trs.length-1)){
  887. if (tdClassList.indexOf("line_top_thin_bottom_thin") != -1) tdClassList = tdClassList.erase("line_top_thin_bottom_thin");
  888. tdClassList.unshift("line_top_thin_bottom_thick");
  889. }
  890. // if (i==(trs.length-1)){
  891. // if (tdClassList.indexOf("line_bottom_thin") != -1) tdClassList = tdClassList.erase("line_bottom_thin");
  892. // if (tdClassList.indexOf("line_bottom_thick") == -1) tdClassList.push("line_bottom_thick");
  893. // // td.setStyles({
  894. // // "border-bottom": "solid windowtext 1.5pt",
  895. // // "mso-border-bottom-alt": "solid windowtext 1pt"
  896. // // });
  897. // }
  898. tdClass = tdClassList.join(" ");
  899. td.set("class", tdClass);
  900. }
  901. }
  902. }
  903. var coptyToTitleNode = (this.layout_copytoTitle || this.layout_copyto2Title);
  904. if (coptyToTitleNode){
  905. var editionTable = coptyToTitleNode.getParent("table");
  906. if (editionTable) if (editionTable.get("data-compute-style")=="y"){
  907. var rows = editionTable.rows;
  908. for (var i=0; i<rows.length; i++){
  909. var cell = rows[i].cells[0];
  910. var tmp = cell.getElement(".doc_layout_edition_issuance_unit");
  911. if (!tmp) tmp = cell.getElement(".doc_layout_edition_issuance_date");
  912. if (!tmp){
  913. var text = cell.get("text").trim();
  914. var l = 14*text.length;
  915. var wl = 19*text.length;
  916. cell.setStyles({
  917. "max-width": ""+l+"pt",
  918. "min-width": ""+l+"pt",
  919. "width": ""+wl+"pt"
  920. });
  921. }
  922. }
  923. }
  924. }
  925. if (this.layout_editionArea) this.layout_editionArea.show();
  926. if (this.layout_copytoTitle) this.layout_copytoTitle[m("copyto")]();
  927. if (this.layout_copytoContent) this.layout_copytoContent[m("copyto")]();
  928. if (this.layout_copyto2Title) this.layout_copyto2Title[m("copyto2")]();
  929. if (this.layout_copyto2Content) this.layout_copyto2Content[m("copyto2")]();
  930. if (this.layout_edition_issuance_unit) this.layout_edition_issuance_unit[m("editionUnit")]();
  931. if (this.layout_edition_issuance_date) this.layout_edition_issuance_date[m("editionDate")]();
  932. }
  933. if (this.layout_meetingAttendArea) this.layout_meetingAttendArea[m("meetingAttend")]();
  934. if (this.layout_meetingLeaveArea) this.layout_meetingLeaveArea[m("meetingLeave")]();
  935. if (this.layout_meetingSitArea) this.layout_meetingSitArea[m("meetingSit")]();
  936. if (this.layout_meetingRecordArea) this.layout_meetingRecordArea[m("meetingRecord")]();
  937. // this.layout_annotation[m("annotation")]();
  938. // this.layout_annotation[m("annotation")]();
  939. // this.layout_annotation[m("annotation")]();
  940. },
  941. reSetEdit: function(control){
  942. //未进行数据绑定时,可允许编辑
  943. if (!control) var control = this.getEditControl();
  944. if (this.layout_subject){
  945. if (!this.json.subjectValueData && this.json.subjectValueType=="data"){
  946. this.layout_subject.set("contenteditable", control.subject);
  947. this.layout_subject.addEvent("paste", function(e){
  948. let paste = (e.event.clipboardData || window.clipboardData).getData('text');
  949. const selection = window.getSelection();
  950. if (!selection.rangeCount) return false;
  951. selection.deleteFromDocument();
  952. selection.getRangeAt(0).insertNode(document.createTextNode(paste));
  953. event.preventDefault();
  954. }.bind(this))
  955. // this.layout_subject.addEvent("blur", function(){
  956. // this.getData();
  957. // }.bind(this))
  958. this.layout_subject.addEvent("blur", function(e){
  959. var subject = this.layout_subject.get("text");
  960. if (!subject){
  961. this.layout_subject.set("html", this.data.subject);
  962. this.form.app.notice(MWF.xApplication.process.Xform.LP.subjectEmpty, "error", this.layout_subject, {"x": "center","y":"top"}, {"x": 0,"y":60});
  963. e.preventDefault();
  964. e.stopPropagation();
  965. }else{
  966. if (this.json.subjectEditBindFormData){
  967. this.form.Macro.environment.data[this.json.subjectEditBindFormData]=subject;
  968. }
  969. this.getData();
  970. }
  971. }.bind(this));
  972. }
  973. }
  974. if (this.layout_issuanceUnit){
  975. if (!this.json.issuanceUnitValueData && this.json.issuanceUnitValueType=="data"){
  976. this.layout_issuanceUnit.set("contenteditable", control.issuanceUnit);
  977. // this.layout_issuanceUnit.addEvent("blur", function(){
  978. // this.getData();
  979. // }.bind(this))
  980. this.layout_issuanceUnit.addEvent("blur", function(e){
  981. var issuanceUnit = this.layout_issuanceUnit.get("text");
  982. if (!issuanceUnit){
  983. this.layout_issuanceUnit.set("html", this.data.issuanceUnit);
  984. this.form.app.notice(MWF.xApplication.process.Xform.LP.issuanceUnitEmpty, "error", this.layout_issuanceUnit, {"x": "center","y":"top"}, {"x": 0,"y":60});
  985. e.preventDefault();
  986. e.stopPropagation();
  987. }else{
  988. this.getData();
  989. }
  990. }.bind(this));
  991. }
  992. }
  993. if (this.layout_filetext){
  994. // if (this.allowEdit) {
  995. // if (!this.loadFileTextEditFun) this.loadFileTextEditFun = this._switchReadOrEditInline.bind(this);
  996. // this.layout_filetext.removeEvent("click", this.loadFileTextEditFun);
  997. // this.layout_filetext.addEvent("click", this.loadFileTextEditFun);
  998. // }
  999. }
  1000. if (this.layout_attachmentText){
  1001. if (control.attachmentText) {
  1002. if (!this.loadAttachmentTextEditFun) this.loadAttachmentTextEditFun = this.loadAttachmentTextEdit.bind(this);
  1003. this.layout_attachmentText.removeEvent("click", this.loadAttachmentTextEditFun);
  1004. this.layout_attachmentText.addEvent("click", this.loadAttachmentTextEditFun);
  1005. if (!this.data.attachmentText){
  1006. this.layout_attachmentText.set("text", MWF.xApplication.process.Xform.LP.documentEditor.attachmentInfor);
  1007. }
  1008. }
  1009. }
  1010. // this.layout_subject.addEvent("keydown", function(e){
  1011. // if (this.json.subjectValueType=="data" && this.json.subjectValueData){
  1012. // // var v = e.target.get("HTML");
  1013. // // this.form.businessData.data[this.json.subjectValueData] = v
  1014. // var module = this.form.all[this.json.subjectValueData];
  1015. // if (module){
  1016. // var bindFun = module.node.retrieve(this.json.id+"bindFun");
  1017. // module.node
  1018. // }
  1019. // }
  1020. // }.bind(this));
  1021. },
  1022. loadAttachmentTextEdit: function(){
  1023. this._createEditor("inline", this.layout_attachmentText, this.data.attachmentText, "attachmentTextEditor", function(){
  1024. this.layout_attachmentText.removeEvent("click", this.loadAttachmentTextEditFun);
  1025. var text = this.layout_attachmentText.get("text");
  1026. text = text.replace(/\u3000*/g, "");
  1027. if (!text || text==MWF.xApplication.process.Xform.LP.documentEditor.attachmentInfor){
  1028. this.layout_attachmentText.empty();
  1029. this["attachmentTextEditor"].insertHtml("<div aria-label=\"分页符\" class=\"cke_pagebreak\" contenteditable=\"false\" data-cke-display-name=\"pagebreak\" data-cke-pagebreak=\"1\" style=\"page-break-after: always\" title=\"分页符\"></div>" +
  1030. "<div style=\"font-family:黑体;font-size:16pt;\">附件1</div>" +
  1031. "<div><span> </span></div>" +
  1032. "<div style=\"font-family: 方正小标宋简体; font-size: 22pt; text-align: center;\">附件标题</div>" +
  1033. "<div><span> </span></div>" +
  1034. "<div>  附件内容</div>");
  1035. }
  1036. }.bind(this));
  1037. },
  1038. _loadUserInterface: function(callback){
  1039. this.node.empty();
  1040. this.node.setStyles(this.form.css.documentEditorNode);
  1041. this.pages = [];
  1042. this.allowEdit = this._isAllowEdit();
  1043. this.allowPrint = this._isAllowPrint();
  1044. this.allowHistory = this._isAllowHistory();
  1045. this.toolNode = new Element("div", {"styles": this.css.doc_toolbar}).inject(this.node);
  1046. this.contentNode = new Element("div#doc_content", {"styles": this.css.doc_content}).inject(this.node);
  1047. if (!this.form.isLoaded){
  1048. this.form.addEvent("afterModulesLoad", function(){this.loadDocumentEditor(callback);}.bind(this));
  1049. }else{
  1050. this.loadDocumentEditor(callback);
  1051. }
  1052. o2.loadCss('../x_desktop/fonts/fonts.css');
  1053. },
  1054. loadDocumentEditor: function(callback){
  1055. this._loadToolbars();
  1056. this._loadFiletextPage(function(){
  1057. this._singlePage();
  1058. this.form.addEvent("beforeSave", function(){
  1059. this.getData();
  1060. this.checkSaveNewEdition();
  1061. }.bind(this));
  1062. if (this.json.toWord=="y"){
  1063. if (this.json.toWordTrigger=="open") this.docToWord();
  1064. if (this.json.toWordTrigger=="save") {
  1065. if (!this.form.toWordSaveList) this.form.toWordSaveList = [];
  1066. this.form.toWordSaveList.push(this);
  1067. }
  1068. if (this.json.toWordTrigger=="submit") {
  1069. if (!this.form.toWordSubmitList) this.form.toWordSubmitList = [];
  1070. this.form.toWordSubmitList.push(this);
  1071. }
  1072. }
  1073. //if (!layout.mobile) this.loadSideToolbar();
  1074. o2.load("../o2_lib/diff-match-patch/diff_match_patch.js");
  1075. if (this.form.businessData.data["$work"]){
  1076. var id = this.form.businessData.data["$work"].job;
  1077. o2.Actions.load("x_processplatform_assemble_surface").DocumentVersionAction.listWithJobCategory(id, this.json.id, function(json){
  1078. this.historyDocumentList = json.data;
  1079. if (this.historyDocumentList.length){
  1080. o2.Actions.load("x_processplatform_assemble_surface").DocumentVersionAction.get(this.historyDocumentList[this.historyDocumentList.length-1].id, function(json){
  1081. var data = JSON.parse(json.data.data);
  1082. this.originaHistoryData = data.data;
  1083. }.bind(this));
  1084. }
  1085. }.bind(this));
  1086. }
  1087. if (callback) callback();
  1088. }.bind(this));
  1089. if (!this.form.documenteditorList) this.form.documenteditorList=[];
  1090. this.form.documenteditorList.push(this);
  1091. },
  1092. getFiletextText: function(data){
  1093. // var div = new Element("div", {
  1094. // "html": data
  1095. // });
  1096. // var text = div.get("text");
  1097. // div.destroy();
  1098. // return text;
  1099. var div = document.createElement("div");
  1100. div.style.height = '0px';
  1101. document.body.appendChild(div);
  1102. div.innerHTML = data.replace(/<br><\/div>/g, '</div>').replace(/[\n\r]/g, '');
  1103. var text = div.innerText;
  1104. if (div.remove){
  1105. div.remove();
  1106. }else{
  1107. if (div.parentNode) div.parentNode.removeChild(div);
  1108. }
  1109. return text;
  1110. // return text.replace(/<br><\/div>/g, '</div>');
  1111. },
  1112. checkSaveNewEdition: function(callback){
  1113. if (!this.allowEdit || !this.data.filetext || this.data.filetext == this.json.defaultValue.filetext) return false;
  1114. if (this.form.businessData.work){
  1115. var originaData = this.form.businessData.originalData[this.json.id];
  1116. var editionData = {"category": this.json.id};
  1117. if (!originaData || !originaData.filetext || !this.originaHistoryData){
  1118. //保存原始版本
  1119. this.originaHistoryData = {"data": this.data.filetext, "v": "6"};
  1120. editionData.data = JSON.stringify({"data": this.data.filetext, "v": "6"});
  1121. }else if (originaData.filetext!=this.data.filetext){
  1122. //保存历史版本
  1123. var data = this.getFiletextText(this.data.filetext);
  1124. var earlyData = this.getFiletextText(originaData.filetext);
  1125. //var data = this.data.filetext;
  1126. //var earlyData = originaData.filetext;
  1127. var dmp = new diff_match_patch();
  1128. var diff_d = dmp.diff_main(earlyData, data);
  1129. dmp.diff_cleanupSemantic(diff_d);
  1130. var patch_list = dmp.patch_make(earlyData, data, diff_d);
  1131. var d = {
  1132. "patchs": dmp.patch_toText(patch_list),
  1133. "data": this.data.filetext,
  1134. "v": "6"
  1135. };
  1136. editionData.data = JSON.stringify(d);
  1137. }else{
  1138. return false;
  1139. }
  1140. o2.Actions.load("x_processplatform_assemble_surface").DocumentVersionAction.create(this.form.businessData.work.id, editionData, function(json){
  1141. //originaData.filetext = this.data.filetext;
  1142. if (callback) callback();
  1143. }.bind(this));
  1144. }
  1145. },
  1146. checkSaveNewHistroy: function(){
  1147. var p = o2.Actions.load("x_processplatform_assemble_surface").DocumentRevisionAction.getLast(this.form.businessData.work.job, this.json.id);
  1148. p.then(function(json){
  1149. if (!json.data || json.data.data!=this.data.filetext){
  1150. var data = {
  1151. "category": this.json.id,
  1152. "data":this.data.filetext
  1153. }
  1154. return o2.Actions.load("x_processplatform_assemble_surface").DocumentRevisionAction.create(this.form.businessData.work.id, data);
  1155. }
  1156. }.bind(this));
  1157. return p;
  1158. },
  1159. resetToolbarEvent: function(node){
  1160. if (Browser.ie11){
  1161. if (!this.waitLocation){
  1162. this.waitLocation = window.setTimeout(function(){
  1163. this.resizeToolbar(node);
  1164. this.waitLocation = false;
  1165. }.bind(this), 1000);
  1166. }
  1167. }else{
  1168. this.resizeToolbar(node);
  1169. }
  1170. },
  1171. resizeToolbar: function(node){
  1172. if (this.toolbarNode){
  1173. var p = this.toolNode.getPosition(node || this.scrollNode);
  1174. var size = this.toolNode.getSize();
  1175. var pl = this.toolbarNode.getStyle("padding-left").toInt();
  1176. var pr = this.toolbarNode.getStyle("padding-right").toInt();
  1177. var x = size.x-pl-pr;
  1178. //var pNode = this.toolNode.getOffsetParent();
  1179. var paddingTop = (this.isFullScreen) ? 0 : (node || this.form.node).getStyle("padding-top");
  1180. try {
  1181. paddingTop = paddingTop.toInt();
  1182. }catch (e) {
  1183. paddingTop = 0;
  1184. }
  1185. if (p.y<paddingTop && this.toolNode.offsetParent){
  1186. this.toolbarNode.inject(node || this.scrollNode);
  1187. this.toolbarNode.setStyles({
  1188. "position": "absolute",
  1189. "width": ""+x+"px",
  1190. "z-index": 200,
  1191. "top": paddingTop+"px",
  1192. "left": ""+p.x+"px"
  1193. });
  1194. }else{
  1195. this.toolbarNode.inject(this.toolNode);
  1196. this.toolbarNode.setStyles({"position": "static", "width": "auto"});
  1197. }
  1198. }
  1199. },
  1200. resizeSidebar: function(){
  1201. if (this.sidebarNode){
  1202. var fileTextNode = this.contentNode.getElement("div.doc_layout_filetext");
  1203. if (fileTextNode){
  1204. this.sidebarNode.position({
  1205. relativeTo: fileTextNode,
  1206. position: 'topLeft',
  1207. edge: 'topRight',
  1208. offset: {"x": -20, "y": 60}
  1209. });
  1210. var p = fileTextNode.getPosition(this.form.app.content);
  1211. var ptop = fileTextNode.getPosition(this.node);
  1212. //if ((p.y+s.y)<0) this.sidebarNode.setStyle("top", p.y+s.y);
  1213. if (p.y<0){
  1214. var top = ptop.y-p.y+200;
  1215. this.sidebarNode.setStyle("top", top);
  1216. }
  1217. // var p = fileTextNode.getPosition();
  1218. // this.sidebarNode.setStyle("top", p.y);
  1219. }
  1220. }
  1221. },
  1222. loadSideToolbar: function(){
  1223. if (this.allowEdit){
  1224. if (this.pages.length){
  1225. var fileTextNode = this.pages[0].getElement("div.doc_layout_filetext");
  1226. if (fileTextNode){
  1227. this.sidebarNode = new Element("div", {"styles": this.css.doc_sidebar}).inject(this.node);
  1228. this.resizeSidebar();
  1229. this.scrollNode = this.sidebarNode.getParentSrcollNode();
  1230. if (this.scrollNode){
  1231. this.scrollNode.addEvent("scroll", function(){
  1232. this.resizeSidebar();
  1233. }.bind(this));
  1234. }
  1235. html = "<span MWFnodetype=\"MWFToolBarButton\" MWFButtonImage=\"../x_component_process_Xform/$Form/default/icon/editdoc.png\" title=\""+MWF.xApplication.process.Xform.LP.editdoc+"\" MWFButtonAction=\"_switchReadOrEditInline\" MWFButtonText=\""+MWF.xApplication.process.Xform.LP.editdoc+"\"></span>";
  1236. this.sidebarNode.set("html", html);
  1237. MWF.require("MWF.widget.Toolbar", function() {
  1238. this.sideToolbar = new MWF.widget.Toolbar(this.sidebarNode, {"style": "documentEdit_side"}, this);
  1239. this.sideToolbar.load();
  1240. }.bind(this));
  1241. }
  1242. }
  1243. }
  1244. },
  1245. _returnScale: function(){
  1246. this.isScale = false;
  1247. this.scale = 0;
  1248. this.contentNode.setStyles({
  1249. "transform":"scale(1)",
  1250. });
  1251. if (this.pages.length){
  1252. this.pages.each(function(page){
  1253. page.setStyles({
  1254. "transform":"scale(1)",
  1255. });
  1256. });
  1257. }
  1258. this.node.setStyles({
  1259. "height": "auto"
  1260. });
  1261. },
  1262. _checkScale: function(offset){
  1263. offset = 0;
  1264. this._contentNodeWitdh();
  1265. if (this.pages.length){
  1266. //var pageSize = this.pages[0].getSize();
  1267. var pageSize_x = this.options.docPageFullWidth;
  1268. // var contentSize = this.contentNode.getSize();
  1269. //var contentSize = this.node.getSize();
  1270. // var contentWidth = (offset) ? contentSize.x-20-offset : contentSize.x-20;
  1271. // if (contentWidth<pageSize_x){
  1272. // this.isScale = true;
  1273. // var scale = (contentWidth)/pageSize_x;
  1274. // //this.scale = scale;
  1275. // this.zoom(scale);
  1276. // this.resetNodeSize();
  1277. // }
  1278. var contentSize_x = this.node.getSize().x;
  1279. //pageSize_x = this.scale;
  1280. // if (this.scale){
  1281. // pageSize_x = this.scale*pageSize_x;
  1282. // contentSize_x = this.scale*contentSize_x;
  1283. // //offset = this.scale*(offset+20);
  1284. // }
  1285. if (this.history && this.history.historyListAreaNode) contentSize_x = contentSize_x-this.history.historyListAreaNode.getComputedSize().totalWidth-2;
  1286. var contentWidth = contentSize_x-offset-20;
  1287. var p = pageSize_x*(this.documenteditorScale || 1);
  1288. if (contentWidth<p){
  1289. this.isScale = true;
  1290. var scale = (contentWidth)/pageSize_x;
  1291. //this.scale = scale;
  1292. this.zoom(scale);
  1293. this.resetNodeSize();
  1294. }else if (this.documenteditorScale){
  1295. // p = pageSize_x*(this.documenteditorScale || 1);
  1296. }
  1297. }
  1298. },
  1299. zoom: function(scale){
  1300. if (scale) this.scale = scale;
  1301. if (this.zoomSelectAction){
  1302. for (var i=0; i<this.zoomSelectAction.options.length; i++){
  1303. var option = this.zoomSelectAction.options[i];
  1304. if (Math.abs(this.scale-option.value.toFloat())<0.05){
  1305. option.set("selected", true);
  1306. break;
  1307. }
  1308. }
  1309. }
  1310. var w = this.node.getSize().x;
  1311. if (this.history && this.history.historyListAreaNode) w = w-this.history.historyListAreaNode.getComputedSize().totalWidth-2;
  1312. w = w/this.scale;
  1313. this.contentNode.setStyles({
  1314. "transform":"scale("+this.scale+")",
  1315. "transform-origin": "0px 0px",
  1316. "overflow": "auto",
  1317. "width": ""+w+"px"
  1318. });
  1319. if (this.filetextEditor && this.filetextEditor.element) {
  1320. this.filetextEditor.element.$.store("scale", this.scale);
  1321. }
  1322. this._pageMargin();
  1323. },
  1324. _switchReadOrEdit: function(){
  1325. if (this.editMode){
  1326. this._readFiletext();
  1327. // if (this.allowEdit) {
  1328. // var button = this.toolbar.childrenButton[0];
  1329. // button.setText((layout.mobile) ? MWF.xApplication.process.Xform.LP.editdoc_mobile : MWF.xApplication.process.Xform.LP.editdoc);
  1330. // button.picNode.getElement("img").set("src", "../x_component_process_Xform/$Form/default/icon/editdoc.png");
  1331. // //this.getFullWidthFlagNode().dispose();
  1332. // }
  1333. this.editMode = false;
  1334. }else{
  1335. this._editFiletext();
  1336. // if (this.allowEdit) {
  1337. // var button = this.toolbar.childrenButton[0];
  1338. // button.setText((layout.mobile) ? MWF.xApplication.process.Xform.LP.editdocCompleted_mobile : MWF.xApplication.process.Xform.LP.editdocCompleted);
  1339. // button.picNode.getElement("img").set("src", "../x_component_process_Xform/$Form/default/icon/editdoc_completed.png");
  1340. // //this.toolbar.node.inject(this.getFullWidthFlagNode());
  1341. //
  1342. // }
  1343. this.editMode = true;
  1344. }
  1345. },
  1346. _switchReadOrEditInline: function(){
  1347. if (this.editMode){
  1348. this._readFiletext();
  1349. this.editMode = false;
  1350. }else{
  1351. this._editFiletext("inline");
  1352. //if (this.loadFileTextEditFun) this.layout_filetext.removeEvent("click", this.loadFileTextEditFun);
  1353. this.editMode = true;
  1354. }
  1355. //this._switchButtonText();
  1356. },
  1357. // _switchButtonText: function(){
  1358. // var text = (layout.mobile) ? MWF.xApplication.process.Xform.LP.editdoc_mobile : MWF.xApplication.process.Xform.LP.editdoc;
  1359. // var img = "editdoc.png";
  1360. // if (this.editMode){
  1361. // text = (layout.mobile) ? MWF.xApplication.process.Xform.LP.editdocCompleted_mobile : MWF.xApplication.process.Xform.LP.editdocCompleted;
  1362. // img = "editdoc_completed.png";
  1363. // }
  1364. //
  1365. // if (!layout.mobile && this.sideToolbar && this.sideToolbar.childrenButton[0]) {
  1366. // var button = this.sideToolbar.childrenButton[0];
  1367. // button.setText(text);
  1368. // button.picNode.getElement("img").set("src", "../x_component_process_Xform/$Form/default/icon/"+img);
  1369. // }
  1370. // if (this.toolbar && this.toolbar.childrenButton[0]){
  1371. // button = this.toolbar.childrenButton[0];
  1372. // button.setText(text);
  1373. // button.picNode.getElement("img").set("src", "../x_component_process_Xform/$Form/default/icon/"+img);
  1374. // }
  1375. // },
  1376. editFiletext: function(){
  1377. if (!this.editMode && this.allowEdit){
  1378. this._editFiletext("inline");
  1379. //if (this.loadFileTextEditFun) this.layout_filetext.removeEvent("click", this.loadFileTextEditFun);
  1380. this.editMode = true;
  1381. //this._switchButtonText();
  1382. }
  1383. },
  1384. // getFullWidthFlagNode: function(){
  1385. // if (!this.fullWidthFlagNode){
  1386. // this.fullWidthFlagNode = new Element("span", {
  1387. // "styles": {
  1388. // "line-height": "26px",
  1389. // "color": "#999999",
  1390. // "font-size": "12px"
  1391. // },
  1392. // "text": MWF.xApplication.process.Xform.LP.fullWidth
  1393. // });
  1394. // }
  1395. // return this.fullWidthFlagNode;
  1396. // },
  1397. _printDoc: function(e,el){
  1398. e.disable();
  1399. var scale = this.scale;
  1400. this.toWord(function(data, filename){
  1401. if (filename){
  1402. o2.saveAs(data, filename);
  1403. }else{
  1404. if (this.form.businessData.work && !this.form.businessData.work.completedTime){
  1405. this.form.workAction.getAttachmentStream(data.id, this.form.businessData.work.id);
  1406. }else{
  1407. this.form.workAction.getWorkcompletedAttachmentStream(data.id, ((this.form.businessData.workCompleted) ? this.form.businessData.workCompleted.id : this.form.businessData.work.id));
  1408. }
  1409. }
  1410. this.scaleTo(scale);
  1411. e.enable();
  1412. }.bind(this), "", null, true);
  1413. },
  1414. _historyDoc: function(){
  1415. if (this.json.viewTracesFullScreen===true){
  1416. this._fullScreen();
  1417. }
  1418. this._readFiletext();
  1419. this.editMode = false;
  1420. this.getHistory(function(){
  1421. }.bind(this), function(){
  1422. this.historyMode = false;
  1423. this.resetData();
  1424. }.bind(this));
  1425. this.historyMode = true;
  1426. },
  1427. getHistory: function(callback, nodiff){
  1428. if (this.history){
  1429. this.history.active(function(){
  1430. if (callback) callback();
  1431. }, function(){
  1432. if (nodiff) nodiff();
  1433. });
  1434. }else{
  1435. MWF.xDesktop.requireApp("process.Xform", "widget.DocumentHistory", function(){
  1436. this.history = new MWF.xApplication.process.Xform.widget.DocumentHistory(this);
  1437. this.history.load(function(){
  1438. if (callback) callback();
  1439. }, function(){
  1440. if (nodiff) nodiff();
  1441. });
  1442. }.bind(this));
  1443. }
  1444. },
  1445. htmlToText: function(html){
  1446. var tmpdiv = new Element("div", {"html": html});
  1447. var text = tmpdiv.get("text");
  1448. tmpdiv.destroy();
  1449. return text;
  1450. },
  1451. _readFiletext: function(){
  1452. //this._returnScale();
  1453. //this.zoom(1);
  1454. var scale = this.scale;
  1455. if (this.filetextEditor) this.filetextEditor.destroy();
  1456. if (this.filetextScrollNode){
  1457. if (this.reLocationFiletextToolbarFun){
  1458. this.filetextScrollNode.removeEvent("scroll", this.reLocationFiletextToolbarFun);
  1459. //this.form.app.removeEvent("resize", this.reLocationFiletextToolbarFun);
  1460. this.reLocationFiletextToolbarFun = null;
  1461. }
  1462. this.filetextScrollNode = null;
  1463. }
  1464. if (this.filetextToolbarNode) this.filetextToolbarNode = null;
  1465. this.layout_filetext.setAttribute('contenteditable', false);
  1466. this.data = this.getData();
  1467. if (!this.data.filetext){
  1468. //this.data.filetext = this.json.defaultValue.filetext;
  1469. this.layout_filetext.set("html", this.json.defaultValue.filetext);
  1470. }
  1471. //this._checkSplitPage(this.pages[0]);
  1472. this._repage();
  1473. this.scaleTo(scale);
  1474. },
  1475. _editFiletext: function(inline){
  1476. if (this.data.filetext == this.json.defaultValue.filetext) this.data.filetext = "  ";
  1477. this.setData(this.data);
  1478. this.node.setStyles({
  1479. "height":"auto"
  1480. });
  1481. this._createEditor(inline);
  1482. },
  1483. _createEditor: function(inline, node, data, editorName, callback){
  1484. if (this.allowEdit){
  1485. this.loadCkeditorFiletext(function(e){
  1486. //e.editor.focus();
  1487. // var text = (data || this.data.filetext).replace(/\u3000*/g, "");
  1488. // if (!text){
  1489. // var range = e.editor.createRange();
  1490. // range.moveToElementEditEnd(e.editor.editable());
  1491. //
  1492. // range.select();
  1493. // range.scrollIntoView();
  1494. // }else{
  1495. // e.editor.getSelection().scrollIntoView();
  1496. // }
  1497. //e.editor.getSelection().scrollIntoView();
  1498. // var text = (data || this.data.filetext).replace(/\u3000*/g, "");
  1499. // if (!text){
  1500. // var range = e.editor.createRange();
  1501. // range.moveToElementEditEnd(e.editor.editable());
  1502. //
  1503. // range.select();
  1504. // range.scrollIntoView();
  1505. // }else{
  1506. // e.editor.getSelection().scrollIntoView();
  1507. // }
  1508. // e.editor.getSelection().scrollIntoView();
  1509. //
  1510. //this.getFiletextToolber();
  1511. //this.filetextToolbarNode.inject(this.layout_filetext.getOffsetParent());
  1512. //this.locationFiletextToolbar(editorName);
  1513. if (callback) callback();
  1514. }.bind(this), inline, node, editorName);
  1515. }
  1516. },
  1517. getFiletextToolber: function(editorName){
  1518. if (editorName){
  1519. if (this[editorName]) {
  1520. if (!this[editorName+"ToolbarNode"]) {
  1521. // var className = "cke_editor_" + this[editorName].name;
  1522. // var toolbarNode = $$("." + className)[0];
  1523. var className = "cke_" + this[editorName].name;
  1524. var toolbarNode = $(className);
  1525. this[editorName+"ToolbarNode"] = toolbarNode;
  1526. }
  1527. }
  1528. }else{
  1529. if (this.filetextEditor) {
  1530. if (!this.filetextToolbarNode) {
  1531. // var className = "cke_editor_" + this.filetextEditor.name;
  1532. // var filetextToolbarNode = $$("." + className)[0];
  1533. var className = "cke_" + this.filetextEditor.name;
  1534. var filetextToolbarNode = $(className);
  1535. this.filetextToolbarNode = filetextToolbarNode;
  1536. //filetextToolbarNode.destroy();
  1537. }
  1538. }
  1539. }
  1540. },
  1541. reLocationFiletextToolbarEvent: function(editorName){
  1542. if (Browser.ie11){
  1543. o2.defer(this.reLocationFiletextToolbar, 500, this, [editorName]);
  1544. // if (this.waitLocationFiletext) window.clearTimeout(this.waitLocationFiletext);
  1545. // this.waitLocationFiletext = window.setTimeout(function(){
  1546. // this.reLocationFiletextToolbar(editorName);
  1547. // this.waitLocationFiletext = false;
  1548. // }.bind(this), 500);
  1549. // if (!this.waitLocationFiletext){
  1550. // this.waitLocationFiletext = window.setTimeout(function(){
  1551. // this.reLocationFiletextToolbar(editorName);
  1552. // this.waitLocationFiletext = false;
  1553. // }.bind(this), 1000);
  1554. // }
  1555. }else{
  1556. this.reLocationFiletextToolbar(editorName)
  1557. }
  1558. },
  1559. reLocationFiletextToolbar: function(editorName){
  1560. this.getFiletextToolber(editorName);
  1561. var toolbarNode = (editorName) ? this[editorName+"ToolbarNode"] : this.filetextToolbarNode;
  1562. var editor = (editorName) ? this[editorName] : this.filetextEditor;
  1563. var node = (editorName) ? this.layout_attachmentText : this.layout_filetext;
  1564. if (toolbarNode){
  1565. if (!this.filetextScrollNode){
  1566. var scrollNode = this.contentNode;
  1567. while (scrollNode){
  1568. if (scrollNode.getStyle("overflow")=="auto" || scrollNode.getStyle("overflow-y")=="auto"){
  1569. var transform;
  1570. if (window.getComputedStyle){
  1571. transform = window.getComputedStyle(this.contentNode).transform;
  1572. }else{
  1573. transform = currentStyle.transform
  1574. }
  1575. transform = transform.substring(transform.indexOf("(")+1);
  1576. transform = transform.substring(0, transform.indexOf(")"));
  1577. var scaleList = transform.split(/,\s*/g);
  1578. var scaleY = scaleList[3];
  1579. var scale = (scaleY || 1).toFloat();
  1580. if ((scrollNode.getScrollSize().y*scale-1)>scrollNode.getSize().y){
  1581. break;
  1582. }
  1583. }
  1584. scrollNode = scrollNode.getParent();
  1585. }
  1586. this.filetextScrollNode = scrollNode;
  1587. }
  1588. var h = toolbarNode.getSize().y;
  1589. var position = node.getPosition();
  1590. var size = node.getSize();
  1591. var contentSize = this.filetextScrollNode.getSize();
  1592. if (layout.userLayout && layout.userLayout.scale && layout.userLayout.scale!==1){
  1593. var x = editor.editable().$.getPosition().x;
  1594. toolbarNode.setStyle("left", ""+x+"px");
  1595. }
  1596. toolbarNode.setStyle("min-width", "530px");
  1597. if (position.y<0 && size.y+position.y+h<contentSize.y){
  1598. var tp = this.toolbar.node.getPosition();
  1599. var tsy = this.toolbar.node.getSize().y;
  1600. var h = tp.y+tsy;
  1601. toolbarNode.setStyle("top", ""+h+"px");
  1602. }else if (position.y-h<0){
  1603. var tp = this.toolbar.node.getPosition();
  1604. var tsy = this.toolbar.node.getSize().y;
  1605. var h = tp.y+tsy;
  1606. toolbarNode.setStyle("top", ""+h+"px");
  1607. }else{
  1608. var p = node.getPosition().y-h;
  1609. toolbarNode.setStyle("top", "" + p + "px");
  1610. }
  1611. }
  1612. },
  1613. locationFiletextToolbar: function(editorName){
  1614. // this.getFiletextToolber(editorName);
  1615. // var toolbarNode = (editorName) ? this[editorName+"ToolbarNode"] : this.filetextToolbarNode;
  1616. //
  1617. // toolbarNode.inject(this.scrollNode, "bottom");
  1618. // toolbarNode.setStyles({
  1619. // "position": "absolute",
  1620. // "top": "40px"
  1621. // });
  1622. this.reLocationFiletextToolbar(editorName);
  1623. var toolbarNode = (editorName) ? this[editorName+"ToolbarNode"] : this.filetextToolbarNode;
  1624. if (toolbarNode) {
  1625. var scrollNode = this.contentNode;
  1626. while (scrollNode){
  1627. if (scrollNode.getStyle("overflow")=="auto" || scrollNode.getStyle("overflow-y")=="auto"){
  1628. var transform;
  1629. if (window.getComputedStyle){
  1630. transform = window.getComputedStyle(this.contentNode).transform;
  1631. }else{
  1632. transform = currentStyle.transform
  1633. }
  1634. transform = transform.substring(transform.indexOf("(")+1);
  1635. transform = transform.substring(0, transform.indexOf(")"));
  1636. var scaleList = transform.split(/,\s*/g);
  1637. var scaleY = scaleList[3];
  1638. var scale = (scaleY || 1).toFloat();
  1639. if ((scrollNode.getScrollSize().y*scale-1)>scrollNode.getSize().y){
  1640. break;
  1641. }
  1642. }
  1643. scrollNode = scrollNode.getParent();
  1644. }
  1645. if (scrollNode){
  1646. this.filetextScrollNode = scrollNode
  1647. if (editorName){
  1648. if (this.reLocationAttachmentTextToolbarFun) this.filetextScrollNode.removeEvent("scroll", this.reLocationAttachmentTextToolbarFun);
  1649. if (!this.reLocationAttachmentTextToolbarFun) this.reLocationAttachmentTextToolbarFun = function(){
  1650. this.reLocationFiletextToolbarEvent(editorName);
  1651. }.bind(this);
  1652. this.filetextScrollNode.addEvent("scroll", this.reLocationAttachmentTextToolbarFun);
  1653. }else{
  1654. if (this.reLocationFiletextToolbarFun) this.filetextScrollNode.removeEvent("scroll", this.reLocationFiletextToolbarFun);
  1655. if (!this.reLocationFiletextToolbarFun) this.reLocationFiletextToolbarFun = this.reLocationFiletextToolbarEvent.bind(this);
  1656. this.filetextScrollNode.addEvent("scroll", this.reLocationFiletextToolbarFun);
  1657. }
  1658. }
  1659. }
  1660. },
  1661. _isAllowEdit:function(){
  1662. if (this.readonly) return false;
  1663. if (this.json.allowEdit=="n") return false;
  1664. if (this.json.allowEdit=="s"){
  1665. if (this.json.allowEditScript && this.json.allowEditScript.code){
  1666. return !!this.form.Macro.exec(this.json.allowEditScript.code, this);
  1667. }
  1668. }
  1669. return true;
  1670. },
  1671. _isAllowPrint: function(){
  1672. if (this.json.allowPrint=="n") return false;
  1673. if (this.json.allowPrint=="s"){
  1674. if (this.json.allowPrintScript && this.json.allowPrintScript.code){
  1675. return !!this.form.Macro.exec(this.json.allowPrintScript.code, this);
  1676. }
  1677. }
  1678. return true;
  1679. },
  1680. _isAllowHistory: function(){
  1681. if (this.json.allowHistory=="n") return false;
  1682. if (this.json.allowHistory=="s"){
  1683. if (this.json.allowHistoryScript && this.json.allowHistoryScript.code){
  1684. return !!this.form.Macro.exec(this.json.allowHistoryScript.code, this);
  1685. }
  1686. }
  1687. return true;
  1688. },
  1689. _getEdit: function(name, typeItem, scriptItem){
  1690. switch (this.json[typeItem]) {
  1691. case "y":
  1692. return true;
  1693. case "n":
  1694. return false;
  1695. case "s":
  1696. if (this.json[scriptItem] && this.json[scriptItem].code){
  1697. return !!this.form.Macro.exec(this.json[scriptItem].code, this);
  1698. }
  1699. return true;
  1700. }
  1701. },
  1702. loadCkeditorStyle: function(node){
  1703. if (node){
  1704. o2.load("ckeditor", function(){
  1705. //CKEDITOR.disableAutoInline = true;
  1706. node.setAttribute('contenteditable', true);
  1707. var editor = CKEDITOR.inline(this.layout_filetext, this._getEditorConfig());
  1708. this.filetextEditor.on("instanceReady", function(e){
  1709. if (callback) callback(e);
  1710. }.bind(this));
  1711. }.bind(this));
  1712. }
  1713. },
  1714. _loadToolbars: function(){
  1715. var html ="";
  1716. var editdoc, printdoc, history, fullscreen=MWF.xApplication.process.Xform.LP.fullScreen;
  1717. if (layout.mobile){
  1718. editdoc = MWF.xApplication.process.Xform.LP.editdoc_mobile;
  1719. printdoc = MWF.xApplication.process.Xform.LP.printdoc_mobile;
  1720. history = MWF.xApplication.process.Xform.LP.history_mobile;
  1721. }else{
  1722. editdoc = MWF.xApplication.process.Xform.LP.editdoc;
  1723. printdoc = MWF.xApplication.process.Xform.LP.printdoc;
  1724. history = MWF.xApplication.process.Xform.LP.history;
  1725. }
  1726. // if (this.allowEdit){
  1727. // //html += "<span MWFnodetype=\"MWFToolBarButton\" MWFButtonImage=\"../x_component_process_Xform/$Form/default/icon/editdoc.png\" title=\""+MWF.xApplication.process.Xform.LP.editdoc+"\" MWFButtonAction=\"_switchReadOrEdit\" MWFButtonText=\""+MWF.xApplication.process.Xform.LP.editdoc+"\"></span>";
  1728. // html += "<span MWFnodetype=\"MWFToolBarButton\" MWFButtonImage=\"../x_component_process_Xform/$Form/default/icon/editdoc.png\" title=\""+editdoc+"\" MWFButtonAction=\"_switchReadOrEditInline\" MWFButtonText=\""+editdoc+"\"></span>";
  1729. // //html += "<span MWFnodetype=\"MWFToolBarButton\" MWFButtonImage=\"../x_component_process_Xform/$Form/default/icon/headerdoc.png\" title=\""+MWF.xApplication.process.Xform.LP.headerdoc+"\" MWFButtonAction=\"_redheaderDoc\" MWFButtonText=\""+MWF.xApplication.process.Xform.LP.headerdoc+"\"></span>";
  1730. // }
  1731. if (this.allowPrint){
  1732. html += "<span MWFnodetype=\"MWFToolBarButton\" MWFButtonImage=\"../x_component_process_Xform/$Form/default/icon/print.png\" title=\""+printdoc+"\" MWFButtonAction=\"_printDoc\" MWFButtonText=\""+printdoc+"\"></span>";
  1733. }
  1734. if (this.allowHistory){
  1735. html += "<span MWFnodetype=\"MWFToolBarButton\" MWFButtonImage=\"../x_component_process_Xform/$Form/default/icon/versions.png\" title=\""+history+"\" MWFButtonAction=\"_historyDoc\" MWFButtonText=\""+history+"\"></span>";
  1736. }
  1737. if (this.json.canFullScreen!=="n"){
  1738. html += "<span MWFnodetype=\"MWFToolBarButton\" MWFButtonImage=\"../x_component_process_Xform/$Form/default/icon/fullscreen.png\" title=\""+fullscreen+"\" MWFButtonAction=\"fullScreen\" MWFButtonText=\""+fullscreen+"\"></span>";
  1739. }
  1740. // if (this.json.fullWidth=="y"){
  1741. // html += "<span style='line-height: 26px; color: #999999; font-size: 12px'>已启用半角空格自动转换为全角空格,如需输入半角空格,请使用:SHIFT+空格</span>"
  1742. // }
  1743. this.toolbarNode = new Element("div", {"styles": this.css.doc_toolbar_node}).inject(this.toolNode);
  1744. this.toolbarNode.set("html", html);
  1745. MWF.require("MWF.widget.Toolbar", function() {
  1746. this.toolbar = new MWF.widget.Toolbar(this.toolbarNode, {"style": "documentEdit"}, this);
  1747. this.toolbar.load();
  1748. }.bind(this));
  1749. if (!layout.mobile){
  1750. this.scrollNode = this.toolbarNode.getParentSrcollNode();
  1751. if (this.scrollNode){
  1752. this.scrollNode.addEvent("scroll", function(){
  1753. this.resetToolbarEvent();
  1754. }.bind(this));
  1755. }
  1756. }
  1757. //if (this.json.canDoublePage!=="n" && !layout.mobile){
  1758. this.doublePageAction = new Element("div", {"styles": this.css.doc_toolbar_doublePage, "text": MWF.xApplication.process.Xform.LP.doublePage}).inject(this.toolbarNode);
  1759. this.doublePageAction.addEvent("click", function(){
  1760. if (this.options.pageShow!=="double"){
  1761. this._doublePage();
  1762. }else{
  1763. this.options.pageShow="single";
  1764. this.reload();
  1765. // this._singlePage();
  1766. var _self = this;
  1767. window.setTimeout(function(){
  1768. _self.scaleTo(_self.documenteditorScale);
  1769. },10);
  1770. }
  1771. }.bind(this));
  1772. if (this.json.canDoublePage==="n" || layout.mobile) this.doublePageAction.hide();
  1773. //}
  1774. this.zoomActionArea = new Element("div", {"styles": {"float": "right", "margin-right": "10px"}}).inject(this.toolbarNode);
  1775. if (this.json.isScale !== "y") this.zoomActionArea.hide();
  1776. this.zoomAddAction = new Element("div", {
  1777. "styles": {
  1778. "float": "right",
  1779. "margin-top": "3px",
  1780. "height": "20px",
  1781. "width": "20px",
  1782. "text-align": "center",
  1783. "line-height": "20px",
  1784. "border": "1px solid #cccccc",
  1785. "background-color": "#ffffff",
  1786. "margin-left": "5px"
  1787. },
  1788. "text": "+"
  1789. }).inject(this.zoomActionArea);
  1790. this.zoomSelectAction = new Element("select", {
  1791. "styles": {
  1792. "float": "right",
  1793. "margin-top": "3px",
  1794. "height": "20px",
  1795. "width": "60px",
  1796. "text-align": "center",
  1797. "line-height": "20px",
  1798. "border": "1px solid #cccccc",
  1799. "background-color": "#ffffff",
  1800. "margin-left": "5px"
  1801. },
  1802. "text": "100%"
  1803. }).inject(this.zoomActionArea);
  1804. this.zoomSubAction = new Element("div", {
  1805. "styles": {
  1806. "float": "right",
  1807. "margin-top": "3px",
  1808. "height": "20px",
  1809. "width": "20px",
  1810. "text-align": "center",
  1811. "line-height": "20px",
  1812. "border": "1px solid #cccccc",
  1813. "background-color": "#ffffff",
  1814. "margin-left": "5px"
  1815. },
  1816. "text": "-"
  1817. }).inject(this.zoomActionArea);
  1818. // this.zoomSelectAction = new Element("select", {"styles": {"float": "right"}}).inject(this.toolbarNode);
  1819. var options = "<option value='2'>200%</option> " +
  1820. "<option value='1.95'>195%</option>" +
  1821. "<option value='1.9'>190%</option>" +
  1822. "<option value='1.85'>185%</option>" +
  1823. "<option value='1.8'>180%</option>" +
  1824. "<option value='1.75'>175%</option>" +
  1825. "<option value='1.7'>170%</option>" +
  1826. "<option value='1.65'>165%</option>" +
  1827. "<option value='1.6'>160%</option>" +
  1828. "<option value='1.55'>155%</option>" +
  1829. "<option value='1.5'>150%</option> " +
  1830. "<option value='1.45'>145%</option>" +
  1831. "<option value='1.4'>140%</option>" +
  1832. "<option value='1.35'>135%</option>" +
  1833. "<option value='1.3'>130%</option>" +
  1834. "<option value='1.25'>125%</option>" +
  1835. "<option value='1.2'>120%</option>" +
  1836. "<option value='1.15'>115%</option>" +
  1837. "<option value='1.1'>110%</option>" +
  1838. "<option value='1.05'>105%</option>" +
  1839. "<option value='1' selected>100%</option>" +
  1840. "<option value='0.95'>95%</option>" +
  1841. "<option value='0.90'>90%</option>" +
  1842. "<option value='0.85'>85%</option>" +
  1843. "<option value='0.80'>80%</option>" +
  1844. "<option value='0.75'>75%</option>" +
  1845. "<option value='0.70'>70%</option>" +
  1846. "<option value='0.65'>65%</option>" +
  1847. "<option value='0.6'>60%</option>" +
  1848. "<option value='0.55'>55%</option>" +
  1849. "<option value='0.5'>50%</option>";
  1850. this.zoomSelectAction.set("html", options);
  1851. this.zoomSelectAction.addEvent("change", function(e){
  1852. this.scaleTo(e.target.options[e.target.selectedIndex].value);
  1853. o2.UD.putData("documenteditorScale", {"scale": this.scale});
  1854. this.documenteditorScale = this.scale;
  1855. }.bind(this));
  1856. this.zoomAddAction.addEvent("click", function(){
  1857. var i = (this.scale/0.05).toInt();
  1858. if (i*0.05<this.scale) i++;
  1859. var v = i*0.05;
  1860. //var v = this.zoomSelectAction.options[this.zoomSelectAction.selectedIndex].value.toFloat();
  1861. v = v+0.05;
  1862. if (v<0.5) v = 0.5;
  1863. if (v>2) v = 2;
  1864. this.scaleTo(v);
  1865. o2.UD.putData("documenteditorScale", {"scale": this.scale});
  1866. this.documenteditorScale = this.scale;
  1867. }.bind(this));
  1868. this.zoomSubAction.addEvent("click", function(){
  1869. var i = (this.scale/0.05).toInt();
  1870. if (i*0.05<this.scale) i++;
  1871. var v = i*0.05;
  1872. //var v = this.zoomSelectAction.options[this.zoomSelectAction.selectedIndex].value.toFloat();
  1873. v = v-0.05;
  1874. if (v<0.5) v = 0.5;
  1875. if (v>2) v = 2;
  1876. this.scaleTo(v);
  1877. o2.UD.putData("documenteditorScale", {"scale": this.scale});
  1878. this.documenteditorScale = this.scale;
  1879. }.bind(this));
  1880. },
  1881. _fullScreen: function(){
  1882. this.positionNode = new Element("div").inject(this.node, "after");
  1883. this.node.inject(this.scrollNode, "top");
  1884. this.form.node.hide();
  1885. this.node.setStyle("min-height", "100%");
  1886. this.fireEvent("fullScreen");
  1887. this.isFullScreen = true;
  1888. this.resizeToolbar();
  1889. },
  1890. _returnScreen: function(){
  1891. this.form.node.show();
  1892. this.node.inject(this.positionNode, "before");
  1893. this.positionNode.destroy();
  1894. this.node.setStyle("min-height", "");
  1895. this.fireEvent("returnScreen");
  1896. this.isFullScreen = false;
  1897. this.resizeToolbar();
  1898. },
  1899. fullScreen: function(bt){
  1900. var text = bt.node.get("text");
  1901. var content = this.form.app.content;
  1902. var stopFun = function(e){ e.stopPropagation(); };
  1903. if (text===MWF.xApplication.process.Xform.LP.returnScreen){
  1904. //this.form.node.getParent().show();
  1905. this.form.node.show();
  1906. this.node.inject(this.positionNode, "before");
  1907. this.positionNode.destroy();
  1908. // var styles = content.retrieve("tmpStyles");
  1909. // content.setStyles({
  1910. // "position": styles.position,
  1911. // "overflow": styles.overflow
  1912. // });
  1913. //this.node.setStyles(this.css.returnScreen);
  1914. this.node.setStyle("min-height", "");
  1915. this.fireEvent("returnScreen");
  1916. bt.setText(MWF.xApplication.process.Xform.LP.fullScreen);
  1917. // this.fullScreenScrollNode = this.node.getOffsetParent().getFirst().getParentSrcollNode();
  1918. // if (this.fullScreenScrollNode){
  1919. // if (this.fullScreenScrollResizeToolbarFun) this.fullScreenScrollNode.removeEvent("scroll", this.fullScreenScrollResizeToolbarFun);
  1920. // }
  1921. //this.node.removeEvent("wheel", stopFun);
  1922. this.isFullScreen = false;
  1923. this.resizeToolbar();
  1924. }else{
  1925. // this.positionNode = new Element("div").inject(this.node, "after");
  1926. // this.node.inject(content, "top");
  1927. // this.form.node.hide();
  1928. this.positionNode = new Element("div").inject(this.node, "after");
  1929. this.node.inject(this.scrollNode, "top");
  1930. //this.form.node.getParent().hide();
  1931. this.form.node.hide();
  1932. // var position = content.getStyle("poaition");
  1933. // var overflow = content.getStyle("overflow");
  1934. // content.store("tmpStyles", {"position": position, "overflow": overflow});
  1935. // content.setStyles({
  1936. // "position": "relative",
  1937. // "overflow": "auto"
  1938. // });
  1939. //this.node.setStyles(this.css.fullScreen);
  1940. this.node.setStyle("min-height", "100%");
  1941. this.fireEvent("fullScreen");
  1942. // this.fullScreenScrollNode = this.node.getOffsetParent().getFirst().getParentSrcollNode();
  1943. // if (this.fullScreenScrollNode){
  1944. // this.fullScreenScrollResizeToolbarFun = function(){this.resizeToolbar(this.fullScreenScrollNode);}.bind(this);
  1945. // this.fullScreenScrollResizeToolbarFun();
  1946. // this.fullScreenScrollNode.addEvent("scroll", this.fullScreenScrollResizeToolbarFun);
  1947. // }
  1948. bt.setText(MWF.xApplication.process.Xform.LP.returnScreen);
  1949. this.isFullScreen = true;
  1950. //this.node.addEvent("wheel", stopFun);
  1951. this.resizeToolbar();
  1952. }
  1953. if (this.options.pageShow!=="double"){
  1954. this.getData();
  1955. }
  1956. // this.getData();
  1957. var _self = this;
  1958. window.setTimeout(function(){
  1959. _self.reload();
  1960. },20)
  1961. },
  1962. /**缩放文件内容
  1963. * @param scale{Number} 缩放的比率
  1964. * @example
  1965. * this.form.get("fieldId").scaleTo(0.5);
  1966. */
  1967. scaleTo: function(scale){
  1968. //this._returnScale();
  1969. this.isScale = false;
  1970. this.scale = scale;
  1971. this.zoom();
  1972. // //var w = this.contentNode.getSize().x*this.scale;
  1973. // var w = this.contentNode.offsetWidth*this.scale;
  1974. // //if (layout.userLayout && layout.userLayout.scale) w = w*layout.userLayout.scale;
  1975. // var count = 1;
  1976. // var docPageFullWidth = (this.scale) ? this.scale*this.options.docPageFullWidth : this.options.docPageFullWidth;
  1977. // //if (layout.userLayout && layout.userLayout.scale) docPageFullWidth = docPageFullWidth*layout.userLayout.scale;
  1978. // var pageWidth = count * docPageFullWidth;
  1979. // var margin = (w-pageWidth)/(count+1);
  1980. // if (this.isScale){
  1981. // margin = "10";
  1982. // }
  1983. // if (this.scale) margin = margin/this.scale;
  1984. // if (margin < 10){
  1985. // var offset = 10-margin;
  1986. // margin = 10;
  1987. // this.contentNode.scrollTo(offset, 0);
  1988. // }
  1989. // this.pages.each(function(page, i){
  1990. // page.setStyles({
  1991. // "float": "left",
  1992. // "margin-left": ""+margin+"px"
  1993. // });
  1994. // });
  1995. this.resetNodeSize();
  1996. },
  1997. _repage: function(delay){
  1998. if (this.options.pageShow!=="double"){
  1999. this._singlePage();
  2000. }else{
  2001. this._doublePage();
  2002. }
  2003. if (delay){
  2004. if (!this.form.isLoaded){
  2005. this.form.addEvent("afterLoad", this._checkScale.bind(this));
  2006. }else{
  2007. this._checkScale();
  2008. }
  2009. }else{
  2010. this._checkScale();
  2011. }
  2012. },
  2013. _contentNodeWitdh: function(){
  2014. var w = this.node.getSize().x;
  2015. if (this.history && this.history.historyListAreaNode) w = w-this.history.historyListAreaNode.getComputedSize().totalWidth-2;
  2016. w = w/this.scale;
  2017. this.contentNode.setStyles({
  2018. "width": ""+w+"px"
  2019. });
  2020. },
  2021. _pageMargin: function(){
  2022. this._contentNodeWitdh();
  2023. var w = this.contentNode.offsetWidth.toFloat();
  2024. w = (this.scale) ? this.scale*w : w;
  2025. var count = 1;
  2026. var docPageFullWidth = (this.scale) ? this.scale*this.options.docPageFullWidth : this.options.docPageFullWidth;
  2027. var pageWidth = count * docPageFullWidth;
  2028. var margin = (w-pageWidth)/(count+1);
  2029. if (this.scale) margin = margin/this.scale;
  2030. if (margin<0) margin=0;
  2031. this.pages.each(function(page, i){
  2032. page.setStyles({
  2033. "float": "left",
  2034. "margin-left": ""+margin+"px"
  2035. });
  2036. });
  2037. if (margin==0){
  2038. var scrollLeft = (this.contentNode.scrollWidth - this.contentNode.offsetWidth)/2;
  2039. if (this.contentNode.scrollTo){
  2040. this.contentNode.scrollTo(scrollLeft, 0);
  2041. }else{
  2042. this.contentNode.scrollLeft = scrollLeft;
  2043. }
  2044. }
  2045. this.fireEvent("pagePosition");
  2046. },
  2047. _singlePage: function(){
  2048. //if (this.editMode) this._readFiletext();
  2049. var scale = this.singlePageZoom;
  2050. if (!scale) scale = this.scale || 1;
  2051. if( this.singlePageZoom && this.singlePageZoom.toInt() != 1 ){
  2052. this.isScale = true;
  2053. this.scale = this.singlePageZoom;
  2054. this.singlePageZoom = null;
  2055. }
  2056. //this.zoom(scale);
  2057. this._checkScale();
  2058. this._pageMargin();
  2059. // var w = this.contentNode.getSize().x;
  2060. // var count = 1;
  2061. // var docPageFullWidth = (this.scale) ? this.scale*this.options.docPageFullWidth : this.options.docPageFullWidth;
  2062. // //var docPageFullWidth = this.options.docPageFullWidt;
  2063. //
  2064. // var pageWidth = count * docPageFullWidth;
  2065. // var margin = (w-pageWidth)/(count+1);
  2066. //
  2067. // if (this.isScale){
  2068. // margin = "10";
  2069. // }
  2070. // if (this.scale) margin = margin/this.scale;
  2071. // this.pages.each(function(page, i){
  2072. // page.setStyles({
  2073. // "float": "left",
  2074. // "margin-left": ""+margin+"px"
  2075. // });
  2076. // });
  2077. this.resetNodeSize();
  2078. // this.pages.each(function(page){
  2079. // page.setStyle("float", "none");
  2080. // });
  2081. this.resizeSidebar();
  2082. this.options.pageShow="single";
  2083. this.doublePageAction.set("text", MWF.xApplication.process.Xform.LP.doublePage);
  2084. },
  2085. resetNodeSize: function(){
  2086. //var contentSize = this.contentNode.getSize();
  2087. var contentHeight = this.contentNode.offsetHeight;
  2088. var toolbarSize = this.toolNode.getSize();
  2089. contentHeight = contentHeight*(this.scale || 1);
  2090. var h = contentHeight+toolbarSize.y+20;
  2091. //h = h - contentSize.y*(1-this.scale);
  2092. this.node.setStyles({
  2093. "height":""+h+"px"
  2094. });
  2095. this.resizeSidebar();
  2096. },
  2097. createWaitSplitPage: function(){
  2098. this.node.mask({
  2099. "style": {
  2100. "background-color": "#cccccc",
  2101. "opacity": 0.3
  2102. }
  2103. });
  2104. this.waitSplitPageNode = new Element("div", {"styles": this.form.css.waitSplitPageNode, "text": MWF.xApplication.process.Xform.LP.computePage}).inject(this.node);
  2105. this.waitSplitPageNode.position({
  2106. "relativeTo": this.node,
  2107. "position": "topRight",
  2108. "edge": "topRight",
  2109. "offset": {
  2110. "x": -10,
  2111. "y": 45
  2112. }
  2113. });
  2114. //this.form.notice(MWF.xApplication.process.Xform.LP.computePage, "info", this.node);
  2115. },
  2116. clearWaitSplitPage: function(){
  2117. this.node.unmask();
  2118. if (this.waitSplitPageNode) this.waitSplitPageNode.destroy();
  2119. this.waitSplitPageNode = null;
  2120. },
  2121. _doublePage: function(){
  2122. if (this.editMode) this._switchReadOrEditInline();
  2123. if( this.zoomSelectAction ){
  2124. this.singlePageZoom = ( this.zoomSelectAction.options[this.zoomSelectAction.selectedIndex].value ).toFloat();
  2125. }
  2126. this.zoom(1);
  2127. this.createWaitSplitPage();
  2128. window.setTimeout(function(){
  2129. this._checkSplitPage(this.pages[0]);
  2130. this.zoom(1);
  2131. var w = this.contentNode.getSize().x;
  2132. var toPageWidth = (w-100)/2;
  2133. scale = toPageWidth/this.options.docPageFullWidth;
  2134. if (scale<1) this.zoom(scale);
  2135. var docPageFullWidth = (this.scale) ? this.scale*this.options.docPageFullWidth : this.options.docPageFullWidth;
  2136. //var docPageFullWidth = this.options.docPageFullWidth;
  2137. var w = this.contentNode.getSize().x;
  2138. var count = (w/docPageFullWidth).toInt();
  2139. var pages = this.contentNode.getElements(".doc_layout_page");
  2140. count = Math.min(pages.length, count);
  2141. var pageWidth = count * docPageFullWidth;
  2142. var margin = (w-pageWidth)/(count+1);
  2143. if (this.scale) margin = margin/(this.scale);
  2144. this.pages.each(function(page, i){
  2145. page.setStyles({
  2146. "float": "left",
  2147. "margin-left": ""+margin+"px"
  2148. });
  2149. });
  2150. // this.pages.each(function(page, i){
  2151. // if ((i % 2)===0){
  2152. // page.setStyle("float", "left");
  2153. // }else{
  2154. // page.setStyle("float", "right");
  2155. // }
  2156. // });
  2157. this.resetNodeSize();
  2158. this.options.pageShow="double";
  2159. this.doublePageAction.set("text", MWF.xApplication.process.Xform.LP.singlePage);
  2160. this.resizeSidebar();
  2161. this.clearWaitSplitPage();
  2162. var s = 0;
  2163. this.pages.forEach(function(page, i){
  2164. s++;
  2165. var styles = {
  2166. "bottom": "-60px",
  2167. "margin-top": "10px",
  2168. "position": "absolute"
  2169. }
  2170. if (s % 2 === 0){
  2171. styles.left = "0";
  2172. }else{
  2173. styles.right = "0";
  2174. }
  2175. var pageNumberNode = new Element("div", {
  2176. "html": "<span>—</span><span> "+s+" </span><span>—</span>",
  2177. "styles": styles
  2178. }).inject(page.getFirst());
  2179. }.bind(this));
  2180. }.bind(this), 1000);
  2181. },
  2182. _getDefaultData: function(){
  2183. return Object.clone(this.json.defaultValue);
  2184. //return Object.clone(MWF.xApplication.process.Xform.LP.documentEditor);
  2185. },
  2186. _loadFiletextPage: function(callback){
  2187. this.data = this._getBusinessData();
  2188. if (!this.data) this.data = this._getDefaultData();
  2189. this._computeData(true);
  2190. this._createPage(function(control){
  2191. this._loadPageLayout(control);
  2192. // this.data = this._getBusinessData();
  2193. // if (!this.data) this.data = this._getDefaultData();
  2194. this.setData(this.data);
  2195. // this._checkSplitPage(this.pages[0]);
  2196. //this._repage(true);
  2197. //this.loadCkeditorFiletext();
  2198. if (!this.readonly){
  2199. //if (this.json.allowEditFiletext!==false) this.loadCkeditorFiletext();
  2200. // if (this.json.allowEditRedheader) this.loadCkeditorRedheader();
  2201. // if (this.json.allowEditSubject) this.loadCkeditorSubject();
  2202. // if (this.json.allowEditMainSend) this.loadCkeditorMainSend();
  2203. // if (this.json.allowEditFileNo) this.loadCkeditorFileNo();
  2204. // if (this.json.allowEditSigner) this.loadCkeditorSigner();
  2205. // if (this.json.allowEditAttachment) this.loadCkeditorAttachment();
  2206. }
  2207. if (!this.editMode && this.allowEdit && !this.historyMode){
  2208. this._editFiletext("inline");
  2209. //if (this.loadFileTextEditFun) this.layout_filetext.removeEvent("click", this.loadFileTextEditFun);
  2210. this.editMode = true;
  2211. }
  2212. if (callback) callback();
  2213. }.bind(this));
  2214. },
  2215. _getEditorConfig: function(editorName){
  2216. // var mathElements = [
  2217. // 'math',
  2218. // 'maction',
  2219. // 'maligngroup',
  2220. // 'malignmark',
  2221. // 'menclose',
  2222. // 'merror',
  2223. // 'mfenced',
  2224. // 'mfrac',
  2225. // 'mglyph',
  2226. // 'mi',
  2227. // 'mlabeledtr',
  2228. // 'mlongdiv',
  2229. // 'mmultiscripts',
  2230. // 'mn',
  2231. // 'mo',
  2232. // 'mover',
  2233. // 'mpadded',
  2234. // 'mphantom',
  2235. // 'mroot',
  2236. // 'mrow',
  2237. // 'ms',
  2238. // 'mscarries',
  2239. // 'mscarry',
  2240. // 'msgroup',
  2241. // 'msline',
  2242. // 'mspace',
  2243. // 'msqrt',
  2244. // 'msrow',
  2245. // 'mstack',
  2246. // 'mstyle',
  2247. // 'msub',
  2248. // 'msup',
  2249. // 'msubsup',
  2250. // 'mtable',
  2251. // 'mtd',
  2252. // 'mtext',
  2253. // 'mtr',
  2254. // 'munder',
  2255. // 'munderover',
  2256. // 'semantics',
  2257. // 'annotation',
  2258. // 'annotation-xml'
  2259. // ];
  2260. //CKEDITOR.plugins.addExternal('ckeditor_wiris', 'https://ckeditor.com/docs/ckeditor4/4.13.0/examples/assets/plugins/ckeditor_wiris/', 'plugin.js');
  2261. var editorConfig = {
  2262. qtRows: 20, // Count of rows
  2263. qtColumns: 20, // Count of columns
  2264. qtBorder: '1', // Border of inserted table
  2265. qtWidth: '95%', // Width of inserted table
  2266. qtStyle: { 'border-collapse' : 'collapse' },
  2267. qtClass: 'documenteditor_table'+this.form.json.id+this.json.id, // Class of table
  2268. qtCellPadding: '0', // Cell padding table
  2269. qtCellSpacing: '0', // Cell spacing table
  2270. qtPreviewBorder: '4px double black', // preview table border
  2271. qtPreviewSize: '4px', // Preview table cell size
  2272. qtPreviewBackground: '#c8def4', // preview table background (hover)
  2273. language: o2.language,
  2274. // format_tags: '标题一;标题二;标题三;标题四;正文', // entries is displayed in "Paragraph format"
  2275. format_tags: '标题一;标题二;正文(标题三,四)', // entries is displayed in "Paragraph format"
  2276. 'format_标题一': {
  2277. name: '标题一(三号黑体)',
  2278. element: 'div',
  2279. styles: {
  2280. 'font-family': '黑体',
  2281. 'font-size': '16pt'
  2282. }
  2283. },
  2284. 'format_标题二': {
  2285. name: '标题二(三号楷体)',
  2286. element: 'div',
  2287. styles: {
  2288. 'font-family': '楷体_GB2312',
  2289. 'font-size': '16pt'
  2290. }
  2291. },
  2292. // 'format_标题三': {
  2293. // name: '标题三',
  2294. // element: 'div',
  2295. // styles: {
  2296. // 'font-family': '仿宋_GB2312',
  2297. // 'font-size': '16pt'
  2298. // }
  2299. // },
  2300. // 'format_标题四': {
  2301. // name: '标题四',
  2302. // element: 'div',
  2303. // styles: {
  2304. // 'font-family': '仿宋_GB2312',
  2305. // 'font-size': '16pt'
  2306. // }
  2307. // },
  2308. 'format_正文(标题三,四)': {
  2309. name: '正文(标题三,四)',
  2310. element: 'div',
  2311. styles: {
  2312. 'font-family': '仿宋_GB2312',
  2313. 'font-size': '16pt'
  2314. }
  2315. }
  2316. };
  2317. editorConfig.toolbarGroups = [
  2318. { name: 'document', groups: [ 'mode', 'document', 'doctools' ] },
  2319. { name: 'clipboard', groups: [ 'clipboard', 'undo' ] },
  2320. { name: 'editing', groups: [ 'find', 'selection', 'spellchecker', 'editing' ] },
  2321. { name: 'forms', groups: [ 'forms' ] },
  2322. { name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] },
  2323. { name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align', 'bidi', 'paragraph' ] },
  2324. { name: 'links', groups: [ 'links' ] },
  2325. { name: 'insert', groups: [ 'insert' ] },
  2326. { name: 'styles', groups: [ 'styles' ] },
  2327. { name: 'colors', groups: [ 'colors' ] },
  2328. { name: 'tools', groups: [ 'tools' ] },
  2329. { name: 'others', groups: [ 'others' ] },
  2330. { name: 'about', groups: [ 'about' ] }
  2331. ];
  2332. //editorConfig.extraPlugins = "ecnet,colordialog,tableresize,quicktable,mathjax,ckeditor_wiris";
  2333. //editorConfig.extraPlugins = "ecnet,colordialog,quicktable,tableresize,eqneditor";
  2334. //editorConfig.extraPlugins = "tableresize,quicktable";
  2335. editorConfig.extraPlugins = "quicktable,tableresize";
  2336. //editorConfig.mathJaxLib = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-AMS_HTML',
  2337. //editorConfig.removeButtons = 'NumberedList,Source,Save,NewPage,Preview,Print,Templates,Paste,PasteFromWord,Scayt,Form,Checkbox,Radio,TextField,Textarea,Select,Button,ImageButton,HiddenField,Bold,Italic,Underline,Strike,Subscript,Superscript,CopyFormatting,RemoveFormat,BulletedList,Outdent,Indent,Blockquote,CreateDiv,BidiLtr,BidiRtl,Language,Link,Unlink,Anchor,Image,Flash,HorizontalRule,Smiley,SpecialChar,PageBreak,Iframe,TextColor,BGColor,Maximize,ShowBlocks,About,Styles,Font,FontSize';
  2338. editorConfig.removeButtons = 'EasyImageUpload,ExportPdf,Source,Save,NewPage,Preview,Print,Templates,Paste,PasteFromWord,Scayt,Form,Checkbox,Radio,TextField,Textarea,Select,Button,ImageButton,HiddenField,Bold,Italic,Underline,Strike,Subscript,Superscript,CopyFormatting,RemoveFormat,Outdent,Indent,Blockquote,CreateDiv,BidiLtr,BidiRtl,Language,Link,Unlink,Anchor,Image,Flash,HorizontalRule,Smiley,SpecialChar,PageBreak,Iframe,TextColor,BGColor,Maximize,ShowBlocks,About,Styles,Font,FontSize';
  2339. //editorConfig.removeButtons = 'Source,Save,NewPage,Preview,Print,Templates,Paste,PasteFromWord,Scayt,Form,Checkbox,Radio,TextField,Textarea,Select,Button,ImageButton,HiddenField,Bold,Italic,Underline,Strike,Subscript,Superscript,CopyFormatting,RemoveFormat,Outdent,Indent,Blockquote,CreateDiv,BidiLtr,BidiRtl,Language,Link,Unlink,Anchor,Flash,HorizontalRule,Smiley,SpecialChar,PageBreak,Iframe,TextColor,BGColor,Maximize,ShowBlocks,About,Styles,Font,FontSize';
  2340. //editorConfig.extraAllowedContent = mathElements.join(' ') + '(*)[*]{*};img[data-mathml,data-custom-editor,role](Wirisformula)';
  2341. editorConfig.pasteFromWordRemoveFontStyles = false;
  2342. editorConfig.pasteFromWordRemoveStyles = false;
  2343. editorConfig.pasteFromWordNumberedHeadingToList = false;
  2344. //editorConfig.removeButtons = 'NewPage,Templates,Scayt,Form,Checkbox,Radio,TextField,Textarea,Select,Button,ImageButton,HiddenField,Bold,Italic,Underline,Strike,Subscript,Superscript,Blockquote,CreateDiv,BidiLtr,BidiRtl,Language,Link,Unlink,Anchor,Image,Flash,HorizontalRule,Smiley,SpecialChar,Iframe,Styles,Font,FontSize,TextColor,BGColor,ShowBlocks,About';
  2345. editorConfig.removePlugins = ['magicline','cloudservices','easyimage', 'exportpdf'];
  2346. editorConfig.enterMode = CKEDITOR.ENTER_DIV;
  2347. editorConfig.pasteFilter = "plain-text";
  2348. // editorConfig.extraPlugins = ['ecnet','mathjax'];
  2349. // editorConfig.removePlugins = ['magicline'];
  2350. // editorConfig.mathJaxLib = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-AMS_HTML';
  2351. if (this.json.ckeditConfigOptions && this.json.ckeditConfigOptions.code){
  2352. var o = this.form.Macro.exec(this.json.ckeditConfigOptions.code, this);
  2353. if (o) editorConfig = Object.merge(editorConfig, o);
  2354. }
  2355. if (editorName){
  2356. editorConfig.removeButtons = editorConfig.removeButtons.split(/,\s*/).erase("PageBreak").join(",");
  2357. var tags = editorConfig.format_tags.split(/;\s*/);
  2358. if (tags.indexOf("附件标题")==-1){
  2359. editorConfig.format_tags = "附件标题"+((editorConfig.format_tags) ? ";" : "")+editorConfig.format_tags;
  2360. }
  2361. if (tags.indexOf("附件序号")==-1){
  2362. editorConfig.format_tags = "附件序号"+((editorConfig.format_tags) ? ";" : "")+editorConfig.format_tags;
  2363. }
  2364. if (!editorConfig["format_附件序号"]) editorConfig["format_附件序号"] = {
  2365. name: '附件序号',
  2366. element: 'div',
  2367. styles: {
  2368. 'font-family': '黑体',
  2369. 'font-size': '16pt'
  2370. }
  2371. };
  2372. if (!editorConfig["format_附件标题"]) editorConfig["format_附件标题"] = {
  2373. name: '附件标题',
  2374. element: 'div',
  2375. styles: {
  2376. 'font-family': '方正小标宋简体',
  2377. 'font-size': '22pt',
  2378. 'text-align': 'center'
  2379. }
  2380. }
  2381. }
  2382. return editorConfig;
  2383. },
  2384. _checkSplitPage: function(pageNode){
  2385. if (this.layout_edition) this.layout_edition.setStyles({ "position": "static"});
  2386. var contentNode = pageNode.getFirst();
  2387. if (contentNode.getSize().y>this.options.docPageHeight){
  2388. this._splitPage(pageNode);
  2389. }
  2390. var i = pageNode.get("data-pagecount").toInt();
  2391. if (i && this.pages.length-1>=i){
  2392. this._checkSplitPage(this.pages[i]);
  2393. }
  2394. if (this.layout_edition) this.layout_edition.setStyles({ "position": "absolute", "bottom": "0px" });
  2395. },
  2396. _splitFiletextNodeOneWord:function(lnode, nextPageNode){
  2397. var text = lnode.textContent;
  2398. var len = text.length;
  2399. var left = text.substring(0, len-1);
  2400. var right = text.substring(len-1, len);
  2401. lnode.textContent = left;
  2402. nextPageNode.textContent = right+nextPageNode.textContent;
  2403. //nextPageNode.appendText(right, "top");
  2404. },
  2405. _splitFiletext: function(node, nextPageNode, nextFiletextNode, pageNode){
  2406. var contentNode = pageNode.getFirst();
  2407. var lnode = node.lastChild;
  2408. if (!lnode){
  2409. if (node.parentNode) node.parentNode.removeChild(node);
  2410. //node.remove();
  2411. }else{
  2412. while (contentNode.getSize().y>this.options.docPageHeight && lnode) {
  2413. var tmpnode = lnode.previousSibling;
  2414. var nodeType = lnode.nodeType;
  2415. if (!nextPageNode) nextPageNode = nextFiletextNode;
  2416. if (nodeType == Node.ELEMENT_NODE) {
  2417. if (lnode.tagName == "table") {
  2418. lnode.inject(nextPageNode);
  2419. } else if (lnode.tagName == "BR") {
  2420. if (lnode.parentNode) lnode.parentNode.removeChild(lnode);
  2421. } else {
  2422. var id = lnode.get("data-pagePart");
  2423. if (!id){
  2424. id = (new o2.widget.UUID()).toString();
  2425. lnode.set("data-pagePart", id);
  2426. }
  2427. var tmpNode = nextPageNode.getFirst();
  2428. if (tmpNode && tmpNode.get("data-pagePart")==id){
  2429. nextPageNode = tmpNode;
  2430. }else{
  2431. nextPageNode = lnode.clone(false).inject(nextPageNode, "top");
  2432. }
  2433. //var subnode = lnode.getLast();
  2434. this._splitFiletext(lnode, nextPageNode, nextFiletextNode, pageNode);
  2435. if (!lnode.firstChild) if (lnode.parentNode) lnode.parentNode.removeChild(lnode);
  2436. nextPageNode = nextPageNode.getParent();
  2437. }
  2438. } else if (nodeType == Node.TEXT_NODE) {
  2439. var nextPageTextNode = nextPageNode.insertBefore(document.createTextNode(""), nextPageNode.firstChild);
  2440. while ((contentNode.getSize().y > this.options.docPageHeight) && lnode.textContent) {
  2441. //console.log(contentNode.getSize().y);
  2442. this._splitFiletextNodeOneWord(lnode, nextPageTextNode)
  2443. }
  2444. if (!lnode.textContent) if (lnode.parentNode) lnode.parentNode.removeChild(lnode); //lnode.remove();
  2445. } else {
  2446. //lnode.remove();
  2447. if (lnode.parentNode) lnode.parentNode.removeChild(lnode);
  2448. }
  2449. lnode = tmpnode;
  2450. }
  2451. if (!node.lastChild) if (node.parentNode) node.parentNode.removeChild(node); //node.remove();
  2452. }
  2453. //this._checkSplitPage(pageNode);
  2454. },
  2455. _splitPage: function(pageNode){
  2456. var contentNode = pageNode.getFirst();
  2457. var blockNodes = pageNode.getElements(".doc_block");
  2458. if (blockNodes.length){
  2459. var blockNode = blockNodes[blockNodes.length-1];
  2460. var idx = this.pages.indexOf(pageNode);
  2461. if (this.pages.length<=idx+1) this._createNewPage();
  2462. var nextPage = this.pages[idx+1];
  2463. if (blockNode.hasClass("doc_layout_filetext")){
  2464. var filetextNode = nextPage.getElement(".doc_layout_filetext");
  2465. if (!filetextNode){
  2466. filetextNode = new Element("div.doc_layout_filetext").inject(nextPage.getFirst(), "top");
  2467. //filetextNode.setAttribute('contenteditable', true);
  2468. }
  2469. if (!filetextNode.hasClass("doc_block"))filetextNode.addClass("doc_block");
  2470. //var nextEditor = filetextNode.retrieve("editor");
  2471. var node = blockNode;
  2472. var nextPageNode = filetextNode;
  2473. this._splitFiletext(node, nextPageNode, filetextNode, pageNode);
  2474. }else{
  2475. blockNode.inject(nextPage.getFirst(), "top");
  2476. //var contentNode = pageNode.getFirst();
  2477. if (contentNode.getSize().y>this.options.docPageHeight){
  2478. this._splitPage(pageNode);
  2479. }
  2480. }
  2481. }
  2482. },
  2483. transWidth: function(node){
  2484. if (!node) return '';
  2485. while (node){
  2486. if (node.nodeType==3){
  2487. node.nodeValue = node.nodeValue.replace(/\x20/g, " ");
  2488. }else if (node.nodeType==8){
  2489. //nothing
  2490. }else{
  2491. this.transWidth(node.firstChild);
  2492. }
  2493. node = node.nextSibling;
  2494. }
  2495. },
  2496. insertFullWidth: function(node, txt){
  2497. if (!node) return '';
  2498. while (node){
  2499. if (node.nodeType==3){
  2500. node.nodeValue = txt+node.nodeValue;
  2501. return true;
  2502. }else if (node.nodeType==8){
  2503. //nothing
  2504. }else{
  2505. var flag = this.insertFullWidth(node.firstChild, txt);
  2506. if (flag) return true;
  2507. }
  2508. node = node.nextSibling;
  2509. }
  2510. },
  2511. loadCkeditorFiletext: function(callback, inline, node, editorName){
  2512. if (node || this.layout_filetext){
  2513. o2.load("../o2_lib/htmleditor/ckeditor4161/ckeditor.js", function(){
  2514. CKEDITOR.disableAutoInline = true;
  2515. (node || this.layout_filetext).setAttribute('contenteditable', true);
  2516. var editor;
  2517. try{
  2518. var editorConfig = this._getEditorConfig(editorName);
  2519. editor = CKEDITOR.inline(node || this.layout_filetext, editorConfig);
  2520. this[(editorName || "filetextEditor")] = editor;
  2521. editor.on("instanceReady", function(e){
  2522. var v = e.editor.editable().$.get("text");
  2523. if (!v || v=="  ") e.editor.setData(this.json.defaultValue.filetext);
  2524. if (callback) callback(e);
  2525. }.bind(this));
  2526. editor.on( 'focus', function( e ) {
  2527. window.setTimeout(function(){
  2528. // this.reLocationFiletextToolbar(editorName);
  2529. this.locationFiletextToolbar(editorName);
  2530. }.bind(this), 10);
  2531. var v = e.editor.editable().$.get("text");
  2532. if (!v || v==this.json.defaultValue.filetext){
  2533. e.editor.setData("  ");
  2534. e.editor.focus();
  2535. var range = e.editor.createRange();
  2536. range.moveToElementEditEnd(e.editor.editable());
  2537. range.select();
  2538. }
  2539. }.bind(this) );
  2540. editor.on( 'blur', function( e ) {
  2541. if (!!editorName) this.getAttachmentTextData();
  2542. var v = e.editor.editable().$.get("text");
  2543. if (!v || v=="  ") e.editor.setData(this.json.defaultValue.filetext);
  2544. }.bind(this) );
  2545. editor.on( 'loaded', function( e ) {
  2546. editor.element.$.store("module", this);
  2547. editor.element.$.store("scale", this.scale);
  2548. }.bind(this) );
  2549. editor.on( 'afterPaste', function( e ) {
  2550. }.bind(this));
  2551. editor.on( 'afterPasteFromWord', function( e ) {
  2552. }.bind(this));
  2553. const _self = this;
  2554. editor.on( 'paste', function( e ) {
  2555. var html = e.data.dataValue;
  2556. //if (this.json.fullWidth=="y") html = html.replace(/\x20/g, " ");
  2557. var rexbr = /\<br\>|\<br \/\>|\<br\/\>/g;
  2558. var rexp = /\<p\>/g;
  2559. if (rexbr.test(html) && !rexp.test(html)){
  2560. var ps = html.split(/\<br\>|\<br \/\>|\<br\/\>/g);
  2561. html = "";
  2562. ps.each(function(p){
  2563. html = html + "<p>"+p+"</p>";
  2564. });
  2565. }
  2566. var tmp = new Element("div")
  2567. tmp.set("html", html);
  2568. var pList = tmp.getElements("p");
  2569. pList.each(function(p, i){
  2570. //if (Browser.name=="ie"){
  2571. if (this.json.fullWidth!=="n") this.transWidth(p);
  2572. if (!p.getParent("table")){
  2573. var text = p.get("text");
  2574. var rex = /^\u3000*/;
  2575. var m = text.match(rex);
  2576. var l = (m[0]) ? Math.max((2-m[0].length), 0): 2;
  2577. var txt = "";
  2578. // for (var i=0; i<l; i++) txt+=" ";
  2579. // this.insertFullWidth(p.getFirst(), txt);
  2580. for (var i=0; i<l; i++) p.appendText(" ","top");
  2581. }
  2582. //}else{
  2583. // var textIndent = p.getStyle("text-indent");
  2584. // if (textIndent.toInt()) p.appendText("  ","top");
  2585. //}
  2586. }.bind(this));
  2587. var tableList = tmp.getElements("table");
  2588. if (tableList && tableList.length){
  2589. var w = (node || this.layout_filetext).offsetWidth.toFloat()-2;
  2590. tableList.each(function(table){
  2591. const rTable = _self.cloneTable(table, editorConfig);
  2592. rTable.inject(table, 'after');
  2593. table.destroy();
  2594. // var twstyle = table.getStyle("width");
  2595. // var tws = (twstyle) ? (twstyle.toFloat() || 0) : 0;
  2596. // var twatt = table.get("width");
  2597. // var twa = (twatt) ? (twatt.toFloat() || 0) : 0;
  2598. // var tw = Math.max(tws, twa);
  2599. // if (tw===0 || tw>w){
  2600. // table.setStyle("width", ""+w+"px");
  2601. // }
  2602. });
  2603. tableList.setStyles({
  2604. "margin-left": "",
  2605. "margin-right": "",
  2606. "word-break": "break-all"
  2607. });
  2608. }
  2609. // var tdList = tmp.getElements("td");
  2610. // tdList.each(function(td){
  2611. // var tbw_top = td.getStyle("border-top-width").toFloat() || 0;
  2612. // var tbw_bottom = td.getStyle("border-bottom-width").toFloat() || 0;
  2613. // var tbw_left = td.getStyle("border-left-width").toFloat() || 0;
  2614. // var tbw_right = td.getStyle("border-right-width").toFloat() || 0;
  2615. //
  2616. // td.setStyles({
  2617. // "border-top-width": (tbw_top/2)+"px",
  2618. // "border-bottom-width": (tbw_bottom/2)+"px",
  2619. // "border-left-width": (tbw_left/2)+"px",
  2620. // "border-right-width": (tbw_right/2)+"px",
  2621. // });
  2622. // });
  2623. e.data.dataValue = tmp.get("html");
  2624. tmp.destroy();
  2625. this.fireEvent("paste");
  2626. }.bind(this) );
  2627. editor.on( 'afterPaste', function( e ) {
  2628. this.resetNodeSize();
  2629. this.fireEvent("afterPaste");
  2630. }.bind(this) );
  2631. editor.on( 'change', function( e ) {
  2632. var h = document.documentElement.scrollTop;
  2633. var scrollNode = this.contentNode;
  2634. while (scrollNode && (scrollNode.getScrollSize().y<=scrollNode.getSize().y || (scrollNode.getStyle("overflow")!=="auto" && scrollNode.getStyle("4-y")!=="auto"))){
  2635. scrollNode = scrollNode.getParent();
  2636. }
  2637. if (scrollNode){
  2638. var top = scrollNode.scrollTop.toFloat();
  2639. scrollNode.scrollTop = h+top;
  2640. }
  2641. document.documentElement.scrollTop = 0;
  2642. if (!!editorName) this.getAttachmentTextData();
  2643. o2.defer(this.resetNodeSize, 500, this);
  2644. }.bind(this) );
  2645. editor.on( 'insertElement', function( e ) {
  2646. if (e.data.$.tagName.toString().toLowerCase()=="table"){
  2647. e.data.$.setStyles({
  2648. "margin-left": "",
  2649. "margin-right": "",
  2650. "word-break": "break-all"
  2651. });
  2652. }
  2653. var tr = e.data.$.getElement("tr");
  2654. if (tr){
  2655. var tds = tr.getElements("td");
  2656. if (tds && tds.length){
  2657. var p = 100/tds.length;
  2658. tds.setStyle("width", ""+p+"%");
  2659. }
  2660. }
  2661. }.bind(this) );
  2662. if (this.json.textIndent!=="n"){
  2663. (node || this.layout_filetext).addEvent("keyup", function(ev){
  2664. if (ev.code==13) editor.insertText("  ");
  2665. }.bind(this));
  2666. }
  2667. if (this.json.fullWidth!=="n"){
  2668. editor.addCommand( 'insertHalfSpace', {
  2669. exec: function( editor ) {
  2670. editor.insertText(" ");
  2671. }
  2672. } );
  2673. editor.setKeystroke( CKEDITOR.SHIFT + 32, 'insertHalfSpace' );
  2674. editor.on("key", function(e){
  2675. if (this.json.fullWidth!=="n") if (e.data.keyCode==32){
  2676. e.editor.insertText(" ");
  2677. e.cancel();
  2678. }
  2679. }.bind(this));
  2680. }
  2681. }catch(e){
  2682. editor = this[(editorName || "filetextEditor")];
  2683. }
  2684. }.bind(this));
  2685. }
  2686. },
  2687. getTableWidth(table) {
  2688. var twstyle = table.getStyle("width");
  2689. var tws = (twstyle) ? (parseFloat(twstyle) || 0) : 0;
  2690. var twatt = table.get("width");
  2691. var twa = (twatt) ? (parseFloat(twatt) || 0) : 0;
  2692. return Math.max(tws, twa);
  2693. },
  2694. cloneTable(table, editorConfig) {
  2695. const rows = table.rows;
  2696. const w = this.getTableWidth(table);
  2697. const rTable = new Element('table');
  2698. rTable.set({
  2699. "border": editorConfig.qtBorder,
  2700. "cellpadding": editorConfig.qtCellPadding || 0,
  2701. "cellspacing": editorConfig.qtCellSpacing || 0,
  2702. "class": editorConfig.qtClass
  2703. });
  2704. rTable.setStyles(editorConfig.qtStyle);
  2705. rTable.setStyles({
  2706. "width": editorConfig.qtWidth,
  2707. "word-break": "break-all"
  2708. });
  2709. rTable.dataset.tableType = 'o2';
  2710. for (let i = 0; i < rows.length; i++) {
  2711. const r = rows.item(i);
  2712. const cr = new Element(r.tagName);
  2713. cr.inject(rTable, 'bottom');
  2714. const cells = r.getElements('td,th');
  2715. cells.forEach((c) => {
  2716. const cc = new Element(c.tagName);
  2717. const rowspan = c.getAttribute('rowspan');
  2718. const colspan = c.getAttribute('colspan');
  2719. if (rowspan) cc.set('rowspan', rowspan);
  2720. if (colspan) cc.set('colspan', colspan);
  2721. const w = c.getStyle('width');
  2722. if (w) cc.setStyle('width', w);
  2723. const pw = c.get('width');
  2724. if (w) cc.set('width', pw);
  2725. cc.set('html', c.get('html'));
  2726. cc.inject(cr, 'bottom');
  2727. });
  2728. }
  2729. return rTable;
  2730. },
  2731. _loadEvents: function(editorConfig){
  2732. Object.each(this.json.events, function(e, key){
  2733. if (e.code){
  2734. this.editor.on(key, function(event){
  2735. return this.form.Macro.fire(e.code, this, event);
  2736. }.bind(this), this);
  2737. }
  2738. }.bind(this));
  2739. },
  2740. _bindFieldChange: function(name,dataItem, dom){
  2741. var field = this.form.all[this.json[dataItem]];
  2742. if (field){
  2743. var bindFun = function(){
  2744. this._computeItemFieldData(name, dataItem);
  2745. //if (this.data[name]){
  2746. if (this[dom]){
  2747. if (dom=="layout_redHeader" ||dom=="layout_issuanceUnit" || dom=="layout_meetingAttendContent" || dom=="layout_meetingLeaveContent" || dom=="layout_meetingSitContent" || dom=="layout_meetingRecordContent" || dom=="layout_signer") {
  2748. this[dom].set("html", this.filterHtml(this.data[name] || ""));
  2749. }else if (dom=="layout_subject"){
  2750. this[dom].set("html", (this.data[name] || ""));
  2751. }else if (dom=="layout_attachment"){
  2752. this.setAttachmentData();
  2753. }else if (dom=="layout_annotation"){
  2754. var annotation = this.data[name];
  2755. if (annotation){
  2756. if (annotation.substring(0, 1)!=="(") annotation = "("+annotation;
  2757. if (annotation.substring(annotation.length-1, annotation.length)!==")") annotation = annotation+")";
  2758. this[dom].set("text", annotation);
  2759. }else{
  2760. this[dom].set("text", "");
  2761. }
  2762. }else{
  2763. this[dom].set("text", this.data[name]|| "");
  2764. }
  2765. }
  2766. this.reSetShow();
  2767. //}
  2768. }.bind(this);
  2769. field.node.store(this.json.id+"bindFun", bindFun);
  2770. field.addModuleEvent("change", bindFun);
  2771. }
  2772. },
  2773. _computeItemFieldData: function(name, dataItem, dataItemNode){
  2774. var v = "";
  2775. var module = (dataItemNode) ? this.form.all[dataItemNode] : this.form.all[this.json[dataItem]];
  2776. if (module && module.getData) v = module.getData();
  2777. if (!v) v = (dataItemNode) ? this.form.businessData.data[dataItemNode] : this.form.businessData.data[this.json[dataItem]];
  2778. if (v){
  2779. var t = o2.typeOf(v);
  2780. switch (t) {
  2781. case "string":
  2782. switch (name) {
  2783. case "issuanceDate":
  2784. case "editionDate":
  2785. var d = new Date(v);
  2786. if (d && d.isValid() && d.getFullYear()!=1970){
  2787. var y = d.getFullYear();
  2788. var m = d.getMonth();
  2789. var day = d.getDate();
  2790. m = m +1;
  2791. var lp = MWF.xApplication.process.Xform.LP;
  2792. this.data[name] = ""+y+lp.year+m+lp.month+day+lp.date;
  2793. }else{
  2794. this.data[name] = v;
  2795. }
  2796. //this.data[name] = (new Date(v).isValid()) ? Date.parse(v).format("%Y年%m月%d%日") : v;
  2797. break;
  2798. case "mainSend":
  2799. this.data[name] = v + ":";
  2800. break;
  2801. case "copyto":
  2802. case "copyto2":
  2803. var flag = (v.substring(v.length-1, v.length)=="。");
  2804. this.data[name] = v + ((flag) ? "" : "。");
  2805. break;
  2806. default:
  2807. if (name==="subject") v = o2.txt(v);
  2808. this.data[name] = v;
  2809. }
  2810. break;
  2811. case "array":
  2812. var strs = [];
  2813. var strLength = 0;
  2814. v.each(function(value){
  2815. if (o2.typeOf(value)=="object" && value.distinguishedName){
  2816. if (value.name.length>strLength) strLength = value.name.length;
  2817. strs.push(value.name);
  2818. }else{
  2819. if (value.length>strLength) strLength = value.length;
  2820. strs.push(value.toString());
  2821. }
  2822. });
  2823. //if (strs.length){
  2824. switch (name) {
  2825. case "attachment":
  2826. // this.data[name] = strs.map(function(n, i){ var j = i+1; return j+"、"+n}).join("<br>");
  2827. var atts = strs.map(function(a){
  2828. return (a.indexOf(".")!=-1) ? a.substring(0, a.lastIndexOf(".")) : a;
  2829. });
  2830. this.data[name] = atts;
  2831. break;
  2832. case "issuanceDate":
  2833. case "editionDate":
  2834. var tmpStrs = strs.map(function(n, i){
  2835. var d = Date.parse(n);
  2836. if (d && d.isValid() && d.getFullYear()!=1970){
  2837. var y = d.getFullYear();
  2838. var m = d.getMonth();
  2839. var day = d.getDate();
  2840. m = m +1;
  2841. var lp = MWF.xApplication.process.Xform.LP;
  2842. return ""+y+lp.year+m+lp.month+day+lp.date;
  2843. }else{
  2844. return n;
  2845. }
  2846. //return () ? d.format("%Y年%m月%d日") : n;
  2847. });
  2848. this.data[name] = tmpStrs.join(",");
  2849. break;
  2850. case "signer":
  2851. var signers = "";
  2852. strs.each(function(name, i){
  2853. while (name.length<strLength){ name = name+" ";}
  2854. //signers.push(name);
  2855. if (i % 2==0){
  2856. signers = signers+name+" ";
  2857. }else{
  2858. signers = signers+name+"<br>";
  2859. }
  2860. });
  2861. this.data[name] = signers;
  2862. break;
  2863. case "mainSend":
  2864. this.data[name] = strs.length ? strs.join(",") + ":" : "";
  2865. break;
  2866. case "copyto":
  2867. case "copyto2":
  2868. this.data[name] = strs.length ? strs.join(",") + "。" : "";
  2869. break;
  2870. default:
  2871. this.data[name] = strs.join(",");
  2872. }
  2873. //}
  2874. break;
  2875. default:
  2876. this.data[name] = v.toString();
  2877. }
  2878. }else{
  2879. this.data[name] = this.json.defaultValue[name];
  2880. }
  2881. },
  2882. computeData: function(){
  2883. this._computeData(false);
  2884. this.setData(this.data);
  2885. },
  2886. _computeItemData: function(name, typeItem, dataItem, scriptItem, ev, dom){
  2887. switch (this.json[typeItem]) {
  2888. case "data":
  2889. if (this.json[dataItem]){
  2890. if (ev) this._bindFieldChange(name, dataItem, dom);
  2891. this._computeItemFieldData(name, dataItem);
  2892. }
  2893. break;
  2894. case "script":
  2895. if (this.json[scriptItem] && this.json[scriptItem].code){
  2896. var v = this.form.Macro.exec(this.json[scriptItem].code, this);
  2897. this.data[name] = v;
  2898. if (name=="attachment"){
  2899. //this.data[name] = (typeOf(v)=="array") ? v.map(function(n, i){ var j = i+1; return j+"、"+n}).join("<br>") : v;
  2900. this.data[name] = (typeOf(v)=="array") ? v : [v];
  2901. }
  2902. if (name=="signer"){
  2903. var strs = [];
  2904. var strLength = 0;
  2905. if (o2.typeOf(v)!=="array") v = [v];
  2906. v.each(function(value){
  2907. if (o2.typeOf(value)=="object" && value.distinguishedName){
  2908. if (value.name.length>strLength) strLength = value.name.length;
  2909. strs.push(value.name);
  2910. }else{
  2911. if (value.length>strLength) strLength = value.length;
  2912. strs.push(value.toString());
  2913. }
  2914. });
  2915. var signers = "";
  2916. strs.each(function(name, i){
  2917. while (name.length<strLength){ name = name+" ";}
  2918. //signers.push(name);
  2919. if (i % 2==0){
  2920. signers = signers+name+" ";
  2921. }else{
  2922. signers = signers+name+"<br>";
  2923. }
  2924. });
  2925. this.data[name] = signers;
  2926. }
  2927. if (name=="issuanceDate" || name=="editionDate"){
  2928. var d = Date.parse(v);
  2929. if (d && d.isValid() && d.getFullYear()!=1970){
  2930. var y = d.getFullYear();
  2931. var m = d.getMonth();
  2932. var day = d.getDate();
  2933. m = m +1;
  2934. var lp = MWF.xApplication.process.Xform.LP;
  2935. this.data[name] = ""+y+lp.year+m+lp.month+day+lp.date;
  2936. }else{
  2937. this.data[name] = v;
  2938. }
  2939. //this.data[name] = (d.isValid() && d.getFullYear()!=1970) ? d.format("%Y年%m月%d日") : v;
  2940. }
  2941. }
  2942. break;
  2943. }
  2944. },
  2945. _computeCustomItemData: function(name, field, ev){
  2946. //if (this.json.customFields[l.name]){
  2947. if (ev) this._bindCustomFieldChange(name, field, name);
  2948. this._computeItemFieldData(name, null, field);
  2949. //}
  2950. },
  2951. _bindCustomFieldChange: function(name, dataItem, dom){
  2952. var field = this.form.all[dataItem];
  2953. if (field){
  2954. var bindFun = function(){
  2955. this._computeItemFieldData(name, null, dataItem);
  2956. //if (this.data[name]){
  2957. if (this[dom]){
  2958. var value = this.data[name] || "";
  2959. var reg = new RegExp("\n","g");
  2960. var text = value.replace(reg,"<br/>");
  2961. if (dom=="layout_redHeader" || dom=="layout_issuanceUnit") {
  2962. this[dom].set("html", this.data[name] || "");
  2963. }else if (dom=="layout_subject"){
  2964. this[dom].set("html", (this.data[name] || ""));
  2965. }else if (dom=="layout_attachment"){
  2966. this.setAttachmentData();
  2967. }else{
  2968. this[dom].set("html", text|| "");
  2969. }
  2970. }
  2971. this.reSetShow();
  2972. //}
  2973. }.bind(this);
  2974. field.node.store(this.json.id+"bindFun", bindFun);
  2975. field.addModuleEvent("change", bindFun);
  2976. }
  2977. },
  2978. _computeData: function(ev){
  2979. this._computeItemData("copies", "copiesValueType", "copiesValueData", "copiesValueScript", ev, "layout_copies");
  2980. this._computeItemData("secret", "secretValueType", "secretValueData", "secretValueScript", ev, "layout_secret");
  2981. this._computeItemData("priority", "priorityValueType", "priorityValueData", "priorityValueScript", ev, "layout_priority");
  2982. this._computeItemData("redHeader", "redHeaderValueType", "redHeaderValueData", "redHeaderValueScript", ev, "layout_redHeader");
  2983. this._computeItemData("fileno", "filenoValueType", "filenoValueData", "filenoValueScript", ev, "layout_fileno");
  2984. this._computeItemData("signer", "signerValueType", "signerValueData", "signerValueScript", ev, "layout_signer");
  2985. this._computeItemData("subject", "subjectValueType", "subjectValueData", "subjectValueScript", ev, "layout_subject");
  2986. this._computeItemData("mainSend", "mainSendValueType", "mainSendValueData", "mainSendValueScript", ev, "layout_mainSend");
  2987. this._computeItemData("attachment", "attachmentValueType", "attachmentValueData", "attachmentValueScript", ev, "layout_attachment");
  2988. this._computeItemData("issuanceUnit", "issuanceUnitValueType", "issuanceUnitValueData", "issuanceUnitValueScript", ev, "layout_issuanceUnit");
  2989. this._computeItemData("issuanceDate", "issuanceDateValueType", "issuanceDateValueData", "issuanceDateValueScript", ev, "layout_issuanceDate");
  2990. this._computeItemData("annotation", "annotationValueType", "annotationValueData", "annotationValueScript", ev, "layout_annotation");
  2991. this._computeItemData("copyto", "copytoValueType", "copytoValueData", "copytoValueScript", ev, "layout_copytoContent");
  2992. this._computeItemData("copyto2", "copyto2ValueType", "copyto2ValueData", "copyto2ValueScript", ev, "layout_copyto2Content");
  2993. this._computeItemData("editionUnit", "editionUnitValueType", "editionUnitValueData", "editionUnitValueScript", ev, "layout_edition_issuance_unit");
  2994. this._computeItemData("editionDate", "editionDateValueType", "editionDateValueData", "editionDateValueScript", ev, "layout_edition_issuance_date");
  2995. this._computeItemData("meetingAttend", "meetingAttendValueType", "meetingAttendValueData", "meetingAttendValueScript", ev, "layout_meetingAttendContent");
  2996. this._computeItemData("meetingLeave", "meetingLeaveValueType", "meetingLeaveValueData", "meetingLeaveValueScript", ev, "layout_meetingLeaveContent");
  2997. this._computeItemData("meetingSit", "meetingSitValueType", "meetingSitValueData", "meetingSitValueScript", ev, "layout_meetingSitContent");
  2998. this._computeItemData("meetingRecord", "meetingRecordValueType", "meetingRecordValueData", "meetingRecordValueScript", ev, "layout_meetingRecordContent");
  2999. Object.each(this.json.customFields, function(field, k){
  3000. this._computeCustomItemData(k, field, ev);
  3001. }.bind(this));
  3002. // if (this.customLayouts){
  3003. // this.customLayouts.each(function(l){
  3004. // this._computeCustomItemData(l, ev);
  3005. // }.bind(this))
  3006. // }
  3007. },
  3008. _loadValue: function(){
  3009. var data = this._getBusinessData();
  3010. },
  3011. /**重新计算公文编辑器的所有字段,当字段是脚本时可以使用该方法立即更新
  3012. * @summary 重新计算公文编辑器的所有字段
  3013. * @example
  3014. * this.form.get("fieldId").reload();
  3015. */
  3016. reload: function(callback){
  3017. this.resetData(false, callback);
  3018. },
  3019. resetData: function(diffFiletext, callback){
  3020. this._computeData(false);
  3021. this.pages = [];
  3022. this.editMode = false;
  3023. this._createPage(function(control){
  3024. this._loadPageLayout(control);
  3025. this.setData(this.data, diffFiletext);
  3026. this._repage();
  3027. if (!this.editMode && this.allowEdit && !this.historyMode && this.options.pageShow!=="double") {
  3028. this._editFiletext("inline");
  3029. this.editMode = true;
  3030. }
  3031. if (callback) callback();
  3032. }.bind(this));
  3033. },
  3034. /**
  3035. * @summary 判断公文编辑器的正文内容是否已经填写
  3036. * @return {Boolean} 是否为空
  3037. * @example
  3038. * if( this.form.get("fieldId").isEmpty() ){
  3039. * this.form.notice('请填写正文内容')
  3040. * }
  3041. */
  3042. isEmpty: function(){
  3043. var data = this.getData();
  3044. if( typeOf(data) !== "object" )return true;
  3045. return !data.filetext || data.filetext===this.json.defaultValue.filetext;
  3046. },
  3047. /**
  3048. * @summary 获取公文编辑器数据
  3049. * @return {Object} 公文编辑器的数据
  3050. * @example
  3051. * var data = this.form.get("fieldId").getData();
  3052. */
  3053. getData: function(){
  3054. //if (this.editMode){
  3055. if (this.layout_copies) this.data.copies = this.layout_copies.get("text");
  3056. if (this.layout_secret) this.data.secret = this.layout_secret.get("text");
  3057. if (this.layout_priority) this.data.priority = this.layout_priority.get("text");
  3058. if (this.layout_redHeader) this.data.redHeader = this.layout_redHeader.get("html");
  3059. if (this.layout_fileno) this.data.fileno = this.layout_fileno.get("text");
  3060. if (this.layout_signerTitle) this.data.signerTitle = this.layout_signerTitle.get("text");
  3061. if (this.layout_signer) this.data.signer = this.layout_signer.get("html");
  3062. if (this.layout_subject) this.data.subject = this.layout_subject.get("html");
  3063. if (this.layout_mainSend) this.data.mainSend = this.layout_mainSend.get("text");
  3064. if (this.editMode) {
  3065. if (this.layout_filetext){
  3066. var text = this.layout_filetext.get("text");
  3067. text = text.replace(/\u3000*/g, "");
  3068. if (text && text !==this.json.defaultValue.filetext){
  3069. this.data.filetext = this.layout_filetext.get("html");
  3070. }else{
  3071. this.data.filetext = "";
  3072. }
  3073. }
  3074. }
  3075. this.getAttachmentTextData();
  3076. if (this.layout_signer) this.data.signer = this.layout_signer.get("html");
  3077. if (this.layout_attachmentTitle) this.data.attachmentTitle = this.layout_attachmentTitle.get("text");
  3078. if (this.layout_attachment){
  3079. this._computeItemData("attachment", "attachmentValueType", "attachmentValueData", "attachmentValueScript", false, "layout_attachment");
  3080. // var atts = [];
  3081. // var nodes = this.layout_attachment.getElements(".doc_layout_attachment_content_name");
  3082. // if (nodes.length){
  3083. // nodes.each(function(node){
  3084. // atts.push(node.get("text"));
  3085. // });
  3086. // }
  3087. // this.data.attachment = atts;
  3088. }
  3089. if (this.layout_issuanceUnit) this.data.issuanceUnit = this.layout_issuanceUnit.get("html");
  3090. if (this.layout_issuanceDate) this.data.issuanceDate = this.layout_issuanceDate.get("text");
  3091. if (this.layout_annotation){
  3092. var annotation = this.layout_annotation.get("text");
  3093. if (annotation.substring(0,1)=="(") annotation = annotation.substring(1, annotation.length);
  3094. if (annotation.substring(annotation.length-1, annotation.length)==")") annotation = annotation.substring(0, annotation.length-1);
  3095. this.data.annotation = annotation;
  3096. }
  3097. if (this.layout_copytoTitle) this.data.copytoTitle = this.layout_copytoTitle.get("text");
  3098. if (this.layout_copytoContent) this.data.copyto = this.layout_copytoContent.get("text");
  3099. if (this.layout_copyto2Title) this.data.copyto2Title = this.layout_copyto2Title.get("text");
  3100. if (this.layout_copyto2Content) this.data.copyto2 = this.layout_copyto2Content.get("text");
  3101. if (this.layout_edition_issuance_unit) this.data.editionUnit = this.layout_edition_issuance_unit.get("text");
  3102. if (this.layout_edition_issuance_date) this.data.editionDate = this.layout_edition_issuance_date.get("text");
  3103. if (this.layout_meetingAttendTitle) this.data.meetingAttendTitle = this.layout_meetingAttendTitle.get("text");
  3104. if (this.layout_meetingLeaveTitle) this.data.meetingLeaveTitle = this.layout_meetingLeaveTitle.get("text");
  3105. if (this.layout_meetingSitTitle) this.data.meetingSitTitle = this.layout_meetingSitTitle.get("text");
  3106. if (this.layout_meetingAttendContent) this.data.meetingAttend = this.layout_meetingAttendContent.get("html");
  3107. if (this.layout_meetingLeaveContent) this.data.meetingLeave = this.layout_meetingLeaveContent.get("html");
  3108. if (this.layout_meetingSitContent) this.data.meetingSit = this.layout_meetingSitContent.get("html");
  3109. if (this.layout_meetingRecordContent) this.data.meetingRecord = this.layout_meetingRecordContent.get("html");
  3110. this.getSealData();
  3111. if (this.customLayouts){
  3112. this.customLayouts.each(function(l){
  3113. this.data[l.name] = l.node.get("html");
  3114. }.bind(this))
  3115. }
  3116. //}
  3117. return this.data;
  3118. },
  3119. getAttachmentTextData: function(){
  3120. if (this.layout_attachmentText && this.layout_attachmentText.get("contenteditable")=="true"){
  3121. var text = this.layout_attachmentText.get("text");
  3122. text = text.replace(/\u3000*/g, "");
  3123. if (text && text !==MWF.xApplication.process.Xform.LP.documentEditor.attachmentInfor){
  3124. this.data.attachmentText = this.layout_attachmentText.get("html");
  3125. }else{
  3126. this.data.attachmentText = "";
  3127. }
  3128. }
  3129. },
  3130. getSealData: function(){
  3131. if (this.layout_seals && this.layout_seals.length) {
  3132. this.data.seals = [];
  3133. this.layout_seals.each(function(seal){
  3134. this.data.seals.push(seal.get("src"));
  3135. }.bind(this));
  3136. }
  3137. },
  3138. setAttachmentData: function(){
  3139. if (!this.attachmentTemplete){
  3140. this.attachmentTemplete = this.layout_attachment.get("html");
  3141. }
  3142. this.layout_attachment.empty();
  3143. if (this.data.attachment && !this.data.attachment.each){
  3144. this.data.attachment = this.data.attachment.split(/,\s*/g);
  3145. }
  3146. if (this.data.attachment && this.data.attachment.length && this.data.attachment.each){
  3147. //var tmpdiv = new Element("div", {"styles": {"display":"none"}}).inject(document.body);
  3148. var tmpdiv = new Element("div");
  3149. this.data.attachment.each(function(name, idx){
  3150. tmpdiv.set("html", this.attachmentTemplete);
  3151. var serialNode = tmpdiv.getElement(".doc_layout_attachment_content_serial");
  3152. var nameNode = tmpdiv.getElement(".doc_layout_attachment_content_name");
  3153. if (this.data.attachment.length>1){
  3154. if (serialNode){
  3155. serialNode.set("text", idx+1);
  3156. serialNode.getNext().set("text", ".");
  3157. }
  3158. }else{
  3159. if (serialNode){
  3160. serialNode.set("text", "");
  3161. serialNode.getNext().set("text", "");
  3162. }
  3163. }
  3164. if (nameNode) nameNode.set("text", name);
  3165. var html = tmpdiv.get("html");
  3166. tmpdiv.empty();
  3167. this.layout_attachment.appendHTML(html);
  3168. }.bind(this));
  3169. tmpdiv.destroy();
  3170. }
  3171. },
  3172. setAttachmentText: function(data){
  3173. this.layout_attachmentText.empty();
  3174. if (data.attachmentText){
  3175. this.layout_attachmentText.set("html", data.attachmentText);
  3176. }else{
  3177. if (this._getEdit("attachmentText", "attachmentTextEdit", "attachmentTextEditScript")){
  3178. this.layout_attachmentText.set("text", MWF.xApplication.process.Xform.LP.documentEditor.attachmentInfor);
  3179. }
  3180. }
  3181. },
  3182. filterHtml: function(html){
  3183. var content = html.replace(/(?:<script[\s\S]*?)(?:(?:<\/script>)|(?:\/>))/gmi, "");
  3184. // content = content.replace(/(?<=[\"\'])javascript\:(?=.*")/gmi, "");
  3185. //content = content.replace(/(?<=\s)on\w*|src|href(?=\=[\"\'])/gmi, function(match){
  3186. content = content.replace(/\son\w*|src|href(?=\=[\"\'])/gmi, function(match){
  3187. return "data-"+match;
  3188. });
  3189. return content;
  3190. },
  3191. /**设置公文编辑器数据
  3192. * @param {Object} data
  3193. * @example
  3194. * var data = this.form.get("fieldId").getData();
  3195. * data.filetext = "测试内容";
  3196. * this.form.get("fieldId").setData(data);
  3197. */
  3198. setData: function(data, diffFiletext){
  3199. if (data){
  3200. this.data = data;
  3201. // this.data["$json"] = this.json;
  3202. this._setBusinessData(data);
  3203. if (this.layout_copies){
  3204. if (data.copies){
  3205. this.layout_copies.set("text", data.copies || " ");
  3206. }else{
  3207. this.layout_copies.set("html", "<span>&nbsp</span>");
  3208. }
  3209. }
  3210. if (this.layout_secret){
  3211. if (data.secret){
  3212. this.layout_secret.set("text", data.secret || " ");
  3213. }else{
  3214. this.layout_secret.set("html", "<span>&nbsp</span>");
  3215. }
  3216. }
  3217. if (this.layout_priority){
  3218. if (data.priority){
  3219. this.layout_priority.set("text", data.priority || " ");
  3220. }else{
  3221. this.layout_priority.set("html", "<span>&nbsp</span>");
  3222. }
  3223. }
  3224. if (this.layout_redHeader) this.layout_redHeader.set("html", data.redHeader || "");
  3225. if (this.layout_fileno) this.layout_fileno.set("text", data.fileno || " ");
  3226. if (this.layout_signerTitle) this.layout_signerTitle.set("text", data.signerTitle || " ");
  3227. if (this.layout_signer) this.layout_signer.set("html", data.signer || " ");
  3228. if (this.layout_subject) this.layout_subject.set("html", data.subject || " ");
  3229. if (this.layout_mainSend) this.layout_mainSend.set("text", data.mainSend || " ");
  3230. if (diffFiletext) {
  3231. this.layout_filetext.set("html", diffFiletext);
  3232. }else if (this.layout_filetext){
  3233. //this.layout_filetext.set("placeholder", this.json.defaultValue.filetext);
  3234. var html = data.filetext.replace(/(?:<script(?:\s+[\w-]+(?:=(?:"[^"]*"|'[^']*'))?)*\s*>([\s\S]*?)<\/script\s*>)|(?:on\w+\s*=\s*(?:"[^"]*"|'[^']*'))|(?:javascript:.*)/g, '');
  3235. this.layout_filetext.set("html", html);
  3236. // this.layout_filetext.set("html", data.filetext || "  ");
  3237. // var tableList = this.layout_filetext.getElements("table");
  3238. // if (tableList && tableList.length){
  3239. // // var w = this.layout_filetext.offsetWidth;
  3240. // // tableList.setStyle("width", ""+w+"px");
  3241. // tableList.setStyles({
  3242. // "margin-left": "",
  3243. // "margin-right": "",
  3244. // "word-break": "break-all"
  3245. // });
  3246. // }
  3247. }
  3248. if (this.layout_signer) this.layout_signer.set("html", data.signer || "");
  3249. if (this.layout_attachmentTitle) this.layout_attachmentTitle.set("text", data.attachmentTitle || " ");
  3250. if (this.layout_attachment){
  3251. this.setAttachmentData();
  3252. }
  3253. if (this.layout_attachmentText){
  3254. this.setAttachmentText(data);
  3255. }
  3256. if (this.layout_issuanceUnit) this.layout_issuanceUnit.set("html", data.issuanceUnit || " ");
  3257. if (this.layout_issuanceDate) this.layout_issuanceDate.set("text", data.issuanceDate || " ");
  3258. if (this.layout_annotation){
  3259. var annotation = data.annotation;
  3260. if (annotation){
  3261. if (annotation.substring(0, 1)!=="(") annotation = "("+annotation;
  3262. if (annotation.substring(annotation.length-1, annotation.length)!==")") annotation = annotation+")";
  3263. this.layout_annotation.set("text", annotation);
  3264. }else{
  3265. this.layout_annotation.set("text", "");
  3266. }
  3267. }
  3268. if (this.layout_copytoTitle) this.layout_copytoTitle.set("text", data.copytoTitle || " ");
  3269. if (this.layout_copytoContent) this.layout_copytoContent.set("text", data.copyto || " ");
  3270. if (this.layout_copyto2Title) this.layout_copyto2Title.set("text", data.copyto2Title || " ");
  3271. if (this.layout_copyto2Content) this.layout_copyto2Content.set("text", data.copyto2 || " ");
  3272. if (this.layout_edition_issuance_unit) this.layout_edition_issuance_unit.set("text", data.editionUnit || " ");
  3273. if (this.layout_edition_issuance_date) this.layout_edition_issuance_date.set("text", data.editionDate || " ");
  3274. if (this.layout_meetingAttendTitle) this.layout_meetingAttendTitle.set("text", data.meetingAttendTitle || this.json.defaultValue.meetingAttendTitle || " ");
  3275. if (this.layout_meetingLeaveTitle) this.layout_meetingLeaveTitle.set("text", data.meetingLeaveTitle || this.json.defaultValue.meetingLeaveTitle || " ");
  3276. if (this.layout_meetingSitTitle) this.layout_meetingSitTitle.set("text", data.meetingSitTitle || this.json.defaultValue.meetingSitTitle || " ");
  3277. if (this.layout_meetingAttendContent) this.layout_meetingAttendContent.set("html", this.filterHtml(data.meetingAttend || " "));
  3278. if (this.layout_meetingLeaveContent) this.layout_meetingLeaveContent.set("html", this.filterHtml(data.meetingLeave || " "));
  3279. if (this.layout_meetingSitContent) this.layout_meetingSitContent.set("html", this.filterHtml(data.meetingSit || " "));
  3280. if (this.layout_meetingRecordContent) this.layout_meetingRecordContent.set("html", this.filterHtml(data.meetingRecord || " "));
  3281. if (this.layout_seals){
  3282. if (data.seals && data.seals.length){
  3283. data.seals.each(function(src, i){
  3284. if (this.layout_seals[i] && src){
  3285. this.layout_seals[i].src = src;
  3286. this.layout_seals[i].show();
  3287. this.layout_seals[i].setStyles({
  3288. "border": "0",
  3289. "border-radius": "0",
  3290. "z-index": -1
  3291. });
  3292. }
  3293. }.bind(this));
  3294. }
  3295. }
  3296. if (this.customLayouts){
  3297. this.customLayouts.each(function(l){
  3298. var value = this.data[l.name] || "";
  3299. var reg = new RegExp("\n","g");
  3300. var text = value.replace(reg,"<br/>");
  3301. l.node.set("html",text || " ");
  3302. }.bind(this))
  3303. }
  3304. if (this.layout_issuanceUnit && this.layout_issuanceDate ){
  3305. var table = this.layout_issuanceUnit.getParent("table")
  3306. if (table && !table.hasClass("doc_layout_headIssuance")){
  3307. var unitWidth = o2.getTextSize(this.layout_issuanceUnit.get("text"), {
  3308. "font-size":"16pt",
  3309. "font-family":"'Times New Roman',仿宋_GB2312",
  3310. "letter-spacing": "-0.2pt"
  3311. }).x;
  3312. var dateWidth = o2.getTextSize(this.layout_issuanceDate.get("text"), {
  3313. "font-size":"16pt",
  3314. "font-family":"'Times New Roman',仿宋_GB2312",
  3315. "letter-spacing": "-0.2pt"
  3316. }).x;
  3317. if (table.hasClass("doc_layout_issuanceV2")){
  3318. if (unitWidth<=dateWidth){
  3319. //日期右空四字,单位相对与日期居中
  3320. var flagTd = this.layout_issuanceUnit.getParent("td").getNext("td");
  3321. if (flagTd) flagTd.setStyle("width", "64pt");
  3322. flagTd = this.layout_issuanceDate.getParent("td").getNext("td");
  3323. if (flagTd) flagTd.setStyle("width", "64pt");
  3324. var dateP = this.layout_issuanceDate.getParent("p");
  3325. if (dateP){
  3326. dateP.setStyle("text-align", "right");
  3327. var span = dateP.getElement("span.space");
  3328. if (span) span.destroy();
  3329. }
  3330. }else{
  3331. var flagTd = this.layout_issuanceUnit.getParent("td").getNext("td");
  3332. if (flagTd) flagTd.setStyle("width", "32pt");
  3333. flagTd = this.layout_issuanceDate.getParent("td").getNext("td");
  3334. if (flagTd) flagTd.setStyle("width", "32pt");
  3335. var dateP = this.layout_issuanceDate.getParent("p");
  3336. if (dateP){
  3337. dateP.setStyle("text-align", "left");
  3338. var span = dateP.getElement("span.space");
  3339. if (!span) new Element("span.space", { "html": "&#x3000;&#x3000;" }).inject(dateP, "top");
  3340. }
  3341. }
  3342. }else{
  3343. if (unitWidth<=dateWidth){
  3344. //日期右空四字,单位相对与日期居中
  3345. var flagTd = this.layout_issuanceDate.getParent("td").getNext("td");
  3346. if (flagTd) {
  3347. var pt = 16*4; //空四字
  3348. flagTd.setStyle("width", "" + pt + "pt");
  3349. flagTd = this.layout_issuanceUnit.getParent("td").getNext("td");
  3350. if (flagTd) flagTd.setStyle("width", "" + pt + "pt");
  3351. }
  3352. //var dateTd = this.layout_issuanceDate.getParent("td");
  3353. var unitTd = this.layout_issuanceUnit.getParent("td");
  3354. unitTd.setStyle("width", dateWidth);
  3355. var p = this.layout_issuanceUnit.getParent("p");
  3356. if (p) p.setStyle("text-align", "center");
  3357. }else{
  3358. var flagTd = this.layout_issuanceUnit.getParent("td").getNext("td");
  3359. if (flagTd) flagTd.setStyle("width", "32pt");
  3360. var unitTd = this.layout_issuanceUnit.getParent("td");
  3361. unitTd.setStyle("width", "auto");
  3362. flagTd = this.layout_issuanceDate.getParent("td").getNext("td");
  3363. if (flagTd) flagTd.setStyle("width", "64pt");
  3364. var p = this.layout_issuanceDate.getParent("p");
  3365. if (p) p.setStyle("text-align", "right");
  3366. }
  3367. }
  3368. }
  3369. }
  3370. var coptyToTitleNode = (this.layout_copytoTitle || this.layout_copyto2Title);
  3371. if (coptyToTitleNode){
  3372. var editionTable = coptyToTitleNode.getParent("table");
  3373. if (editionTable) if (editionTable.get("data-compute-style")=="y"){
  3374. var rows = editionTable.rows;
  3375. for (var i=0; i<rows.length; i++){
  3376. var cell = rows[i].cells[0];
  3377. var tmp = cell.getElement(".doc_layout_edition_issuance_unit");
  3378. if (!tmp) tmp = cell.getElement(".doc_layout_edition_issuance_date");
  3379. if (!tmp){
  3380. var text = cell.get("text").trim();
  3381. var l = 14*text.length;
  3382. var wl = 19*text.length;
  3383. cell.setStyles({
  3384. "max-width": ""+l+"pt",
  3385. "min-width": ""+l+"pt",
  3386. "width": ""+wl+"pt"
  3387. });
  3388. }
  3389. }
  3390. }
  3391. }
  3392. }
  3393. },
  3394. createErrorNode: function(text){
  3395. var node = new Element("div");
  3396. var iconNode = new Element("div", {
  3397. "styles": {
  3398. "width": "20px",
  3399. "height": "20px",
  3400. "float": "left",
  3401. "background": "url("+"../x_component_process_Xform/$Form/default/icon/error.png) center center no-repeat"
  3402. }
  3403. }).inject(node);
  3404. var textNode = new Element("div", {
  3405. "styles": {
  3406. "line-height": "20px",
  3407. "margin-left": "20px",
  3408. "color": "red",
  3409. "word-break": "keep-all"
  3410. },
  3411. "text": text
  3412. }).inject(node);
  3413. return node;
  3414. },
  3415. notValidationMode: function(text){
  3416. if (!this.isNotValidationMode){
  3417. this.isNotValidationMode = true;
  3418. this.node.store("borderStyle", this.node.getStyles("border-left", "border-right", "border-top", "border-bottom"));
  3419. this.node.setStyle("border", "1px solid red");
  3420. this.errNode = this.createErrorNode(text).inject(this.node, "after");
  3421. this.showNotValidationMode(this.node);
  3422. }
  3423. },
  3424. showNotValidationMode: function(node){
  3425. var p = node.getParent("div");
  3426. if (p){
  3427. if (p.get("MWFtype") == "tab$Content"){
  3428. if (p.getParent("div").getStyle("display")=="none"){
  3429. var contentAreaNode = p.getParent("div").getParent("div");
  3430. var tabAreaNode = contentAreaNode.getPrevious("div");
  3431. var idx = contentAreaNode.getChildren().indexOf(p.getParent("div"));
  3432. var tabNode = tabAreaNode.getLast().getFirst().getChildren()[idx];
  3433. tabNode.click();
  3434. p = tabAreaNode.getParent("div");
  3435. }
  3436. }
  3437. this.showNotValidationMode(p);
  3438. }
  3439. },
  3440. validationMode: function(){
  3441. if (this.isNotValidationMode){
  3442. this.isNotValidationMode = false;
  3443. this.node.setStyles(this.node.retrieve("borderStyle"));
  3444. if (this.errNode){
  3445. this.errNode.destroy();
  3446. this.errNode = null;
  3447. }
  3448. }
  3449. },
  3450. validationConfigItem: function(routeName, data){
  3451. var flag = (data.status=="all") ? true: (routeName == data.decision);
  3452. if (flag){
  3453. var n = this.getData();
  3454. var v = (data.valueType=="value") ? n : n.length;
  3455. switch (data.operateor){
  3456. case "isnull":
  3457. if (!v){
  3458. this.notValidationMode(data.prompt);
  3459. return false;
  3460. }
  3461. break;
  3462. case "notnull":
  3463. if (v){
  3464. this.notValidationMode(data.prompt);
  3465. return false;
  3466. }
  3467. break;
  3468. case "gt":
  3469. if (v>data.value){
  3470. this.notValidationMode(data.prompt);
  3471. return false;
  3472. }
  3473. break;
  3474. case "lt":
  3475. if (v<data.value){
  3476. this.notValidationMode(data.prompt);
  3477. return false;
  3478. }
  3479. break;
  3480. case "equal":
  3481. if (v==data.value){
  3482. this.notValidationMode(data.prompt);
  3483. return false;
  3484. }
  3485. break;
  3486. case "neq":
  3487. if (v!=data.value){
  3488. this.notValidationMode(data.prompt);
  3489. return false;
  3490. }
  3491. break;
  3492. case "contain":
  3493. if (v.indexOf(data.value)!=-1){
  3494. this.notValidationMode(data.prompt);
  3495. return false;
  3496. }
  3497. break;
  3498. case "notcontain":
  3499. if (v.indexOf(data.value)==-1){
  3500. this.notValidationMode(data.prompt);
  3501. return false;
  3502. }
  3503. break;
  3504. }
  3505. }
  3506. return true;
  3507. },
  3508. validationConfig: function(routeName, opinion){
  3509. if (this.json.validationConfig){
  3510. if (this.json.validationConfig.length){
  3511. for (var i=0; i<this.json.validationConfig.length; i++) {
  3512. var data = this.json.validationConfig[i];
  3513. if (!this.validationConfigItem(routeName, data)) return false;
  3514. }
  3515. }
  3516. return true;
  3517. }
  3518. return true;
  3519. },
  3520. validation: function(routeName, opinion){
  3521. if (!this.validationConfig(routeName, opinion)) return false;
  3522. if (!this.json.validation) return true;
  3523. if (!this.json.validation.code) return true;
  3524. this.currentRouteName = routeName;
  3525. var flag = this.form.Macro.exec(this.json.validation.code, this);
  3526. this.currentRouteName = "";
  3527. if (!flag) flag = MWF.xApplication.process.Xform.LP.notValidation;
  3528. if (flag.toString()!="true"){
  3529. this.notValidationMode(flag);
  3530. return false;
  3531. }
  3532. return true;
  3533. },
  3534. removeDisplayNone: function(node){
  3535. var n = node.getFirst();
  3536. while (n){
  3537. if (n.getStyle("display")=="none" || (this.json.toWordSeal=="n" && n.hasClass("doc_layout_seal"))){
  3538. var tmp = n.getNext();
  3539. n.destroy();
  3540. n = tmp;
  3541. }else{
  3542. n = this.removeDisplayNone(n);
  3543. n = n.getNext();
  3544. }
  3545. }
  3546. return node;
  3547. },
  3548. /**将公文编辑器内容以html形式输出
  3549. * @return {String}
  3550. * @example
  3551. * var html = this.form.get("fieldId").getDocumentHtml();
  3552. */
  3553. getDocumentHtml: function(){
  3554. var docNode = this.contentNode.getFirst().getFirst();
  3555. var filetextNode = docNode.getElement(".doc_layout_filetext");
  3556. var tables = filetextNode.getElements("table");
  3557. tables.each(function(table){
  3558. var tableWidth = table.offsetWidth;
  3559. table.set("data-o2-width", tableWidth);
  3560. // var tr = table.getElement("tr");
  3561. // if (tr){
  3562. table.getElements("td").each(function(td){
  3563. var tdx = td.offsetWidth;
  3564. var p = (tdx/tableWidth)*100;
  3565. td.set("data-o2-width", tdx);
  3566. });
  3567. //}
  3568. });
  3569. var tmpNode = this.contentNode.getFirst().getFirst().clone(true);
  3570. var htmlNode = tmpNode.getLast();
  3571. htmlNode = this.removeDisplayNone(htmlNode);
  3572. var nodes = tmpNode.querySelectorAll("[data-w-style]");
  3573. if (nodes.length){
  3574. for (var i=0; i<nodes.length; i++){
  3575. var n = nodes.item(i);
  3576. wStyle = n.dataset["wStyle"];
  3577. var styles = wStyle.split(/\s*\;\s*/g);
  3578. styles.each(function(style){
  3579. if (style){
  3580. try{
  3581. s = style.split(/\s*\:\s*/g);
  3582. n.setStyle(s[0], s[1]);
  3583. }catch(e) {}
  3584. }
  3585. });
  3586. }
  3587. }
  3588. var filetextNode = tmpNode.getElement(".doc_layout_filetext");
  3589. filetextNode.getElements("td").setStyle("width", "");
  3590. //var tables = filetextNode.getElements("table");
  3591. var tables = tmpNode.querySelectorAll("table[data-o2-width]");
  3592. for (var i=0; i<tables.length; i++){
  3593. tables[i].setStyle("width", tables[i].dataset["o2Width"]+"px");
  3594. }
  3595. var tds = tmpNode.querySelectorAll("td[data-o2-width]");
  3596. for (var i=0; i<tds.length; i++){
  3597. tds[i].setStyle("width", tds[i].dataset["o2Width"]+"px");
  3598. }
  3599. var htmlStr = tmpNode.get("html");
  3600. tmpNode.destroy();
  3601. return "<html xmlns:v=\"urn:schemas-microsoft-com:vml\"><head><meta charset=\"UTF-8\" /></head><body>"+htmlStr+"</body></html>";
  3602. },
  3603. /**
  3604. * @summary 将公文编辑器转换成附件,转换的文件名和格式等信息与配置有关
  3605. * @param {Function} [callback] 转换后的回调方法,参数是附件数据.
  3606. * @param {string} [name] - 如果为空或者不传,转换的文件名和格式等信息与配置有关.
  3607. * @example
  3608. * this.form.get("fieldId").toWord( function(attachmentData){
  3609. * //attachmentData 转换后的附件数据
  3610. * })
  3611. */
  3612. toWord: function(callback, name, cb, notSave){
  3613. var docNmae = name || this.json.toWordFilename || this.form.businessData.data.subject || this.form.businessData.data["$work"].title;
  3614. this.getData();
  3615. this.reload(function(){
  3616. if (!this.data.attachmentText && this.layout_attachmentText){
  3617. this.layout_attachmentText.set("text", "");
  3618. }
  3619. var fileName = docNmae || this.json.toWordFilename || "$doc";
  3620. var n = fileName.lastIndexOf(".");
  3621. if (this.json.wordConversionType==="service"){
  3622. if (n==-1) fileName = fileName+".doc";
  3623. var content = encodeURIComponent(this.getDocumentHtml());
  3624. var body = {
  3625. "fileName": fileName,
  3626. "site": this.json.toWordSite || "$doc",
  3627. "content": content
  3628. };
  3629. this.toWordServiceService(body, callback, cb);
  3630. }else{
  3631. if (n==-1) fileName = fileName+".docx";
  3632. var extName = fileName.split('.').pop();
  3633. if (extName.toLowerCase()!=='docx') fileName = fileName+".docx";
  3634. var content = this.getDocumentHtml();
  3635. o2.xDesktop.requireApp("process.Xform", "widget.OOXML", function(){
  3636. (new o2.OOXML.WML({
  3637. "protection": (this.json.wordConversionEncryption===true),
  3638. "firstPageNumber": (this.json.firstPageNumber!==false)
  3639. })).load(content).then(function(oo_content){
  3640. if (!notSave) {
  3641. oo_content.name = fileName
  3642. var formData = new FormData();
  3643. formData.append("site", this.json.toWordSite || "$doc");
  3644. formData.append("fileName", fileName);
  3645. formData.append('file', oo_content);
  3646. this.toWordOOXMLService(formData, oo_content, callback, cb);
  3647. }else{
  3648. if (callback) callback(oo_content, fileName);
  3649. if (cb) cb();
  3650. }
  3651. }.bind(this));
  3652. }.bind(this));
  3653. }
  3654. }.bind(this));
  3655. },
  3656. toWordServiceService: function(body, callback, cb){
  3657. if (this.toWordServiceServiceProcessing){
  3658. if (!this.toWordServiceServiceProcessList) this.toWordServiceServiceProcessList = [];
  3659. this.toWordServiceServiceProcessList.push({
  3660. body: body,
  3661. callback: callback,
  3662. cb: cb
  3663. });
  3664. return false;
  3665. }
  3666. this.toWordServiceServiceProcessing = true;
  3667. o2.Actions.get("x_processplatform_assemble_surface").docToWord(this.form.businessData.work.id, body, function(json){
  3668. if (this.form.businessData.workCompleted){
  3669. o2.Actions.get("x_processplatform_assemble_surface").getAttachmentWorkcompleted(json.data.id, this.form.businessData.workCompleted.id,function(attjson){
  3670. if (callback) callback(attjson.data);
  3671. this.showToWord(attjson.data);
  3672. }.bind(this));
  3673. }else{
  3674. o2.Actions.get("x_processplatform_assemble_surface").getAttachment(json.data.id, this.form.businessData.work.id,function(attjson){
  3675. if (callback) callback(attjson.data);
  3676. this.showToWord(attjson.data);
  3677. }.bind(this));
  3678. }
  3679. if (cb) cb();
  3680. this.toWordServiceServiceProcessing = false;
  3681. if (this.toWordServiceServiceProcessList && this.toWordServiceServiceProcessList.length){
  3682. var o = this.toWordServiceServiceProcessList.shift();
  3683. this.toWordServiceService(o.body, o.callback, o.cb);
  3684. }
  3685. }.bind(this), function(){
  3686. this.toWordServiceServiceProcessing = false;
  3687. if (this.toWordServiceServiceProcessList && this.toWordServiceServiceProcessList.length){
  3688. var o = this.toWordServiceServiceProcessList.shift();
  3689. this.toWordServiceService(o.body, o.callback, o.cb);
  3690. }
  3691. });
  3692. },
  3693. toWordOOXMLService: function(formData, oo_content, callback, cb){
  3694. if (this.toWordOOXMLServiceProcessing){
  3695. if (!this.toWordOOXMLServiceProcessList) this.toWordOOXMLServiceProcessList = [];
  3696. this.toWordOOXMLServiceProcessList.push({
  3697. formData: formData,
  3698. oo_content: oo_content,
  3699. callback: callback,
  3700. cb: cb
  3701. });
  3702. return false;
  3703. }
  3704. this.toWordOOXMLServiceProcessing = true;
  3705. o2.Actions.get("x_processplatform_assemble_surface").V2UploadWorkOrWorkCompleted(this.form.businessData.work.id, formData, oo_content, function (json) {
  3706. if (this.form.businessData.workCompleted) {
  3707. o2.Actions.get("x_processplatform_assemble_surface").getAttachmentWorkcompleted(json.data.id, this.form.businessData.workCompleted.id, function (attjson) {
  3708. if (callback) callback(attjson.data);
  3709. this.showToWord(attjson.data);
  3710. }.bind(this));
  3711. } else {
  3712. o2.Actions.get("x_processplatform_assemble_surface").getAttachment(json.data.id, this.form.businessData.work.id, function (attjson) {
  3713. if (callback) callback(attjson.data);
  3714. this.showToWord(attjson.data);
  3715. }.bind(this));
  3716. }
  3717. if (cb) cb();
  3718. this.toWordOOXMLServiceProcessing = false;
  3719. if (this.toWordOOXMLServiceProcessList && this.toWordOOXMLServiceProcessList.length){
  3720. var o = this.toWordOOXMLServiceProcessList.shift();
  3721. this.toWordOOXMLService(o.formData, o.oo_content, o.callback, o.cb);
  3722. }
  3723. }.bind(this), function(){
  3724. this.toWordOOXMLServiceProcessing = false;
  3725. if (this.toWordOOXMLServiceProcessList && this.toWordOOXMLServiceProcessList.length){
  3726. var o = this.toWordOOXMLServiceProcessList.shift();
  3727. this.toWordOOXMLService(o.formData, o.oo_content, o.callback, o.cb);
  3728. }
  3729. }.bind(this));
  3730. },
  3731. docToWord: function(callback){
  3732. try {
  3733. var flag = true;
  3734. if (this.json.toWordConditionScript && this.json.toWordConditionScript.code){
  3735. flag = !!this.form.Macro.exec(this.json.toWordConditionScript.code, this);
  3736. }
  3737. if (flag){
  3738. this.toWord(null, "", callback);
  3739. }else{
  3740. if (callback) callback();
  3741. }
  3742. }catch(e){
  3743. console.error(e);
  3744. if (callback) callback();
  3745. };
  3746. },
  3747. showToWord: function(att_word){
  3748. var site = this.json.toWordSite || "$doc";
  3749. var attModule = this.form.all[site];
  3750. if (attModule){
  3751. var atts = [];
  3752. attModule.attachmentController.attachments.each(function(att){
  3753. if (att.data.name!==att_word.name){
  3754. atts.push(att.data)
  3755. }
  3756. }.bind(this));
  3757. attModule.attachmentController.clear();
  3758. atts.each(function (att) {
  3759. //if (att.site===this.json.id || (this.json.isOpenInOffice && this.json.officeControlName===att.site)) this.attachmentController.addAttachment(att);
  3760. if ((att.site === attModule.json.id) && att.name!==att_word.name) attModule.attachmentController.addAttachment(att);
  3761. }.bind(this));
  3762. // attModule.attachmentController.reloadAttachments();
  3763. attModule.attachmentController.addAttachment(att_word);
  3764. }
  3765. }
  3766. });