Documenteditor.js 105 KB

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