Documenteditor.js 128 KB

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