Documenteditor.js 99 KB

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