Documenteditor.js 100 KB

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