Documenteditor.js 122 KB

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