Documenteditor.js 99 KB

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