Documenteditor.js 142 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108
  1. MWF.xDesktop.requireApp("process.Xform", "$Module", null, false);
  2. /** @class Documenteditor 公文编辑器。
  3. * @example
  4. * //可以在脚本中获取该组件
  5. * //方法1:
  6. * var attachment = this.form.get("name"); //获取组件
  7. * //方法2
  8. * var attachment = this.target; //在组件事件脚本中获取
  9. * @extends MWF.xApplication.process.Xform.$Module
  10. * @hideconstructor
  11. */
  12. MWF.xApplication.process.Xform.Documenteditor = MWF.APPDocumenteditor = new Class(
  13. /** @lends MWF.xApplication.process.Xform.Documenteditor# */
  14. {
  15. Extends: MWF.APP$Module,
  16. options: {
  17. "moduleEvents": ["load", "queryLoad", "beforeLoad", "postLoad", "afterLoad", "loadPage"],
  18. "docPageHeight": 850.4,
  19. "docPageFullWidth": 794,
  20. "pageShow": "single"
  21. },
  22. initialize: function(node, json, form, options){
  23. this.node = $(node);
  24. this.node.store("module", this);
  25. this.json = json;
  26. this.form = form;
  27. this.field = true;
  28. },
  29. _loadCss: function(reload){
  30. var key = encodeURIComponent(this.cssPath);
  31. if (!reload && o2.widget.css[key]){
  32. this.css = o2.widget.css[key];
  33. }else{
  34. this.cssPath = (this.cssPath.indexOf("?")!=-1) ? this.cssPath+"&v="+o2.version.v : this.cssPath+"?v="+o2.version.v;
  35. var r = new Request.JSON({
  36. url: this.cssPath,
  37. secure: false,
  38. async: false,
  39. method: "get",
  40. noCache: false,
  41. onSuccess: function(responseJSON, responseText){
  42. this.css = responseJSON;
  43. o2.widget.css[key] = responseJSON;
  44. }.bind(this),
  45. onError: function(text, error){
  46. console.log(error + text);
  47. }
  48. });
  49. r.send();
  50. }
  51. },
  52. load: function(){
  53. if (!this.json.isDelay){
  54. this.active();
  55. }
  56. },
  57. /**
  58. * 激活公文编辑器编辑。设置了延迟加载的时候,可以通过这个方法来激活
  59. * @example
  60. * this.form.get("fieldName").active();
  61. */
  62. active: function(){
  63. this._loadModuleEvents();
  64. if (this.fireEvent("queryLoad")){
  65. this.fireEvent("beforeLoad");
  66. this.cssPath = this.form.path+this.form.options.style+"/doc.wcss";
  67. this._loadCss();
  68. this._queryLoaded();
  69. this._loadUserInterface(function(){
  70. this.fireEvent("postLoad");
  71. this.fireEvent("afterLoad");
  72. this.fireEvent("load");
  73. this.form.app.addEvent("resize", function(){
  74. // if (this.options.pageShow!=="double"){
  75. // this._doublePage();
  76. // }else{
  77. this._singlePage();
  78. // }
  79. this._checkScale();
  80. }.bind(this));
  81. }.bind(this));
  82. this._loadStyles();
  83. this._afterLoaded();
  84. }
  85. },
  86. _createNewPage: function(){
  87. var pageNode = new Element("div.doc_layout_page", {"styles": this.css.doc_page}).inject(this.contentNode);
  88. var pageContentNode = new Element("div.doc_layout_page_content", {"styles": this.css.doc_layout_page_content}).inject(pageNode);
  89. pageNode.set("data-pagecount", this.pages.length+1);
  90. this.pages.push(pageNode);
  91. return pageNode;
  92. },
  93. _getShow: function(name, typeItem, scriptItem){
  94. switch (this.json[typeItem]) {
  95. case "y":
  96. return true;
  97. case "n":
  98. return false;
  99. case "a":
  100. if (["copies", "secret", "priority", "attachment", "annotation", "copyto", "copyto2"].indexOf(name!=-1)){
  101. return !!this.data[name] && (!!this.data[name].length);
  102. }
  103. return true;
  104. case "s":
  105. if (this.json[scriptItem] && this.json[scriptItem].code){
  106. return !!this.form.Macro.exec(this.json[scriptItem].code, this);
  107. }
  108. return true;
  109. default:
  110. return true;
  111. }
  112. },
  113. _createPage: function(callback){
  114. var pageContentNode = this._createNewPage().getFirst();
  115. var control = this.getShowControl();
  116. this.json.fileup = !!(control.signer);
  117. if (this.json.css && this.json.css.code && !this.styleNode){
  118. var cssText = this.form.parseCSS(this.json.css.code);
  119. cssText = cssText.replace(/documenteditor_table/g, 'documenteditor_table'+this.form.json.id+this.json.id)
  120. // var rex = new RegExp("(.+)(?=\\{)", "g");
  121. // var match;
  122. // var id = this.json.id.replace(/\-/g, "");
  123. // var prefix = this.form.json.id+this.json.id;
  124. //
  125. // while ((match = rex.exec(cssText)) !== null) {
  126. // var rulesStr = match[0];
  127. // if (rulesStr.indexOf(",")!=-1){
  128. // var rules = rulesStr.split(/\s*,\s*/g);
  129. // rules = rules.map(function(r){
  130. // return r+prefix;
  131. // });
  132. // var rule = rules.join(", ");
  133. // cssText = cssText.substring(0, match.index) + rule + cssText.substring(rex.lastIndex, cssText.length);
  134. // rex.lastIndex = rex.lastIndex + (prefix.length*rules.length);
  135. //
  136. // }else{
  137. // var rule = match[0]+prefix;
  138. // cssText = cssText.substring(0, match.index) + rule + cssText.substring(rex.lastIndex, cssText.length);
  139. // rex.lastIndex = rex.lastIndex + prefix.length;
  140. // }
  141. // }
  142. var styleNode = document.createElement("style");
  143. styleNode.setAttribute("type", "text/css");
  144. styleNode.id="style"+this.json.id;
  145. //styleNode.inject(pageContentNode);
  146. styleNode.inject(this.node, "top");
  147. if(styleNode.styleSheet){
  148. var setFunc = function(){
  149. styleNode.styleSheet.cssText = cssText;
  150. };
  151. if(styleNode.styleSheet.disabled){
  152. setTimeout(setFunc, 10);
  153. }else{
  154. setFunc();
  155. }
  156. }else{
  157. var cssTextNode = document.createTextNode(cssText);
  158. styleNode.appendChild(cssTextNode);
  159. }
  160. this.styleNode = styleNode;
  161. }
  162. if (this.json.documentTempleteType=="cus"){
  163. pageContentNode.loadHtml(o2.filterUrl(this.json.documentTempleteUrl), function(){
  164. if (this.json.toWordPageNumber=="y") this.doPageStyles(pageContentNode);
  165. if (this.attachmentTemplete){
  166. var attNode = pageContentNode.getElement(".doc_layout_attachment_content");
  167. if (attNode) attNode.empty();
  168. }
  169. if (callback) callback(control);
  170. this.fireEvent("loadPage");
  171. }.bind(this));
  172. }else{
  173. this.getTempleteJson(function(){
  174. var templete = this.json.documentTempleteName || "standard";
  175. pageContentNode.loadHtml(o2.filterUrl("../x_component_process_FormDesigner/Module/Documenteditor/templete/"+this.templeteJson[templete].file), function(){
  176. if (this.json.toWordPageNumber=="y") this.doPageStyles(pageContentNode);
  177. if (this.attachmentTemplete){
  178. var attNode = pageContentNode.getElement(".doc_layout_attachment_content");
  179. if (attNode) attNode.empty();
  180. }
  181. if (callback) callback(control);
  182. this.fireEvent("loadPage");
  183. }.bind(this));
  184. }.bind(this));
  185. }
  186. },
  187. doPageStyles: function(pageContentNode){
  188. var style = pageContentNode.getLast("style");
  189. if (style){
  190. var origin = window.location.origin;
  191. var header = o2.filterUrl(origin+"/x_component_process_FormDesigner/Module/Documenteditor/header.htm");
  192. var text = style.get("html");
  193. var pageRex = /(?:@page\s*\{)([\s\S]*?)(?:\})/;
  194. var arr = text.match(pageRex);
  195. if (arr && arr.length){
  196. cssText = arr[2];
  197. if (cssText){
  198. var last = cssText.substr(cssText.length-1,1);
  199. if (last!==";") cssText = cssText+";";
  200. cssText += "mso-page-border-surround-header:no;\n" +
  201. " mso-page-border-surround-footer:no;\n" +
  202. " mso-footnote-separator:url(\""+header+"\") fs;\n" +
  203. " mso-footnote-continuation-separator:url(\""+header+"\") fcs;\n" +
  204. " mso-endnote-separator:url(\""+header+"\") es;\n" +
  205. " mso-endnote-continuation-separator:url(\""+header+"\") ecs;\n" +
  206. " mso-facing-pages:yes;";
  207. text = text.replace(arr[0], arr[1]+cssText+arr[3]);
  208. }
  209. }else{
  210. text += "@page\n" +
  211. " {mso-page-border-surround-header:no;\n" +
  212. " mso-page-border-surround-footer:no;\n" +
  213. " mso-footnote-separator:url(\""+header+"\") fs;\n" +
  214. " mso-footnote-continuation-separator:url(\""+header+"\") fcs;\n" +
  215. " mso-endnote-separator:url(\""+header+"\") es;\n" +
  216. " mso-endnote-continuation-separator:url(\""+header+"\") ecs;\n" +
  217. " mso-facing-pages:yes;}"
  218. }
  219. pageRex = /(@page\s*WordSection1\s*\{)([\s\S]*?)(\})/;
  220. arr = text.match(pageRex);
  221. if (arr && arr.length){
  222. cssText = arr[2];
  223. if (cssText){
  224. var last = cssText.substr(cssText.length-1,1);
  225. if (last!==";") cssText = cssText+";";
  226. cssText += "mso-header-margin:42.55pt;\n" +
  227. " mso-footer-margin:70.9pt;\n" +
  228. " mso-even-footer:url(\""+header+"\") ef1;\n" +
  229. " mso-footer:url(\""+header+"\") f1;\n" +
  230. " mso-paper-source:0;";
  231. text = text.replace(arr[0], arr[1]+cssText+arr[3]);
  232. }
  233. }else{
  234. text += "@page WordSection1\n" +
  235. " {size:595.3pt 841.9pt;\n" +
  236. " margin:104.9pt 73.7pt 99.25pt 79.4pt;\n" +
  237. " layout-grid:15.6pt;\n" +
  238. " line-height:normal;\n" +
  239. " font-size:16.0pt;\n" +
  240. " font-family:仿宋;\n" +
  241. " letter-spacing:-0.4pt;\n" +
  242. " mso-header-margin:42.55pt;\n" +
  243. " mso-footer-margin:70.9pt;\n" +
  244. " mso-even-footer:url(\""+header+"\") ef1;\n" +
  245. " mso-footer:url(\""+header+"\") f1;\n" +
  246. " mso-paper-source:0;\n" +
  247. " }"
  248. }
  249. style.set("html", text)
  250. }
  251. },
  252. getTempleteJson: function(callback){
  253. if (this.templeteJson){
  254. if (callback) callback();
  255. }else{
  256. o2.getJSON(o2.filterUrl("../x_component_process_FormDesigner/Module/Documenteditor/templete/templete.json"), function(json){
  257. this.templeteJson = json;
  258. if (callback) callback();
  259. }.bind(this));
  260. }
  261. },
  262. getShowControl: function(){
  263. var control = {};
  264. control.copiesSecretPriority = this._getShow("copiesSecretPriority", "copiesSecretPriorityShow", "copiesSecretPriorityShowScript");
  265. control.copies = this._getShow("copies", "copiesShow", "copiesShowScript");
  266. control.secret = this._getShow("secret", "secretShow", "secretShowScript");
  267. control.priority = this._getShow("priority", "priorityShow", "priorityShowScript");
  268. control.redHeader = this._getShow("redHeader", "redHeaderShow", "redHeaderShowScript");
  269. control.redLine = this._getShow("redLine", "redLineShow", "redLineShowScript");
  270. control.signer = this._getShow("signer", "signerShow", "signerShowScript");
  271. control.fileno = this._getShow("fileno", "filenoShow", "filenoShowScript");
  272. control.subject = this._getShow("subject", "subjectShow", "subjectShowScript");
  273. control.mainSend = this._getShow("mainSend", "mainSendShow", "mainSendShowScript");
  274. control.attachment = this._getShow("attachment", "attachmentShow", "attachmentShowScript");
  275. control.issuanceUnit = this._getShow("issuanceUnit", "issuanceUnitShow", "issuanceUnitShowScript");
  276. control.issuanceDate = this._getShow("issuanceDate", "issuanceDateShow", "issuanceDateShowScript");
  277. control.annotation = this._getShow("annotation", "annotationShow", "annotationShowScript");
  278. control.copyto = this._getShow("copyto", "copytoShow", "copytoShowScript");
  279. control.copyto2 = this._getShow("copyto2", "copyto2Show", "copyto2ShowScript");
  280. control.editionUnit = this._getShow("editionUnit", "editionUnitShow", "editionUnitShowScript");
  281. control.editionDate = this._getShow("editionDate", "editionDateShow", "editionDateShowScript");
  282. control.meetingAttend = this._getShow("meetingAttend", "meetingAttendShow", "meetingAttendShowScript");
  283. control.meetingLeave = this._getShow("meetingLeave", "meetingLeaveShow", "meetingLeaveShowScript");
  284. control.meetingSit = this._getShow("meetingSit", "meetingSitShow", "meetingSitShowScript");
  285. control.meetingRecord = this._getShow("meetingRecord", "meetingRecordShow", "meetingRecordShowScript");
  286. return control;
  287. },
  288. // _getEdit: function(name, typeItem, scriptItem){
  289. // switch (this.json[typeItem]) {
  290. // case "y":
  291. // return true;
  292. // case "n":
  293. // return false;
  294. // // case "a":
  295. // // if (["copies", "secret", "priority", "attachment", "annotation", "copyto"].indexOf(name!=-1)){
  296. // // return !!this.data[name] && (!!this.data[name].length);
  297. // // }
  298. // // return true;
  299. // case "s":
  300. // if (this.json[scriptItem] && this.json[scriptItem].code){
  301. // return !!this.form.Macro.exec(this.json[scriptItem].code, this);
  302. // }
  303. // return true;
  304. // }
  305. // },
  306. getEditControl: function(){
  307. var control = {};
  308. control.copies = this._getEdit("copies", "copiesEdit", "copiesEditScript");
  309. control.secret = this._getEdit("secret", "secretEdit", "secretEditScript");
  310. control.priority = this._getEdit("priority", "priorityEdit", "priorityEditScript");
  311. control.redHeader = this._getEdit("redHeader", "redHeaderEdit", "redHeaderEditScript");
  312. control.signer = this._getEdit("signer", "signerEdit", "signerEditScript");
  313. control.fileno = this._getEdit("fileno", "filenoEdit", "filenoEditScript");
  314. control.subject = this._getEdit("subject", "subjectEdit", "subjectEditScript");
  315. control.mainSend = this._getEdit("mainSend", "mainSendEdit", "mainSendEditScript");
  316. control.attachment = this._getEdit("attachment", "attachmentEdit", "attachmentEditScript");
  317. control.issuanceUnit = this._getEdit("issuanceUnit", "issuanceUnitEdit", "issuanceUnitEditScript");
  318. control.issuanceDate = this._getEdit("issuanceDate", "issuanceDateEdit", "issuanceDateEditScript");
  319. control.annotation = this._getEdit("annotation", "annotationEdit", "annotationEditScript");
  320. control.copyto = this._getEdit("copyto", "copytoEdit", "copytoEditScript");
  321. control.copyto2 = this._getEdit("copyto2", "copyto2Edit", "copyto2EditScript");
  322. control.editionUnit = this._getEdit("editionUnit", "editionUnitEdit", "editionUnitEditScript");
  323. control.editionDate = this._getEdit("editionDate", "editionDateEdit", "editionDateEditScript");
  324. control.meetingAttend = this._getShow("meetingAttend", "meetingAttendEdit", "meetingAttendEditScript");
  325. control.meetingLeave = this._getShow("meetingLeave", "meetingLeaveEdit", "meetingLeaveEditScript");
  326. control.meetingSit = this._getShow("meetingSit", "meetingSitEdit", "meetingSitEditScript");
  327. control.meetingRecord = this._getShow("meetingRecord", "meetingRecordEdit", "meetingRecordEditScript");
  328. return control;
  329. },
  330. //份数 密级 紧急程度
  331. _loadCopiesSecretPriority: function(){
  332. this.layout_copiesSecretPriority = this.contentNode.getElement(".doc_layout_copiesSecretPriority");
  333. if (this.layout_copiesSecretPriority) this.layout_copiesSecretPriority.setStyles(this.css.doc_layout_copiesSecretPriority);
  334. this.layout_copies = this.contentNode.getElement(".doc_layout_copies");
  335. if (this.layout_copies) this.layout_copies.setStyles(this.css.doc_layout_copies);
  336. this.layout_secret = this.contentNode.getElement(".doc_layout_secret");
  337. if (this.layout_secret) this.layout_secret.setStyles(this.css.doc_layout_secret);
  338. this.layout_priority = this.contentNode.getElement(".doc_layout_priority");
  339. if (this.layout_priority) this.layout_priority.setStyles(this.css.doc_layout_priority);
  340. this.layout_copiesSecretPriority_blank = this.contentNode.getElement(".doc_layout_copiesSecretPriority_blank");
  341. },
  342. //红头
  343. _loadRedHeader: function(){
  344. this.layout_redHeader = this.contentNode.getElement(".doc_layout_redHeader");
  345. if (this.layout_redHeader) this.layout_redHeader.setStyles(this.css.doc_layout_redHeader);
  346. },
  347. //文号签发人(上行文)
  348. _loadFileNoUp: function(){
  349. this.layout_filenoArea = this.contentNode.getElement(".doc_layout_fileno_area");
  350. this.layout_fileNoUpTable = this.contentNode.getElement(".doc_layout_filenoup");
  351. if (this.layout_fileNoUpTable) this.layout_fileNoUpTable.setStyles(this.css.doc_layout_filenoup);
  352. var td = this.contentNode.getElement(".doc_layout_filenoup_fileno_td");
  353. if (td) td.setStyles(this.css.doc_layout_filenoup_fileno_td);
  354. this.layout_fileno = this.contentNode.getElement(".doc_layout_filenoup_fileno");
  355. if (this.layout_fileno) this.layout_fileno.setStyles(this.css.doc_layout_filenoup_fileno);
  356. td = this.contentNode.getElement(".doc_layout_filenoup_signer_td");
  357. if (td) td.setStyles(this.css.doc_layout_filenoup_signer_td);
  358. var node = this.contentNode.getElement(".doc_layout_filenoup_signer_table");
  359. if (node) node.setStyles(this.css.doc_layout_filenoup_signer_table);
  360. node = this.contentNode.getElement(".doc_layout_filenoup_signerTitle_td");
  361. if (node) node.setStyles(this.css.doc_layout_filenoup_signerTitle_td);
  362. this.layout_signerTitle = this.contentNode.getElement(".doc_layout_filenoup_signer");
  363. if (this.layout_signerTitle) this.layout_signerTitle.setStyles(this.css.doc_layout_filenoup_signer);
  364. node = this.contentNode.getElement(".doc_layout_filenoup_signerContent_td");
  365. if (node) node.setStyles(this.css.doc_layout_filenoup_signerContent_td);
  366. this.layout_signer = this.contentNode.getElement(".doc_layout_filenoup_signerContent");
  367. if (this.layout_signer) this.layout_signer.setStyles(this.css.doc_layout_filenoup_signerContent);
  368. if (!this.layout_fileno){
  369. this.layout_fileNoUpTable = this.contentNode.getElement(".doc_layout_filenoup");
  370. this.layout_filenoArea = this.contentNode.getElement(".doc_layout_fileno_area");
  371. this.layout_fileno = this.contentNode.getElement(".doc_layout_fileno");
  372. if (this.layout_fileno) this.layout_fileno.setStyles(this.css.doc_layout_fileno);
  373. }
  374. },
  375. //文号
  376. _loadFileNo: function(){
  377. this.layout_fileNoUpTable = this.contentNode.getElement(".doc_layout_filenoup");
  378. this.layout_filenoArea = this.contentNode.getElement(".doc_layout_fileno_area");
  379. this.layout_fileno = this.contentNode.getElement(".doc_layout_fileno");
  380. if (this.layout_fileno) this.layout_fileno.setStyles(this.css.doc_layout_fileno);
  381. td = this.contentNode.getElement(".doc_layout_filenoup_signer_td");
  382. if (td) td.setStyles(this.css.doc_layout_filenoup_signer_td);
  383. var node = this.contentNode.getElement(".doc_layout_filenoup_signer_table");
  384. if (node) node.setStyles(this.css.doc_layout_filenoup_signer_table);
  385. node = this.contentNode.getElement(".doc_layout_filenoup_signerTitle_td");
  386. if (node) node.setStyles(this.css.doc_layout_filenoup_signerTitle_td);
  387. this.layout_signerTitle = this.contentNode.getElement(".doc_layout_filenoup_signer");
  388. if (this.layout_signerTitle) this.layout_signerTitle.setStyles(this.css.doc_layout_filenoup_signer);
  389. node = this.contentNode.getElement(".doc_layout_filenoup_signerContent_td");
  390. if (node) node.setStyles(this.css.doc_layout_filenoup_signerContent_td);
  391. this.layout_signer = this.contentNode.getElement(".doc_layout_filenoup_signerContent");
  392. if (this.layout_signer) this.layout_signer.setStyles(this.css.doc_layout_filenoup_signerContent);
  393. if (!this.layout_fileno){
  394. this.layout_filenoArea = this.contentNode.getElement(".doc_layout_fileno_area");
  395. this.layout_fileNoUpTable = this.contentNode.getElement(".doc_layout_filenoup");
  396. if (this.layout_fileNoUpTable) this.layout_fileNoUpTable.setStyles(this.css.doc_layout_filenoup);
  397. var td = this.contentNode.getElement(".doc_layout_filenoup_fileno_td");
  398. if (td) td.setStyles(this.css.doc_layout_filenoup_fileno_td);
  399. this.layout_fileno = this.contentNode.getElement(".doc_layout_filenoup_fileno");
  400. if (this.layout_fileno) this.layout_fileno.setStyles(this.css.doc_layout_filenoup_fileno);
  401. }
  402. },
  403. //红线
  404. _loadRedLine: function(){
  405. this.layout_redLine = this.contentNode.getElement(".doc_layout_redline");
  406. if (this.layout_redLine) this.layout_redLine.setStyles(this.css.doc_layout_redline);
  407. },
  408. //标题
  409. _loadSubject:function(){
  410. this.layout_subject = this.contentNode.getElement(".doc_layout_subject");
  411. if (this.layout_subject) this.layout_subject.setStyles(this.css.doc_layout_subject);
  412. },
  413. //主送
  414. _loadMainSend: function(){
  415. this.layout_mainSend = this.contentNode.getElement(".doc_layout_mainSend");
  416. if (this.layout_mainSend) this.layout_mainSend.setStyles(this.css.doc_layout_mainSend);
  417. },
  418. //正文
  419. // _createFiletext: function(filetextNode, node, where){
  420. // if (!filetextNode){
  421. // var filetextNode = new Element("div.doc_layout_filetext").inject(node, where);
  422. // filetextNode.addClass("doc_block");
  423. // filetextNode.setAttribute('contenteditable', true);
  424. // }
  425. // CKEDITOR.disableAutoInline = true;
  426. // var filetextEditor = CKEDITOR.inline(filetextNode, this._getEditorConfig());
  427. // filetextNode.store("editor", filetextEditor);
  428. // if (!this.filetextEditors) this.filetextEditors = [];
  429. // this.filetextEditors.push(filetextEditor);
  430. //
  431. // filetextEditor.on( 'blur', function(e) {
  432. // // var filetextNode = e.editor.container.$;
  433. // // var pageNode = filetextNode.getParent(".doc_layout_page");
  434. // // this._checkSplitPage(pageNode);
  435. // // this._repage();
  436. // }.bind(this));
  437. //
  438. // return filetextNode;
  439. // },
  440. _loadFiletext: function(){
  441. this.layout_filetext = this.contentNode.getElement(".doc_layout_filetext");
  442. this.layout_filetext.addClass("css"+this.form.json.id+this.json.id);
  443. this.layout_filetext.setStyles(this.css.doc_layout_filetext);
  444. //this.layout_filetext = this.contentNode.getElement(".doc_layout_filetext");
  445. // if (this.layout_filetexts.length){
  446. // this.layout_filetexts.each(function(layout_filetext){
  447. // layout_filetext.setStyles(this.css.doc_layout_filetext);
  448. // }.bind(this));
  449. // }
  450. },
  451. //附件
  452. _loadAttachment: function(){
  453. this.layout_attachmentTable = this.contentNode.getElement(".doc_layout_attachment");
  454. if (this.layout_attachmentTable) this.layout_attachmentTable.setStyles(this.css.doc_layout_attachment);
  455. var node = this.contentNode.getElement(".doc_layout_attachment_title_td");
  456. if (node) node.setStyles(this.css.doc_layout_attachment_title_td);
  457. this.layout_attachmentTitle = this.contentNode.getElement(".doc_layout_attachment_title");
  458. if (node) node.setStyles(this.css.doc_layout_attachment_title);
  459. node = this.contentNode.getElement(".doc_layout_attachment_content_td");
  460. if (node) node.setStyles(this.css.doc_layout_attachment_content_td);
  461. this.layout_attachment = this.contentNode.getElement(".doc_layout_attachment_content");
  462. if (this.layout_attachment) this.layout_attachment.setStyles(this.css.doc_layout_attachment_content);
  463. },
  464. //发布单位
  465. _loadIssuance: function(){
  466. this.layout_issuanceTable = this.contentNode.getElement(".doc_layout_issuance");
  467. this.layout_issuanceUnit = this.contentNode.getElement(".doc_layout_issuanceUnit");
  468. this.layout_issuanceDate = this.contentNode.getElement(".doc_layout_issuanceDate");
  469. if (this.layout_issuanceTable) this.layout_issuanceTable.setStyles(this.css.doc_layout_issuance);
  470. if (this.layout_issuanceUnit) this.layout_issuanceUnit.setStyles(this.css.doc_layout_issuanceUnit);
  471. if (this.layout_issuanceDate) this.layout_issuanceDate.setStyles(this.css.doc_layout_issuanceDate);
  472. },
  473. //附注
  474. _loadAnnotation: function(){
  475. this.layout_annotation = this.contentNode.getElement(".doc_layout_annotation");
  476. if (this.layout_annotation) this.layout_annotation.setStyles(this.css.doc_layout_annotation);
  477. },
  478. //版记
  479. _loadEdition: function(){
  480. this.layout_editionArea = this.contentNode.getElement(".doc_layout_editionArea");
  481. this.layout_edition = this.contentNode.getElement(".doc_layout_edition");
  482. if (this.layout_edition) this.layout_edition.setStyles(this.css.doc_layout_edition);
  483. var node = this.contentNode.getElement(".doc_layout_edition_copyto");
  484. if (node) node.setStyles(this.css.doc_layout_edition_copyto);
  485. node = this.contentNode.getElement(".doc_layout_edition_copyto_table");
  486. if (node) node.setStyles(this.css.doc_layout_edition_copyto_table);
  487. var node = this.contentNode.getElement(".doc_layout_edition_copyto2");
  488. if (node) node.setStyles(this.css.doc_layout_edition_copyto);
  489. node = this.contentNode.getElement(".doc_layout_edition_copyto2_table");
  490. if (node) node.setStyles(this.css.doc_layout_edition_copyto_table);
  491. this.layout_copytoTitle = this.contentNode.getElement(".doc_layout_edition_copyto_title");
  492. if (this.layout_copytoTitle) this.layout_copytoTitle.setStyles(this.css.doc_layout_edition_copyto_title);
  493. this.layout_copytoContent = this.contentNode.getElement(".doc_layout_edition_copyto_content");
  494. if (this.layout_copytoContent) this.layout_copytoContent.setStyles(this.css.doc_layout_edition_copyto_content);
  495. this.layout_copyto2Title = this.contentNode.getElement(".doc_layout_edition_copyto2_title");
  496. if (this.layout_copyto2Title) this.layout_copyto2Title.setStyles(this.css.doc_layout_edition_copyto_title);
  497. this.layout_copyto2Content = this.contentNode.getElement(".doc_layout_edition_copyto2_content");
  498. if (this.layout_copyto2Content) this.layout_copyto2Content.setStyles(this.css.doc_layout_edition_copyto_content);
  499. var issuance = this.contentNode.getElement(".doc_layout_edition_issuance");
  500. if (issuance) issuance.setStyles(this.css.doc_layout_edition_issuance);
  501. var issuance_table = this.contentNode.getElement(".doc_layout_edition_issuance_table");
  502. if (issuance_table) issuance_table.setStyles(this.css.doc_layout_edition_issuance_table);
  503. this.layout_edition_issuance_unit = this.contentNode.getElement(".doc_layout_edition_issuance_unit");
  504. if (this.layout_edition_issuance_unit) this.layout_edition_issuance_unit.setStyles(this.css.doc_layout_edition_issuance_unit);
  505. this.layout_edition_issuance_date = this.contentNode.getElement(".doc_layout_edition_issuance_date");
  506. if (this.layout_edition_issuance_date) this.layout_edition_issuance_date.setStyles(this.css.doc_layout_edition_issuance_date);
  507. },
  508. _loadMeeting: function(){
  509. this.layout_meetingAttendArea = this.contentNode.getElement(".doc_layout_meeting_attend");
  510. this.layout_meetingAttendTitle = this.contentNode.getElement(".doc_layout_meeting_attend_title");
  511. this.layout_meetingAttendContent = this.contentNode.getElement(".doc_layout_meeting_attend_content");
  512. this.layout_meetingLeaveArea = this.contentNode.getElement(".doc_layout_meeting_leave");
  513. this.layout_meetingLeaveTitle = this.contentNode.getElement(".doc_layout_meeting_leave_title");
  514. this.layout_meetingLeaveContent = this.contentNode.getElement(".doc_layout_meeting_leave_content");
  515. this.layout_meetingSitArea = this.contentNode.getElement(".doc_layout_meeting_sit");
  516. this.layout_meetingSitTitle = this.contentNode.getElement(".doc_layout_meeting_sit_title");
  517. this.layout_meetingSitContent = this.contentNode.getElement(".doc_layout_meeting_sit_content");
  518. this.layout_meetingRecordArea = this.contentNode.getElement(".doc_layout_meeting_record");
  519. this.layout_meetingRecordTitle = this.contentNode.getElement(".doc_layout_meeting_record_title");
  520. this.layout_meetingRecordContent = this.contentNode.getElement(".doc_layout_meeting_record_content");
  521. },
  522. _loadCustom: function(){
  523. var nodes = this.contentNode.getElements(".doc_layout");
  524. nodes.each(function(node){
  525. var name = node.get("data-doc-layout");
  526. if (!this.customLayouts) this.customLayouts = [];
  527. this.customLayouts.push({
  528. "name": name,
  529. "node": node,
  530. });
  531. this[name] = node;
  532. }.bind(this));
  533. },
  534. _loadPageLayout: function(control){
  535. this._loadCopiesSecretPriority();
  536. this._loadRedHeader();
  537. if (this.json.fileup){
  538. this._loadFileNoUp();
  539. }else{
  540. this._loadFileNo();
  541. }
  542. if (!this.layout_fileno) this._loadFileNo();
  543. this._loadRedLine();
  544. this._loadSubject();
  545. this._loadMainSend();
  546. this._loadFiletext();
  547. this._loadAttachment();
  548. this._loadIssuance();
  549. this._loadAnnotation();
  550. this._loadEdition();
  551. //会议纪要
  552. this._loadMeeting();
  553. //自定义
  554. this._loadCustom();
  555. this.reSetShow(control);
  556. this.reSetEdit();
  557. // 份数: this.layout_copies
  558. // 密级: this.layout_secret
  559. // 紧急程度: this.layout_priority
  560. // 红头: this.layout_redHeader
  561. // 上行文编号签发: this.layout_fileNoUpTable
  562. // 文号: this.layout_fileno
  563. // 签发: this.layout_signerTitle
  564. // 签发人: this.layout_signer
  565. // 文号: this.layout_fileno
  566. // 红线: this.layout_redLine
  567. // 标题: this.layout_subject
  568. // 主送单位: this.layout_mainSend
  569. // 正文: this.layout_filetexts
  570. // 附件: this.layout_attachmentTitle
  571. // 附件: this.layout_attachment
  572. // 单位: this.layout_issuanceUnit
  573. // 签发时间: this.layout_issuanceDate
  574. // 附注: this.layout_annotation
  575. // 抄送: this.layout_copytoTitle
  576. // 抄送: this.layout_copytoContent
  577. // 版记单位 this.layout_edition_issuance_unit
  578. // 版记日期 this.layout_edition_issuance_date
  579. },
  580. reSetShow: function(control){
  581. if (!control) control = this.getShowControl();
  582. var m = function(s){ return (control[s]) ? "show" : "hide"; }
  583. if (this.layout_copiesSecretPriority) this.layout_copiesSecretPriority[m("copiesSecretPriority")]();
  584. // control.copies = this._getShow("copies", "copiesShow", "copiesShowScript");
  585. // control.secret = this._getShow("secret", "secretShow", "secretShowScript");
  586. // control.priority = this._getShow("priority", "priorityShow", "priorityShowScript");
  587. var n = 0;
  588. if (!control.copies) n++;
  589. if (!control.secret) n++;
  590. if (!control.priority) n++;
  591. if (this.layout_copiesSecretPriority_blank){
  592. while (n>0){
  593. this.layout_copiesSecretPriority_blank.empty();
  594. this.layout_copiesSecretPriority_blank.appendHTML("<span style='font-size:16.0pt'>&nbsp;</span>");
  595. n--;
  596. }
  597. }
  598. if (this.layout_copies) this.layout_copies[m("copies")]();
  599. if (this.layout_secret) this.layout_secret[m("secret")]();
  600. if (this.layout_priority) this.layout_priority[m("priority")]();
  601. if (this.layout_redHeader) this.layout_redHeader[m("redHeader")]();
  602. if (this.layout_redLine) this.layout_redLine[m("redLine")]();
  603. if (this.layout_fileNoUpTable) this.layout_fileNoUpTable[m("signer")]();
  604. if (this.layout_filenoArea) this.layout_filenoArea[(!control.signer) ? "show" : "hide"]();
  605. if (this.layout_signerTitle) this.layout_signerTitle[m("signer")]();
  606. if (this.layout_signer) this.layout_signer[m("signer")]();
  607. if (this.layout_fileno) this.layout_fileno[m("fileno")]();
  608. if (this.layout_subject) this.layout_subject[m("subject")]();
  609. if (this.layout_mainSend) this.layout_mainSend[m("mainSend")]();
  610. if (this.layout_attachmentTable) this.layout_attachmentTable[m("attachment")]();
  611. if (this.layout_issuanceUnit) this.layout_issuanceUnit[m("issuanceUnit")]();
  612. if (this.layout_issuanceDate) this.layout_issuanceDate[m("issuanceDate")]();
  613. if (this.layout_issuanceUnit && this.layout_issuanceDate){
  614. var table = this.layout_issuanceUnit.getParent("table")
  615. if (table && !table.hasClass("doc_layout_headIssuance")) {
  616. var unitWidth = o2.getTextSize(this.layout_issuanceUnit.get("text"), {
  617. "font-size": "16pt",
  618. "font-family": "'Times New Roman',仿宋",
  619. "letter-spacing": "-0.4pt"
  620. }).x;
  621. var dateWidth = o2.getTextSize(this.layout_issuanceDate.get("text"), {
  622. "font-size": "16pt",
  623. "font-family": "'Times New Roman',仿宋",
  624. "letter-spacing": "-0.4pt"
  625. }).x;
  626. // var unitWidth = this.layout_issuanceUnit.getSize().x;
  627. // var dateWidth = this.layout_issuanceDate.getSize().x;
  628. if (unitWidth < dateWidth) {
  629. var flagTd = this.layout_issuanceUnit.getParent("td").getNext("td");
  630. if (flagTd) {
  631. var pt = ((dateWidth - unitWidth) / 96) * 72 + 32 + 32;
  632. flagTd.setStyle("width", "" + pt + "pt");
  633. }
  634. table = this.layout_issuanceDate.getParent("table");
  635. table.setStyle("width", "auto");
  636. flagTd = this.layout_issuanceDate.getParent("td").getNext("td");
  637. if (flagTd) flagTd.setStyle("width", "32pt");
  638. var p = this.layout_issuanceDate.getParent("p");
  639. if (p) p.setStyle("text-align", "right");
  640. } else {
  641. var flagTd = this.layout_issuanceUnit.getParent("td").getNext("td");
  642. if (flagTd) flagTd.setStyle("width", "32pt");
  643. var table = this.layout_issuanceUnit.getParent("table");
  644. var x = table.getSize().x;
  645. table = this.layout_issuanceDate.getParent("table");
  646. table.setStyle("width", "" + x + "px");
  647. flagTd = this.layout_issuanceDate.getParent("td").getNext("td");
  648. if (flagTd) flagTd.setStyle("width", "32pt");
  649. var p = this.layout_issuanceDate.getParent("p");
  650. if (p) p.setStyle("text-align", "center");
  651. }
  652. }
  653. }
  654. if (this.layout_annotation) this.layout_annotation[m("annotation")]();
  655. 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)){
  656. if (this.layout_editionArea) this.layout_editionArea.hide();
  657. }else{
  658. if ((!control.copyto || !this.layout_copytoContent) && (!control.copyto2 || !this.layout_copyto2Content) ){
  659. if (this.layout_edition){
  660. if (this.layout_copytoContent) this.layout_copytoContent.getParent("tr").destroy();
  661. if (this.layout_copyto2Content) this.layout_copyto2Content.getParent("tr").destroy();
  662. // if (this.layout_edition) this.layout_edition.getElement("tr").getElements("td")[0].setStyles({
  663. // "border-top": "solid windowtext 1.5pt",
  664. // "mso-border-top-alt": "solid windowtext 1pt"
  665. // });
  666. }
  667. }else if (!control.copyto || !this.layout_copytoContent){
  668. if (this.layout_copytoContent) this.layout_copytoContent.getParent("tr").destroy();
  669. //if (this.layout_copyto2Content) this.layout_edition.getElement("tr").destroy();
  670. // if (this.layout_edition) this.layout_edition.getElement("tr").getElements("td").setStyles({
  671. // "border-top": "solid windowtext 1.5pt",
  672. // "mso-border-top-alt": "solid windowtext 1pt"
  673. // });
  674. }else if (!control.copyto2 || !this.layout_copyto2Content) {
  675. if (this.layout_copyto2Content) this.layout_copyto2Content.getParent("tr").destroy();
  676. // if (this.layout_edition) this.layout_edition.getElement("tr").getElements("td").setStyles({
  677. // "border-bottom": "solid windowtext 0.75pt",
  678. // "mso-border-bottom-alt": "solid windowtext 0.75pt"
  679. // });
  680. }
  681. if ((!control.editionUnit || !this.layout_edition_issuance_unit) && (!control.editionDate || !this.layout_edition_issuance_date)){
  682. if (this.layout_editionArea && (this.layout_edition_issuance_date || this.layout_edition_issuance_unit)){
  683. var trs = this.layout_editionArea.getElement("table").rows;
  684. trs.item(trs.length-1).destroy();
  685. // trs = this.layout_editionArea.getElement("table").rows;
  686. // var tr = trs.item(trs.length-1);
  687. // if (tr){
  688. // tr.getElements("td").setStyles({
  689. // "border-bottom": "solid windowtext 1.5pt",
  690. // "mso-border-bottom-alt": "solid windowtext 1pt"
  691. // });
  692. // }
  693. }
  694. }
  695. if (this.layout_editionArea && (this.layout_edition_issuance_date || this.layout_edition_issuance_unit)){
  696. trs = this.layout_editionArea.getElement("table").rows;
  697. for (var i=0; i<trs.length; i++){
  698. var tds = trs.item(i).cells;
  699. for (var n=0; n<tds.length; n++){
  700. var td = tds.item(n);
  701. var tdClass = td.get("class");
  702. var tdClassList = (tdClass) ? tdClass.split(/\s+/g) : [];
  703. if (tdClassList.indexOf("line_top_thin_bottom_thick") != -1) tdClassList = tdClassList.erase("line_top_thin_bottom_thick");
  704. if (tdClassList.indexOf("line_top_thick_bottom_thin") != -1) tdClassList = tdClassList.erase("line_top_thick_bottom_thin");
  705. if (tdClassList.indexOf("line_top_thick_bottom_thick") != -1) tdClassList = tdClassList.erase("line_top_thick_bottom_thick");
  706. if (tdClassList.indexOf("line_top_thin_bottom_thin") == -1) tdClassList.unshift("line_top_thin_bottom_thin");
  707. // td.setStyles({
  708. // "border-top": "solid windowtext 0.75pt",
  709. // "mso-border-top-alt": "solid windowtext 0.75pt",
  710. // "border-bottom": "solid windowtext 0.75pt",
  711. // "mso-border-bottom-alt": "solid windowtext 0.75pt",
  712. // });
  713. if (i==0 && i!=(trs.length-1)){
  714. if (tdClassList.indexOf("line_top_thin_bottom_thin") != -1) tdClassList = tdClassList.erase("line_top_thin_bottom_thin");
  715. tdClassList.unshift("line_top_thick_bottom_thin");
  716. // td.setStyles({
  717. // "border-top": "solid windowtext 1.5pt",
  718. // "mso-border-top-alt": "solid windowtext 1pt"
  719. // });
  720. }else if (i==0 && i==(trs.length-1)){
  721. if (tdClassList.indexOf("line_top_thin_bottom_thin") != -1) tdClassList = tdClassList.erase("line_top_thin_bottom_thin");
  722. tdClassList.unshift("line_top_thick_bottom_thick");
  723. }else if (i!=0 && i==(trs.length-1)){
  724. if (tdClassList.indexOf("line_top_thin_bottom_thin") != -1) tdClassList = tdClassList.erase("line_top_thin_bottom_thin");
  725. tdClassList.unshift("line_top_thin_bottom_thick");
  726. }
  727. // if (i==(trs.length-1)){
  728. // if (tdClassList.indexOf("line_bottom_thin") != -1) tdClassList = tdClassList.erase("line_bottom_thin");
  729. // if (tdClassList.indexOf("line_bottom_thick") == -1) tdClassList.push("line_bottom_thick");
  730. // // td.setStyles({
  731. // // "border-bottom": "solid windowtext 1.5pt",
  732. // // "mso-border-bottom-alt": "solid windowtext 1pt"
  733. // // });
  734. // }
  735. tdClass = tdClassList.join(" ");
  736. td.set("class", tdClass);
  737. }
  738. }
  739. }
  740. var coptyToTitleNode = (this.layout_copytoTitle || this.layout_copyto2Title);
  741. if (coptyToTitleNode){
  742. var editionTable = coptyToTitleNode.getParent("table");
  743. if (editionTable) if (editionTable.get("data-compute-style")=="y"){
  744. var rows = editionTable.rows;
  745. for (var i=0; i<rows.length; i++){
  746. var cell = rows[i].cells[0];
  747. var tmp = cell.getElement(".doc_layout_edition_issuance_unit");
  748. if (!tmp) tmp = cell.getElement(".doc_layout_edition_issuance_date");
  749. if (!tmp){
  750. var text = cell.get("text").trim();
  751. var l = 14*text.length;
  752. var wl = 19*text.length;
  753. cell.setStyles({
  754. "max-width": ""+l+"pt",
  755. "min-width": ""+l+"pt",
  756. "width": ""+wl+"pt"
  757. });
  758. }
  759. }
  760. }
  761. }
  762. if (this.layout_editionArea) this.layout_editionArea.show();
  763. if (this.layout_copytoTitle) this.layout_copytoTitle[m("copyto")]();
  764. if (this.layout_copytoContent) this.layout_copytoContent[m("copyto")]();
  765. if (this.layout_copyto2Title) this.layout_copyto2Title[m("copyto2")]();
  766. if (this.layout_copyto2Content) this.layout_copyto2Content[m("copyto2")]();
  767. if (this.layout_edition_issuance_unit) this.layout_edition_issuance_unit[m("editionUnit")]();
  768. if (this.layout_edition_issuance_date) this.layout_edition_issuance_date[m("editionDate")]();
  769. }
  770. if (this.layout_meetingAttendArea) this.layout_meetingAttendArea[m("meetingAttend")]();
  771. if (this.layout_meetingLeaveArea) this.layout_meetingLeaveArea[m("meetingLeave")]();
  772. if (this.layout_meetingSitArea) this.layout_meetingSitArea[m("meetingSit")]();
  773. if (this.layout_meetingRecordArea) this.layout_meetingRecordArea[m("meetingRecord")]();
  774. // this.layout_annotation[m("annotation")]();
  775. // this.layout_annotation[m("annotation")]();
  776. // this.layout_annotation[m("annotation")]();
  777. },
  778. reSetEdit: function(control){
  779. //未进行数据绑定时,可允许编辑
  780. if (!control) var control = this.getEditControl();
  781. if (this.layout_subject){
  782. if (!this.json.subjectValueData && this.json.subjectValueType=="data"){
  783. this.layout_subject.set("contenteditable", control.subject);
  784. // this.layout_subject.addEvent("blur", function(){
  785. // this.getData();
  786. // }.bind(this))
  787. this.layout_subject.addEvent("blur", function(e){
  788. var subject = this.layout_subject.get("text");
  789. if (!subject){
  790. this.layout_subject.set("html", this.data.subject);
  791. this.form.app.notice(MWF.xApplication.process.Xform.LP.subjectEmpty, "error", this.layout_subject, {"x": "center","y":"top"}, {"x": 0,"y":60});
  792. e.preventDefault();
  793. e.stopPropagation();
  794. }else{
  795. this.getData();
  796. }
  797. }.bind(this));
  798. }
  799. }
  800. if (this.layout_issuanceUnit){
  801. if (!this.json.issuanceUnitValueData && this.json.issuanceUnitValueType=="data"){
  802. this.layout_issuanceUnit.set("contenteditable", control.issuanceUnit);
  803. // this.layout_issuanceUnit.addEvent("blur", function(){
  804. // this.getData();
  805. // }.bind(this))
  806. this.layout_issuanceUnit.addEvent("blur", function(e){
  807. var issuanceUnit = this.layout_issuanceUnit.get("text");
  808. if (!issuanceUnit){
  809. this.layout_issuanceUnit.set("html", this.data.issuanceUnit);
  810. this.form.app.notice(MWF.xApplication.process.Xform.LP.issuanceUnitEmpty, "error", this.layout_issuanceUnit, {"x": "center","y":"top"}, {"x": 0,"y":60});
  811. e.preventDefault();
  812. e.stopPropagation();
  813. }else{
  814. this.getData();
  815. }
  816. }.bind(this));
  817. }
  818. }
  819. // this.layout_subject.addEvent("keydown", function(e){
  820. // debugger;
  821. // if (this.json.subjectValueType=="data" && this.json.subjectValueData){
  822. // // var v = e.target.get("HTML");
  823. // // this.form.businessData.data[this.json.subjectValueData] = v
  824. // var module = this.form.all[this.json.subjectValueData];
  825. // if (module){
  826. // var bindFun = module.node.retrieve(this.json.id+"bindFun");
  827. // module.node
  828. // }
  829. // }
  830. // }.bind(this));
  831. },
  832. _loadUserInterface: function(callback){
  833. this.node.empty();
  834. this.node.setStyles(this.form.css.documentEditorNode);
  835. this.pages = [];
  836. this.allowEdit = this._isAllowEdit();
  837. this.allowPrint = this._isAllowPrint();
  838. this.allowHistory = this._isAllowHistory();
  839. this.toolNode = new Element("div", {"styles": this.css.doc_toolbar}).inject(this.node);
  840. this.contentNode = new Element("div#doc_content", {"styles": this.css.doc_content}).inject(this.node);
  841. if (!this.form.isLoaded){
  842. this.form.addEvent("afterModulesLoad", function(){this.loadDocumentEditor(callback);}.bind(this));
  843. }else{
  844. this.loadDocumentEditor(callback);
  845. }
  846. },
  847. loadDocumentEditor: function(callback){
  848. this._loadToolbars();
  849. this._loadFiletextPage(function(){
  850. if (this.options.pageShow!=="double"){
  851. this._singlePage();
  852. }else{
  853. this._doublePage();
  854. }
  855. // this.form.addEvent("beforeProcess", function(){
  856. // this.resetData();
  857. // if (this.checkSaveNewEdition()) this.saveNewDataEdition();
  858. // this.notSaveResetData = true;
  859. // }.bind(this));
  860. this.form.addEvent("beforeSave", function(){
  861. this.resetData();
  862. this.checkSaveNewEdition();
  863. //if (!this.notSaveResetData) this.resetData();
  864. }.bind(this));
  865. if (this.json.toWord=="y"){
  866. if (this.json.toWordTrigger=="open") this.docToWord();
  867. if (this.json.toWordTrigger=="save") this.form.addEvent("beforeSave", this.docToWord.bind(this));
  868. if (this.json.toWordTrigger=="submit") this.form.addEvent("beforeProcess", this.docToWord.bind(this));
  869. }
  870. if (!layout.mobile) this.loadSideToolbar();
  871. o2.load("../o2_lib/diff-match-patch/diff_match_patch.js");
  872. if (this.form.businessData.data["$work"]){
  873. var id = this.form.businessData.data["$work"].job;
  874. o2.Actions.load("x_processplatform_assemble_surface").DocumentVersionAction.listWithJobCategory(id, this.json.id, function(json){
  875. this.historyDocumentList = json.data;
  876. if (this.historyDocumentList.length){
  877. o2.Actions.load("x_processplatform_assemble_surface").DocumentVersionAction.get(this.historyDocumentList[this.historyDocumentList.length-1].id, function(json){
  878. var data = JSON.parse(json.data.data);
  879. this.originaHistoryData = data.data;
  880. }.bind(this));
  881. }
  882. }.bind(this));
  883. }
  884. if (callback) callback();
  885. }.bind(this));
  886. if (!this.form.documenteditorList) this.form.documenteditorList=[];
  887. this.form.documenteditorList.push(this);
  888. },
  889. checkSaveNewEdition: function(callback){
  890. if (!this.allowEdit || !this.data.filetext || this.data.filetext == this.json.defaultValue.filetext) return false;
  891. if (this.form.businessData.work){
  892. var originaData = this.form.businessData.originalData[this.json.id];
  893. var editionData = {"category": this.json.id};
  894. if (!originaData || !originaData.filetext || !this.originaHistoryData){
  895. //保存原始版本
  896. this.originaHistoryData = {"data": this.data.filetext};
  897. editionData.data = JSON.stringify({"data": this.data.filetext});
  898. }else if (originaData.filetext!=this.data.filetext){
  899. //保存历史版本
  900. var data = this.data.filetext;
  901. var earlyData = originaData.filetext;
  902. var dmp = new diff_match_patch();
  903. var diff_d = dmp.diff_main(earlyData, data);
  904. dmp.diff_cleanupSemantic(diff_d);
  905. var patch_list = dmp.patch_make(earlyData, data, diff_d);
  906. editionData.data = JSON.stringify({"patchs": dmp.patch_toText(patch_list)});
  907. }else{
  908. return false;
  909. }
  910. o2.Actions.load("x_processplatform_assemble_surface").DocumentVersionAction.create(this.form.businessData.work.id, editionData, function(json){
  911. //originaData.filetext = this.data.filetext;
  912. if (callback) callback();
  913. }.bind(this));
  914. }
  915. },
  916. // saveNewDataEdition: function(callback){
  917. // if (this.form.businessData.work){
  918. // var editionData = {"category": this.json.id};
  919. // if (this.form.businessData.originalData[this.json.id] && this.form.businessData.originalData[this.json.id].filetext){
  920. // var data = this.data.filetext;
  921. // var earlyData = this.form.businessData.originalData[this.json.id].filetext;
  922. // var dmp = new diff_match_patch();
  923. // var diff_d = dmp.diff_main(earlyData, data);
  924. // dmp.diff_cleanupSemantic(diff_d);
  925. // var patch_list = dmp.patch_make(earlyData, data, diff_d);
  926. // editionData.data = {"patchs": dmp.patch_toText(patch_list)};
  927. //
  928. // }else{
  929. // editionData.data = {"data": this.data.filetext};
  930. // }
  931. // o2.Actions.load("x_processplatform_assemble_surface").DocumentVersionAction.create(this.form.businessData.work.id, editionData, function(json){
  932. // this.form.businessData.originalData[this.json.id] = this.data.filetext;
  933. // if (callback) callback();
  934. // }.bind(this));
  935. // }
  936. // },
  937. resizeToolbar: function(){
  938. if (this.toolbarNode){
  939. var p = this.toolNode.getPosition(this.scrollNode);
  940. var size = this.toolNode.getSize();
  941. var pl = this.toolbarNode.getStyle("padding-left").toInt();
  942. var pr = this.toolbarNode.getStyle("padding-right").toInt();
  943. var x = size.x-pl-pr;
  944. //var pNode = this.toolNode.getOffsetParent();
  945. var paddingTop = this.form.node.getStyle("padding-top");
  946. try {
  947. paddingTop = paddingTop.toInt();
  948. }catch (e) {
  949. paddingTop = 0;
  950. }
  951. if (p.y<paddingTop){
  952. this.toolbarNode.inject(this.scrollNode);
  953. this.toolbarNode.setStyles({
  954. "position": "absolute",
  955. "width": ""+x+"px",
  956. "z-index": 200,
  957. "top": paddingTop+"px",
  958. "left": ""+p.x+"px"
  959. });
  960. }else{
  961. this.toolbarNode.inject(this.toolNode);
  962. this.toolbarNode.setStyles({"position": "static"});
  963. }
  964. }
  965. },
  966. resizeSidebar: function(){
  967. if (this.sidebarNode){
  968. var fileTextNode = this.contentNode.getElement("div.doc_layout_filetext");
  969. if (fileTextNode){
  970. this.sidebarNode.position({
  971. relativeTo: fileTextNode,
  972. position: 'topLeft',
  973. edge: 'topRight',
  974. offset: {"x": -20, "y": 60}
  975. });
  976. var p = fileTextNode.getPosition(this.form.app.content);
  977. var ptop = fileTextNode.getPosition(this.node);
  978. //if ((p.y+s.y)<0) this.sidebarNode.setStyle("top", p.y+s.y);
  979. if (p.y<0){
  980. var top = ptop.y-p.y+200;
  981. this.sidebarNode.setStyle("top", top);
  982. }
  983. // var p = fileTextNode.getPosition();
  984. // this.sidebarNode.setStyle("top", p.y);
  985. }
  986. }
  987. },
  988. loadSideToolbar: function(){
  989. if (this.allowEdit){
  990. if (this.pages.length){
  991. var fileTextNode = this.pages[0].getElement("div.doc_layout_filetext");
  992. if (fileTextNode){
  993. this.sidebarNode = new Element("div", {"styles": this.css.doc_sidebar}).inject(this.node);
  994. this.resizeSidebar();
  995. this.scrollNode = this.sidebarNode.getParentSrcollNode();
  996. if (this.scrollNode){
  997. this.scrollNode.addEvent("scroll", function(){
  998. this.resizeSidebar();
  999. }.bind(this));
  1000. }
  1001. 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>";
  1002. this.sidebarNode.set("html", html);
  1003. MWF.require("MWF.widget.Toolbar", function() {
  1004. this.sideToolbar = new MWF.widget.Toolbar(this.sidebarNode, {"style": "documentEdit_side"}, this);
  1005. this.sideToolbar.load();
  1006. }.bind(this));
  1007. }
  1008. }
  1009. }
  1010. },
  1011. _returnScale: function(){
  1012. this.isScale = false;
  1013. this.scale = 0;
  1014. this.contentNode.setStyles({
  1015. "transform":"scale(1)",
  1016. });
  1017. if (this.pages.length){
  1018. this.pages.each(function(page){
  1019. page.setStyles({
  1020. "transform":"scale(1)",
  1021. });
  1022. });
  1023. }
  1024. this.node.setStyles({
  1025. "height": "auto"
  1026. });
  1027. },
  1028. _checkScale: function(offset){
  1029. offset = 0;
  1030. if (this.pages.length){
  1031. //var pageSize = this.pages[0].getSize();
  1032. var pageSize_x = this.options.docPageFullWidth
  1033. var contentSize = this.contentNode.getSize();
  1034. var contentWidth = (offset) ? contentSize.x-20-offset : contentSize.x-20;
  1035. if (contentWidth<pageSize_x){
  1036. this.isScale = true;
  1037. var scale = (contentWidth)/pageSize_x;
  1038. this.scale = scale;
  1039. this.zoom();
  1040. this.resetNodeSize();
  1041. }
  1042. }
  1043. },
  1044. zoom: function(scale){
  1045. if (scale) this.scale = scale;
  1046. if (this.zoomSelectAction){
  1047. for (var i=0; i<this.zoomSelectAction.options.length; i++){
  1048. var option = this.zoomSelectAction.options[i];
  1049. if (Math.abs(this.scale-option.value.toFloat())<0.05){
  1050. option.set("selected", true);
  1051. break;
  1052. }
  1053. }
  1054. }
  1055. var w = this.node.getSize().x;
  1056. if (this.history && this.history.historyListAreaNode) w = w-this.history.historyListAreaNode.getComputedSize().totalWidth-2;
  1057. w = w/this.scale;
  1058. this.contentNode.setStyles({
  1059. "transform":"scale("+this.scale+")",
  1060. "transform-origin": "0px 0px",
  1061. "overflow": "auto",
  1062. "width": ""+w+"px"
  1063. });
  1064. },
  1065. _switchReadOrEdit: function(){
  1066. if (this.editMode){
  1067. this._readFiletext();
  1068. if (this.allowEdit) {
  1069. var button = this.toolbar.childrenButton[0];
  1070. button.setText((layout.mobile) ? MWF.xApplication.process.Xform.LP.editdoc_mobile : MWF.xApplication.process.Xform.LP.editdoc);
  1071. button.picNode.getElement("img").set("src", "../x_component_process_Xform/$Form/default/icon/editdoc.png");
  1072. //this.getFullWidthFlagNode().dispose();
  1073. }
  1074. this.editMode = false;
  1075. }else{
  1076. this._editFiletext();
  1077. if (this.allowEdit) {
  1078. var button = this.toolbar.childrenButton[0];
  1079. button.setText((layout.mobile) ? MWF.xApplication.process.Xform.LP.editdocCompleted_mobile : MWF.xApplication.process.Xform.LP.editdocCompleted);
  1080. button.picNode.getElement("img").set("src", "../x_component_process_Xform/$Form/default/icon/editdoc_completed.png");
  1081. //this.toolbar.node.inject(this.getFullWidthFlagNode());
  1082. }
  1083. this.editMode = true;
  1084. }
  1085. },
  1086. _switchReadOrEditInline: function(){
  1087. if (this.editMode){
  1088. this._readFiletext();
  1089. if (this.allowEdit){
  1090. if (!layout.mobile) {
  1091. var button = this.sideToolbar.childrenButton[0];
  1092. button.setText((layout.mobile) ? MWF.xApplication.process.Xform.LP.editdoc_mobile : MWF.xApplication.process.Xform.LP.editdoc);
  1093. button.picNode.getElement("img").set("src", "../x_component_process_Xform/$Form/default/icon/editdoc.png");
  1094. //this.getFullWidthFlagNode().dispose();
  1095. }
  1096. button = this.toolbar.childrenButton[0];
  1097. button.setText((layout.mobile) ? MWF.xApplication.process.Xform.LP.editdoc_mobile : MWF.xApplication.process.Xform.LP.editdoc);
  1098. button.picNode.getElement("img").set("src", "../x_component_process_Xform/$Form/default/icon/editdoc.png");
  1099. //this.getFullWidthFlagNode().dispose();
  1100. // if (!layout.mobile)this.sideToolbar.childrenButton[0].setText(MWF.xApplication.process.Xform.LP.editdoc);
  1101. // this.toolbar.childrenButton[0].setText(MWF.xApplication.process.Xform.LP.editdoc);
  1102. }
  1103. this.editMode = false;
  1104. }else{
  1105. this._editFiletext("inline");
  1106. if (this.allowEdit){
  1107. if (!layout.mobile) {
  1108. var button = this.sideToolbar.childrenButton[0];
  1109. button.setText((layout.mobile) ? MWF.xApplication.process.Xform.LP.editdocCompleted_mobile : MWF.xApplication.process.Xform.LP.editdocCompleted);
  1110. button.picNode.getElement("img").set("src", "../x_component_process_Xform/$Form/default/icon/editdoc_completed.png");
  1111. //this.toolbar.node.inject(this.getFullWidthFlagNode());
  1112. }
  1113. button = this.toolbar.childrenButton[0];
  1114. button.setText((layout.mobile) ? MWF.xApplication.process.Xform.LP.editdocCompleted_mobile : MWF.xApplication.process.Xform.LP.editdocCompleted);
  1115. button.picNode.getElement("img").set("src", "../x_component_process_Xform/$Form/default/icon/editdoc_completed.png");
  1116. //this.toolbar.node.inject(this.getFullWidthFlagNode());
  1117. // if (!layout.mobile) this.sideToolbar.childrenButton[0].setText(MWF.xApplication.process.Xform.LP.editdocCompleted);
  1118. // this.toolbar.childrenButton[0].setText(MWF.xApplication.process.Xform.LP.editdocCompleted);
  1119. }
  1120. this.editMode = true;
  1121. }
  1122. },
  1123. // getFullWidthFlagNode: function(){
  1124. // if (!this.fullWidthFlagNode){
  1125. // this.fullWidthFlagNode = new Element("span", {
  1126. // "styles": {
  1127. // "line-height": "26px",
  1128. // "color": "#999999",
  1129. // "font-size": "12px"
  1130. // },
  1131. // "text": MWF.xApplication.process.Xform.LP.fullWidth
  1132. // });
  1133. // }
  1134. // return this.fullWidthFlagNode;
  1135. // },
  1136. _printDoc: function(){
  1137. var scale = this.scale;
  1138. this.toWord(function(data){
  1139. if (this.form.businessData.work && !this.form.businessData.work.completedTime){
  1140. this.form.workAction.getAttachmentStream(data.id, this.form.businessData.work.id);
  1141. }else{
  1142. this.form.workAction.getWorkcompletedAttachmentStream(data.id, ((this.form.businessData.workCompleted) ? this.form.businessData.workCompleted.id : this.form.businessData.work.id));
  1143. }
  1144. this.scaleTo(scale);
  1145. }.bind(this));
  1146. },
  1147. _historyDoc: function(){
  1148. this.getHistory(function(){
  1149. //this.history.play();
  1150. }.bind(this));
  1151. },
  1152. getHistory: function(callback){
  1153. if (this.history){
  1154. this.history.active(function(){
  1155. if (callback) callback();
  1156. });
  1157. }else{
  1158. MWF.xDesktop.requireApp("process.Xform", "widget.DocumentHistory", function(){
  1159. this.history = new MWF.xApplication.process.Xform.widget.DocumentHistory(this);
  1160. this.history.load(function(){
  1161. if (callback) callback();
  1162. });
  1163. }.bind(this));
  1164. }
  1165. },
  1166. htmlToText: function(html){
  1167. var tmpdiv = new Element("div", {"html": html});
  1168. var text = tmpdiv.get("text");
  1169. tmpdiv.destroy();
  1170. return text;
  1171. },
  1172. _readFiletext: function(){
  1173. //this._returnScale();
  1174. //this.zoom(1);
  1175. var scale = this.scale;
  1176. if (this.filetextEditor) this.filetextEditor.destroy();
  1177. if (this.filetextScrollNode){
  1178. if (this.reLocationFiletextToolbarFun){
  1179. this.filetextScrollNode.removeEvent("scroll", this.reLocationFiletextToolbarFun);
  1180. //this.form.app.removeEvent("resize", this.reLocationFiletextToolbarFun);
  1181. this.reLocationFiletextToolbarFun = null;
  1182. }
  1183. this.filetextScrollNode = null;
  1184. }
  1185. if (this.filetextToolbarNode) this.filetextToolbarNode = null;
  1186. this.layout_filetext.setAttribute('contenteditable', false);
  1187. this.data = this.getData();
  1188. // debugger;
  1189. if (!this.data.filetext){
  1190. //this.data.filetext = this.json.defaultValue.filetext;
  1191. this.layout_filetext.set("html", this.json.defaultValue.filetext);
  1192. }
  1193. //this._checkSplitPage(this.pages[0]);
  1194. this._repage();
  1195. this.scaleTo(scale);
  1196. },
  1197. _editFiletext: function(inline){
  1198. this._returnScale();
  1199. this.zoom(1);
  1200. this._singlePage();
  1201. this.pages = [];
  1202. this.contentNode.empty();
  1203. this._createPage(function(control){
  1204. this._loadPageLayout(control);
  1205. // var docData = this._getBusinessData();
  1206. // if (!docData) docData = this._getDefaultData();
  1207. if (this.data.filetext == this.json.defaultValue.filetext) this.data.filetext = "  ";
  1208. this.setData(this.data);
  1209. this._checkScale();
  1210. this.node.setStyles({
  1211. "height":"auto"
  1212. });
  1213. this._createEditor(inline);
  1214. }.bind(this));
  1215. },
  1216. _createEditor: function(inline){
  1217. if (this.allowEdit){
  1218. this.loadCkeditorFiletext(function(e){
  1219. e.editor.focus();
  1220. var text = this.data.filetext.replace(/\u3000*/g, "");
  1221. if (!text){
  1222. var range = e.editor.createRange();
  1223. range.moveToElementEditEnd(e.editor.editable());
  1224. range.select();
  1225. range.scrollIntoView();
  1226. }else{
  1227. e.editor.getSelection().scrollIntoView();
  1228. }
  1229. //e.editor.getSelection().scrollIntoView();
  1230. var text = this.data.filetext.replace(/\u3000*/g, "");
  1231. if (!text){
  1232. var range = e.editor.createRange();
  1233. range.moveToElementEditEnd(e.editor.editable());
  1234. range.select();
  1235. range.scrollIntoView();
  1236. }else{
  1237. e.editor.getSelection().scrollIntoView();
  1238. }
  1239. // e.editor.getSelection().scrollIntoView();
  1240. //
  1241. //this.getFiletextToolber();
  1242. //this.filetextToolbarNode.inject(this.layout_filetext.getOffsetParent());
  1243. this.locationFiletextToolbar();
  1244. }.bind(this), inline);
  1245. }
  1246. },
  1247. getFiletextToolber: function(){
  1248. if (this.filetextEditor) {
  1249. if (!this.filetextToolbarNode) {
  1250. var className = "cke_editor_" + this.filetextEditor.name;
  1251. var filetextToolbarNode = $$("." + className)[0];
  1252. this.filetextToolbarNode = filetextToolbarNode;
  1253. //filetextToolbarNode.destroy();
  1254. }
  1255. }
  1256. },
  1257. reLocationFiletextToolbar: function(){
  1258. this.getFiletextToolber();
  1259. // if (this.filetextToolbarNode){
  1260. // this.filetextToolbarNode.setStyle("display", "block");
  1261. // var offsetNode = this.layout_filetext.getOffsetParent();
  1262. //
  1263. // this.filetextToolbarNode.setStyle("left", 0);
  1264. // var h = this.filetextToolbarNode.getSize().y;
  1265. // var p = this.layout_filetext.getPosition(offsetNode).y-h;
  1266. //
  1267. // var postion = this.layout_filetext.getPosition(this.form.app.content);
  1268. // if (postion.y-h<0){
  1269. // this.filetextToolbarNode.inject(this.form.app.content);
  1270. // this.filetextToolbarNode.setStyle("top", 0);
  1271. // this.filetextToolbarNode.setStyle("left", ""+postion.x+"px");
  1272. // }else{
  1273. // this.filetextToolbarNode.inject(offsetNode);
  1274. // this.filetextToolbarNode.setStyle("top", "" + p + "px");
  1275. // this.filetextToolbarNode.setStyle("left", 0);
  1276. // this.filetextToolbarNode.setStyle("left", "auto");
  1277. // }
  1278. // }
  1279. if (this.filetextToolbarNode){
  1280. if (!this.filetextScrollNode){
  1281. var scrollNode = this.contentNode;
  1282. while (scrollNode && (scrollNode.getScrollSize().y<=scrollNode.getSize().y || (scrollNode.getStyle("overflow")!=="auto" && scrollNode.getStyle("4-y")!=="auto"))){
  1283. scrollNode = scrollNode.getParent();
  1284. }
  1285. this.filetextScrollNode = scrollNode;
  1286. }
  1287. var h = this.filetextToolbarNode.getSize().y;
  1288. var position = this.layout_filetext.getPosition();
  1289. var size = this.layout_filetext.getSize();
  1290. var contentSize = this.filetextScrollNode.getSize();
  1291. if (position.y<0 && size.y+position.y+h<contentSize.y){
  1292. // var top = size.y+position.y;
  1293. // this.filetextToolbarNode.setStyle("top", ""+top+"px");
  1294. var tp = this.toolbar.node.getPosition();
  1295. var tsy = this.toolbar.node.getSize().y;
  1296. var h = tp.y+tsy;
  1297. this.filetextToolbarNode.setStyle("top", ""+h+"px");
  1298. }else if (position.y-h<0){
  1299. var tp = this.toolbar.node.getPosition();
  1300. var tsy = this.toolbar.node.getSize().y;
  1301. var h = tp.y+tsy;
  1302. this.filetextToolbarNode.setStyle("top", ""+h+"px");
  1303. }else{
  1304. var p = this.layout_filetext.getPosition().y-h;
  1305. this.filetextToolbarNode.setStyle("top", "" + p + "px");
  1306. }
  1307. }
  1308. //
  1309. // this.filetextToolbarNode.inject(offsetNode);
  1310. //
  1311. //
  1312. // this.filetextToolbarNode.setStyle("top", ""+p+"px");
  1313. },
  1314. locationFiletextToolbar: function(){
  1315. this.reLocationFiletextToolbar();
  1316. if (this.filetextToolbarNode) {
  1317. var scrollNode = this.contentNode;
  1318. while (scrollNode && (scrollNode.getScrollSize().y<=scrollNode.getSize().y || (scrollNode.getStyle("overflow")!=="auto" && scrollNode.getStyle("overflow-y")!=="auto"))){
  1319. scrollNode = scrollNode.getParent();
  1320. }
  1321. if (scrollNode){
  1322. this.filetextScrollNode = scrollNode;
  1323. this.reLocationFiletextToolbarFun = this.reLocationFiletextToolbar.bind(this);
  1324. this.filetextScrollNode.addEvent("scroll", this.reLocationFiletextToolbarFun);
  1325. }
  1326. }
  1327. },
  1328. _isAllowEdit:function(){
  1329. if (this.readonly) return false;
  1330. if (this.json.allowEdit=="n") return false;
  1331. if (this.json.allowEdit=="s"){
  1332. if (this.json.allowEditScript && this.json.allowEditScript.code){
  1333. return !!this.form.Macro.exec(this.json.allowEditScript.code, this);
  1334. }
  1335. }
  1336. return true;
  1337. },
  1338. _isAllowPrint: function(){
  1339. if (this.json.allowPrint=="n") return false;
  1340. if (this.json.allowPrint=="s"){
  1341. if (this.json.allowPrintScript && this.json.allowPrintScript.code){
  1342. return !!this.form.Macro.exec(this.json.allowPrintScript.code, this);
  1343. }
  1344. }
  1345. return true;
  1346. },
  1347. _isAllowHistory: function(){
  1348. if (this.json.allowHistory=="n") return false;
  1349. if (this.json.allowHistory=="s"){
  1350. if (this.json.allowHistoryScript && this.json.allowHistoryScript.code){
  1351. return !!this.form.Macro.exec(this.json.allowHistoryScript.code, this);
  1352. }
  1353. }
  1354. return true;
  1355. },
  1356. _getEdit: function(name, typeItem, scriptItem){
  1357. switch (this.json[typeItem]) {
  1358. case "y":
  1359. return true;
  1360. case "n":
  1361. return false;
  1362. case "s":
  1363. if (this.json[scriptItem] && this.json[scriptItem].code){
  1364. return !!this.form.Macro.exec(this.json[scriptItem].code, this);
  1365. }
  1366. return true;
  1367. }
  1368. },
  1369. loadCkeditorStyle: function(node){
  1370. if (node){
  1371. o2.load("ckeditor", function(){
  1372. //CKEDITOR.disableAutoInline = true;
  1373. node.setAttribute('contenteditable', true);
  1374. var editor = CKEDITOR.inline(this.layout_filetext, this._getEditorConfig());
  1375. this.filetextEditor.on("instanceReady", function(e){
  1376. if (callback) callback(e);
  1377. }.bind(this));
  1378. }.bind(this));
  1379. }
  1380. },
  1381. _loadToolbars: function(){
  1382. var html ="";
  1383. var editdoc, printdoc, history;
  1384. if (layout.mobile){
  1385. editdoc = MWF.xApplication.process.Xform.LP.editdoc_mobile;
  1386. printdoc = MWF.xApplication.process.Xform.LP.printdoc_mobile;
  1387. history = MWF.xApplication.process.Xform.LP.history_mobile;
  1388. }else{
  1389. editdoc = MWF.xApplication.process.Xform.LP.editdoc;
  1390. printdoc = MWF.xApplication.process.Xform.LP.printdoc;
  1391. history = MWF.xApplication.process.Xform.LP.history;
  1392. }
  1393. if (this.allowEdit){
  1394. //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>";
  1395. html += "<span MWFnodetype=\"MWFToolBarButton\" MWFButtonImage=\"../x_component_process_Xform/$Form/default/icon/editdoc.png\" title=\""+editdoc+"\" MWFButtonAction=\"_switchReadOrEditInline\" MWFButtonText=\""+editdoc+"\"></span>";
  1396. //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>";
  1397. }
  1398. if (this.allowPrint){
  1399. html += "<span MWFnodetype=\"MWFToolBarButton\" MWFButtonImage=\"../x_component_process_Xform/$Form/default/icon/print.png\" title=\""+printdoc+"\" MWFButtonAction=\"_printDoc\" MWFButtonText=\""+printdoc+"\"></span>";
  1400. }
  1401. if (this.allowHistory){
  1402. html += "<span MWFnodetype=\"MWFToolBarButton\" MWFButtonImage=\"../x_component_process_Xform/$Form/default/icon/versions.png\" title=\""+history+"\" MWFButtonAction=\"_historyDoc\" MWFButtonText=\""+history+"\"></span>";
  1403. }
  1404. // if (this.json.fullWidth=="y"){
  1405. // html += "<span style='line-height: 26px; color: #999999; font-size: 12px'>已启用半角空格自动转换为全角空格,如需输入半角空格,请使用:SHIFT+空格</span>"
  1406. // }
  1407. this.toolbarNode = new Element("div", {"styles": this.css.doc_toolbar_node}).inject(this.toolNode);
  1408. this.toolbarNode.set("html", html);
  1409. MWF.require("MWF.widget.Toolbar", function() {
  1410. this.toolbar = new MWF.widget.Toolbar(this.toolbarNode, {"style": "documentEdit"}, this);
  1411. this.toolbar.load();
  1412. }.bind(this));
  1413. if (!layout.mobile){
  1414. this.scrollNode = this.toolbarNode.getParentSrcollNode();
  1415. if (this.scrollNode){
  1416. this.scrollNode.addEvent("scroll", function(){
  1417. this.resizeToolbar();
  1418. }.bind(this));
  1419. }
  1420. }
  1421. //if (this.json.canDoublePage!=="n" && !layout.mobile){
  1422. this.doublePageAction = new Element("div", {"styles": this.css.doc_toolbar_doublePage, "text": MWF.xApplication.process.Xform.LP.doublePage}).inject(this.toolbarNode);
  1423. this.doublePageAction.addEvent("click", function(){
  1424. if (this.options.pageShow!=="double"){
  1425. this._doublePage();
  1426. }else{
  1427. this.options.pageShow="single";
  1428. this.reload();
  1429. //this._singlePage();
  1430. }
  1431. }.bind(this));
  1432. if (this.json.canDoublePage!=="n" && !layout.mobile) this.doublePageAction.hide();
  1433. //}
  1434. this.zoomActionArea = new Element("div", {"styles": {"float": "right", "margin-right": "10px"}}).inject(this.toolbarNode);
  1435. if (this.json.isScale !== "y") this.zoomActionArea.hide();
  1436. this.zoomAddAction = new Element("div", {
  1437. "styles": {
  1438. "float": "right",
  1439. "margin-top": "3px",
  1440. "height": "20px",
  1441. "width": "20px",
  1442. "text-align": "center",
  1443. "line-height": "20px",
  1444. "border": "1px solid #cccccc",
  1445. "background-color": "#ffffff",
  1446. "margin-left": "5px"
  1447. },
  1448. "text": "+"
  1449. }).inject(this.zoomActionArea);
  1450. this.zoomSelectAction = new Element("select", {
  1451. "styles": {
  1452. "float": "right",
  1453. "margin-top": "3px",
  1454. "height": "20px",
  1455. "width": "60px",
  1456. "text-align": "center",
  1457. "line-height": "20px",
  1458. "border": "1px solid #cccccc",
  1459. "background-color": "#ffffff",
  1460. "margin-left": "5px"
  1461. },
  1462. "text": "100%"
  1463. }).inject(this.zoomActionArea);
  1464. this.zoomSubAction = new Element("div", {
  1465. "styles": {
  1466. "float": "right",
  1467. "margin-top": "3px",
  1468. "height": "20px",
  1469. "width": "20px",
  1470. "text-align": "center",
  1471. "line-height": "20px",
  1472. "border": "1px solid #cccccc",
  1473. "background-color": "#ffffff",
  1474. "margin-left": "5px"
  1475. },
  1476. "text": "-"
  1477. }).inject(this.zoomActionArea);
  1478. // this.zoomSelectAction = new Element("select", {"styles": {"float": "right"}}).inject(this.toolbarNode);
  1479. var options = "<option value='2'>200%</option> " +
  1480. "<option value='1.95'>195%</option>" +
  1481. "<option value='1.9'>190%</option>" +
  1482. "<option value='1.85'>185%</option>" +
  1483. "<option value='1.8'>180%</option>" +
  1484. "<option value='1.75'>175%</option>" +
  1485. "<option value='1.7'>170%</option>" +
  1486. "<option value='1.65'>165%</option>" +
  1487. "<option value='1.6'>160%</option>" +
  1488. "<option value='1.55'>155%</option>" +
  1489. "<option value='1.5'>150%</option> " +
  1490. "<option value='1.45'>145%</option>" +
  1491. "<option value='1.4'>140%</option>" +
  1492. "<option value='1.35'>135%</option>" +
  1493. "<option value='1.3'>130%</option>" +
  1494. "<option value='1.25'>125%</option>" +
  1495. "<option value='1.2'>120%</option>" +
  1496. "<option value='1.15'>115%</option>" +
  1497. "<option value='1.1'>110%</option>" +
  1498. "<option value='1.05'>105%</option>" +
  1499. "<option value='1' selected>100%</option>" +
  1500. "<option value='0.95'>95%</option>" +
  1501. "<option value='0.90'>90%</option>" +
  1502. "<option value='0.85'>85%</option>" +
  1503. "<option value='0.80'>80%</option>" +
  1504. "<option value='0.75'>75%</option>" +
  1505. "<option value='0.70'>70%</option>" +
  1506. "<option value='0.65'>65%</option>" +
  1507. "<option value='0.6'>60%</option>" +
  1508. "<option value='0.55'>55%</option>" +
  1509. "<option value='0.5'>50%</option>";
  1510. this.zoomSelectAction.set("html", options);
  1511. this.zoomSelectAction.addEvent("change", function(e){
  1512. this.scaleTo(e.target.options[e.target.selectedIndex].value);
  1513. }.bind(this));
  1514. this.zoomAddAction.addEvent("click", function(){
  1515. var i = (this.scale/0.05).toInt();
  1516. if (i*0.05<this.scale) i++;
  1517. var v = i*0.05;
  1518. //var v = this.zoomSelectAction.options[this.zoomSelectAction.selectedIndex].value.toFloat();
  1519. v = v+0.05;
  1520. if (v<0.5) v = 0.5;
  1521. if (v>2) v = 2;
  1522. this.scaleTo(v);
  1523. }.bind(this));
  1524. this.zoomSubAction.addEvent("click", function(){
  1525. var i = (this.scale/0.05).toInt();
  1526. if (i*0.05<this.scale) i++;
  1527. var v = i*0.05;
  1528. //var v = this.zoomSelectAction.options[this.zoomSelectAction.selectedIndex].value.toFloat();
  1529. v = v-0.05;
  1530. if (v<0.5) v = 0.5;
  1531. if (v>2) v = 2;
  1532. this.scaleTo(v);
  1533. }.bind(this));
  1534. },
  1535. /**缩放文件内容
  1536. * @param scale{Number} 缩放的比率
  1537. * @example
  1538. * this.form.get("fieldName").scaleTo(0.5);
  1539. */
  1540. scaleTo: function(scale){
  1541. this._returnScale();
  1542. this.scale = scale;
  1543. this.zoom();
  1544. var w = this.contentNode.getSize().x;
  1545. var count = 1;
  1546. var docPageFullWidth = (this.scale) ? this.scale*this.options.docPageFullWidth : this.options.docPageFullWidth;
  1547. var pageWidth = count * docPageFullWidth;
  1548. var margin = (w-pageWidth)/(count+1);
  1549. if (this.isScale){
  1550. margin = "10";
  1551. }
  1552. if (this.scale) margin = margin/this.scale;
  1553. if (margin < 10){
  1554. var offset = 10-margin;
  1555. margin = 10;
  1556. this.contentNode.scrollTo(offset, 0);
  1557. }
  1558. this.pages.each(function(page, i){
  1559. page.setStyles({
  1560. "float": "left",
  1561. "margin-left": ""+margin+"px"
  1562. });
  1563. });
  1564. this.resetNodeSize();
  1565. },
  1566. _repage: function(delay){
  1567. if (this.options.pageShow!=="double"){
  1568. this._singlePage();
  1569. }else{
  1570. this._doublePage();
  1571. }
  1572. if (delay){
  1573. if (!this.form.isLoaded){
  1574. this.form.addEvent("afterLoad", this._checkScale.bind(this));
  1575. }else{
  1576. this._checkScale();
  1577. }
  1578. }else{
  1579. this._checkScale();
  1580. }
  1581. },
  1582. _singlePage: function(){
  1583. //if (this.editMode) this._readFiletext();
  1584. var scale = this.singlePageZoom || 1;
  1585. if( this.singlePageZoom && this.singlePageZoom.toInt() != 1 ){
  1586. this.isScale = true;
  1587. this.scale = this.singlePageZoom;
  1588. this.singlePageZoom = null;
  1589. }
  1590. this.zoom(scale);
  1591. this._checkScale();
  1592. var w = this.contentNode.getSize().x;
  1593. var count = 1;
  1594. var docPageFullWidth = (this.scale) ? this.scale*this.options.docPageFullWidth : this.options.docPageFullWidth;
  1595. //var docPageFullWidth = this.options.docPageFullWidt;
  1596. var pageWidth = count * docPageFullWidth;
  1597. var margin = (w-pageWidth)/(count+1);
  1598. if (this.isScale){
  1599. margin = "10";
  1600. }
  1601. if (this.scale) margin = margin/this.scale;
  1602. this.pages.each(function(page, i){
  1603. page.setStyles({
  1604. "float": "left",
  1605. "margin-left": ""+margin+"px"
  1606. });
  1607. });
  1608. this.resetNodeSize();
  1609. // this.pages.each(function(page){
  1610. // page.setStyle("float", "none");
  1611. // });
  1612. this.resizeSidebar();
  1613. this.options.pageShow="single";
  1614. this.doublePageAction.set("text", MWF.xApplication.process.Xform.LP.doublePage);
  1615. },
  1616. resetNodeSize: function(){
  1617. var contentSize = this.contentNode.getSize();
  1618. var toolbarSize = this.toolNode.getSize();
  1619. contentHeight = contentSize.y;
  1620. var h = contentHeight+toolbarSize.y+20;
  1621. //h = h - contentSize.y*(1-this.scale);
  1622. this.node.setStyles({
  1623. "height":""+h+"px"
  1624. });
  1625. this.resizeSidebar();
  1626. },
  1627. createWaitSplitPage: function(){
  1628. this.node.mask({
  1629. "style": {
  1630. "background-color": "#cccccc",
  1631. "opacity": 0.3
  1632. }
  1633. });
  1634. this.waitSplitPageNode = new Element("div", {"styles": this.form.css.waitSplitPageNode, "text": MWF.xApplication.process.Xform.LP.computePage}).inject(this.node);
  1635. this.waitSplitPageNode.position({
  1636. "relativeTo": this.node,
  1637. "position": "topRight",
  1638. "edge": "topRight",
  1639. "offset": {
  1640. "x": -10,
  1641. "y": 45
  1642. }
  1643. });
  1644. //this.form.notice(MWF.xApplication.process.Xform.LP.computePage, "info", this.node);
  1645. },
  1646. clearWaitSplitPage: function(){
  1647. this.node.unmask();
  1648. if (this.waitSplitPageNode) this.waitSplitPageNode.destroy();
  1649. this.waitSplitPageNode = null;
  1650. },
  1651. _doublePage: function(){
  1652. if (this.editMode) this._switchReadOrEditInline();
  1653. if( this.zoomSelectAction ){
  1654. this.singlePageZoom = ( this.zoomSelectAction.options[this.zoomSelectAction.selectedIndex].value ).toFloat();
  1655. }
  1656. this.zoom(1);
  1657. this.createWaitSplitPage();
  1658. window.setTimeout(function(){
  1659. this._checkSplitPage(this.pages[0]);
  1660. this.zoom(1);
  1661. var w = this.contentNode.getSize().x;
  1662. var toPageWidth = (w-100)/2;
  1663. scale = toPageWidth/this.options.docPageFullWidth;
  1664. if (scale<1) this.zoom(scale);
  1665. var docPageFullWidth = (this.scale) ? this.scale*this.options.docPageFullWidth : this.options.docPageFullWidth;
  1666. //var docPageFullWidth = this.options.docPageFullWidth;
  1667. var w = this.contentNode.getSize().x;
  1668. var count = (w/docPageFullWidth).toInt();
  1669. var pages = this.contentNode.getElements(".doc_layout_page");
  1670. count = Math.min(pages.length, count);
  1671. var pageWidth = count * docPageFullWidth;
  1672. var margin = (w-pageWidth)/(count+1);
  1673. if (this.scale) margin = margin/(this.scale);
  1674. this.pages.each(function(page, i){
  1675. page.setStyles({
  1676. "float": "left",
  1677. "margin-left": ""+margin+"px"
  1678. });
  1679. });
  1680. // this.pages.each(function(page, i){
  1681. // if ((i % 2)===0){
  1682. // page.setStyle("float", "left");
  1683. // }else{
  1684. // page.setStyle("float", "right");
  1685. // }
  1686. // });
  1687. this.resetNodeSize();
  1688. this.options.pageShow="double";
  1689. this.doublePageAction.set("text", MWF.xApplication.process.Xform.LP.singlePage);
  1690. this.resizeSidebar();
  1691. this.clearWaitSplitPage();
  1692. }.bind(this), 1000);
  1693. },
  1694. _getDefaultData: function(){
  1695. return Object.clone(this.json.defaultValue);
  1696. //return Object.clone(MWF.xApplication.process.Xform.LP.documentEditor);
  1697. },
  1698. _loadFiletextPage: function(callback){
  1699. this.data = this._getBusinessData();
  1700. if (!this.data) this.data = this._getDefaultData();
  1701. this._computeData(true);
  1702. this._createPage(function(control){
  1703. this._loadPageLayout(control);
  1704. // this.data = this._getBusinessData();
  1705. // if (!this.data) this.data = this._getDefaultData();
  1706. this.setData(this.data);
  1707. // this._checkSplitPage(this.pages[0]);
  1708. //this._repage(true);
  1709. //this.loadCkeditorFiletext();
  1710. if (!this.readonly){
  1711. //if (this.json.allowEditFiletext!==false) this.loadCkeditorFiletext();
  1712. // if (this.json.allowEditRedheader) this.loadCkeditorRedheader();
  1713. // if (this.json.allowEditSubject) this.loadCkeditorSubject();
  1714. // if (this.json.allowEditMainSend) this.loadCkeditorMainSend();
  1715. // if (this.json.allowEditFileNo) this.loadCkeditorFileNo();
  1716. // if (this.json.allowEditSigner) this.loadCkeditorSigner();
  1717. // if (this.json.allowEditAttachment) this.loadCkeditorAttachment();
  1718. }
  1719. if (callback) callback();
  1720. }.bind(this));
  1721. },
  1722. _getEditorConfig: function(){
  1723. // var mathElements = [
  1724. // 'math',
  1725. // 'maction',
  1726. // 'maligngroup',
  1727. // 'malignmark',
  1728. // 'menclose',
  1729. // 'merror',
  1730. // 'mfenced',
  1731. // 'mfrac',
  1732. // 'mglyph',
  1733. // 'mi',
  1734. // 'mlabeledtr',
  1735. // 'mlongdiv',
  1736. // 'mmultiscripts',
  1737. // 'mn',
  1738. // 'mo',
  1739. // 'mover',
  1740. // 'mpadded',
  1741. // 'mphantom',
  1742. // 'mroot',
  1743. // 'mrow',
  1744. // 'ms',
  1745. // 'mscarries',
  1746. // 'mscarry',
  1747. // 'msgroup',
  1748. // 'msline',
  1749. // 'mspace',
  1750. // 'msqrt',
  1751. // 'msrow',
  1752. // 'mstack',
  1753. // 'mstyle',
  1754. // 'msub',
  1755. // 'msup',
  1756. // 'msubsup',
  1757. // 'mtable',
  1758. // 'mtd',
  1759. // 'mtext',
  1760. // 'mtr',
  1761. // 'munder',
  1762. // 'munderover',
  1763. // 'semantics',
  1764. // 'annotation',
  1765. // 'annotation-xml'
  1766. // ];
  1767. //CKEDITOR.plugins.addExternal('ckeditor_wiris', 'https://ckeditor.com/docs/ckeditor4/4.13.0/examples/assets/plugins/ckeditor_wiris/', 'plugin.js');
  1768. var editorConfig = {
  1769. qtRows: 20, // Count of rows
  1770. qtColumns: 20, // Count of columns
  1771. qtBorder: '1', // Border of inserted table
  1772. qtWidth: '95%', // Width of inserted table
  1773. qtStyle: { 'border-collapse' : 'collapse' },
  1774. qtClass: 'documenteditor_table'+this.form.json.id+this.json.id, // Class of table
  1775. qtCellPadding: '0', // Cell padding table
  1776. qtCellSpacing: '0', // Cell spacing table
  1777. qtPreviewBorder: '4px double black', // preview table border
  1778. qtPreviewSize: '4px', // Preview table cell size
  1779. qtPreviewBackground: '#c8def4', // preview table background (hover)
  1780. // format_tags: '标题一;标题二;标题三;标题四;正文', // entries is displayed in "Paragraph format"
  1781. format_tags: '标题一;标题二;正文(标题三,四)', // entries is displayed in "Paragraph format"
  1782. 'format_标题一': {
  1783. name: '标题一(三号黑体)',
  1784. element: 'div',
  1785. styles: {
  1786. 'font-family': '黑体',
  1787. 'font-size': '16pt'
  1788. }
  1789. },
  1790. 'format_标题二': {
  1791. name: '标题二(三号楷体)',
  1792. element: 'div',
  1793. styles: {
  1794. 'font-family': '楷体',
  1795. 'font-size': '16pt'
  1796. }
  1797. },
  1798. // 'format_标题三': {
  1799. // name: '标题三',
  1800. // element: 'div',
  1801. // styles: {
  1802. // 'font-family': '仿宋',
  1803. // 'font-size': '16pt'
  1804. // }
  1805. // },
  1806. // 'format_标题四': {
  1807. // name: '标题四',
  1808. // element: 'div',
  1809. // styles: {
  1810. // 'font-family': '仿宋',
  1811. // 'font-size': '16pt'
  1812. // }
  1813. // },
  1814. 'format_正文(标题三,四)': {
  1815. name: '正文(标题三,四)',
  1816. element: 'div',
  1817. styles: {
  1818. 'font-family': '仿宋',
  1819. 'font-size': '16pt'
  1820. }
  1821. }
  1822. };
  1823. editorConfig.toolbarGroups = [
  1824. { name: 'document', groups: [ 'mode', 'document', 'doctools' ] },
  1825. { name: 'clipboard', groups: [ 'clipboard', 'undo' ] },
  1826. { name: 'editing', groups: [ 'find', 'selection', 'spellchecker', 'editing' ] },
  1827. { name: 'forms', groups: [ 'forms' ] },
  1828. { name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] },
  1829. { name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align', 'bidi', 'paragraph' ] },
  1830. { name: 'links', groups: [ 'links' ] },
  1831. { name: 'insert', groups: [ 'insert' ] },
  1832. { name: 'styles', groups: [ 'styles' ] },
  1833. { name: 'colors', groups: [ 'colors' ] },
  1834. { name: 'tools', groups: [ 'tools' ] },
  1835. { name: 'others', groups: [ 'others' ] },
  1836. { name: 'about', groups: [ 'about' ] }
  1837. ];
  1838. //editorConfig.extraPlugins = "ecnet,colordialog,tableresize,quicktable,mathjax,ckeditor_wiris";
  1839. //editorConfig.extraPlugins = "ecnet,colordialog,quicktable,tableresize,eqneditor";
  1840. //editorConfig.extraPlugins = "tableresize,quicktable";
  1841. editorConfig.extraPlugins = "quicktable,tableresize";
  1842. //editorConfig.mathJaxLib = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-AMS_HTML',
  1843. 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';
  1844. //editorConfig.extraAllowedContent = mathElements.join(' ') + '(*)[*]{*};img[data-mathml,data-custom-editor,role](Wirisformula)';
  1845. editorConfig.pasteFromWordRemoveFontStyles = false;
  1846. editorConfig.pasteFromWordRemoveStyles = false;
  1847. //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';
  1848. editorConfig.removePlugins = ['magicline'];
  1849. editorConfig.enterMode = 3;
  1850. // editorConfig.extraPlugins = ['ecnet','mathjax'];
  1851. // editorConfig.removePlugins = ['magicline'];
  1852. // editorConfig.mathJaxLib = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-AMS_HTML';
  1853. return editorConfig;
  1854. },
  1855. _checkSplitPage: function(pageNode){
  1856. if (this.layout_edition) this.layout_edition.setStyles({ "position": "static"});
  1857. var contentNode = pageNode.getFirst();
  1858. if (contentNode.getSize().y>this.options.docPageHeight){
  1859. this._splitPage(pageNode);
  1860. }
  1861. var i = pageNode.get("data-pagecount").toInt();
  1862. if (i && this.pages.length-1>=i){
  1863. this._checkSplitPage(this.pages[i]);
  1864. }
  1865. if (this.layout_edition) this.layout_edition.setStyles({ "position": "absolute", "bottom": "0px" });
  1866. },
  1867. _splitFiletextNodeOneWord:function(lnode, nextPageNode){
  1868. var text = lnode.textContent;
  1869. var len = text.length;
  1870. var left = text.substring(0, len-1);
  1871. var right = text.substring(len-1, len);
  1872. lnode.textContent = left;
  1873. nextPageNode.textContent = right+nextPageNode.textContent;
  1874. //nextPageNode.appendText(right, "top");
  1875. },
  1876. _splitFiletext: function(node, nextPageNode, nextFiletextNode, pageNode){
  1877. var contentNode = pageNode.getFirst();
  1878. var lnode = node.lastChild;
  1879. if (!lnode){
  1880. if (node.parentNode) node.parentNode.removeChild(node);
  1881. //node.remove();
  1882. }else{
  1883. while (contentNode.getSize().y>this.options.docPageHeight && lnode) {
  1884. var tmpnode = lnode.previousSibling;
  1885. var nodeType = lnode.nodeType;
  1886. if (!nextPageNode) nextPageNode = nextFiletextNode;
  1887. if (nodeType == Node.ELEMENT_NODE) {
  1888. if (lnode.tagName == "table") {
  1889. lnode.inject(nextPageNode);
  1890. } else if (lnode.tagName == "BR") {
  1891. if (lnode.parentNode) lnode.parentNode.removeChild(lnode);
  1892. } else {
  1893. var id = lnode.get("data-pagePart");
  1894. if (!id){
  1895. id = (new o2.widget.UUID()).toString();
  1896. lnode.set("data-pagePart", id);
  1897. }
  1898. var tmpNode = nextPageNode.getFirst();
  1899. if (tmpNode && tmpNode.get("data-pagePart")==id){
  1900. nextPageNode = tmpNode;
  1901. }else{
  1902. nextPageNode = lnode.clone(false).inject(nextPageNode, "top");
  1903. }
  1904. //var subnode = lnode.getLast();
  1905. this._splitFiletext(lnode, nextPageNode, nextFiletextNode, pageNode);
  1906. if (!lnode.firstChild) if (lnode.parentNode) lnode.parentNode.removeChild(lnode);
  1907. nextPageNode = nextPageNode.getParent();
  1908. }
  1909. } else if (nodeType == Node.TEXT_NODE) {
  1910. var nextPageTextNode = nextPageNode.insertBefore(document.createTextNode(""), nextPageNode.firstChild);
  1911. while ((contentNode.getSize().y > this.options.docPageHeight) && lnode.textContent) {
  1912. //console.log(contentNode.getSize().y);
  1913. this._splitFiletextNodeOneWord(lnode, nextPageTextNode)
  1914. }
  1915. if (!lnode.textContent) if (lnode.parentNode) lnode.parentNode.removeChild(lnode); //lnode.remove();
  1916. } else {
  1917. //lnode.remove();
  1918. if (lnode.parentNode) lnode.parentNode.removeChild(lnode);
  1919. }
  1920. lnode = tmpnode;
  1921. }
  1922. if (!node.lastChild) if (node.parentNode) node.parentNode.removeChild(node); //node.remove();
  1923. }
  1924. //this._checkSplitPage(pageNode);
  1925. },
  1926. _splitPage: function(pageNode){
  1927. var contentNode = pageNode.getFirst();
  1928. var blockNodes = pageNode.getElements(".doc_block");
  1929. if (blockNodes.length){
  1930. var blockNode = blockNodes[blockNodes.length-1];
  1931. var idx = this.pages.indexOf(pageNode);
  1932. if (this.pages.length<=idx+1) this._createNewPage();
  1933. var nextPage = this.pages[idx+1];
  1934. if (blockNode.hasClass("doc_layout_filetext")){
  1935. var filetextNode = nextPage.getElement(".doc_layout_filetext");
  1936. if (!filetextNode){
  1937. filetextNode = new Element("div.doc_layout_filetext").inject(nextPage.getFirst(), "top");
  1938. //filetextNode.setAttribute('contenteditable', true);
  1939. }
  1940. if (!filetextNode.hasClass("doc_block"))filetextNode.addClass("doc_block");
  1941. //var nextEditor = filetextNode.retrieve("editor");
  1942. var node = blockNode;
  1943. var nextPageNode = filetextNode;
  1944. this._splitFiletext(node, nextPageNode, filetextNode, pageNode);
  1945. }else{
  1946. blockNode.inject(nextPage.getFirst(), "top");
  1947. //var contentNode = pageNode.getFirst();
  1948. if (contentNode.getSize().y>this.options.docPageHeight){
  1949. this._splitPage(pageNode);
  1950. }
  1951. }
  1952. }
  1953. },
  1954. transWidth: function(node){
  1955. if (!node) return '';
  1956. while (node){
  1957. if (node.nodeType==3){
  1958. node.nodeValue = node.nodeValue.replace(/\x20/g, " ");
  1959. }else if (node.nodeType==8){
  1960. //nothing
  1961. }else{
  1962. this.transWidth(node.firstChild);
  1963. }
  1964. node = node.nextSibling;
  1965. }
  1966. },
  1967. insertFullWidth: function(node, txt){
  1968. if (!node) return '';
  1969. while (node){
  1970. if (node.nodeType==3){
  1971. node.nodeValue = txt+node.nodeValue;
  1972. return true;
  1973. }else if (node.nodeType==8){
  1974. //nothing
  1975. }else{
  1976. var flag = this.insertFullWidth(node.firstChild, txt);
  1977. if (flag) return true;
  1978. }
  1979. node = node.nextSibling;
  1980. }
  1981. },
  1982. loadCkeditorFiletext: function(callback, inline){
  1983. if (this.layout_filetext){
  1984. o2.load("../o2_lib/htmleditor/ckeditor4130/ckeditor.js", function(){
  1985. CKEDITOR.disableAutoInline = true;
  1986. this.layout_filetext.setAttribute('contenteditable', true);
  1987. if (inline){
  1988. this.filetextEditor = CKEDITOR.inline(this.layout_filetext, this._getEditorConfig());
  1989. }else{
  1990. this.filetextEditor = CKEDITOR.replace(this.layout_filetext, this._getEditorConfig());
  1991. }
  1992. this.filetextEditor.on("instanceReady", function(e){
  1993. if (callback) callback(e);
  1994. }.bind(this));
  1995. this.filetextEditor.on( 'focus', function( e ) {
  1996. window.setTimeout(this.reLocationFiletextToolbar.bind(this), 10);
  1997. }.bind(this) );
  1998. this.filetextEditor.on( 'paste', function( e ) {
  1999. var html = e.data.dataValue;
  2000. //if (this.json.fullWidth=="y") html = html.replace(/\x20/g, " ");
  2001. var tmp = new Element("div")
  2002. tmp.set("html", html);
  2003. var pList = tmp.getElements("p");
  2004. pList.each(function(p, i){
  2005. //if (Browser.name=="ie"){
  2006. if (this.json.fullWidth!=="n") this.transWidth(p);
  2007. if (!p.getParent("table")){
  2008. var text = p.get("text");
  2009. var rex = /^\u3000*/;
  2010. var m = text.match(rex);
  2011. var l = (m[0]) ? Math.max((2-m[0].length), 0): 2;
  2012. var txt = "";
  2013. // for (var i=0; i<l; i++) txt+=" ";
  2014. // this.insertFullWidth(p.getFirst(), txt);
  2015. for (var i=0; i<l; i++) p.appendText(" ","top");
  2016. }
  2017. //}else{
  2018. // var textIndent = p.getStyle("text-indent");
  2019. // if (textIndent.toInt()) p.appendText("  ","top");
  2020. //}
  2021. }.bind(this));
  2022. e.data.dataValue = tmp.get("html");
  2023. tmp.destroy();
  2024. this.fireEvent("paste");
  2025. }.bind(this) );
  2026. this.filetextEditor.on( 'afterPaste', function( e ) {
  2027. this.resetNodeSize();
  2028. this.fireEvent("afterPaste");
  2029. }.bind(this) );
  2030. if (this.json.textIndent!=="n"){
  2031. this.layout_filetext.addEvent("keyup", function(ev){
  2032. if (ev.code==13) this.filetextEditor.insertText("  ");
  2033. }.bind(this));
  2034. }
  2035. if (this.json.fullWidth!=="n"){
  2036. this.filetextEditor.addCommand( 'insertHalfSpace', {
  2037. exec: function( editor ) {
  2038. editor.insertText(" ");
  2039. }
  2040. } );
  2041. this.filetextEditor.setKeystroke( CKEDITOR.SHIFT + 32, 'insertHalfSpace' );
  2042. this.filetextEditor.on("key", function(e){
  2043. if (this.json.fullWidth!=="n") if (e.data.keyCode==32){
  2044. e.editor.insertText(" ");
  2045. e.cancel();
  2046. }
  2047. }.bind(this));
  2048. }
  2049. }.bind(this));
  2050. }
  2051. },
  2052. _loadEvents: function(editorConfig){
  2053. Object.each(this.json.events, function(e, key){
  2054. if (e.code){
  2055. this.editor.on(key, function(event){
  2056. return this.form.Macro.fire(e.code, this, event);
  2057. }.bind(this), this);
  2058. }
  2059. }.bind(this));
  2060. },
  2061. _bindFieldChange: function(name,dataItem, dom){
  2062. var field = this.form.all[this.json[dataItem]];
  2063. if (field){
  2064. var bindFun = function(){
  2065. this._computeItemFieldData(name, dataItem);
  2066. //if (this.data[name]){
  2067. if (this[dom]){
  2068. if (dom=="layout_redHeader" || dom=="layout_subject" || dom=="layout_issuanceUnit" || dom=="layout_meetingAttendContent" || dom=="layout_meetingLeaveContent" || dom=="layout_meetingSitContent" || dom=="layout_meetingRecordContent"){
  2069. this[dom].set("html", this.data[name]|| "");
  2070. }else if (dom=="layout_attachment"){
  2071. this.setAttachmentData();
  2072. }else{
  2073. this[dom].set("text", this.data[name]|| "");
  2074. }
  2075. }
  2076. this.reSetShow();
  2077. //}
  2078. }.bind(this);
  2079. field.node.store(this.json.id+"bindFun", bindFun);
  2080. field.addModuleEvent("change", bindFun);
  2081. }
  2082. },
  2083. _computeItemFieldData: function(name, dataItem, dataItemNode){
  2084. var v = "";
  2085. var module = (dataItemNode) ? this.form.all[dataItemNode] : this.form.all[this.json[dataItem]];
  2086. if (module && module.getData) v = module.getData();
  2087. if (!v) v = (dataItemNode) ? this.form.businessData.data[dataItemNode] : this.form.businessData.data[this.json[dataItem]];
  2088. if (v){
  2089. var t = o2.typeOf(v);
  2090. switch (t) {
  2091. case "string":
  2092. switch (name) {
  2093. case "issuanceDate":
  2094. case "editionDate":
  2095. var d = new Date(v);
  2096. if (d.isValid() && d.getFullYear()!=1970){
  2097. var y = d.getFullYear();
  2098. var m = d.getMonth();
  2099. var day = d.getDate();
  2100. m = m +1;
  2101. this.data[name] = ""+y+"年"+m+"月"+day+"日";
  2102. }else{
  2103. this.data[name] = v;
  2104. }
  2105. //this.data[name] = (new Date(v).isValid()) ? Date.parse(v).format("%Y年%m月%d%日") : v;
  2106. break;
  2107. case "mainSend":
  2108. this.data[name] = v + ":";
  2109. break;
  2110. default:
  2111. this.data[name] = v;
  2112. }
  2113. break;
  2114. case "array":
  2115. var strs = [];
  2116. v.each(function(value){
  2117. if (o2.typeOf(value)=="object" && value.distinguishedName){
  2118. strs.push(value.name);
  2119. }else{
  2120. strs.push(value.toString());
  2121. }
  2122. });
  2123. //if (strs.length){
  2124. switch (name) {
  2125. case "attachment":
  2126. // this.data[name] = strs.map(function(n, i){ var j = i+1; return j+"、"+n}).join("<br>");
  2127. var atts = strs.map(function(a){
  2128. return (a.indexOf(".")!=-1) ? a.substring(0, a.lastIndexOf(".")) : a;
  2129. });
  2130. this.data[name] = atts;
  2131. break;
  2132. case "issuanceDate":
  2133. case "editionDate":
  2134. var tmpStrs = strs.map(function(n, i){
  2135. var d = Date.parse(n);
  2136. if (d.isValid() && d.getFullYear()!=1970){
  2137. var y = d.getFullYear();
  2138. var m = d.getMonth();
  2139. var day = d.getDate();
  2140. m = m +1;
  2141. return ""+y+"年"+m+"月"+day+"日";
  2142. }else{
  2143. return n;
  2144. }
  2145. //return () ? d.format("%Y年%m月%d日") : n;
  2146. });
  2147. this.data[name] = tmpStrs.join(",");
  2148. break;
  2149. case "mainSend":
  2150. this.data[name] = strs.join(",") + ":";
  2151. break;
  2152. default:
  2153. this.data[name] = strs.join(",");
  2154. }
  2155. //}
  2156. break;
  2157. default:
  2158. this.data[name] = v.toString();
  2159. }
  2160. }else{
  2161. this.data[name] = this.json.defaultValue[name];
  2162. }
  2163. },
  2164. computeData: function(){
  2165. this._computeData(false);
  2166. this.setData(this.data);
  2167. },
  2168. _computeItemData: function(name, typeItem, dataItem, scriptItem, ev, dom){
  2169. switch (this.json[typeItem]) {
  2170. case "data":
  2171. if (this.json[dataItem]){
  2172. if (ev) this._bindFieldChange(name, dataItem, dom);
  2173. this._computeItemFieldData(name, dataItem);
  2174. }
  2175. break;
  2176. case "script":
  2177. if (this.json[scriptItem] && this.json[scriptItem].code){
  2178. var v = this.form.Macro.exec(this.json[scriptItem].code, this);
  2179. this.data[name] = v;
  2180. if (name=="attachment"){
  2181. //this.data[name] = (typeOf(v)=="array") ? v.map(function(n, i){ var j = i+1; return j+"、"+n}).join("<br>") : v;
  2182. this.data[name] = (typeOf(v)=="array") ? v : [v];
  2183. }
  2184. if (name=="issuanceDate" || name=="editionDate"){
  2185. var d = Date.parse(v);
  2186. if (d.isValid() && d.getFullYear()!=1970){
  2187. var y = d.getFullYear();
  2188. var m = d.getMonth();
  2189. var day = d.getDate();
  2190. m = m +1;
  2191. this.data[name] = ""+y+"年"+m+"月"+day+"日";
  2192. }else{
  2193. this.data[name] = v;
  2194. }
  2195. //this.data[name] = (d.isValid() && d.getFullYear()!=1970) ? d.format("%Y年%m月%d日") : v;
  2196. }
  2197. }
  2198. break;
  2199. }
  2200. },
  2201. _computeCustomItemData: function(name, field, ev){
  2202. //if (this.json.customFields[l.name]){
  2203. if (ev) this._bindCustomFieldChange(name, field, name);
  2204. this._computeItemFieldData(name, null, field);
  2205. //}
  2206. },
  2207. _bindCustomFieldChange: function(name, dataItem, dom){
  2208. var field = this.form.all[dataItem];
  2209. if (field){
  2210. var bindFun = function(){
  2211. this._computeItemFieldData(name, null, dataItem);
  2212. //if (this.data[name]){
  2213. if (this[dom]){
  2214. if (dom=="layout_redHeader" || dom=="layout_subject" || dom=="layout_issuanceUnit"){
  2215. this[dom].set("html", this.data[name]|| "");
  2216. }else if (dom=="layout_attachment"){
  2217. this.setAttachmentData();
  2218. }else{
  2219. this[dom].set("text", this.data[name]|| "");
  2220. }
  2221. }
  2222. this.reSetShow();
  2223. //}
  2224. }.bind(this);
  2225. field.node.store(this.json.id+"bindFun", bindFun);
  2226. field.addModuleEvent("change", bindFun);
  2227. }
  2228. },
  2229. _computeData: function(ev){
  2230. this._computeItemData("copies", "copiesValueType", "copiesValueData", "copiesValueScript", ev, "layout_copies");
  2231. this._computeItemData("secret", "secretValueType", "secretValueData", "secretValueScript", ev, "layout_secret");
  2232. this._computeItemData("priority", "priorityValueType", "priorityValueData", "priorityValueScript", ev, "layout_priority");
  2233. this._computeItemData("redHeader", "redHeaderValueType", "redHeaderValueData", "redHeaderValueScript", ev, "layout_redHeader");
  2234. this._computeItemData("fileno", "filenoValueType", "filenoValueData", "filenoValueScript", ev, "layout_fileno");
  2235. this._computeItemData("signer", "signerValueType", "signerValueData", "signerValueScript", ev, "layout_signer");
  2236. this._computeItemData("subject", "subjectValueType", "subjectValueData", "subjectValueScript", ev, "layout_subject");
  2237. this._computeItemData("mainSend", "mainSendValueType", "mainSendValueData", "mainSendValueScript", ev, "layout_mainSend");
  2238. this._computeItemData("attachment", "attachmentValueType", "attachmentValueData", "attachmentValueScript", ev, "layout_attachment");
  2239. this._computeItemData("issuanceUnit", "issuanceUnitValueType", "issuanceUnitValueData", "issuanceUnitValueScript", ev, "layout_issuanceUnit");
  2240. this._computeItemData("issuanceDate", "issuanceDateValueType", "issuanceDateValueData", "issuanceDateValueScript", ev, "layout_issuanceDate");
  2241. this._computeItemData("annotation", "annotationValueType", "annotationValueData", "annotationValueScript", ev, "layout_annotation");
  2242. this._computeItemData("copyto", "copytoValueType", "copytoValueData", "copytoValueScript", ev, "layout_copytoContent");
  2243. this._computeItemData("copyto2", "copyto2ValueType", "copyto2ValueData", "copyto2ValueScript", ev, "layout_copyto2Content");
  2244. this._computeItemData("editionUnit", "editionUnitValueType", "editionUnitValueData", "editionUnitValueScript", ev, "layout_edition_issuance_unit");
  2245. this._computeItemData("editionDate", "editionDateValueType", "editionDateValueData", "editionDateValueScript", ev, "layout_edition_issuance_date");
  2246. this._computeItemData("meetingAttend", "meetingAttendValueType", "meetingAttendValueData", "meetingAttendValueScript", ev, "layout_meetingAttendContent");
  2247. this._computeItemData("meetingLeave", "meetingLeaveValueType", "meetingLeaveValueData", "meetingLeaveValueScript", ev, "layout_meetingLeaveContent");
  2248. this._computeItemData("meetingSit", "meetingSitValueType", "meetingSitValueData", "meetingSitValueScript", ev, "layout_meetingSitContent");
  2249. this._computeItemData("meetingRecord", "meetingRecordValueType", "meetingRecordValueData", "meetingRecordValueScript", ev, "layout_meetingRecordContent");
  2250. Object.each(this.json.customFields, function(field, k){
  2251. this._computeCustomItemData(k, field, ev);
  2252. }.bind(this));
  2253. // if (this.customLayouts){
  2254. // this.customLayouts.each(function(l){
  2255. // this._computeCustomItemData(l, ev);
  2256. // }.bind(this))
  2257. // }
  2258. },
  2259. _loadValue: function(){
  2260. var data = this._getBusinessData();
  2261. },
  2262. /**重新计算公文编辑器的所有字段,当字段是脚本时可以使用该方法立即更新
  2263. * @summary 重新计算公文编辑器的所有字段
  2264. * @example
  2265. * this.form.get("fieldName").reload();
  2266. */
  2267. reload: function(){
  2268. this.resetData();
  2269. },
  2270. resetData: function(diffFiletext){
  2271. if (this.editMode){ this._switchReadOrEditInline(); }
  2272. this._computeData(false);
  2273. this.pages = [];
  2274. this.contentNode.empty();
  2275. if (this.allowEdit) this.toolbar.childrenButton[0].setText((layout.mobile) ? MWF.xApplication.process.Xform.LP.editdoc_mobile : MWF.xApplication.process.Xform.LP.editdoc);
  2276. this.editMode = false;
  2277. this._createPage(function(control){
  2278. this._loadPageLayout(control);
  2279. this.setData(this.data, diffFiletext);
  2280. //this._checkSplitPage(this.pages[0]);
  2281. this._repage();
  2282. }.bind(this));
  2283. },
  2284. /**
  2285. * @summary 判断公文编辑器的正文内容是否已经填写
  2286. * @return {Boolean} 是否为空
  2287. * @example
  2288. * if( this.form.get("fieldName").isEmpty() ){
  2289. * this.form.notice('请填写正文内容')
  2290. * }
  2291. */
  2292. isEmpty: function(){
  2293. var data = this.getData();
  2294. if( typeOf(data) !== "object" )return true;
  2295. return !data.filetext || data.filetext===this.json.defaultValue.filetext;
  2296. },
  2297. /*
  2298. * 获取公文编辑器数据
  2299. * @return {Object} 公文编辑器的数据
  2300. * @example
  2301. * var data = this.form.get("fieldName").getData();
  2302. */
  2303. getData: function(){
  2304. //if (this.editMode){
  2305. if (this.layout_copies) this.data.copies = this.layout_copies.get("text");
  2306. if (this.layout_secret) this.data.secret = this.layout_secret.get("text");
  2307. if (this.layout_priority) this.data.priority = this.layout_priority.get("text");
  2308. if (this.layout_redHeader) this.data.redHeader = this.layout_redHeader.get("html");
  2309. if (this.layout_fileno) this.data.fileno = this.layout_fileno.get("text");
  2310. if (this.layout_signerTitle) this.data.signerTitle = this.layout_signerTitle.get("text");
  2311. if (this.layout_signer) this.data.signer = this.layout_signer.get("text");
  2312. if (this.layout_subject) this.data.subject = this.layout_subject.get("html");
  2313. if (this.layout_mainSend) this.data.mainSend = this.layout_mainSend.get("text");
  2314. if (this.editMode) if (this.layout_filetext){
  2315. var text = this.layout_filetext.get("text");
  2316. text = text.replace(/\u3000*/g, "");
  2317. if (text && text !==this.json.defaultValue.filetext){
  2318. this.data.filetext = this.layout_filetext.get("html");
  2319. }else{
  2320. this.data.filetext = "";
  2321. }
  2322. }
  2323. if (this.layout_signer) this.data.signer = this.layout_signer.get("text");
  2324. if (this.layout_attachmentTitle) this.data.attachmentTitle = this.layout_attachmentTitle.get("text");
  2325. if (this.layout_attachment){
  2326. this._computeItemData("attachment", "attachmentValueType", "attachmentValueData", "attachmentValueScript", false, "layout_attachment");
  2327. // var atts = [];
  2328. // var nodes = this.layout_attachment.getElements(".doc_layout_attachment_content_name");
  2329. // if (nodes.length){
  2330. // nodes.each(function(node){
  2331. // atts.push(node.get("text"));
  2332. // });
  2333. // }
  2334. // this.data.attachment = atts;
  2335. }
  2336. if (this.layout_issuanceUnit) this.data.issuanceUnit = this.layout_issuanceUnit.get("html");
  2337. if (this.layout_issuanceDate) this.data.issuanceDate = this.layout_issuanceDate.get("text");
  2338. if (this.layout_annotation) this.data.annotation = this.layout_annotation.get("text");
  2339. if (this.layout_copytoTitle) this.data.copytoTitle = this.layout_copytoTitle.get("text");
  2340. if (this.layout_copytoContent) this.data.copyto = this.layout_copytoContent.get("text");
  2341. if (this.layout_copyto2Title) this.data.copyto2Title = this.layout_copyto2Title.get("text");
  2342. if (this.layout_copyto2Content) this.data.copyto2 = this.layout_copyto2Content.get("text");
  2343. if (this.layout_edition_issuance_unit) this.data.editionUnit = this.layout_edition_issuance_unit.get("text");
  2344. if (this.layout_edition_issuance_date) this.data.editionDate = this.layout_edition_issuance_date.get("text");
  2345. if (this.layout_meetingAttendTitle) this.data.meetingAttendTitle = this.layout_meetingAttendTitle.get("text");
  2346. if (this.layout_meetingLeaveTitle) this.data.meetingLeaveTitle = this.layout_meetingLeaveTitle.get("text");
  2347. if (this.layout_meetingSitTitle) this.data.meetingSitTitle = this.layout_meetingSitTitle.get("text");
  2348. if (this.layout_meetingAttendContent) this.data.meetingAttend = this.layout_meetingAttendContent.get("html");
  2349. if (this.layout_meetingLeaveContent) this.data.meetingLeave = this.layout_meetingLeaveContent.get("html");
  2350. if (this.layout_meetingSitContent) this.data.meetingSit = this.layout_meetingSitContent.get("html");
  2351. if (this.layout_meetingRecordContent) this.data.meetingRecord = this.layout_meetingRecordContent.get("html");
  2352. if (this.customLayouts){
  2353. this.customLayouts.each(function(l){
  2354. this.data[l.name] = l.node.get("html");
  2355. }.bind(this))
  2356. }
  2357. //}
  2358. return this.data;
  2359. },
  2360. setAttachmentData: function(){
  2361. if (!this.attachmentTemplete){
  2362. this.attachmentTemplete = this.layout_attachment.get("html");
  2363. }
  2364. this.layout_attachment.empty();
  2365. if (this.data.attachment && this.data.attachment.length && this.data.attachment.each){
  2366. //var tmpdiv = new Element("div", {"styles": {"display":"none"}}).inject(document.body);
  2367. var tmpdiv = new Element("div");
  2368. this.data.attachment.each(function(name, idx){
  2369. tmpdiv.set("html", this.attachmentTemplete);
  2370. var serialNode = tmpdiv.getElement(".doc_layout_attachment_content_serial");
  2371. var nameNode = tmpdiv.getElement(".doc_layout_attachment_content_name");
  2372. if (serialNode) serialNode.set("text", idx+1);
  2373. if (nameNode) nameNode.set("text", name);
  2374. var html = tmpdiv.get("html");
  2375. tmpdiv.empty();
  2376. this.layout_attachment.appendHTML(html);
  2377. }.bind(this));
  2378. tmpdiv.destroy();
  2379. }
  2380. },
  2381. /**设置公文编辑器数据
  2382. * @param data{Object}
  2383. * @example
  2384. * var data = this.form.get("fieldName").getData();
  2385. * data.filetext = "测试内容";
  2386. * this.form.get("fieldName").getData(data);
  2387. */
  2388. setData: function(data, diffFiletext){
  2389. if (data){
  2390. this.data = data;
  2391. // this.data["$json"] = this.json;
  2392. this._setBusinessData(data);
  2393. if (this.layout_copies){
  2394. if (data.copies){
  2395. this.layout_copies.set("text", data.copies || " ");
  2396. }else{
  2397. this.layout_copies.set("html", "<span>&nbsp</span>");
  2398. }
  2399. }
  2400. if (this.layout_secret){
  2401. if (data.secret){
  2402. this.layout_secret.set("text", data.secret || " ");
  2403. }else{
  2404. this.layout_secret.set("html", "<span>&nbsp</span>");
  2405. }
  2406. }
  2407. if (this.layout_priority){
  2408. if (data.priority){
  2409. this.layout_priority.set("text", data.priority || " ");
  2410. }else{
  2411. this.layout_priority.set("html", "<span>&nbsp</span>");
  2412. }
  2413. }
  2414. if (this.layout_redHeader) this.layout_redHeader.set("html", data.redHeader || "");
  2415. if (this.layout_fileno) this.layout_fileno.set("text", data.fileno || " ");
  2416. if (this.layout_signerTitle) this.layout_signerTitle.set("text", data.signerTitle || " ");
  2417. if (this.layout_signer) this.layout_signer.set("text", data.signer || " ");
  2418. if (this.layout_subject) this.layout_subject.set("html", data.subject || " ");
  2419. if (this.layout_mainSend) this.layout_mainSend.set("text", data.mainSend || " ");
  2420. if (diffFiletext) {
  2421. this.layout_filetext.set("html", diffFiletext);
  2422. }else if (this.layout_filetext){
  2423. //this.layout_filetext.set("placeholder", this.json.defaultValue.filetext);
  2424. this.layout_filetext.set("html", data.filetext || "  ");
  2425. }
  2426. if (this.layout_signer) this.layout_signer.set("text", data.signer || "");
  2427. if (this.layout_attachmentTitle) this.layout_attachmentTitle.set("text", data.attachmentTitle || " ");
  2428. if (this.layout_attachment){
  2429. this.setAttachmentData();
  2430. }
  2431. if (this.layout_issuanceUnit) this.layout_issuanceUnit.set("html", data.issuanceUnit || " ");
  2432. if (this.layout_issuanceDate) this.layout_issuanceDate.set("text", data.issuanceDate || " ");
  2433. if (this.layout_annotation) this.layout_annotation.set("text", data.annotation || " ");
  2434. if (this.layout_copytoTitle) this.layout_copytoTitle.set("text", data.copytoTitle || " ");
  2435. if (this.layout_copytoContent) this.layout_copytoContent.set("text", data.copyto || " ");
  2436. if (this.layout_copyto2Title) this.layout_copyto2Title.set("text", data.copyto2Title || " ");
  2437. if (this.layout_copyto2Content) this.layout_copyto2Content.set("text", data.copyto2 || " ");
  2438. if (this.layout_edition_issuance_unit) this.layout_edition_issuance_unit.set("text", data.editionUnit || " ");
  2439. if (this.layout_edition_issuance_date) this.layout_edition_issuance_date.set("text", data.editionDate || " ");
  2440. if (this.layout_meetingAttendTitle) this.layout_meetingAttendTitle.set("text", data.meetingAttendTitle || this.json.defaultValue.meetingAttendTitle || " ");
  2441. if (this.layout_meetingLeaveTitle) this.layout_meetingLeaveTitle.set("text", data.meetingLeaveTitle || this.json.defaultValue.meetingLeaveTitle || " ");
  2442. if (this.layout_meetingSitTitle) this.layout_meetingSitTitle.set("text", data.meetingSitTitle || this.json.defaultValue.meetingSitTitle || " ");
  2443. if (this.layout_meetingAttendContent) this.layout_meetingAttendContent.set("html", data.meetingAttend || " ");
  2444. if (this.layout_meetingLeaveContent) this.layout_meetingLeaveContent.set("html", data.meetingLeave || " ");
  2445. if (this.layout_meetingSitContent) this.layout_meetingSitContent.set("html", data.meetingSit || " ");
  2446. if (this.layout_meetingRecordContent) this.layout_meetingRecordContent.set("html", data.meetingRecord || " ");
  2447. if (this.customLayouts){
  2448. this.customLayouts.each(function(l){
  2449. l.node.set("html", this.data[l.name] || " ");
  2450. }.bind(this))
  2451. }
  2452. if (this.layout_issuanceUnit && this.layout_issuanceDate ){
  2453. var table = this.layout_issuanceUnit.getParent("table")
  2454. if (table && !table.hasClass("doc_layout_headIssuance")){
  2455. var unitWidth = o2.getTextSize(this.layout_issuanceUnit.get("text"), {
  2456. "font-size":"16pt",
  2457. "font-family":"'Times New Roman',仿宋",
  2458. "letter-spacing": "-0.4pt"
  2459. }).x;
  2460. var dateWidth = o2.getTextSize(this.layout_issuanceDate.get("text"), {
  2461. "font-size":"16pt",
  2462. "font-family":"'Times New Roman',仿宋",
  2463. "letter-spacing": "-0.4pt"
  2464. }).x;
  2465. // var unitWidth = this.layout_issuanceUnit.getSize().x;
  2466. // var dateWidth = this.layout_issuanceDate.getSize().x;
  2467. if (unitWidth<dateWidth){
  2468. var flagTd = this.layout_issuanceUnit.getParent("td").getNext("td");
  2469. if (flagTd){
  2470. var pt = ((dateWidth-unitWidth)/96)*72 +32+32;
  2471. flagTd.setStyle("width", ""+pt+"pt");
  2472. }
  2473. table = this.layout_issuanceDate.getParent("table");
  2474. table.setStyle("width", "auto");
  2475. flagTd = this.layout_issuanceDate.getParent("td").getNext("td");
  2476. if (flagTd) flagTd.setStyle("width", "32pt");
  2477. var p = this.layout_issuanceDate.getParent("p");
  2478. if (p) p.setStyle("text-align", "right");
  2479. }else{
  2480. var flagTd = this.layout_issuanceUnit.getParent("td").getNext("td");
  2481. if (flagTd) flagTd.setStyle("width", "32pt");
  2482. var table = this.layout_issuanceUnit.getParent("table");
  2483. var x = table.getSize().x;
  2484. table = this.layout_issuanceDate.getParent("table");
  2485. table.setStyle("width", ""+x+"px");
  2486. flagTd = this.layout_issuanceDate.getParent("td").getNext("td");
  2487. if (flagTd) flagTd.setStyle("width", "32pt");
  2488. var p = this.layout_issuanceDate.getParent("p");
  2489. if (p) p.setStyle("text-align", "center");
  2490. }
  2491. }
  2492. }
  2493. var coptyToTitleNode = (this.layout_copytoTitle || this.layout_copyto2Title);
  2494. if (coptyToTitleNode){
  2495. var editionTable = coptyToTitleNode.getParent("table");
  2496. if (editionTable) if (editionTable.get("data-compute-style")=="y"){
  2497. var rows = editionTable.rows;
  2498. for (var i=0; i<rows.length; i++){
  2499. var cell = rows[i].cells[0];
  2500. var tmp = cell.getElement(".doc_layout_edition_issuance_unit");
  2501. if (!tmp) tmp = cell.getElement(".doc_layout_edition_issuance_date");
  2502. if (!tmp){
  2503. var text = cell.get("text").trim();
  2504. var l = 14*text.length;
  2505. var wl = 19*text.length;
  2506. cell.setStyles({
  2507. "max-width": ""+l+"pt !important",
  2508. "min-width": ""+l+"pt !important",
  2509. "width": ""+wl+"pt"
  2510. });
  2511. }
  2512. }
  2513. }
  2514. }
  2515. }
  2516. },
  2517. createErrorNode: function(text){
  2518. var node = new Element("div");
  2519. var iconNode = new Element("div", {
  2520. "styles": {
  2521. "width": "20px",
  2522. "height": "20px",
  2523. "float": "left",
  2524. "background": "url("+"../x_component_process_Xform/$Form/default/icon/error.png) center center no-repeat"
  2525. }
  2526. }).inject(node);
  2527. var textNode = new Element("div", {
  2528. "styles": {
  2529. "line-height": "20px",
  2530. "margin-left": "20px",
  2531. "color": "red",
  2532. "word-break": "keep-all"
  2533. },
  2534. "text": text
  2535. }).inject(node);
  2536. return node;
  2537. },
  2538. notValidationMode: function(text){
  2539. if (!this.isNotValidationMode){
  2540. this.isNotValidationMode = true;
  2541. this.node.store("borderStyle", this.node.getStyles("border-left", "border-right", "border-top", "border-bottom"));
  2542. this.node.setStyle("border", "1px solid red");
  2543. this.errNode = this.createErrorNode(text).inject(this.node, "after");
  2544. this.showNotValidationMode(this.node);
  2545. }
  2546. },
  2547. showNotValidationMode: function(node){
  2548. var p = node.getParent("div");
  2549. if (p){
  2550. if (p.get("MWFtype") == "tab$Content"){
  2551. if (p.getParent("div").getStyle("display")=="none"){
  2552. var contentAreaNode = p.getParent("div").getParent("div");
  2553. var tabAreaNode = contentAreaNode.getPrevious("div");
  2554. var idx = contentAreaNode.getChildren().indexOf(p.getParent("div"));
  2555. var tabNode = tabAreaNode.getLast().getFirst().getChildren()[idx];
  2556. tabNode.click();
  2557. p = tabAreaNode.getParent("div");
  2558. }
  2559. }
  2560. this.showNotValidationMode(p);
  2561. }
  2562. },
  2563. validationMode: function(){
  2564. if (this.isNotValidationMode){
  2565. this.isNotValidationMode = false;
  2566. this.node.setStyles(this.node.retrieve("borderStyle"));
  2567. if (this.errNode){
  2568. this.errNode.destroy();
  2569. this.errNode = null;
  2570. }
  2571. }
  2572. },
  2573. validationConfigItem: function(routeName, data){
  2574. var flag = (data.status=="all") ? true: (routeName == data.decision);
  2575. if (flag){
  2576. var n = this.getData();
  2577. var v = (data.valueType=="value") ? n : n.length;
  2578. switch (data.operateor){
  2579. case "isnull":
  2580. if (!v){
  2581. this.notValidationMode(data.prompt);
  2582. return false;
  2583. }
  2584. break;
  2585. case "notnull":
  2586. if (v){
  2587. this.notValidationMode(data.prompt);
  2588. return false;
  2589. }
  2590. break;
  2591. case "gt":
  2592. if (v>data.value){
  2593. this.notValidationMode(data.prompt);
  2594. return false;
  2595. }
  2596. break;
  2597. case "lt":
  2598. if (v<data.value){
  2599. this.notValidationMode(data.prompt);
  2600. return false;
  2601. }
  2602. break;
  2603. case "equal":
  2604. if (v==data.value){
  2605. this.notValidationMode(data.prompt);
  2606. return false;
  2607. }
  2608. break;
  2609. case "neq":
  2610. if (v!=data.value){
  2611. this.notValidationMode(data.prompt);
  2612. return false;
  2613. }
  2614. break;
  2615. case "contain":
  2616. if (v.indexOf(data.value)!=-1){
  2617. this.notValidationMode(data.prompt);
  2618. return false;
  2619. }
  2620. break;
  2621. case "notcontain":
  2622. if (v.indexOf(data.value)==-1){
  2623. this.notValidationMode(data.prompt);
  2624. return false;
  2625. }
  2626. break;
  2627. }
  2628. }
  2629. return true;
  2630. },
  2631. validationConfig: function(routeName, opinion){
  2632. if (this.json.validationConfig){
  2633. if (this.json.validationConfig.length){
  2634. for (var i=0; i<this.json.validationConfig.length; i++) {
  2635. var data = this.json.validationConfig[i];
  2636. if (!this.validationConfigItem(routeName, data)) return false;
  2637. }
  2638. }
  2639. return true;
  2640. }
  2641. return true;
  2642. },
  2643. /**
  2644. * @summary 根据组件的校验设置进行校验。
  2645. * @param {String} [routeName] - 可选,路由名称.
  2646. * @example
  2647. * if( !this.form.get('fieldName').validation() ){
  2648. * return false;
  2649. * }
  2650. * @return {Boolean} 是否通过校验
  2651. */
  2652. validation: function(routeName, opinion){
  2653. if (!this.validationConfig(routeName, opinion)) return false;
  2654. if (!this.json.validation) return true;
  2655. if (!this.json.validation.code) return true;
  2656. this.currentRouteName = routeName;
  2657. var flag = this.form.Macro.exec(this.json.validation.code, this);
  2658. this.currentRouteName = "";
  2659. if (!flag) flag = MWF.xApplication.process.Xform.LP.notValidation;
  2660. if (flag.toString()!="true"){
  2661. this.notValidationMode(flag);
  2662. return false;
  2663. }
  2664. return true;
  2665. },
  2666. removeDisplayNone: function(node){
  2667. var n = node.getFirst();
  2668. while (n){
  2669. if (n.getStyle("display")=="none"){
  2670. var tmp = n.getNext();
  2671. n.destroy();
  2672. n = tmp;
  2673. }else{
  2674. n = this.removeDisplayNone(n);
  2675. n = n.getNext();
  2676. }
  2677. }
  2678. return node;
  2679. },
  2680. /**将公文编辑器内容以html形式输出
  2681. * @return {String}
  2682. * @example
  2683. * var html = this.form.get("fieldName").getDocumentHtml();
  2684. */
  2685. getDocumentHtml: function(){
  2686. var tmpNode = this.contentNode.getFirst().getFirst().clone(true);
  2687. var htmlNode = tmpNode.getLast();
  2688. htmlNode = this.removeDisplayNone(htmlNode);
  2689. var nodes = tmpNode.querySelectorAll("[data-w-style]");
  2690. if (nodes.length){
  2691. for (var i=0; i<nodes.length; i++){
  2692. var n = nodes.item(i);
  2693. wStyle = n.dataset["wStyle"];
  2694. var styles = wStyle.split(/\s*\;\s*/g);
  2695. styles.each(function(style){
  2696. if (style){
  2697. try{
  2698. s = style.split(/\s*\:\s*/g);
  2699. n.setStyle(s[0], s[1]);
  2700. }catch(e) {}
  2701. }
  2702. });
  2703. }
  2704. }
  2705. var htmlStr = tmpNode.get("html");
  2706. tmpNode.destroy();
  2707. return "<html xmlns:v=\"urn:schemas-microsoft-com:vml\"><head><meta charset=\"UTF-8\" /></head><body>"+htmlStr+"</body></html>";
  2708. },
  2709. /**
  2710. * @summary 将公文编辑器转换成附件,转换的文件名和格式等信息与配置有关
  2711. * @param {Function} [callback] 转换后的回调方法,参数是附件数据.
  2712. * @param {string} [name] - 如果为空或者不传,转换的文件名和格式等信息与配置有关.
  2713. * @example
  2714. * this.form.get("fieldName").toWord( function(attachmentData){
  2715. * //attachmentData 转换后的附件数据
  2716. * })
  2717. */
  2718. toWord: function(callback, name){
  2719. var docNmae = name || "";
  2720. if (!docNmae){
  2721. try{
  2722. docNmae = this.json.toWordFilename || this.form.businessData.data.subject || this.form.businessData.data["$work"].title
  2723. }catch (e) {}
  2724. }
  2725. var toEdit = false;
  2726. if (this.editMode){
  2727. toEdit = true;
  2728. this._readFiletext();
  2729. }
  2730. //this._returnScale();
  2731. this.zoom(1);
  2732. this.pages = [];
  2733. this.contentNode.empty();
  2734. this._createPage(function(control){
  2735. this._loadPageLayout(control);
  2736. this.setData(this.data);
  2737. this._checkScale();
  2738. this.node.setStyles({
  2739. "height":"auto"
  2740. });
  2741. //var content = this.contentNode.getFirst().getFirst().get("html");
  2742. // var tmpNode = this.contentNode.getFirst().getFirst().clone(true);
  2743. // var htmlNode = tmpNode.getLast();
  2744. // htmlNode = this.removeDisplayNone(htmlNode);
  2745. // var nodes = tmpNode.querySelectorAll("[data-w-style]");
  2746. // if (nodes.length){
  2747. // for (var i=0; i<nodes.length; i++){
  2748. // var n = nodes.item(i);
  2749. // wStyle = n.dataset["wStyle"];
  2750. // var styles = wStyle.split(/\s*\;\s*/g);
  2751. // styles.each(function(style){
  2752. // if (style){
  2753. // try{
  2754. // s = style.split(/\s*\:\s*/g);
  2755. // n.setStyle(s[0], s[1]);
  2756. // }catch(e) {}
  2757. // }
  2758. // });
  2759. // }
  2760. // }
  2761. var content = this.getDocumentHtml();
  2762. //var content = "<html xmlns:v=\"urn:schemas-microsoft-com:vml\"><head><meta charset=\"UTF-8\" /></head><body>"+tmpNode.get("html")+"</body></html>";
  2763. var fileName = docNmae || this.json.toWordFilename || "$doc";
  2764. var n = fileName.lastIndexOf(".");
  2765. if (n==-1) fileName = fileName+".doc";
  2766. // var ex = fileName.substring(n, fileName.length).toLowerCase();
  2767. // if (ex!==".doc" && ex!==".docx") fileName = fileName+".doc";
  2768. var body = {
  2769. "fileName": fileName,
  2770. "site": this.json.toWordSite || "$doc",
  2771. "content": content
  2772. };
  2773. o2.Actions.get("x_processplatform_assemble_surface").docToWord(this.form.businessData.work.id, body, function(json){
  2774. if (this.form.businessData.workCompleted){
  2775. o2.Actions.get("x_processplatform_assemble_surface").getAttachmentWorkcompleted(json.data.id, this.form.businessData.workCompleted.id,function(attjson){
  2776. if (callback) callback(attjson.data);
  2777. this.showToWord(attjson.data);
  2778. }.bind(this));
  2779. }else{
  2780. o2.Actions.get("x_processplatform_assemble_surface").getAttachment(json.data.id, this.form.businessData.work.id,function(attjson){
  2781. if (callback) callback(attjson.data);
  2782. this.showToWord(attjson.data);
  2783. }.bind(this));
  2784. }
  2785. }.bind(this));
  2786. //tmpNode.destroy();
  2787. if (!toEdit){
  2788. this._readFiletext();
  2789. }else{
  2790. this._createEditor("inline");
  2791. }
  2792. }.bind(this));
  2793. },
  2794. docToWord: function(){
  2795. var flag = true;
  2796. if (this.json.toWordConditionScript && this.json.toWordConditionScript.code){
  2797. flag = !!this.form.Macro.exec(this.json.toWordConditionScript.code, this);
  2798. }
  2799. if (flag){
  2800. this.toWord();
  2801. }
  2802. },
  2803. showToWord: function(att_word){
  2804. var site = this.json.toWordSite || "$doc";
  2805. var attModule = this.form.all[site];
  2806. if (attModule){
  2807. var atts = [];
  2808. attModule.attachmentController.attachments.each(function(att){
  2809. if (att.data.name!==att_word.name){
  2810. atts.push(att.data)
  2811. }
  2812. }.bind(this));
  2813. attModule.attachmentController.clear();
  2814. atts.each(function (att) {
  2815. //if (att.site===this.json.id || (this.json.isOpenInOffice && this.json.officeControlName===att.site)) this.attachmentController.addAttachment(att);
  2816. if ((att.site === attModule.json.id) && att.name!==att_word.name) attModule.attachmentController.addAttachment(att);
  2817. }.bind(this));
  2818. // attModule.attachmentController.reloadAttachments();
  2819. attModule.attachmentController.addAttachment(att_word);
  2820. }
  2821. }
  2822. });