Documenteditor.js 104 KB

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