Documenteditor.js 122 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654
  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. cell.setStyles({
  636. "max-width": ""+l+"pt",
  637. "min-width": ""+l+"pt"
  638. });
  639. }
  640. }
  641. }
  642. }
  643. if (this.layout_editionArea) this.layout_editionArea.show();
  644. if (this.layout_copytoTitle) this.layout_copytoTitle[m("copyto")]();
  645. if (this.layout_copytoContent) this.layout_copytoContent[m("copyto")]();
  646. if (this.layout_copyto2Title) this.layout_copyto2Title[m("copyto2")]();
  647. if (this.layout_copyto2Content) this.layout_copyto2Content[m("copyto2")]();
  648. if (this.layout_edition_issuance_unit) this.layout_edition_issuance_unit[m("editionUnit")]();
  649. if (this.layout_edition_issuance_date) this.layout_edition_issuance_date[m("editionDate")]();
  650. }
  651. if (this.layout_meetingAttendArea) this.layout_meetingAttendArea[m("meetingAttend")]();
  652. if (this.layout_meetingLeaveArea) this.layout_meetingLeaveArea[m("meetingLeave")]();
  653. if (this.layout_meetingSitArea) this.layout_meetingSitArea[m("meetingSit")]();
  654. if (this.layout_meetingRecordArea) this.layout_meetingRecordArea[m("meetingRecord")]();
  655. // this.layout_annotation[m("annotation")]();
  656. // this.layout_annotation[m("annotation")]();
  657. // this.layout_annotation[m("annotation")]();
  658. },
  659. reSetEdit: function(control){
  660. //未进行数据绑定时,可允许编辑
  661. if (!control) var control = this.getEditControl();
  662. if (this.layout_subject){
  663. if (!this.json.subjectValueData && this.json.subjectValueType=="data"){
  664. this.layout_subject.set("contenteditable", control.subject);
  665. this.layout_subject.addEvent("blur", function(){
  666. this.getData();
  667. }.bind(this))
  668. }
  669. }
  670. if (this.layout_issuanceUnit){
  671. if (!this.json.issuanceUnitValueData && this.json.issuanceUnitValueType=="data"){
  672. this.layout_issuanceUnit.set("contenteditable", control.issuanceUnit);
  673. this.layout_issuanceUnit.addEvent("blur", function(){
  674. this.getData();
  675. }.bind(this))
  676. }
  677. }
  678. // this.layout_subject.addEvent("keydown", function(e){
  679. // debugger;
  680. // if (this.json.subjectValueType=="data" && this.json.subjectValueData){
  681. // // var v = e.target.get("HTML");
  682. // // this.form.businessData.data[this.json.subjectValueData] = v
  683. // var module = this.form.all[this.json.subjectValueData];
  684. // if (module){
  685. // var bindFun = module.node.retrieve(this.json.id+"bindFun");
  686. // module.node
  687. // }
  688. // }
  689. // }.bind(this));
  690. },
  691. _loadUserInterface: function(callback){
  692. this.node.empty();
  693. this.node.setStyles(this.form.css.documentEditorNode);
  694. this.pages = [];
  695. this.allowEdit = this._isAllowEdit();
  696. this.allowPrint = this._isAllowPrint();
  697. this.allowHistory = this._isAllowHistory();
  698. this.toolNode = new Element("div", {"styles": this.css.doc_toolbar}).inject(this.node);
  699. this.contentNode = new Element("div", {"styles": this.css.doc_content}).inject(this.node);
  700. if (!this.form.isLoaded){
  701. this.form.addEvent("afterModulesLoad", function(){this.loadDocumentEditor(callback);}.bind(this));
  702. }else{
  703. this.loadDocumentEditor(callback);
  704. }
  705. },
  706. loadDocumentEditor: function(callback){
  707. this._loadToolbars();
  708. this._loadFiletextPage(function(){
  709. if (this.options.pageShow!=="double"){
  710. this._singlePage();
  711. }else{
  712. this._doublePage();
  713. }
  714. // this.form.addEvent("beforeProcess", function(){
  715. // this.resetData();
  716. // if (this.checkSaveNewEdition()) this.saveNewDataEdition();
  717. // this.notSaveResetData = true;
  718. // }.bind(this));
  719. this.form.addEvent("beforeSave", function(){
  720. this.resetData();
  721. this.checkSaveNewEdition();
  722. //if (!this.notSaveResetData) this.resetData();
  723. }.bind(this));
  724. if (this.json.toWord=="y"){
  725. if (this.json.toWordTrigger=="open") this.docToWord();
  726. if (this.json.toWordTrigger=="save") this.form.addEvent("beforeSave", this.docToWord.bind(this));
  727. if (this.json.toWordTrigger=="submit") this.form.addEvent("beforeProcess", this.docToWord.bind(this));
  728. }
  729. if (!layout.mobile) this.loadSideToolbar();
  730. o2.load("../o2_lib/diff-match-patch/diff_match_patch.js");
  731. if (this.form.businessData.data["$work"]){
  732. var id = this.form.businessData.data["$work"].job;
  733. o2.Actions.load("x_processplatform_assemble_surface").DocumentVersionAction.listWithJobCategory(id, this.json.id, function(json){
  734. this.historyDocumentList = json.data;
  735. if (this.historyDocumentList.length){
  736. o2.Actions.load("x_processplatform_assemble_surface").DocumentVersionAction.get(this.historyDocumentList[this.historyDocumentList.length-1].id, function(json){
  737. var data = JSON.parse(json.data.data);
  738. this.originaHistoryData = data.data;
  739. }.bind(this));
  740. }
  741. }.bind(this));
  742. }
  743. if (callback) callback();
  744. }.bind(this));
  745. if (!this.form.documenteditorList) this.form.documenteditorList=[];
  746. this.form.documenteditorList.push(this);
  747. },
  748. checkSaveNewEdition: function(callback){
  749. debugger;
  750. if (!this.allowEdit || !this.data.filetext || this.data.filetext == this.json.defaultValue.filetext) return false;
  751. if (this.form.businessData.work){
  752. var originaData = this.form.businessData.originalData[this.json.id];
  753. var editionData = {"category": this.json.id};
  754. if (!originaData || !originaData.filetext || !this.originaHistoryData){
  755. //保存原始版本
  756. this.originaHistoryData = {"data": this.data.filetext};
  757. editionData.data = JSON.stringify({"data": this.data.filetext});
  758. }else if (originaData.filetext!=this.data.filetext){
  759. //保存历史版本
  760. var data = this.data.filetext;
  761. var earlyData = originaData.filetext;
  762. var dmp = new diff_match_patch();
  763. var diff_d = dmp.diff_main(earlyData, data);
  764. dmp.diff_cleanupSemantic(diff_d);
  765. var patch_list = dmp.patch_make(earlyData, data, diff_d);
  766. editionData.data = JSON.stringify({"patchs": dmp.patch_toText(patch_list)});
  767. }else{
  768. return false;
  769. }
  770. o2.Actions.load("x_processplatform_assemble_surface").DocumentVersionAction.create(this.form.businessData.work.id, editionData, function(json){
  771. //originaData.filetext = this.data.filetext;
  772. if (callback) callback();
  773. }.bind(this));
  774. }
  775. },
  776. // saveNewDataEdition: function(callback){
  777. // if (this.form.businessData.work){
  778. // var editionData = {"category": this.json.id};
  779. // if (this.form.businessData.originalData[this.json.id] && this.form.businessData.originalData[this.json.id].filetext){
  780. // var data = this.data.filetext;
  781. // var earlyData = this.form.businessData.originalData[this.json.id].filetext;
  782. // var dmp = new diff_match_patch();
  783. // var diff_d = dmp.diff_main(earlyData, data);
  784. // dmp.diff_cleanupSemantic(diff_d);
  785. // var patch_list = dmp.patch_make(earlyData, data, diff_d);
  786. // editionData.data = {"patchs": dmp.patch_toText(patch_list)};
  787. //
  788. // }else{
  789. // editionData.data = {"data": this.data.filetext};
  790. // }
  791. // o2.Actions.load("x_processplatform_assemble_surface").DocumentVersionAction.create(this.form.businessData.work.id, editionData, function(json){
  792. // this.form.businessData.originalData[this.json.id] = this.data.filetext;
  793. // if (callback) callback();
  794. // }.bind(this));
  795. // }
  796. // },
  797. resizeToolbar: function(){
  798. if (this.toolbarNode){
  799. var p = this.toolNode.getPosition(this.scrollNode);
  800. var size = this.toolNode.getSize();
  801. var pl = this.toolbarNode.getStyle("padding-left").toInt();
  802. var pr = this.toolbarNode.getStyle("padding-right").toInt();
  803. var x = size.x-pl-pr;
  804. //var pNode = this.toolNode.getOffsetParent();
  805. var paddingTop = this.form.node.getStyle("padding-top");
  806. try {
  807. paddingTop = paddingTop.toInt();
  808. }catch (e) {
  809. paddingTop = 0;
  810. }
  811. if (p.y<paddingTop){
  812. this.toolbarNode.inject(this.scrollNode);
  813. this.toolbarNode.setStyles({
  814. "position": "absolute",
  815. "width": ""+x+"px",
  816. "z-index": 200,
  817. "top": paddingTop+"px",
  818. "left": ""+p.x+"px"
  819. });
  820. }else{
  821. this.toolbarNode.inject(this.toolNode);
  822. this.toolbarNode.setStyles({"position": "static"});
  823. }
  824. }
  825. },
  826. resizeSidebar: function(){
  827. if (this.sidebarNode){
  828. var fileTextNode = this.contentNode.getElement("div.doc_layout_filetext");
  829. if (fileTextNode){
  830. this.sidebarNode.position({
  831. relativeTo: fileTextNode,
  832. position: 'topLeft',
  833. edge: 'topRight',
  834. offset: {"x": -20, "y": 60}
  835. });
  836. var p = fileTextNode.getPosition(this.form.app.content);
  837. var ptop = fileTextNode.getPosition(this.node);
  838. //if ((p.y+s.y)<0) this.sidebarNode.setStyle("top", p.y+s.y);
  839. if (p.y<0){
  840. var top = ptop.y-p.y+200;
  841. this.sidebarNode.setStyle("top", top);
  842. }
  843. // var p = fileTextNode.getPosition();
  844. // this.sidebarNode.setStyle("top", p.y);
  845. }
  846. }
  847. },
  848. loadSideToolbar: function(){
  849. if (this.allowEdit){
  850. if (this.pages.length){
  851. var fileTextNode = this.pages[0].getElement("div.doc_layout_filetext");
  852. if (fileTextNode){
  853. this.sidebarNode = new Element("div", {"styles": this.css.doc_sidebar}).inject(this.node);
  854. this.resizeSidebar();
  855. this.scrollNode = this.sidebarNode.getParentSrcollNode();
  856. if (this.scrollNode){
  857. this.scrollNode.addEvent("scroll", function(){
  858. this.resizeSidebar();
  859. }.bind(this));
  860. }
  861. 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>";
  862. this.sidebarNode.set("html", html);
  863. MWF.require("MWF.widget.Toolbar", function() {
  864. this.sideToolbar = new MWF.widget.Toolbar(this.sidebarNode, {"style": "documentEdit_side"}, this);
  865. this.sideToolbar.load();
  866. }.bind(this));
  867. }
  868. }
  869. }
  870. },
  871. _returnScale: function(){
  872. this.isScale = false;
  873. this.scale = 0;
  874. this.contentNode.setStyles({
  875. "transform":"scale(1)",
  876. });
  877. if (this.pages.length){
  878. this.pages.each(function(page){
  879. page.setStyles({
  880. "transform":"scale(1)",
  881. });
  882. });
  883. }
  884. this.node.setStyles({
  885. "height": "auto"
  886. });
  887. },
  888. _checkScale: function(offset){
  889. offset = 0;
  890. if (this.pages.length){
  891. //var pageSize = this.pages[0].getSize();
  892. var pageSize_x = this.options.docPageFullWidth
  893. var contentSize = this.contentNode.getSize();
  894. var contentWidth = (offset) ? contentSize.x-20-offset : contentSize.x-20;
  895. if (contentWidth<pageSize_x){
  896. this.isScale = true;
  897. var scale = (contentWidth)/pageSize_x;
  898. this.scale = scale;
  899. this.zoom();
  900. this.resetNodeSize();
  901. }
  902. }
  903. },
  904. zoom: function(scale){
  905. if (scale) this.scale = scale;
  906. var w = this.node.getSize().x;
  907. if (this.history && this.history.historyListAreaNode) w = w-this.history.historyListAreaNode.getComputedSize().totalWidth-2;
  908. w = w/this.scale;
  909. this.contentNode.setStyles({
  910. "transform":"scale("+this.scale+")",
  911. "transform-origin": "0px 0px",
  912. "overflow": "hidden",
  913. "width": ""+w+"px"
  914. });
  915. },
  916. _switchReadOrEdit: function(){
  917. if (this.editMode){
  918. this._readFiletext();
  919. if (this.allowEdit) {
  920. var button = this.toolbar.childrenButton[0];
  921. button.setText(MWF.xApplication.process.Xform.LP.editdoc);
  922. button.picNode.getElement("img").set("src", "../x_component_process_Xform/$Form/default/icon/editdoc.png");
  923. //this.getFullWidthFlagNode().dispose();
  924. }
  925. this.editMode = false;
  926. }else{
  927. this._editFiletext();
  928. if (this.allowEdit) {
  929. var button = this.toolbar.childrenButton[0];
  930. button.setText(MWF.xApplication.process.Xform.LP.editdocCompleted);
  931. button.picNode.getElement("img").set("src", "../x_component_process_Xform/$Form/default/icon/editdoc_completed.png");
  932. //this.toolbar.node.inject(this.getFullWidthFlagNode());
  933. }
  934. this.editMode = true;
  935. }
  936. },
  937. _switchReadOrEditInline: function(){
  938. if (this.editMode){
  939. this._readFiletext();
  940. if (this.allowEdit){
  941. if (!layout.mobile) {
  942. var button = this.sideToolbar.childrenButton[0];
  943. button.setText(MWF.xApplication.process.Xform.LP.editdoc);
  944. button.picNode.getElement("img").set("src", "../x_component_process_Xform/$Form/default/icon/editdoc.png");
  945. //this.getFullWidthFlagNode().dispose();
  946. }
  947. button = this.toolbar.childrenButton[0];
  948. button.setText(MWF.xApplication.process.Xform.LP.editdoc);
  949. button.picNode.getElement("img").set("src", "../x_component_process_Xform/$Form/default/icon/editdoc.png");
  950. //this.getFullWidthFlagNode().dispose();
  951. // if (!layout.mobile)this.sideToolbar.childrenButton[0].setText(MWF.xApplication.process.Xform.LP.editdoc);
  952. // this.toolbar.childrenButton[0].setText(MWF.xApplication.process.Xform.LP.editdoc);
  953. }
  954. this.editMode = false;
  955. }else{
  956. this._editFiletext("inline");
  957. if (this.allowEdit){
  958. if (!layout.mobile) {
  959. var button = this.sideToolbar.childrenButton[0];
  960. button.setText(MWF.xApplication.process.Xform.LP.editdocCompleted);
  961. button.picNode.getElement("img").set("src", "../x_component_process_Xform/$Form/default/icon/editdoc_completed.png");
  962. //this.toolbar.node.inject(this.getFullWidthFlagNode());
  963. }
  964. button = this.toolbar.childrenButton[0];
  965. button.setText(MWF.xApplication.process.Xform.LP.editdocCompleted);
  966. button.picNode.getElement("img").set("src", "../x_component_process_Xform/$Form/default/icon/editdoc_completed.png");
  967. //this.toolbar.node.inject(this.getFullWidthFlagNode());
  968. // if (!layout.mobile) this.sideToolbar.childrenButton[0].setText(MWF.xApplication.process.Xform.LP.editdocCompleted);
  969. // this.toolbar.childrenButton[0].setText(MWF.xApplication.process.Xform.LP.editdocCompleted);
  970. }
  971. this.editMode = true;
  972. }
  973. },
  974. // getFullWidthFlagNode: function(){
  975. // if (!this.fullWidthFlagNode){
  976. // this.fullWidthFlagNode = new Element("span", {
  977. // "styles": {
  978. // "line-height": "26px",
  979. // "color": "#999999",
  980. // "font-size": "12px"
  981. // },
  982. // "text": MWF.xApplication.process.Xform.LP.fullWidth
  983. // });
  984. // }
  985. // return this.fullWidthFlagNode;
  986. // },
  987. _printDoc: function(){
  988. this.toWord(function(data){
  989. if (this.form.businessData.work && !this.form.businessData.work.completedTime){
  990. this.form.workAction.getAttachmentStream(data.id, this.form.businessData.work.id);
  991. }else{
  992. this.form.workAction.getWorkcompletedAttachmentStream(data.id, ((this.form.businessData.workCompleted) ? this.form.businessData.workCompleted.id : this.form.businessData.work.id));
  993. }
  994. }.bind(this));
  995. },
  996. _historyDoc: function(){
  997. this.getHistory(function(){
  998. //this.history.play();
  999. }.bind(this));
  1000. },
  1001. getHistory: function(callback){
  1002. if (this.history){
  1003. this.history.active(function(){
  1004. if (callback) callback();
  1005. });
  1006. }else{
  1007. MWF.xDesktop.requireApp("process.Xform", "widget.DocumentHistory", function(){
  1008. this.history = new MWF.xApplication.process.Xform.widget.DocumentHistory(this);
  1009. this.history.load(function(){
  1010. if (callback) callback();
  1011. });
  1012. }.bind(this));
  1013. }
  1014. },
  1015. htmlToText: function(html){
  1016. var tmpdiv = new Element("div", {"html": html});
  1017. var text = tmpdiv.get("text");
  1018. tmpdiv.destroy();
  1019. return text;
  1020. },
  1021. _readFiletext: function(){
  1022. //this._returnScale();
  1023. this.zoom(1);
  1024. if (this.filetextEditor) this.filetextEditor.destroy();
  1025. if (this.filetextScrollNode){
  1026. if (this.reLocationFiletextToolbarFun){
  1027. this.filetextScrollNode.removeEvent("scroll", this.reLocationFiletextToolbarFun);
  1028. //this.form.app.removeEvent("resize", this.reLocationFiletextToolbarFun);
  1029. this.reLocationFiletextToolbarFun = null;
  1030. }
  1031. this.filetextScrollNode = null;
  1032. }
  1033. if (this.filetextToolbarNode) this.filetextToolbarNode = null;
  1034. this.layout_filetext.setAttribute('contenteditable', false);
  1035. this.data = this.getData();
  1036. // debugger;
  1037. if (!this.data.filetext){
  1038. //this.data.filetext = this.json.defaultValue.filetext;
  1039. this.layout_filetext.set("html", this.json.defaultValue.filetext);
  1040. }
  1041. //this._checkSplitPage(this.pages[0]);
  1042. this._repage();
  1043. },
  1044. _editFiletext: function(inline){
  1045. this._returnScale();
  1046. this.zoom(1);
  1047. this._singlePage();
  1048. this.pages = [];
  1049. this.contentNode.empty();
  1050. this._createPage(function(control){
  1051. this._loadPageLayout(control);
  1052. // var docData = this._getBusinessData();
  1053. // if (!docData) docData = this._getDefaultData();
  1054. if (this.data.filetext == this.json.defaultValue.filetext) this.data.filetext = "  ";
  1055. this.setData(this.data);
  1056. this._checkScale();
  1057. this.node.setStyles({
  1058. "height":"auto"
  1059. });
  1060. this._createEditor(inline);
  1061. }.bind(this));
  1062. },
  1063. _createEditor: function(inline){
  1064. if (this.allowEdit){
  1065. this.loadCkeditorFiletext(function(e){
  1066. e.editor.focus();
  1067. e.editor.getSelection().scrollIntoView();
  1068. //this.getFiletextToolber();
  1069. //this.filetextToolbarNode.inject(this.layout_filetext.getOffsetParent());
  1070. this.locationFiletextToolbar();
  1071. }.bind(this), inline);
  1072. }
  1073. },
  1074. getFiletextToolber: function(){
  1075. if (this.filetextEditor) {
  1076. if (!this.filetextToolbarNode) {
  1077. var className = "cke_editor_" + this.filetextEditor.name;
  1078. var filetextToolbarNode = $$("." + className)[0];
  1079. this.filetextToolbarNode = filetextToolbarNode;
  1080. //filetextToolbarNode.destroy();
  1081. }
  1082. }
  1083. },
  1084. reLocationFiletextToolbar: function(){
  1085. this.getFiletextToolber();
  1086. // if (this.filetextToolbarNode){
  1087. // this.filetextToolbarNode.setStyle("display", "block");
  1088. // var offsetNode = this.layout_filetext.getOffsetParent();
  1089. //
  1090. // this.filetextToolbarNode.setStyle("left", 0);
  1091. // var h = this.filetextToolbarNode.getSize().y;
  1092. // var p = this.layout_filetext.getPosition(offsetNode).y-h;
  1093. //
  1094. // var postion = this.layout_filetext.getPosition(this.form.app.content);
  1095. // if (postion.y-h<0){
  1096. // this.filetextToolbarNode.inject(this.form.app.content);
  1097. // this.filetextToolbarNode.setStyle("top", 0);
  1098. // this.filetextToolbarNode.setStyle("left", ""+postion.x+"px");
  1099. // }else{
  1100. // this.filetextToolbarNode.inject(offsetNode);
  1101. // this.filetextToolbarNode.setStyle("top", "" + p + "px");
  1102. // this.filetextToolbarNode.setStyle("left", 0);
  1103. // this.filetextToolbarNode.setStyle("left", "auto");
  1104. // }
  1105. // }
  1106. if (this.filetextToolbarNode){
  1107. if (!this.filetextScrollNode){
  1108. var scrollNode = this.contentNode;
  1109. while (scrollNode && (scrollNode.getScrollSize().y<=scrollNode.getSize().y || (scrollNode.getStyle("overflow")!=="auto" && scrollNode.getStyle("overflow-y")!=="auto"))){
  1110. scrollNode = scrollNode.getParent();
  1111. }
  1112. this.filetextScrollNode = scrollNode;
  1113. }
  1114. var h = this.filetextToolbarNode.getSize().y;
  1115. var position = this.layout_filetext.getPosition();
  1116. var size = this.layout_filetext.getSize();
  1117. var contentSize = this.filetextScrollNode.getSize();
  1118. if (position.y<0 && size.y+position.y+h<contentSize.y){
  1119. // var top = size.y+position.y;
  1120. // this.filetextToolbarNode.setStyle("top", ""+top+"px");
  1121. var tp = this.toolbar.node.getPosition();
  1122. var tsy = this.toolbar.node.getSize().y;
  1123. var h = tp.y+tsy;
  1124. this.filetextToolbarNode.setStyle("top", ""+h+"px");
  1125. }else if (position.y-h<0){
  1126. var tp = this.toolbar.node.getPosition();
  1127. var tsy = this.toolbar.node.getSize().y;
  1128. var h = tp.y+tsy;
  1129. this.filetextToolbarNode.setStyle("top", ""+h+"px");
  1130. }else{
  1131. var p = this.layout_filetext.getPosition().y-h;
  1132. this.filetextToolbarNode.setStyle("top", "" + p + "px");
  1133. }
  1134. }
  1135. //
  1136. // this.filetextToolbarNode.inject(offsetNode);
  1137. //
  1138. //
  1139. // this.filetextToolbarNode.setStyle("top", ""+p+"px");
  1140. },
  1141. locationFiletextToolbar: function(){
  1142. this.reLocationFiletextToolbar();
  1143. if (this.filetextToolbarNode) {
  1144. var scrollNode = this.contentNode;
  1145. while (scrollNode && (scrollNode.getScrollSize().y<=scrollNode.getSize().y || (scrollNode.getStyle("overflow")!=="auto" && scrollNode.getStyle("overflow-y")!=="auto"))){
  1146. scrollNode = scrollNode.getParent();
  1147. }
  1148. if (scrollNode){
  1149. this.filetextScrollNode = scrollNode;
  1150. this.reLocationFiletextToolbarFun = this.reLocationFiletextToolbar.bind(this);
  1151. this.filetextScrollNode.addEvent("scroll", this.reLocationFiletextToolbarFun);
  1152. }
  1153. }
  1154. },
  1155. _isAllowEdit:function(){
  1156. if (this.readonly) return false;
  1157. if (this.json.allowEdit=="n") return false;
  1158. if (this.json.allowEdit=="s"){
  1159. if (this.json.allowEditScript && this.json.allowEditScript.code){
  1160. return !!this.form.Macro.exec(this.json.allowEditScript.code, this);
  1161. }
  1162. }
  1163. return true;
  1164. },
  1165. _isAllowPrint: function(){
  1166. if (this.json.allowPrint=="n") return false;
  1167. if (this.json.allowPrint=="s"){
  1168. if (this.json.allowPrintScript && this.json.allowPrintScript.code){
  1169. return !!this.form.Macro.exec(this.json.allowPrintScript.code, this);
  1170. }
  1171. }
  1172. return true;
  1173. },
  1174. _isAllowHistory: function(){
  1175. if (this.json.allowHistory=="n") return false;
  1176. if (this.json.allowHistory=="s"){
  1177. if (this.json.allowHistoryScript && this.json.allowHistoryScript.code){
  1178. return !!this.form.Macro.exec(this.json.allowHistoryScript.code, this);
  1179. }
  1180. }
  1181. return true;
  1182. },
  1183. _getEdit: function(name, typeItem, scriptItem){
  1184. switch (this.json[typeItem]) {
  1185. case "y":
  1186. return true;
  1187. case "n":
  1188. return false;
  1189. case "s":
  1190. if (this.json[scriptItem] && this.json[scriptItem].code){
  1191. return !!this.form.Macro.exec(this.json[scriptItem].code, this);
  1192. }
  1193. return true;
  1194. }
  1195. },
  1196. loadCkeditorStyle: function(node){
  1197. if (node){
  1198. o2.load("ckeditor", function(){
  1199. //CKEDITOR.disableAutoInline = true;
  1200. node.setAttribute('contenteditable', true);
  1201. var editor = CKEDITOR.inline(this.layout_filetext, this._getEditorConfig());
  1202. this.filetextEditor.on("instanceReady", function(e){
  1203. if (callback) callback(e);
  1204. }.bind(this));
  1205. }.bind(this));
  1206. }
  1207. },
  1208. _loadToolbars: function(){
  1209. var html ="";
  1210. if (this.allowEdit){
  1211. //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>";
  1212. 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>";
  1213. //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>";
  1214. }
  1215. if (this.allowPrint){
  1216. 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>";
  1217. }
  1218. if (this.allowHistory){
  1219. 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>";
  1220. }
  1221. // if (this.json.fullWidth=="y"){
  1222. // html += "<span style='line-height: 26px; color: #999999; font-size: 12px'>已启用半角空格自动转换为全角空格,如需输入半角空格,请使用:SHIFT+空格</span>"
  1223. // }
  1224. this.toolbarNode = new Element("div", {"styles": this.css.doc_toolbar_node}).inject(this.toolNode);
  1225. this.toolbarNode.set("html", html);
  1226. MWF.require("MWF.widget.Toolbar", function() {
  1227. this.toolbar = new MWF.widget.Toolbar(this.toolbarNode, {"style": "documentEdit"}, this);
  1228. this.toolbar.load();
  1229. }.bind(this));
  1230. this.scrollNode = this.toolbarNode.getParentSrcollNode();
  1231. if (this.scrollNode){
  1232. this.scrollNode.addEvent("scroll", function(){
  1233. this.resizeToolbar();
  1234. }.bind(this));
  1235. }
  1236. this.doublePageAction = new Element("div", {"styles": this.css.doc_toolbar_doublePage, "text": MWF.xApplication.process.Xform.LP.doublePage}).inject(this.toolbarNode);
  1237. this.doublePageAction.addEvent("click", function(){
  1238. if (this.options.pageShow!=="double"){
  1239. this._doublePage();
  1240. }else{
  1241. this._singlePage();
  1242. }
  1243. }.bind(this));
  1244. // this.zoomSelectAction = new Element("select", {"styles": {"float": "right"}}).inject(this.toolbarNode);
  1245. // var options = "<option value='2'>200%</option> " +
  1246. // "<option value='1.75'>175%</option>" +
  1247. // "<option value='1.5'>150%</option>" +
  1248. // "<option value='1' selected>100%</option>" +
  1249. // "<option value='0.75'>75%</option>" +
  1250. // "<option value='0.5'>50%</option>" +
  1251. // "<option value='0.25'>25%</option>"
  1252. // this.zoomSelectAction.set("html", options);
  1253. // this.zoomSelectAction.addEvent("change", function(e){
  1254. // this._returnScale();
  1255. // this.scale = e.target.options[e.target.selectedIndex].value;
  1256. // this.zoom();
  1257. // }.bind(this));
  1258. },
  1259. _repage: function(delay){
  1260. if (this.options.pageShow!=="double"){
  1261. this._singlePage();
  1262. }else{
  1263. this._doublePage();
  1264. }
  1265. if (delay){
  1266. if (!this.form.isLoaded){
  1267. this.form.addEvent("afterLoad", this._checkScale.bind(this));
  1268. }else{
  1269. this._checkScale();
  1270. }
  1271. }else{
  1272. this._checkScale();
  1273. }
  1274. },
  1275. _singlePage: function(){
  1276. //if (this.editMode) this._readFiletext();
  1277. this.zoom(1);
  1278. this._checkScale();
  1279. var w = this.contentNode.getSize().x;
  1280. var count = 1;
  1281. var docPageFullWidth = (this.scale) ? this.scale*this.options.docPageFullWidth : this.options.docPageFullWidth;
  1282. //var docPageFullWidth = this.options.docPageFullWidt;
  1283. var pageWidth = count * docPageFullWidth;
  1284. var margin = (w-pageWidth)/(count+1);
  1285. if (this.isScale){
  1286. margin = "10";
  1287. }
  1288. if (this.scale) margin = margin/this.scale;
  1289. this.pages.each(function(page, i){
  1290. page.setStyles({
  1291. "float": "left",
  1292. "margin-left": ""+margin+"px"
  1293. });
  1294. });
  1295. this.resetNodeSize();
  1296. // this.pages.each(function(page){
  1297. // page.setStyle("float", "none");
  1298. // });
  1299. this.resizeSidebar();
  1300. this.options.pageShow="single";
  1301. this.doublePageAction.set("text", MWF.xApplication.process.Xform.LP.doublePage);
  1302. },
  1303. resetNodeSize: function(){
  1304. var contentSize = this.contentNode.getSize();
  1305. var toolbarSize = this.toolNode.getSize();
  1306. contentHeight = contentSize.y;
  1307. var h = contentHeight+toolbarSize.y+20;
  1308. //h = h - contentSize.y*(1-this.scale);
  1309. this.node.setStyles({
  1310. "height":""+h+"px"
  1311. });
  1312. },
  1313. createWaitSplitPage: function(){
  1314. this.node.mask({
  1315. "style": {
  1316. "background-color": "#cccccc",
  1317. "opacity": 0.3
  1318. }
  1319. });
  1320. this.waitSplitPageNode = new Element("div", {"styles": this.form.css.waitSplitPageNode, "text": MWF.xApplication.process.Xform.LP.computePage}).inject(this.node);
  1321. this.waitSplitPageNode.position({
  1322. "relativeTo": this.node,
  1323. "position": "topRight",
  1324. "edge": "topRight",
  1325. "offset": {
  1326. "x": -10,
  1327. "y": 45
  1328. }
  1329. });
  1330. //this.form.notice(MWF.xApplication.process.Xform.LP.computePage, "info", this.node);
  1331. },
  1332. clearWaitSplitPage: function(){
  1333. this.node.unmask();
  1334. if (this.waitSplitPageNode) this.waitSplitPageNode.destroy();
  1335. this.waitSplitPageNode = null;
  1336. },
  1337. _doublePage: function(){
  1338. if (this.editMode) this._switchReadOrEditInline();
  1339. this.zoom(1);
  1340. this.createWaitSplitPage();
  1341. window.setTimeout(function(){
  1342. this._checkSplitPage(this.pages[0]);
  1343. this.zoom(1);
  1344. var w = this.contentNode.getSize().x;
  1345. var toPageWidth = (w-100)/2;
  1346. scale = toPageWidth/this.options.docPageFullWidth;
  1347. if (scale<1) this.zoom(scale);
  1348. var docPageFullWidth = (this.scale) ? this.scale*this.options.docPageFullWidth : this.options.docPageFullWidth;
  1349. //var docPageFullWidth = this.options.docPageFullWidth;
  1350. var w = this.contentNode.getSize().x;
  1351. var count = (w/docPageFullWidth).toInt();
  1352. var pages = this.contentNode.getElements(".doc_layout_page");
  1353. count = Math.min(pages.length, count);
  1354. var pageWidth = count * docPageFullWidth;
  1355. var margin = (w-pageWidth)/(count+1);
  1356. if (this.scale) margin = margin/(this.scale);
  1357. this.pages.each(function(page, i){
  1358. page.setStyles({
  1359. "float": "left",
  1360. "margin-left": ""+margin+"px"
  1361. });
  1362. });
  1363. // this.pages.each(function(page, i){
  1364. // if ((i % 2)===0){
  1365. // page.setStyle("float", "left");
  1366. // }else{
  1367. // page.setStyle("float", "right");
  1368. // }
  1369. // });
  1370. this.resetNodeSize();
  1371. this.options.pageShow="double";
  1372. this.doublePageAction.set("text", MWF.xApplication.process.Xform.LP.singlePage);
  1373. this.resizeSidebar();
  1374. this.clearWaitSplitPage();
  1375. }.bind(this), 1000);
  1376. },
  1377. _getDefaultData: function(){
  1378. return Object.clone(this.json.defaultValue);
  1379. //return Object.clone(MWF.xApplication.process.Xform.LP.documentEditor);
  1380. },
  1381. _loadFiletextPage: function(callback){
  1382. this.data = this._getBusinessData();
  1383. if (!this.data) this.data = this._getDefaultData();
  1384. this._computeData(true);
  1385. this._createPage(function(control){
  1386. this._loadPageLayout(control);
  1387. // this.data = this._getBusinessData();
  1388. // if (!this.data) this.data = this._getDefaultData();
  1389. this.setData(this.data);
  1390. // this._checkSplitPage(this.pages[0]);
  1391. //this._repage(true);
  1392. //this.loadCkeditorFiletext();
  1393. if (!this.readonly){
  1394. //if (this.json.allowEditFiletext!==false) this.loadCkeditorFiletext();
  1395. // if (this.json.allowEditRedheader) this.loadCkeditorRedheader();
  1396. // if (this.json.allowEditSubject) this.loadCkeditorSubject();
  1397. // if (this.json.allowEditMainSend) this.loadCkeditorMainSend();
  1398. // if (this.json.allowEditFileNo) this.loadCkeditorFileNo();
  1399. // if (this.json.allowEditSigner) this.loadCkeditorSigner();
  1400. // if (this.json.allowEditAttachment) this.loadCkeditorAttachment();
  1401. }
  1402. if (callback) callback();
  1403. }.bind(this));
  1404. },
  1405. _getEditorConfig: function(){
  1406. // var mathElements = [
  1407. // 'math',
  1408. // 'maction',
  1409. // 'maligngroup',
  1410. // 'malignmark',
  1411. // 'menclose',
  1412. // 'merror',
  1413. // 'mfenced',
  1414. // 'mfrac',
  1415. // 'mglyph',
  1416. // 'mi',
  1417. // 'mlabeledtr',
  1418. // 'mlongdiv',
  1419. // 'mmultiscripts',
  1420. // 'mn',
  1421. // 'mo',
  1422. // 'mover',
  1423. // 'mpadded',
  1424. // 'mphantom',
  1425. // 'mroot',
  1426. // 'mrow',
  1427. // 'ms',
  1428. // 'mscarries',
  1429. // 'mscarry',
  1430. // 'msgroup',
  1431. // 'msline',
  1432. // 'mspace',
  1433. // 'msqrt',
  1434. // 'msrow',
  1435. // 'mstack',
  1436. // 'mstyle',
  1437. // 'msub',
  1438. // 'msup',
  1439. // 'msubsup',
  1440. // 'mtable',
  1441. // 'mtd',
  1442. // 'mtext',
  1443. // 'mtr',
  1444. // 'munder',
  1445. // 'munderover',
  1446. // 'semantics',
  1447. // 'annotation',
  1448. // 'annotation-xml'
  1449. // ];
  1450. //CKEDITOR.plugins.addExternal('ckeditor_wiris', 'https://ckeditor.com/docs/ckeditor4/4.13.0/examples/assets/plugins/ckeditor_wiris/', 'plugin.js');
  1451. debugger;
  1452. var editorConfig = {
  1453. qtRows: 20, // Count of rows
  1454. qtColumns: 20, // Count of columns
  1455. qtBorder: '1', // Border of inserted table
  1456. qtWidth: '95%', // Width of inserted table
  1457. qtStyle: { 'border-collapse' : 'collapse' },
  1458. qtClass: 'documenteditor_table'+this.form.json.id+this.json.id, // Class of table
  1459. qtCellPadding: '0', // Cell padding table
  1460. qtCellSpacing: '0', // Cell spacing table
  1461. qtPreviewBorder: '4px double black', // preview table border
  1462. qtPreviewSize: '4px', // Preview table cell size
  1463. qtPreviewBackground: '#c8def4', // preview table background (hover)
  1464. // format_tags: '标题一;标题二;标题三;标题四;正文', // entries is displayed in "Paragraph format"
  1465. format_tags: '标题一;标题二;正文(标题三,四)', // entries is displayed in "Paragraph format"
  1466. 'format_标题一': {
  1467. name: '标题一(三号黑体)',
  1468. element: 'div',
  1469. styles: {
  1470. 'font-family': '黑体',
  1471. 'font-size': '16pt'
  1472. }
  1473. },
  1474. 'format_标题二': {
  1475. name: '标题二(三号楷体)',
  1476. element: 'div',
  1477. styles: {
  1478. 'font-family': '楷体',
  1479. 'font-size': '16pt'
  1480. }
  1481. },
  1482. // 'format_标题三': {
  1483. // name: '标题三',
  1484. // element: 'div',
  1485. // styles: {
  1486. // 'font-family': '仿宋',
  1487. // 'font-size': '16pt'
  1488. // }
  1489. // },
  1490. // 'format_标题四': {
  1491. // name: '标题四',
  1492. // element: 'div',
  1493. // styles: {
  1494. // 'font-family': '仿宋',
  1495. // 'font-size': '16pt'
  1496. // }
  1497. // },
  1498. 'format_正文(标题三,四)': {
  1499. name: '正文(标题三,四)',
  1500. element: 'div',
  1501. styles: {
  1502. 'font-family': '仿宋',
  1503. 'font-size': '16pt'
  1504. }
  1505. }
  1506. };
  1507. editorConfig.toolbarGroups = [
  1508. { name: 'document', groups: [ 'mode', 'document', 'doctools' ] },
  1509. { name: 'clipboard', groups: [ 'clipboard', 'undo' ] },
  1510. { name: 'editing', groups: [ 'find', 'selection', 'spellchecker', 'editing' ] },
  1511. { name: 'forms', groups: [ 'forms' ] },
  1512. { name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] },
  1513. { name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align', 'bidi', 'paragraph' ] },
  1514. { name: 'links', groups: [ 'links' ] },
  1515. { name: 'insert', groups: [ 'insert' ] },
  1516. { name: 'styles', groups: [ 'styles' ] },
  1517. { name: 'colors', groups: [ 'colors' ] },
  1518. { name: 'tools', groups: [ 'tools' ] },
  1519. { name: 'others', groups: [ 'others' ] },
  1520. { name: 'about', groups: [ 'about' ] }
  1521. ];
  1522. //editorConfig.extraPlugins = "ecnet,colordialog,tableresize,quicktable,mathjax,ckeditor_wiris";
  1523. //editorConfig.extraPlugins = "ecnet,colordialog,quicktable,tableresize,eqneditor";
  1524. //editorConfig.extraPlugins = "tableresize,quicktable";
  1525. editorConfig.extraPlugins = "quicktable,tableresize";
  1526. //editorConfig.mathJaxLib = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-AMS_HTML',
  1527. 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';
  1528. //editorConfig.extraAllowedContent = mathElements.join(' ') + '(*)[*]{*};img[data-mathml,data-custom-editor,role](Wirisformula)';
  1529. editorConfig.pasteFromWordRemoveFontStyles = false;
  1530. editorConfig.pasteFromWordRemoveStyles = false;
  1531. //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';
  1532. editorConfig.removePlugins = ['magicline'];
  1533. editorConfig.enterMode = 3;
  1534. // editorConfig.extraPlugins = ['ecnet','mathjax'];
  1535. // editorConfig.removePlugins = ['magicline'];
  1536. // editorConfig.mathJaxLib = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-AMS_HTML';
  1537. return editorConfig;
  1538. },
  1539. _checkSplitPage: function(pageNode){
  1540. if (this.layout_edition) this.layout_edition.setStyles({ "position": "static"});
  1541. var contentNode = pageNode.getFirst();
  1542. if (contentNode.getSize().y>this.options.docPageHeight){
  1543. this._splitPage(pageNode);
  1544. }
  1545. var i = pageNode.get("data-pagecount").toInt();
  1546. if (i && this.pages.length-1>=i){
  1547. this._checkSplitPage(this.pages[i]);
  1548. }
  1549. if (this.layout_edition) this.layout_edition.setStyles({ "position": "absolute", "bottom": "0px" });
  1550. },
  1551. _splitFiletextNodeOneWord:function(lnode, nextPageNode){
  1552. var text = lnode.textContent;
  1553. var len = text.length;
  1554. var left = text.substring(0, len-1);
  1555. var right = text.substring(len-1, len);
  1556. lnode.textContent = left;
  1557. nextPageNode.textContent = right+nextPageNode.textContent;
  1558. //nextPageNode.appendText(right, "top");
  1559. },
  1560. _splitFiletext: function(node, nextPageNode, nextFiletextNode, pageNode){
  1561. var contentNode = pageNode.getFirst();
  1562. var lnode = node.lastChild;
  1563. if (!lnode){
  1564. if (node.parentNode) node.parentNode.removeChild(node);
  1565. //node.remove();
  1566. }else{
  1567. while (contentNode.getSize().y>this.options.docPageHeight && lnode) {
  1568. var tmpnode = lnode.previousSibling;
  1569. var nodeType = lnode.nodeType;
  1570. if (!nextPageNode) nextPageNode = nextFiletextNode;
  1571. if (nodeType == Node.ELEMENT_NODE) {
  1572. if (lnode.tagName == "table") {
  1573. lnode.inject(nextPageNode);
  1574. } else if (lnode.tagName == "BR") {
  1575. if (lnode.parentNode) lnode.parentNode.removeChild(lnode);
  1576. } else {
  1577. var id = lnode.get("data-pagePart");
  1578. if (!id){
  1579. id = (new o2.widget.UUID()).toString();
  1580. lnode.set("data-pagePart", id);
  1581. }
  1582. var tmpNode = nextPageNode.getFirst();
  1583. if (tmpNode && tmpNode.get("data-pagePart")==id){
  1584. nextPageNode = tmpNode;
  1585. }else{
  1586. nextPageNode = lnode.clone(false).inject(nextPageNode, "top");
  1587. }
  1588. //var subnode = lnode.getLast();
  1589. this._splitFiletext(lnode, nextPageNode, nextFiletextNode, pageNode);
  1590. if (!lnode.firstChild) if (lnode.parentNode) lnode.parentNode.removeChild(lnode);
  1591. nextPageNode = nextPageNode.getParent();
  1592. }
  1593. } else if (nodeType == Node.TEXT_NODE) {
  1594. var nextPageTextNode = nextPageNode.insertBefore(document.createTextNode(""), nextPageNode.firstChild);
  1595. while ((contentNode.getSize().y > this.options.docPageHeight) && lnode.textContent) {
  1596. //console.log(contentNode.getSize().y);
  1597. this._splitFiletextNodeOneWord(lnode, nextPageTextNode)
  1598. }
  1599. if (!lnode.textContent) if (lnode.parentNode) lnode.parentNode.removeChild(lnode); //lnode.remove();
  1600. } else {
  1601. //lnode.remove();
  1602. if (lnode.parentNode) lnode.parentNode.removeChild(lnode);
  1603. }
  1604. lnode = tmpnode;
  1605. }
  1606. if (!node.lastChild) if (node.parentNode) node.parentNode.removeChild(node); //node.remove();
  1607. }
  1608. //this._checkSplitPage(pageNode);
  1609. },
  1610. _splitPage: function(pageNode){
  1611. var contentNode = pageNode.getFirst();
  1612. var blockNodes = pageNode.getElements(".doc_block");
  1613. if (blockNodes.length){
  1614. var blockNode = blockNodes[blockNodes.length-1];
  1615. var idx = this.pages.indexOf(pageNode);
  1616. if (this.pages.length<=idx+1) this._createNewPage();
  1617. var nextPage = this.pages[idx+1];
  1618. if (blockNode.hasClass("doc_layout_filetext")){
  1619. var filetextNode = nextPage.getElement(".doc_layout_filetext");
  1620. if (!filetextNode){
  1621. filetextNode = new Element("div.doc_layout_filetext").inject(nextPage.getFirst(), "top");
  1622. //filetextNode.setAttribute('contenteditable', true);
  1623. }
  1624. if (!filetextNode.hasClass("doc_block"))filetextNode.addClass("doc_block");
  1625. //var nextEditor = filetextNode.retrieve("editor");
  1626. var node = blockNode;
  1627. var nextPageNode = filetextNode;
  1628. this._splitFiletext(node, nextPageNode, filetextNode, pageNode);
  1629. }else{
  1630. blockNode.inject(nextPage.getFirst(), "top");
  1631. //var contentNode = pageNode.getFirst();
  1632. if (contentNode.getSize().y>this.options.docPageHeight){
  1633. this._splitPage(pageNode);
  1634. }
  1635. }
  1636. }
  1637. },
  1638. transWidth: function(node){
  1639. if (!node) return '';
  1640. while (node){
  1641. if (node.nodeType==3){
  1642. node.nodeValue = node.nodeValue.replace(/\x20/g, " ");
  1643. }else if (node.nodeType==8){
  1644. //nothing
  1645. }else{
  1646. this.transWidth(node.firstChild);
  1647. }
  1648. node = node.nextSibling;
  1649. }
  1650. },
  1651. insertFullWidth: function(node, txt){
  1652. if (!node) return '';
  1653. while (node){
  1654. if (node.nodeType==3){
  1655. node.nodeValue = txt+node.nodeValue;
  1656. return true;
  1657. }else if (node.nodeType==8){
  1658. //nothing
  1659. }else{
  1660. var flag = this.insertFullWidth(node.firstChild, txt);
  1661. if (flag) return true;
  1662. }
  1663. node = node.nextSibling;
  1664. }
  1665. },
  1666. loadCkeditorFiletext: function(callback, inline){
  1667. if (this.layout_filetext){
  1668. o2.load("../o2_lib/htmleditor/ckeditor4130/ckeditor.js", function(){
  1669. CKEDITOR.disableAutoInline = true;
  1670. this.layout_filetext.setAttribute('contenteditable', true);
  1671. if (inline){
  1672. this.filetextEditor = CKEDITOR.inline(this.layout_filetext, this._getEditorConfig());
  1673. }else{
  1674. this.filetextEditor = CKEDITOR.replace(this.layout_filetext, this._getEditorConfig());
  1675. }
  1676. this.filetextEditor.on("instanceReady", function(e){
  1677. if (callback) callback(e);
  1678. }.bind(this));
  1679. this.filetextEditor.on( 'focus', function( e ) {
  1680. window.setTimeout(this.reLocationFiletextToolbar.bind(this), 10);
  1681. }.bind(this) );
  1682. this.filetextEditor.on( 'paste', function( e ) {
  1683. var html = e.data.dataValue;
  1684. //if (this.json.fullWidth=="y") html = html.replace(/\x20/g, " ");
  1685. var tmp = new Element("div")
  1686. tmp.set("html", html);
  1687. var pList = tmp.getElements("p");
  1688. pList.each(function(p, i){
  1689. //if (Browser.name=="ie"){
  1690. if (this.json.fullWidth!=="n") this.transWidth(p);
  1691. if (!p.getParent("table")){
  1692. var text = p.get("text");
  1693. var rex = /^\u3000*/;
  1694. var m = text.match(rex);
  1695. var l = (m[0]) ? Math.max((2-m[0].length), 0): 2;
  1696. var txt = "";
  1697. // for (var i=0; i<l; i++) txt+=" ";
  1698. // this.insertFullWidth(p.getFirst(), txt);
  1699. for (var i=0; i<l; i++) p.appendText(" ","top");
  1700. }
  1701. //}else{
  1702. // var textIndent = p.getStyle("text-indent");
  1703. // if (textIndent.toInt()) p.appendText("  ","top");
  1704. //}
  1705. }.bind(this));
  1706. e.data.dataValue = tmp.get("html");
  1707. tmp.destroy();
  1708. }.bind(this) );
  1709. if (this.json.textIndent!=="n"){
  1710. // this.filetextEditor.addCommand( 'textIndent_P', {
  1711. // exec: function( editor ) {
  1712. // debugger;
  1713. // editor.insertHtml("<br><div>  </div>");
  1714. // }
  1715. // } );
  1716. // this.filetextEditor.setKeystroke( CKEDITOR.CTRL + 13, 'textIndent_P' );
  1717. this.layout_filetext.addEvent("keyup", function(ev){
  1718. if (ev.code==13) this.filetextEditor.insertText("  ");
  1719. }.bind(this));
  1720. //
  1721. // this.filetextEditor.on("key", function(e){
  1722. // if (e.data.keyCode==13){
  1723. // e.editor.insertText("  ");
  1724. // //e.cancel();
  1725. // }
  1726. // }.bind(this));
  1727. }
  1728. if (this.json.fullWidth!=="n"){
  1729. this.filetextEditor.addCommand( 'insertHalfSpace', {
  1730. exec: function( editor ) {
  1731. editor.insertText(" ");
  1732. }
  1733. } );
  1734. this.filetextEditor.setKeystroke( CKEDITOR.SHIFT + 32, 'insertHalfSpace' );
  1735. this.filetextEditor.on("key", function(e){
  1736. if (this.json.fullWidth!=="n") if (e.data.keyCode==32){
  1737. e.editor.insertText(" ");
  1738. e.cancel();
  1739. }
  1740. }.bind(this));
  1741. }
  1742. }.bind(this));
  1743. }
  1744. },
  1745. _loadEvents: function(editorConfig){
  1746. Object.each(this.json.events, function(e, key){
  1747. if (e.code){
  1748. this.editor.on(key, function(event){
  1749. return this.form.Macro.fire(e.code, this, event);
  1750. }.bind(this), this);
  1751. }
  1752. }.bind(this));
  1753. },
  1754. _bindFieldChange: function(name,dataItem, dom){
  1755. var field = this.form.all[this.json[dataItem]];
  1756. if (field){
  1757. var bindFun = function(){
  1758. this._computeItemFieldData(name, dataItem);
  1759. //if (this.data[name]){
  1760. if (this[dom]){
  1761. if (dom=="layout_redHeader" || dom=="layout_subject"){
  1762. this[dom].set("html", this.data[name]|| "");
  1763. }else if (dom=="layout_attachment"){
  1764. this.setAttachmentData();
  1765. }else{
  1766. this[dom].set("text", this.data[name]|| "");
  1767. }
  1768. }
  1769. this.reSetShow();
  1770. //}
  1771. }.bind(this);
  1772. field.node.store(this.json.id+"bindFun", bindFun);
  1773. field.addModuleEvent("change", bindFun);
  1774. }
  1775. },
  1776. _computeItemFieldData: function(name, dataItem, dataItemNode){
  1777. var v = "";
  1778. var module = (dataItemNode) ? this.form.all[dataItemNode] : this.form.all[this.json[dataItem]];
  1779. if (module && module.getData) v = module.getData();
  1780. if (!v) v = (dataItemNode) ? this.form.businessData.data[dataItemNode] : this.form.businessData.data[this.json[dataItem]];
  1781. if (v){
  1782. var t = o2.typeOf(v);
  1783. switch (t) {
  1784. case "string":
  1785. switch (name) {
  1786. case "issuanceDate":
  1787. case "editionDate":
  1788. var d = new Date(v);
  1789. debugger;
  1790. if (d.isValid() && d.getFullYear()!=1970){
  1791. var y = d.getFullYear();
  1792. var m = d.getMonth();
  1793. var day = d.getDate();
  1794. m = m +1;
  1795. this.data[name] = ""+y+"年"+m+"月"+day+"日";
  1796. }else{
  1797. this.data[name] = v;
  1798. }
  1799. //this.data[name] = (new Date(v).isValid()) ? Date.parse(v).format("%Y年%m月%d%日") : v;
  1800. break;
  1801. case "mainSend":
  1802. this.data[name] = v + ":";
  1803. break;
  1804. default:
  1805. this.data[name] = v;
  1806. }
  1807. break;
  1808. case "array":
  1809. var strs = [];
  1810. v.each(function(value){
  1811. if (o2.typeOf(value)=="object" && value.distinguishedName){
  1812. strs.push(value.name);
  1813. }else{
  1814. strs.push(value.toString());
  1815. }
  1816. });
  1817. //if (strs.length){
  1818. switch (name) {
  1819. case "attachment":
  1820. // this.data[name] = strs.map(function(n, i){ var j = i+1; return j+"、"+n}).join("<br>");
  1821. var atts = strs.map(function(a){
  1822. return (a.indexOf(".")!=-1) ? a.substring(0, a.lastIndexOf(".")) : a;
  1823. });
  1824. this.data[name] = atts;
  1825. break;
  1826. case "issuanceDate":
  1827. case "editionDate":
  1828. var tmpStrs = strs.map(function(n, i){
  1829. var d = Date.parse(n);
  1830. if (d.isValid() && d.getFullYear()!=1970){
  1831. var y = d.getFullYear();
  1832. var m = d.getMonth();
  1833. var day = d.getDate();
  1834. m = m +1;
  1835. return ""+y+"年"+m+"月"+day+"日";
  1836. }else{
  1837. return n;
  1838. }
  1839. //return () ? d.format("%Y年%m月%d日") : n;
  1840. });
  1841. this.data[name] = tmpStrs.join(",");
  1842. break;
  1843. case "mainSend":
  1844. this.data[name] = strs.join(",") + ":";
  1845. break;
  1846. default:
  1847. this.data[name] = strs.join(",");
  1848. }
  1849. //}
  1850. break;
  1851. default:
  1852. this.data[name] = v.toString();
  1853. }
  1854. }else{
  1855. this.data[name] = this.json.defaultValue[name];
  1856. }
  1857. },
  1858. computeData: function(){
  1859. this._computeData(false);
  1860. this.setData(this.data);
  1861. },
  1862. _computeItemData: function(name, typeItem, dataItem, scriptItem, ev, dom){
  1863. switch (this.json[typeItem]) {
  1864. case "data":
  1865. if (this.json[dataItem]){
  1866. if (ev) this._bindFieldChange(name, dataItem, dom);
  1867. this._computeItemFieldData(name, dataItem);
  1868. }
  1869. break;
  1870. case "script":
  1871. if (this.json[scriptItem] && this.json[scriptItem].code){
  1872. var v = this.form.Macro.exec(this.json[scriptItem].code, this);
  1873. this.data[name] = v;
  1874. if (name=="attachment"){
  1875. //this.data[name] = (typeOf(v)=="array") ? v.map(function(n, i){ var j = i+1; return j+"、"+n}).join("<br>") : v;
  1876. this.data[name] = (typeOf(v)=="array") ? v : [v];
  1877. }
  1878. if (name=="issuanceDate" || name=="editionDate"){
  1879. var d = Date.parse(v);
  1880. if (d.isValid() && d.getFullYear()!=1970){
  1881. var y = d.getFullYear();
  1882. var m = d.getMonth();
  1883. var day = d.getDate();
  1884. m = m +1;
  1885. this.data[name] = ""+y+"年"+m+"月"+day+"日";
  1886. }else{
  1887. this.data[name] = v;
  1888. }
  1889. //this.data[name] = (d.isValid() && d.getFullYear()!=1970) ? d.format("%Y年%m月%d日") : v;
  1890. }
  1891. }
  1892. break;
  1893. }
  1894. },
  1895. _computeCustomItemData: function(name, field, ev){
  1896. //if (this.json.customFields[l.name]){
  1897. if (ev) this._bindCustomFieldChange(name, field, name);
  1898. this._computeItemFieldData(name, null, field);
  1899. //}
  1900. },
  1901. _bindCustomFieldChange: function(name, dataItem, dom){
  1902. var field = this.form.all[dataItem];
  1903. if (field){
  1904. var bindFun = function(){
  1905. this._computeItemFieldData(name, null, dataItem);
  1906. //if (this.data[name]){
  1907. if (this[dom]){
  1908. if (dom=="layout_redHeader" || dom=="layout_subject"){
  1909. this[dom].set("html", this.data[name]|| "");
  1910. }else if (dom=="layout_attachment"){
  1911. this.setAttachmentData();
  1912. }else{
  1913. this[dom].set("text", this.data[name]|| "");
  1914. }
  1915. }
  1916. this.reSetShow();
  1917. //}
  1918. }.bind(this);
  1919. field.node.store(this.json.id+"bindFun", bindFun);
  1920. field.addModuleEvent("change", bindFun);
  1921. }
  1922. },
  1923. _computeData: function(ev){
  1924. this._computeItemData("copies", "copiesValueType", "copiesValueData", "copiesValueScript", ev, "layout_copies");
  1925. this._computeItemData("secret", "secretValueType", "secretValueData", "secretValueScript", ev, "layout_secret");
  1926. this._computeItemData("priority", "priorityValueType", "priorityValueData", "priorityValueScript", ev, "layout_priority");
  1927. this._computeItemData("redHeader", "redHeaderValueType", "redHeaderValueData", "redHeaderValueScript", ev, "layout_redHeader");
  1928. this._computeItemData("fileno", "filenoValueType", "filenoValueData", "filenoValueScript", ev, "layout_fileno");
  1929. this._computeItemData("signer", "signerValueType", "signerValueData", "signerValueScript", ev, "layout_signer");
  1930. this._computeItemData("subject", "subjectValueType", "subjectValueData", "subjectValueScript", ev, "layout_subject");
  1931. this._computeItemData("mainSend", "mainSendValueType", "mainSendValueData", "mainSendValueScript", ev, "layout_mainSend");
  1932. this._computeItemData("attachment", "attachmentValueType", "attachmentValueData", "attachmentValueScript", ev, "layout_attachment");
  1933. this._computeItemData("issuanceUnit", "issuanceUnitValueType", "issuanceUnitValueData", "issuanceUnitValueScript", ev, "layout_issuanceUnit");
  1934. this._computeItemData("issuanceDate", "issuanceDateValueType", "issuanceDateValueData", "issuanceDateValueScript", ev, "layout_issuanceDate");
  1935. this._computeItemData("annotation", "annotationValueType", "annotationValueData", "annotationValueScript", ev, "layout_annotation");
  1936. this._computeItemData("copyto", "copytoValueType", "copytoValueData", "copytoValueScript", ev, "layout_copytoContent");
  1937. this._computeItemData("copyto2", "copyto2ValueType", "copyto2ValueData", "copyto2ValueScript", ev, "layout_copyto2Content");
  1938. this._computeItemData("editionUnit", "editionUnitValueType", "editionUnitValueData", "editionUnitValueScript", ev, "layout_edition_issuance_unit");
  1939. this._computeItemData("editionDate", "editionDateValueType", "editionDateValueData", "editionDateValueScript", ev, "layout_edition_issuance_date");
  1940. this._computeItemData("meetingAttend", "meetingAttendValueType", "meetingAttendValueData", "meetingAttendValueScript", ev, "layout_meetingAttendContent");
  1941. this._computeItemData("meetingLeave", "meetingLeaveValueType", "meetingLeaveValueData", "meetingLeaveValueScript", ev, "layout_meetingLeaveContent");
  1942. this._computeItemData("meetingSit", "meetingSitValueType", "meetingSitValueData", "meetingSitValueScript", ev, "layout_meetingSitContent");
  1943. this._computeItemData("meetingRecord", "meetingRecordValueType", "meetingRecordValueData", "meetingRecordValueScript", ev, "layout_meetingRecordContent");
  1944. Object.each(this.json.customFields, function(field, k){
  1945. this._computeCustomItemData(k, field, ev);
  1946. }.bind(this));
  1947. // if (this.customLayouts){
  1948. // this.customLayouts.each(function(l){
  1949. // this._computeCustomItemData(l, ev);
  1950. // }.bind(this))
  1951. // }
  1952. },
  1953. _loadValue: function(){
  1954. var data = this._getBusinessData();
  1955. },
  1956. reload: function(){
  1957. this.resetData();
  1958. },
  1959. resetData: function(diffFiletext){
  1960. if (this.editMode){ this._switchReadOrEditInline(); }
  1961. this._computeData(false);
  1962. this.pages = [];
  1963. this.contentNode.empty();
  1964. if (this.allowEdit) this.toolbar.childrenButton[0].setText(MWF.xApplication.process.Xform.LP.editdoc);
  1965. this.editMode = false;
  1966. this._createPage(function(control){
  1967. this._loadPageLayout(control);
  1968. this.setData(this.data, diffFiletext);
  1969. //this._checkSplitPage(this.pages[0]);
  1970. debugger;
  1971. this._repage();
  1972. }.bind(this));
  1973. },
  1974. isEmpty: function(){
  1975. var data = this.getData();
  1976. if( typeOf(data) !== "object" )return true;
  1977. return !data.filetext || data.filetext===this.json.defaultValue.filetext;
  1978. },
  1979. getData: function(){
  1980. //if (this.editMode){
  1981. debugger;
  1982. if (this.layout_copies) this.data.copies = this.layout_copies.get("text");
  1983. if (this.layout_secret) this.data.secret = this.layout_secret.get("text");
  1984. if (this.layout_priority) this.data.priority = this.layout_priority.get("text");
  1985. if (this.layout_redHeader) this.data.redHeader = this.layout_redHeader.get("html");
  1986. if (this.layout_fileno) this.data.fileno = this.layout_fileno.get("text");
  1987. if (this.layout_signerTitle) this.data.signerTitle = this.layout_signerTitle.get("text");
  1988. if (this.layout_signer) this.data.signer = this.layout_signer.get("text");
  1989. if (this.layout_subject) this.data.subject = this.layout_subject.get("html");
  1990. if (this.layout_mainSend) this.data.mainSend = this.layout_mainSend.get("text");
  1991. if (this.editMode) if (this.layout_filetext){
  1992. var text = this.layout_filetext.get("text");
  1993. text = text.replace(/\u3000*/g, "");
  1994. if (text && text !==this.json.defaultValue.filetext){
  1995. this.data.filetext = this.layout_filetext.get("html");
  1996. }else{
  1997. this.data.filetext = "";
  1998. }
  1999. }
  2000. if (this.layout_signer) this.data.signer = this.layout_signer.get("text");
  2001. if (this.layout_attachmentTitle) this.data.attachmentTitle = this.layout_attachmentTitle.get("text");
  2002. if (this.layout_attachment){
  2003. this._computeItemData("attachment", "attachmentValueType", "attachmentValueData", "attachmentValueScript", false, "layout_attachment");
  2004. // var atts = [];
  2005. // var nodes = this.layout_attachment.getElements(".doc_layout_attachment_content_name");
  2006. // if (nodes.length){
  2007. // nodes.each(function(node){
  2008. // atts.push(node.get("text"));
  2009. // });
  2010. // }
  2011. // this.data.attachment = atts;
  2012. }
  2013. if (this.layout_issuanceUnit) this.data.issuanceUnit = this.layout_issuanceUnit.get("html");
  2014. if (this.layout_issuanceDate) this.data.issuanceDate = this.layout_issuanceDate.get("text");
  2015. if (this.layout_annotation) this.data.annotation = this.layout_annotation.get("text");
  2016. if (this.layout_copytoTitle) this.data.copytoTitle = this.layout_copytoTitle.get("text");
  2017. if (this.layout_copytoContent) this.data.copyto = this.layout_copytoContent.get("text");
  2018. if (this.layout_copyto2Title) this.data.copyto2Title = this.layout_copyto2Title.get("text");
  2019. if (this.layout_copyto2Content) this.data.copyto2 = this.layout_copyto2Content.get("text");
  2020. if (this.layout_edition_issuance_unit) this.data.editionUnit = this.layout_edition_issuance_unit.get("text");
  2021. if (this.layout_edition_issuance_date) this.data.editionDate = this.layout_edition_issuance_date.get("text");
  2022. if (this.layout_meetingAttendTitle) this.data.meetingAttendTitle = this.layout_meetingAttendTitle.get("text");
  2023. if (this.layout_meetingLeaveTitle) this.data.meetingLeaveTitle = this.layout_meetingLeaveTitle.get("text");
  2024. if (this.layout_meetingSitTitle) this.data.meetingSitTitle = this.layout_meetingSitTitle.get("text");
  2025. if (this.layout_meetingAttendContent) this.data.meetingAttend = this.layout_meetingAttendContent.get("html");
  2026. if (this.layout_meetingLeaveContent) this.data.meetingLeave = this.layout_meetingLeaveContent.get("html");
  2027. if (this.layout_meetingSitContent) this.data.meetingSit = this.layout_meetingSitContent.get("html");
  2028. if (this.layout_meetingRecordContent) this.data.meetingRecord = this.layout_meetingRecordContent.get("html");
  2029. if (this.customLayouts){
  2030. this.customLayouts.each(function(l){
  2031. this.data[l.name] = l.node.get("html");
  2032. }.bind(this))
  2033. }
  2034. //}
  2035. return this.data;
  2036. },
  2037. setAttachmentData: function(){
  2038. if (!this.attachmentTemplete){
  2039. this.attachmentTemplete = this.layout_attachment.get("html");
  2040. }
  2041. this.layout_attachment.empty();
  2042. if (this.data.attachment && this.data.attachment.length && this.data.attachment.each){
  2043. //var tmpdiv = new Element("div", {"styles": {"display":"none"}}).inject(document.body);
  2044. var tmpdiv = new Element("div");
  2045. this.data.attachment.each(function(name, idx){
  2046. tmpdiv.set("html", this.attachmentTemplete);
  2047. var serialNode = tmpdiv.getElement(".doc_layout_attachment_content_serial");
  2048. var nameNode = tmpdiv.getElement(".doc_layout_attachment_content_name");
  2049. if (serialNode) serialNode.set("text", idx+1);
  2050. if (nameNode) nameNode.set("text", name);
  2051. var html = tmpdiv.get("html");
  2052. tmpdiv.empty();
  2053. this.layout_attachment.appendHTML(html);
  2054. }.bind(this));
  2055. tmpdiv.destroy();
  2056. }
  2057. },
  2058. setData: function(data, diffFiletext){
  2059. if (data){
  2060. this.data = data;
  2061. // this.data["$json"] = this.json;
  2062. this._setBusinessData(data);
  2063. if (this.layout_copies){
  2064. if (data.copies){
  2065. this.layout_copies.set("text", data.copies || " ");
  2066. }else{
  2067. this.layout_copies.set("html", "<span>&nbsp</span>");
  2068. }
  2069. }
  2070. if (this.layout_secret){
  2071. if (data.secret){
  2072. this.layout_secret.set("text", data.secret || " ");
  2073. }else{
  2074. this.layout_secret.set("html", "<span>&nbsp</span>");
  2075. }
  2076. }
  2077. if (this.layout_priority){
  2078. if (data.priority){
  2079. this.layout_priority.set("text", data.priority || " ");
  2080. }else{
  2081. this.layout_priority.set("html", "<span>&nbsp</span>");
  2082. }
  2083. }
  2084. if (this.layout_redHeader) this.layout_redHeader.set("html", data.redHeader || "");
  2085. if (this.layout_fileno) this.layout_fileno.set("text", data.fileno || " ");
  2086. if (this.layout_signerTitle) this.layout_signerTitle.set("text", data.signerTitle || " ");
  2087. if (this.layout_signer) this.layout_signer.set("text", data.signer || " ");
  2088. if (this.layout_subject) this.layout_subject.set("html", data.subject || " ");
  2089. if (this.layout_mainSend) this.layout_mainSend.set("text", data.mainSend || " ");
  2090. if (diffFiletext) {
  2091. this.layout_filetext.set("html", diffFiletext);
  2092. }else if (this.layout_filetext){
  2093. //this.layout_filetext.set("placeholder", this.json.defaultValue.filetext);
  2094. this.layout_filetext.set("html", data.filetext || "  ");
  2095. }
  2096. if (this.layout_signer) this.layout_signer.set("text", data.signer || "");
  2097. if (this.layout_attachmentTitle) this.layout_attachmentTitle.set("text", data.attachmentTitle || " ");
  2098. if (this.layout_attachment){
  2099. this.setAttachmentData();
  2100. }
  2101. if (this.layout_issuanceUnit) this.layout_issuanceUnit.set("html", data.issuanceUnit || " ");
  2102. if (this.layout_issuanceDate) this.layout_issuanceDate.set("text", data.issuanceDate || " ");
  2103. if (this.layout_annotation) this.layout_annotation.set("text", data.annotation || " ");
  2104. if (this.layout_copytoTitle) this.layout_copytoTitle.set("text", data.copytoTitle || " ");
  2105. if (this.layout_copytoContent) this.layout_copytoContent.set("text", data.copyto || " ");
  2106. if (this.layout_copyto2Title) this.layout_copyto2Title.set("text", data.copyto2Title || " ");
  2107. if (this.layout_copyto2Content) this.layout_copyto2Content.set("text", data.copyto2 || " ");
  2108. if (this.layout_edition_issuance_unit) this.layout_edition_issuance_unit.set("text", data.editionUnit || " ");
  2109. if (this.layout_edition_issuance_date) this.layout_edition_issuance_date.set("text", data.editionDate || " ");
  2110. if (this.layout_meetingAttendTitle) this.layout_meetingAttendTitle.set("text", data.meetingAttendTitle || this.json.defaultValue.meetingAttendTitle || " ");
  2111. if (this.layout_meetingLeaveTitle) this.layout_meetingLeaveTitle.set("text", data.meetingLeaveTitle || this.json.defaultValue.meetingLeaveTitle || " ");
  2112. if (this.layout_meetingSitTitle) this.layout_meetingSitTitle.set("text", data.meetingSitTitle || this.json.defaultValue.meetingSitTitle || " ");
  2113. if (this.layout_meetingAttendContent) this.layout_meetingAttendContent.set("html", data.meetingAttend || " ");
  2114. if (this.layout_meetingLeaveContent) this.layout_meetingLeaveContent.set("html", data.meetingLeave || " ");
  2115. if (this.layout_meetingSitContent) this.layout_meetingSitContent.set("html", data.meetingSit || " ");
  2116. if (this.layout_meetingRecordContent) this.layout_meetingRecordContent.set("html", data.meetingRecord || " ");
  2117. if (this.customLayouts){
  2118. this.customLayouts.each(function(l){
  2119. l.node.set("html", this.data[l.name] || " ");
  2120. }.bind(this))
  2121. }
  2122. debugger;
  2123. if (this.layout_issuanceUnit && this.layout_issuanceDate ){
  2124. var table = this.layout_issuanceUnit.getParent("table")
  2125. if (table && !table.hasClass("doc_layout_headIssuance")){
  2126. var unitWidth = o2.getTextSize(this.layout_issuanceUnit.get("text"), {
  2127. "font-size":"16pt",
  2128. "font-family":"'Times New Roman',仿宋",
  2129. "letter-spacing": "-0.4pt"
  2130. }).x;
  2131. var dateWidth = o2.getTextSize(this.layout_issuanceDate.get("text"), {
  2132. "font-size":"16pt",
  2133. "font-family":"'Times New Roman',仿宋",
  2134. "letter-spacing": "-0.4pt"
  2135. }).x;
  2136. // var unitWidth = this.layout_issuanceUnit.getSize().x;
  2137. // var dateWidth = this.layout_issuanceDate.getSize().x;
  2138. if (unitWidth<dateWidth){
  2139. var flagTd = this.layout_issuanceUnit.getParent("td").getNext("td");
  2140. if (flagTd){
  2141. var pt = ((dateWidth-unitWidth)/96)*72 +32+32;
  2142. flagTd.setStyle("width", ""+pt+"pt");
  2143. }
  2144. table = this.layout_issuanceDate.getParent("table");
  2145. table.setStyle("width", "auto");
  2146. flagTd = this.layout_issuanceDate.getParent("td").getNext("td");
  2147. if (flagTd) flagTd.setStyle("width", "32pt");
  2148. var p = this.layout_issuanceDate.getParent("p");
  2149. if (p) p.setStyle("text-align", "right");
  2150. }else{
  2151. var flagTd = this.layout_issuanceUnit.getParent("td").getNext("td");
  2152. if (flagTd) flagTd.setStyle("width", "32pt");
  2153. var table = this.layout_issuanceUnit.getParent("table");
  2154. var x = table.getSize().x;
  2155. table = this.layout_issuanceDate.getParent("table");
  2156. table.setStyle("width", ""+x+"px");
  2157. flagTd = this.layout_issuanceDate.getParent("td").getNext("td");
  2158. if (flagTd) flagTd.setStyle("width", "32pt");
  2159. var p = this.layout_issuanceDate.getParent("p");
  2160. if (p) p.setStyle("text-align", "center");
  2161. }
  2162. }
  2163. }
  2164. var coptyToTitleNode = (this.layout_copytoTitle || this.layout_copyto2Title);
  2165. if (coptyToTitleNode){
  2166. var editionTable = coptyToTitleNode.getParent("table");
  2167. if (editionTable) if (editionTable.get("data-compute-style")=="y"){
  2168. var rows = editionTable.rows;
  2169. for (var i=0; i<rows.length; i++){
  2170. var cell = rows[i].cells[0];
  2171. var tmp = cell.getElement(".doc_layout_edition_issuance_unit");
  2172. if (!tmp) tmp = cell.getElement(".doc_layout_edition_issuance_date");
  2173. if (!tmp){
  2174. var text = cell.get("text").trim();
  2175. var l = 14*text.length;
  2176. cell.setStyles({
  2177. "max-width": ""+l+"pt",
  2178. "min-width": ""+l+"pt"
  2179. });
  2180. }
  2181. }
  2182. }
  2183. }
  2184. }
  2185. },
  2186. createErrorNode: function(text){
  2187. var node = new Element("div");
  2188. var iconNode = new Element("div", {
  2189. "styles": {
  2190. "width": "20px",
  2191. "height": "20px",
  2192. "float": "left",
  2193. "background": "url("+"../x_component_process_Xform/$Form/default/icon/error.png) center center no-repeat"
  2194. }
  2195. }).inject(node);
  2196. var textNode = new Element("div", {
  2197. "styles": {
  2198. "line-height": "20px",
  2199. "margin-left": "20px",
  2200. "color": "red",
  2201. "word-break": "keep-all"
  2202. },
  2203. "text": text
  2204. }).inject(node);
  2205. return node;
  2206. },
  2207. notValidationMode: function(text){
  2208. if (!this.isNotValidationMode){
  2209. this.isNotValidationMode = true;
  2210. this.node.store("borderStyle", this.node.getStyles("border-left", "border-right", "border-top", "border-bottom"));
  2211. this.node.setStyle("border", "1px solid red");
  2212. this.errNode = this.createErrorNode(text).inject(this.node, "after");
  2213. this.showNotValidationMode(this.node);
  2214. }
  2215. },
  2216. showNotValidationMode: function(node){
  2217. var p = node.getParent("div");
  2218. if (p){
  2219. if (p.get("MWFtype") == "tab$Content"){
  2220. if (p.getParent("div").getStyle("display")=="none"){
  2221. var contentAreaNode = p.getParent("div").getParent("div");
  2222. var tabAreaNode = contentAreaNode.getPrevious("div");
  2223. var idx = contentAreaNode.getChildren().indexOf(p.getParent("div"));
  2224. var tabNode = tabAreaNode.getLast().getFirst().getChildren()[idx];
  2225. tabNode.click();
  2226. p = tabAreaNode.getParent("div");
  2227. }
  2228. }
  2229. this.showNotValidationMode(p);
  2230. }
  2231. },
  2232. validationMode: function(){
  2233. if (this.isNotValidationMode){
  2234. this.isNotValidationMode = false;
  2235. this.node.setStyles(this.node.retrieve("borderStyle"));
  2236. if (this.errNode){
  2237. this.errNode.destroy();
  2238. this.errNode = null;
  2239. }
  2240. }
  2241. },
  2242. validationConfigItem: function(routeName, data){
  2243. var flag = (data.status=="all") ? true: (routeName == data.decision);
  2244. if (flag){
  2245. var n = this.getData();
  2246. var v = (data.valueType=="value") ? n : n.length;
  2247. switch (data.operateor){
  2248. case "isnull":
  2249. if (!v){
  2250. this.notValidationMode(data.prompt);
  2251. return false;
  2252. }
  2253. break;
  2254. case "notnull":
  2255. if (v){
  2256. this.notValidationMode(data.prompt);
  2257. return false;
  2258. }
  2259. break;
  2260. case "gt":
  2261. if (v>data.value){
  2262. this.notValidationMode(data.prompt);
  2263. return false;
  2264. }
  2265. break;
  2266. case "lt":
  2267. if (v<data.value){
  2268. this.notValidationMode(data.prompt);
  2269. return false;
  2270. }
  2271. break;
  2272. case "equal":
  2273. if (v==data.value){
  2274. this.notValidationMode(data.prompt);
  2275. return false;
  2276. }
  2277. break;
  2278. case "neq":
  2279. if (v!=data.value){
  2280. this.notValidationMode(data.prompt);
  2281. return false;
  2282. }
  2283. break;
  2284. case "contain":
  2285. if (v.indexOf(data.value)!=-1){
  2286. this.notValidationMode(data.prompt);
  2287. return false;
  2288. }
  2289. break;
  2290. case "notcontain":
  2291. if (v.indexOf(data.value)==-1){
  2292. this.notValidationMode(data.prompt);
  2293. return false;
  2294. }
  2295. break;
  2296. }
  2297. }
  2298. return true;
  2299. },
  2300. validationConfig: function(routeName, opinion){
  2301. if (this.json.validationConfig){
  2302. if (this.json.validationConfig.length){
  2303. for (var i=0; i<this.json.validationConfig.length; i++) {
  2304. var data = this.json.validationConfig[i];
  2305. if (!this.validationConfigItem(routeName, data)) return false;
  2306. }
  2307. }
  2308. return true;
  2309. }
  2310. return true;
  2311. },
  2312. validation: function(routeName, opinion){
  2313. if (!this.validationConfig(routeName, opinion)) return false;
  2314. if (!this.json.validation) return true;
  2315. if (!this.json.validation.code) return true;
  2316. var flag = this.form.Macro.exec(this.json.validation.code, this);
  2317. if (!flag) flag = MWF.xApplication.process.Xform.LP.notValidation;
  2318. if (flag.toString()!="true"){
  2319. this.notValidationMode(flag);
  2320. return false;
  2321. }
  2322. return true;
  2323. },
  2324. removeDisplayNone: function(node){
  2325. var n = node.getFirst();
  2326. while (n){
  2327. if (n.getStyle("display")=="none"){
  2328. var tmp = n.getNext();
  2329. n.destroy();
  2330. n = tmp;
  2331. }else{
  2332. n = this.removeDisplayNone(n);
  2333. n = n.getNext();
  2334. }
  2335. }
  2336. return node;
  2337. },
  2338. toWord: function(callback, name){
  2339. debugger;
  2340. var docNmae = name || "";
  2341. if (!docNmae){
  2342. try{
  2343. docNmae = this.json.toWordFilename || this.form.businessData.data.subject || this.form.businessData.data["$work"].title
  2344. }catch (e) {}
  2345. }
  2346. var toEdit = false;
  2347. if (this.editMode){
  2348. toEdit = true;
  2349. this._readFiletext();
  2350. }
  2351. //this._returnScale();
  2352. this.zoom(1);
  2353. this.pages = [];
  2354. this.contentNode.empty();
  2355. this._createPage(function(control){
  2356. this._loadPageLayout(control);
  2357. this.setData(this.data);
  2358. this._checkScale();
  2359. this.node.setStyles({
  2360. "height":"auto"
  2361. });
  2362. //var content = this.contentNode.getFirst().getFirst().get("html");
  2363. var tmpNode = this.contentNode.getFirst().getFirst().clone(true);
  2364. var htmlNode = tmpNode.getLast();
  2365. htmlNode = this.removeDisplayNone(htmlNode);
  2366. var content = "<html xmlns:v=\"urn:schemas-microsoft-com:vml\"><head><meta charset=\"UTF-8\" /></head><body>"+tmpNode.get("html")+"</body></html>";
  2367. var fileName = docNmae || this.json.toWordFilename || "$doc";
  2368. fileName = fileName+".doc";
  2369. var body = {
  2370. "fileName": fileName,
  2371. "site": this.json.toWordSite || "$doc",
  2372. "content": content
  2373. };
  2374. o2.Actions.get("x_processplatform_assemble_surface").docToWord(this.form.businessData.work.id, body, function(json){
  2375. if (this.form.businessData.workCompleted){
  2376. o2.Actions.get("x_processplatform_assemble_surface").getAttachmentWorkcompleted(json.data.id, this.form.businessData.workCompleted.id,function(attjson){
  2377. if (callback) callback(attjson.data);
  2378. this.showToWord(attjson.data);
  2379. }.bind(this));
  2380. }else{
  2381. o2.Actions.get("x_processplatform_assemble_surface").getAttachment(json.data.id, this.form.businessData.work.id,function(attjson){
  2382. if (callback) callback(attjson.data);
  2383. this.showToWord(attjson.data);
  2384. }.bind(this));
  2385. }
  2386. }.bind(this));
  2387. tmpNode.destroy();
  2388. if (!toEdit){
  2389. this._readFiletext();
  2390. }else{
  2391. this._createEditor();
  2392. }
  2393. }.bind(this));
  2394. },
  2395. docToWord: function(){
  2396. debugger;
  2397. var flag = true;
  2398. if (this.json.toWordConditionScript && this.json.toWordConditionScript.code){
  2399. flag = !!this.form.Macro.exec(this.json.toWordConditionScript.code, this);
  2400. }
  2401. if (flag){
  2402. this.toWord();
  2403. }
  2404. },
  2405. showToWord: function(att){
  2406. var site = this.json.toWordSite || "$doc";
  2407. var attModule = this.form.all[site];
  2408. if (attModule){
  2409. attModule.attachmentController.clear();
  2410. attModule.attachmentController.addAttachment(att);
  2411. }
  2412. }
  2413. });