Documenteditor.js 136 KB

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