Documenteditor.js 127 KB

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