Documenteditor.js 99 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138
  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.toolNode = new Element("div", {"styles": this.css.doc_toolbar}).inject(this.node);
  545. this.contentNode = new Element("div", {"styles": this.css.doc_content}).inject(this.node);
  546. if (!this.form.isLoaded){
  547. this.form.addEvent("afterModulesLoad", function(){this.loadDocumentEditor(callback);}.bind(this));
  548. }else{
  549. this.loadDocumentEditor(callback);
  550. }
  551. },
  552. loadDocumentEditor: function(callback){
  553. this._loadToolbars();
  554. this._loadFiletextPage(function(){
  555. if (this.options.pageShow!=="double"){
  556. this._singlePage();
  557. }else{
  558. this._doublePage();
  559. }
  560. // this.form.addEvent("beforeProcess", function(){
  561. // this.resetData();
  562. // if (this.checkSaveNewEdition()) this.saveNewDataEdition();
  563. // this.notSaveResetData = true;
  564. // }.bind(this));
  565. this.form.addEvent("beforeSave", function(){
  566. this.resetData();
  567. this.checkSaveNewEdition();
  568. //if (!this.notSaveResetData) this.resetData();
  569. }.bind(this));
  570. if (this.json.toWord=="y"){
  571. if (this.json.toWordTrigger=="open") this.docToWord();
  572. if (this.json.toWordTrigger=="save") this.form.addEvent("beforeSave", this.docToWord.bind(this));
  573. if (this.json.toWordTrigger=="submit") this.form.addEvent("beforeProcess", this.docToWord.bind(this));
  574. }
  575. if (!layout.mobile) this.loadSideToolbar();
  576. o2.load("/o2_lib/diff-match-patch/diff_match_patch.js");
  577. var id = this.form.businessData.data["$work"].job;
  578. o2.Actions.load("x_processplatform_assemble_surface").DocumentVersionAction.listWithJobCategory(id, this.json.id, function(json){
  579. this.historyDocumentList = json.data;
  580. if (this.historyDocumentList.length){
  581. o2.Actions.load("x_processplatform_assemble_surface").DocumentVersionAction.get(this.historyDocumentList[this.historyDocumentList.length-1].id, function(json){
  582. var data = JSON.parse(json.data.data);
  583. this.originaHistoryData = data.data;
  584. }.bind(this));
  585. }
  586. }.bind(this));
  587. if (callback) callback();
  588. }.bind(this));
  589. if (!this.form.documenteditorList) this.form.documenteditorList=[];
  590. this.form.documenteditorList.push(this);
  591. },
  592. checkSaveNewEdition: function(callback){
  593. debugger;
  594. if (!this.allowEdit || !this.data.filetext || this.data.filetext == this.json.defaultValue.filetext) return false;
  595. if (this.form.businessData.work){
  596. var originaData = this.form.businessData.originalData[this.json.id];
  597. var editionData = {"category": this.json.id};
  598. if (!originaData || !originaData.filetext || !this.originaHistoryData){
  599. //保存原始版本
  600. editionData.data = JSON.stringify({"data": this.data.filetext});
  601. }else if (originaData.filetext!=this.data.filetext){
  602. //保存历史版本
  603. var data = this.data.filetext;
  604. var earlyData = originaData.filetext;
  605. var dmp = new diff_match_patch();
  606. var diff_d = dmp.diff_main(earlyData, data);
  607. dmp.diff_cleanupSemantic(diff_d);
  608. var patch_list = dmp.patch_make(earlyData, data, diff_d);
  609. editionData.data = JSON.stringify({"patchs": dmp.patch_toText(patch_list)});
  610. }else{
  611. return false;
  612. }
  613. o2.Actions.load("x_processplatform_assemble_surface").DocumentVersionAction.create(this.form.businessData.work.id, editionData, function(json){
  614. //originaData.filetext = this.data.filetext;
  615. if (callback) callback();
  616. }.bind(this));
  617. }
  618. },
  619. // saveNewDataEdition: function(callback){
  620. // if (this.form.businessData.work){
  621. // var editionData = {"category": this.json.id};
  622. // if (this.form.businessData.originalData[this.json.id] && this.form.businessData.originalData[this.json.id].filetext){
  623. // var data = this.data.filetext;
  624. // var earlyData = this.form.businessData.originalData[this.json.id].filetext;
  625. // var dmp = new diff_match_patch();
  626. // var diff_d = dmp.diff_main(earlyData, data);
  627. // dmp.diff_cleanupSemantic(diff_d);
  628. // var patch_list = dmp.patch_make(earlyData, data, diff_d);
  629. // editionData.data = {"patchs": dmp.patch_toText(patch_list)};
  630. //
  631. // }else{
  632. // editionData.data = {"data": this.data.filetext};
  633. // }
  634. // o2.Actions.load("x_processplatform_assemble_surface").DocumentVersionAction.create(this.form.businessData.work.id, editionData, function(json){
  635. // this.form.businessData.originalData[this.json.id] = this.data.filetext;
  636. // if (callback) callback();
  637. // }.bind(this));
  638. // }
  639. // },
  640. resizeToolbar: function(){
  641. if (this.toolbarNode){
  642. var p = this.toolNode.getPosition(this.form.app.content);
  643. var size = this.toolNode.getSize();
  644. var pl = this.toolbarNode.getStyle("padding-left").toInt();
  645. var pr = this.toolbarNode.getStyle("padding-right").toInt();
  646. var x = size.x-pl-pr;
  647. if (p.y<0){
  648. this.toolbarNode.inject(this.form.node);
  649. this.toolbarNode.setStyles({
  650. "position": "absolute",
  651. "width": ""+x+"px",
  652. "z-index": 20000,
  653. "top": "0px",
  654. "left": ""+p.x+"px"
  655. });
  656. }else{
  657. this.toolbarNode.inject(this.toolNode);
  658. this.toolbarNode.setStyles({"position": "static"});
  659. }
  660. }
  661. },
  662. resizeSidebar: function(){
  663. if (this.sidebarNode){
  664. var fileTextNode = this.contentNode.getElement("div.doc_layout_filetext");
  665. if (fileTextNode){
  666. this.sidebarNode.position({
  667. relativeTo: fileTextNode,
  668. position: 'topLeft',
  669. edge: 'topRight',
  670. offset: {"x": -20, "y": 60}
  671. });
  672. var p = fileTextNode.getPosition(this.form.app.content);
  673. var ptop = fileTextNode.getPosition(this.node);
  674. //if ((p.y+s.y)<0) this.sidebarNode.setStyle("top", p.y+s.y);
  675. if (p.y<0){
  676. var top = ptop.y-p.y+200;
  677. this.sidebarNode.setStyle("top", top);
  678. }
  679. // var p = fileTextNode.getPosition();
  680. // this.sidebarNode.setStyle("top", p.y);
  681. }
  682. }
  683. },
  684. loadSideToolbar: function(){
  685. if (this.allowEdit){
  686. if (this.pages.length){
  687. var fileTextNode = this.pages[0].getElement("div.doc_layout_filetext");
  688. if (fileTextNode){
  689. this.sidebarNode = new Element("div", {"styles": this.css.doc_sidebar}).inject(this.node);
  690. this.resizeSidebar();
  691. this.scrollNode = this.sidebarNode.getParentSrcollNode();
  692. if (this.scrollNode){
  693. this.scrollNode.addEvent("scroll", function(){
  694. this.resizeSidebar();
  695. }.bind(this));
  696. }
  697. 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>";
  698. this.sidebarNode.set("html", html);
  699. MWF.require("MWF.widget.Toolbar", function() {
  700. this.sideToolbar = new MWF.widget.Toolbar(this.sidebarNode, {"style": "documentEdit_side"}, this);
  701. this.sideToolbar.load();
  702. }.bind(this));
  703. }
  704. }
  705. }
  706. },
  707. _returnScale: function(){
  708. this.isScale = false;
  709. this.scale = 0;
  710. this.contentNode.setStyles({
  711. "transform":"scale(1)",
  712. });
  713. if (this.pages.length){
  714. this.pages.each(function(page){
  715. page.setStyles({
  716. "transform":"scale(1)",
  717. });
  718. });
  719. }
  720. this.node.setStyles({
  721. "height": "auto"
  722. });
  723. },
  724. _checkScale: function(offset){
  725. offset = 0;
  726. if (this.pages.length){
  727. var pageSize = this.pages[0].getSize();
  728. var contentSize = this.contentNode.getSize();
  729. var contentWidth = (offset) ? contentSize.x-20-offset : contentSize.x-20;
  730. if (contentWidth<pageSize.x){
  731. this.isScale = true;
  732. var scale = (contentWidth)/pageSize.x;
  733. this.scale = scale;
  734. this.zoom();
  735. this.resetNodeSize();
  736. }
  737. }
  738. },
  739. zoom: function(scale){
  740. if (scale) this.scale = scale;
  741. var w = this.node.getSize().x;
  742. if (this.history && this.history.historyListAreaNode) w = w-this.history.historyListAreaNode.getComputedSize().totalWidth-2;
  743. w = w/this.scale;
  744. this.contentNode.setStyles({
  745. "transform":"scale("+this.scale+")",
  746. "transform-origin": "0px 0px",
  747. "overflow": "hidden",
  748. "width": ""+w+"px"
  749. });
  750. },
  751. _switchReadOrEdit: function(){
  752. if (this.editMode){
  753. this._readFiletext();
  754. if (this.allowEdit) this.toolbar.childrenButton[0].setText(MWF.xApplication.process.Xform.LP.editdoc);
  755. this.editMode = false;
  756. }else{
  757. this._editFiletext();
  758. if (this.allowEdit) this.toolbar.childrenButton[0].setText(MWF.xApplication.process.Xform.LP.editdocCompleted)
  759. this.editMode = true;
  760. }
  761. },
  762. _switchReadOrEditInline: function(){
  763. if (this.editMode){
  764. this._readFiletext();
  765. if (this.allowEdit){
  766. if (!layout.mobile) this.sideToolbar.childrenButton[0].setText(MWF.xApplication.process.Xform.LP.editdoc);
  767. this.toolbar.childrenButton[0].setText(MWF.xApplication.process.Xform.LP.editdoc);
  768. }
  769. this.editMode = false;
  770. }else{
  771. this._editFiletext("inline");
  772. if (this.allowEdit){
  773. if (!layout.mobile) this.sideToolbar.childrenButton[0].setText(MWF.xApplication.process.Xform.LP.editdocCompleted);
  774. this.toolbar.childrenButton[0].setText(MWF.xApplication.process.Xform.LP.editdocCompleted);
  775. }
  776. this.editMode = true;
  777. }
  778. },
  779. _printDoc: function(){
  780. this.toWord(function(data){
  781. if (this.form.businessData.work && !this.form.businessData.work.completedTime){
  782. this.form.workAction.getAttachmentStream(data.id, this.form.businessData.work.id);
  783. }else{
  784. this.form.workAction.getWorkcompletedAttachmentStream(data.id, ((this.form.businessData.workCompleted) ? this.form.businessData.workCompleted.id : this.form.businessData.work.id));
  785. }
  786. }.bind(this), "$doc.doc");
  787. },
  788. _historyDoc: function(){
  789. this.getHistory(function(){
  790. //this.history.play();
  791. }.bind(this));
  792. },
  793. getHistory: function(callback){
  794. if (this.history){
  795. this.history.active(function(){
  796. if (callback) callback();
  797. });
  798. }else{
  799. MWF.xDesktop.requireApp("process.Xform", "widget.DocumentHistory", function(){
  800. this.history = new MWF.xApplication.process.Xform.widget.DocumentHistory(this);
  801. this.history.load(function(){
  802. if (callback) callback();
  803. });
  804. }.bind(this));
  805. }
  806. },
  807. htmlToText: function(html){
  808. var tmpdiv = new Element("div", {"html": html});
  809. var text = tmpdiv.get("text");
  810. tmpdiv.destroy();
  811. return text;
  812. },
  813. _readFiletext: function(){
  814. //this._returnScale();
  815. this.zoom(1);
  816. if (this.filetextEditor) this.filetextEditor.destroy();
  817. if (this.filetextScrollNode){
  818. if (this.reLocationFiletextToolbarFun){
  819. this.filetextScrollNode.removeEvent("scroll", this.reLocationFiletextToolbarFun);
  820. //this.form.app.removeEvent("resize", this.reLocationFiletextToolbarFun);
  821. this.reLocationFiletextToolbarFun = null;
  822. }
  823. this.filetextScrollNode = null;
  824. }
  825. if (this.filetextToolbarNode) this.filetextToolbarNode = null;
  826. this.layout_filetext.setAttribute('contenteditable', false);
  827. this.data = this.getData();
  828. // debugger;
  829. if (!this.data.filetext){
  830. //this.data.filetext = this.json.defaultValue.filetext;
  831. this.layout_filetext.set("html", this.json.defaultValue.filetext);
  832. }
  833. //this._checkSplitPage(this.pages[0]);
  834. this._repage();
  835. },
  836. _editFiletext: function(inline){
  837. this._returnScale();
  838. this.zoom(1);
  839. this._singlePage();
  840. this.pages = [];
  841. this.contentNode.empty();
  842. this._createPage(function(control){
  843. this._loadPageLayout(control);
  844. // var docData = this._getBusinessData();
  845. // if (!docData) docData = this._getDefaultData();
  846. if (this.data.filetext == this.json.defaultValue.filetext) this.data.filetext = "";
  847. this.setData(this.data);
  848. this._checkScale();
  849. this.node.setStyles({
  850. "height":"auto"
  851. });
  852. this._createEditor(inline);
  853. }.bind(this));
  854. },
  855. _createEditor: function(inline){
  856. if (this.allowEdit){
  857. this.loadCkeditorFiletext(function(e){
  858. e.editor.focus();
  859. e.editor.getSelection().scrollIntoView();
  860. //this.getFiletextToolber();
  861. //this.filetextToolbarNode.inject(this.layout_filetext.getOffsetParent());
  862. this.locationFiletextToolbar();
  863. }.bind(this), inline);
  864. }
  865. },
  866. getFiletextToolber: function(){
  867. if (this.filetextEditor) {
  868. if (!this.filetextToolbarNode) {
  869. var className = "cke_editor_" + this.filetextEditor.name;
  870. var filetextToolbarNode = $$("." + className)[0];
  871. this.filetextToolbarNode = filetextToolbarNode;
  872. //filetextToolbarNode.destroy();
  873. }
  874. }
  875. },
  876. reLocationFiletextToolbar: function(){
  877. this.getFiletextToolber();
  878. // if (this.filetextToolbarNode){
  879. // this.filetextToolbarNode.setStyle("display", "block");
  880. // var offsetNode = this.layout_filetext.getOffsetParent();
  881. //
  882. // this.filetextToolbarNode.setStyle("left", 0);
  883. // var h = this.filetextToolbarNode.getSize().y;
  884. // var p = this.layout_filetext.getPosition(offsetNode).y-h;
  885. //
  886. // var postion = this.layout_filetext.getPosition(this.form.app.content);
  887. // if (postion.y-h<0){
  888. // this.filetextToolbarNode.inject(this.form.app.content);
  889. // this.filetextToolbarNode.setStyle("top", 0);
  890. // this.filetextToolbarNode.setStyle("left", ""+postion.x+"px");
  891. // }else{
  892. // this.filetextToolbarNode.inject(offsetNode);
  893. // this.filetextToolbarNode.setStyle("top", "" + p + "px");
  894. // this.filetextToolbarNode.setStyle("left", 0);
  895. // this.filetextToolbarNode.setStyle("left", "auto");
  896. // }
  897. // }
  898. if (this.filetextToolbarNode){
  899. if (!this.filetextScrollNode){
  900. var scrollNode = this.contentNode;
  901. while (scrollNode && (scrollNode.getScrollSize().y<=scrollNode.getSize().y || (scrollNode.getStyle("overflow")!=="auto" && scrollNode.getStyle("overflow-y")!=="auto"))){
  902. scrollNode = scrollNode.getParent();
  903. }
  904. this.filetextScrollNode = scrollNode;
  905. }
  906. var h = this.filetextToolbarNode.getSize().y;
  907. var position = this.layout_filetext.getPosition();
  908. var size = this.layout_filetext.getSize();
  909. var contentSize = this.filetextScrollNode.getSize();
  910. if (position.y<0 && size.y+position.y+h<contentSize.y){
  911. var top = size.y+position.y;
  912. this.filetextToolbarNode.setStyle("top", ""+top+"px");
  913. }else if (position.y-h<0){
  914. this.filetextToolbarNode.setStyle("top", 0);
  915. }else{
  916. var p = this.layout_filetext.getPosition().y-h;
  917. this.filetextToolbarNode.setStyle("top", "" + p + "px");
  918. }
  919. }
  920. //
  921. // this.filetextToolbarNode.inject(offsetNode);
  922. //
  923. //
  924. // this.filetextToolbarNode.setStyle("top", ""+p+"px");
  925. },
  926. locationFiletextToolbar: function(){
  927. this.reLocationFiletextToolbar();
  928. if (this.filetextToolbarNode) {
  929. var scrollNode = this.contentNode;
  930. while (scrollNode && (scrollNode.getScrollSize().y<=scrollNode.getSize().y || (scrollNode.getStyle("overflow")!=="auto" && scrollNode.getStyle("overflow-y")!=="auto"))){
  931. scrollNode = scrollNode.getParent();
  932. }
  933. if (scrollNode){
  934. this.filetextScrollNode = scrollNode;
  935. this.reLocationFiletextToolbarFun = this.reLocationFiletextToolbar.bind(this);
  936. this.filetextScrollNode.addEvent("scroll", this.reLocationFiletextToolbarFun);
  937. }
  938. }
  939. },
  940. _isAllowEdit:function(){
  941. if (this.readonly) return false;
  942. if (this.json.allowEdit=="n") return false;
  943. if (this.json.allowEdit=="s"){
  944. if (this.json.allowEditScript && this.json.allowEditScript.code){
  945. return !!this.form.Macro.exec(this.json.allowEditScript.code, this);
  946. }
  947. }
  948. return true;
  949. },
  950. _isAllowPrint: function(){
  951. if (this.json.allowPrint=="n") return false;
  952. if (this.json.allowPrint=="s"){
  953. if (this.json.allowPrintScript && this.json.allowPrintScript.code){
  954. return !!this.form.Macro.exec(this.json.allowPrintScript.code, this);
  955. }
  956. }
  957. return true;
  958. },
  959. _getEdit: function(name, typeItem, scriptItem){
  960. switch (this.json[typeItem]) {
  961. case "y":
  962. return true;
  963. case "n":
  964. return false;
  965. case "s":
  966. if (this.json[scriptItem] && this.json[scriptItem].code){
  967. return !!this.form.Macro.exec(this.json[scriptItem].code, this);
  968. }
  969. return true;
  970. }
  971. },
  972. loadCkeditorStyle: function(node){
  973. if (node){
  974. o2.load("ckeditor", function(){
  975. //CKEDITOR.disableAutoInline = true;
  976. node.setAttribute('contenteditable', true);
  977. var editor = CKEDITOR.inline(this.layout_filetext, this._getEditorConfig());
  978. this.filetextEditor.on("instanceReady", function(e){
  979. if (callback) callback(e);
  980. }.bind(this));
  981. }.bind(this));
  982. }
  983. },
  984. _loadToolbars: function(){
  985. var html ="";
  986. if (this.allowEdit){
  987. //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>";
  988. 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>";
  989. //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>";
  990. }
  991. if (this.allowPrint){
  992. 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>";
  993. }
  994. if (this.allowPrint){
  995. 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>";
  996. }
  997. this.toolbarNode = new Element("div", {"styles": this.css.doc_toolbar_node}).inject(this.toolNode);
  998. this.toolbarNode.set("html", html);
  999. MWF.require("MWF.widget.Toolbar", function() {
  1000. this.toolbar = new MWF.widget.Toolbar(this.toolbarNode, {"style": "documentEdit"}, this);
  1001. this.toolbar.load();
  1002. }.bind(this));
  1003. this.scrollNode = this.toolbarNode.getParentSrcollNode();
  1004. if (this.scrollNode){
  1005. this.scrollNode.addEvent("scroll", function(){
  1006. this.resizeToolbar();
  1007. }.bind(this));
  1008. }
  1009. this.doublePageAction = new Element("div", {"styles": this.css.doc_toolbar_doublePage, "text": MWF.xApplication.process.Xform.LP.doublePage}).inject(this.toolbarNode);
  1010. this.doublePageAction.addEvent("click", function(){
  1011. if (this.options.pageShow!=="double"){
  1012. this._doublePage();
  1013. }else{
  1014. this._singlePage();
  1015. }
  1016. }.bind(this));
  1017. // this.zoomSelectAction = new Element("select", {"styles": {"float": "right"}}).inject(this.toolbarNode);
  1018. // var options = "<option value='2'>200%</option> " +
  1019. // "<option value='1.75'>175%</option>" +
  1020. // "<option value='1.5'>150%</option>" +
  1021. // "<option value='1' selected>100%</option>" +
  1022. // "<option value='0.75'>75%</option>" +
  1023. // "<option value='0.5'>50%</option>" +
  1024. // "<option value='0.25'>25%</option>"
  1025. // this.zoomSelectAction.set("html", options);
  1026. // this.zoomSelectAction.addEvent("change", function(e){
  1027. // this._returnScale();
  1028. // this.scale = e.target.options[e.target.selectedIndex].value;
  1029. // this.zoom();
  1030. // }.bind(this));
  1031. },
  1032. _repage: function(delay){
  1033. if (this.options.pageShow!=="double"){
  1034. this._singlePage();
  1035. }else{
  1036. this._doublePage();
  1037. }
  1038. if (delay){
  1039. if (!this.form.isLoaded){
  1040. this.form.addEvent("afterLoad", this._checkScale.bind(this));
  1041. }else{
  1042. this._checkScale();
  1043. }
  1044. }else{
  1045. this._checkScale();
  1046. }
  1047. },
  1048. _singlePage: function(){
  1049. //if (this.editMode) this._readFiletext();
  1050. this.zoom(1);
  1051. this._checkScale();
  1052. var w = this.contentNode.getSize().x;
  1053. var count = 1;
  1054. var docPageFullWidth = (this.scale) ? this.scale*this.options.docPageFullWidth : this.options.docPageFullWidth;
  1055. //var docPageFullWidth = this.options.docPageFullWidt;
  1056. var pageWidth = count * docPageFullWidth;
  1057. var margin = (w-pageWidth)/(count+1);
  1058. if (this.isScale){
  1059. margin = "10";
  1060. }
  1061. if (this.scale) margin = margin/this.scale;
  1062. this.pages.each(function(page, i){
  1063. page.setStyles({
  1064. "float": "left",
  1065. "margin-left": ""+margin+"px"
  1066. });
  1067. });
  1068. this.resetNodeSize();
  1069. // this.pages.each(function(page){
  1070. // page.setStyle("float", "none");
  1071. // });
  1072. this.resizeSidebar();
  1073. this.options.pageShow="single";
  1074. this.doublePageAction.set("text", MWF.xApplication.process.Xform.LP.doublePage);
  1075. },
  1076. resetNodeSize: function(){
  1077. var contentSize = this.contentNode.getSize();
  1078. var toolbarSize = this.toolNode.getSize();
  1079. contentHeight = contentSize.y;
  1080. var h = contentHeight+toolbarSize.y+20;
  1081. //h = h - contentSize.y*(1-this.scale);
  1082. this.node.setStyles({
  1083. "height":""+h+"px"
  1084. });
  1085. },
  1086. createWaitSplitPage: function(){
  1087. this.node.mask({
  1088. "style": {
  1089. "background-color": "#cccccc",
  1090. "opacity": 0.3
  1091. }
  1092. });
  1093. this.waitSplitPageNode = new Element("div", {"styles": this.form.css.waitSplitPageNode, "text": MWF.xApplication.process.Xform.LP.computePage}).inject(this.node);
  1094. this.waitSplitPageNode.position({
  1095. "relativeTo": this.node,
  1096. "position": "topRight",
  1097. "edge": "topRight",
  1098. "offset": {
  1099. "x": -10,
  1100. "y": 45
  1101. }
  1102. });
  1103. //this.form.notice(MWF.xApplication.process.Xform.LP.computePage, "info", this.node);
  1104. },
  1105. clearWaitSplitPage: function(){
  1106. this.node.unmask();
  1107. if (this.waitSplitPageNode) this.waitSplitPageNode.destroy();
  1108. this.waitSplitPageNode = null;
  1109. },
  1110. _doublePage: function(){
  1111. if (this.editMode) this._switchReadOrEditInline();
  1112. this.zoom(1);
  1113. this.createWaitSplitPage();
  1114. window.setTimeout(function(){
  1115. this._checkSplitPage(this.pages[0]);
  1116. this.zoom(1);
  1117. var w = this.contentNode.getSize().x;
  1118. var toPageWidth = (w-100)/2;
  1119. scale = toPageWidth/this.options.docPageFullWidth;
  1120. if (scale<1) this.zoom(scale);
  1121. var docPageFullWidth = (this.scale) ? this.scale*this.options.docPageFullWidth : this.options.docPageFullWidth;
  1122. //var docPageFullWidth = this.options.docPageFullWidth;
  1123. var w = this.contentNode.getSize().x;
  1124. var count = (w/docPageFullWidth).toInt();
  1125. var pages = this.contentNode.getElements(".doc_layout_page");
  1126. count = Math.min(pages.length, count);
  1127. var pageWidth = count * docPageFullWidth;
  1128. var margin = (w-pageWidth)/(count+1);
  1129. if (this.scale) margin = margin/(this.scale);
  1130. this.pages.each(function(page, i){
  1131. page.setStyles({
  1132. "float": "left",
  1133. "margin-left": ""+margin+"px"
  1134. });
  1135. });
  1136. // this.pages.each(function(page, i){
  1137. // if ((i % 2)===0){
  1138. // page.setStyle("float", "left");
  1139. // }else{
  1140. // page.setStyle("float", "right");
  1141. // }
  1142. // });
  1143. this.resetNodeSize();
  1144. this.options.pageShow="double";
  1145. this.doublePageAction.set("text", MWF.xApplication.process.Xform.LP.singlePage);
  1146. this.resizeSidebar();
  1147. this.clearWaitSplitPage();
  1148. }.bind(this), 1000);
  1149. },
  1150. _getDefaultData: function(){
  1151. return Object.clone(this.json.defaultValue);
  1152. //return Object.clone(MWF.xApplication.process.Xform.LP.documentEditor);
  1153. },
  1154. _loadFiletextPage: function(callback){
  1155. this.data = this._getBusinessData();
  1156. if (!this.data) this.data = this._getDefaultData();
  1157. this._computeData(true);
  1158. this._createPage(function(control){
  1159. this._loadPageLayout(control);
  1160. // this.data = this._getBusinessData();
  1161. // if (!this.data) this.data = this._getDefaultData();
  1162. this.setData(this.data);
  1163. // this._checkSplitPage(this.pages[0]);
  1164. //this._repage(true);
  1165. //this.loadCkeditorFiletext();
  1166. if (!this.readonly){
  1167. //if (this.json.allowEditFiletext!==false) this.loadCkeditorFiletext();
  1168. // if (this.json.allowEditRedheader) this.loadCkeditorRedheader();
  1169. // if (this.json.allowEditSubject) this.loadCkeditorSubject();
  1170. // if (this.json.allowEditMainSend) this.loadCkeditorMainSend();
  1171. // if (this.json.allowEditFileNo) this.loadCkeditorFileNo();
  1172. // if (this.json.allowEditSigner) this.loadCkeditorSigner();
  1173. // if (this.json.allowEditAttachment) this.loadCkeditorAttachment();
  1174. }
  1175. if (callback) callback();
  1176. }.bind(this));
  1177. },
  1178. _getEditorConfig: function(){
  1179. // var mathElements = [
  1180. // 'math',
  1181. // 'maction',
  1182. // 'maligngroup',
  1183. // 'malignmark',
  1184. // 'menclose',
  1185. // 'merror',
  1186. // 'mfenced',
  1187. // 'mfrac',
  1188. // 'mglyph',
  1189. // 'mi',
  1190. // 'mlabeledtr',
  1191. // 'mlongdiv',
  1192. // 'mmultiscripts',
  1193. // 'mn',
  1194. // 'mo',
  1195. // 'mover',
  1196. // 'mpadded',
  1197. // 'mphantom',
  1198. // 'mroot',
  1199. // 'mrow',
  1200. // 'ms',
  1201. // 'mscarries',
  1202. // 'mscarry',
  1203. // 'msgroup',
  1204. // 'msline',
  1205. // 'mspace',
  1206. // 'msqrt',
  1207. // 'msrow',
  1208. // 'mstack',
  1209. // 'mstyle',
  1210. // 'msub',
  1211. // 'msup',
  1212. // 'msubsup',
  1213. // 'mtable',
  1214. // 'mtd',
  1215. // 'mtext',
  1216. // 'mtr',
  1217. // 'munder',
  1218. // 'munderover',
  1219. // 'semantics',
  1220. // 'annotation',
  1221. // 'annotation-xml'
  1222. // ];
  1223. //CKEDITOR.plugins.addExternal('ckeditor_wiris', 'https://ckeditor.com/docs/ckeditor4/4.13.0/examples/assets/plugins/ckeditor_wiris/', 'plugin.js');
  1224. var editorConfig = {
  1225. qtRows: 20, // Count of rows
  1226. qtColumns: 20, // Count of columns
  1227. qtBorder: '1', // Border of inserted table
  1228. qtWidth: '95%', // Width of inserted table
  1229. qtStyle: { 'border-collapse' : 'collapse' },
  1230. qtClass: 'test', // Class of table
  1231. qtCellPadding: '0', // Cell padding table
  1232. qtCellSpacing: '0', // Cell spacing table
  1233. qtPreviewBorder: '4px double black', // preview table border
  1234. qtPreviewSize: '4px', // Preview table cell size
  1235. qtPreviewBackground: '#c8def4', // preview table background (hover)
  1236. // format_tags: '标题一;标题二;标题三;标题四;正文', // entries is displayed in "Paragraph format"
  1237. format_tags: '标题一;标题二;正文(标题三,四)', // entries is displayed in "Paragraph format"
  1238. 'format_标题一': {
  1239. name: '标题一',
  1240. element: 'div',
  1241. styles: {
  1242. 'font-family': '黑体',
  1243. 'font-size': '16pt'
  1244. }
  1245. },
  1246. 'format_标题二': {
  1247. name: '标题二',
  1248. element: 'div',
  1249. styles: {
  1250. 'font-family': '楷体',
  1251. 'font-size': '16pt'
  1252. }
  1253. },
  1254. // 'format_标题三': {
  1255. // name: '标题三',
  1256. // element: 'div',
  1257. // styles: {
  1258. // 'font-family': '仿宋',
  1259. // 'font-size': '16pt'
  1260. // }
  1261. // },
  1262. // 'format_标题四': {
  1263. // name: '标题四',
  1264. // element: 'div',
  1265. // styles: {
  1266. // 'font-family': '仿宋',
  1267. // 'font-size': '16pt'
  1268. // }
  1269. // },
  1270. 'format_正文(标题三,四)': {
  1271. name: '正文(标题三,四)',
  1272. element: 'div',
  1273. styles: {
  1274. 'font-family': '仿宋',
  1275. 'font-size': '16pt'
  1276. }
  1277. }
  1278. };
  1279. editorConfig.toolbarGroups = [
  1280. { name: 'document', groups: [ 'mode', 'document', 'doctools' ] },
  1281. { name: 'clipboard', groups: [ 'clipboard', 'undo' ] },
  1282. { name: 'editing', groups: [ 'find', 'selection', 'spellchecker', 'editing' ] },
  1283. { name: 'forms', groups: [ 'forms' ] },
  1284. { name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] },
  1285. { name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align', 'bidi', 'paragraph' ] },
  1286. { name: 'links', groups: [ 'links' ] },
  1287. { name: 'insert', groups: [ 'insert' ] },
  1288. { name: 'styles', groups: [ 'styles' ] },
  1289. { name: 'colors', groups: [ 'colors' ] },
  1290. { name: 'tools', groups: [ 'tools' ] },
  1291. { name: 'others', groups: [ 'others' ] },
  1292. { name: 'about', groups: [ 'about' ] }
  1293. ];
  1294. //editorConfig.extraPlugins = "ecnet,colordialog,tableresize,quicktable,mathjax,ckeditor_wiris";
  1295. //editorConfig.extraPlugins = "ecnet,colordialog,quicktable,tableresize,eqneditor";
  1296. //editorConfig.extraPlugins = "tableresize,quicktable";
  1297. editorConfig.extraPlugins = "quicktable,tableresize";
  1298. //editorConfig.mathJaxLib = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-AMS_HTML',
  1299. 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';
  1300. //editorConfig.extraAllowedContent = mathElements.join(' ') + '(*)[*]{*};img[data-mathml,data-custom-editor,role](Wirisformula)';
  1301. //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';
  1302. editorConfig.removePlugins = ['magicline'];
  1303. editorConfig.enterMode = 3;
  1304. // editorConfig.extraPlugins = ['ecnet','mathjax'];
  1305. // editorConfig.removePlugins = ['magicline'];
  1306. // editorConfig.mathJaxLib = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-AMS_HTML';
  1307. return editorConfig;
  1308. },
  1309. _checkSplitPage: function(pageNode){
  1310. if (this.layout_edition) this.layout_edition.setStyles({ "position": "static"});
  1311. var contentNode = pageNode.getFirst();
  1312. if (contentNode.getSize().y>this.options.docPageHeight){
  1313. this._splitPage(pageNode);
  1314. }
  1315. var i = pageNode.get("data-pagecount").toInt();
  1316. if (i && this.pages.length-1>=i){
  1317. this._checkSplitPage(this.pages[i]);
  1318. }
  1319. if (this.layout_edition) this.layout_edition.setStyles({ "position": "absolute", "bottom": "0px" });
  1320. },
  1321. _splitFiletextNodeOneWord:function(lnode, nextPageNode){
  1322. var text = lnode.textContent;
  1323. var len = text.length;
  1324. var left = text.substring(0, len-1);
  1325. var right = text.substring(len-1, len);
  1326. lnode.textContent = left;
  1327. nextPageNode.textContent = right+nextPageNode.textContent;
  1328. //nextPageNode.appendText(right, "top");
  1329. },
  1330. _splitFiletext: function(node, nextPageNode, nextFiletextNode, pageNode){
  1331. var contentNode = pageNode.getFirst();
  1332. var lnode = node.lastChild;
  1333. if (!lnode){
  1334. if (node.parentNode) node.parentNode.removeChild(node);
  1335. //node.remove();
  1336. }else{
  1337. while (contentNode.getSize().y>this.options.docPageHeight && lnode) {
  1338. var tmpnode = lnode.previousSibling;
  1339. var nodeType = lnode.nodeType;
  1340. if (!nextPageNode) nextPageNode = nextFiletextNode;
  1341. if (nodeType == Node.ELEMENT_NODE) {
  1342. if (lnode.tagName == "table") {
  1343. lnode.inject(nextPageNode);
  1344. } else if (lnode.tagName == "BR") {
  1345. if (lnode.parentNode) lnode.parentNode.removeChild(lnode);
  1346. } else {
  1347. var id = lnode.get("data-pagePart");
  1348. if (!id){
  1349. id = (new o2.widget.UUID()).toString();
  1350. lnode.set("data-pagePart", id);
  1351. }
  1352. var tmpNode = nextPageNode.getFirst();
  1353. if (tmpNode && tmpNode.get("data-pagePart")==id){
  1354. nextPageNode = tmpNode;
  1355. }else{
  1356. nextPageNode = lnode.clone(false).inject(nextPageNode, "top");
  1357. }
  1358. //var subnode = lnode.getLast();
  1359. this._splitFiletext(lnode, nextPageNode, nextFiletextNode, pageNode);
  1360. if (!lnode.firstChild) if (lnode.parentNode) lnode.parentNode.removeChild(lnode);
  1361. nextPageNode = nextPageNode.getParent();
  1362. }
  1363. } else if (nodeType == Node.TEXT_NODE) {
  1364. var nextPageTextNode = nextPageNode.insertBefore(document.createTextNode(""), nextPageNode.firstChild);
  1365. while ((contentNode.getSize().y > this.options.docPageHeight) && lnode.textContent) {
  1366. //console.log(contentNode.getSize().y);
  1367. this._splitFiletextNodeOneWord(lnode, nextPageTextNode)
  1368. }
  1369. if (!lnode.textContent) if (lnode.parentNode) lnode.parentNode.removeChild(lnode); //lnode.remove();
  1370. } else {
  1371. //lnode.remove();
  1372. if (lnode.parentNode) lnode.parentNode.removeChild(lnode);
  1373. }
  1374. lnode = tmpnode;
  1375. }
  1376. if (!node.lastChild) if (node.parentNode) node.parentNode.removeChild(node); //node.remove();
  1377. }
  1378. //this._checkSplitPage(pageNode);
  1379. },
  1380. _splitPage: function(pageNode){
  1381. var contentNode = pageNode.getFirst();
  1382. var blockNodes = pageNode.getElements(".doc_block");
  1383. if (blockNodes.length){
  1384. var blockNode = blockNodes[blockNodes.length-1];
  1385. var idx = this.pages.indexOf(pageNode);
  1386. if (this.pages.length<=idx+1) this._createNewPage();
  1387. var nextPage = this.pages[idx+1];
  1388. if (blockNode.hasClass("doc_layout_filetext")){
  1389. var filetextNode = nextPage.getElement(".doc_layout_filetext");
  1390. if (!filetextNode){
  1391. filetextNode = new Element("div.doc_layout_filetext").inject(nextPage.getFirst(), "top");
  1392. //filetextNode.setAttribute('contenteditable', true);
  1393. }
  1394. if (!filetextNode.hasClass("doc_block"))filetextNode.addClass("doc_block");
  1395. //var nextEditor = filetextNode.retrieve("editor");
  1396. var node = blockNode;
  1397. var nextPageNode = filetextNode;
  1398. this._splitFiletext(node, nextPageNode, filetextNode, pageNode);
  1399. }else{
  1400. blockNode.inject(nextPage.getFirst(), "top");
  1401. //var contentNode = pageNode.getFirst();
  1402. if (contentNode.getSize().y>this.options.docPageHeight){
  1403. this._splitPage(pageNode);
  1404. }
  1405. }
  1406. }
  1407. },
  1408. loadCkeditorFiletext: function(callback, inline){
  1409. if (this.layout_filetext){
  1410. o2.load("/o2_lib/htmleditor/ckeditor4130/ckeditor.js", function(){
  1411. CKEDITOR.disableAutoInline = true;
  1412. this.layout_filetext.setAttribute('contenteditable', true);
  1413. if (inline){
  1414. this.filetextEditor = CKEDITOR.inline(this.layout_filetext, this._getEditorConfig());
  1415. }else{
  1416. this.filetextEditor = CKEDITOR.replace(this.layout_filetext, this._getEditorConfig());
  1417. }
  1418. this.filetextEditor.on("instanceReady", function(e){
  1419. if (callback) callback(e);
  1420. }.bind(this));
  1421. this.filetextEditor.on( 'focus', function( e ) {
  1422. window.setTimeout(this.reLocationFiletextToolbar.bind(this), 10);
  1423. }.bind(this) );
  1424. // this.filetextEditor.on("key", function(e){
  1425. // debugger;
  1426. // }.bind(this));
  1427. }.bind(this));
  1428. }
  1429. },
  1430. _loadEvents: function(editorConfig){
  1431. Object.each(this.json.events, function(e, key){
  1432. if (e.code){
  1433. this.editor.on(key, function(event){
  1434. return this.form.Macro.fire(e.code, this, event);
  1435. }.bind(this), this);
  1436. }
  1437. }.bind(this));
  1438. },
  1439. _bindFieldChange: function(name,dataItem, dom){
  1440. var field = this.form.all[this.json[dataItem]];
  1441. if (field){
  1442. var bindFun = function(){
  1443. this._computeItemFieldData(name, dataItem);
  1444. //if (this.data[name]){
  1445. if (this[dom]){
  1446. if (dom=="layout_redHeader" || dom=="layout_subject"){
  1447. this[dom].set("html", this.data[name]|| "");
  1448. }else if (dom=="layout_attachment"){
  1449. this.setAttachmentData();
  1450. }else{
  1451. this[dom].set("text", this.data[name]|| "");
  1452. }
  1453. }
  1454. this.reSetShow();
  1455. //}
  1456. }.bind(this);
  1457. field.node.store(this.json.id+"bindFun", bindFun);
  1458. field.addModuleEvent("change", bindFun);
  1459. }
  1460. },
  1461. _computeItemFieldData: function(name, dataItem){
  1462. var v = "";
  1463. var module = this.form.all[this.json[dataItem]];
  1464. if (module && module.getData) v = module.getData();
  1465. if (!v) v = this.form.businessData.data[this.json[dataItem]];
  1466. if (v){
  1467. var t = o2.typeOf(v);
  1468. switch (t) {
  1469. case "string":
  1470. switch (name) {
  1471. case "issuanceDate":
  1472. case "editionDate":
  1473. var d = new Date(v);
  1474. if (d.isValid()){
  1475. var y = d.getFullYear();
  1476. var m = d.getMonth();
  1477. var day = d.getDate();
  1478. m = m +1;
  1479. this.data[name] = ""+y+"年"+m+"月"+day+"日";
  1480. }else{
  1481. this.data[name] = v;
  1482. }
  1483. //this.data[name] = (new Date(v).isValid()) ? Date.parse(v).format("%Y年%m月%d%日") : v;
  1484. break;
  1485. case "mainSend":
  1486. this.data[name] = v + ":";
  1487. break;
  1488. default:
  1489. this.data[name] = v;
  1490. }
  1491. break;
  1492. case "array":
  1493. var strs = [];
  1494. v.each(function(value){
  1495. if (o2.typeOf(value)=="object" && value.distinguishedName){
  1496. strs.push(value.name);
  1497. }else{
  1498. strs.push(value.toString());
  1499. }
  1500. });
  1501. //if (strs.length){
  1502. switch (name) {
  1503. case "attachment":
  1504. // this.data[name] = strs.map(function(n, i){ var j = i+1; return j+"、"+n}).join("<br>");
  1505. var atts = strs.map(function(a){
  1506. return (a.indexOf(".")!=-1) ? a.substring(0, a.lastIndexOf(".")) : a;
  1507. });
  1508. this.data[name] = atts;
  1509. break;
  1510. case "issuanceDate":
  1511. case "editionDate":
  1512. var tmpStrs = strs.map(function(n, i){
  1513. var d = Date.parse(n);
  1514. return (d.isValid()) ? d.format("%Y年%m月%d日") : n;
  1515. });
  1516. this.data[name] = tmpStrs.join(",");
  1517. break;
  1518. case "mainSend":
  1519. this.data[name] = strs.join(",") + ":";
  1520. break;
  1521. default:
  1522. this.data[name] = strs.join(",");
  1523. }
  1524. //}
  1525. break;
  1526. default:
  1527. this.data[name] = v.toString();
  1528. }
  1529. }else{
  1530. this.data[name] = this.json.defaultValue[name];
  1531. }
  1532. },
  1533. computeData: function(){
  1534. this._computeData(false);
  1535. this.setData(this.data);
  1536. },
  1537. _computeItemData: function(name, typeItem, dataItem, scriptItem, ev, dom){
  1538. switch (this.json[typeItem]) {
  1539. case "data":
  1540. if (this.json[dataItem]){
  1541. if (ev) this._bindFieldChange(name, dataItem, dom);
  1542. this._computeItemFieldData(name, dataItem);
  1543. }
  1544. break;
  1545. case "script":
  1546. if (this.json[scriptItem] && this.json[scriptItem].code){
  1547. var v = this.form.Macro.exec(this.json[scriptItem].code, this);
  1548. this.data[name] = v;
  1549. if (name=="attachment"){
  1550. //this.data[name] = (typeOf(v)=="array") ? v.map(function(n, i){ var j = i+1; return j+"、"+n}).join("<br>") : v;
  1551. this.data[name] = (typeOf(v)=="array") ? v : [v];
  1552. }
  1553. if (name=="issuanceDate" || name=="editionDate"){
  1554. var d = Date.parse(v);
  1555. this.data[name] = (d.isValid()) ? d.format("%Y年%m月%d日") : v;
  1556. }
  1557. }
  1558. break;
  1559. }
  1560. },
  1561. _computeData: function(ev){
  1562. this._computeItemData("copies", "copiesValueType", "copiesValueData", "copiesValueScript", ev, "layout_copies");
  1563. this._computeItemData("secret", "secretValueType", "secretValueData", "secretValueScript", ev, "layout_secret");
  1564. this._computeItemData("priority", "priorityValueType", "priorityValueData", "priorityValueScript", ev, "layout_priority");
  1565. this._computeItemData("redHeader", "redHeaderValueType", "redHeaderValueData", "redHeaderValueScript", ev, "layout_redHeader");
  1566. this._computeItemData("fileno", "filenoValueType", "filenoValueData", "filenoValueScript", ev, "layout_fileno");
  1567. this._computeItemData("signer", "signerValueType", "signerValueData", "signerValueScript", ev, "layout_signer");
  1568. this._computeItemData("subject", "subjectValueType", "subjectValueData", "subjectValueScript", ev, "layout_subject");
  1569. this._computeItemData("mainSend", "mainSendValueType", "mainSendValueData", "mainSendValueScript", ev, "layout_mainSend");
  1570. this._computeItemData("attachment", "attachmentValueType", "attachmentValueData", "attachmentValueScript", ev, "layout_attachment");
  1571. this._computeItemData("issuanceUnit", "issuanceUnitValueType", "issuanceUnitValueData", "issuanceUnitValueScript", ev, "layout_issuanceUnit");
  1572. this._computeItemData("issuanceDate", "issuanceDateValueType", "issuanceDateValueData", "issuanceDateValueScript", ev, "layout_issuanceDate");
  1573. this._computeItemData("annotation", "annotationValueType", "annotationValueData", "annotationValueScript", ev, "layout_annotation");
  1574. this._computeItemData("copyto", "copytoValueType", "copytoValueData", "copytoValueScript", ev, "layout_copytoContent");
  1575. this._computeItemData("copyto2", "copyto2ValueType", "copyto2ValueData", "copyto2ValueScript", ev, "layout_copyto2Content");
  1576. this._computeItemData("editionUnit", "editionUnitValueType", "editionUnitValueData", "editionUnitValueScript", ev, "layout_edition_issuance_unit");
  1577. this._computeItemData("editionDate", "editionDateValueType", "editionDateValueData", "editionDateValueScript", ev, "layout_edition_issuance_date");
  1578. this._computeItemData("meetingAttend", "meetingAttendValueType", "meetingAttendValueData", "meetingAttendValueScript", ev, "layout_meetingAttendContent");
  1579. this._computeItemData("meetingLeave", "meetingLeaveValueType", "meetingLeaveValueData", "meetingLeaveValueScript", ev, "layout_meetingLeaveContent");
  1580. this._computeItemData("meetingSit", "meetingSitValueType", "meetingSitValueData", "meetingSitValueScript", ev, "layout_meetingSitContent");
  1581. },
  1582. _loadValue: function(){
  1583. var data = this._getBusinessData();
  1584. },
  1585. reload: function(){
  1586. this.resetData();
  1587. },
  1588. resetData: function(diffFiletext){
  1589. if (this.editMode){ this._switchReadOrEditInline(); }
  1590. this._computeData(false);
  1591. this.pages = [];
  1592. this.contentNode.empty();
  1593. if (this.allowEdit) this.toolbar.childrenButton[0].setText(MWF.xApplication.process.Xform.LP.editdoc);
  1594. this.editMode = false;
  1595. this._createPage(function(control){
  1596. this._loadPageLayout(control);
  1597. this.setData(this.data, diffFiletext);
  1598. //this._checkSplitPage(this.pages[0]);
  1599. this._repage();
  1600. }.bind(this));
  1601. },
  1602. getData: function(){
  1603. //if (this.editMode){
  1604. if (this.layout_copies) this.data.copies = this.layout_copies.get("text");
  1605. if (this.layout_secret) this.data.secret = this.layout_secret.get("text");
  1606. if (this.layout_priority) this.data.priority = this.layout_priority.get("text");
  1607. if (this.layout_redHeader) this.data.redHeader = this.layout_redHeader.get("html");
  1608. if (this.layout_fileno) this.data.fileno = this.layout_fileno.get("text");
  1609. if (this.layout_signerTitle) this.data.signerTitle = this.layout_signerTitle.get("text");
  1610. if (this.layout_signer) this.data.signer = this.layout_signer.get("text");
  1611. if (this.layout_subject) this.data.subject = this.layout_subject.get("html");
  1612. if (this.layout_mainSend) this.data.mainSend = this.layout_mainSend.get("text");
  1613. if (this.editMode) if (this.layout_filetext) this.data.filetext = this.layout_filetext.get("html");
  1614. if (this.layout_signer) this.data.signer = this.layout_signer.get("text");
  1615. if (this.layout_attachmentTitle) this.data.attachmentTitle = this.layout_attachmentTitle.get("text");
  1616. if (this.layout_attachment){
  1617. this._computeItemData("attachment", "attachmentValueType", "attachmentValueData", "attachmentValueScript", false, "layout_attachment");
  1618. // var atts = [];
  1619. // var nodes = this.layout_attachment.getElements(".doc_layout_attachment_content_name");
  1620. // if (nodes.length){
  1621. // nodes.each(function(node){
  1622. // atts.push(node.get("text"));
  1623. // });
  1624. // }
  1625. // this.data.attachment = atts;
  1626. }
  1627. if (this.layout_issuanceUnit) this.data.issuanceUnit = this.layout_issuanceUnit.get("text");
  1628. if (this.layout_issuanceDate) this.data.issuanceDate = this.layout_issuanceDate.get("text");
  1629. if (this.layout_annotation) this.data.annotation = this.layout_annotation.get("text");
  1630. if (this.layout_copytoTitle) this.data.copytoTitle = this.layout_copytoTitle.get("text");
  1631. if (this.layout_copytoContent) this.data.copyto = this.layout_copytoContent.get("text");
  1632. if (this.layout_copyto2Title) this.data.copyto2Title = this.layout_copyto2Title.get("text");
  1633. if (this.layout_copyto2Content) this.data.copyto2 = this.layout_copyto2Content.get("text");
  1634. if (this.layout_edition_issuance_unit) this.data.editionUnit = this.layout_edition_issuance_unit.get("text");
  1635. if (this.layout_edition_issuance_date) this.data.editionDate = this.layout_edition_issuance_date.get("text");
  1636. if (this.layout_meetingAttendTitle) this.data.meetingAttendTitle = this.layout_meetingAttendTitle.get("text");
  1637. if (this.layout_meetingLeaveTitle) this.data.meetingLeaveTitle = this.layout_meetingLeaveTitle.get("text");
  1638. if (this.layout_meetingSitTitle) this.data.meetingSitTitle = this.layout_meetingSitTitle.get("text");
  1639. if (this.layout_meetingAttendContent) this.data.meetingAttend = this.layout_meetingAttendContent.get("html");
  1640. if (this.layout_meetingLeaveContent) this.data.meetingLeave = this.layout_meetingLeaveContent.get("html");
  1641. if (this.layout_meetingSitContent) this.data.meetingSit = this.layout_meetingSitContent.get("html");
  1642. //}
  1643. return this.data;
  1644. },
  1645. setAttachmentData: function(){
  1646. if (!this.attachmentTemplete){
  1647. this.attachmentTemplete = this.layout_attachment.get("html");
  1648. }
  1649. this.layout_attachment.empty();
  1650. if (this.data.attachment && this.data.attachment.length && this.data.attachment.each){
  1651. //var tmpdiv = new Element("div", {"styles": {"display":"none"}}).inject(document.body);
  1652. var tmpdiv = new Element("div");
  1653. this.data.attachment.each(function(name, idx){
  1654. tmpdiv.set("html", this.attachmentTemplete);
  1655. var serialNode = tmpdiv.getElement(".doc_layout_attachment_content_serial");
  1656. var nameNode = tmpdiv.getElement(".doc_layout_attachment_content_name");
  1657. if (serialNode) serialNode.set("text", idx+1);
  1658. if (nameNode) nameNode.set("text", name);
  1659. var html = tmpdiv.get("html");
  1660. tmpdiv.empty();
  1661. this.layout_attachment.appendHTML(html);
  1662. }.bind(this));
  1663. tmpdiv.destroy();
  1664. }
  1665. },
  1666. setData: function(data, diffFiletext){
  1667. if (data){
  1668. this.data = data;
  1669. // this.data["$json"] = this.json;
  1670. this._setBusinessData(data);
  1671. if (this.layout_copies){
  1672. if (data.copies){
  1673. this.layout_copies.set("text", data.copies || " ");
  1674. }else{
  1675. this.layout_copies.set("html", "<span>&nbsp</span>");
  1676. }
  1677. }
  1678. if (this.layout_secret){
  1679. if (data.secret){
  1680. this.layout_secret.set("text", data.secret || " ");
  1681. }else{
  1682. this.layout_secret.set("html", "<span>&nbsp</span>");
  1683. }
  1684. }
  1685. if (this.layout_priority){
  1686. if (data.priority){
  1687. this.layout_priority.set("text", data.priority || " ");
  1688. }else{
  1689. this.layout_priority.set("html", "<span>&nbsp</span>");
  1690. }
  1691. }
  1692. if (this.layout_redHeader) this.layout_redHeader.set("html", data.redHeader || "");
  1693. if (this.layout_fileno) this.layout_fileno.set("text", data.fileno || " ");
  1694. if (this.layout_signerTitle) this.layout_signerTitle.set("text", data.signerTitle || " ");
  1695. if (this.layout_signer) this.layout_signer.set("text", data.signer || " ");
  1696. if (this.layout_subject) this.layout_subject.set("html", data.subject || " ");
  1697. if (this.layout_mainSend) this.layout_mainSend.set("text", data.mainSend || " ");
  1698. if (diffFiletext) {
  1699. this.layout_filetext.set("html", diffFiletext);
  1700. }else if (this.layout_filetext){
  1701. //this.layout_filetext.set("placeholder", this.json.defaultValue.filetext);
  1702. this.layout_filetext.set("html", data.filetext || "");
  1703. }
  1704. if (this.layout_signer) this.layout_signer.set("text", data.signer || "");
  1705. if (this.layout_attachmentTitle) this.layout_attachmentTitle.set("text", data.attachmentTitle || " ");
  1706. if (this.layout_attachment){
  1707. this.setAttachmentData();
  1708. }
  1709. if (this.layout_issuanceUnit) this.layout_issuanceUnit.set("text", data.issuanceUnit || " ");
  1710. if (this.layout_issuanceDate) this.layout_issuanceDate.set("text", data.issuanceDate || " ");
  1711. if (this.layout_annotation) this.layout_annotation.set("text", data.annotation || " ");
  1712. if (this.layout_copytoTitle) this.layout_copytoTitle.set("text", data.copytoTitle || " ");
  1713. if (this.layout_copytoContent) this.layout_copytoContent.set("text", data.copyto || " ");
  1714. if (this.layout_copyto2Title) this.layout_copyto2Title.set("text", data.copyto2Title || " ");
  1715. if (this.layout_copyto2Content) this.layout_copyto2Content.set("text", data.copyto2 || " ");
  1716. if (this.layout_edition_issuance_unit) this.layout_edition_issuance_unit.set("text", data.editionUnit || " ");
  1717. if (this.layout_edition_issuance_date) this.layout_edition_issuance_date.set("text", data.editionDate || " ");
  1718. if (this.layout_meetingAttendTitle) this.layout_meetingAttendTitle.set("text", data.meetingAttendTitle || this.json.defaultValue.meetingAttendTitle || " ");
  1719. if (this.layout_meetingLeaveTitle) this.layout_meetingLeaveTitle.set("text", data.meetingLeaveTitle || this.json.defaultValue.meetingLeaveTitle || " ");
  1720. if (this.layout_meetingSitTitle) this.layout_meetingSitTitle.set("text", data.meetingSitTitle || this.json.defaultValue.meetingSitTitle || " ");
  1721. if (this.layout_meetingAttendContent) this.layout_meetingAttendContent.set("html", data.meetingAttend || " ");
  1722. if (this.layout_meetingLeaveContent) this.layout_meetingLeaveContent.set("html", data.meetingLeave || " ");
  1723. if (this.layout_meetingSitContent) this.layout_meetingSitContent.set("html", data.meetingSit || " ");
  1724. }
  1725. },
  1726. createErrorNode: function(text){
  1727. var node = new Element("div");
  1728. var iconNode = new Element("div", {
  1729. "styles": {
  1730. "width": "20px",
  1731. "height": "20px",
  1732. "float": "left",
  1733. "background": "url("+"/x_component_process_Xform/$Form/default/icon/error.png) center center no-repeat"
  1734. }
  1735. }).inject(node);
  1736. var textNode = new Element("div", {
  1737. "styles": {
  1738. "line-height": "20px",
  1739. "margin-left": "20px",
  1740. "color": "red",
  1741. "word-break": "keep-all"
  1742. },
  1743. "text": text
  1744. }).inject(node);
  1745. return node;
  1746. },
  1747. notValidationMode: function(text){
  1748. if (!this.isNotValidationMode){
  1749. this.isNotValidationMode = true;
  1750. this.node.store("borderStyle", this.node.getStyles("border-left", "border-right", "border-top", "border-bottom"));
  1751. this.node.setStyle("border", "1px solid red");
  1752. this.errNode = this.createErrorNode(text).inject(this.node, "after");
  1753. this.showNotValidationMode(this.node);
  1754. }
  1755. },
  1756. showNotValidationMode: function(node){
  1757. var p = node.getParent("div");
  1758. if (p){
  1759. if (p.get("MWFtype") == "tab$Content"){
  1760. if (p.getParent("div").getStyle("display")=="none"){
  1761. var contentAreaNode = p.getParent("div").getParent("div");
  1762. var tabAreaNode = contentAreaNode.getPrevious("div");
  1763. var idx = contentAreaNode.getChildren().indexOf(p.getParent("div"));
  1764. var tabNode = tabAreaNode.getLast().getFirst().getChildren()[idx];
  1765. tabNode.click();
  1766. p = tabAreaNode.getParent("div");
  1767. }
  1768. }
  1769. this.showNotValidationMode(p);
  1770. }
  1771. },
  1772. validationMode: function(){
  1773. if (this.isNotValidationMode){
  1774. this.isNotValidationMode = false;
  1775. this.node.setStyles(this.node.retrieve("borderStyle"));
  1776. if (this.errNode){
  1777. this.errNode.destroy();
  1778. this.errNode = null;
  1779. }
  1780. }
  1781. },
  1782. validationConfigItem: function(routeName, data){
  1783. var flag = (data.status=="all") ? true: (routeName == data.decision);
  1784. if (flag){
  1785. var n = this.getData();
  1786. var v = (data.valueType=="value") ? n : n.length;
  1787. switch (data.operateor){
  1788. case "isnull":
  1789. if (!v){
  1790. this.notValidationMode(data.prompt);
  1791. return false;
  1792. }
  1793. break;
  1794. case "notnull":
  1795. if (v){
  1796. this.notValidationMode(data.prompt);
  1797. return false;
  1798. }
  1799. break;
  1800. case "gt":
  1801. if (v>data.value){
  1802. this.notValidationMode(data.prompt);
  1803. return false;
  1804. }
  1805. break;
  1806. case "lt":
  1807. if (v<data.value){
  1808. this.notValidationMode(data.prompt);
  1809. return false;
  1810. }
  1811. break;
  1812. case "equal":
  1813. if (v==data.value){
  1814. this.notValidationMode(data.prompt);
  1815. return false;
  1816. }
  1817. break;
  1818. case "neq":
  1819. if (v!=data.value){
  1820. this.notValidationMode(data.prompt);
  1821. return false;
  1822. }
  1823. break;
  1824. case "contain":
  1825. if (v.indexOf(data.value)!=-1){
  1826. this.notValidationMode(data.prompt);
  1827. return false;
  1828. }
  1829. break;
  1830. case "notcontain":
  1831. if (v.indexOf(data.value)==-1){
  1832. this.notValidationMode(data.prompt);
  1833. return false;
  1834. }
  1835. break;
  1836. }
  1837. }
  1838. return true;
  1839. },
  1840. validationConfig: function(routeName, opinion){
  1841. if (this.json.validationConfig){
  1842. if (this.json.validationConfig.length){
  1843. for (var i=0; i<this.json.validationConfig.length; i++) {
  1844. var data = this.json.validationConfig[i];
  1845. if (!this.validationConfigItem(routeName, data)) return false;
  1846. }
  1847. }
  1848. return true;
  1849. }
  1850. return true;
  1851. },
  1852. validation: function(routeName, opinion){
  1853. if (!this.validationConfig(routeName, opinion)) return false;
  1854. if (!this.json.validation) return true;
  1855. if (!this.json.validation.code) return true;
  1856. var flag = this.form.Macro.exec(this.json.validation.code, this);
  1857. if (!flag) flag = MWF.xApplication.process.Xform.LP.notValidation;
  1858. if (flag.toString()!="true"){
  1859. this.notValidationMode(flag);
  1860. return false;
  1861. }
  1862. return true;
  1863. },
  1864. removeDisplayNone: function(node){
  1865. var n = node.getFirst();
  1866. while (n){
  1867. if (n.getStyle("display")=="none"){
  1868. var tmp = n.getNext();
  1869. n.destroy();
  1870. n = tmp;
  1871. }else{
  1872. n = this.removeDisplayNone(n);
  1873. n = n.getNext();
  1874. }
  1875. }
  1876. return node;
  1877. },
  1878. toWord: function(callback, name){
  1879. var toEdit = false;
  1880. if (this.editMode){
  1881. toEdit = true;
  1882. this._readFiletext();
  1883. }
  1884. //this._returnScale();
  1885. this.zoom(1);
  1886. this.pages = [];
  1887. this.contentNode.empty();
  1888. this._createPage(function(control){
  1889. this._loadPageLayout(control);
  1890. this.setData(this.data);
  1891. this._checkScale();
  1892. this.node.setStyles({
  1893. "height":"auto"
  1894. });
  1895. //var content = this.contentNode.getFirst().getFirst().get("html");
  1896. var tmpNode = this.contentNode.getFirst().getFirst().clone(true);
  1897. var htmlNode = tmpNode.getLast();
  1898. htmlNode = this.removeDisplayNone(htmlNode);
  1899. var content = "<html><head><meta charset=\"UTF-8\" /></head><body>"+tmpNode.get("html")+"</body></html>";
  1900. var body = {
  1901. "fileName": name || this.json.toWordFilename || "$doc.doc",
  1902. "site": this.json.toWordSite || "$doc",
  1903. "content": content
  1904. };
  1905. o2.Actions.get("x_processplatform_assemble_surface").docToWord(this.form.businessData.work.id, body, function(json){
  1906. if (this.form.businessData.workCompleted){
  1907. o2.Actions.get("x_processplatform_assemble_surface").getAttachmentWorkcompleted(json.data.id, this.form.businessData.workCompleted.id,function(attjson){
  1908. if (callback) callback(attjson.data);
  1909. this.showToWord(attjson.data);
  1910. }.bind(this));
  1911. }else{
  1912. o2.Actions.get("x_processplatform_assemble_surface").getAttachment(json.data.id, this.form.businessData.work.id,function(attjson){
  1913. if (callback) callback(attjson.data);
  1914. this.showToWord(attjson.data);
  1915. }.bind(this));
  1916. }
  1917. }.bind(this));
  1918. tmpNode.destroy();
  1919. if (!toEdit){
  1920. this._readFiletext();
  1921. }else{
  1922. this._createEditor();
  1923. }
  1924. }.bind(this));
  1925. },
  1926. docToWord: function(){
  1927. var flag = true;
  1928. if (this.json.toWordConditionScript && this.json.toWordConditionScript.code){
  1929. flag = !!this.form.Macro.exec(this.json.toWordConditionScript.code, this);
  1930. }
  1931. if (flag){
  1932. this.toWord();
  1933. }
  1934. },
  1935. showToWord: function(att){
  1936. var site = this.json.toWordSite || "$doc";
  1937. var attModule = this.form.all[site];
  1938. if (attModule){
  1939. attModule.attachmentController.clear();
  1940. attModule.attachmentController.addAttachment(att);
  1941. }
  1942. }
  1943. });