Documenteditor.js 190 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196
  1. MWF.xDesktop.requireApp("process.Xform", "$Module", null, false);
  2. /** @class Documenteditor 公文编辑器。
  3. * @o2cn 公文编辑器
  4. * @example
  5. * //可以在脚本中获取该组件
  6. * //方法1:
  7. * var documenteditor = this.form.get("fieldId"); //获取组件
  8. * //方法2
  9. * var documenteditor = this.target; //在组件事件脚本中获取
  10. * @extends MWF.xApplication.process.Xform.$Module
  11. * @o2category FormComponents
  12. * @o2range {Process}
  13. * @hideconstructor
  14. */
  15. MWF.xApplication.process.Xform.Documenteditor = MWF.APPDocumenteditor = new Class(
  16. /** @lends MWF.xApplication.process.Xform.Documenteditor# */
  17. {
  18. Extends: MWF.APP$Module,
  19. options: {
  20. /**
  21. * 当公文编辑器内容每次被渲染的时候都会触发。
  22. * @event MWF.xApplication.process.Xform.Documenteditor#loadPage
  23. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  24. */
  25. "moduleEvents": ["load", "queryLoad", "beforeLoad", "postLoad", "afterLoad", "loadPage", "fullScreen", "returnScreen", "pagePosition"],
  26. "docPageHeight": 850.4,
  27. "docPageFullWidth": 794,
  28. "pageShow": "single"
  29. },
  30. initialize: function(node, json, form, options){
  31. this.node = $(node);
  32. this.node.store("module", this);
  33. this.json = json;
  34. this.form = form;
  35. this.field = true;
  36. this.fieldModuleLoaded = false;
  37. },
  38. _loadCss: function(reload){
  39. var key = encodeURIComponent(this.cssPath);
  40. if (!reload && o2.widget.css[key]){
  41. this.css = o2.widget.css[key];
  42. }else{
  43. this.cssPath = (this.cssPath.indexOf("?")!=-1) ? this.cssPath+"&v="+o2.version.v : this.cssPath+"?v="+o2.version.v;
  44. var r = new Request.JSON({
  45. url: this.cssPath,
  46. secure: false,
  47. async: false,
  48. method: "get",
  49. noCache: false,
  50. onSuccess: function(responseJSON, responseText){
  51. this.css = responseJSON;
  52. o2.widget.css[key] = responseJSON;
  53. }.bind(this),
  54. onError: function(text, error){
  55. console.log(error + text);
  56. }
  57. });
  58. r.send();
  59. }
  60. },
  61. load: function(){
  62. if (!this.json.isDelay){
  63. this.active();
  64. }
  65. },
  66. /**
  67. * 激活公文编辑器编辑。设置了延迟加载的时候,可以通过这个方法来激活
  68. * @example
  69. * this.form.get("fieldId").active();
  70. */
  71. active: function(){
  72. this._loadModuleEvents();
  73. if (this.fireEvent("queryLoad")){
  74. this.fireEvent("beforeLoad");
  75. this.cssPath = this.form.path+this.form.options.style+"/doc.wcss";
  76. this._loadCss();
  77. this._queryLoaded();
  78. this._loadUserInterface(function(){
  79. this.fieldModuleLoaded = true;
  80. this.fireEvent("postLoad");
  81. this.fireEvent("afterLoad");
  82. this.fireEvent("load");
  83. this.form.app.addEvent("resize", function(){
  84. // if (this.options.pageShow!=="double"){
  85. // this._doublePage();
  86. // }else{
  87. this._singlePage();
  88. // }
  89. // this.scaleTo(this.scale);
  90. // this._checkScale();
  91. }.bind(this));
  92. o2.UD.getDataJson("documenteditorScale", function(json){
  93. if (json){
  94. this.scaleTo(json.scale);
  95. this.documenteditorScale = json.scale
  96. }
  97. // if (this.documenteditorScale) this.scaleTo(this.documenteditorScale);
  98. // this.addEvent("loadPage", function(){
  99. // if (this.documenteditorScale) this.scaleTo(this.documenteditorScale);
  100. // }.bind(this));
  101. this._checkScale();
  102. }.bind(this));
  103. }.bind(this));
  104. this._loadStyles();
  105. this._afterLoaded();
  106. }
  107. },
  108. _createNewPage: function(){
  109. var pageNode = new Element("div.doc_layout_page", {"styles": this.css.doc_page}).inject(this.contentNode);
  110. var pageContentNode = new Element("div.doc_layout_page_content", {"styles": this.css.doc_layout_page_content}).inject(pageNode);
  111. pageNode.set("data-pagecount", this.pages.length+1);
  112. this.pages.push(pageNode);
  113. return pageNode;
  114. },
  115. _getShow: function(name, typeItem, scriptItem){
  116. switch (this.json[typeItem]) {
  117. case "y":
  118. return true;
  119. case "n":
  120. return false;
  121. case "a":
  122. if (["copies", "secret", "priority", "attachment", "annotation"].indexOf(name!=-1)){
  123. if (o2.typeOf(this.data[name])=="string"){
  124. var v = this.data[name].trim();
  125. return !!v && (!!v.length);
  126. }else{
  127. return !!this.data[name] && (!!this.data[name].length);
  128. }
  129. }
  130. return true;
  131. case "s":
  132. if (this.json[scriptItem] && this.json[scriptItem].code){
  133. return !!this.form.Macro.exec(this.json[scriptItem].code, this);
  134. }
  135. return true;
  136. default:
  137. return true;
  138. }
  139. },
  140. _loadCssStyle: function(){
  141. if (this.json.css && this.json.css.code && !this.styleNode){
  142. var cssText = this.form.parseCSS(this.json.css.code);
  143. cssText = cssText.replace(/documenteditor_table/g, 'documenteditor_table'+this.form.json.id+this.json.id);
  144. var styleNode = document.createElement("style");
  145. styleNode.setAttribute("type", "text/css");
  146. styleNode.id="style"+this.json.id;
  147. styleNode.inject(this.node, "top");
  148. if(styleNode.styleSheet){
  149. var setFunc = function(){
  150. if(styleNode.styleSheet.disabled){
  151. setTimeout(setFunc, 100);
  152. }else{
  153. styleNode.styleSheet.cssText = cssText;
  154. }
  155. };
  156. setFunc();
  157. }else{
  158. var cssTextNode = document.createTextNode(cssText);
  159. styleNode.appendChild(cssTextNode);
  160. }
  161. this.styleNode = styleNode;
  162. }
  163. },
  164. _createPage: function(callback, callbackAftreLoad){
  165. var control = this.getShowControl();
  166. this.json.fileup = !!(control.signer);
  167. this._loadCssStyle();
  168. var url = (this.json.documentTempleteType==="cus") ?
  169. this.json.documentTempleteUrl :
  170. "../x_component_process_FormDesigner/Module/Documenteditor/templete/"+(this.json.documentTempleteName || "standard")+".html";
  171. url = url+((url.indexOf("?")!==-1) ? "&" : "?")+"v="+o2.version.v;
  172. this._clearCopytoTrs();
  173. fetch(o2.filterUrl(url)).then(function(res){
  174. return res.text();
  175. }).then(function(html){
  176. this.contentNode.empty();
  177. if (this.filetextEditor) this.filetextEditor.destroy();
  178. if (this.attachmentTextEditor) this.attachmentTextEditor.destroy();
  179. this.editMode = false;
  180. // this.historyMode = false;
  181. var pageContentNode = this._createNewPage().getFirst();
  182. pageContentNode.set("html", html);
  183. if (this.attachmentTemplete){
  184. var attNode = pageContentNode.getElement(".doc_layout_attachment_content");
  185. if (attNode) attNode.empty();
  186. }
  187. if (callback) callback(control);
  188. this.fireEvent("loadPage");
  189. if (callbackAftreLoad) callbackAftreLoad(control);
  190. }.bind(this));
  191. },
  192. _clearCopytoTrs: function(){
  193. if (this.layout_copytoContentTr){
  194. this.layout_copytoContentTr.destroy();
  195. this.layout_copytoContentTr = null;
  196. }
  197. if (this.layout_copytoContentTrP){
  198. this.layout_copytoContentTrP.destroy();
  199. this.layout_copytoContentTrP = null;
  200. }
  201. if (this.layout_copyto2ContentTr){
  202. this.layout_copyto2ContentTr.destroy();
  203. this.layout_copyto2ContentTr = null;
  204. }
  205. if (this.layout_copyto2ContentTrP){
  206. this.layout_copyto2ContentTrP.destroy();
  207. this.layout_copyto2ContentTrP = null;
  208. }
  209. },
  210. getTempleteJson: function(callback){
  211. if (this.templeteJson){
  212. if (callback) callback();
  213. }else{
  214. o2.getJSON(o2.filterUrl("../x_component_process_FormDesigner/Module/Documenteditor/templete/templete.json"), function(json){
  215. this.templeteJson = json;
  216. if (callback) callback();
  217. }.bind(this));
  218. }
  219. },
  220. getShowControl: function(){
  221. var control = {};
  222. control.copiesSecretPriority = this._getShow("copiesSecretPriority", "copiesSecretPriorityShow", "copiesSecretPriorityShowScript");
  223. control.copies = this._getShow("copies", "copiesShow", "copiesShowScript");
  224. control.secret = this._getShow("secret", "secretShow", "secretShowScript");
  225. control.priority = this._getShow("priority", "priorityShow", "priorityShowScript");
  226. control.redHeader = this._getShow("redHeader", "redHeaderShow", "redHeaderShowScript");
  227. control.redLine = this._getShow("redLine", "redLineShow", "redLineShowScript");
  228. control.signer = this._getShow("signer", "signerShow", "signerShowScript");
  229. control.fileno = this._getShow("fileno", "filenoShow", "filenoShowScript");
  230. control.subject = this._getShow("subject", "subjectShow", "subjectShowScript");
  231. control.mainSend = this._getShow("mainSend", "mainSendShow", "mainSendShowScript");
  232. control.attachment = this._getShow("attachment", "attachmentShow", "attachmentShowScript");
  233. control.issuanceUnit = this._getShow("issuanceUnit", "issuanceUnitShow", "issuanceUnitShowScript");
  234. control.issuanceDate = this._getShow("issuanceDate", "issuanceDateShow", "issuanceDateShowScript");
  235. control.annotation = this._getShow("annotation", "annotationShow", "annotationShowScript");
  236. control.copyto = this._getShow("copyto", "copytoShow", "copytoShowScript");
  237. control.copyto2 = this._getShow("copyto2", "copyto2Show", "copyto2ShowScript");
  238. control.editionUnit = this._getShow("editionUnit", "editionUnitShow", "editionUnitShowScript");
  239. control.editionDate = this._getShow("editionDate", "editionDateShow", "editionDateShowScript");
  240. control.meetingAttend = this._getShow("meetingAttend", "meetingAttendShow", "meetingAttendShowScript");
  241. control.meetingLeave = this._getShow("meetingLeave", "meetingLeaveShow", "meetingLeaveShowScript");
  242. control.meetingSit = this._getShow("meetingSit", "meetingSitShow", "meetingSitShowScript");
  243. control.meetingRecord = this._getShow("meetingRecord", "meetingRecordShow", "meetingRecordShowScript");
  244. this.json.fileup = !!(control.signer);
  245. return control;
  246. },
  247. getEditControl: function(){
  248. var control = {};
  249. control.copies = this._getEdit("copies", "copiesEdit", "copiesEditScript");
  250. control.secret = this._getEdit("secret", "secretEdit", "secretEditScript");
  251. control.priority = this._getEdit("priority", "priorityEdit", "priorityEditScript");
  252. control.redHeader = this._getEdit("redHeader", "redHeaderEdit", "redHeaderEditScript");
  253. control.signer = this._getEdit("signer", "signerEdit", "signerEditScript");
  254. control.fileno = this._getEdit("fileno", "filenoEdit", "filenoEditScript");
  255. control.subject = this._getEdit("subject", "subjectEdit", "subjectEditScript");
  256. control.mainSend = this._getEdit("mainSend", "mainSendEdit", "mainSendEditScript");
  257. control.attachment = this._getEdit("attachment", "attachmentEdit", "attachmentEditScript");
  258. control.attachmentText = this._getEdit("attachmentText", "attachmentTextEdit", "attachmentTextEditScript");
  259. control.issuanceUnit = this._getEdit("issuanceUnit", "issuanceUnitEdit", "issuanceUnitEditScript");
  260. control.issuanceDate = this._getEdit("issuanceDate", "issuanceDateEdit", "issuanceDateEditScript");
  261. control.annotation = this._getEdit("annotation", "annotationEdit", "annotationEditScript");
  262. control.copyto = this._getEdit("copyto", "copytoEdit", "copytoEditScript");
  263. control.copyto2 = this._getEdit("copyto2", "copyto2Edit", "copyto2EditScript");
  264. control.editionUnit = this._getEdit("editionUnit", "editionUnitEdit", "editionUnitEditScript");
  265. control.editionDate = this._getEdit("editionDate", "editionDateEdit", "editionDateEditScript");
  266. control.meetingAttend = this._getShow("meetingAttend", "meetingAttendEdit", "meetingAttendEditScript");
  267. control.meetingLeave = this._getShow("meetingLeave", "meetingLeaveEdit", "meetingLeaveEditScript");
  268. control.meetingSit = this._getShow("meetingSit", "meetingSitEdit", "meetingSitEditScript");
  269. control.meetingRecord = this._getShow("meetingRecord", "meetingRecordEdit", "meetingRecordEditScript");
  270. return control;
  271. },
  272. //份数 密级 紧急程度
  273. _loadCopiesSecretPriority: function(){
  274. this.layout_copiesSecretPriority = this.contentNode.getElement(".doc_layout_copiesSecretPriority");
  275. if (this.layout_copiesSecretPriority) this.layout_copiesSecretPriority.setStyles(this.css.doc_layout_copiesSecretPriority);
  276. /**
  277. * @summary 份数的dom对象.
  278. * @member {MWF.xApplication.process.Xform.Documenteditor}
  279. */
  280. this.layout_copies = this.contentNode.getElement(".doc_layout_copies");
  281. if (this.layout_copies) this.layout_copies.setStyles(this.css.doc_layout_copies);
  282. /**
  283. * @summary 密级的dom对象.
  284. * @member {MWF.xApplication.process.Xform.Documenteditor}
  285. */
  286. this.layout_secret = this.contentNode.getElement(".doc_layout_secret");
  287. if (this.layout_secret) this.layout_secret.setStyles(this.css.doc_layout_secret);
  288. /**
  289. * @summary 紧急度的dom对象.
  290. * @member {MWF.xApplication.process.Xform.Documenteditor}
  291. */
  292. this.layout_priority = this.contentNode.getElement(".doc_layout_priority");
  293. if (this.layout_priority) this.layout_priority.setStyles(this.css.doc_layout_priority);
  294. this.layout_copiesSecretPriority_blank = this.contentNode.getElement(".doc_layout_copiesSecretPriority_blank");
  295. },
  296. //红头
  297. _loadRedHeader: function(){
  298. /**
  299. * @summary 红头的dom对象.
  300. * @member {MWF.xApplication.process.Xform.Documenteditor}
  301. */
  302. this.layout_redHeader = this.contentNode.getElement(".doc_layout_redHeader");
  303. if (this.layout_redHeader) this.layout_redHeader.setStyles(this.css.doc_layout_redHeader);
  304. },
  305. //文号签发人(上行文)
  306. _loadFileNoUp: function(){
  307. this.layout_filenoArea = this.contentNode.getElement(".doc_layout_fileno_area");
  308. this.layout_fileNoUpTable = this.contentNode.getElement(".doc_layout_filenoup");
  309. if (this.layout_fileNoUpTable) this.layout_fileNoUpTable.setStyles(this.css.doc_layout_filenoup);
  310. var td = this.contentNode.getElement(".doc_layout_filenoup_fileno_td");
  311. if (td) td.setStyles(this.css.doc_layout_filenoup_fileno_td);
  312. /**
  313. * @summary 文号的dom对象.
  314. * @member {MWF.xApplication.process.Xform.Documenteditor}
  315. */
  316. this.layout_fileno = this.contentNode.getElement(".doc_layout_filenoup_fileno");
  317. if (this.layout_fileno) this.layout_fileno.setStyles(this.css.doc_layout_filenoup_fileno);
  318. td = this.contentNode.getElement(".doc_layout_filenoup_signer_td");
  319. if (td) td.setStyles(this.css.doc_layout_filenoup_signer_td);
  320. var node = this.contentNode.getElement(".doc_layout_filenoup_signer_table");
  321. if (node) node.setStyles(this.css.doc_layout_filenoup_signer_table);
  322. node = this.contentNode.getElement(".doc_layout_filenoup_signerTitle_td");
  323. if (node) node.setStyles(this.css.doc_layout_filenoup_signerTitle_td);
  324. this.layout_signerTitle = this.contentNode.getElement(".doc_layout_filenoup_signer");
  325. if (this.layout_signerTitle) this.layout_signerTitle.setStyles(this.css.doc_layout_filenoup_signer);
  326. node = this.contentNode.getElement(".doc_layout_filenoup_signerContent_td");
  327. if (node) node.setStyles(this.css.doc_layout_filenoup_signerContent_td);
  328. /**
  329. * @summary 签发人的dom对象.
  330. * @member {MWF.xApplication.process.Xform.Documenteditor}
  331. */
  332. this.layout_signer = this.contentNode.getElement(".doc_layout_filenoup_signerContent");
  333. if (this.layout_signer) this.layout_signer.setStyles(this.css.doc_layout_filenoup_signerContent);
  334. if (!this.layout_fileno){
  335. this.layout_fileNoUpTable = this.contentNode.getElement(".doc_layout_filenoup");
  336. this.layout_filenoArea = this.contentNode.getElement(".doc_layout_fileno_area");
  337. this.layout_fileno = this.contentNode.getElement(".doc_layout_fileno");
  338. if (this.layout_fileno) this.layout_fileno.setStyles(this.css.doc_layout_fileno);
  339. }
  340. },
  341. //文号
  342. _loadFileNo: function(){
  343. this.layout_fileNoUpTable = this.contentNode.getElement(".doc_layout_filenoup");
  344. this.layout_filenoArea = this.contentNode.getElement(".doc_layout_fileno_area");
  345. this.layout_fileno = this.contentNode.getElement(".doc_layout_fileno");
  346. if (this.layout_fileno) this.layout_fileno.setStyles(this.css.doc_layout_fileno);
  347. td = this.contentNode.getElement(".doc_layout_filenoup_signer_td");
  348. if (td) td.setStyles(this.css.doc_layout_filenoup_signer_td);
  349. var node = this.contentNode.getElement(".doc_layout_filenoup_signer_table");
  350. if (node) node.setStyles(this.css.doc_layout_filenoup_signer_table);
  351. node = this.contentNode.getElement(".doc_layout_filenoup_signerTitle_td");
  352. if (node) node.setStyles(this.css.doc_layout_filenoup_signerTitle_td);
  353. this.layout_signerTitle = this.contentNode.getElement(".doc_layout_filenoup_signer");
  354. if (this.layout_signerTitle) this.layout_signerTitle.setStyles(this.css.doc_layout_filenoup_signer);
  355. node = this.contentNode.getElement(".doc_layout_filenoup_signerContent_td");
  356. if (node) node.setStyles(this.css.doc_layout_filenoup_signerContent_td);
  357. this.layout_signer = this.contentNode.getElement(".doc_layout_filenoup_signerContent");
  358. if (this.layout_signer) this.layout_signer.setStyles(this.css.doc_layout_filenoup_signerContent);
  359. if (!this.layout_fileno){
  360. this.layout_filenoArea = this.contentNode.getElement(".doc_layout_fileno_area");
  361. this.layout_fileNoUpTable = this.contentNode.getElement(".doc_layout_filenoup");
  362. if (this.layout_fileNoUpTable) this.layout_fileNoUpTable.setStyles(this.css.doc_layout_filenoup);
  363. var td = this.contentNode.getElement(".doc_layout_filenoup_fileno_td");
  364. if (td) td.setStyles(this.css.doc_layout_filenoup_fileno_td);
  365. this.layout_fileno = this.contentNode.getElement(".doc_layout_filenoup_fileno");
  366. if (this.layout_fileno) this.layout_fileno.setStyles(this.css.doc_layout_filenoup_fileno);
  367. }
  368. },
  369. //红线
  370. _loadRedLine: function(){
  371. this.layout_redLine = this.contentNode.getElement(".doc_layout_redline");
  372. if (this.layout_redLine) this.layout_redLine.setStyles(this.css.doc_layout_redline);
  373. },
  374. //标题
  375. _loadSubject:function(){
  376. /**
  377. * @summary 标题的dom对象.
  378. * @member {MWF.xApplication.process.Xform.Documenteditor}
  379. */
  380. this.layout_subject = this.contentNode.getElement(".doc_layout_subject");
  381. if (this.layout_subject) this.layout_subject.setStyles(this.css.doc_layout_subject);
  382. if (this.json.subjectFontFamily){
  383. if (this.layout_subject) this.layout_subject.setStyle("font-family", this.json.subjectFontFamily);
  384. }
  385. },
  386. //主送
  387. _loadMainSend: function(){
  388. /**
  389. * @summary 主送的dom对象.
  390. * @member {MWF.xApplication.process.Xform.Documenteditor}
  391. */
  392. this.layout_mainSend = this.contentNode.getElement(".doc_layout_mainSend");
  393. if (this.layout_mainSend) this.layout_mainSend.setStyles(this.css.doc_layout_mainSend);
  394. },
  395. //正文
  396. // _createFiletext: function(filetextNode, node, where){
  397. // if (!filetextNode){
  398. // var filetextNode = new Element("div.doc_layout_filetext").inject(node, where);
  399. // filetextNode.addClass("doc_block");
  400. // filetextNode.setAttribute('contenteditable', true);
  401. // }
  402. // CKEDITOR.disableAutoInline = true;
  403. // var filetextEditor = CKEDITOR.inline(filetextNode, this._getEditorConfig());
  404. // filetextNode.store("editor", filetextEditor);
  405. // if (!this.filetextEditors) this.filetextEditors = [];
  406. // this.filetextEditors.push(filetextEditor);
  407. //
  408. // filetextEditor.on( 'blur', function(e) {
  409. // // var filetextNode = e.editor.container.$;
  410. // // var pageNode = filetextNode.getParent(".doc_layout_page");
  411. // // this._checkSplitPage(pageNode);
  412. // // this._repage();
  413. // }.bind(this));
  414. //
  415. // return filetextNode;
  416. // },
  417. _loadFiletext: function(){
  418. /**
  419. * @summary 正文区域的dom对象.
  420. * @member {MWF.xApplication.process.Xform.Documenteditor}
  421. */
  422. this.layout_filetext = this.contentNode.getElement(".doc_layout_filetext");
  423. this.layout_filetext.addClass("css"+this.form.json.id+this.json.id);
  424. this.layout_filetext.setStyles(this.css.doc_layout_filetext);
  425. //this.layout_filetext = this.contentNode.getElement(".doc_layout_filetext");
  426. // if (this.layout_filetexts.length){
  427. // this.layout_filetexts.each(function(layout_filetext){
  428. // layout_filetext.setStyles(this.css.doc_layout_filetext);
  429. // }.bind(this));
  430. // }
  431. },
  432. //附件
  433. _loadAttachment: function(){
  434. this.layout_attachmentTable = this.contentNode.getElement(".doc_layout_attachment");
  435. if (this.layout_attachmentTable) this.layout_attachmentTable.setStyles(this.css.doc_layout_attachment);
  436. var node = this.contentNode.getElement(".doc_layout_attachment_title_td");
  437. if (node) node.setStyles(this.css.doc_layout_attachment_title_td);
  438. this.layout_attachmentTitle = this.contentNode.getElement(".doc_layout_attachment_title");
  439. if (node) node.setStyles(this.css.doc_layout_attachment_title);
  440. node = this.contentNode.getElement(".doc_layout_attachment_content_td");
  441. if (node) node.setStyles(this.css.doc_layout_attachment_content_td);
  442. /**
  443. * @summary 附件区域的dom对象.
  444. * @member {MWF.xApplication.process.Xform.Documenteditor}
  445. */
  446. this.layout_attachment = this.contentNode.getElement(".doc_layout_attachment_content");
  447. if (this.layout_attachment) this.layout_attachment.setStyles(this.css.doc_layout_attachment_content);
  448. },
  449. //发布单位
  450. _loadIssuance: function(){
  451. this.layout_issuanceTable = this.contentNode.getElement(".doc_layout_issuance");
  452. /**
  453. * @summary 发文单位的dom对象.
  454. * @member {MWF.xApplication.process.Xform.Documenteditor}
  455. */
  456. this.layout_issuanceUnit = this.contentNode.getElement(".doc_layout_issuanceUnit");
  457. /**
  458. * @summary 发文时间的dom对象.
  459. * @member {MWF.xApplication.process.Xform.Documenteditor}
  460. */
  461. this.layout_issuanceDate = this.contentNode.getElement(".doc_layout_issuanceDate");
  462. if (this.layout_issuanceTable) this.layout_issuanceTable.setStyles(this.css.doc_layout_issuance);
  463. if (this.layout_issuanceUnit) this.layout_issuanceUnit.setStyles(this.css.doc_layout_issuanceUnit);
  464. if (this.layout_issuanceDate) this.layout_issuanceDate.setStyles(this.css.doc_layout_issuanceDate);
  465. },
  466. //附注
  467. _loadAnnotation: function(){
  468. /**
  469. * @summary 附注的dom对象.
  470. * @member {MWF.xApplication.process.Xform.Documenteditor}
  471. */
  472. this.layout_annotation = this.contentNode.getElement(".doc_layout_annotation");
  473. if (this.layout_annotation) this.layout_annotation.setStyles(this.css.doc_layout_annotation);
  474. },
  475. //附件文本
  476. _loadAttachmentText: function(){
  477. this.layout_attachmentText = this.contentNode.getElement(".doc_layout_attachment_text");
  478. },
  479. //版记
  480. _loadEdition: function(){
  481. this.layout_editionArea = this.contentNode.getElement(".doc_layout_editionArea");
  482. this.layout_edition = this.contentNode.getElement(".doc_layout_edition");
  483. if (this.layout_edition) this.layout_edition.setStyles(this.css.doc_layout_edition);
  484. var node = this.contentNode.getElement(".doc_layout_edition_copyto");
  485. if (node) node.setStyles(this.css.doc_layout_edition_copyto);
  486. node = this.contentNode.getElement(".doc_layout_edition_copyto_table");
  487. if (node) node.setStyles(this.css.doc_layout_edition_copyto_table);
  488. var node = this.contentNode.getElement(".doc_layout_edition_copyto2");
  489. if (node) node.setStyles(this.css.doc_layout_edition_copyto);
  490. node = this.contentNode.getElement(".doc_layout_edition_copyto2_table");
  491. if (node) node.setStyles(this.css.doc_layout_edition_copyto_table);
  492. this.layout_copytoTitle = this.contentNode.getElement(".doc_layout_edition_copyto_title");
  493. if (this.layout_copytoTitle) this.layout_copytoTitle.setStyles(this.css.doc_layout_edition_copyto_title);
  494. /**
  495. * @summary 抄送的dom对象.
  496. * @member {MWF.xApplication.process.Xform.Documenteditor}
  497. */
  498. this.layout_copytoContent = this.contentNode.getElement(".doc_layout_edition_copyto_content");
  499. if (this.layout_copytoContent) this.layout_copytoContent.setStyles(this.css.doc_layout_edition_copyto_content);
  500. this.layout_copyto2Title = this.contentNode.getElement(".doc_layout_edition_copyto2_title");
  501. if (this.layout_copyto2Title) this.layout_copyto2Title.setStyles(this.css.doc_layout_edition_copyto_title);
  502. this.layout_copyto2Content = this.contentNode.getElement(".doc_layout_edition_copyto2_content");
  503. if (this.layout_copyto2Content) this.layout_copyto2Content.setStyles(this.css.doc_layout_edition_copyto_content);
  504. var issuance = this.contentNode.getElement(".doc_layout_edition_issuance");
  505. if (issuance) issuance.setStyles(this.css.doc_layout_edition_issuance);
  506. var issuance_table = this.contentNode.getElement(".doc_layout_edition_issuance_table");
  507. if (issuance_table) issuance_table.setStyles(this.css.doc_layout_edition_issuance_table);
  508. /**
  509. * @summary 印发单位的dom对象.
  510. * @member {MWF.xApplication.process.Xform.Documenteditor}
  511. */
  512. this.layout_edition_issuance_unit = this.contentNode.getElement(".doc_layout_edition_issuance_unit");
  513. if (this.layout_edition_issuance_unit) this.layout_edition_issuance_unit.setStyles(this.css.doc_layout_edition_issuance_unit);
  514. /**
  515. * @summary 印发时间的dom对象.
  516. * @member {MWF.xApplication.process.Xform.Documenteditor}
  517. */
  518. this.layout_edition_issuance_date = this.contentNode.getElement(".doc_layout_edition_issuance_date");
  519. if (this.layout_edition_issuance_date) this.layout_edition_issuance_date.setStyles(this.css.doc_layout_edition_issuance_date);
  520. },
  521. loadSeal: function(){
  522. /**
  523. * @summary 模拟盖章的dom对象.
  524. * @member {MWF.xApplication.process.Xform.Documenteditor}
  525. */
  526. this.layout_seals = this.contentNode.getElements(".doc_layout_seal");
  527. this.layout_seals.each(function(node){
  528. // if (!node.get("src")){
  529. node.hide();
  530. // }else{
  531. // node.show();
  532. // node.setStyles({
  533. // "border": "0",
  534. // "border-radius": "0"
  535. // });
  536. // }
  537. });
  538. },
  539. /**对正文进行模拟盖章(模板中必须有class为“doc_layout_seal”的img对象)
  540. * @summary 对正文进行模拟盖章,此方法只是进行模拟盖章,通过图片显示,并非专业盖章,不具备法律效应。
  541. * * @param src{String} 盖章图片的url.
  542. * @param position{integer} 要盖章的位置, 默认为0.
  543. * @example
  544. * this.form.get("documenteditor").seal("../custom/img/seal.png", 0); //在第一个盖章位置进行模拟盖章
  545. */
  546. seal: function(src, position){
  547. var p = position || 0;
  548. if (this.layout_seals && this.layout_seals.length){
  549. if (this.layout_seals[p]){
  550. this.layout_seals[p].src = src;
  551. this.layout_seals[p].show();
  552. this.layout_seals[p].setStyles({
  553. "border": "0",
  554. "border-radius": "0",
  555. "z-index": -1
  556. });
  557. }
  558. this.getSealData();
  559. }
  560. },
  561. _loadMeeting: function(){
  562. this.layout_meetingAttendArea = this.contentNode.getElement(".doc_layout_meeting_attend");
  563. this.layout_meetingAttendTitle = this.contentNode.getElement(".doc_layout_meeting_attend_title");
  564. this.layout_meetingAttendContent = this.contentNode.getElement(".doc_layout_meeting_attend_content");
  565. this.layout_meetingLeaveArea = this.contentNode.getElement(".doc_layout_meeting_leave");
  566. this.layout_meetingLeaveTitle = this.contentNode.getElement(".doc_layout_meeting_leave_title");
  567. this.layout_meetingLeaveContent = this.contentNode.getElement(".doc_layout_meeting_leave_content");
  568. this.layout_meetingSitArea = this.contentNode.getElement(".doc_layout_meeting_sit");
  569. this.layout_meetingSitTitle = this.contentNode.getElement(".doc_layout_meeting_sit_title");
  570. this.layout_meetingSitContent = this.contentNode.getElement(".doc_layout_meeting_sit_content");
  571. this.layout_meetingRecordArea = this.contentNode.getElement(".doc_layout_meeting_record");
  572. this.layout_meetingRecordTitle = this.contentNode.getElement(".doc_layout_meeting_record_title");
  573. this.layout_meetingRecordContent = this.contentNode.getElement(".doc_layout_meeting_record_content");
  574. },
  575. _loadCustom: function(){
  576. var nodes = this.contentNode.getElements(".doc_layout");
  577. nodes.each(function(node){
  578. var name = node.get("data-doc-layout");
  579. if (!this.customLayouts) this.customLayouts = [];
  580. this.customLayouts.push({
  581. "name": name,
  582. "node": node,
  583. });
  584. this[name] = node;
  585. }.bind(this));
  586. },
  587. _loadPageLayout: function(control){
  588. this._loadCopiesSecretPriority();
  589. this._loadRedHeader();
  590. if (this.json.fileup){
  591. this._loadFileNoUp();
  592. }else{
  593. this._loadFileNo();
  594. }
  595. if (!this.layout_fileno) this._loadFileNo();
  596. this._loadRedLine();
  597. this._loadSubject();
  598. this._loadMainSend();
  599. this._loadFiletext();
  600. this._loadAttachment();
  601. this._loadIssuance();
  602. this._loadAnnotation();
  603. this._loadAttachmentText()
  604. this._loadEdition();
  605. this.loadSeal();
  606. //会议纪要
  607. this._loadMeeting();
  608. //自定义
  609. this._loadCustom();
  610. this.reSetShow(control);
  611. this.reSetEdit();
  612. // 份数: this.layout_copies
  613. // 密级: this.layout_secret
  614. // 紧急程度: this.layout_priority
  615. // 红头: this.layout_redHeader
  616. // 上行文编号签发: this.layout_fileNoUpTable
  617. // 文号: this.layout_fileno
  618. // 签发: this.layout_signerTitle
  619. // 签发人: this.layout_signer
  620. // 文号: this.layout_fileno
  621. // 红线: this.layout_redLine
  622. // 标题: this.layout_subject
  623. // 主送单位: this.layout_mainSend
  624. // 正文: this.layout_filetexts
  625. // 附件: this.layout_attachmentTitle
  626. // 附件: this.layout_attachment
  627. // 单位: this.layout_issuanceUnit
  628. // 签发时间: this.layout_issuanceDate
  629. // 附注: this.layout_annotation
  630. // 抄送: this.layout_copytoTitle
  631. // 抄送: this.layout_copytoContent
  632. // 版记单位 this.layout_edition_issuance_unit
  633. // 版记日期 this.layout_edition_issuance_date
  634. },
  635. reSetShow: function(control){
  636. if (!control) control = this.getShowControl();
  637. var m = function(s){ return (control[s]) ? "show" : "hide"; }
  638. if (this.layout_copiesSecretPriority) this.layout_copiesSecretPriority[m("copiesSecretPriority")]();
  639. // control.copies = this._getShow("copies", "copiesShow", "copiesShowScript");
  640. // control.secret = this._getShow("secret", "secretShow", "secretShowScript");
  641. // control.priority = this._getShow("priority", "priorityShow", "priorityShowScript");
  642. var n = 0;
  643. if (!control.copies) n++;
  644. if (!control.secret) n++;
  645. if (!control.priority) n++;
  646. if (this.layout_copiesSecretPriority_blank){
  647. this.layout_copiesSecretPriority_blank.empty();
  648. while (n>0){
  649. this.layout_copiesSecretPriority_blank.appendHTML("<p class=\"MsoNormal\"><span style='font-size:16.0pt'>&nbsp;</span></p>");
  650. n--;
  651. }
  652. }
  653. if (this.layout_copies) this.layout_copies[m("copies")]();
  654. if (this.layout_secret) this.layout_secret[m("secret")]();
  655. if (this.layout_priority) this.layout_priority[m("priority")]();
  656. if (this.layout_redHeader) this.layout_redHeader[m("redHeader")]();
  657. if (this.layout_redLine) this.layout_redLine[m("redLine")]();
  658. if (this.layout_fileNoUpTable) this.layout_fileNoUpTable[m("signer")]();
  659. if (this.layout_filenoArea) this.layout_filenoArea[(!control.signer) ? "show" : "hide"]();
  660. if (this.json.fileup){
  661. this._loadFileNoUp();
  662. }else{
  663. this._loadFileNo();
  664. }
  665. if (this.layout_fileno) this.layout_fileno.set("text", this.data.fileno || " ");
  666. if (this.layout_signerTitle) this.layout_signerTitle[m("signer")]();
  667. if (this.layout_signer) this.layout_signer[m("signer")]();
  668. if (this.layout_fileno) this.layout_fileno[m("fileno")]();
  669. if (this.layout_subject) this.layout_subject[m("subject")]();
  670. if (this.layout_mainSend) this.layout_mainSend[m("mainSend")]();
  671. if (this.layout_attachmentTable) this.layout_attachmentTable[m("attachment")]();
  672. if (this.layout_issuanceUnit) this.layout_issuanceUnit[m("issuanceUnit")]();
  673. if (this.layout_issuanceDate) this.layout_issuanceDate[m("issuanceDate")]();
  674. if (this.layout_issuanceUnit && this.layout_issuanceDate){
  675. var table = this.layout_issuanceUnit.getParent("table")
  676. if (table && !table.hasClass("doc_layout_headIssuance")) {
  677. var unitWidth = o2.getTextSize(this.layout_issuanceUnit.get("text"), {
  678. "font-size": "16pt",
  679. "font-family": "'Times New Roman',仿宋_GB2312",
  680. "letter-spacing": "-0.4pt"
  681. }).x;
  682. var dateWidth = o2.getTextSize(this.layout_issuanceDate.get("text"), {
  683. "font-size": "16pt",
  684. "font-family": "'Times New Roman',仿宋_GB2312",
  685. "letter-spacing": "-0.4pt"
  686. }).x;
  687. if (table.hasClass("doc_layout_issuanceV2")){
  688. if (unitWidth<=dateWidth){
  689. //日期右空四字,单位相对与日期居中
  690. var flagTd = this.layout_issuanceUnit.getParent("td").getNext("td");
  691. if (flagTd) flagTd.setStyle("width", "64pt");
  692. flagTd = this.layout_issuanceDate.getParent("td").getNext("td");
  693. if (flagTd) flagTd.setStyle("width", "64pt");
  694. var dateP = this.layout_issuanceDate.getParent("p");
  695. if (dateP){
  696. dateP.setStyle("text-align", "right");
  697. var span = dateP.getElement("span.space");
  698. if (span) span.destroy();
  699. }
  700. }else{
  701. var flagTd = this.layout_issuanceUnit.getParent("td").getNext("td");
  702. if (flagTd) flagTd.setStyle("width", "32pt");
  703. flagTd = this.layout_issuanceDate.getParent("td").getNext("td");
  704. if (flagTd) flagTd.setStyle("width", "32pt");
  705. var dateP = this.layout_issuanceDate.getParent("p");
  706. var dateP = this.layout_issuanceDate.getParent("p");
  707. if (dateP){
  708. dateP.setStyle("text-align", "left");
  709. var span = dateP.getElement("span.space");
  710. if (!span) new Element("span.space", { "html": "&#x3000;&#x3000;" }).inject(dateP, "top");
  711. }
  712. }
  713. }else{
  714. if (unitWidth <= dateWidth) {
  715. //日期右空四字,单位相对与日期居中
  716. var flagTd = this.layout_issuanceDate.getParent("td").getNext("td");
  717. if (flagTd) {
  718. var pt = 16*4; //空四字
  719. flagTd.setStyle("width", "" + pt + "pt");
  720. flagTd = this.layout_issuanceUnit.getParent("td").getNext("td");
  721. if (flagTd) flagTd.setStyle("width", "" + pt + "pt");
  722. }
  723. //var dateTd = this.layout_issuanceDate.getParent("td");
  724. var unitTd = this.layout_issuanceUnit.getParent("td");
  725. unitTd.setStyle("width", dateWidth);
  726. var p = this.layout_issuanceUnit.getParent("p");
  727. if (p) p.setStyle("text-align", "center");
  728. } else {
  729. var flagTd = this.layout_issuanceUnit.getParent("td").getNext("td");
  730. if (flagTd) flagTd.setStyle("width", "32pt");
  731. var unitTd = this.layout_issuanceUnit.getParent("td");
  732. unitTd.setStyle("width", "auto");
  733. flagTd = this.layout_issuanceDate.getParent("td").getNext("td");
  734. if (flagTd) flagTd.setStyle("width", "64pt");
  735. var p = this.layout_issuanceDate.getParent("p");
  736. if (p) p.setStyle("text-align", "right");
  737. }
  738. }
  739. }
  740. }
  741. if (this.layout_annotation) this.layout_annotation[m("annotation")]();
  742. 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)){
  743. if (this.layout_editionArea) this.layout_editionArea.hide();
  744. }else{
  745. if (this.layout_copytoContent){
  746. if (!this.layout_copytoContentTr) this.layout_copytoContentTr = this.layout_copytoContent.getParent("tr");
  747. if (!this.layout_copytoContentTrP) this.layout_copytoContentTrP = this.layout_copytoContentTr.getParent();
  748. }
  749. if (this.layout_copyto2Content){
  750. if (!this.layout_copyto2ContentTr) this.layout_copyto2ContentTr = this.layout_copyto2Content.getParent("tr");
  751. if (!this.layout_copyto2ContentTrP) this.layout_copyto2ContentTrP = this.layout_copyto2ContentTr.getParent();
  752. }
  753. if (!this.copyToOrder){
  754. this.copyToOrder = "unknow"
  755. if (this.layout_copytoContentTr && this.layout_copyto2ContentTr){ //需要知道顺序
  756. if (this.layout_copytoContentTrP && this.layout_copyto2ContentTrP && this.layout_copytoContentTrP==this.layout_copyto2ContentTrP){
  757. var n = this.layout_copytoContentTrP.getFirst();
  758. while (n && n!=this.layout_copytoContentTr && n!=this.layout_copyto2ContentTr){
  759. n = n.getNext();
  760. }
  761. if (n==this.layout_copytoContentTr){
  762. this.copyToOrder = "copyto";
  763. }
  764. if (n==this.layout_copyto2ContentTr){
  765. this.copyToOrder = "copyto2";
  766. }
  767. }
  768. }
  769. }
  770. if ((!control.copyto || !this.layout_copytoContent) && (!control.copyto2 || !this.layout_copyto2Content) ){
  771. if (this.layout_edition){
  772. if (this.layout_copytoContentTr) this.layout_copytoContentTr.dispose();
  773. if (this.layout_copyto2ContentTr) this.layout_copyto2ContentTr.dispose();
  774. // if (this.layout_edition) this.layout_edition.getElement("tr").getElements("td")[0].setStyles({
  775. // "border-top": "solid windowtext 1.5pt",
  776. // "mso-border-top-alt": "solid windowtext 1pt"
  777. // });
  778. }
  779. }else if (!control.copyto || !this.layout_copytoContent){
  780. if (this.layout_copytoContentTr) this.layout_copytoContentTr.dispose();
  781. if (this.layout_copyto2ContentTr){
  782. try{
  783. this.layout_copyto2ContentTr.inject(this.layout_copyto2ContentTrP, "top");
  784. }catch (e){
  785. this.layout_copyto2ContentTrP.appendHTML(this.layout_copyto2ContentTr.outerHTML, "top");
  786. }
  787. }
  788. //if (this.layout_copyto2Content) this.layout_edition.getElement("tr").destroy();
  789. // if (this.layout_edition) this.layout_edition.getElement("tr").getElements("td").setStyles({
  790. // "border-top": "solid windowtext 1.5pt",
  791. // "mso-border-top-alt": "solid windowtext 1pt"
  792. // });
  793. }else if (!control.copyto2 || !this.layout_copyto2Content) {
  794. if (this.layout_copyto2ContentTr) this.layout_copyto2ContentTr.dispose();
  795. // if (this.layout_copytoContentTr) this.layout_copytoContentTr.inject(this.layout_copytoContentTrP, "top");
  796. if (this.layout_copytoContentTr){
  797. try{
  798. this.layout_copytoContentTr.inject(this.layout_copytoContentTrP, "top");
  799. }catch (e){
  800. this.layout_copytoContentTrP.appendHTML(this.layout_copytoContentTr.outerHTML, "top");
  801. }
  802. }
  803. // if (this.layout_edition) this.layout_edition.getElement("tr").getElements("td").setStyles({
  804. // "border-bottom": "solid windowtext 0.75pt",
  805. // "mso-border-bottom-alt": "solid windowtext 0.75pt"
  806. // });
  807. }else{
  808. if (this.copyToOrder == "copyto2"){
  809. // if (this.layout_copytoContentTr) this.layout_copytoContentTr.inject(this.layout_copytoContentTrP, "top");
  810. // if (this.layout_copyto2ContentTr) this.layout_copyto2ContentTr.inject(this.layout_copyto2ContentTrP, "top");
  811. if (this.layout_copytoContentTr){
  812. try{
  813. this.layout_copytoContentTr.inject(this.layout_copytoContentTrP, "top");
  814. }catch (e){
  815. this.layout_copytoContentTrP.appendHTML(this.layout_copytoContentTr.outerHTML, "top");
  816. }
  817. }
  818. if (this.layout_copyto2ContentTr){
  819. try{
  820. this.layout_copyto2ContentTr.inject(this.layout_copyto2ContentTrP, "top");
  821. }catch (e){
  822. this.layout_copyto2ContentTrP.appendHTML(this.layout_copyto2ContentTr.outerHTML, "top");
  823. }
  824. }
  825. }else{
  826. // if (this.layout_copyto2ContentTr) this.layout_copyto2ContentTr.inject(this.layout_copyto2ContentTrP, "top");
  827. // if (this.layout_copytoContentTr) this.layout_copytoContentTr.inject(this.layout_copytoContentTrP, "top");
  828. if (this.layout_copyto2ContentTr){
  829. try{
  830. this.layout_copyto2ContentTr.inject(this.layout_copyto2ContentTrP, "top");
  831. }catch (e){
  832. this.layout_copyto2ContentTrP.appendHTML(this.layout_copyto2ContentTr.outerHTML, "top");
  833. }
  834. }
  835. if (this.layout_copytoContentTr){
  836. try{
  837. this.layout_copytoContentTr.inject(this.layout_copytoContentTrP, "top");
  838. }catch (e){
  839. this.layout_copytoContentTrP.appendHTML(this.layout_copytoContentTr.outerHTML, "top");
  840. }
  841. }
  842. }
  843. }
  844. if ((!control.editionUnit || !this.layout_edition_issuance_unit) && (!control.editionDate || !this.layout_edition_issuance_date)){
  845. if (this.layout_editionArea && (this.contentNode.getElement(".doc_layout_edition_issuance_date") || this.contentNode.getElement(".doc_layout_edition_issuance_unit"))){
  846. var trs = this.layout_editionArea.getElement("table").rows;
  847. trs.item(trs.length-1).destroy();
  848. // trs = this.layout_editionArea.getElement("table").rows;
  849. // var tr = trs.item(trs.length-1);
  850. // if (tr){
  851. // tr.getElements("td").setStyles({
  852. // "border-bottom": "solid windowtext 1.5pt",
  853. // "mso-border-bottom-alt": "solid windowtext 1pt"
  854. // });
  855. // }
  856. }
  857. }
  858. if (this.layout_editionArea && (this.layout_edition_issuance_date || this.layout_edition_issuance_unit)){
  859. trs = this.layout_editionArea.getElement("table").rows;
  860. for (var i=0; i<trs.length; i++){
  861. var tds = trs.item(i).cells;
  862. for (var n=0; n<tds.length; n++){
  863. var td = tds.item(n);
  864. var tdClass = td.get("class");
  865. var tdClassList = (tdClass) ? tdClass.split(/\s+/g) : [];
  866. if (tdClassList.indexOf("line_top_thin_bottom_thick") != -1) tdClassList = tdClassList.erase("line_top_thin_bottom_thick");
  867. if (tdClassList.indexOf("line_top_thick_bottom_thin") != -1) tdClassList = tdClassList.erase("line_top_thick_bottom_thin");
  868. if (tdClassList.indexOf("line_top_thick_bottom_thick") != -1) tdClassList = tdClassList.erase("line_top_thick_bottom_thick");
  869. if (tdClassList.indexOf("line_top_thin_bottom_thin") == -1) tdClassList.unshift("line_top_thin_bottom_thin");
  870. // td.setStyles({
  871. // "border-top": "solid windowtext 0.75pt",
  872. // "mso-border-top-alt": "solid windowtext 0.75pt",
  873. // "border-bottom": "solid windowtext 0.75pt",
  874. // "mso-border-bottom-alt": "solid windowtext 0.75pt",
  875. // });
  876. if (i==0 && i!=(trs.length-1)){
  877. if (tdClassList.indexOf("line_top_thin_bottom_thin") != -1) tdClassList = tdClassList.erase("line_top_thin_bottom_thin");
  878. tdClassList.unshift("line_top_thick_bottom_thin");
  879. // td.setStyles({
  880. // "border-top": "solid windowtext 1.5pt",
  881. // "mso-border-top-alt": "solid windowtext 1pt"
  882. // });
  883. }else if (i==0 && i==(trs.length-1)){
  884. if (tdClassList.indexOf("line_top_thin_bottom_thin") != -1) tdClassList = tdClassList.erase("line_top_thin_bottom_thin");
  885. tdClassList.unshift("line_top_thick_bottom_thick");
  886. }else if (i!=0 && i==(trs.length-1)){
  887. if (tdClassList.indexOf("line_top_thin_bottom_thin") != -1) tdClassList = tdClassList.erase("line_top_thin_bottom_thin");
  888. tdClassList.unshift("line_top_thin_bottom_thick");
  889. }
  890. // if (i==(trs.length-1)){
  891. // if (tdClassList.indexOf("line_bottom_thin") != -1) tdClassList = tdClassList.erase("line_bottom_thin");
  892. // if (tdClassList.indexOf("line_bottom_thick") == -1) tdClassList.push("line_bottom_thick");
  893. // // td.setStyles({
  894. // // "border-bottom": "solid windowtext 1.5pt",
  895. // // "mso-border-bottom-alt": "solid windowtext 1pt"
  896. // // });
  897. // }
  898. tdClass = tdClassList.join(" ");
  899. td.set("class", tdClass);
  900. }
  901. }
  902. }
  903. var coptyToTitleNode = (this.layout_copytoTitle || this.layout_copyto2Title);
  904. if (coptyToTitleNode){
  905. var editionTable = coptyToTitleNode.getParent("table");
  906. if (editionTable) if (editionTable.get("data-compute-style")=="y"){
  907. var rows = editionTable.rows;
  908. for (var i=0; i<rows.length; i++){
  909. var cell = rows[i].cells[0];
  910. var tmp = cell.getElement(".doc_layout_edition_issuance_unit");
  911. if (!tmp) tmp = cell.getElement(".doc_layout_edition_issuance_date");
  912. if (!tmp){
  913. var text = cell.get("text").trim();
  914. var l = 14*text.length;
  915. var wl = 19*text.length;
  916. cell.setStyles({
  917. "max-width": ""+l+"pt",
  918. "min-width": ""+l+"pt",
  919. "width": ""+wl+"pt"
  920. });
  921. }
  922. }
  923. }
  924. }
  925. if (this.layout_editionArea) this.layout_editionArea.show();
  926. if (this.layout_copytoTitle) this.layout_copytoTitle[m("copyto")]();
  927. if (this.layout_copytoContent) this.layout_copytoContent[m("copyto")]();
  928. if (this.layout_copyto2Title) this.layout_copyto2Title[m("copyto2")]();
  929. if (this.layout_copyto2Content) this.layout_copyto2Content[m("copyto2")]();
  930. if (this.layout_edition_issuance_unit) this.layout_edition_issuance_unit[m("editionUnit")]();
  931. if (this.layout_edition_issuance_date) this.layout_edition_issuance_date[m("editionDate")]();
  932. }
  933. if (this.layout_meetingAttendArea) this.layout_meetingAttendArea[m("meetingAttend")]();
  934. if (this.layout_meetingLeaveArea) this.layout_meetingLeaveArea[m("meetingLeave")]();
  935. if (this.layout_meetingSitArea) this.layout_meetingSitArea[m("meetingSit")]();
  936. if (this.layout_meetingRecordArea) this.layout_meetingRecordArea[m("meetingRecord")]();
  937. // this.layout_annotation[m("annotation")]();
  938. // this.layout_annotation[m("annotation")]();
  939. // this.layout_annotation[m("annotation")]();
  940. },
  941. reSetEdit: function(control){
  942. //未进行数据绑定时,可允许编辑
  943. if (!control) var control = this.getEditControl();
  944. if (this.layout_subject){
  945. if (!this.json.subjectValueData && this.json.subjectValueType=="data"){
  946. this.layout_subject.set("contenteditable", control.subject);
  947. this.layout_subject.addEvent("paste", function(e){
  948. let paste = (e.event.clipboardData || window.clipboardData).getData('text');
  949. const selection = window.getSelection();
  950. if (!selection.rangeCount) return false;
  951. selection.deleteFromDocument();
  952. selection.getRangeAt(0).insertNode(document.createTextNode(paste));
  953. event.preventDefault();
  954. }.bind(this))
  955. // this.layout_subject.addEvent("blur", function(){
  956. // this.getData();
  957. // }.bind(this))
  958. this.layout_subject.addEvent("blur", function(e){
  959. var subject = this.layout_subject.get("text");
  960. if (!subject){
  961. this.layout_subject.set("html", this.data.subject);
  962. this.form.app.notice(MWF.xApplication.process.Xform.LP.subjectEmpty, "error", this.layout_subject, {"x": "center","y":"top"}, {"x": 0,"y":60});
  963. e.preventDefault();
  964. e.stopPropagation();
  965. }else{
  966. if (this.json.subjectEditBindFormData){
  967. this.form.Macro.environment.data[this.json.subjectEditBindFormData]=subject;
  968. }
  969. this.getData();
  970. }
  971. }.bind(this));
  972. }
  973. }
  974. if (this.layout_issuanceUnit){
  975. if (!this.json.issuanceUnitValueData && this.json.issuanceUnitValueType=="data"){
  976. this.layout_issuanceUnit.set("contenteditable", control.issuanceUnit);
  977. // this.layout_issuanceUnit.addEvent("blur", function(){
  978. // this.getData();
  979. // }.bind(this))
  980. this.layout_issuanceUnit.addEvent("blur", function(e){
  981. var issuanceUnit = this.layout_issuanceUnit.get("text");
  982. if (!issuanceUnit){
  983. this.layout_issuanceUnit.set("html", this.data.issuanceUnit);
  984. this.form.app.notice(MWF.xApplication.process.Xform.LP.issuanceUnitEmpty, "error", this.layout_issuanceUnit, {"x": "center","y":"top"}, {"x": 0,"y":60});
  985. e.preventDefault();
  986. e.stopPropagation();
  987. }else{
  988. this.getData();
  989. }
  990. }.bind(this));
  991. }
  992. }
  993. if (this.layout_filetext){
  994. // if (this.allowEdit) {
  995. // if (!this.loadFileTextEditFun) this.loadFileTextEditFun = this._switchReadOrEditInline.bind(this);
  996. // this.layout_filetext.removeEvent("click", this.loadFileTextEditFun);
  997. // this.layout_filetext.addEvent("click", this.loadFileTextEditFun);
  998. // }
  999. }
  1000. if (this.layout_attachmentText){
  1001. if (control.attachmentText) {
  1002. if (!this.loadAttachmentTextEditFun) this.loadAttachmentTextEditFun = this.loadAttachmentTextEdit.bind(this);
  1003. this.layout_attachmentText.removeEvent("click", this.loadAttachmentTextEditFun);
  1004. this.layout_attachmentText.addEvent("click", this.loadAttachmentTextEditFun);
  1005. if (!this.data.attachmentText){
  1006. this.layout_attachmentText.set("text", MWF.xApplication.process.Xform.LP.documentEditor.attachmentInfor);
  1007. }
  1008. }
  1009. }
  1010. // this.layout_subject.addEvent("keydown", function(e){
  1011. // if (this.json.subjectValueType=="data" && this.json.subjectValueData){
  1012. // // var v = e.target.get("HTML");
  1013. // // this.form.businessData.data[this.json.subjectValueData] = v
  1014. // var module = this.form.all[this.json.subjectValueData];
  1015. // if (module){
  1016. // var bindFun = module.node.retrieve(this.json.id+"bindFun");
  1017. // module.node
  1018. // }
  1019. // }
  1020. // }.bind(this));
  1021. },
  1022. loadAttachmentTextEdit: function(){
  1023. this._createEditor("inline", this.layout_attachmentText, this.data.attachmentText, "attachmentTextEditor", function(){
  1024. this.layout_attachmentText.removeEvent("click", this.loadAttachmentTextEditFun);
  1025. var text = this.layout_attachmentText.get("text");
  1026. text = text.replace(/\u3000*/g, "");
  1027. if (!text || text==MWF.xApplication.process.Xform.LP.documentEditor.attachmentInfor){
  1028. this.layout_attachmentText.empty();
  1029. this["attachmentTextEditor"].insertHtml("<div aria-label=\"分页符\" class=\"cke_pagebreak\" contenteditable=\"false\" data-cke-display-name=\"pagebreak\" data-cke-pagebreak=\"1\" style=\"page-break-after: always\" title=\"分页符\"></div>" +
  1030. "<div style=\"font-family:黑体;font-size:16pt;\">附件1</div>" +
  1031. "<div><span> </span></div>" +
  1032. "<div style=\"font-family: 方正小标宋简体; font-size: 22pt; text-align: center;\">附件标题</div>" +
  1033. "<div><span> </span></div>" +
  1034. "<div>  附件内容</div>");
  1035. }
  1036. }.bind(this));
  1037. },
  1038. _loadUserInterface: function(callback){
  1039. this.node.empty();
  1040. this.node.setStyles(this.form.css.documentEditorNode);
  1041. this.pages = [];
  1042. this.allowEdit = this._isAllowEdit();
  1043. this.allowPrint = this._isAllowPrint();
  1044. this.allowHistory = this._isAllowHistory();
  1045. this.toolNode = new Element("div", {"styles": this.css.doc_toolbar}).inject(this.node);
  1046. this.contentNode = new Element("div#doc_content", {"styles": this.css.doc_content}).inject(this.node);
  1047. if (!this.form.isLoaded){
  1048. this.form.addEvent("afterModulesLoad", function(){this.loadDocumentEditor(callback);}.bind(this));
  1049. }else{
  1050. this.loadDocumentEditor(callback);
  1051. }
  1052. o2.loadCss('../x_desktop/fonts/fonts.css');
  1053. },
  1054. loadDocumentEditor: function(callback){
  1055. this._loadToolbars();
  1056. this._loadFiletextPage(function(){
  1057. this._singlePage();
  1058. this.form.addEvent("beforeSave", function(){
  1059. this.getData();
  1060. this.checkSaveNewEdition();
  1061. }.bind(this));
  1062. if (this.json.toWord=="y"){
  1063. if (this.json.toWordTrigger=="open") this.docToWord();
  1064. if (this.json.toWordTrigger=="save") {
  1065. if (!this.form.toWordSaveList) this.form.toWordSaveList = [];
  1066. this.form.toWordSaveList.push(this);
  1067. }
  1068. if (this.json.toWordTrigger=="submit") {
  1069. if (!this.form.toWordSubmitList) this.form.toWordSubmitList = [];
  1070. this.form.toWordSubmitList.push(this);
  1071. }
  1072. }
  1073. //if (!layout.mobile) this.loadSideToolbar();
  1074. o2.load("../o2_lib/diff-match-patch/diff_match_patch.js");
  1075. if (this.form.businessData.data["$work"]){
  1076. var id = this.form.businessData.data["$work"].job;
  1077. o2.Actions.load("x_processplatform_assemble_surface").DocumentVersionAction.listWithJobCategory(id, this.json.id, function(json){
  1078. this.historyDocumentList = json.data;
  1079. if (this.historyDocumentList.length){
  1080. o2.Actions.load("x_processplatform_assemble_surface").DocumentVersionAction.get(this.historyDocumentList[this.historyDocumentList.length-1].id, function(json){
  1081. var data = JSON.parse(json.data.data);
  1082. this.originaHistoryData = data.data;
  1083. }.bind(this));
  1084. }
  1085. }.bind(this));
  1086. }
  1087. if (callback) callback();
  1088. }.bind(this));
  1089. if (!this.form.documenteditorList) this.form.documenteditorList=[];
  1090. this.form.documenteditorList.push(this);
  1091. },
  1092. getFiletextText: function(data){
  1093. // var div = new Element("div", {
  1094. // "html": data
  1095. // });
  1096. // var text = div.get("text");
  1097. // div.destroy();
  1098. // return text;
  1099. var div = document.createElement("div");
  1100. div.style.height = '0px';
  1101. document.body.appendChild(div);
  1102. div.innerHTML = data.replace(/<br><\/div>/g, '</div>').replace(/[\n\r]/g, '');
  1103. var text = div.innerText;
  1104. if (div.remove){
  1105. div.remove();
  1106. }else{
  1107. if (div.parentNode) div.parentNode.removeChild(div);
  1108. }
  1109. return text;
  1110. // return text.replace(/<br><\/div>/g, '</div>');
  1111. },
  1112. checkSaveNewEdition: function(callback){
  1113. if (!this.allowEdit || !this.data.filetext || this.data.filetext == this.json.defaultValue.filetext) return false;
  1114. if (this.form.businessData.work){
  1115. var originaData = this.form.businessData.originalData[this.json.id];
  1116. var editionData = {"category": this.json.id};
  1117. if (!originaData || !originaData.filetext || !this.originaHistoryData){
  1118. //保存原始版本
  1119. this.originaHistoryData = {"data": this.data.filetext, "v": "6"};
  1120. editionData.data = JSON.stringify({"data": this.data.filetext, "v": "6"});
  1121. }else if (originaData.filetext!=this.data.filetext){
  1122. //保存历史版本
  1123. var data = this.getFiletextText(this.data.filetext);
  1124. var earlyData = this.getFiletextText(originaData.filetext);
  1125. //var data = this.data.filetext;
  1126. //var earlyData = originaData.filetext;
  1127. var dmp = new diff_match_patch();
  1128. var diff_d = dmp.diff_main(earlyData, data);
  1129. dmp.diff_cleanupSemantic(diff_d);
  1130. var patch_list = dmp.patch_make(earlyData, data, diff_d);
  1131. var d = {
  1132. "patchs": dmp.patch_toText(patch_list),
  1133. "data": this.data.filetext,
  1134. "v": "6"
  1135. };
  1136. editionData.data = JSON.stringify(d);
  1137. }else{
  1138. return false;
  1139. }
  1140. o2.Actions.load("x_processplatform_assemble_surface").DocumentVersionAction.create(this.form.businessData.work.id, editionData, function(json){
  1141. //originaData.filetext = this.data.filetext;
  1142. if (callback) callback();
  1143. }.bind(this));
  1144. }
  1145. },
  1146. checkSaveNewHistroy: function(){
  1147. var p = o2.Actions.load("x_processplatform_assemble_surface").DocumentRevisionAction.getLast(this.form.businessData.work.job, this.json.id);
  1148. p.then(function(json){
  1149. if (!json.data || json.data.data!=this.data.filetext){
  1150. var data = {
  1151. "category": this.json.id,
  1152. "data":this.data.filetext
  1153. }
  1154. return o2.Actions.load("x_processplatform_assemble_surface").DocumentRevisionAction.create(this.form.businessData.work.id, data);
  1155. }
  1156. }.bind(this));
  1157. return p;
  1158. },
  1159. resetToolbarEvent: function(node){
  1160. if (Browser.ie11){
  1161. if (!this.waitLocation){
  1162. this.waitLocation = window.setTimeout(function(){
  1163. this.resizeToolbar(node);
  1164. this.waitLocation = false;
  1165. }.bind(this), 1000);
  1166. }
  1167. }else{
  1168. this.resizeToolbar(node);
  1169. }
  1170. },
  1171. resizeToolbar: function(node){
  1172. if (this.toolbarNode){
  1173. var p = this.toolNode.getPosition(node || this.scrollNode);
  1174. var size = this.toolNode.getSize();
  1175. var pl = this.toolbarNode.getStyle("padding-left").toInt();
  1176. var pr = this.toolbarNode.getStyle("padding-right").toInt();
  1177. var x = size.x-pl-pr;
  1178. //var pNode = this.toolNode.getOffsetParent();
  1179. debugger;
  1180. var paddingTop = (this.isFullScreen) ? 0 : (node || this.form.node).getStyle("padding-top");
  1181. var pTop = window.getComputedStyle(node || this.scrollNode).paddingTop;
  1182. try {
  1183. paddingTop = paddingTop.toInt();
  1184. pTop = pTop.toInt();
  1185. }catch (e) {
  1186. paddingTop = 0;
  1187. pTop = 0;
  1188. }
  1189. if (p.y<paddingTop && this.toolNode.offsetParent){
  1190. paddingTop = paddingTop - pTop;
  1191. this.toolbarNode.inject(node || this.scrollNode, "top");
  1192. this.toolbarNode.setStyles({
  1193. "position": "sticky",
  1194. "width": ""+x+"px",
  1195. "z-index": 200,
  1196. "top": paddingTop+"px",
  1197. "left": ""+p.x+"px"
  1198. });
  1199. var position = this.scrollNode.getStyle('position');
  1200. }else{
  1201. this.toolbarNode.inject(this.toolNode);
  1202. this.toolbarNode.setStyles({"position": "static", "width": "auto"});
  1203. }
  1204. }
  1205. },
  1206. resizeSidebar: function(){
  1207. if (this.sidebarNode){
  1208. var fileTextNode = this.contentNode.getElement("div.doc_layout_filetext");
  1209. if (fileTextNode){
  1210. this.sidebarNode.position({
  1211. relativeTo: fileTextNode,
  1212. position: 'topLeft',
  1213. edge: 'topRight',
  1214. offset: {"x": -20, "y": 60}
  1215. });
  1216. var p = fileTextNode.getPosition(this.form.app.content);
  1217. var ptop = fileTextNode.getPosition(this.node);
  1218. //if ((p.y+s.y)<0) this.sidebarNode.setStyle("top", p.y+s.y);
  1219. if (p.y<0){
  1220. var top = ptop.y-p.y+200;
  1221. this.sidebarNode.setStyle("top", top);
  1222. }
  1223. // var p = fileTextNode.getPosition();
  1224. // this.sidebarNode.setStyle("top", p.y);
  1225. }
  1226. }
  1227. },
  1228. loadSideToolbar: function(){
  1229. if (this.allowEdit){
  1230. if (this.pages.length){
  1231. var fileTextNode = this.pages[0].getElement("div.doc_layout_filetext");
  1232. if (fileTextNode){
  1233. this.sidebarNode = new Element("div", {"styles": this.css.doc_sidebar}).inject(this.node);
  1234. this.resizeSidebar();
  1235. this.scrollNode = this.sidebarNode.getParentSrcollNode() || this.node.getParent();
  1236. if (this.scrollNode){
  1237. this.scrollNode.addEvent("scroll", function(){
  1238. this.resizeSidebar();
  1239. }.bind(this));
  1240. }
  1241. 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>";
  1242. this.sidebarNode.set("html", html);
  1243. MWF.require("MWF.widget.Toolbar", function() {
  1244. this.sideToolbar = new MWF.widget.Toolbar(this.sidebarNode, {"style": "documentEdit_side"}, this);
  1245. this.sideToolbar.load();
  1246. }.bind(this));
  1247. }
  1248. }
  1249. }
  1250. },
  1251. _returnScale: function(){
  1252. this.isScale = false;
  1253. this.scale = 0;
  1254. this.contentNode.setStyles({
  1255. "transform":"scale(1)",
  1256. });
  1257. if (this.pages.length){
  1258. this.pages.each(function(page){
  1259. page.setStyles({
  1260. "transform":"scale(1)",
  1261. });
  1262. });
  1263. }
  1264. this.node.setStyles({
  1265. "height": "auto"
  1266. });
  1267. },
  1268. _checkScale: function(offset){
  1269. offset = 0;
  1270. this._contentNodeWitdh();
  1271. if (this.pages.length){
  1272. //var pageSize = this.pages[0].getSize();
  1273. var pageSize_x = this.options.docPageFullWidth;
  1274. // var contentSize = this.contentNode.getSize();
  1275. //var contentSize = this.node.getSize();
  1276. // var contentWidth = (offset) ? contentSize.x-20-offset : contentSize.x-20;
  1277. // if (contentWidth<pageSize_x){
  1278. // this.isScale = true;
  1279. // var scale = (contentWidth)/pageSize_x;
  1280. // //this.scale = scale;
  1281. // this.zoom(scale);
  1282. // this.resetNodeSize();
  1283. // }
  1284. var contentSize_x = this.node.getSize().x;
  1285. //pageSize_x = this.scale;
  1286. // if (this.scale){
  1287. // pageSize_x = this.scale*pageSize_x;
  1288. // contentSize_x = this.scale*contentSize_x;
  1289. // //offset = this.scale*(offset+20);
  1290. // }
  1291. if (this.history && this.history.historyListAreaNode) contentSize_x = contentSize_x-this.history.historyListAreaNode.getComputedSize().totalWidth-2;
  1292. var contentWidth = contentSize_x-offset-20;
  1293. var p = pageSize_x*(this.documenteditorScale || 1);
  1294. if (contentWidth<p){
  1295. this.isScale = true;
  1296. var scale = (contentWidth)/pageSize_x;
  1297. //this.scale = scale;
  1298. this.zoom(scale);
  1299. this.resetNodeSize();
  1300. }else if (this.documenteditorScale){
  1301. // p = pageSize_x*(this.documenteditorScale || 1);
  1302. }
  1303. }
  1304. },
  1305. zoom: function(scale){
  1306. if (scale) this.scale = scale;
  1307. if (this.zoomSelectAction){
  1308. for (var i=0; i<this.zoomSelectAction.options.length; i++){
  1309. var option = this.zoomSelectAction.options[i];
  1310. if (Math.abs(this.scale-option.value.toFloat())<0.05){
  1311. option.set("selected", true);
  1312. break;
  1313. }
  1314. }
  1315. }
  1316. var w = this.node.getSize().x;
  1317. if (this.history && this.history.historyListAreaNode) w = w-this.history.historyListAreaNode.getComputedSize().totalWidth-2;
  1318. w = w/this.scale;
  1319. this.contentNode.setStyles({
  1320. "transform":"scale("+this.scale+")",
  1321. "transform-origin": "0px 0px",
  1322. "overflow": "auto",
  1323. "width": ""+w+"px"
  1324. });
  1325. if (this.filetextEditor && this.filetextEditor.element) {
  1326. this.filetextEditor.element.$.store("scale", this.scale);
  1327. }
  1328. this._pageMargin();
  1329. },
  1330. _switchReadOrEdit: function(){
  1331. if (this.editMode){
  1332. this._readFiletext();
  1333. // if (this.allowEdit) {
  1334. // var button = this.toolbar.childrenButton[0];
  1335. // button.setText((layout.mobile) ? MWF.xApplication.process.Xform.LP.editdoc_mobile : MWF.xApplication.process.Xform.LP.editdoc);
  1336. // button.picNode.getElement("img").set("src", "../x_component_process_Xform/$Form/default/icon/editdoc.png");
  1337. // //this.getFullWidthFlagNode().dispose();
  1338. // }
  1339. this.editMode = false;
  1340. }else{
  1341. this._editFiletext();
  1342. // if (this.allowEdit) {
  1343. // var button = this.toolbar.childrenButton[0];
  1344. // button.setText((layout.mobile) ? MWF.xApplication.process.Xform.LP.editdocCompleted_mobile : MWF.xApplication.process.Xform.LP.editdocCompleted);
  1345. // button.picNode.getElement("img").set("src", "../x_component_process_Xform/$Form/default/icon/editdoc_completed.png");
  1346. // //this.toolbar.node.inject(this.getFullWidthFlagNode());
  1347. //
  1348. // }
  1349. this.editMode = true;
  1350. }
  1351. },
  1352. _switchReadOrEditInline: function(){
  1353. if (this.editMode){
  1354. this._readFiletext();
  1355. this.editMode = false;
  1356. }else{
  1357. this._editFiletext("inline");
  1358. //if (this.loadFileTextEditFun) this.layout_filetext.removeEvent("click", this.loadFileTextEditFun);
  1359. this.editMode = true;
  1360. }
  1361. //this._switchButtonText();
  1362. },
  1363. // _switchButtonText: function(){
  1364. // var text = (layout.mobile) ? MWF.xApplication.process.Xform.LP.editdoc_mobile : MWF.xApplication.process.Xform.LP.editdoc;
  1365. // var img = "editdoc.png";
  1366. // if (this.editMode){
  1367. // text = (layout.mobile) ? MWF.xApplication.process.Xform.LP.editdocCompleted_mobile : MWF.xApplication.process.Xform.LP.editdocCompleted;
  1368. // img = "editdoc_completed.png";
  1369. // }
  1370. //
  1371. // if (!layout.mobile && this.sideToolbar && this.sideToolbar.childrenButton[0]) {
  1372. // var button = this.sideToolbar.childrenButton[0];
  1373. // button.setText(text);
  1374. // button.picNode.getElement("img").set("src", "../x_component_process_Xform/$Form/default/icon/"+img);
  1375. // }
  1376. // if (this.toolbar && this.toolbar.childrenButton[0]){
  1377. // button = this.toolbar.childrenButton[0];
  1378. // button.setText(text);
  1379. // button.picNode.getElement("img").set("src", "../x_component_process_Xform/$Form/default/icon/"+img);
  1380. // }
  1381. // },
  1382. editFiletext: function(){
  1383. if (!this.editMode && this.allowEdit){
  1384. this._editFiletext("inline");
  1385. //if (this.loadFileTextEditFun) this.layout_filetext.removeEvent("click", this.loadFileTextEditFun);
  1386. this.editMode = true;
  1387. //this._switchButtonText();
  1388. }
  1389. },
  1390. // getFullWidthFlagNode: function(){
  1391. // if (!this.fullWidthFlagNode){
  1392. // this.fullWidthFlagNode = new Element("span", {
  1393. // "styles": {
  1394. // "line-height": "26px",
  1395. // "color": "#999999",
  1396. // "font-size": "12px"
  1397. // },
  1398. // "text": MWF.xApplication.process.Xform.LP.fullWidth
  1399. // });
  1400. // }
  1401. // return this.fullWidthFlagNode;
  1402. // },
  1403. _printDoc: function(e,el){
  1404. e.disable();
  1405. var scale = this.scale;
  1406. this.toWord(function(data, filename){
  1407. if (filename){
  1408. o2.saveAs(data, filename);
  1409. }else{
  1410. if (this.form.businessData.work && !this.form.businessData.work.completedTime){
  1411. this.form.workAction.getAttachmentStream(data.id, this.form.businessData.work.id);
  1412. }else{
  1413. this.form.workAction.getWorkcompletedAttachmentStream(data.id, ((this.form.businessData.workCompleted) ? this.form.businessData.workCompleted.id : this.form.businessData.work.id));
  1414. }
  1415. }
  1416. this.scaleTo(scale);
  1417. e.enable();
  1418. }.bind(this), "", null, true);
  1419. },
  1420. _historyDoc: function(){
  1421. if (this.json.viewTracesFullScreen===true){
  1422. this._fullScreen();
  1423. }
  1424. this._readFiletext();
  1425. this.editMode = false;
  1426. this.getHistory(function(){
  1427. }.bind(this), function(){
  1428. this.historyMode = false;
  1429. this.resetData();
  1430. }.bind(this));
  1431. this.historyMode = true;
  1432. },
  1433. getHistory: function(callback, nodiff){
  1434. if (this.history){
  1435. this.history.active(function(){
  1436. if (callback) callback();
  1437. }, function(){
  1438. if (nodiff) nodiff();
  1439. });
  1440. }else{
  1441. MWF.xDesktop.requireApp("process.Xform", "widget.DocumentHistory", function(){
  1442. this.history = new MWF.xApplication.process.Xform.widget.DocumentHistory(this);
  1443. this.history.load(function(){
  1444. if (callback) callback();
  1445. }, function(){
  1446. if (nodiff) nodiff();
  1447. });
  1448. }.bind(this));
  1449. }
  1450. },
  1451. htmlToText: function(html){
  1452. var tmpdiv = new Element("div", {"html": html});
  1453. var text = tmpdiv.get("text");
  1454. tmpdiv.destroy();
  1455. return text;
  1456. },
  1457. _readFiletext: function(){
  1458. //this._returnScale();
  1459. //this.zoom(1);
  1460. var scale = this.scale;
  1461. if (this.filetextEditor) this.filetextEditor.destroy();
  1462. if (this.filetextScrollNode){
  1463. if (this.reLocationFiletextToolbarFun){
  1464. this.filetextScrollNode.removeEvent("scroll", this.reLocationFiletextToolbarFun);
  1465. //this.form.app.removeEvent("resize", this.reLocationFiletextToolbarFun);
  1466. this.reLocationFiletextToolbarFun = null;
  1467. }
  1468. this.filetextScrollNode = null;
  1469. }
  1470. if (this.filetextToolbarNode) this.filetextToolbarNode = null;
  1471. this.layout_filetext.setAttribute('contenteditable', false);
  1472. this.data = this.getData();
  1473. if (!this.data.filetext){
  1474. //this.data.filetext = this.json.defaultValue.filetext;
  1475. this.layout_filetext.set("html", this.json.defaultValue.filetext);
  1476. }
  1477. //this._checkSplitPage(this.pages[0]);
  1478. this._repage();
  1479. this.scaleTo(scale);
  1480. },
  1481. _editFiletext: function(inline){
  1482. if (this.data.filetext == this.json.defaultValue.filetext) this.data.filetext = "  ";
  1483. this.setData(this.data);
  1484. this.node.setStyles({
  1485. "height":"auto"
  1486. });
  1487. this._createEditor(inline);
  1488. },
  1489. _createEditor: function(inline, node, data, editorName, callback){
  1490. if (this.allowEdit){
  1491. this.loadCkeditorFiletext(function(e){
  1492. //e.editor.focus();
  1493. // var text = (data || this.data.filetext).replace(/\u3000*/g, "");
  1494. // if (!text){
  1495. // var range = e.editor.createRange();
  1496. // range.moveToElementEditEnd(e.editor.editable());
  1497. //
  1498. // range.select();
  1499. // range.scrollIntoView();
  1500. // }else{
  1501. // e.editor.getSelection().scrollIntoView();
  1502. // }
  1503. //e.editor.getSelection().scrollIntoView();
  1504. // var text = (data || this.data.filetext).replace(/\u3000*/g, "");
  1505. // if (!text){
  1506. // var range = e.editor.createRange();
  1507. // range.moveToElementEditEnd(e.editor.editable());
  1508. //
  1509. // range.select();
  1510. // range.scrollIntoView();
  1511. // }else{
  1512. // e.editor.getSelection().scrollIntoView();
  1513. // }
  1514. // e.editor.getSelection().scrollIntoView();
  1515. //
  1516. //this.getFiletextToolber();
  1517. //this.filetextToolbarNode.inject(this.layout_filetext.getOffsetParent());
  1518. //this.locationFiletextToolbar(editorName);
  1519. if (callback) callback();
  1520. }.bind(this), inline, node, editorName);
  1521. }
  1522. },
  1523. getFiletextToolber: function(editorName){
  1524. if (editorName){
  1525. if (this[editorName]) {
  1526. if (!this[editorName+"ToolbarNode"]) {
  1527. // var className = "cke_editor_" + this[editorName].name;
  1528. // var toolbarNode = $$("." + className)[0];
  1529. var className = "cke_" + this[editorName].name;
  1530. var toolbarNode = $(className);
  1531. this[editorName+"ToolbarNode"] = toolbarNode;
  1532. }
  1533. }
  1534. }else{
  1535. if (this.filetextEditor) {
  1536. if (!this.filetextToolbarNode) {
  1537. // var className = "cke_editor_" + this.filetextEditor.name;
  1538. // var filetextToolbarNode = $$("." + className)[0];
  1539. var className = "cke_" + this.filetextEditor.name;
  1540. var filetextToolbarNode = $(className);
  1541. this.filetextToolbarNode = filetextToolbarNode;
  1542. //filetextToolbarNode.destroy();
  1543. }
  1544. }
  1545. }
  1546. },
  1547. reLocationFiletextToolbarEvent: function(editorName){
  1548. if (Browser.ie11){
  1549. o2.defer(this.reLocationFiletextToolbar, 500, this, [editorName]);
  1550. // if (this.waitLocationFiletext) window.clearTimeout(this.waitLocationFiletext);
  1551. // this.waitLocationFiletext = window.setTimeout(function(){
  1552. // this.reLocationFiletextToolbar(editorName);
  1553. // this.waitLocationFiletext = false;
  1554. // }.bind(this), 500);
  1555. // if (!this.waitLocationFiletext){
  1556. // this.waitLocationFiletext = window.setTimeout(function(){
  1557. // this.reLocationFiletextToolbar(editorName);
  1558. // this.waitLocationFiletext = false;
  1559. // }.bind(this), 1000);
  1560. // }
  1561. }else{
  1562. this.reLocationFiletextToolbar(editorName)
  1563. }
  1564. },
  1565. reLocationFiletextToolbar: function(editorName){
  1566. this.getFiletextToolber(editorName);
  1567. var toolbarNode = (editorName) ? this[editorName+"ToolbarNode"] : this.filetextToolbarNode;
  1568. var editor = (editorName) ? this[editorName] : this.filetextEditor;
  1569. var node = (editorName) ? this.layout_attachmentText : this.layout_filetext;
  1570. if (toolbarNode){
  1571. if (!this.filetextScrollNode){
  1572. var scrollNode = this.contentNode;
  1573. while (scrollNode){
  1574. if (scrollNode.getStyle("overflow")=="auto" || scrollNode.getStyle("overflow-y")=="auto"){
  1575. var transform;
  1576. if (window.getComputedStyle){
  1577. transform = window.getComputedStyle(this.contentNode).transform;
  1578. }else{
  1579. transform = currentStyle.transform
  1580. }
  1581. transform = transform.substring(transform.indexOf("(")+1);
  1582. transform = transform.substring(0, transform.indexOf(")"));
  1583. var scaleList = transform.split(/,\s*/g);
  1584. var scaleY = scaleList[3];
  1585. var scale = (scaleY || 1).toFloat();
  1586. if ((scrollNode.getScrollSize().y*scale-1)>scrollNode.getSize().y){
  1587. break;
  1588. }
  1589. }
  1590. scrollNode = scrollNode.getParent();
  1591. }
  1592. this.filetextScrollNode = scrollNode || this.node.getParent();
  1593. }
  1594. var h = toolbarNode.getSize().y;
  1595. var position = node.getPosition();
  1596. var size = node.getSize();
  1597. var contentSize = this.filetextScrollNode.getSize();
  1598. if (layout.userLayout && layout.userLayout.scale && layout.userLayout.scale!==1){
  1599. var x = editor.editable().$.getPosition().x;
  1600. toolbarNode.setStyle("left", ""+x+"px");
  1601. }
  1602. toolbarNode.setStyle("min-width", "530px");
  1603. if (position.y<0 && size.y+position.y+h<contentSize.y){
  1604. var tp = this.toolbar.node.getPosition();
  1605. var tsy = this.toolbar.node.getSize().y;
  1606. var h = tp.y+tsy;
  1607. toolbarNode.setStyle("top", ""+h+"px");
  1608. }else if (position.y-h<0){
  1609. var tp = this.toolbar.node.getPosition();
  1610. var tsy = this.toolbar.node.getSize().y;
  1611. var h = tp.y+tsy;
  1612. toolbarNode.setStyle("top", ""+h+"px");
  1613. }else{
  1614. var p = node.getPosition().y-h;
  1615. toolbarNode.setStyle("top", "" + p + "px");
  1616. }
  1617. }
  1618. },
  1619. locationFiletextToolbar: function(editorName){
  1620. // this.getFiletextToolber(editorName);
  1621. // var toolbarNode = (editorName) ? this[editorName+"ToolbarNode"] : this.filetextToolbarNode;
  1622. //
  1623. // toolbarNode.inject(this.scrollNode, "bottom");
  1624. // toolbarNode.setStyles({
  1625. // "position": "absolute",
  1626. // "top": "40px"
  1627. // });
  1628. this.reLocationFiletextToolbar(editorName);
  1629. var toolbarNode = (editorName) ? this[editorName+"ToolbarNode"] : this.filetextToolbarNode;
  1630. if (toolbarNode) {
  1631. var scrollNode = this.contentNode;
  1632. while (scrollNode){
  1633. if (scrollNode.getStyle("overflow")=="auto" || scrollNode.getStyle("overflow-y")=="auto"){
  1634. var transform;
  1635. if (window.getComputedStyle){
  1636. transform = window.getComputedStyle(this.contentNode).transform;
  1637. }else{
  1638. transform = currentStyle.transform
  1639. }
  1640. transform = transform.substring(transform.indexOf("(")+1);
  1641. transform = transform.substring(0, transform.indexOf(")"));
  1642. var scaleList = transform.split(/,\s*/g);
  1643. var scaleY = scaleList[3];
  1644. var scale = (scaleY || 1).toFloat();
  1645. if ((scrollNode.getScrollSize().y*scale-1)>scrollNode.getSize().y){
  1646. break;
  1647. }
  1648. }
  1649. scrollNode = scrollNode.getParent();
  1650. }
  1651. if (scrollNode){
  1652. this.filetextScrollNode = scrollNode
  1653. if (editorName){
  1654. if (this.reLocationAttachmentTextToolbarFun) this.filetextScrollNode.removeEvent("scroll", this.reLocationAttachmentTextToolbarFun);
  1655. if (!this.reLocationAttachmentTextToolbarFun) this.reLocationAttachmentTextToolbarFun = function(){
  1656. this.reLocationFiletextToolbarEvent(editorName);
  1657. }.bind(this);
  1658. this.filetextScrollNode.addEvent("scroll", this.reLocationAttachmentTextToolbarFun);
  1659. }else{
  1660. if (this.reLocationFiletextToolbarFun) this.filetextScrollNode.removeEvent("scroll", this.reLocationFiletextToolbarFun);
  1661. if (!this.reLocationFiletextToolbarFun) this.reLocationFiletextToolbarFun = this.reLocationFiletextToolbarEvent.bind(this);
  1662. this.filetextScrollNode.addEvent("scroll", this.reLocationFiletextToolbarFun);
  1663. }
  1664. }
  1665. }
  1666. },
  1667. _isAllowEdit:function(){
  1668. if (this.readonly) return false;
  1669. if (this.json.allowEdit=="n") return false;
  1670. if (this.json.allowEdit=="s"){
  1671. if (this.json.allowEditScript && this.json.allowEditScript.code){
  1672. return !!this.form.Macro.exec(this.json.allowEditScript.code, this);
  1673. }
  1674. }
  1675. return true;
  1676. },
  1677. _isAllowPrint: function(){
  1678. if (this.json.allowPrint=="n") return false;
  1679. if (this.json.allowPrint=="s"){
  1680. if (this.json.allowPrintScript && this.json.allowPrintScript.code){
  1681. return !!this.form.Macro.exec(this.json.allowPrintScript.code, this);
  1682. }
  1683. }
  1684. return true;
  1685. },
  1686. _isAllowHistory: function(){
  1687. if (this.json.allowHistory=="n") return false;
  1688. if (this.json.allowHistory=="s"){
  1689. if (this.json.allowHistoryScript && this.json.allowHistoryScript.code){
  1690. return !!this.form.Macro.exec(this.json.allowHistoryScript.code, this);
  1691. }
  1692. }
  1693. return true;
  1694. },
  1695. _getEdit: function(name, typeItem, scriptItem){
  1696. switch (this.json[typeItem]) {
  1697. case "y":
  1698. return true;
  1699. case "n":
  1700. return false;
  1701. case "s":
  1702. if (this.json[scriptItem] && this.json[scriptItem].code){
  1703. return !!this.form.Macro.exec(this.json[scriptItem].code, this);
  1704. }
  1705. return true;
  1706. }
  1707. },
  1708. loadCkeditorStyle: function(node){
  1709. if (node){
  1710. o2.load("ckeditor", function(){
  1711. //CKEDITOR.disableAutoInline = true;
  1712. node.setAttribute('contenteditable', true);
  1713. var editor = CKEDITOR.inline(this.layout_filetext, this._getEditorConfig());
  1714. this.filetextEditor.on("instanceReady", function(e){
  1715. if (callback) callback(e);
  1716. }.bind(this));
  1717. }.bind(this));
  1718. }
  1719. },
  1720. _loadToolbars: function(){
  1721. var html ="";
  1722. var editdoc, printdoc, history, fullscreen=MWF.xApplication.process.Xform.LP.fullScreen;
  1723. if (layout.mobile){
  1724. editdoc = MWF.xApplication.process.Xform.LP.editdoc_mobile;
  1725. printdoc = MWF.xApplication.process.Xform.LP.printdoc_mobile;
  1726. history = MWF.xApplication.process.Xform.LP.history_mobile;
  1727. }else{
  1728. editdoc = MWF.xApplication.process.Xform.LP.editdoc;
  1729. printdoc = MWF.xApplication.process.Xform.LP.printdoc;
  1730. history = MWF.xApplication.process.Xform.LP.history;
  1731. }
  1732. // if (this.allowEdit){
  1733. // //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>";
  1734. // html += "<span MWFnodetype=\"MWFToolBarButton\" MWFButtonImage=\"../x_component_process_Xform/$Form/default/icon/editdoc.png\" title=\""+editdoc+"\" MWFButtonAction=\"_switchReadOrEditInline\" MWFButtonText=\""+editdoc+"\"></span>";
  1735. // //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>";
  1736. // }
  1737. if (this.allowPrint){
  1738. html += "<span MWFnodetype=\"MWFToolBarButton\" MWFButtonImage=\"../x_component_process_Xform/$Form/default/icon/print.png\" title=\""+printdoc+"\" MWFButtonAction=\"_printDoc\" MWFButtonText=\""+printdoc+"\"></span>";
  1739. }
  1740. if (this.allowHistory){
  1741. html += "<span MWFnodetype=\"MWFToolBarButton\" MWFButtonImage=\"../x_component_process_Xform/$Form/default/icon/versions.png\" title=\""+history+"\" MWFButtonAction=\"_historyDoc\" MWFButtonText=\""+history+"\"></span>";
  1742. }
  1743. if (this.json.canFullScreen!=="n"){
  1744. html += "<span MWFnodetype=\"MWFToolBarButton\" MWFButtonImage=\"../x_component_process_Xform/$Form/default/icon/fullscreen.png\" title=\""+fullscreen+"\" MWFButtonAction=\"fullScreen\" MWFButtonText=\""+fullscreen+"\"></span>";
  1745. }
  1746. // if (this.json.fullWidth=="y"){
  1747. // html += "<span style='line-height: 26px; color: #999999; font-size: 12px'>已启用半角空格自动转换为全角空格,如需输入半角空格,请使用:SHIFT+空格</span>"
  1748. // }
  1749. this.toolbarNode = new Element("div", {"styles": this.css.doc_toolbar_node}).inject(this.toolNode);
  1750. this.toolbarNode.set("html", html);
  1751. MWF.require("MWF.widget.Toolbar", function() {
  1752. this.toolbar = new MWF.widget.Toolbar(this.toolbarNode, {"style": "documentEdit"}, this);
  1753. this.toolbar.load();
  1754. }.bind(this));
  1755. if (!layout.mobile){
  1756. window.setTimeout(function(){
  1757. this.scrollNode = this.toolbarNode.getParentSrcollNode()|| this.node.getParent();;
  1758. if (this.scrollNode){
  1759. this.scrollNode.addEvent("scroll", function(){
  1760. this.resetToolbarEvent();
  1761. }.bind(this));
  1762. }
  1763. }.bind(this), 1000)
  1764. }
  1765. // 取消双野功能 todo
  1766. this.doublePageAction = new Element("div", {"styles": this.css.doc_toolbar_doublePage, "text": MWF.xApplication.process.Xform.LP.doublePage}).inject(this.toolbarNode);
  1767. this.doublePageAction.addEvent("click", function(){
  1768. if (this.options.pageShow!=="double"){
  1769. this._doublePage();
  1770. }else{
  1771. this.options.pageShow="single";
  1772. this.reload();
  1773. // this._singlePage();
  1774. var _self = this;
  1775. window.setTimeout(function(){
  1776. _self.scaleTo((_self.json.isScale !== "y") ? 1 : _self.documenteditorScale);
  1777. },10);
  1778. }
  1779. }.bind(this));
  1780. if (this.json.canDoublePage==="n" || layout.mobile) this.doublePageAction.hide();
  1781. this.zoomActionArea = new Element("div", {"styles": {"float": "right", "margin-right": "10px"}}).inject(this.toolbarNode);
  1782. if (this.json.isScale !== "y") this.zoomActionArea.hide();
  1783. this.zoomAddAction = new Element("div", {
  1784. "styles": {
  1785. "float": "right",
  1786. "margin-top": "3px",
  1787. "height": "20px",
  1788. "width": "20px",
  1789. "text-align": "center",
  1790. "line-height": "20px",
  1791. "border": "1px solid #cccccc",
  1792. "background-color": "#ffffff",
  1793. "margin-left": "5px"
  1794. },
  1795. "text": "+"
  1796. }).inject(this.zoomActionArea);
  1797. this.zoomSelectAction = new Element("select", {
  1798. "styles": {
  1799. "float": "right",
  1800. "margin-top": "3px",
  1801. "height": "20px",
  1802. "width": "60px",
  1803. "text-align": "center",
  1804. "line-height": "20px",
  1805. "border": "1px solid #cccccc",
  1806. "background-color": "#ffffff",
  1807. "margin-left": "5px"
  1808. },
  1809. "text": "100%"
  1810. }).inject(this.zoomActionArea);
  1811. this.zoomSubAction = new Element("div", {
  1812. "styles": {
  1813. "float": "right",
  1814. "margin-top": "3px",
  1815. "height": "20px",
  1816. "width": "20px",
  1817. "text-align": "center",
  1818. "line-height": "20px",
  1819. "border": "1px solid #cccccc",
  1820. "background-color": "#ffffff",
  1821. "margin-left": "5px"
  1822. },
  1823. "text": "-"
  1824. }).inject(this.zoomActionArea);
  1825. // this.zoomSelectAction = new Element("select", {"styles": {"float": "right"}}).inject(this.toolbarNode);
  1826. var options = "<option value='2'>200%</option> " +
  1827. "<option value='1.95'>195%</option>" +
  1828. "<option value='1.9'>190%</option>" +
  1829. "<option value='1.85'>185%</option>" +
  1830. "<option value='1.8'>180%</option>" +
  1831. "<option value='1.75'>175%</option>" +
  1832. "<option value='1.7'>170%</option>" +
  1833. "<option value='1.65'>165%</option>" +
  1834. "<option value='1.6'>160%</option>" +
  1835. "<option value='1.55'>155%</option>" +
  1836. "<option value='1.5'>150%</option> " +
  1837. "<option value='1.45'>145%</option>" +
  1838. "<option value='1.4'>140%</option>" +
  1839. "<option value='1.35'>135%</option>" +
  1840. "<option value='1.3'>130%</option>" +
  1841. "<option value='1.25'>125%</option>" +
  1842. "<option value='1.2'>120%</option>" +
  1843. "<option value='1.15'>115%</option>" +
  1844. "<option value='1.1'>110%</option>" +
  1845. "<option value='1.05'>105%</option>" +
  1846. "<option value='1' selected>100%</option>" +
  1847. "<option value='0.95'>95%</option>" +
  1848. "<option value='0.90'>90%</option>" +
  1849. "<option value='0.85'>85%</option>" +
  1850. "<option value='0.80'>80%</option>" +
  1851. "<option value='0.75'>75%</option>" +
  1852. "<option value='0.70'>70%</option>" +
  1853. "<option value='0.65'>65%</option>" +
  1854. "<option value='0.6'>60%</option>" +
  1855. "<option value='0.55'>55%</option>" +
  1856. "<option value='0.5'>50%</option>";
  1857. this.zoomSelectAction.set("html", options);
  1858. this.zoomSelectAction.addEvent("change", function(e){
  1859. this.scaleTo(e.target.options[e.target.selectedIndex].value);
  1860. o2.UD.putData("documenteditorScale", {"scale": this.scale});
  1861. this.documenteditorScale = this.scale;
  1862. }.bind(this));
  1863. this.zoomAddAction.addEvent("click", function(){
  1864. var i = (this.scale/0.05).toInt();
  1865. if (i*0.05<this.scale) i++;
  1866. var v = i*0.05;
  1867. //var v = this.zoomSelectAction.options[this.zoomSelectAction.selectedIndex].value.toFloat();
  1868. v = v+0.05;
  1869. if (v<0.5) v = 0.5;
  1870. if (v>2) v = 2;
  1871. this.scaleTo(v);
  1872. o2.UD.putData("documenteditorScale", {"scale": this.scale});
  1873. this.documenteditorScale = this.scale;
  1874. }.bind(this));
  1875. this.zoomSubAction.addEvent("click", function(){
  1876. var i = (this.scale/0.05).toInt();
  1877. if (i*0.05<this.scale) i++;
  1878. var v = i*0.05;
  1879. //var v = this.zoomSelectAction.options[this.zoomSelectAction.selectedIndex].value.toFloat();
  1880. v = v-0.05;
  1881. if (v<0.5) v = 0.5;
  1882. if (v>2) v = 2;
  1883. this.scaleTo(v);
  1884. o2.UD.putData("documenteditorScale", {"scale": this.scale});
  1885. this.documenteditorScale = this.scale;
  1886. }.bind(this));
  1887. },
  1888. _fullScreen: function(){
  1889. this.positionNode = new Element("div").inject(this.node, "after");
  1890. // this.node.inject(this.scrollNode, "top");
  1891. this.node.inject(this.form?.node?.getParent() || document.body, "top");
  1892. this.form.node.hide();
  1893. this.node.setStyle("min-height", "100%");
  1894. this.fireEvent("fullScreen");
  1895. this.isFullScreen = true;
  1896. this.resizeToolbar();
  1897. },
  1898. _returnScreen: function(){
  1899. this.form.node.show();
  1900. this.node.inject(this.positionNode, "before");
  1901. this.positionNode.destroy();
  1902. this.node.setStyle("min-height", "");
  1903. this.fireEvent("returnScreen");
  1904. this.isFullScreen = false;
  1905. this.resizeToolbar();
  1906. },
  1907. fullScreen: function(bt){
  1908. var text = bt.node.get("text");
  1909. var content = this.form.app.content;
  1910. var stopFun = function(e){ e.stopPropagation(); };
  1911. if (text===MWF.xApplication.process.Xform.LP.returnScreen){
  1912. //this.form.node.getParent().show();
  1913. this.form.node.show();
  1914. this.node.inject(this.positionNode, "before");
  1915. this.positionNode.destroy();
  1916. // var styles = content.retrieve("tmpStyles");
  1917. // content.setStyles({
  1918. // "position": styles.position,
  1919. // "overflow": styles.overflow
  1920. // });
  1921. //this.node.setStyles(this.css.returnScreen);
  1922. this.node.setStyle("min-height", "");
  1923. this.fireEvent("returnScreen");
  1924. bt.setText(MWF.xApplication.process.Xform.LP.fullScreen);
  1925. // this.fullScreenScrollNode = this.node.getOffsetParent().getFirst().getParentSrcollNode();
  1926. // if (this.fullScreenScrollNode){
  1927. // if (this.fullScreenScrollResizeToolbarFun) this.fullScreenScrollNode.removeEvent("scroll", this.fullScreenScrollResizeToolbarFun);
  1928. // }
  1929. if (this.fullScrollNode){
  1930. if (this.fullScrollNodeResizeFun) this.fullScrollNode.removeEvent("scroll", this.fullScrollNodeResizeFun);
  1931. }
  1932. //this.node.removeEvent("wheel", stopFun);
  1933. this.isFullScreen = false;
  1934. this.resizeToolbar();
  1935. }else{
  1936. // this.positionNode = new Element("div").inject(this.node, "after");
  1937. // this.node.inject(content, "top");
  1938. // this.form.node.hide();
  1939. this.positionNode = new Element("div").inject(this.node, "after");
  1940. this.node.inject(this.form?.node?.getParent() || document.body, "top");
  1941. //this.form.node.getParent().hide();
  1942. this.form.node.hide();
  1943. this.fullScrollNode = this.node.getParentSrcollNode()|| this.node.getParent();;
  1944. if (this.fullScrollNode){
  1945. if (!this.fullScrollNodeResizeFun) this.fullScrollNodeResizeFun = function(){
  1946. this.resetToolbarEvent(this.fullScrollNode);
  1947. }.bind(this)
  1948. this.fullScrollNode.addEvent("scroll", this.fullScrollNodeResizeFun);
  1949. }
  1950. // var position = content.getStyle("poaition");
  1951. // var overflow = content.getStyle("overflow");
  1952. // content.store("tmpStyles", {"position": position, "overflow": overflow});
  1953. // content.setStyles({
  1954. // "position": "relative",
  1955. // "overflow": "auto"
  1956. // });
  1957. //this.node.setStyles(this.css.fullScreen);
  1958. this.node.setStyle("min-height", "100%");
  1959. this.fireEvent("fullScreen");
  1960. // this.fullScreenScrollNode = this.node.getOffsetParent().getFirst().getParentSrcollNode();
  1961. // if (this.fullScreenScrollNode){
  1962. // this.fullScreenScrollResizeToolbarFun = function(){this.resizeToolbar(this.fullScreenScrollNode);}.bind(this);
  1963. // this.fullScreenScrollResizeToolbarFun();
  1964. // this.fullScreenScrollNode.addEvent("scroll", this.fullScreenScrollResizeToolbarFun);
  1965. // }
  1966. bt.setText(MWF.xApplication.process.Xform.LP.returnScreen);
  1967. this.isFullScreen = true;
  1968. //this.node.addEvent("wheel", stopFun);
  1969. this.resizeToolbar();
  1970. }
  1971. if (this.options.pageShow!=="double"){
  1972. this.getData();
  1973. }
  1974. // this.getData();
  1975. var _self = this;
  1976. window.setTimeout(function(){
  1977. _self.reload();
  1978. },20)
  1979. },
  1980. /**缩放文件内容
  1981. * @param scale{Number} 缩放的比率
  1982. * @example
  1983. * this.form.get("fieldId").scaleTo(0.5);
  1984. */
  1985. scaleTo: function(scale){
  1986. //this._returnScale();
  1987. this.isScale = false;
  1988. this.scale = scale;
  1989. this.zoom();
  1990. // //var w = this.contentNode.getSize().x*this.scale;
  1991. // var w = this.contentNode.offsetWidth*this.scale;
  1992. // //if (layout.userLayout && layout.userLayout.scale) w = w*layout.userLayout.scale;
  1993. // var count = 1;
  1994. // var docPageFullWidth = (this.scale) ? this.scale*this.options.docPageFullWidth : this.options.docPageFullWidth;
  1995. // //if (layout.userLayout && layout.userLayout.scale) docPageFullWidth = docPageFullWidth*layout.userLayout.scale;
  1996. // var pageWidth = count * docPageFullWidth;
  1997. // var margin = (w-pageWidth)/(count+1);
  1998. // if (this.isScale){
  1999. // margin = "10";
  2000. // }
  2001. // if (this.scale) margin = margin/this.scale;
  2002. // if (margin < 10){
  2003. // var offset = 10-margin;
  2004. // margin = 10;
  2005. // this.contentNode.scrollTo(offset, 0);
  2006. // }
  2007. // this.pages.each(function(page, i){
  2008. // page.setStyles({
  2009. // "float": "left",
  2010. // "margin-left": ""+margin+"px"
  2011. // });
  2012. // });
  2013. this.resetNodeSize();
  2014. },
  2015. _repage: function(delay){
  2016. if (this.options.pageShow!=="double"){
  2017. this._singlePage();
  2018. }else{
  2019. this._doublePage();
  2020. }
  2021. if (delay){
  2022. if (!this.form.isLoaded){
  2023. this.form.addEvent("afterLoad", this._checkScale.bind(this));
  2024. }else{
  2025. this._checkScale();
  2026. }
  2027. }else{
  2028. this._checkScale();
  2029. }
  2030. },
  2031. _contentNodeWitdh: function(){
  2032. var w = this.node.getSize().x;
  2033. if (this.history && this.history.historyListAreaNode) w = w-this.history.historyListAreaNode.getComputedSize().totalWidth-2;
  2034. w = w/this.scale;
  2035. this.contentNode.setStyles({
  2036. "width": ""+w+"px"
  2037. });
  2038. },
  2039. _pageMargin: function(){
  2040. this._contentNodeWitdh();
  2041. var w = this.contentNode.offsetWidth.toFloat();
  2042. w = (this.scale) ? this.scale*w : w;
  2043. var count = 1;
  2044. var docPageFullWidth = (this.scale) ? this.scale*this.options.docPageFullWidth : this.options.docPageFullWidth;
  2045. var pageWidth = count * docPageFullWidth;
  2046. var margin = (w-pageWidth)/(count+1);
  2047. if (this.scale) margin = margin/this.scale;
  2048. if (margin<0) margin=0;
  2049. this.pages.each(function(page, i){
  2050. page.setStyles({
  2051. "float": "left",
  2052. "margin-left": ""+margin+"px"
  2053. });
  2054. });
  2055. if (margin==0){
  2056. var scrollLeft = (this.contentNode.scrollWidth - this.contentNode.offsetWidth)/2;
  2057. if (this.contentNode.scrollTo){
  2058. this.contentNode.scrollTo(scrollLeft, 0);
  2059. }else{
  2060. this.contentNode.scrollLeft = scrollLeft;
  2061. }
  2062. }
  2063. this.fireEvent("pagePosition");
  2064. },
  2065. _singlePage: function(){
  2066. //if (this.editMode) this._readFiletext();
  2067. var scale = this.singlePageZoom;
  2068. if (!scale) scale = this.scale || 1;
  2069. if( this.singlePageZoom && this.singlePageZoom.toInt() != 1 ){
  2070. this.isScale = true;
  2071. this.scale = this.singlePageZoom;
  2072. this.singlePageZoom = null;
  2073. }
  2074. //this.zoom(scale);
  2075. this._checkScale();
  2076. this._pageMargin();
  2077. // var w = this.contentNode.getSize().x;
  2078. // var count = 1;
  2079. // var docPageFullWidth = (this.scale) ? this.scale*this.options.docPageFullWidth : this.options.docPageFullWidth;
  2080. // //var docPageFullWidth = this.options.docPageFullWidt;
  2081. //
  2082. // var pageWidth = count * docPageFullWidth;
  2083. // var margin = (w-pageWidth)/(count+1);
  2084. //
  2085. // if (this.isScale){
  2086. // margin = "10";
  2087. // }
  2088. // if (this.scale) margin = margin/this.scale;
  2089. // this.pages.each(function(page, i){
  2090. // page.setStyles({
  2091. // "float": "left",
  2092. // "margin-left": ""+margin+"px"
  2093. // });
  2094. // });
  2095. this.resetNodeSize();
  2096. // this.pages.each(function(page){
  2097. // page.setStyle("float", "none");
  2098. // });
  2099. this.resizeSidebar();
  2100. this.options.pageShow="single";
  2101. this.doublePageAction.set("text", MWF.xApplication.process.Xform.LP.doublePage);
  2102. },
  2103. resetNodeSize: function(){
  2104. //var contentSize = this.contentNode.getSize();
  2105. var contentHeight = this.contentNode.offsetHeight;
  2106. var toolbarSize = this.toolNode.getSize();
  2107. contentHeight = contentHeight*(this.scale || 1);
  2108. var h = contentHeight+toolbarSize.y+20;
  2109. //h = h - contentSize.y*(1-this.scale);
  2110. this.node.setStyles({
  2111. "height":""+h+"px"
  2112. });
  2113. this.resizeSidebar();
  2114. },
  2115. createWaitSplitPage: function(){
  2116. this.node.mask({
  2117. "style": {
  2118. "background-color": "#cccccc",
  2119. "opacity": 0.3
  2120. }
  2121. });
  2122. this.waitSplitPageNode = new Element("div", {"styles": this.form.css.waitSplitPageNode, "text": MWF.xApplication.process.Xform.LP.computePage}).inject(this.node);
  2123. this.waitSplitPageNode.position({
  2124. "relativeTo": this.node,
  2125. "position": "topRight",
  2126. "edge": "topRight",
  2127. "offset": {
  2128. "x": -10,
  2129. "y": 45
  2130. }
  2131. });
  2132. //this.form.notice(MWF.xApplication.process.Xform.LP.computePage, "info", this.node);
  2133. },
  2134. clearWaitSplitPage: function(){
  2135. this.node.unmask();
  2136. if (this.waitSplitPageNode) this.waitSplitPageNode.destroy();
  2137. this.waitSplitPageNode = null;
  2138. },
  2139. _doublePage: function(){
  2140. if (this.editMode) this._switchReadOrEditInline();
  2141. if( this.zoomSelectAction ){
  2142. this.singlePageZoom = ( this.zoomSelectAction.options[this.zoomSelectAction.selectedIndex].value ).toFloat();
  2143. }
  2144. this.zoom(1);
  2145. this.createWaitSplitPage();
  2146. window.setTimeout(function(){
  2147. this._checkSplitPage(this.pages[0]);
  2148. this.zoom(1);
  2149. var w = this.contentNode.getSize().x;
  2150. var toPageWidth = (w-100)/2;
  2151. scale = toPageWidth/this.options.docPageFullWidth;
  2152. if (scale<1) this.zoom(scale);
  2153. var docPageFullWidth = (this.scale) ? this.scale*this.options.docPageFullWidth : this.options.docPageFullWidth;
  2154. //var docPageFullWidth = this.options.docPageFullWidth;
  2155. var w = this.contentNode.getSize().x;
  2156. var count = (w/docPageFullWidth).toInt();
  2157. var pages = this.contentNode.getElements(".doc_layout_page");
  2158. count = Math.min(pages.length, count);
  2159. var pageWidth = count * docPageFullWidth;
  2160. var margin = (w-pageWidth)/(count+1);
  2161. if (this.scale) margin = margin/(this.scale);
  2162. this.pages.each(function(page, i){
  2163. page.setStyles({
  2164. "float": "left",
  2165. "margin-left": ""+margin+"px"
  2166. });
  2167. });
  2168. // this.pages.each(function(page, i){
  2169. // if ((i % 2)===0){
  2170. // page.setStyle("float", "left");
  2171. // }else{
  2172. // page.setStyle("float", "right");
  2173. // }
  2174. // });
  2175. this.resetNodeSize();
  2176. this.options.pageShow="double";
  2177. this.doublePageAction.set("text", MWF.xApplication.process.Xform.LP.singlePage);
  2178. this.resizeSidebar();
  2179. this.clearWaitSplitPage();
  2180. var s = 0;
  2181. this.pages.forEach(function(page, i){
  2182. s++;
  2183. var styles = {
  2184. "bottom": "-60px",
  2185. "margin-top": "10px",
  2186. "position": "absolute"
  2187. }
  2188. if (s % 2 === 0){
  2189. styles.left = "0";
  2190. }else{
  2191. styles.right = "0";
  2192. }
  2193. var pageNumberNode = new Element("div", {
  2194. "html": "<span>—</span><span> "+s+" </span><span>—</span>",
  2195. "styles": styles
  2196. }).inject(page.getFirst());
  2197. }.bind(this));
  2198. }.bind(this), 1000);
  2199. },
  2200. _getDefaultData: function(){
  2201. return Object.clone(this.json.defaultValue);
  2202. //return Object.clone(MWF.xApplication.process.Xform.LP.documentEditor);
  2203. },
  2204. _loadFiletextPage: function(callback){
  2205. this.data = this._getBusinessData();
  2206. if (!this.data) this.data = this._getDefaultData();
  2207. this._computeData(true);
  2208. this._createPage(function(control){
  2209. this._loadPageLayout(control);
  2210. // this.data = this._getBusinessData();
  2211. // if (!this.data) this.data = this._getDefaultData();
  2212. this.setData(this.data);
  2213. // this._checkSplitPage(this.pages[0]);
  2214. //this._repage(true);
  2215. //this.loadCkeditorFiletext();
  2216. if (!this.readonly){
  2217. //if (this.json.allowEditFiletext!==false) this.loadCkeditorFiletext();
  2218. // if (this.json.allowEditRedheader) this.loadCkeditorRedheader();
  2219. // if (this.json.allowEditSubject) this.loadCkeditorSubject();
  2220. // if (this.json.allowEditMainSend) this.loadCkeditorMainSend();
  2221. // if (this.json.allowEditFileNo) this.loadCkeditorFileNo();
  2222. // if (this.json.allowEditSigner) this.loadCkeditorSigner();
  2223. // if (this.json.allowEditAttachment) this.loadCkeditorAttachment();
  2224. }
  2225. if (!this.editMode && this.allowEdit && !this.historyMode){
  2226. this._editFiletext("inline");
  2227. //if (this.loadFileTextEditFun) this.layout_filetext.removeEvent("click", this.loadFileTextEditFun);
  2228. this.editMode = true;
  2229. }
  2230. if (callback) callback();
  2231. }.bind(this));
  2232. },
  2233. _getEditorConfig: function(editorName){
  2234. // var mathElements = [
  2235. // 'math',
  2236. // 'maction',
  2237. // 'maligngroup',
  2238. // 'malignmark',
  2239. // 'menclose',
  2240. // 'merror',
  2241. // 'mfenced',
  2242. // 'mfrac',
  2243. // 'mglyph',
  2244. // 'mi',
  2245. // 'mlabeledtr',
  2246. // 'mlongdiv',
  2247. // 'mmultiscripts',
  2248. // 'mn',
  2249. // 'mo',
  2250. // 'mover',
  2251. // 'mpadded',
  2252. // 'mphantom',
  2253. // 'mroot',
  2254. // 'mrow',
  2255. // 'ms',
  2256. // 'mscarries',
  2257. // 'mscarry',
  2258. // 'msgroup',
  2259. // 'msline',
  2260. // 'mspace',
  2261. // 'msqrt',
  2262. // 'msrow',
  2263. // 'mstack',
  2264. // 'mstyle',
  2265. // 'msub',
  2266. // 'msup',
  2267. // 'msubsup',
  2268. // 'mtable',
  2269. // 'mtd',
  2270. // 'mtext',
  2271. // 'mtr',
  2272. // 'munder',
  2273. // 'munderover',
  2274. // 'semantics',
  2275. // 'annotation',
  2276. // 'annotation-xml'
  2277. // ];
  2278. //CKEDITOR.plugins.addExternal('ckeditor_wiris', 'https://ckeditor.com/docs/ckeditor4/4.13.0/examples/assets/plugins/ckeditor_wiris/', 'plugin.js');
  2279. var editorConfig = {
  2280. qtRows: 20, // Count of rows
  2281. qtColumns: 20, // Count of columns
  2282. qtBorder: '1', // Border of inserted table
  2283. qtWidth: '95%', // Width of inserted table
  2284. qtStyle: { 'border-collapse' : 'collapse' },
  2285. qtClass: 'documenteditor_table'+this.form.json.id+this.json.id, // Class of table
  2286. qtCellPadding: '0', // Cell padding table
  2287. qtCellSpacing: '0', // Cell spacing table
  2288. qtPreviewBorder: '4px double black', // preview table border
  2289. qtPreviewSize: '4px', // Preview table cell size
  2290. qtPreviewBackground: '#c8def4', // preview table background (hover)
  2291. language: o2.language,
  2292. // format_tags: '标题一;标题二;标题三;标题四;正文', // entries is displayed in "Paragraph format"
  2293. format_tags: '标题一;标题二;正文(标题三,四)', // entries is displayed in "Paragraph format"
  2294. 'format_标题一': {
  2295. name: '标题一(三号黑体)',
  2296. element: 'div',
  2297. styles: {
  2298. 'font-family': '黑体',
  2299. 'font-size': '16pt'
  2300. }
  2301. },
  2302. 'format_标题二': {
  2303. name: '标题二(三号楷体)',
  2304. element: 'div',
  2305. styles: {
  2306. 'font-family': '楷体_GB2312',
  2307. 'font-size': '16pt'
  2308. }
  2309. },
  2310. // 'format_标题三': {
  2311. // name: '标题三',
  2312. // element: 'div',
  2313. // styles: {
  2314. // 'font-family': '仿宋_GB2312',
  2315. // 'font-size': '16pt'
  2316. // }
  2317. // },
  2318. // 'format_标题四': {
  2319. // name: '标题四',
  2320. // element: 'div',
  2321. // styles: {
  2322. // 'font-family': '仿宋_GB2312',
  2323. // 'font-size': '16pt'
  2324. // }
  2325. // },
  2326. 'format_正文(标题三,四)': {
  2327. name: '正文(标题三,四)',
  2328. element: 'div',
  2329. styles: {
  2330. 'font-family': '仿宋_GB2312',
  2331. 'font-size': '16pt'
  2332. }
  2333. }
  2334. };
  2335. editorConfig.toolbarGroups = [
  2336. { name: 'document', groups: [ 'mode', 'document', 'doctools' ] },
  2337. { name: 'clipboard', groups: [ 'clipboard', 'undo' ] },
  2338. { name: 'editing', groups: [ 'find', 'selection', 'spellchecker', 'editing' ] },
  2339. { name: 'forms', groups: [ 'forms' ] },
  2340. { name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] },
  2341. { name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align', 'bidi', 'paragraph' ] },
  2342. { name: 'links', groups: [ 'links' ] },
  2343. { name: 'insert', groups: [ 'insert' ] },
  2344. { name: 'styles', groups: [ 'styles' ] },
  2345. { name: 'colors', groups: [ 'colors' ] },
  2346. { name: 'tools', groups: [ 'tools' ] },
  2347. { name: 'others', groups: [ 'others' ] },
  2348. { name: 'about', groups: [ 'about' ] }
  2349. ];
  2350. //editorConfig.extraPlugins = "ecnet,colordialog,tableresize,quicktable,mathjax,ckeditor_wiris";
  2351. //editorConfig.extraPlugins = "ecnet,colordialog,quicktable,tableresize,eqneditor";
  2352. //editorConfig.extraPlugins = "tableresize,quicktable";
  2353. editorConfig.extraPlugins = "quicktable,tableresize";
  2354. //editorConfig.mathJaxLib = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-AMS_HTML',
  2355. //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';
  2356. editorConfig.removeButtons = 'EasyImageUpload,ExportPdf,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,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';
  2357. //editorConfig.removeButtons = '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,Outdent,Indent,Blockquote,CreateDiv,BidiLtr,BidiRtl,Language,Link,Unlink,Anchor,Flash,HorizontalRule,Smiley,SpecialChar,PageBreak,Iframe,TextColor,BGColor,Maximize,ShowBlocks,About,Styles,Font,FontSize';
  2358. //editorConfig.extraAllowedContent = mathElements.join(' ') + '(*)[*]{*};img[data-mathml,data-custom-editor,role](Wirisformula)';
  2359. editorConfig.pasteFromWordRemoveFontStyles = false;
  2360. editorConfig.pasteFromWordRemoveStyles = false;
  2361. editorConfig.pasteFromWordNumberedHeadingToList = false;
  2362. //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';
  2363. editorConfig.removePlugins = ['magicline','cloudservices','easyimage', 'exportpdf'];
  2364. editorConfig.enterMode = CKEDITOR.ENTER_DIV;
  2365. editorConfig.pasteFilter = "plain-text";
  2366. // editorConfig.extraPlugins = ['ecnet','mathjax'];
  2367. // editorConfig.removePlugins = ['magicline'];
  2368. // editorConfig.mathJaxLib = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-AMS_HTML';
  2369. if (this.json.ckeditConfigOptions && this.json.ckeditConfigOptions.code){
  2370. var o = this.form.Macro.exec(this.json.ckeditConfigOptions.code, this);
  2371. if (o) editorConfig = Object.merge(editorConfig, o);
  2372. }
  2373. if (editorName){
  2374. editorConfig.removeButtons = editorConfig.removeButtons.split(/,\s*/).erase("PageBreak").join(",");
  2375. var tags = editorConfig.format_tags.split(/;\s*/);
  2376. if (tags.indexOf("附件标题")==-1){
  2377. editorConfig.format_tags = "附件标题"+((editorConfig.format_tags) ? ";" : "")+editorConfig.format_tags;
  2378. }
  2379. if (tags.indexOf("附件序号")==-1){
  2380. editorConfig.format_tags = "附件序号"+((editorConfig.format_tags) ? ";" : "")+editorConfig.format_tags;
  2381. }
  2382. if (!editorConfig["format_附件序号"]) editorConfig["format_附件序号"] = {
  2383. name: '附件序号',
  2384. element: 'div',
  2385. styles: {
  2386. 'font-family': '黑体',
  2387. 'font-size': '16pt'
  2388. }
  2389. };
  2390. if (!editorConfig["format_附件标题"]) editorConfig["format_附件标题"] = {
  2391. name: '附件标题',
  2392. element: 'div',
  2393. styles: {
  2394. 'font-family': '方正小标宋简体',
  2395. 'font-size': '22pt',
  2396. 'text-align': 'center'
  2397. }
  2398. }
  2399. }
  2400. return editorConfig;
  2401. },
  2402. _checkSplitPage: function(pageNode){
  2403. if (this.layout_edition) this.layout_edition.setStyles({ "position": "static"});
  2404. var contentNode = pageNode.getFirst();
  2405. if (contentNode.getSize().y>this.options.docPageHeight){
  2406. this._splitPage(pageNode);
  2407. }
  2408. var i = pageNode.get("data-pagecount").toInt();
  2409. if (i && this.pages.length-1>=i){
  2410. this._checkSplitPage(this.pages[i]);
  2411. }
  2412. if (this.layout_edition) this.layout_edition.setStyles({ "position": "absolute", "bottom": "0px" });
  2413. },
  2414. _splitFiletextNodeOneWord:function(lnode, nextPageNode){
  2415. var text = lnode.textContent;
  2416. var len = text.length;
  2417. var left = text.substring(0, len-1);
  2418. var right = text.substring(len-1, len);
  2419. lnode.textContent = left;
  2420. nextPageNode.textContent = right+nextPageNode.textContent;
  2421. //nextPageNode.appendText(right, "top");
  2422. },
  2423. _splitFiletext: function(node, nextPageNode, nextFiletextNode, pageNode){
  2424. var contentNode = pageNode.getFirst();
  2425. var lnode = node.lastChild;
  2426. if (!lnode){
  2427. if (node.parentNode) node.parentNode.removeChild(node);
  2428. //node.remove();
  2429. }else{
  2430. while (contentNode.getSize().y>this.options.docPageHeight && lnode) {
  2431. var tmpnode = lnode.previousSibling;
  2432. var nodeType = lnode.nodeType;
  2433. if (!nextPageNode) nextPageNode = nextFiletextNode;
  2434. if (nodeType == Node.ELEMENT_NODE) {
  2435. if (lnode.tagName == "table") {
  2436. lnode.inject(nextPageNode);
  2437. } else if (lnode.tagName == "BR") {
  2438. if (lnode.parentNode) lnode.parentNode.removeChild(lnode);
  2439. } else {
  2440. var id = lnode.get("data-pagePart");
  2441. if (!id){
  2442. id = (new o2.widget.UUID()).toString();
  2443. lnode.set("data-pagePart", id);
  2444. }
  2445. var tmpNode = nextPageNode.getFirst();
  2446. if (tmpNode && tmpNode.get("data-pagePart")==id){
  2447. nextPageNode = tmpNode;
  2448. }else{
  2449. nextPageNode = lnode.clone(false).inject(nextPageNode, "top");
  2450. }
  2451. //var subnode = lnode.getLast();
  2452. this._splitFiletext(lnode, nextPageNode, nextFiletextNode, pageNode);
  2453. if (!lnode.firstChild) if (lnode.parentNode) lnode.parentNode.removeChild(lnode);
  2454. nextPageNode = nextPageNode.getParent();
  2455. }
  2456. } else if (nodeType == Node.TEXT_NODE) {
  2457. var nextPageTextNode = nextPageNode.insertBefore(document.createTextNode(""), nextPageNode.firstChild);
  2458. while ((contentNode.getSize().y > this.options.docPageHeight) && lnode.textContent) {
  2459. //console.log(contentNode.getSize().y);
  2460. this._splitFiletextNodeOneWord(lnode, nextPageTextNode)
  2461. }
  2462. if (!lnode.textContent) if (lnode.parentNode) lnode.parentNode.removeChild(lnode); //lnode.remove();
  2463. } else {
  2464. //lnode.remove();
  2465. if (lnode.parentNode) lnode.parentNode.removeChild(lnode);
  2466. }
  2467. lnode = tmpnode;
  2468. }
  2469. if (!node.lastChild) if (node.parentNode) node.parentNode.removeChild(node); //node.remove();
  2470. }
  2471. //this._checkSplitPage(pageNode);
  2472. },
  2473. _splitPage: function(pageNode){
  2474. var contentNode = pageNode.getFirst();
  2475. var blockNodes = pageNode.getElements(".doc_block");
  2476. if (blockNodes.length){
  2477. var blockNode = blockNodes[blockNodes.length-1];
  2478. var idx = this.pages.indexOf(pageNode);
  2479. if (this.pages.length<=idx+1) this._createNewPage();
  2480. var nextPage = this.pages[idx+1];
  2481. if (blockNode.hasClass("doc_layout_filetext")){
  2482. var filetextNode = nextPage.getElement(".doc_layout_filetext");
  2483. if (!filetextNode){
  2484. filetextNode = new Element("div.doc_layout_filetext").inject(nextPage.getFirst(), "top");
  2485. //filetextNode.setAttribute('contenteditable', true);
  2486. }
  2487. if (!filetextNode.hasClass("doc_block"))filetextNode.addClass("doc_block");
  2488. //var nextEditor = filetextNode.retrieve("editor");
  2489. var node = blockNode;
  2490. var nextPageNode = filetextNode;
  2491. this._splitFiletext(node, nextPageNode, filetextNode, pageNode);
  2492. }else{
  2493. blockNode.inject(nextPage.getFirst(), "top");
  2494. //var contentNode = pageNode.getFirst();
  2495. if (contentNode.getSize().y>this.options.docPageHeight){
  2496. this._splitPage(pageNode);
  2497. }
  2498. }
  2499. }
  2500. },
  2501. transWidth: function(node){
  2502. if (!node) return '';
  2503. while (node){
  2504. if (node.nodeType==3){
  2505. node.nodeValue = node.nodeValue.replace(/\x20/g, " ");
  2506. }else if (node.nodeType==8){
  2507. //nothing
  2508. }else{
  2509. this.transWidth(node.firstChild);
  2510. }
  2511. node = node.nextSibling;
  2512. }
  2513. },
  2514. insertFullWidth: function(node, txt){
  2515. if (!node) return '';
  2516. while (node){
  2517. if (node.nodeType==3){
  2518. node.nodeValue = txt+node.nodeValue;
  2519. return true;
  2520. }else if (node.nodeType==8){
  2521. //nothing
  2522. }else{
  2523. var flag = this.insertFullWidth(node.firstChild, txt);
  2524. if (flag) return true;
  2525. }
  2526. node = node.nextSibling;
  2527. }
  2528. },
  2529. loadCkeditorFiletext: function(callback, inline, node, editorName){
  2530. if (node || this.layout_filetext){
  2531. o2.load("../o2_lib/htmleditor/ckeditor4161/ckeditor.js", function(){
  2532. CKEDITOR.disableAutoInline = true;
  2533. (node || this.layout_filetext).setAttribute('contenteditable', true);
  2534. var editor;
  2535. try{
  2536. var editorConfig = this._getEditorConfig(editorName);
  2537. editor = CKEDITOR.inline(node || this.layout_filetext, editorConfig);
  2538. this[(editorName || "filetextEditor")] = editor;
  2539. editor.on("instanceReady", function(e){
  2540. var v = e.editor.editable().$.get("text");
  2541. if (!v || v=="  ") e.editor.setData(this.json.defaultValue.filetext);
  2542. if (callback) callback(e);
  2543. }.bind(this));
  2544. editor.on( 'focus', function( e ) {
  2545. window.setTimeout(function(){
  2546. // this.reLocationFiletextToolbar(editorName);
  2547. this.locationFiletextToolbar(editorName);
  2548. }.bind(this), 10);
  2549. var v = e.editor.editable().$.get("text");
  2550. if (!v || v==this.json.defaultValue.filetext){
  2551. e.editor.setData("  ");
  2552. e.editor.focus();
  2553. var range = e.editor.createRange();
  2554. range.moveToElementEditEnd(e.editor.editable());
  2555. range.select();
  2556. }
  2557. }.bind(this) );
  2558. editor.on( 'blur', function( e ) {
  2559. if (!!editorName) this.getAttachmentTextData();
  2560. var v = e.editor.editable().$.get("text");
  2561. if (!v || v=="  "){
  2562. if (this.json && this.json.defaultValue){
  2563. e.editor.setData(this.json.defaultValue.filetext);
  2564. }
  2565. }
  2566. }.bind(this) );
  2567. editor.on( 'loaded', function( e ) {
  2568. editor.element.$.store("module", this);
  2569. editor.element.$.store("scale", this.scale);
  2570. }.bind(this) );
  2571. editor.on( 'afterPaste', function( e ) {
  2572. }.bind(this));
  2573. editor.on( 'afterPasteFromWord', function( e ) {
  2574. }.bind(this));
  2575. const _self = this;
  2576. editor.on( 'paste', function( e ) {
  2577. var html = e.data.dataValue;
  2578. //if (this.json.fullWidth=="y") html = html.replace(/\x20/g, " ");
  2579. var rexbr = /\<br\>|\<br \/\>|\<br\/\>/g;
  2580. var rexp = /\<p\>/g;
  2581. if (rexbr.test(html) && !rexp.test(html)){
  2582. var ps = html.split(/\<br\>|\<br \/\>|\<br\/\>/g);
  2583. html = "";
  2584. ps.each(function(p){
  2585. html = html + "<p>"+p+"</p>";
  2586. });
  2587. }
  2588. var tmp = new Element("div")
  2589. tmp.set("html", html);
  2590. var pList = tmp.getElements("p");
  2591. pList.each(function(p, i){
  2592. //if (Browser.name=="ie"){
  2593. if (this.json.fullWidth!=="n") this.transWidth(p);
  2594. if (!p.getParent("table")){
  2595. var text = p.get("text");
  2596. var rex = /^\u3000*/;
  2597. var m = text.match(rex);
  2598. var l = (m[0]) ? Math.max((2-m[0].length), 0): 2;
  2599. var txt = "";
  2600. // for (var i=0; i<l; i++) txt+=" ";
  2601. // this.insertFullWidth(p.getFirst(), txt);
  2602. for (var i=0; i<l; i++) p.appendText(" ","top");
  2603. }
  2604. //}else{
  2605. // var textIndent = p.getStyle("text-indent");
  2606. // if (textIndent.toInt()) p.appendText("  ","top");
  2607. //}
  2608. }.bind(this));
  2609. var tableList = tmp.getElements("table");
  2610. if (tableList && tableList.length){
  2611. var w = (node || this.layout_filetext).offsetWidth.toFloat()-2;
  2612. tableList.each(function(table){
  2613. const rTable = _self.cloneTable(table, editorConfig);
  2614. rTable.inject(table, 'after');
  2615. table.destroy();
  2616. // var twstyle = table.getStyle("width");
  2617. // var tws = (twstyle) ? (twstyle.toFloat() || 0) : 0;
  2618. // var twatt = table.get("width");
  2619. // var twa = (twatt) ? (twatt.toFloat() || 0) : 0;
  2620. // var tw = Math.max(tws, twa);
  2621. // if (tw===0 || tw>w){
  2622. // table.setStyle("width", ""+w+"px");
  2623. // }
  2624. });
  2625. tableList.setStyles({
  2626. "margin-left": "",
  2627. "margin-right": "",
  2628. "word-break": "break-all"
  2629. });
  2630. }
  2631. // var tdList = tmp.getElements("td");
  2632. // tdList.each(function(td){
  2633. // var tbw_top = td.getStyle("border-top-width").toFloat() || 0;
  2634. // var tbw_bottom = td.getStyle("border-bottom-width").toFloat() || 0;
  2635. // var tbw_left = td.getStyle("border-left-width").toFloat() || 0;
  2636. // var tbw_right = td.getStyle("border-right-width").toFloat() || 0;
  2637. //
  2638. // td.setStyles({
  2639. // "border-top-width": (tbw_top/2)+"px",
  2640. // "border-bottom-width": (tbw_bottom/2)+"px",
  2641. // "border-left-width": (tbw_left/2)+"px",
  2642. // "border-right-width": (tbw_right/2)+"px",
  2643. // });
  2644. // });
  2645. e.data.dataValue = tmp.get("html");
  2646. tmp.destroy();
  2647. this.fireEvent("paste");
  2648. // this.flashContentNode();
  2649. }.bind(this) );
  2650. editor.on( 'afterPaste', function( e ) {
  2651. this.resetNodeSize();
  2652. this.fireEvent("afterPaste");
  2653. }.bind(this) );
  2654. editor.on( 'change', function( e ) {
  2655. var h = document.documentElement.scrollTop;
  2656. var scrollNode = this.contentNode;
  2657. while (scrollNode && (scrollNode.getScrollSize().y<=scrollNode.getSize().y || (scrollNode.getStyle("overflow")!=="auto" && scrollNode.getStyle("4-y")!=="auto"))){
  2658. scrollNode = scrollNode.getParent();
  2659. }
  2660. if (scrollNode){
  2661. var top = scrollNode.scrollTop.toFloat();
  2662. scrollNode.scrollTop = h+top;
  2663. }
  2664. document.documentElement.scrollTop = 0;
  2665. if (!!editorName) this.getAttachmentTextData();
  2666. o2.defer(this.resetNodeSize, 500, this);
  2667. }.bind(this) );
  2668. editor.on( 'insertElement', function( e ) {
  2669. if (e.data.$.tagName.toString().toLowerCase()=="table"){
  2670. e.data.$.setStyles({
  2671. "margin-left": "",
  2672. "margin-right": "",
  2673. "word-break": "break-all"
  2674. });
  2675. }
  2676. var tr = e.data.$.getElement("tr");
  2677. if (tr){
  2678. var tds = tr.getElements("td");
  2679. if (tds && tds.length){
  2680. var p = 100/tds.length;
  2681. tds.setStyle("width", ""+p+"%");
  2682. }
  2683. }
  2684. }.bind(this) );
  2685. if (this.json.textIndent!=="n"){
  2686. (node || this.layout_filetext).addEvent("keyup", function(ev){
  2687. if (ev.code==13) editor.insertText("  ");
  2688. }.bind(this));
  2689. }
  2690. if (this.json.fullWidth!=="n"){
  2691. editor.addCommand( 'insertHalfSpace', {
  2692. exec: function( editor ) {
  2693. editor.insertText(" ");
  2694. }
  2695. } );
  2696. editor.setKeystroke( CKEDITOR.SHIFT + 32, 'insertHalfSpace' );
  2697. editor.on("key", function(e){
  2698. if (this.json.fullWidth!=="n") if (e.data.keyCode==32){
  2699. e.editor.insertText(" ");
  2700. e.cancel();
  2701. }
  2702. }.bind(this));
  2703. }
  2704. }catch(e){
  2705. editor = this[(editorName || "filetextEditor")];
  2706. }
  2707. }.bind(this));
  2708. }
  2709. },
  2710. // flashContentNode: function(){
  2711. // if (this.flashContentNodeTimer) window.clearTimeout(this.flashContentNodeTimer);
  2712. // var contentNode = this.contentNode;
  2713. // this.flashContentNodeTimer = window.setTimeout(function(){
  2714. // // contentNode.hide();
  2715. // // window.setTimeout(function(){
  2716. // // contentNode.show();
  2717. // // }, 10);
  2718. // this.flashContentNodeTimer = null;
  2719. // },1000);
  2720. // },
  2721. getTableWidth(table) {
  2722. var twstyle = table.getStyle("width");
  2723. var tws = (twstyle) ? (parseFloat(twstyle) || 0) : 0;
  2724. var twatt = table.get("width");
  2725. var twa = (twatt) ? (parseFloat(twatt) || 0) : 0;
  2726. return Math.max(tws, twa);
  2727. },
  2728. cloneTable(table, editorConfig) {
  2729. const rows = table.rows;
  2730. const w = this.getTableWidth(table);
  2731. const rTable = new Element('table');
  2732. rTable.set({
  2733. "border": editorConfig.qtBorder,
  2734. "cellpadding": editorConfig.qtCellPadding || 0,
  2735. "cellspacing": editorConfig.qtCellSpacing || 0,
  2736. "class": editorConfig.qtClass
  2737. });
  2738. rTable.setStyles(editorConfig.qtStyle);
  2739. rTable.setStyles({
  2740. "width": editorConfig.qtWidth,
  2741. "word-break": "break-all"
  2742. });
  2743. rTable.dataset.tableType = 'o2';
  2744. for (let i = 0; i < rows.length; i++) {
  2745. const r = rows.item(i);
  2746. const cr = new Element(r.tagName);
  2747. cr.inject(rTable, 'bottom');
  2748. const cells = r.getElements('td,th');
  2749. cells.forEach((c) => {
  2750. const cc = new Element(c.tagName);
  2751. const rowspan = c.getAttribute('rowspan');
  2752. const colspan = c.getAttribute('colspan');
  2753. if (rowspan) cc.set('rowspan', rowspan);
  2754. if (colspan) cc.set('colspan', colspan);
  2755. const w = c.getStyle('width');
  2756. if (w) cc.setStyle('width', w);
  2757. const pw = c.get('width');
  2758. if (w) cc.set('width', pw);
  2759. cc.set('html', c.get('html'));
  2760. cc.inject(cr, 'bottom');
  2761. });
  2762. }
  2763. return rTable;
  2764. },
  2765. _loadEvents: function(editorConfig){
  2766. Object.each(this.json.events, function(e, key){
  2767. if (e.code){
  2768. this.editor.on(key, function(event){
  2769. return this.form.Macro.fire(e.code, this, event);
  2770. }.bind(this), this);
  2771. }
  2772. }.bind(this));
  2773. },
  2774. _bindFieldChange: function(name,dataItem, dom){
  2775. var field = this.form.all[this.json[dataItem]];
  2776. if (field){
  2777. var bindFun = function(){
  2778. this._computeItemFieldData(name, dataItem);
  2779. //if (this.data[name]){
  2780. if (this[dom]){
  2781. if (dom=="layout_redHeader" ||dom=="layout_issuanceUnit" || dom=="layout_meetingAttendContent" || dom=="layout_meetingLeaveContent" || dom=="layout_meetingSitContent" || dom=="layout_meetingRecordContent" || dom=="layout_signer") {
  2782. this[dom].set("html", this.filterHtml(this.data[name] || ""));
  2783. }else if (dom=="layout_subject"){
  2784. this[dom].set("html", (this.data[name] || ""));
  2785. }else if (dom=="layout_attachment"){
  2786. this.setAttachmentData();
  2787. }else if (dom=="layout_annotation"){
  2788. var annotation = this.data[name];
  2789. if (annotation){
  2790. if (annotation.substring(0, 1)!=="(") annotation = "("+annotation;
  2791. if (annotation.substring(annotation.length-1, annotation.length)!==")") annotation = annotation+")";
  2792. this[dom].set("text", annotation);
  2793. }else{
  2794. this[dom].set("text", "");
  2795. }
  2796. }else{
  2797. this[dom].set("text", this.data[name]|| "");
  2798. }
  2799. }
  2800. this.reSetShow();
  2801. //}
  2802. }.bind(this);
  2803. field.node.store(this.json.id+"bindFun", bindFun);
  2804. field.addModuleEvent("change", bindFun);
  2805. }
  2806. },
  2807. _computeItemFieldData: function(name, dataItem, dataItemNode){
  2808. var v = "";
  2809. var module = (dataItemNode) ? this.form.all[dataItemNode] : this.form.all[this.json[dataItem]];
  2810. if (module && module.getData) v = module.getData();
  2811. if (!v) v = (dataItemNode) ? this.form.businessData.data[dataItemNode] : this.form.businessData.data[this.json[dataItem]];
  2812. if (v){
  2813. var t = o2.typeOf(v);
  2814. switch (t) {
  2815. case "string":
  2816. switch (name) {
  2817. case "issuanceDate":
  2818. case "editionDate":
  2819. var d = new Date(v);
  2820. if (d && d.isValid() && d.getFullYear()!=1970){
  2821. var y = d.getFullYear();
  2822. var m = d.getMonth();
  2823. var day = d.getDate();
  2824. m = m +1;
  2825. var lp = MWF.xApplication.process.Xform.LP;
  2826. this.data[name] = ""+y+lp.year+m+lp.month+day+lp.date;
  2827. }else{
  2828. this.data[name] = v;
  2829. }
  2830. //this.data[name] = (new Date(v).isValid()) ? Date.parse(v).format("%Y年%m月%d%日") : v;
  2831. break;
  2832. case "mainSend":
  2833. this.data[name] = v + ":";
  2834. break;
  2835. case "copyto":
  2836. case "copyto2":
  2837. var flag = (v.substring(v.length-1, v.length)=="。");
  2838. this.data[name] = v + ((flag) ? "" : "。");
  2839. break;
  2840. default:
  2841. if (name==="subject") v = o2.txt(v);
  2842. this.data[name] = v;
  2843. }
  2844. break;
  2845. case "array":
  2846. var strs = [];
  2847. var strLength = 0;
  2848. v.each(function(value){
  2849. if (o2.typeOf(value)=="object" && value.distinguishedName){
  2850. if (value.name.length>strLength) strLength = value.name.length;
  2851. strs.push(value.name);
  2852. }else{
  2853. if (value.length>strLength) strLength = value.length;
  2854. strs.push(value.toString());
  2855. }
  2856. });
  2857. //if (strs.length){
  2858. switch (name) {
  2859. case "attachment":
  2860. // this.data[name] = strs.map(function(n, i){ var j = i+1; return j+"、"+n}).join("<br>");
  2861. var atts = strs.map(function(a){
  2862. return (a.indexOf(".")!=-1) ? a.substring(0, a.lastIndexOf(".")) : a;
  2863. });
  2864. this.data[name] = atts;
  2865. break;
  2866. case "issuanceDate":
  2867. case "editionDate":
  2868. var tmpStrs = strs.map(function(n, i){
  2869. var d = Date.parse(n);
  2870. if (d && d.isValid() && d.getFullYear()!=1970){
  2871. var y = d.getFullYear();
  2872. var m = d.getMonth();
  2873. var day = d.getDate();
  2874. m = m +1;
  2875. var lp = MWF.xApplication.process.Xform.LP;
  2876. return ""+y+lp.year+m+lp.month+day+lp.date;
  2877. }else{
  2878. return n;
  2879. }
  2880. //return () ? d.format("%Y年%m月%d日") : n;
  2881. });
  2882. this.data[name] = tmpStrs.join(",");
  2883. break;
  2884. case "signer":
  2885. var signers = "";
  2886. strs.each(function(name, i){
  2887. while (name.length<strLength){ name = name+" ";}
  2888. //signers.push(name);
  2889. if (i % 2==0){
  2890. signers = signers+name+" ";
  2891. }else{
  2892. signers = signers+name+"<br>";
  2893. }
  2894. });
  2895. this.data[name] = signers;
  2896. break;
  2897. case "mainSend":
  2898. this.data[name] = strs.length ? strs.join(",") + ":" : "";
  2899. break;
  2900. case "copyto":
  2901. case "copyto2":
  2902. this.data[name] = strs.length ? strs.join(",") + "。" : "";
  2903. break;
  2904. default:
  2905. this.data[name] = strs.join(",");
  2906. }
  2907. //}
  2908. break;
  2909. default:
  2910. this.data[name] = v.toString();
  2911. }
  2912. }else{
  2913. this.data[name] = this.json.defaultValue[name];
  2914. }
  2915. },
  2916. computeData: function(){
  2917. this._computeData(false);
  2918. this.setData(this.data);
  2919. },
  2920. _computeItemData: function(name, typeItem, dataItem, scriptItem, ev, dom){
  2921. switch (this.json[typeItem]) {
  2922. case "data":
  2923. if (this.json[dataItem]){
  2924. if (ev) this._bindFieldChange(name, dataItem, dom);
  2925. this._computeItemFieldData(name, dataItem);
  2926. }
  2927. break;
  2928. case "script":
  2929. if (this.json[scriptItem] && this.json[scriptItem].code){
  2930. var v = this.form.Macro.exec(this.json[scriptItem].code, this);
  2931. this.data[name] = v;
  2932. if (name=="attachment"){
  2933. //this.data[name] = (typeOf(v)=="array") ? v.map(function(n, i){ var j = i+1; return j+"、"+n}).join("<br>") : v;
  2934. this.data[name] = (typeOf(v)=="array") ? v : [v];
  2935. }
  2936. if (name=="signer"){
  2937. var strs = [];
  2938. var strLength = 0;
  2939. if (o2.typeOf(v)!=="array") v = [v];
  2940. v.each(function(value){
  2941. if (o2.typeOf(value)=="object" && value.distinguishedName){
  2942. if (value.name.length>strLength) strLength = value.name.length;
  2943. strs.push(value.name);
  2944. }else{
  2945. if (value.length>strLength) strLength = value.length;
  2946. strs.push(value.toString());
  2947. }
  2948. });
  2949. var signers = "";
  2950. strs.each(function(name, i){
  2951. while (name.length<strLength){ name = name+" ";}
  2952. //signers.push(name);
  2953. if (i % 2==0){
  2954. signers = signers+name+" ";
  2955. }else{
  2956. signers = signers+name+"<br>";
  2957. }
  2958. });
  2959. this.data[name] = signers;
  2960. }
  2961. if (name=="issuanceDate" || name=="editionDate"){
  2962. var d = Date.parse(v);
  2963. if (d && d.isValid() && d.getFullYear()!=1970){
  2964. var y = d.getFullYear();
  2965. var m = d.getMonth();
  2966. var day = d.getDate();
  2967. m = m +1;
  2968. var lp = MWF.xApplication.process.Xform.LP;
  2969. this.data[name] = ""+y+lp.year+m+lp.month+day+lp.date;
  2970. }else{
  2971. this.data[name] = v;
  2972. }
  2973. //this.data[name] = (d.isValid() && d.getFullYear()!=1970) ? d.format("%Y年%m月%d日") : v;
  2974. }
  2975. }
  2976. break;
  2977. }
  2978. },
  2979. _computeCustomItemData: function(name, field, ev){
  2980. //if (this.json.customFields[l.name]){
  2981. if (ev) this._bindCustomFieldChange(name, field, name);
  2982. this._computeItemFieldData(name, null, field);
  2983. //}
  2984. },
  2985. _bindCustomFieldChange: function(name, dataItem, dom){
  2986. var field = this.form.all[dataItem];
  2987. if (field){
  2988. var bindFun = function(){
  2989. this._computeItemFieldData(name, null, dataItem);
  2990. //if (this.data[name]){
  2991. if (this[dom]){
  2992. var value = this.data[name] || "";
  2993. var reg = new RegExp("\n","g");
  2994. var text = value.replace(reg,"<br/>");
  2995. if (dom=="layout_redHeader" || dom=="layout_issuanceUnit") {
  2996. this[dom].set("html", this.data[name] || "");
  2997. }else if (dom=="layout_subject"){
  2998. this[dom].set("html", (this.data[name] || ""));
  2999. }else if (dom=="layout_attachment"){
  3000. this.setAttachmentData();
  3001. }else{
  3002. this[dom].set("html", text|| "");
  3003. }
  3004. }
  3005. this.reSetShow();
  3006. //}
  3007. }.bind(this);
  3008. field.node.store(this.json.id+"bindFun", bindFun);
  3009. field.addModuleEvent("change", bindFun);
  3010. }
  3011. },
  3012. _computeData: function(ev){
  3013. this._computeItemData("copies", "copiesValueType", "copiesValueData", "copiesValueScript", ev, "layout_copies");
  3014. this._computeItemData("secret", "secretValueType", "secretValueData", "secretValueScript", ev, "layout_secret");
  3015. this._computeItemData("priority", "priorityValueType", "priorityValueData", "priorityValueScript", ev, "layout_priority");
  3016. this._computeItemData("redHeader", "redHeaderValueType", "redHeaderValueData", "redHeaderValueScript", ev, "layout_redHeader");
  3017. this._computeItemData("fileno", "filenoValueType", "filenoValueData", "filenoValueScript", ev, "layout_fileno");
  3018. this._computeItemData("signer", "signerValueType", "signerValueData", "signerValueScript", ev, "layout_signer");
  3019. this._computeItemData("subject", "subjectValueType", "subjectValueData", "subjectValueScript", ev, "layout_subject");
  3020. this._computeItemData("mainSend", "mainSendValueType", "mainSendValueData", "mainSendValueScript", ev, "layout_mainSend");
  3021. this._computeItemData("attachment", "attachmentValueType", "attachmentValueData", "attachmentValueScript", ev, "layout_attachment");
  3022. this._computeItemData("issuanceUnit", "issuanceUnitValueType", "issuanceUnitValueData", "issuanceUnitValueScript", ev, "layout_issuanceUnit");
  3023. this._computeItemData("issuanceDate", "issuanceDateValueType", "issuanceDateValueData", "issuanceDateValueScript", ev, "layout_issuanceDate");
  3024. this._computeItemData("annotation", "annotationValueType", "annotationValueData", "annotationValueScript", ev, "layout_annotation");
  3025. this._computeItemData("copyto", "copytoValueType", "copytoValueData", "copytoValueScript", ev, "layout_copytoContent");
  3026. this._computeItemData("copyto2", "copyto2ValueType", "copyto2ValueData", "copyto2ValueScript", ev, "layout_copyto2Content");
  3027. this._computeItemData("editionUnit", "editionUnitValueType", "editionUnitValueData", "editionUnitValueScript", ev, "layout_edition_issuance_unit");
  3028. this._computeItemData("editionDate", "editionDateValueType", "editionDateValueData", "editionDateValueScript", ev, "layout_edition_issuance_date");
  3029. this._computeItemData("meetingAttend", "meetingAttendValueType", "meetingAttendValueData", "meetingAttendValueScript", ev, "layout_meetingAttendContent");
  3030. this._computeItemData("meetingLeave", "meetingLeaveValueType", "meetingLeaveValueData", "meetingLeaveValueScript", ev, "layout_meetingLeaveContent");
  3031. this._computeItemData("meetingSit", "meetingSitValueType", "meetingSitValueData", "meetingSitValueScript", ev, "layout_meetingSitContent");
  3032. this._computeItemData("meetingRecord", "meetingRecordValueType", "meetingRecordValueData", "meetingRecordValueScript", ev, "layout_meetingRecordContent");
  3033. Object.each(this.json.customFields, function(field, k){
  3034. this._computeCustomItemData(k, field, ev);
  3035. }.bind(this));
  3036. // if (this.customLayouts){
  3037. // this.customLayouts.each(function(l){
  3038. // this._computeCustomItemData(l, ev);
  3039. // }.bind(this))
  3040. // }
  3041. },
  3042. _loadValue: function(){
  3043. var data = this._getBusinessData();
  3044. },
  3045. /**重新计算公文编辑器的所有字段,当字段是脚本时可以使用该方法立即更新
  3046. * @summary 重新计算公文编辑器的所有字段
  3047. * @example
  3048. * this.form.get("fieldId").reload();
  3049. */
  3050. reload: function(callback){
  3051. this.resetData(false, callback);
  3052. },
  3053. resetData: function(diffFiletext, callback){
  3054. this._computeData(false);
  3055. this.pages = [];
  3056. this.editMode = false;
  3057. this._createPage(function(control){
  3058. this._loadPageLayout(control);
  3059. this.setData(this.data, diffFiletext);
  3060. this._repage();
  3061. if (!this.editMode && this.allowEdit && !this.historyMode && this.options.pageShow!=="double") {
  3062. this._editFiletext("inline");
  3063. this.editMode = true;
  3064. }
  3065. if (callback) callback();
  3066. }.bind(this));
  3067. },
  3068. /**
  3069. * @summary 判断公文编辑器的正文内容是否已经填写
  3070. * @return {Boolean} 是否为空
  3071. * @example
  3072. * if( this.form.get("fieldId").isEmpty() ){
  3073. * this.form.notice('请填写正文内容')
  3074. * }
  3075. */
  3076. isEmpty: function(){
  3077. var data = this.getData();
  3078. if( typeOf(data) !== "object" )return true;
  3079. return !data.filetext || data.filetext===this.json.defaultValue.filetext;
  3080. },
  3081. /**
  3082. * @summary 获取公文编辑器数据
  3083. * @return {Object} 公文编辑器的数据
  3084. * @example
  3085. * var data = this.form.get("fieldId").getData();
  3086. */
  3087. getData: function(){
  3088. //if (this.editMode){
  3089. if (this.layout_copies) this.data.copies = this.layout_copies.get("text");
  3090. if (this.layout_secret) this.data.secret = this.layout_secret.get("text");
  3091. if (this.layout_priority) this.data.priority = this.layout_priority.get("text");
  3092. if (this.layout_redHeader) this.data.redHeader = this.layout_redHeader.get("html");
  3093. if (this.layout_fileno) this.data.fileno = this.layout_fileno.get("text");
  3094. if (this.layout_signerTitle) this.data.signerTitle = this.layout_signerTitle.get("text");
  3095. if (this.layout_signer) this.data.signer = this.layout_signer.get("html");
  3096. if (this.layout_subject) this.data.subject = this.layout_subject.get("html");
  3097. if (this.layout_mainSend) this.data.mainSend = this.layout_mainSend.get("text");
  3098. if (this.editMode) {
  3099. if (this.layout_filetext){
  3100. var text = this.layout_filetext.get("text");
  3101. text = text.replace(/\u3000*/g, "");
  3102. if (text && text !==this.json.defaultValue.filetext){
  3103. this.data.filetext = this.layout_filetext.get("html");
  3104. }else{
  3105. this.data.filetext = "";
  3106. }
  3107. }
  3108. }
  3109. this.getAttachmentTextData();
  3110. if (this.layout_signer) this.data.signer = this.layout_signer.get("html");
  3111. if (this.layout_attachmentTitle) this.data.attachmentTitle = this.layout_attachmentTitle.get("text");
  3112. if (this.layout_attachment){
  3113. this._computeItemData("attachment", "attachmentValueType", "attachmentValueData", "attachmentValueScript", false, "layout_attachment");
  3114. // var atts = [];
  3115. // var nodes = this.layout_attachment.getElements(".doc_layout_attachment_content_name");
  3116. // if (nodes.length){
  3117. // nodes.each(function(node){
  3118. // atts.push(node.get("text"));
  3119. // });
  3120. // }
  3121. // this.data.attachment = atts;
  3122. }
  3123. if (this.layout_issuanceUnit) this.data.issuanceUnit = this.layout_issuanceUnit.get("html");
  3124. if (this.layout_issuanceDate) this.data.issuanceDate = this.layout_issuanceDate.get("text");
  3125. if (this.layout_annotation){
  3126. var annotation = this.layout_annotation.get("text");
  3127. if (annotation.substring(0,1)=="(") annotation = annotation.substring(1, annotation.length);
  3128. if (annotation.substring(annotation.length-1, annotation.length)==")") annotation = annotation.substring(0, annotation.length-1);
  3129. this.data.annotation = annotation;
  3130. }
  3131. if (this.layout_copytoTitle) this.data.copytoTitle = this.layout_copytoTitle.get("text");
  3132. if (this.layout_copytoContent) this.data.copyto = this.layout_copytoContent.get("text");
  3133. if (this.layout_copyto2Title) this.data.copyto2Title = this.layout_copyto2Title.get("text");
  3134. if (this.layout_copyto2Content) this.data.copyto2 = this.layout_copyto2Content.get("text");
  3135. if (this.layout_edition_issuance_unit) this.data.editionUnit = this.layout_edition_issuance_unit.get("text");
  3136. if (this.layout_edition_issuance_date) this.data.editionDate = this.layout_edition_issuance_date.get("text");
  3137. if (this.layout_meetingAttendTitle) this.data.meetingAttendTitle = this.layout_meetingAttendTitle.get("text");
  3138. if (this.layout_meetingLeaveTitle) this.data.meetingLeaveTitle = this.layout_meetingLeaveTitle.get("text");
  3139. if (this.layout_meetingSitTitle) this.data.meetingSitTitle = this.layout_meetingSitTitle.get("text");
  3140. if (this.layout_meetingAttendContent) this.data.meetingAttend = this.layout_meetingAttendContent.get("html");
  3141. if (this.layout_meetingLeaveContent) this.data.meetingLeave = this.layout_meetingLeaveContent.get("html");
  3142. if (this.layout_meetingSitContent) this.data.meetingSit = this.layout_meetingSitContent.get("html");
  3143. if (this.layout_meetingRecordContent) this.data.meetingRecord = this.layout_meetingRecordContent.get("html");
  3144. this.getSealData();
  3145. if (this.customLayouts){
  3146. this.customLayouts.each(function(l){
  3147. this.data[l.name] = l.node.get("html");
  3148. }.bind(this))
  3149. }
  3150. //}
  3151. return this.data;
  3152. },
  3153. getAttachmentTextData: function(){
  3154. if (this.layout_attachmentText && this.layout_attachmentText.get("contenteditable")=="true"){
  3155. var text = this.layout_attachmentText.get("text");
  3156. text = text.replace(/\u3000*/g, "");
  3157. if (text && text !==MWF.xApplication.process.Xform.LP.documentEditor.attachmentInfor){
  3158. this.data.attachmentText = this.layout_attachmentText.get("html");
  3159. }else{
  3160. this.data.attachmentText = "";
  3161. }
  3162. }
  3163. },
  3164. getSealData: function(){
  3165. if (this.layout_seals && this.layout_seals.length) {
  3166. this.data.seals = [];
  3167. this.layout_seals.each(function(seal){
  3168. this.data.seals.push(seal.get("src"));
  3169. }.bind(this));
  3170. }
  3171. },
  3172. setAttachmentData: function(){
  3173. if (!this.attachmentTemplete){
  3174. this.attachmentTemplete = this.layout_attachment.get("html");
  3175. }
  3176. this.layout_attachment.empty();
  3177. if (this.data.attachment && !this.data.attachment.each){
  3178. this.data.attachment = this.data.attachment.split(/,\s*/g);
  3179. }
  3180. if (this.data.attachment && this.data.attachment.length && this.data.attachment.each){
  3181. //var tmpdiv = new Element("div", {"styles": {"display":"none"}}).inject(document.body);
  3182. var tmpdiv = new Element("div");
  3183. this.data.attachment.each(function(name, idx){
  3184. tmpdiv.set("html", this.attachmentTemplete);
  3185. var serialNode = tmpdiv.getElement(".doc_layout_attachment_content_serial");
  3186. var nameNode = tmpdiv.getElement(".doc_layout_attachment_content_name");
  3187. if (this.data.attachment.length>1){
  3188. if (serialNode){
  3189. serialNode.set("text", idx+1);
  3190. serialNode.getNext().set("text", ".");
  3191. }
  3192. }else{
  3193. if (serialNode){
  3194. serialNode.set("text", "");
  3195. serialNode.getNext().set("text", "");
  3196. }
  3197. }
  3198. if (nameNode) nameNode.set("text", name);
  3199. var html = tmpdiv.get("html");
  3200. tmpdiv.empty();
  3201. this.layout_attachment.appendHTML(html);
  3202. }.bind(this));
  3203. tmpdiv.destroy();
  3204. }
  3205. },
  3206. setAttachmentText: function(data){
  3207. this.layout_attachmentText.empty();
  3208. if (data.attachmentText){
  3209. this.layout_attachmentText.set("html", data.attachmentText);
  3210. }else{
  3211. if (this._getEdit("attachmentText", "attachmentTextEdit", "attachmentTextEditScript")){
  3212. this.layout_attachmentText.set("text", MWF.xApplication.process.Xform.LP.documentEditor.attachmentInfor);
  3213. }
  3214. }
  3215. },
  3216. filterHtml: function(html){
  3217. var content = html.replace(/(?:<script[\s\S]*?)(?:(?:<\/script>)|(?:\/>))/gmi, "");
  3218. // content = content.replace(/(?<=[\"\'])javascript\:(?=.*")/gmi, "");
  3219. //content = content.replace(/(?<=\s)on\w*|src|href(?=\=[\"\'])/gmi, function(match){
  3220. content = content.replace(/\son\w*|src|href(?=\=[\"\'])/gmi, function(match){
  3221. return "data-"+match;
  3222. });
  3223. return content;
  3224. },
  3225. /**设置公文编辑器数据
  3226. * @param {Object} data
  3227. * @example
  3228. * var data = this.form.get("fieldId").getData();
  3229. * data.filetext = "测试内容";
  3230. * this.form.get("fieldId").setData(data);
  3231. */
  3232. setData: function(data, diffFiletext){
  3233. if (data){
  3234. this.data = data;
  3235. // this.data["$json"] = this.json;
  3236. this._setBusinessData(data);
  3237. if (this.layout_copies){
  3238. if (data.copies){
  3239. this.layout_copies.set("text", data.copies || " ");
  3240. }else{
  3241. this.layout_copies.set("html", "<span>&nbsp</span>");
  3242. }
  3243. }
  3244. if (this.layout_secret){
  3245. if (data.secret){
  3246. this.layout_secret.set("text", data.secret || " ");
  3247. }else{
  3248. this.layout_secret.set("html", "<span>&nbsp</span>");
  3249. }
  3250. }
  3251. if (this.layout_priority){
  3252. if (data.priority){
  3253. this.layout_priority.set("text", data.priority || " ");
  3254. }else{
  3255. this.layout_priority.set("html", "<span>&nbsp</span>");
  3256. }
  3257. }
  3258. if (this.layout_redHeader) this.layout_redHeader.set("html", data.redHeader || "");
  3259. if (this.layout_fileno) this.layout_fileno.set("text", data.fileno || " ");
  3260. if (this.layout_signerTitle) this.layout_signerTitle.set("text", data.signerTitle || " ");
  3261. if (this.layout_signer) this.layout_signer.set("html", data.signer || " ");
  3262. if (this.layout_subject) this.layout_subject.set("html", data.subject || " ");
  3263. if (this.layout_mainSend) this.layout_mainSend.set("text", data.mainSend || " ");
  3264. if (diffFiletext) {
  3265. this.layout_filetext.set("html", diffFiletext);
  3266. }else if (this.layout_filetext){
  3267. //this.layout_filetext.set("placeholder", this.json.defaultValue.filetext);
  3268. var html = data.filetext.replace(/(?:<script(?:\s+[\w-]+(?:=(?:"[^"]*"|'[^']*'))?)*\s*>([\s\S]*?)<\/script\s*>)|(?:on\w+\s*=\s*(?:"[^"]*"|'[^']*'))|(?:javascript:.*)/g, '');
  3269. this.layout_filetext.set("html", html);
  3270. // this.layout_filetext.set("html", data.filetext || "  ");
  3271. // var tableList = this.layout_filetext.getElements("table");
  3272. // if (tableList && tableList.length){
  3273. // // var w = this.layout_filetext.offsetWidth;
  3274. // // tableList.setStyle("width", ""+w+"px");
  3275. // tableList.setStyles({
  3276. // "margin-left": "",
  3277. // "margin-right": "",
  3278. // "word-break": "break-all"
  3279. // });
  3280. // }
  3281. }
  3282. if (this.layout_signer) this.layout_signer.set("html", data.signer || "");
  3283. if (this.layout_attachmentTitle) this.layout_attachmentTitle.set("text", data.attachmentTitle || " ");
  3284. if (this.layout_attachment){
  3285. this.setAttachmentData();
  3286. }
  3287. if (this.layout_attachmentText){
  3288. this.setAttachmentText(data);
  3289. }
  3290. if (this.layout_issuanceUnit) this.layout_issuanceUnit.set("html", data.issuanceUnit || " ");
  3291. if (this.layout_issuanceDate) this.layout_issuanceDate.set("text", data.issuanceDate || " ");
  3292. if (this.layout_annotation){
  3293. var annotation = data.annotation;
  3294. if (annotation){
  3295. if (annotation.substring(0, 1)!=="(") annotation = "("+annotation;
  3296. if (annotation.substring(annotation.length-1, annotation.length)!==")") annotation = annotation+")";
  3297. this.layout_annotation.set("text", annotation);
  3298. }else{
  3299. this.layout_annotation.set("text", "");
  3300. }
  3301. }
  3302. if (this.layout_copytoTitle) this.layout_copytoTitle.set("text", data.copytoTitle || " ");
  3303. if (this.layout_copytoContent) this.layout_copytoContent.set("text", data.copyto || " ");
  3304. if (this.layout_copyto2Title) this.layout_copyto2Title.set("text", data.copyto2Title || " ");
  3305. if (this.layout_copyto2Content) this.layout_copyto2Content.set("text", data.copyto2 || " ");
  3306. if (this.layout_edition_issuance_unit) this.layout_edition_issuance_unit.set("text", data.editionUnit || " ");
  3307. if (this.layout_edition_issuance_date) this.layout_edition_issuance_date.set("text", data.editionDate || " ");
  3308. if (this.layout_meetingAttendTitle) this.layout_meetingAttendTitle.set("text", data.meetingAttendTitle || this.json.defaultValue.meetingAttendTitle || " ");
  3309. if (this.layout_meetingLeaveTitle) this.layout_meetingLeaveTitle.set("text", data.meetingLeaveTitle || this.json.defaultValue.meetingLeaveTitle || " ");
  3310. if (this.layout_meetingSitTitle) this.layout_meetingSitTitle.set("text", data.meetingSitTitle || this.json.defaultValue.meetingSitTitle || " ");
  3311. if (this.layout_meetingAttendContent) this.layout_meetingAttendContent.set("html", this.filterHtml(data.meetingAttend || " "));
  3312. if (this.layout_meetingLeaveContent) this.layout_meetingLeaveContent.set("html", this.filterHtml(data.meetingLeave || " "));
  3313. if (this.layout_meetingSitContent) this.layout_meetingSitContent.set("html", this.filterHtml(data.meetingSit || " "));
  3314. if (this.layout_meetingRecordContent) this.layout_meetingRecordContent.set("html", this.filterHtml(data.meetingRecord || " "));
  3315. if (this.layout_seals){
  3316. if (data.seals && data.seals.length){
  3317. data.seals.each(function(src, i){
  3318. if (this.layout_seals[i] && src){
  3319. this.layout_seals[i].src = src;
  3320. this.layout_seals[i].show();
  3321. this.layout_seals[i].setStyles({
  3322. "border": "0",
  3323. "border-radius": "0",
  3324. "z-index": -1
  3325. });
  3326. }
  3327. }.bind(this));
  3328. }
  3329. }
  3330. if (this.customLayouts){
  3331. this.customLayouts.each(function(l){
  3332. var value = this.data[l.name] || "";
  3333. var reg = new RegExp("\n","g");
  3334. var text = value.replace(reg,"<br/>");
  3335. l.node.set("html",text || " ");
  3336. }.bind(this))
  3337. }
  3338. if (this.layout_issuanceUnit && this.layout_issuanceDate ){
  3339. var table = this.layout_issuanceUnit.getParent("table")
  3340. if (table && !table.hasClass("doc_layout_headIssuance")){
  3341. var unitWidth = o2.getTextSize(this.layout_issuanceUnit.get("text"), {
  3342. "font-size":"16pt",
  3343. "font-family":"'Times New Roman',仿宋_GB2312",
  3344. "letter-spacing": "-0.2pt"
  3345. }).x;
  3346. var dateWidth = o2.getTextSize(this.layout_issuanceDate.get("text"), {
  3347. "font-size":"16pt",
  3348. "font-family":"'Times New Roman',仿宋_GB2312",
  3349. "letter-spacing": "-0.2pt"
  3350. }).x;
  3351. if (table.hasClass("doc_layout_issuanceV2")){
  3352. if (unitWidth<=dateWidth){
  3353. //日期右空四字,单位相对与日期居中
  3354. var flagTd = this.layout_issuanceUnit.getParent("td").getNext("td");
  3355. if (flagTd) flagTd.setStyle("width", "64pt");
  3356. flagTd = this.layout_issuanceDate.getParent("td").getNext("td");
  3357. if (flagTd) flagTd.setStyle("width", "64pt");
  3358. var dateP = this.layout_issuanceDate.getParent("p");
  3359. if (dateP){
  3360. dateP.setStyle("text-align", "right");
  3361. var span = dateP.getElement("span.space");
  3362. if (span) span.destroy();
  3363. }
  3364. }else{
  3365. var flagTd = this.layout_issuanceUnit.getParent("td").getNext("td");
  3366. if (flagTd) flagTd.setStyle("width", "32pt");
  3367. flagTd = this.layout_issuanceDate.getParent("td").getNext("td");
  3368. if (flagTd) flagTd.setStyle("width", "32pt");
  3369. var dateP = this.layout_issuanceDate.getParent("p");
  3370. if (dateP){
  3371. dateP.setStyle("text-align", "left");
  3372. var span = dateP.getElement("span.space");
  3373. if (!span) new Element("span.space", { "html": "&#x3000;&#x3000;" }).inject(dateP, "top");
  3374. }
  3375. }
  3376. }else{
  3377. if (unitWidth<=dateWidth){
  3378. //日期右空四字,单位相对与日期居中
  3379. var flagTd = this.layout_issuanceDate.getParent("td").getNext("td");
  3380. if (flagTd) {
  3381. var pt = 16*4; //空四字
  3382. flagTd.setStyle("width", "" + pt + "pt");
  3383. flagTd = this.layout_issuanceUnit.getParent("td").getNext("td");
  3384. if (flagTd) flagTd.setStyle("width", "" + pt + "pt");
  3385. }
  3386. //var dateTd = this.layout_issuanceDate.getParent("td");
  3387. var unitTd = this.layout_issuanceUnit.getParent("td");
  3388. unitTd.setStyle("width", dateWidth);
  3389. var p = this.layout_issuanceUnit.getParent("p");
  3390. if (p) p.setStyle("text-align", "center");
  3391. }else{
  3392. var flagTd = this.layout_issuanceUnit.getParent("td").getNext("td");
  3393. if (flagTd) flagTd.setStyle("width", "32pt");
  3394. var unitTd = this.layout_issuanceUnit.getParent("td");
  3395. unitTd.setStyle("width", "auto");
  3396. flagTd = this.layout_issuanceDate.getParent("td").getNext("td");
  3397. if (flagTd) flagTd.setStyle("width", "64pt");
  3398. var p = this.layout_issuanceDate.getParent("p");
  3399. if (p) p.setStyle("text-align", "right");
  3400. }
  3401. }
  3402. }
  3403. }
  3404. var coptyToTitleNode = (this.layout_copytoTitle || this.layout_copyto2Title);
  3405. if (coptyToTitleNode){
  3406. var editionTable = coptyToTitleNode.getParent("table");
  3407. if (editionTable) if (editionTable.get("data-compute-style")=="y"){
  3408. var rows = editionTable.rows;
  3409. for (var i=0; i<rows.length; i++){
  3410. var cell = rows[i].cells[0];
  3411. var tmp = cell.getElement(".doc_layout_edition_issuance_unit");
  3412. if (!tmp) tmp = cell.getElement(".doc_layout_edition_issuance_date");
  3413. if (!tmp){
  3414. var text = cell.get("text").trim();
  3415. var l = 14*text.length;
  3416. var wl = 19*text.length;
  3417. cell.setStyles({
  3418. "max-width": ""+l+"pt",
  3419. "min-width": ""+l+"pt",
  3420. "width": ""+wl+"pt"
  3421. });
  3422. }
  3423. }
  3424. }
  3425. }
  3426. }
  3427. },
  3428. createErrorNode: function(text){
  3429. var node = new Element("div");
  3430. var iconNode = new Element("div", {
  3431. "styles": {
  3432. "width": "20px",
  3433. "height": "20px",
  3434. "float": "left",
  3435. "background": "url("+"../x_component_process_Xform/$Form/default/icon/error.png) center center no-repeat"
  3436. }
  3437. }).inject(node);
  3438. var textNode = new Element("div", {
  3439. "styles": {
  3440. "line-height": "20px",
  3441. "margin-left": "20px",
  3442. "color": "red",
  3443. "word-break": "keep-all"
  3444. },
  3445. "text": text
  3446. }).inject(node);
  3447. return node;
  3448. },
  3449. notValidationMode: function(text){
  3450. if (!this.isNotValidationMode){
  3451. this.isNotValidationMode = true;
  3452. this.node.store("borderStyle", this.node.getStyles("border-left", "border-right", "border-top", "border-bottom"));
  3453. this.node.setStyle("border", "1px solid red");
  3454. this.errNode = this.createErrorNode(text).inject(this.node, "after");
  3455. this.showNotValidationMode(this.node);
  3456. }
  3457. },
  3458. showNotValidationMode: function(node){
  3459. var p = node.getParent("div");
  3460. if (p){
  3461. if (p.get("MWFtype") == "tab$Content"){
  3462. if (p.getParent("div").getStyle("display")=="none"){
  3463. var contentAreaNode = p.getParent("div").getParent("div");
  3464. var tabAreaNode = contentAreaNode.getPrevious("div");
  3465. var idx = contentAreaNode.getChildren().indexOf(p.getParent("div"));
  3466. var tabNode = tabAreaNode.getLast().getFirst().getChildren()[idx];
  3467. tabNode.click();
  3468. p = tabAreaNode.getParent("div");
  3469. }
  3470. }
  3471. this.showNotValidationMode(p);
  3472. }
  3473. },
  3474. validationMode: function(){
  3475. if (this.isNotValidationMode){
  3476. this.isNotValidationMode = false;
  3477. this.node.setStyles(this.node.retrieve("borderStyle"));
  3478. if (this.errNode){
  3479. this.errNode.destroy();
  3480. this.errNode = null;
  3481. }
  3482. }
  3483. },
  3484. validationConfigItem: function(routeName, data){
  3485. var flag = (data.status=="all") ? true: (routeName == data.decision);
  3486. if (flag){
  3487. var n = this.getData();
  3488. var v = (data.valueType=="value") ? n : n.length;
  3489. switch (data.operateor){
  3490. case "isnull":
  3491. if (!v){
  3492. this.notValidationMode(data.prompt);
  3493. return false;
  3494. }
  3495. break;
  3496. case "notnull":
  3497. if (v){
  3498. this.notValidationMode(data.prompt);
  3499. return false;
  3500. }
  3501. break;
  3502. case "gt":
  3503. if (v>data.value){
  3504. this.notValidationMode(data.prompt);
  3505. return false;
  3506. }
  3507. break;
  3508. case "lt":
  3509. if (v<data.value){
  3510. this.notValidationMode(data.prompt);
  3511. return false;
  3512. }
  3513. break;
  3514. case "equal":
  3515. if (v==data.value){
  3516. this.notValidationMode(data.prompt);
  3517. return false;
  3518. }
  3519. break;
  3520. case "neq":
  3521. if (v!=data.value){
  3522. this.notValidationMode(data.prompt);
  3523. return false;
  3524. }
  3525. break;
  3526. case "contain":
  3527. if (v.indexOf(data.value)!=-1){
  3528. this.notValidationMode(data.prompt);
  3529. return false;
  3530. }
  3531. break;
  3532. case "notcontain":
  3533. if (v.indexOf(data.value)==-1){
  3534. this.notValidationMode(data.prompt);
  3535. return false;
  3536. }
  3537. break;
  3538. }
  3539. }
  3540. return true;
  3541. },
  3542. validationConfig: function(routeName, opinion){
  3543. if (this.json.validationConfig){
  3544. if (this.json.validationConfig.length){
  3545. for (var i=0; i<this.json.validationConfig.length; i++) {
  3546. var data = this.json.validationConfig[i];
  3547. if (!this.validationConfigItem(routeName, data)) return false;
  3548. }
  3549. }
  3550. return true;
  3551. }
  3552. return true;
  3553. },
  3554. validation: function(routeName, opinion){
  3555. if (!this.validationConfig(routeName, opinion)) return false;
  3556. if (!this.json.validation) return true;
  3557. if (!this.json.validation.code) return true;
  3558. this.currentRouteName = routeName;
  3559. var flag = this.form.Macro.exec(this.json.validation.code, this);
  3560. this.currentRouteName = "";
  3561. if (!flag) flag = MWF.xApplication.process.Xform.LP.notValidation;
  3562. if (flag.toString()!="true"){
  3563. this.notValidationMode(flag);
  3564. return false;
  3565. }
  3566. return true;
  3567. },
  3568. removeDisplayNone: function(node){
  3569. var n = node.getFirst();
  3570. while (n){
  3571. if (n.getStyle("display")=="none" || (this.json.toWordSeal=="n" && n.hasClass("doc_layout_seal"))){
  3572. var tmp = n.getNext();
  3573. n.destroy();
  3574. n = tmp;
  3575. }else{
  3576. n = this.removeDisplayNone(n);
  3577. n = n.getNext();
  3578. }
  3579. }
  3580. return node;
  3581. },
  3582. /**将公文编辑器内容以html形式输出
  3583. * @return {String}
  3584. * @example
  3585. * var html = this.form.get("fieldId").getDocumentHtml();
  3586. */
  3587. getDocumentHtml: function(){
  3588. var docNode = this.contentNode.getFirst().getFirst();
  3589. var filetextNode = docNode.getElement(".doc_layout_filetext");
  3590. var tables = filetextNode.getElements("table");
  3591. tables.each(function(table){
  3592. var tableWidth = table.offsetWidth;
  3593. table.set("data-o2-width", tableWidth);
  3594. // var tr = table.getElement("tr");
  3595. // if (tr){
  3596. table.getElements("td").each(function(td){
  3597. var tdx = td.offsetWidth;
  3598. var p = (tdx/tableWidth)*100;
  3599. td.set("data-o2-width", tdx);
  3600. });
  3601. //}
  3602. });
  3603. var tmpNode = this.contentNode.getFirst().getFirst().clone(true);
  3604. var htmlNode = tmpNode.getLast();
  3605. htmlNode = this.removeDisplayNone(htmlNode);
  3606. var nodes = tmpNode.querySelectorAll("[data-w-style]");
  3607. if (nodes.length){
  3608. for (var i=0; i<nodes.length; i++){
  3609. var n = nodes.item(i);
  3610. wStyle = n.dataset["wStyle"];
  3611. var styles = wStyle.split(/\s*\;\s*/g);
  3612. styles.each(function(style){
  3613. if (style){
  3614. try{
  3615. s = style.split(/\s*\:\s*/g);
  3616. n.setStyle(s[0], s[1]);
  3617. }catch(e) {}
  3618. }
  3619. });
  3620. }
  3621. }
  3622. var filetextNode = tmpNode.getElement(".doc_layout_filetext");
  3623. filetextNode.getElements("td").setStyle("width", "");
  3624. //var tables = filetextNode.getElements("table");
  3625. var tables = tmpNode.querySelectorAll("table[data-o2-width]");
  3626. for (var i=0; i<tables.length; i++){
  3627. tables[i].setStyle("width", tables[i].dataset["o2Width"]+"px");
  3628. }
  3629. var tds = tmpNode.querySelectorAll("td[data-o2-width]");
  3630. for (var i=0; i<tds.length; i++){
  3631. tds[i].setStyle("width", tds[i].dataset["o2Width"]+"px");
  3632. }
  3633. var htmlStr = tmpNode.get("html");
  3634. tmpNode.destroy();
  3635. return "<html xmlns:v=\"urn:schemas-microsoft-com:vml\"><head><meta charset=\"UTF-8\" /></head><body>"+htmlStr+"</body></html>";
  3636. },
  3637. /**
  3638. * @summary 将公文编辑器转换成附件,转换的文件名和格式等信息与配置有关
  3639. * @param {Function} [callback] 转换后的回调方法,参数是附件数据.
  3640. * @param {string} [name] - 如果为空或者不传,转换的文件名和格式等信息与配置有关.
  3641. * @example
  3642. * this.form.get("fieldId").toWord( function(attachmentData){
  3643. * //attachmentData 转换后的附件数据
  3644. * })
  3645. */
  3646. toWord: function(callback, name, cb, notSave){
  3647. var docNmae = name || this.json.toWordFilename || this.form.businessData.data.subject || this.form.businessData.data["$work"].title;
  3648. this.getData();
  3649. this.reload(function(){
  3650. if (!this.data.attachmentText && this.layout_attachmentText){
  3651. this.layout_attachmentText.set("text", "");
  3652. }
  3653. var fileName = docNmae || this.json.toWordFilename || "$doc";
  3654. var n = fileName.lastIndexOf(".");
  3655. if (this.json.wordConversionType==="service"){
  3656. if (n==-1) fileName = fileName+".doc";
  3657. var content = encodeURIComponent(this.getDocumentHtml());
  3658. var body = {
  3659. "fileName": fileName,
  3660. "site": this.json.toWordSite || "$doc",
  3661. "content": content
  3662. };
  3663. this.toWordServiceService(body, callback, cb);
  3664. }else{
  3665. if (n==-1) fileName = fileName+".docx";
  3666. var extName = fileName.split('.').pop();
  3667. if (extName.toLowerCase()!=='docx') fileName = fileName+".docx";
  3668. var content = this.getDocumentHtml();
  3669. o2.xDesktop.requireApp("process.Xform", "widget.OOXML", function(){
  3670. (new o2.OOXML.WML({
  3671. "protection": (this.json.wordConversionEncryption===true),
  3672. "firstPageNumber": (this.json.firstPageNumber!==false)
  3673. })).load(content).then(function(oo_content){
  3674. if (!notSave) {
  3675. oo_content.name = fileName
  3676. var formData = new FormData();
  3677. formData.append("site", this.json.toWordSite || "$doc");
  3678. formData.append("fileName", fileName);
  3679. formData.append('file', oo_content);
  3680. this.toWordOOXMLService(formData, oo_content, callback, cb);
  3681. }else{
  3682. if (callback) callback(oo_content, fileName);
  3683. if (cb) cb();
  3684. }
  3685. }.bind(this));
  3686. }.bind(this));
  3687. }
  3688. }.bind(this));
  3689. },
  3690. toWordServiceService: function(body, callback, cb){
  3691. if (this.toWordServiceServiceProcessing){
  3692. if (!this.toWordServiceServiceProcessList) this.toWordServiceServiceProcessList = [];
  3693. this.toWordServiceServiceProcessList.push({
  3694. body: body,
  3695. callback: callback,
  3696. cb: cb
  3697. });
  3698. return false;
  3699. }
  3700. this.toWordServiceServiceProcessing = true;
  3701. o2.Actions.get("x_processplatform_assemble_surface").docToWord(this.form.businessData.work.id, body, function(json){
  3702. if (this.form.businessData.workCompleted){
  3703. o2.Actions.get("x_processplatform_assemble_surface").getAttachmentWorkcompleted(json.data.id, this.form.businessData.workCompleted.id,function(attjson){
  3704. if (callback) callback(attjson.data);
  3705. this.showToWord(attjson.data);
  3706. }.bind(this));
  3707. }else{
  3708. o2.Actions.get("x_processplatform_assemble_surface").getAttachment(json.data.id, this.form.businessData.work.id,function(attjson){
  3709. if (callback) callback(attjson.data);
  3710. this.showToWord(attjson.data);
  3711. }.bind(this));
  3712. }
  3713. if (cb) cb();
  3714. this.toWordServiceServiceProcessing = false;
  3715. if (this.toWordServiceServiceProcessList && this.toWordServiceServiceProcessList.length){
  3716. var o = this.toWordServiceServiceProcessList.shift();
  3717. this.toWordServiceService(o.body, o.callback, o.cb);
  3718. }
  3719. }.bind(this), function(){
  3720. this.toWordServiceServiceProcessing = false;
  3721. if (this.toWordServiceServiceProcessList && this.toWordServiceServiceProcessList.length){
  3722. var o = this.toWordServiceServiceProcessList.shift();
  3723. this.toWordServiceService(o.body, o.callback, o.cb);
  3724. }
  3725. });
  3726. },
  3727. toWordOOXMLService: function(formData, oo_content, callback, cb){
  3728. if (this.toWordOOXMLServiceProcessing){
  3729. if (!this.toWordOOXMLServiceProcessList) this.toWordOOXMLServiceProcessList = [];
  3730. this.toWordOOXMLServiceProcessList.push({
  3731. formData: formData,
  3732. oo_content: oo_content,
  3733. callback: callback,
  3734. cb: cb
  3735. });
  3736. return false;
  3737. }
  3738. this.toWordOOXMLServiceProcessing = true;
  3739. o2.Actions.get("x_processplatform_assemble_surface").V2UploadWorkOrWorkCompleted(this.form.businessData.work.id, formData, oo_content, function (json) {
  3740. if (this.form.businessData.workCompleted) {
  3741. o2.Actions.get("x_processplatform_assemble_surface").getAttachmentWorkcompleted(json.data.id, this.form.businessData.workCompleted.id, function (attjson) {
  3742. if (callback) callback(attjson.data);
  3743. this.showToWord(attjson.data);
  3744. }.bind(this));
  3745. } else {
  3746. o2.Actions.get("x_processplatform_assemble_surface").getAttachment(json.data.id, this.form.businessData.work.id, function (attjson) {
  3747. if (callback) callback(attjson.data);
  3748. this.showToWord(attjson.data);
  3749. }.bind(this));
  3750. }
  3751. if (cb) cb();
  3752. this.toWordOOXMLServiceProcessing = false;
  3753. if (this.toWordOOXMLServiceProcessList && this.toWordOOXMLServiceProcessList.length){
  3754. var o = this.toWordOOXMLServiceProcessList.shift();
  3755. this.toWordOOXMLService(o.formData, o.oo_content, o.callback, o.cb);
  3756. }
  3757. }.bind(this), function(){
  3758. this.toWordOOXMLServiceProcessing = false;
  3759. if (this.toWordOOXMLServiceProcessList && this.toWordOOXMLServiceProcessList.length){
  3760. var o = this.toWordOOXMLServiceProcessList.shift();
  3761. this.toWordOOXMLService(o.formData, o.oo_content, o.callback, o.cb);
  3762. }
  3763. }.bind(this));
  3764. },
  3765. docToWord: function(callback){
  3766. try {
  3767. var flag = true;
  3768. if (this.json.toWordConditionScript && this.json.toWordConditionScript.code){
  3769. flag = !!this.form.Macro.exec(this.json.toWordConditionScript.code, this);
  3770. }
  3771. if (flag){
  3772. this.toWord(null, "", callback);
  3773. }else{
  3774. if (callback) callback();
  3775. }
  3776. }catch(e){
  3777. console.error(e);
  3778. if (callback) callback();
  3779. };
  3780. },
  3781. showToWord: function(att_word){
  3782. var site = this.json.toWordSite || "$doc";
  3783. var attModule = this.form.all[site];
  3784. if (attModule){
  3785. var atts = [];
  3786. attModule.attachmentController.attachments.each(function(att){
  3787. if (att.data.name!==att_word.name){
  3788. atts.push(att.data)
  3789. }
  3790. }.bind(this));
  3791. attModule.attachmentController.clear();
  3792. atts.each(function (att) {
  3793. //if (att.site===this.json.id || (this.json.isOpenInOffice && this.json.officeControlName===att.site)) this.attachmentController.addAttachment(att);
  3794. if ((att.site === attModule.json.id) && att.name!==att_word.name) attModule.attachmentController.addAttachment(att);
  3795. }.bind(this));
  3796. // attModule.attachmentController.reloadAttachments();
  3797. attModule.attachmentController.addAttachment(att_word);
  3798. }
  3799. }
  3800. });