Viewer.js 179 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236
  1. MWF.xApplication.query = MWF.xApplication.query || {};
  2. MWF.xApplication.query.Query = MWF.xApplication.query.Query || {};
  3. MWF.require("MWF.widget.Common", null, false);
  4. MWF.require("o2.widget.Paging", null, false);
  5. MWF.require("MWF.xScript.Macro", null, false);
  6. MWF.xDesktop.requireApp("query.Query", "lp."+o2.language, null, false);
  7. /** @classdesc View 数据中心的视图。本章节的脚本上下文请看<b>{@link module:queryView|queryView}。</b>
  8. * @class
  9. * @o2cn 视图
  10. * @o2category QueryView
  11. * @o2range {QueryView}
  12. * @hideconstructor
  13. * @example
  14. * //在视图的事件中获取该类
  15. * var view = this.target;
  16. * @example
  17. * //在视图的条目中,操作条组件中,分页事件中获取该类
  18. * var view = this.target.view;
  19. * @example
  20. * //调用api进行提示
  21. * this.queryView.notice("this is my information", "info");
  22. * */
  23. MWF.xApplication.query.Query.Viewer = MWF.QViewer = new Class(
  24. /** @lends MWF.xApplication.query.Query.Viewer# */
  25. {
  26. Implements: [Options, Events],
  27. Extends: MWF.widget.Common,
  28. options: {
  29. "style": "default",
  30. "skin" : null,
  31. "resizeNode": true,
  32. "paging" : "scroll",
  33. "perPageCount" : 50,
  34. "isload": "true",
  35. "isloadTitle": true,
  36. "isloadContent": true,
  37. "isloadActionbar": true,
  38. "isloadSearchbar": true,
  39. "export": false,
  40. "lazy": false,
  41. "defaultBundles": [],
  42. "moduleEvents": [
  43. /**
  44. * 加载前触发。可通过this.target获取当前对象。
  45. * @event MWF.xApplication.query.Query.Viewer#queryLoad
  46. */
  47. "queryLoad",
  48. /**
  49. * 视图界面和当前页数据加载后执行。需注意,翻页也会执行本事件。可通过this.target获取当前对象。
  50. * @event MWF.xApplication.query.Query.Viewer#postLoad
  51. */
  52. "postLoad",
  53. /**
  54. * 加载当前页数据后,渲染界面前执行,翻页后也会执行本事件。可通过this.target获取当前对象。
  55. * @event MWF.xApplication.query.Query.Viewer#postLoadPageData
  56. */
  57. "postLoadPageData",
  58. /**
  59. * 渲染当前页内容后执行,翻页后也会执行本事件。可通过this.target获取当前对象。
  60. * @event MWF.xApplication.query.Query.Viewer#postLoadPage
  61. */
  62. "postLoadPage",
  63. /**
  64. * 选择行后执行。可通过this.target获取视图对象,通过this.event获取行对象。
  65. * @event MWF.xApplication.query.Query.Viewer#selectRow
  66. */
  67. "selectRow",
  68. /**
  69. * 取消选择行后执行。可通过this.target获取视图对象,通过this.event获取行对象。
  70. * @event MWF.xApplication.query.Query.Viewer#unselectRow
  71. */
  72. "unselectRow",
  73. /**
  74. * 加载每行之前执行(非分类行)。可通过this.target获取视图对象,通过this.event获取行对象。
  75. * @event MWF.xApplication.query.Query.Viewer#queryLoadItemRow
  76. */
  77. "queryLoadItemRow",
  78. /**
  79. * 加载每行之后执行(非分类行)。可通过this.target获取视图对象,通过this.event获取行对象。
  80. * @event MWF.xApplication.query.Query.Viewer#postLoadItemRow
  81. */
  82. "postLoadItemRow",
  83. /**
  84. * 加载分类行之前执行。可通过this.target获取视图对象,通过this.event获取行对象。
  85. * @event MWF.xApplication.query.Query.Viewer#queryLoadCategoryRow
  86. */
  87. "queryLoadCategoryRow",
  88. /**
  89. * 加载分类行后执行。可通过this.target获取视图对象,通过this.event获取行对象。
  90. * @event MWF.xApplication.query.Query.Viewer#postLoadCategoryRow
  91. */
  92. "postLoadCategoryRow",
  93. /**
  94. * 导出查询Excel的事件,这个时候导出数据已经准备好,this.target可获得查询视图对象。this.event如下:
  95. * <pre><code class='language-js'>{
  96. * headText: headText, //文本,表格头部文本
  97. * headStyle: headStyle, //对象,表格头部样式
  98. * titleStyle: titleStyle, //对象,表格标题样式
  99. * contentStyle: contentStyle, //对象,表格内容样式
  100. * data : data, //对象数组,导出的数据,第一个数组为标题。修改后导出的excel内容也会修改。
  101. * colWidthArray : colWidthArr, //数组,每列的宽度
  102. * title : excelName //字符串,导出的文件名
  103. * }</code></pre>
  104. * @event MWF.xApplication.query.Query.Viewer#export
  105. */
  106. "export",
  107. /**
  108. * 导出查询Excel,产生每行后执行的事件,this.target可获得查询视图对象,可以通过this.event获取下列内容
  109. * <pre><code class='language-js'>{
  110. * data : data, //对象,当前行导出的数据。修改后导出的excel内容也会修改。
  111. * index : 1, //数字,导出的行号,从1开始
  112. * source : source //对象,从后台获取的源数据
  113. * }</code></pre>
  114. * @event MWF.xApplication.query.Query.Viewer#exportRow
  115. */
  116. "exportRow"
  117. ]
  118. // "actions": {
  119. // "lookup": {"uri": "/jaxrs/view/flag/{view}/query/{application}/execute", "method":"PUT"},
  120. // "getView": {"uri": "/jaxrs/view/flag/{view}/query/{application}"}
  121. //
  122. // },
  123. // "actionRoot": "x_query_assemble_surface"
  124. },
  125. initialize: function(container, json, options, app, parentMacro){
  126. //本类有三种事件,
  127. //一种是通过 options 传进来的事件,包括 loadView、openDocument、select、unselect
  128. //一种是用户配置的 事件, 在this.options.moduleEvents 中定义的作为类事件
  129. //还有一种也是用户配置的事件,不在this.options.moduleEvents 中定义的作为 this.node 的DOM事件
  130. this.setOptions(options);
  131. this.path = "../x_component_query_Query/$Viewer/";
  132. this.cssPath = "../x_component_query_Query/$Viewer/"+this.options.style+"/css.wcss";
  133. this._loadCss();
  134. this.lp = MWF.xApplication.query.Query.LP;
  135. this.app = app;
  136. this.container = $(container);
  137. this.json = json;
  138. this.parentMacro = parentMacro;
  139. this.originalJson = Object.clone(json);
  140. /**
  141. * @summary 视图的详细配置信息,比如条目的选择类型等.
  142. * @member {Object}
  143. * @example
  144. * //可以在视图脚本中获取视图基本信息(视图事件中)
  145. * var json = this.target.viewJson; //视图配置信息
  146. * var name = json.selectList; //视图的列配置
  147. * @example
  148. * //可以在视图的组件中获取视图基本信息(在视图的操作条组件中,分页事件中)
  149. * var json = this.target.view.viewJson; //视图配置信息
  150. * var name = json.selectList; //视图的列配置
  151. */
  152. this.viewJson = null;
  153. this.filterItems = [];
  154. this.manualOrderColumnMap = {};
  155. this.searchStatus = "none"; //none, custom, default
  156. /**
  157. * @summary 视图当前页的所有行对象数组.
  158. * @member {Array}
  159. * @example
  160. * //获取视图当前页的所有行对象数组
  161. * var itemList = this.target.items;
  162. */
  163. this.items = [];
  164. /**
  165. * @summary 视图选中行的对象数组.
  166. * @member {Array}
  167. * @example
  168. * //获取视图选中行的对象数组
  169. * var itemList = this.target.selectedItems;
  170. * itemList.each(function(item){
  171. * //取消选中
  172. * item.unSelected()
  173. * })
  174. */
  175. this.selectedItems = [];
  176. this.hideColumns = [];
  177. this.openColumns = [];
  178. this.gridJson = null;
  179. if (this.options.isload){
  180. this.init(function(){
  181. if( this.json.isTitle==="no" )this.options.isloadTitle = false;
  182. this.load();
  183. }.bind(this));
  184. }
  185. },
  186. loadView: function( callback ){
  187. if (this.viewJson){
  188. this.reload( callback );
  189. }else{
  190. this.init(function(){
  191. if( this.json.isTitle==="no" )this.options.isloadTitle = false;
  192. this.load( callback );
  193. }.bind(this));
  194. }
  195. },
  196. init: function(callback){
  197. if (this.json.data){
  198. this.viewJson = JSON.decode(this.json.data);
  199. if (callback) callback();
  200. }else{
  201. this.getView(callback);
  202. }
  203. },
  204. load: function( callback ){
  205. this.loadResource(function () {
  206. this.loadLanguage( function () {
  207. this._loadModuleEvents();
  208. if (this.fireEvent("queryLoad")){
  209. this._loadUserInterface( callback );
  210. //this._loadStyles();
  211. this._loadDomEvents();
  212. }
  213. }.bind(this))
  214. }.bind(this));
  215. },
  216. _loadUserInterface: function( callback ){
  217. this.viewJson = this.bindLP( this.viewJson );
  218. var defaultSelectedScript, selectedAbleScript;
  219. if( typeOf(this.json.defaultSelectedScript) === "function" )defaultSelectedScript = this.json.defaultSelectedScript;
  220. if( typeOf(this.json.selectedAbleScript) === "function" )selectedAbleScript = this.json.selectedAbleScript;
  221. this.json = this.bindLP( this.json );
  222. if(defaultSelectedScript)this.json.defaultSelectedScript = defaultSelectedScript;
  223. if(selectedAbleScript)this.json.selectedAbleScript = selectedAbleScript;
  224. this.loadLayout();
  225. if( this.options.isloadActionbar )this.createActionbarNode();
  226. if( this.options.isloadSearchbar )this.createSearchNode();
  227. this.createViewNode({"filterList": this.json.filter ? this.json.filter.clone() : null}, callback);
  228. if (this.options.resizeNode){
  229. this.setContentHeightFun = this.setContentHeight.bind(this);
  230. this.container.addEvent("resize", this.setContentHeightFun);
  231. this.setContentHeightFun();
  232. }
  233. },
  234. loadLayout: function(){
  235. /**
  236. * @summary 视图的节点,mootools封装过的Dom对象,可以直接使用原生的js和moootools方法访问和操作该对象。
  237. * @see https://mootools.net/core/docs/1.6.0/Element/Element
  238. * @member {Element}
  239. * @example
  240. * //可以在视图脚本中获取视图的Dom
  241. * var node = this.target.node;
  242. * @example
  243. * //可以在视图的组件中获取视图的Dom(在视图的操作条组件中,分页事件中)
  244. * var node = this.target.view.node;
  245. */
  246. this.node = new Element("div", {"styles": this.css.node}).inject(this.container);
  247. /**
  248. * @summary 操作组件容器
  249. * @member {Element}
  250. */
  251. this.actionbarAreaNode = new Element("div.actionbarAreaNode", {"styles": this.css.actionbarAreaNode}).inject(this.node);
  252. //if (this.options.export) this.exportAreaNode = new Element("div", {"styles": this.css.exportAreaNode}).inject(this.node);
  253. /**
  254. * @summary 搜索界面容器
  255. * @member {Element}
  256. */
  257. this.searchAreaNode = new Element("div", {"styles": this.css.searchAreaNode}).inject(this.node);
  258. /**
  259. * @summary 表头和条目容器,
  260. * @member {Element}
  261. */
  262. this.viewAreaNode = new Element("div", {"styles": this.css.viewAreaNode}).inject(this.node);
  263. // this.viewPageNode = new Element("div", {"styles": this.css.viewPageNode}).inject(this.node);
  264. /**
  265. * @summary 分页组件容器,
  266. * @member {Element}
  267. */
  268. this.viewPageAreaNode = new Element("div", {"styles": this.css.viewPageAreaNode}).inject(this.node);
  269. this.fireEvent("loadLayout");
  270. },
  271. loadResource: function( callback ){
  272. if( this.options.lazy ){
  273. var loadedIOResource = false;
  274. var callback2 = function(){
  275. if( this.Macro && loadedIOResource )callback();
  276. }.bind(this)
  277. this.loadMacro( callback2 );
  278. this.loadIOResource( function(){
  279. loadedIOResource = true;
  280. callback2();
  281. }.bind(this));
  282. }else{
  283. this.loadMacro( callback );
  284. }
  285. },
  286. loadMacro: function (callback) {
  287. MWF.require("MWF.xScript.Macro", function () {
  288. this.Macro = new MWF.Macro.ViewContext(this);
  289. if (callback) callback();
  290. }.bind(this));
  291. },
  292. loadLanguage: function(callback){
  293. if (this.viewJson.languageType!=="script"){
  294. if (callback) callback();
  295. return true;
  296. }
  297. var language = MWF.xApplication.query.Query.LP.form;
  298. var languageJson = null;
  299. if (this.viewJson.languageType=="script"){
  300. if (this.viewJson.languageScript ){
  301. languageJson = this.Macro.exec(this.viewJson.languageScript, this);
  302. }
  303. }
  304. if (languageJson){
  305. if (languageJson.then && o2.typeOf(languageJson.then)=="function"){
  306. languageJson.then(function(json) {
  307. if (!json.data){
  308. var o = Object.clone(json);
  309. json.data = o;
  310. }
  311. MWF.xApplication.query.Query.LP.form = Object.merge(MWF.xApplication.query.Query.LP.form, json);
  312. if (callback) callback(true);
  313. }, function(){
  314. if (callback) callback(true);
  315. })
  316. }else{
  317. MWF.xApplication.query.Query.LP.form = Object.merge(MWF.xApplication.query.Query.LP.form, languageJson);
  318. if (callback) callback(true);
  319. }
  320. }else{
  321. if (callback) callback(true);
  322. }
  323. },
  324. setContentHeight: function(){
  325. var size;
  326. if( !this.node.offsetParent === null ){
  327. size = this.node.getStyle("height");
  328. }else{
  329. size = this.node.getSize()
  330. }
  331. var searchSize = this.searchAreaNode.getComputedSize();
  332. var h = size.y-searchSize.totalHeight;
  333. //if (this.exportAreaNode){
  334. // var exportSize = this.exportAreaNode.getComputedSize();
  335. // h = h-exportSize.totalHeight;
  336. //}
  337. if( this.actionbarAreaNode ){
  338. var exportSize = this.actionbarAreaNode.getComputedSize();
  339. h = h-exportSize.totalHeight;
  340. }
  341. var pageSize = this.viewPageAreaNode.getComputedSize();
  342. h = h-pageSize.totalHeight;
  343. var paddingTop = (this.viewAreaNode.getStyle("padding-top") || "0").toInt();
  344. var paddingBottom = (this.viewAreaNode.getStyle("padding-bottom") || "0").toInt();
  345. h = h - paddingTop - paddingBottom;
  346. this.viewAreaNode.setStyle("height", ""+h+"px");
  347. },
  348. createLoadding: function(){
  349. this.loadingAreaNode = new Element("div", {"styles": this.css.viewLoadingAreaNode}).inject(this.contentAreaNode);
  350. new Element("div", {"styles": {"height": "5px"}}).inject(this.loadingAreaNode);
  351. var loadingNode = new Element("div", {"styles": this.css.viewLoadingNode}).inject(this.loadingAreaNode);
  352. new Element("div", {"styles": this.css.viewLoadingIconNode}).inject(loadingNode);
  353. var loadingTextNode = new Element("div", {"styles": this.css.viewLoadingTextNode}).inject(loadingNode);
  354. loadingTextNode.set("text", "loading...");
  355. },
  356. createActionbarNode : function(){
  357. this.actionbarAreaNode.empty();
  358. if( typeOf(this.json.showActionbar) === "boolean" && this.json.showActionbar !== true )return;
  359. if( typeOf( this.viewJson.actionbarHidden ) === "boolean" ){
  360. if( this.viewJson.actionbarHidden === true || !this.viewJson.actionbarList || !this.viewJson.actionbarList.length )return;
  361. /**
  362. * @summary 视图的操作条对象.
  363. * @member {Object}
  364. * @example
  365. * var actionbar = this.target.actionbar;
  366. */
  367. this.actionbar = new MWF.xApplication.query.Query.Viewer.Actionbar(this.actionbarAreaNode, this.viewJson.actionbarList[0], this, {});
  368. this.actionbar.load();
  369. }else{ //兼容以前的ExportNode
  370. this.createExportNode();
  371. }
  372. },
  373. createViewNode: function(data, callback){
  374. this.viewAreaNode.empty();
  375. this.selectedItems = [];
  376. var viewStyles = this.viewJson.viewStyles;
  377. this.contentAreaNode = new Element("div", {"styles":
  378. (viewStyles && viewStyles["container"]) ? viewStyles["container"] : this.css.contentAreaNode
  379. }).inject(this.viewAreaNode);
  380. this.loadObserver();
  381. this.viewTable = new Element("table", {
  382. "styles": this.css.viewTitleTableNode,
  383. "border": "0px",
  384. "cellPadding": "0",
  385. "cellSpacing": "0"
  386. }).inject(this.contentAreaNode);
  387. if( viewStyles ){
  388. if( viewStyles["tableProperties"] )this.viewTable.set(viewStyles["tableProperties"]);
  389. if( viewStyles["table"] )this.viewTable.setStyles(viewStyles["table"]);
  390. }
  391. if( this.options.isloadContent )this.createLoadding();
  392. var viewTitleCellNode = (viewStyles && viewStyles["titleTd"]) ? viewStyles["titleTd"] : this.css.viewTitleCellNode;
  393. if (this.options.isloadTitle){
  394. this.viewTitleLine = new Element("tr.viewTitleLine", {
  395. "styles": (viewStyles && viewStyles["titleTr"]) ? viewStyles["titleTr"] : this.css.viewTitleLineNode
  396. }).inject(this.viewTable);
  397. //if (this.json.select==="single" || this.json.select==="multi") {
  398. this.selectTitleCell = new Element("td.selectTitleCell", {
  399. "styles": viewTitleCellNode
  400. }).inject(this.viewTitleLine);
  401. this.selectTitleCell.setStyle("width", "10px");
  402. if (this.json.titleStyles) this.selectTitleCell.setStyles(this.json.titleStyles);
  403. //}
  404. if( this.isSelectTdHidden() ){
  405. this.selectTitleCell.hide();
  406. }
  407. if( this.getSelectFlag( true ) !== "multi" || !this.viewJson.allowSelectAll ){
  408. this.expandTitleCell = this.selectTitleCell;
  409. }
  410. //序号
  411. if (this.viewJson.isSequence==="yes"){
  412. this.sequenceTitleCell = new Element("td", {
  413. "styles": viewTitleCellNode,
  414. "text": this.lp.sequence
  415. }).inject(this.viewTitleLine);
  416. this.sequenceTitleCell.setStyles({
  417. "width": "30px",
  418. "text-align": "center"
  419. });
  420. if (this.json.titleStyles) this.sequenceTitleCell.setStyles(this.json.titleStyles);
  421. if( !this.expandTitleCell )this.expandTitleCell = this.sequenceTitleCell;
  422. }
  423. this.entries = {};
  424. this.viewJson.selectList.each(function(column, index){
  425. this.entries[column.column] = column;
  426. if (!column.hideColumn){
  427. var viewCell = new Element("td", {
  428. "styles": viewTitleCellNode
  429. }).inject(this.viewTitleLine);
  430. var textNode = new Element("div", {
  431. "styles": this.css.viewTitleTextNode,
  432. "text": column.displayName
  433. }).inject(viewCell);
  434. var size = MWF.getTextSize(column.displayName, viewTitleCellNode);
  435. if( column.isSwitchOrder ){
  436. size.x += 24;
  437. }
  438. viewCell.setStyle("min-width", ""+size.x+"px");
  439. if (this.json.titleStyles) viewCell.setStyles(this.json.titleStyles);
  440. if( column.groupEntry && !this.expandTitleCell )this.expandTitleCell = viewCell;
  441. if( typeOf(column.titleStyles) === "object" )viewCell.setStyles(column.titleStyles);
  442. if( typeOf(column.titleProperties) === "object" )viewCell.setProperties(column.titleProperties);
  443. if( column.events && column.events.loadTitle && column.events.loadTitle.code ){
  444. var code = column.events.loadTitle.code;
  445. this.Macro.fire( code, {"node" : viewCell, "json" : column, "data" : column.displayName, "view" : this});
  446. }
  447. if( column.isSwitchOrder || this.isSortedType(column.orderType) ){
  448. var sortNode = new Element("div", {
  449. styles: this.css.viewTitleOrderNode
  450. }).inject(textNode);
  451. new Element("div.o2-up.ooicon-icon_arrow_up").inject(sortNode);
  452. new Element("div.o2-down.ooicon-drop_down").inject(sortNode);
  453. var _self = this;
  454. if( column.isSwitchOrder ){
  455. textNode.addEvent('click', function(){
  456. _self.switchOrder(this.sortNode, this.column, this.index);
  457. }.bind({ sortNode: sortNode, column: column, index: index }));
  458. }else{
  459. sortNode.setStyle("cursor", "not-allowed");
  460. }
  461. this.setOrderStyle(column, sortNode);
  462. }
  463. }else{
  464. this.hideColumns.push(column.column);
  465. }
  466. if (column.allowOpen) this.openColumns.push(column.column);
  467. }.bind(this));
  468. if( this.options.isloadContent )this.lookup(data, callback);
  469. }else{
  470. this.entries = {};
  471. this.viewJson.selectList.each(function(column){
  472. this.entries[column.column] = column;
  473. if (column.hideColumn) this.hideColumns.push(column.column);
  474. if (column.allowOpen) this.openColumns.push(column.column);
  475. }.bind(this));
  476. if( this.options.isloadContent )this.lookup(data, callback);
  477. }
  478. },
  479. switchOrder: function (node, column){
  480. var map = this.manualOrderColumnMap;
  481. var clearOtherOrder = function (){
  482. this.viewJson.selectList.each(function(c, index){
  483. if( c.column === column.column )return;
  484. if( map.hasOwnProperty(c.column) ){
  485. map[c.column] = "";
  486. }else if(this.isSortedType(c.orderType)){
  487. map[c.column] = "";
  488. }
  489. }.bind(this));
  490. }.bind(this);
  491. var restoreOtherOrder = function (){
  492. this.viewJson.selectList.each(function(c, index){
  493. if( c.column === column.column )return;
  494. if( map.hasOwnProperty(c.column) && this.isSortedType(c.orderType) ){
  495. delete map[c.column];
  496. }
  497. }.bind(this));
  498. }.bind(this);
  499. switch ( this.getOrderType(column) ){
  500. case 'asc':
  501. map[column.column] = 'desc';
  502. if(column.orderByCurrent)clearOtherOrder();
  503. break;
  504. case 'desc':
  505. map[column.column] = '';
  506. if(column.orderByCurrent)restoreOtherOrder();
  507. break;
  508. default:
  509. map[column.column] = 'asc';
  510. if(column.orderByCurrent)clearOtherOrder();
  511. break;
  512. }
  513. this.createViewNode(this.requestBody);
  514. // this.setOrderStyle(column, node);
  515. },
  516. getOrderType: function (column){
  517. var orderType;
  518. if( this.manualOrderColumnMap.hasOwnProperty(column.column) ){
  519. orderType = this.manualOrderColumnMap[column.column];
  520. }else{
  521. if( this.isSortedType(column.orderType) ){
  522. orderType = column.orderType;
  523. }
  524. }
  525. return orderType;
  526. },
  527. setOrderStyle: function (column, node){
  528. var upNode = node.getElement('.o2-up');
  529. var downNode = node.getElement('.o2-down');
  530. var orderType = this.getOrderType(column);
  531. if( !column.isSwitchOrder ){
  532. switch (orderType){
  533. case 'asc':
  534. downNode.hide(); break;
  535. case 'desc':
  536. upNode.hide(); break;
  537. default:
  538. upNode.hide();
  539. downNode.hide();
  540. break;
  541. }
  542. }
  543. switch (orderType){
  544. case 'asc':
  545. upNode.addClass('mainColor_color');
  546. downNode.removeClass('mainColor_color');
  547. break;
  548. case 'desc':
  549. upNode.removeClass('mainColor_color');
  550. downNode.addClass('mainColor_color');
  551. break;
  552. default:
  553. upNode.removeClass('mainColor_color');
  554. downNode.removeClass('mainColor_color');
  555. break;
  556. }
  557. },
  558. getExpandFlag : function(){
  559. if( this.options && this.options.isExpand )return this.options.isExpand;
  560. if( this.json && this.json.isExpand )return this.json.isExpand;
  561. if( this.viewJson && this.viewJson.isExpand )return this.viewJson.isExpand;
  562. return "no";
  563. },
  564. getSelectFlag : function( ignoreSelectEnable ){
  565. if( !ignoreSelectEnable && !this.viewSelectedEnable )return "none";
  566. if( this.options && this.options.select )return this.options.select;
  567. if( this.json && this.json.select )return this.json.select;
  568. if( this.viewJson && this.viewJson.select )return this.viewJson.select;
  569. // if( this.json.select === "single" || this.json.select === "multi" )return this.json.select;
  570. // if( this.viewJson.select === "single" || this.viewJson.select === "multi" )return this.viewJson.select;
  571. // if( this.options.select === "single" || this.options.select === "multi" )return this.options.select;
  572. return "none";
  573. },
  574. isSelectTdHidden :function(){
  575. if( !this.viewJson.firstTdHidden ){
  576. return false;
  577. }
  578. if( this.viewJson.group && this.viewJson.group.column ){
  579. return false;
  580. }
  581. if( this.json.defaultSelectedScript || this.viewJson.defaultSelectedScript ){
  582. return false;
  583. }
  584. // if( !this.viewSelectedEnable ){
  585. // return true;
  586. // }
  587. if( this.options && this.options.select ){
  588. return this.options.select === "none" || this.options.select === "no";
  589. }
  590. if( this.json && this.json.select ){
  591. return this.json.select === "none" || this.json.select === "no";
  592. }
  593. if( this.viewJson && this.viewJson.select ){
  594. return this.viewJson.select === "none" || this.viewJson.select === "no";
  595. }
  596. return true;
  597. // if( this.json.select === "single" || this.json.select === "multi" || this.json.defaultSelectedScript || this.viewJson.defaultSelectedScript ){
  598. // return false;
  599. // }
  600. // if( this.options.select === "single" || this.options.select === "multi" ){
  601. // return false;
  602. // }
  603. // if( this.viewJson.select === "single" || this.viewJson.select === "multi" ){
  604. // return false;
  605. // }
  606. // if( this.viewJson.group && this.viewJson.group.column ){
  607. // return false;
  608. // }
  609. // return true;
  610. },
  611. // _loadPageCountNode: function(){
  612. // this.viewPageContentNode.empty();
  613. //
  614. // var size = this.viewPageAreaNode.getSize();
  615. // var w1 = this.viewPageFirstNode.getSize().x*2;
  616. // var w2 = this.viewPageContentNode.getStyle("margin-left").toInt();
  617. // var w = size.x-w1-w2;
  618. //
  619. // var bw = this.css.viewPageButtonNode.width.toInt()+this.css.viewPageButtonNode["margin-right"].toInt();
  620. // var count = (w/bw).toInt()-2;
  621. // if (count>10) count = 10;
  622. // this.showPageCount = Math.min(count, this.pages);
  623. //
  624. // var tmp = this.showPageCount/2;
  625. // var n = tmp.toInt();
  626. // var left = this.currentPage-n;
  627. // if (left<=0) left = 1;
  628. // var right = this.showPageCount + left-1;
  629. // if (right>this.pages) right = this.pages;
  630. // left = right-this.showPageCount+1;
  631. // if (left<=1) left = 1;
  632. //
  633. // this.viewPagePrevNode = new Element("div", {"styles": this.css.viewPagePrevButtonNode}).inject(this.viewPageContentNode);
  634. // this.loadPageButtonEvent(this.viewPagePrevNode, "viewPagePrevButtonNode_over", "viewPagePrevButtonNode_up", "viewPagePrevButtonNode_down", function(){
  635. // if (this.currentPage>1) this.currentPage--;
  636. // this.loadCurrentPageData();
  637. // }.bind(this));
  638. //
  639. // for (i=left; i<=right; i++){
  640. // var node = new Element("div", {"styles": this.css.viewPageButtonNode, "text": i}).inject(this.viewPageContentNode);
  641. // if (i==this.currentPage){
  642. // node.setStyles(this.css.viewPageButtonNode_current);
  643. // }else{
  644. // this.loadPageButtonEvent(node, "viewPageButtonNode_over", "viewPageButtonNode_up", "viewPageButtonNode_down", function(e){
  645. // this.currentPage = e.target.get("text").toInt();
  646. // this.loadCurrentPageData();
  647. // }.bind(this));
  648. // }
  649. // }
  650. // this.viewPageNextNode = new Element("div", {"styles": this.css.viewPageNextButtonNode}).inject(this.viewPageContentNode);
  651. // this.loadPageButtonEvent(this.viewPageNextNode, "viewPageNextButtonNode_over", "viewPageNextButtonNode_up", "viewPageNextButtonNode_down", function(){
  652. // if (this.currentPage<=this.pages-1) this.currentPage++;
  653. // this.loadCurrentPageData();
  654. // }.bind(this));
  655. // },
  656. // loadPageButtonEvent: function(node, over, out, down, click){
  657. // node.addEvents({
  658. // "mouseover": function(){node.setStyles(this.css[over])}.bind(this),
  659. // "mouseout": function(){node.setStyles(this.css[out])}.bind(this),
  660. // "mousedown": function(){node.setStyles(this.css[down])}.bind(this),
  661. // "mouseup": function(){node.setStyles(this.css[out])}.bind(this),
  662. // "click": click
  663. // });
  664. // },
  665. // _loadPageNode: function(){
  666. // this.viewPageAreaNode.empty();
  667. // this.viewPageFirstNode = new Element("div", {"styles": this.css.viewPageFirstLastNode, "text": this.lp.firstPage}).inject(this.viewPageAreaNode);
  668. // this.viewPageContentNode = new Element("div", {"styles": this.css.viewPageContentNode}).inject(this.viewPageAreaNode);
  669. // this.viewPageLastNode = new Element("div", {"styles": this.css.viewPageFirstLastNode, "text": this.lp.lastPage}).inject(this.viewPageAreaNode);
  670. // this._loadPageCountNode();
  671. //
  672. // this.loadPageButtonEvent(this.viewPageFirstNode, "viewPageFirstLastNode_over", "viewPageFirstLastNode_up", "viewPageFirstLastNode_down", function(){
  673. // this.currentPage = 1;
  674. // this.loadCurrentPageData();
  675. // }.bind(this));
  676. // this.loadPageButtonEvent(this.viewPageLastNode, "viewPageFirstLastNode_over", "viewPageFirstLastNode_up", "viewPageFirstLastNode_down", function(){
  677. // this.currentPage = this.pages;
  678. // this.loadCurrentPageData();
  679. // }.bind(this));
  680. // },
  681. _loadPageNode : function(){
  682. this.viewPageAreaNode.empty();
  683. if( this.viewJson.pagingbarHidden === true ){
  684. return;
  685. }
  686. if( !this.paging ){
  687. var json;
  688. if( !this.viewJson.pagingList || !this.viewJson.pagingList.length ){
  689. json = {
  690. "firstPageText": this.lp.firstPage,
  691. "lastPageText": this.lp.lastPage
  692. };
  693. }else{
  694. json = this.viewJson.pagingList[0];
  695. // var jsonStr = JSON.stringify(json);
  696. // jsonStr = o2.bindJson(jsonStr, {"lp": MWF.xApplication.query.Query.LP.form});
  697. // json = JSON.parse(jsonStr);
  698. }
  699. /**
  700. * @summary 视图的分页组件对象.
  701. * @member {Object}
  702. * @example
  703. * var paging = this.target.paging;
  704. */
  705. this.paging = new MWF.xApplication.query.Query.Viewer.Paging(this.viewPageAreaNode, json, this, {});
  706. this.paging.load();
  707. }else{
  708. this.paging.reload();
  709. }
  710. },
  711. _initPage: function(){
  712. this.count = this.bundleItems.length;
  713. var i = this.count/this.json.pageSize;
  714. this.pages = (i.toInt()<i) ? i.toInt()+1 : i;
  715. this.currentPage = this.options.defaultPage || 1;
  716. this.options.defaultPage = null;
  717. this.exportExcelStart = null;
  718. this.exportExcelEnd = null;
  719. },
  720. isSortedType: function(value){
  721. return ['asc', 'desc'].contains(value);
  722. },
  723. setOrderList: function (d){
  724. var map = this.manualOrderColumnMap;
  725. if( Object.keys(map).length === 0 ){
  726. delete d.orderList;
  727. return;
  728. }
  729. var orderList = [];
  730. this.viewJson.selectList.each(function(column, index){
  731. if( map.hasOwnProperty(column.column) ){
  732. var orderType = map[column.column];
  733. if( this.isSortedType(orderType) ){
  734. var c = Object.clone(column);
  735. c.orderType = orderType;
  736. orderList.push(c);
  737. }
  738. }else{
  739. this.isSortedType(column.orderType) && orderList.push(Object.clone(column));
  740. }
  741. }.bind(this));
  742. d.orderList = orderList;
  743. },
  744. lookup: function(data, callback){
  745. if( this.lookuping )return;
  746. this.lookuping = true;
  747. this.getLookupAction(function(){
  748. if (this.json.application){
  749. var d = data || {};
  750. d.count = this.json.count;
  751. this.requestBody = data;
  752. this.setOrderList(d);
  753. this.lookupAction.bundleView(this.json.id, d, function(json){
  754. this.bundleItems = json.data.valueList;
  755. this.bundleKey = json.data.key;
  756. this._initPage();
  757. if (this.bundleItems.length){
  758. if( this.noDataTextNode )this.noDataTextNode.destroy();
  759. if( this.options.defaultBundles.length && !this.isDefaultDataLoaded ){
  760. this.loadDefaultData(function () {
  761. this.loadCurrentPageData( function () {
  762. this.fireEvent("postLoad"); //用户配置的事件
  763. this.lookuping = false;
  764. if(callback)callback(this);
  765. }.bind(this));
  766. }.bind(this))
  767. }else{
  768. this.loadCurrentPageData( function () {
  769. this.fireEvent("postLoad"); //用户配置的事件
  770. this.lookuping = false;
  771. if(callback)callback(this);
  772. }.bind(this));
  773. }
  774. }else{
  775. //this._loadPageNode();
  776. this.viewPageAreaNode.empty();
  777. if( this.viewJson.noDataText ){
  778. var noDataTextNodeStyle = this.css.noDataTextNode;
  779. if( this.viewJson.viewStyles && this.viewJson.viewStyles["noDataTextNode"] ){
  780. noDataTextNodeStyle = this.viewJson.viewStyles["noDataTextNode"];
  781. }
  782. this.noDataTextNode = new Element( "div", {
  783. "styles": noDataTextNodeStyle,
  784. "text" : this.viewJson.noDataText
  785. }).inject( this.contentAreaNode );
  786. }
  787. if (this.loadingAreaNode){
  788. this.loadingAreaNode.destroy();
  789. this.loadingAreaNode = null;
  790. }
  791. this.fireEvent("loadView"); //options 传入的事件
  792. this.fireEvent("postLoad"); //用户配置的事件
  793. this.lookuping = false;
  794. if(callback)callback(this);
  795. }
  796. }.bind(this));
  797. }
  798. }.bind(this));
  799. },
  800. loadDefaultData: function( callback ){
  801. var d = {};
  802. d.bundleList = this.options.defaultBundles;
  803. d.key = this.bundleKey;
  804. this.lookupAction.loadView(this.json.name, this.json.application, d, function(json){
  805. var resultJson, viewData = json.data;
  806. if (this.viewJson.group.column){
  807. resultJson = [];
  808. json.data.groupGrid.each(function (g) {
  809. resultJson = resultJson.concat( g.list );
  810. })
  811. }else{
  812. resultJson = json.data.grid;
  813. }
  814. resultJson.each(function (data) {
  815. this.selectedItems.push({
  816. data: data
  817. })
  818. }.bind(this));
  819. this.isDefaultDataLoaded = true;
  820. if(callback)callback();
  821. }.bind(this), function () {
  822. this.isDefaultDataLoaded = true;
  823. if(callback)callback();
  824. }, true );
  825. },
  826. loadCurrentPageData: function( callback, async ){
  827. //是否需要在翻页的时候清空之前的items ?
  828. if( this.pageloading )return;
  829. this.pageloading = true;
  830. if( this.io ){
  831. this.items.each(function(item){
  832. this.io.unobserve(item.node);
  833. }.bind(this))
  834. }
  835. this.items = [];
  836. var p = this.currentPage;
  837. var d = {};
  838. var valueList = this.bundleItems.slice((p-1)*this.json.pageSize,this.json.pageSize*p);
  839. d.bundleList = valueList;
  840. d.key = this.bundleKey;
  841. this.setOrderList(d);
  842. while (this.viewTable.rows.length>1){
  843. this.viewTable.deleteRow(-1);
  844. }
  845. if( this.viewTable.rows.length>0 && !this.viewTable.rows[0].hasClass("viewTitleLine") ){
  846. this.viewTable.deleteRow(0);
  847. }
  848. this.contentAreaNode.scrollTo(0, 0);
  849. //this.createLoadding();
  850. this.loadViewRes = this.lookupAction.loadView(this.json.name, this.json.application, d, function(json){
  851. this.viewData = json.data;
  852. this.fireEvent("postLoadPageData");
  853. if (this.viewJson.group.column){
  854. this.gridJson = json.data.groupGrid;
  855. this.setSelectedableFlag();
  856. this.loadGroupData();
  857. }else{
  858. this.gridJson = json.data.grid;
  859. this.setSelectedableFlag();
  860. this.loadData();
  861. }
  862. if (this.gridJson.length) this._loadPageNode();
  863. if (this.loadingAreaNode){
  864. this.loadingAreaNode.destroy();
  865. this.loadingAreaNode = null;
  866. }
  867. this.pageloading = false;
  868. this.fireEvent("loadView"); //options 传入的事件
  869. this.fireEvent("postLoadPage");
  870. if(callback)callback();
  871. }.bind(this), null, async === false ? false : true );
  872. },
  873. showAssociatedDocumentResult: function(failureList, successList){
  874. var fL = [];
  875. failureList.each(function( f ){
  876. if( f.properties.view === this.json.id )fL.push( f.targetBundle );
  877. }.bind(this));
  878. var sl = [];
  879. successList.each(function( f ){
  880. if( f.properties.view === this.json.id )sl.push( f.targetBundle );
  881. }.bind(this));
  882. var d = {};
  883. d.bundleList = fL.concat( sl );
  884. d.key = this.bundleKey;
  885. if( d.bundleList.length ){
  886. this.lookupAction.loadView(this.json.name, this.json.application, d, function(json){
  887. var resultJson, viewData = json.data;
  888. if (this.viewJson.group.column){
  889. resultJson = [];
  890. json.data.groupGrid.each(function (g) {
  891. resultJson = resultJson.concat( g.list );
  892. })
  893. }else{
  894. resultJson = json.data.grid;
  895. }
  896. this._showAssociatedDocumentResult( resultJson, failureList, successList );
  897. }.bind(this), null, true );
  898. }else{
  899. this._showAssociatedDocumentResult( [], failureList, successList );
  900. }
  901. },
  902. _showAssociatedDocumentResult: function(resultJson, failureList, successList){
  903. this.entries.$result = {
  904. "id": "$result",
  905. "column": "$result",
  906. "events": {},
  907. "allowOpen": false,
  908. "numberOrder": false,
  909. "groupEntry": false,
  910. "hideColumn": false,
  911. "isName": false,
  912. "isHtml": false,
  913. "path": "$result"
  914. };
  915. var viewStyles = this.viewJson.viewStyles;
  916. if (this.options.isloadTitle && this.selectTitleCell){
  917. //if (this.json.select==="single" || this.json.select==="multi") {
  918. var titleCell = new Element("td.titleCell", {
  919. "styles": (viewStyles && viewStyles["titleTd"]) ? viewStyles["titleTd"] : this.css.viewTitleCellNode,
  920. "text": this.lp.associationResult
  921. }).inject(this.viewTitleLine);
  922. if (this.json.titleStyles) titleCell.setStyles(this.json.titleStyles);
  923. }
  924. if(this.expandAllNode){
  925. this.expandAllNode.hide();
  926. }
  927. while (this.viewTable.rows.length>1){
  928. this.viewTable.deleteRow(-1);
  929. }
  930. if( this.viewTable.rows.length>0 && !this.viewTable.rows[0].hasClass("viewTitleLine") ){
  931. this.viewTable.deleteRow(0);
  932. }
  933. this.contentAreaNode.scrollTo(0, 0);
  934. this.gridJson = resultJson.map(function (item) {
  935. var flag = true;
  936. if( !item.data )item.data = {};
  937. failureList.each(function (d) {
  938. if( item.bundle === d.bundle ){
  939. item.$failure = true;
  940. item.data.$result = d.$result || this.lp.noPermission;
  941. flag = false;
  942. }
  943. }.bind(this));
  944. if( flag ){
  945. item.data.$result = this.lp.associationSuccess;
  946. }
  947. item.$selectedEnable = false;
  948. return item;
  949. }.bind(this));
  950. //if( this.paging )this.paging.hide();
  951. if(this.actionbarAreaNode)this.actionbarAreaNode.hide();
  952. if(this.searchAreaNode)this.searchAreaNode.hide();
  953. if(this.viewPageAreaNode)this.viewPageAreaNode.hide();
  954. //this.selectedItems = [];
  955. if(this.selectAllNode){
  956. this.clearSelectAllStyle();
  957. }
  958. if (this.gridJson.length){
  959. this.gridJson.each(function(line, i){
  960. new MWF.xApplication.query.Query.Viewer.AssociatedResultItem(this, line, null, i, null, false);
  961. }.bind(this));
  962. }else{
  963. if (this.viewPageAreaNode) this.viewPageAreaNode.empty();
  964. }
  965. },
  966. setSelectedableFlag : function(){
  967. this.viewSelectedEnable = false;
  968. var selectedAbleScript = this.json.selectedAbleScript || this.viewJson.selectedAbleScript;
  969. if (this.viewJson.group.column){
  970. this.gridJson.each( function( d ){
  971. d.list.each( function( v ){
  972. switch (typeOf(selectedAbleScript)) {
  973. case "string":
  974. if( selectedAbleScript ){
  975. v.$selectedEnable = this.Macro.exec( selectedAbleScript, { "data" : v, "groupData" : d ,"view": this });
  976. }else{
  977. v.$selectedEnable = true;
  978. }
  979. break;
  980. case "function":
  981. v.$selectedEnable = selectedAbleScript({ "data" : v, "groupData" : d ,"view": this });
  982. break;
  983. default:
  984. v.$selectedEnable = true;
  985. }
  986. if( v.$selectedEnable ){
  987. d.$selectedEnable = true;
  988. this.viewSelectedEnable = true;
  989. }
  990. }.bind(this))
  991. }.bind(this))
  992. }else{
  993. this.gridJson.each( function( v ){
  994. switch (typeOf(selectedAbleScript)) {
  995. case "string":
  996. if( selectedAbleScript ){
  997. v.$selectedEnable = this.Macro.exec( selectedAbleScript, { "data" : v, "view": this });
  998. }else{
  999. v.$selectedEnable = true;
  1000. }
  1001. break;
  1002. case "function":
  1003. v.$selectedEnable = selectedAbleScript({ "data" : v, "view": this });
  1004. break;
  1005. default:
  1006. v.$selectedEnable = true;
  1007. }
  1008. if( v.$selectedEnable )this.viewSelectedEnable = true;
  1009. }.bind(this))
  1010. }
  1011. },
  1012. getMode: function(){
  1013. return this.viewJson.group.column ? "group" : "item";
  1014. },
  1015. createSelectAllNode: function(){
  1016. if( this.getSelectFlag() === "multi" && this.viewJson.allowSelectAll ){
  1017. if (this.selectTitleCell && !this.selectTitleCell.retrieve("selectAllLoaded") ){
  1018. if( this.viewJson.viewStyles && this.viewJson.viewStyles["checkboxNode"] ){
  1019. this.selectAllNode = this.selectTitleCell;
  1020. this.selectAllNode.setStyles( this.viewJson.viewStyles["checkboxNode"] );
  1021. // this.selectAllNode = new Element("div", {
  1022. // styles : this.viewJson.viewStyles["checkboxNode"]
  1023. // }).inject( this.selectTitleCell );
  1024. }else{
  1025. this.selectAllNode.html( "<img src='../x_component_query_Query/$Viewer/"+this.options.style+"/icon/checkbox.png'/>"+"</span>" )
  1026. // this.selectAllNode = new Element("div",{
  1027. // html : "<img src='../x_component_query_Query/$Viewer/"+this.options.style+"/icon/checkbox.png'/>"+"</span>",
  1028. // style : "font-family: Webdings"
  1029. // }).inject( this.selectTitleCell );
  1030. }
  1031. this.selectTitleCell.setStyle("cursor", "pointer");
  1032. this.selectTitleCell.addEvent("click", function () {
  1033. if( this.getSelectAllStatus() === "all" ){
  1034. this.unSelectAll("view")
  1035. }else{
  1036. this.selectAll("view");
  1037. }
  1038. }.bind(this));
  1039. this.selectTitleCell.store("selectAllLoaded", true);
  1040. }
  1041. }
  1042. },
  1043. loadData: function(){
  1044. if( this.getSelectFlag() === "multi" && this.viewJson.allowSelectAll ) {
  1045. if(this.selectTitleCell && this.selectTitleCell.retrieve("selectAllLoaded")){
  1046. this.setUnSelectAllStyle();
  1047. }else{
  1048. this.createSelectAllNode();
  1049. }
  1050. }else if(this.selectAllNode){
  1051. this.clearSelectAllStyle();
  1052. }
  1053. if (this.gridJson.length){
  1054. // if( !this.options.paging ){
  1055. this.gridJson.each(function(line, i){
  1056. this.items.push(new MWF.xApplication.query.Query.Viewer.Item(this, line, null, i, null, this.options.lazy));
  1057. }.bind(this));
  1058. // }else{
  1059. // this.loadPaging();
  1060. // }
  1061. }else{
  1062. if (this.viewPageAreaNode) this.viewPageAreaNode.empty();
  1063. }
  1064. },
  1065. loadPaging : function(){
  1066. this.isItemsLoading = false;
  1067. this.pageNumber = 0;
  1068. this.isItemsLoaded = false;
  1069. this.isSetedScroll = false;
  1070. this.setScroll();
  1071. this.loadDataByPaging()
  1072. },
  1073. setScroll : function(){
  1074. if( this.options.paging && !this.isSetedScroll ){
  1075. this.contentAreaNode.setStyle("overflow","auto");
  1076. this.scrollContainerFun = function(){
  1077. var scrollSize = this.contentAreaNode.getScrollSize();
  1078. var clientSize = this.contentAreaNode.getSize();
  1079. var scrollHeight = scrollSize.y - clientSize.y;
  1080. //alert( "clientSize.y=" + clientSize.y + " scrollSize.y="+scrollSize.y + " this.contentAreaNode.scrollTop="+this.contentAreaNode.scrollTop);
  1081. if (this.contentAreaNode.scrollTop + 150 > scrollHeight ) {
  1082. if (!this.isItemsLoaded) this.loadDataByPaging();
  1083. }
  1084. }.bind(this);
  1085. this.isSetedScroll = true;
  1086. this.contentAreaNode.addEvent("scroll", this.scrollContainerFun )
  1087. }
  1088. },
  1089. loadDataByPaging : function(){
  1090. if( this.isItemsLoading )return;
  1091. if( !this.isItemsLoaded ){
  1092. var from = Math.min( this.pageNumber * this.options.perPageCount , this.gridJson.length);
  1093. var to = Math.min( ( this.pageNumber + 1 ) * this.options.perPageCount + 1 , this.gridJson.length);
  1094. this.isItemsLoading = true;
  1095. for( var i = from; i<to; i++ ){
  1096. this.items.push(new MWF.xApplication.query.Query.Viewer.Item(this, this.gridJson[i], null, i, null, this.options.lazy));
  1097. }
  1098. this.isItemsLoading = false;
  1099. this.pageNumber ++;
  1100. if( to == this.gridJson.length )this.isItemsLoaded = true;
  1101. }
  1102. },
  1103. loadGroupData: function(){
  1104. if( this.getSelectFlag() === "multi" && this.viewJson.allowSelectAll ) {
  1105. if(this.selectTitleCell && this.selectTitleCell.retrieve("selectAllLoaded")){
  1106. this.setUnSelectAllStyle();
  1107. }else{
  1108. this.createSelectAllNode();
  1109. }
  1110. }else if( this.selectAllNode ){
  1111. this.clearSelectAllStyle();
  1112. }
  1113. if( this.expandTitleCell ){
  1114. if ( !this.expandTitleCell.retrieve("expandLoaded") ){
  1115. if( this.viewJson.viewStyles && this.viewJson.viewStyles["groupCollapseNode"] ){
  1116. this.expandAllNode = new Element("span", {
  1117. styles : this.viewJson.viewStyles["groupCollapseNode"]
  1118. }).inject( this.expandTitleCell, "top" );
  1119. // this.selectTitleCell.setStyle("cursor", "pointer");
  1120. }else{
  1121. // this.selectTitleCell.set("html", "<span style='font-family: Webdings'>"+"<img src='../x_component_query_Query/$Viewer/"+this.options.style+"/icon/expand.png'/>"+"</span>");
  1122. this.expandAllNode = new Element("span",{
  1123. html : "<img src='../x_component_query_Query/$Viewer/"+this.options.style+"/icon/expand.png'/>"+"</span>",
  1124. style : "font-family: Webdings"
  1125. }).inject( this.expandTitleCell, "top" );
  1126. }
  1127. this.expandTitleCell.setStyle("cursor", "pointer");
  1128. this.expandTitleCell.addEvent("click", this.expandOrCollapseAll.bind(this));
  1129. this.expandTitleCell.store("expandLoaded", true);
  1130. }else if( this.getExpandFlag() !=="yes" ){
  1131. this.setCollapseAllStyle();
  1132. }
  1133. }
  1134. // this.isAllExpanded = false;
  1135. if (this.gridJson.length){
  1136. var i = 0;
  1137. this.gridJson.each(function(data){
  1138. this.items.push(new MWF.xApplication.query.Query.Viewer.ItemCategory(this, data, i));
  1139. i += data.list.length;
  1140. }.bind(this));
  1141. if (this.getExpandFlag()=="yes") this.expandOrCollapseAll();
  1142. }else{
  1143. if (this.viewPageAreaNode) this.viewPageAreaNode.empty();
  1144. }
  1145. },
  1146. getView: function(callback){
  1147. this.getLookupAction(function(){
  1148. if (this.json.application){
  1149. this.getViewRes = this.lookupAction.getView(this.json.viewName, this.json.application, function(json){
  1150. this.viewJson = JSON.decode(json.data.data);
  1151. this.json = Object.merge(this.json, json.data);
  1152. if (callback) callback();
  1153. }.bind(this));
  1154. // this.lookupAction.invoke({"name": "getView","async": true, "parameter": {"view": this.json.viewName, "application": this.json.application},"success": function(json){
  1155. // this.viewJson = JSON.decode(json.data.data);
  1156. // this.json = Object.merge(this.json, json.data);
  1157. // //var viewData = JSON.decode(json.data.data);
  1158. // if (callback) callback();
  1159. // }.bind(this)});
  1160. }else{
  1161. this.getViewRes = this.lookupAction.getViewById(this.json.viewId, function(json){
  1162. this.viewJson = JSON.decode(json.data.data);
  1163. this.json.application = json.data.query;
  1164. this.json = Object.merge(this.json, json.data);
  1165. if (callback) callback();
  1166. }.bind(this));
  1167. }
  1168. }.bind(this));
  1169. },
  1170. bindLP: function( json ){
  1171. var jsonStr = JSON.stringify( json );
  1172. jsonStr = o2.bindJson(jsonStr, {"lp": MWF.xApplication.query.Query.LP.form});
  1173. return JSON.parse(jsonStr);
  1174. },
  1175. getLookupAction: function(callback){
  1176. if (!this.lookupAction){
  1177. this.lookupAction = MWF.Actions.get("x_query_assemble_surface");
  1178. if (callback) callback();
  1179. // var _self = this;
  1180. // MWF.require("MWF.xDesktop.Actions.RestActions", function(){
  1181. // this.lookupAction = new MWF.xDesktop.Actions.RestActions("", this.options.actionRoot, "");
  1182. // this.lookupAction.getActions = function(actionCallback){
  1183. // this.actions = _self.options.actions;
  1184. // if (actionCallback) actionCallback();
  1185. // };
  1186. // if (callback) callback();
  1187. // }.bind(this));
  1188. }else{
  1189. if (callback) callback();
  1190. }
  1191. },
  1192. hide: function(){
  1193. this.node.setStyle("display", "none");
  1194. },
  1195. /**
  1196. * @summary 刷新视图。
  1197. * @param {Function} [callback] - 可选,刷新视图后的回调.
  1198. * @example
  1199. * this.target.reload();
  1200. */
  1201. reload: function( callback ){
  1202. if( this.lookuping || this.pageloading )return;
  1203. this.node.setStyle("display", "block");
  1204. if (this.loadingAreaNode) this.loadingAreaNode.setStyle("display", "block");
  1205. this.filterItems.each(function(filter){
  1206. filter.destroy();
  1207. }.bind(this));
  1208. this.filterItems = [];
  1209. this.manualOrderColumnMap = {};
  1210. if (this.viewSearchInputNode) this.viewSearchInputNode.set("text", this.lp.searchKeywork);
  1211. this.closeCustomSearch();
  1212. this.viewAreaNode.empty();
  1213. this.createViewNode({"filterList": this.json.filter ? this.json.filter.clone() : null}, callback);
  1214. },
  1215. getFilter: function(){
  1216. var filterData = [];
  1217. if (this.searchStatus==="custom"){
  1218. if (this.filterItems.length){
  1219. this.filterItems.each(function(filter){
  1220. filterData.push(filter.data);
  1221. }.bind(this));
  1222. }
  1223. }
  1224. if (this.searchStatus==="default"){
  1225. var key = this.viewSearchInputNode.get("value");
  1226. if (key && key!==this.lp.searchKeywork){
  1227. this.viewJson.customFilterList.each(function(entry){
  1228. if (entry.formatType==="textValue"){
  1229. var d = {
  1230. "path": entry.path,
  1231. "value": key,
  1232. "formatType": entry.formatType,
  1233. "logic": "or",
  1234. "comparison": "like"
  1235. };
  1236. filterData.push(d);
  1237. }
  1238. if (entry.formatType==="numberValue"){
  1239. var v = key.toFloat();
  1240. if (!isNaN(v)){
  1241. var d = {
  1242. "path": entry.path,
  1243. "value": v,
  1244. "formatType": entry.formatType,
  1245. "logic": "or",
  1246. "comparison": "like"
  1247. };
  1248. filterData.push(d);
  1249. }
  1250. }
  1251. }.bind(this));
  1252. }
  1253. }
  1254. return (filterData.length) ? filterData : null;
  1255. },
  1256. getData: function(){
  1257. if (this.selectedItems.length){
  1258. var arr = [];
  1259. this.selectedItems.each(function(item){
  1260. arr.push(item.data);
  1261. });
  1262. return arr;
  1263. }else{
  1264. return [];
  1265. }
  1266. },
  1267. _loadModuleEvents : function(){
  1268. this.moduleEventMap = {};
  1269. Object.each(this.viewJson.events, function(e, key){
  1270. if (e.code){
  1271. if (this.options.moduleEvents.indexOf(key)!==-1){
  1272. this.moduleEventMap[key] = function(event, target){
  1273. return this.Macro.fire(e.code, target || this, event);
  1274. }.bind(this);
  1275. this.addEvent(key, this.moduleEventMap[key]);
  1276. }
  1277. }
  1278. }.bind(this));
  1279. },
  1280. _removeModuleEvents: function (){
  1281. Object.each(this.moduleEventMap, function(fun, key){
  1282. this.removeEvent(key, this.moduleEventMap[key]);
  1283. }.bind(this))
  1284. },
  1285. _loadDomEvents: function(){
  1286. this.domEventMap = {};
  1287. Object.each(this.viewJson.events, function(e, key){
  1288. if (e.code){
  1289. if (this.options.moduleEvents.indexOf(key)===-1){
  1290. this.domEventMap[key] = function(event){
  1291. return this.Macro.fire(e.code, this, event);
  1292. }.bind(this);
  1293. this.node.addEvent(key, this.domEventMap[key]);
  1294. }
  1295. }
  1296. }.bind(this));
  1297. },
  1298. _removeDomEvents: function (){
  1299. Object.each(this.domEventMap, function(fun, key){
  1300. this.removeEvent(key, this.domEventMap[key]);
  1301. }.bind(this))
  1302. },
  1303. //搜索相关开始
  1304. createSearchNode: function(){
  1305. if( this.viewJson.searchbarHidden === true ){
  1306. return;
  1307. }
  1308. if (this.viewJson.customFilterList && this.viewJson.customFilterList.length){
  1309. this.searchStatus = "default";
  1310. this.loadFilterSearch();
  1311. }else{
  1312. this.loadSimpleSearch();
  1313. }
  1314. },
  1315. loadSimpleSearch: function(){
  1316. return false;
  1317. this.searchSimpleNode = new Element("div", {"styles": this.css.searchSimpleNode}).inject(this.searchAreaNode);
  1318. this.searchSimpleButtonNode = new Element("div", {"styles": this.css.searchSimpleButtonNode}).inject(this.searchSimpleNode);
  1319. this.searchSimpleInputNode = new Element("input", {"type":"text", "styles": this.css.searchSimpleInputNode, "value": this.lp.searchKeywork}).inject(this.searchSimpleNode);
  1320. this.searchSimpleButtonNode.addEvent("click", function(){
  1321. this.search();
  1322. }.bind(this));
  1323. this.searchSimpleInputNode.addEvents({
  1324. "focus": function(){
  1325. if (this.searchSimpleInputNode.get("value")===this.lp.searchKeywork) this.searchSimpleInputNode.set("value", "");
  1326. }.bind(this),
  1327. "blur": function(){if (!this.searchSimpleInputNode.get("value")) this.searchSimpleInputNode.set("value", this.lp.searchKeywork);}.bind(this),
  1328. "keydown": function(e){
  1329. if (e.code===13) this.search();
  1330. }.bind(this)
  1331. });
  1332. },
  1333. search: function(){
  1334. if (this.gridJson){
  1335. var key = this.searchSimpleInputNode.get("value");
  1336. var rows = this.viewTable.rows;
  1337. var first = (this.options.isloadTitle) ? 1 : 0;
  1338. for (var i = first; i<rows.length; i++){
  1339. var tr = rows[i];
  1340. if (!key || key==this.lp.searchKeywork){
  1341. if (tr.getStyle("display")==="none") tr.setStyle("display", "table-row");
  1342. }else{
  1343. if (tr.get("text").indexOf(key)!==-1){
  1344. if (tr.getStyle("display")==="none") tr.setStyle("display", "table-row");
  1345. }else{
  1346. if (tr.getStyle("display")!=="none") tr.setStyle("display", "none");
  1347. }
  1348. }
  1349. }
  1350. //if (this.viewPageAreaNode) this.viewPageAreaNode.hide();
  1351. }
  1352. },
  1353. loadFilterSearch: function(){
  1354. this.viewSearchCustomActionNode = new Element("div", {"styles": this.css.viewFilterSearchCustomActionNode, "text": this.lp.customSearch}).inject(this.searchAreaNode);
  1355. this.viewSearchInputAreaNode = new Element("div", {"styles": this.css.viewFilterSearchInputAreaNode}).inject(this.searchAreaNode);
  1356. this.viewSearchIconNode = new Element("div", {"styles": this.css.viewFilterSearchIconNode}).inject(this.viewSearchInputAreaNode);
  1357. this.viewSearchInputBoxNode = new Element("div", {"styles": this.css.viewFilterSearchInputBoxNode}).inject(this.viewSearchInputAreaNode);
  1358. this.viewSearchInputNode = new Element("input", {"styles": this.css.viewFilterSearchInputNode, "value": this.lp.searchKeywork}).inject(this.viewSearchInputBoxNode);
  1359. this.viewSearchInputNode.addEvents({
  1360. "focus": function(){
  1361. if (this.viewSearchInputNode.get("value")===this.lp.searchKeywork) this.viewSearchInputNode.set("value", "");
  1362. }.bind(this),
  1363. "blur": function(){if (!this.viewSearchInputNode.get("value")) this.viewSearchInputNode.set("value", this.lp.searchKeywork);}.bind(this),
  1364. "keydown": function(e){
  1365. if (e.code===13) this.searchView();
  1366. }.bind(this)
  1367. });
  1368. this.viewSearchIconNode.addEvents({
  1369. "click": function(){this.searchView();}.bind(this)
  1370. });
  1371. this.viewSearchCustomActionNode.addEvents({
  1372. "click": function(){this.loadCustomSearch();}.bind(this)
  1373. });
  1374. },
  1375. searchView: function(){
  1376. debugger;
  1377. if (this.viewJson.customFilterList) {
  1378. var key = this.viewSearchInputNode.get("value");
  1379. if (key && key !== this.lp.searchKeywork) {
  1380. var filterData = [];
  1381. this.filterItems = [];
  1382. this.viewJson.customFilterList.each(function (entry) {
  1383. if (entry.formatType === "textValue") {
  1384. var d = {
  1385. "path": entry.path,
  1386. "value": key,
  1387. "formatType": entry.formatType,
  1388. "logic": "or",
  1389. "comparison": "like"
  1390. };
  1391. filterData.push(d);
  1392. this.filterItems.push({"data":d});
  1393. }
  1394. if (entry.formatType === "numberValue") {
  1395. var v = key.toFloat();
  1396. if (!isNaN(v)) {
  1397. var d = {
  1398. "path": entry.path,
  1399. "value": v,
  1400. "formatType": entry.formatType,
  1401. "logic": "or",
  1402. "comparison": "equals"
  1403. };
  1404. filterData.push(d);
  1405. this.filterItems.push({"data":d});
  1406. }
  1407. }
  1408. }.bind(this));
  1409. if( this.json.filter ){
  1410. this.json.filter.clone().each(function(f){
  1411. filterData.push(f);
  1412. })
  1413. }
  1414. this.createViewNode({"filterList": filterData});
  1415. }else{
  1416. this.filterItems = [];
  1417. var filterData = this.json.filter ? this.json.filter.clone() : [];
  1418. this.createViewNode( {"filterList": filterData} );
  1419. }
  1420. }
  1421. },
  1422. searchCustomView: function(){
  1423. if (this.filterItems.length){
  1424. var filterData = this.json.filter ? this.json.filter.clone() : [];
  1425. this.filterItems.each(function(filter){
  1426. filterData.push(filter.data);
  1427. }.bind(this));
  1428. this.createViewNode({"filterList": filterData});
  1429. }else{
  1430. this.createViewNode({"filterList": this.json.filter ? this.json.filter.clone() : null});
  1431. }
  1432. },
  1433. loadCustomSearch: function(){
  1434. if( this.lastFilterItems ){
  1435. this.filterItems = this.lastFilterItems;
  1436. }else{
  1437. this.filterItems = [];
  1438. }
  1439. this.viewSearchIconNode.setStyle("display", "none");
  1440. this.viewSearchInputBoxNode.setStyle("display", "none");
  1441. this.viewSearchCustomActionNode.setStyle("display", "none");
  1442. if (!this.searchMorph) this.searchMorph = new Fx.Morph(this.viewSearchInputAreaNode);
  1443. var x = this.viewSearchInputAreaNode.getParent().getSize().x-2-20;
  1444. this.css.viewFilterSearchInputAreaNode_custom.width = ""+x+"px";
  1445. var x1 = this.viewSearchInputAreaNode.getSize().x-2;
  1446. this.viewSearchInputAreaNode.setStyle("width", ""+x1+"px");
  1447. this.searchMorph.start(this.css.viewFilterSearchInputAreaNode_custom).chain(function(){
  1448. this.searchStatus = "custom";
  1449. this.css.viewFilterSearchInputAreaNode_custom.width = "auto";
  1450. this.viewSearchInputAreaNode.setStyle("width", "auto");
  1451. if (this.viewSearchCustomContentNode){
  1452. this.viewSearchCustomCloseActionNode.setStyle("display", "block");
  1453. this.viewSearchCustomContentNode.setStyle("display", "block");
  1454. }else{
  1455. this.loadCustomSearchContent();
  1456. }
  1457. if(this.setContentHeightFun)this.setContentHeightFun();
  1458. }.bind(this));
  1459. this.searchCustomView();
  1460. },
  1461. loadCustomSearchContent: function(){
  1462. this.viewSearchCustomCloseActionNode = new Element("div", {"styles": this.css.viewFilterSearchCustomCloseActionNode}).inject(this.viewSearchInputAreaNode);
  1463. this.viewSearchCustomContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomContentNode}).inject(this.viewSearchInputAreaNode);
  1464. this.viewSearchCustomPathContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomPathContentNode}).inject(this.viewSearchCustomContentNode);
  1465. this.viewSearchCustomComparisonContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomComparisonContentNode}).inject(this.viewSearchCustomContentNode);
  1466. this.viewSearchCustomValueContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomValueContentNode}).inject(this.viewSearchCustomContentNode);
  1467. this.viewSearchCustomAddContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomAddContentNode}).inject(this.viewSearchCustomContentNode);
  1468. this.viewSearchCustomAddIconNode = new Element("div", {"styles": this.css.viewFilterSearchCustomAddIconNode}).inject(this.viewSearchCustomAddContentNode);
  1469. this.viewSearchCustomFilterContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomFilterContentNode}).inject(this.viewSearchCustomContentNode);
  1470. this.loadViewSearchCustomList();
  1471. this.viewSearchCustomCloseActionNode.addEvents({
  1472. "click": function(){this.closeCustomSearch();}.bind(this)
  1473. });
  1474. this.viewSearchCustomAddIconNode.addEvents({
  1475. "click": function(){this.viewSearchCustomAddToFilter();}.bind(this)
  1476. });
  1477. },
  1478. loadViewSearchCustomList: function(){
  1479. this.viewSearchCustomPathListNode = new Element("select", {
  1480. "styles": this.css.viewFilterSearchCustomPathListNode,
  1481. "multiple": true
  1482. }).inject(this.viewSearchCustomPathContentNode);
  1483. this.viewSearchCustomComparisonListNode = new Element("select", {
  1484. "styles": this.css.viewFilterSearchCustomComparisonListNode,
  1485. "multiple": true
  1486. }).inject(this.viewSearchCustomComparisonContentNode);
  1487. this.viewJson.customFilterList.each(function(entry){
  1488. var option = new Element("option", {
  1489. "style": this.css.viewFilterSearchOptionNode,
  1490. "value": entry.path,
  1491. "text": entry.title
  1492. }).inject(this.viewSearchCustomPathListNode);
  1493. option.store("entry", entry);
  1494. }.bind(this));
  1495. this.viewSearchCustomPathListNode.addEvent("change", function(){
  1496. this.loadViewSearchCustomComparisonList();
  1497. }.bind(this));
  1498. },
  1499. loadViewSearchCustomComparisonList: function(){
  1500. var idx = this.viewSearchCustomPathListNode.selectedIndex;
  1501. var option = this.viewSearchCustomPathListNode.options[idx];
  1502. var entry = option.retrieve("entry");
  1503. if (entry){
  1504. var selectableList = this.getCustomSelectScriptResult(entry);
  1505. switch (entry.formatType){
  1506. case "numberValue":
  1507. this.loadComparisonSelect(this.lp.numberFilter);
  1508. if( selectableList.length > 0 ){
  1509. this.loadViewSerchCustomSelectByScript(selectableList)
  1510. }else{
  1511. this.loadViewSearchCustomValueNumberInput();
  1512. }
  1513. break;
  1514. case "dateTimeValue":
  1515. this.loadComparisonSelect(this.lp.dateTimeFilter);
  1516. if( selectableList.length > 0 ){
  1517. this.loadViewSerchCustomSelectByScript(selectableList)
  1518. }else {
  1519. this.loadViewSearchCustomValueDateTimeInput();
  1520. }
  1521. break;
  1522. case "dateValue":
  1523. this.loadComparisonSelect(this.lp.dateFilter);
  1524. if( selectableList.length > 0 ){
  1525. this.loadViewSerchCustomSelectByScript(selectableList)
  1526. }else {
  1527. this.loadViewSearchCustomValueDateInput();
  1528. }
  1529. break;
  1530. case "timeValue":
  1531. this.loadComparisonSelect(this.lp.dateTimeFilter);
  1532. if( selectableList.length > 0 ){
  1533. this.loadViewSerchCustomSelectByScript(selectableList)
  1534. }else {
  1535. this.loadViewSearchCustomValueTimeInput();
  1536. }
  1537. break;
  1538. case "booleanValue":
  1539. this.loadComparisonSelect(this.lp.booleanFilter);
  1540. if( selectableList.length > 0 ){
  1541. this.loadViewSerchCustomSelectByScript(selectableList)
  1542. }else {
  1543. this.loadViewSearchCustomValueBooleanInput();
  1544. }
  1545. break;
  1546. default:
  1547. this.loadComparisonSelect(this.lp.textFilter);
  1548. if( selectableList.length > 0 ){
  1549. this.loadViewSerchCustomSelectByScript(selectableList)
  1550. }else {
  1551. this.loadViewSearchCustomValueTextInput();
  1552. }
  1553. }
  1554. }
  1555. },
  1556. getCustomSelectScriptResult : function( entry ){
  1557. var scriptResult = [];
  1558. if( entry.valueType === "script" ){
  1559. if( entry.valueScript && entry.valueScript.code ){
  1560. var result = this.Macro.exec(entry.valueScript.code, this);
  1561. var array = typeOf( result ) === "array" ? result : [result];
  1562. for( var i=0; i<array.length; i++ ){
  1563. if( array[i].indexOf( "|" ) > -1 ){
  1564. var arr = array[i].split("|");
  1565. scriptResult.push({ "text" : arr[0], "value" : arr[1] })
  1566. }else{
  1567. scriptResult.push({ "text" : array[i], "value" : array[i] })
  1568. }
  1569. }
  1570. }
  1571. }
  1572. return scriptResult;
  1573. },
  1574. loadViewSerchCustomSelectByScript: function( array ){
  1575. this.viewSearchCustomValueContentNode.empty();
  1576. this.viewSearchCustomValueNode = new Element("select", {
  1577. "styles": this.css.viewFilterSearchCustomComparisonListNode,
  1578. "multiple": true
  1579. }).inject(this.viewSearchCustomValueContentNode);
  1580. array.each(function( v ){
  1581. var option = new Element("option", {
  1582. "style": this.css.viewFilterSearchOptionNode,
  1583. "value": v.value,
  1584. "text": v.text,
  1585. "selected" : array.length === 1
  1586. }).inject(this.viewSearchCustomValueNode);
  1587. }.bind(this));
  1588. },
  1589. loadViewSearchCustomValueNumberInput: function(){
  1590. this.viewSearchCustomValueContentNode.empty();
  1591. this.viewSearchCustomValueNode = new Element("input", {
  1592. "styles": this.css.viewFilterSearchCustomValueNode,
  1593. "type": "number"
  1594. }).inject(this.viewSearchCustomValueContentNode);
  1595. },
  1596. loadViewSearchCustomValueDateTimeInput: function(){
  1597. this.viewSearchCustomValueContentNode.empty();
  1598. this.viewSearchCustomValueNode = new Element("input", {
  1599. "styles": this.css.viewFilterSearchCustomValueNode,
  1600. "type": "text",
  1601. "readonly": true
  1602. }).inject(this.viewSearchCustomValueContentNode);
  1603. MWF.require("MWF.widget.Calendar", function(){
  1604. this.calendar = new MWF.widget.Calendar(this.viewSearchCustomValueNode, {
  1605. "style": "xform",
  1606. "isTime": true,
  1607. "secondEnable" : true,
  1608. "target": this.app ? this.app.content : this.container,
  1609. "format": "db"
  1610. });
  1611. }.bind(this));
  1612. },
  1613. loadViewSearchCustomValueDateInput: function(){
  1614. this.viewSearchCustomValueContentNode.empty();
  1615. this.viewSearchCustomValueNode = new Element("input", {
  1616. "styles": this.css.viewFilterSearchCustomValueNode,
  1617. "type": "text",
  1618. "readonly": true
  1619. }).inject(this.viewSearchCustomValueContentNode);
  1620. MWF.require("MWF.widget.Calendar", function(){
  1621. this.calendar = new MWF.widget.Calendar(this.viewSearchCustomValueNode, {
  1622. "style": "xform",
  1623. "isTime": false,
  1624. "target": this.app ? this.app.content : this.container,
  1625. "format": "%Y-%m-%d"
  1626. });
  1627. }.bind(this));
  1628. },
  1629. loadViewSearchCustomValueTimeInput: function(){
  1630. this.viewSearchCustomValueContentNode.empty();
  1631. this.viewSearchCustomValueNode = new Element("input", {
  1632. "styles": this.css.viewFilterSearchCustomValueNode,
  1633. "type": "text",
  1634. "readonly": true
  1635. }).inject(this.viewSearchCustomValueContentNode);
  1636. MWF.require("MWF.widget.Calendar", function(){
  1637. this.calendar = new MWF.widget.Calendar(this.viewSearchCustomValueNode, {
  1638. "style": "xform",
  1639. "timeOnly": true,
  1640. "target": this.app ? this.app.content : this.container,
  1641. "format": "%H:%M:%S"
  1642. });
  1643. }.bind(this));
  1644. },
  1645. loadViewSearchCustomValueBooleanInput: function(){
  1646. this.viewSearchCustomValueContentNode.empty();
  1647. this.viewSearchCustomValueNode = new Element("select", {
  1648. "styles": this.css.viewFilterSearchCustomValueSelectNode,
  1649. "multiple": true
  1650. }).inject(this.viewSearchCustomValueContentNode);
  1651. new Element("option", {"value": "true","text": this.lp.yes}).inject(this.viewSearchCustomValueNode);
  1652. new Element("option", {"value": "false","text": this.lp.no}).inject(this.viewSearchCustomValueNode);
  1653. },
  1654. loadViewSearchCustomValueTextInput: function(){
  1655. this.viewSearchCustomValueContentNode.empty();
  1656. this.viewSearchCustomValueNode = new Element("textarea", {
  1657. "styles": this.css.viewFilterSearchCustomValueNode
  1658. }).inject(this.viewSearchCustomValueContentNode);
  1659. },
  1660. loadComparisonSelect:function(obj){
  1661. this.viewSearchCustomComparisonListNode.empty();
  1662. Object.each(obj, function(v, k){
  1663. var option = new Element("option", {"value": k,"text": v}).inject(this.viewSearchCustomComparisonListNode);
  1664. }.bind(this));
  1665. },
  1666. closeCustomSearch: function(){
  1667. if (this.viewSearchCustomContentNode && this.viewSearchCustomContentNode.getStyle("display")==="block"){
  1668. this.viewSearchCustomCloseActionNode.setStyle("display", "none");
  1669. this.viewSearchCustomContentNode.setStyle("display", "none");
  1670. var x = this.viewSearchInputAreaNode.getParent().getSize().x;
  1671. x1 = x-2-10-90;
  1672. this.css.viewFilterSearchInputAreaNode.width = ""+x1+"px";
  1673. var x1 = this.viewSearchInputAreaNode.getSize().x-2;
  1674. this.viewSearchInputAreaNode.setStyle("width", ""+x1+"px");
  1675. if (!this.searchMorph) this.searchMorph = new Fx.Morph(this.viewSearchInputAreaNode);
  1676. this.searchMorph.start(this.css.viewFilterSearchInputAreaNode).chain(function(){
  1677. this.searchStatus = "default";
  1678. this.css.viewFilterSearchInputAreaNode.width = "auto";
  1679. this.viewSearchInputAreaNode.setStyle("margin-right", "90px");
  1680. this.viewSearchIconNode.setStyle("display", "block");
  1681. this.viewSearchInputBoxNode.setStyle("display", "block");
  1682. this.viewSearchCustomActionNode.setStyle("display", "block");
  1683. if(this.setContentHeightFun)this.setContentHeightFun();
  1684. }.bind(this));
  1685. this.lastFilterItems = this.filterItems;
  1686. this.createViewNode({"filterList": this.json.filter ? this.json.filter.clone() : null});
  1687. }
  1688. },
  1689. viewSearchCustomAddToFilter: function(){
  1690. var pathIdx = this.viewSearchCustomPathListNode.selectedIndex;
  1691. var comparisonIdx = this.viewSearchCustomComparisonListNode.selectedIndex;
  1692. if (pathIdx===-1){
  1693. MWF.xDesktop.notice("error", {"x": "left", "y": "top"}, this.lp.filterErrorTitle, this.viewSearchCustomPathListNode, {"x": 0, "y": 85});
  1694. return false;
  1695. }
  1696. if (comparisonIdx===-1){
  1697. MWF.xDesktop.notice("error", {"x": "left", "y": "top"}, this.lp.filterErrorComparison, this.viewSearchCustomComparisonListNode, {"x": 0, "y": 85});
  1698. return false;
  1699. }
  1700. var pathOption = this.viewSearchCustomPathListNode.options[pathIdx];
  1701. var entry = pathOption.retrieve("entry");
  1702. if (entry){
  1703. var pathTitle = entry.title;
  1704. var path = entry.path;
  1705. var comparison = this.viewSearchCustomComparisonListNode.options[comparisonIdx].get("value");
  1706. var comparisonTitle = this.viewSearchCustomComparisonListNode.options[comparisonIdx].get("text");
  1707. var value = "";
  1708. if( entry.valueType === "script" && entry.valueScript && entry.valueScript.code ){
  1709. var idx = this.viewSearchCustomValueNode.selectedIndex;
  1710. if (idx!==-1){
  1711. var v = this.viewSearchCustomValueNode.options[idx].get("value");
  1712. value = entry.formatType === "booleanValue" ? (v==="true") : v;
  1713. }
  1714. }else{
  1715. switch (entry.formatType){
  1716. case "numberValue":
  1717. value = this.viewSearchCustomValueNode.get("value");
  1718. break;
  1719. case "dateTimeValue":
  1720. value = this.viewSearchCustomValueNode.get("value");
  1721. break;
  1722. case "booleanValue":
  1723. var idx = this.viewSearchCustomValueNode.selectedIndex;
  1724. if (idx!==-1){
  1725. var v = this.viewSearchCustomValueNode.options[idx].get("value");
  1726. value = (v==="true");
  1727. }
  1728. break;
  1729. default:
  1730. value = this.viewSearchCustomValueNode.get("value");
  1731. }
  1732. }
  1733. if (value===""){
  1734. MWF.xDesktop.notice("error", {"x": "left", "y": "top"}, this.lp.filterErrorValue, this.viewSearchCustomValueContentNode, {"x": 0, "y": 85});
  1735. return false;
  1736. }
  1737. this.filterItems.push(new MWF.xApplication.query.Query.Viewer.Filter(this, {
  1738. "logic": "and",
  1739. "path": path,
  1740. "title": pathTitle,
  1741. "comparison": comparison,
  1742. "comparisonTitle": comparisonTitle,
  1743. "value": value,
  1744. "formatType": (entry.formatType=="datetimeValue") ? "dateTimeValue": entry.formatType
  1745. }, this.viewSearchCustomFilterContentNode));
  1746. this.searchCustomView();
  1747. }
  1748. },
  1749. searchViewRemoveFilter: function(filter){
  1750. this.filterItems.erase(filter);
  1751. filter.destroy();
  1752. this.searchCustomView()
  1753. },
  1754. //搜索相关结束
  1755. //api 使用 开始
  1756. /**
  1757. * @summary 如果当前视图是嵌入在表单或者页面中,使用该方法获取表单或页面的上下文。
  1758. * @see {@link module:queryView.getParentEnvironment|详情查看 this.queryViewer.getParentEnvironment}
  1759. * @return {Object}
  1760. * @example
  1761. * this.target.getParentEnvironment();
  1762. */
  1763. getParentEnvironment : function(){
  1764. return this.parentMacro ? this.parentMacro.environment : null;
  1765. },
  1766. /**
  1767. * @summary 获取视图的配置信息。
  1768. * @see {@link module:queryView.getViewInfor|详情查看 this.queryViewer.getViewInfor}
  1769. * @return {Object}
  1770. * @example
  1771. * this.target.getViewInfor();
  1772. */
  1773. getViewInfor : function(){
  1774. return this.json;
  1775. },
  1776. /**
  1777. * @summary 获取视图当前页的基本信息。
  1778. * @see {@link module:queryView.getPageInfor|详情查看 this.queryViewer.getPageInfor}
  1779. * @return {Object}
  1780. * @example
  1781. * this.target.getPageInfor();
  1782. */
  1783. getPageInfor : function(){
  1784. return {
  1785. pages : this.pages,
  1786. perPageCount : this.options.perPageCount,
  1787. currentPageNumber : this.currentPage
  1788. };
  1789. },
  1790. /**
  1791. * @summary 获取当前页的数据。
  1792. * @see {@link module:queryView.getPageData|详情查看 this.queryViewer.getPageData}
  1793. * @return {Object}
  1794. * @example
  1795. * this.target.getPageData();
  1796. */
  1797. getPageData : function () {
  1798. return this.gridJson;
  1799. },
  1800. /**
  1801. * @summary 跳转到指定的页面。
  1802. * @see {@link module:queryView.toPage|详情查看 this.queryViewer.toPage}
  1803. * @param {Number} pageNumber 需要跳转的页码
  1804. * @param {Function} callback 跳转的页面数据加载完成以后的回调方法。
  1805. * @example
  1806. * // 跳转到第2页并且获取该页的数据。
  1807. * this.target.toPage( 2, function(){
  1808. * var data = this.target.getPageData();
  1809. * }.bind(this) )
  1810. */
  1811. toPage : function( pageNumber, callback ){
  1812. this.currentPage = pageNumber;
  1813. this.loadCurrentPageData( callback );
  1814. },
  1815. /**
  1816. * 获取选中的条目的数据。
  1817. * @method getSelectedData
  1818. * @see {@link module:queryView.getSelectedData|详情查看 this.queryViewer.getSelectedData}
  1819. * @memberOf module:queryView
  1820. * @static
  1821. * @return {Object[]} 选中的条目的数据。
  1822. * <div>格式如下:</div>
  1823. * <pre><code class='language-js'>
  1824. * [
  1825. {
  1826. "bundle": "099ed3c9-dfbc-4094-a8b7-5bfd6c5f7070", //cms 的 documentId, process 的 jobId
  1827. "data": { //视图中配置的数据
  1828. "title": "考勤管理-配置-统计周期设置", //列名称及列值
  1829. "time": "2018-08-25 11:29:45"
  1830. }
  1831. },
  1832. ...
  1833. * ]
  1834. </code></pre>
  1835. * @o2syntax
  1836. * var data = this.target.getSelectedData();
  1837. */
  1838. getSelectedData : function(){
  1839. return this.getData();
  1840. },
  1841. getSelectAllStatus : function(){
  1842. if( this.getSelectFlag()!=="multi")return;
  1843. if( !this.items.length )return "none";
  1844. var allFlag = true, noneFlag = true;
  1845. for( var i=0; i<this.items.length; i++ ){
  1846. var item = this.items[i];
  1847. if( item.clazzType === "item" ){
  1848. if( item.data.$selectedEnable ){
  1849. item.isSelected ? ( noneFlag = false ) : (allFlag = false);
  1850. }
  1851. }else{
  1852. if( item.data.$selectedEnable ) {
  1853. var f = item.getSelectAllStatus();
  1854. if (f === "none") {
  1855. allFlag = false;
  1856. } else if (f === "all") {
  1857. noneFlag = false;
  1858. } else if (f === "some") {
  1859. allFlag = false;
  1860. noneFlag = false;
  1861. }
  1862. }
  1863. }
  1864. if( !allFlag && !noneFlag )return "some"
  1865. }
  1866. if( noneFlag )return "none";
  1867. if( allFlag )return "all";
  1868. return "some";
  1869. },
  1870. checkSelectAllStatus : function(){
  1871. if(!this.selectAllNode)return;
  1872. var status = this.getSelectAllStatus();
  1873. if( status === "all" ){
  1874. this.setSelectAllStyle()
  1875. }else{
  1876. this.setUnSelectAllStyle()
  1877. }
  1878. },
  1879. setSelectAllStyle : function () {
  1880. if(!this.selectAllNode)return;
  1881. if( this.viewJson.viewStyles && this.viewJson.viewStyles["checkedCheckboxNode"] ){
  1882. this.selectAllNode.setStyles( this.viewJson.viewStyles["checkedCheckboxNode"] );
  1883. }else {
  1884. this.selectAllNode.getElement("img").set("src",
  1885. '../x_component_query_Query/$Viewer/" + this.options.style + "/icon/checkbox_checked.png' )
  1886. }
  1887. },
  1888. setUnSelectAllStyle : function () {
  1889. if(!this.selectAllNode)return;
  1890. if( this.viewJson.viewStyles && this.viewJson.viewStyles["checkboxNode"] ){
  1891. this.selectAllNode.setStyles( this.viewJson.viewStyles["checkboxNode"] );
  1892. }else {
  1893. this.selectAllNode.getElement("img").set("src",
  1894. '../x_component_query_Query/$Viewer/" + this.options.style + "/icon/checkbox.png' )
  1895. }
  1896. },
  1897. clearSelectAllStyle : function(){
  1898. if(!this.selectAllNode)return;
  1899. var viewStyles = this.viewJson.viewStyles;
  1900. var viewTitleCellNode = (viewStyles && viewStyles["titleTd"]) ? viewStyles["titleTd"] : this.css.viewTitleCellNode;
  1901. if( !viewTitleCellNode["background"] || !viewTitleCellNode["background-image"] || !viewTitleCellNode["background-color"] ){
  1902. viewTitleCellNode["background"] = "inherit";
  1903. }
  1904. this.selectAllNode.setStyles( viewTitleCellNode );
  1905. var img = this.selectAllNode.getElement("img");
  1906. if( img )img.set("src", '../x_component_query_Query/$Viewer/" + this.options.style + "/icon/blank.png')
  1907. },
  1908. selectAll : function(){
  1909. // var flag = this.json.select || this.viewJson.select || "none";
  1910. if ( this.getSelectFlag()==="multi"){
  1911. this.items.each( function (item) {
  1912. if( item.data.$selectedEnable ){
  1913. if( item.clazzType === "item" ){
  1914. item.selected("view");
  1915. }else{
  1916. item.selectAll("view");
  1917. }
  1918. }
  1919. })
  1920. if( this.viewJson.allowSelectAll ) {
  1921. this.setSelectAllStyle();
  1922. }
  1923. }
  1924. },
  1925. unSelectAll : function(){
  1926. // var flag = this.json.select || this.viewJson.select || "none";
  1927. if ( this.getSelectFlag()==="multi"){
  1928. this.items.each( function (item) {
  1929. if( item.data.$selectedEnable ) {
  1930. if (item.clazzType === "item") {
  1931. item.unSelected("view");
  1932. } else {
  1933. item.unSelectAll("view");
  1934. }
  1935. }
  1936. })
  1937. if( this.viewJson.allowSelectAll ) {
  1938. this.setUnSelectAllStyle();
  1939. }
  1940. }
  1941. },
  1942. getExpandAllStatus: function(){
  1943. if( !this.items.length )return "none";
  1944. var allFlag = true, noneFlag = true;
  1945. for( var i=0; i<this.items.length; i++ ){
  1946. var item = this.items[i];
  1947. item.expanded ? ( noneFlag = false ) : (allFlag = false);
  1948. if( !allFlag && !noneFlag )return "some"
  1949. }
  1950. if( allFlag )return "all";
  1951. if( noneFlag )return "none";
  1952. return "some";
  1953. },
  1954. checkExpandAllStatus: function(){
  1955. if(!this.expandAllNode)return;
  1956. var status = this.getExpandAllStatus();
  1957. if( status === "all" ){
  1958. this.setExpandAllStyle()
  1959. }else{
  1960. this.setCollapseAllStyle()
  1961. }
  1962. },
  1963. setExpandAllStyle: function(){
  1964. if(!this.expandAllNode)return;
  1965. if( this.viewJson.viewStyles && this.viewJson.viewStyles["groupExpandNode"] ){
  1966. this.expandAllNode.setStyles( this.viewJson.viewStyles["groupExpandNode"] );
  1967. }else{
  1968. this.expandAllNode.set("html", "<img src='../x_component_query_Query/$Viewer/"+this.options.style+"/icon/expand.png'/>");
  1969. }
  1970. },
  1971. setCollapseAllStyle : function(){
  1972. if(!this.expandAllNode)return;
  1973. if( this.viewJson.viewStyles && this.viewJson.viewStyles["groupCollapseNode"] ){
  1974. this.expandAllNode.setStyles( this.viewJson.viewStyles["groupCollapseNode"] );
  1975. }else{
  1976. this.expandAllNode.set("html", "<img src='../x_component_query_Query/$Viewer/"+this.options.style+"/icon/down.png'/>");
  1977. }
  1978. },
  1979. expandAll: function(){
  1980. this.items.each(function(item, i){
  1981. window.setTimeout(function(){
  1982. item.expand( "view" );
  1983. }.bind(this), 10*i+5);
  1984. }.bind(this));
  1985. this.setExpandAllStyle();
  1986. },
  1987. collapseAll: function(){
  1988. this.items.each(function(item){
  1989. item.collapse( "view" );
  1990. }.bind(this));
  1991. this.setCollapseAllStyle();
  1992. },
  1993. expandOrCollapseAll: function(){
  1994. this.getExpandAllStatus() === "all" ? this.collapseAll() : this.expandAll();
  1995. // if( this.viewJson.viewStyles && this.viewJson.viewStyles["groupCollapseNode"] ){
  1996. // var span = this.expandAllNode; //this.selectTitleCell.getElement("span");
  1997. // if( this.isAllExpanded ){
  1998. // this.items.each(function(item){
  1999. // item.collapse();
  2000. // span.setStyles( this.viewJson.viewStyles["groupCollapseNode"] );
  2001. // }.bind(this));
  2002. // this.isAllExpanded = false;
  2003. // }else{
  2004. // this.items.each(function(item, i){
  2005. // window.setTimeout(function(){
  2006. // item.expand();
  2007. // }.bind(this), 10*i+5);
  2008. //
  2009. // span.setStyles( this.viewJson.viewStyles["groupExpandNode"] );
  2010. // this.isAllExpanded = true;
  2011. // }.bind(this));
  2012. // }
  2013. // }else{
  2014. // var icon = this.expandAllNode; //this.selectTitleCell.getElement("span");
  2015. // if (icon.get("html").indexOf("expand.png")===-1){
  2016. // this.items.each(function(item){
  2017. // item.collapse();
  2018. // icon.set("html", "<img src='../x_component_query_Query/$Viewer/"+this.options.style+"/icon/expand.png'/>");
  2019. // }.bind(this));
  2020. // this.isAllExpanded = false;
  2021. // }else{
  2022. // this.items.each(function(item, i){
  2023. // window.setTimeout(function(){
  2024. // item.expand();
  2025. // }.bind(this), 10*i+5);
  2026. //
  2027. // icon.set("html", "<img src='../x_component_query_Query/$Viewer/"+this.options.style+"/icon/down.png'/>");
  2028. // }.bind(this));
  2029. // this.isAllExpanded = true;
  2030. // }
  2031. // }
  2032. },
  2033. /**
  2034. * @summary 设置视图的过滤条件,该方法不能修改视图中默认的过滤条件(在开发视图的时候添加的过滤条件),而是在这上面新增。
  2035. * @see {@link module:queryView.setFilter|详情查看 this.queryViewer.setFilter}
  2036. * @param {(ViewFilter[]|ViewFilter|Null)} [filter] 过滤条件
  2037. * @param {Function} callback 过滤完成并重新加载数据后的回调方法。
  2038. */
  2039. setFilter : function( filter, callback ){
  2040. if( this.lookuping || this.pageloading )return;
  2041. if( !filter )filter = [];
  2042. if( typeOf( filter ) === "object" )filter = [ filter ];
  2043. this.json.filter = filter;
  2044. if( this.viewAreaNode ){
  2045. this.createViewNode({"filterList": this.json.filter ? this.json.filter.clone() : null}, callback);
  2046. }
  2047. },
  2048. /**
  2049. * @summary 把当前视图切换成另外一个视图。
  2050. * @see {@link module:queryView.switchView|详情查看 this.queryViewer.switchView}
  2051. * @param {(ViewFilter[]|ViewFilter|Null)} [filter] 过滤条件
  2052. * @param {Object} options 需要跳转的参数配置
  2053. */
  2054. switchView : function( json ){
  2055. // json = {
  2056. // "application": application,
  2057. // "viewName": viewName,
  2058. // "isTitle": "yes",
  2059. // "select": "none",
  2060. // "titleStyles": titleStyles,
  2061. // "itemStyles": itemStyles,
  2062. // "isExpand": "no",
  2063. // "filter": filter
  2064. // }
  2065. this.node.setStyle("display", "block");
  2066. if (this.loadingAreaNode) this.loadingAreaNode.setStyle("display", "block");
  2067. this.searchMorph = null;
  2068. this.viewSearchCustomContentNode = null;
  2069. this.paging = null;
  2070. this._removeModuleEvents();
  2071. this._removeDomEvents();
  2072. if( this.setContentHeightFun ){
  2073. this.container.removeEvent("resize", this.setContentHeightFun);
  2074. }
  2075. var newJson = Object.merge( Object.clone(this.originalJson), json );
  2076. this.container.empty();
  2077. this.initialize( this.container, newJson, Object.clone(this.options), this.app, this.parentMacro);
  2078. },
  2079. confirm: function (type, e, title, text, width, height, ok, cancel, callback, mask, style) {
  2080. this.app.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style)
  2081. },
  2082. alert: function (type, title, text, width, height) {
  2083. this.app.alert(type, "center", title, text, width, height);
  2084. },
  2085. notice: function (content, type, target, where, offset, option) {
  2086. this.app.notice(content, type, target, where, offset, option)
  2087. },
  2088. dialog: function( options ){
  2089. if( !options )options = {};
  2090. var opts = {
  2091. "style" : options.style || "user",
  2092. "title": options.title || "",
  2093. "width": options.width || 300,
  2094. "height" : options.height || 150,
  2095. "isMax": o2.typeOf( options.isMax ) === "boolean" ? options.isMax : false,
  2096. "isClose": o2.typeOf( options.isClose ) === "boolean" ? options.isClose : true,
  2097. "isResize": o2.typeOf( options.isResize ) === "boolean" ? options.isResize : true,
  2098. "isMove": o2.typeOf( options.isMove ) === "boolean" ? options.isMove : true,
  2099. "isTitle": o2.typeOf( options.isTitle ) === "boolean" ? options.isTitle : true,
  2100. "offset": options.offset || null,
  2101. "mask": o2.typeOf( options.mask ) === "boolean" ? options.mask : true,
  2102. "container": options.container || ( layout.mobile ? $(document.body) : this.app.content ),
  2103. "duration": options.duration || 200,
  2104. "lp": options.lp || null,
  2105. "zindex": ( options.zindex || 100 ).toInt(),
  2106. "buttonList": options.buttonList || [
  2107. {
  2108. "type": "ok",
  2109. "text": MWF.LP.process.button.ok,
  2110. "action": function(){
  2111. if(options.ok){
  2112. var flag = options.ok.call( this );
  2113. if( flag === true || o2.typeOf(flag) === "null" )this.close();
  2114. }else{
  2115. this.close();
  2116. }
  2117. }
  2118. },
  2119. {
  2120. "type": "cancel",
  2121. "text": MWF.LP.process.button.cancel,
  2122. "action": function(){
  2123. if(options.close){
  2124. var flag = options.close.call(this);
  2125. if( flag === true || o2.typeOf(flag) === "null" )this.close();
  2126. }else{
  2127. this.close();
  2128. }
  2129. }
  2130. }
  2131. ]
  2132. };
  2133. var positionNode;
  2134. if( options.content ) {
  2135. opts.content = options.content;
  2136. var parent = opts.content.getParent();
  2137. if(parent)positionNode = new Element("div", {style:"display:none;"}).inject( opts.content, "before" );
  2138. }
  2139. opts.onQueryClose = function(){
  2140. if( positionNode && opts.content ){
  2141. opts.content.inject( positionNode, "after" );
  2142. positionNode.destroy();
  2143. }
  2144. if( o2.typeOf(options.onQueryClose) === "function" )options.onQueryClose.call( this );
  2145. }
  2146. for( var key in options ){
  2147. if( !opts.hasOwnProperty( key ) ){
  2148. opts[key] = options[key];
  2149. }
  2150. }
  2151. var dialog;
  2152. MWF.require("MWF.xDesktop.Dialog", function(){
  2153. dialog = o2.DL.open(opts)
  2154. }, null, false);
  2155. return dialog;
  2156. },
  2157. //api 使用 结束
  2158. loadObserver: function(){
  2159. if( this.io ){
  2160. this.io.disconnect();
  2161. this.io = null;
  2162. }
  2163. if( !this.options.lazy )return;
  2164. if (typeof window !== 'undefined' && window.IntersectionObserver) {
  2165. this.io = new IntersectionObserver( function (entries, observer) {
  2166. entries.forEach(function (entry) {
  2167. if (entry.intersectionRatio > 0 || entry.isIntersecting) {
  2168. var item = entry.target.retrieve("item");
  2169. if( item && !item.loading && !item.loaded){ //已经加载完成
  2170. item.active();
  2171. }
  2172. observer.unobserve(entry.target);
  2173. }
  2174. })
  2175. }, {
  2176. root: this.contentAreaNode,
  2177. rootMargin: "10px 0px 0px 0px"
  2178. });
  2179. }
  2180. },
  2181. loadIOResource: function (callback) {
  2182. if( !this.options.lazy ){
  2183. callback();
  2184. return;
  2185. }
  2186. var observerPath = "../o2_lib/IntersectionObserver/intersection-observer.min.js";
  2187. var observerPath_ie11 = "../o2_lib/IntersectionObserver/polyfill_ie11.min.js";
  2188. if( window.IntersectionObserver && window.MutationObserver) {
  2189. if(callback)callback();
  2190. }else if( !!window.MSInputMethodContext && !!document.documentMode ){ //ie11
  2191. o2.load(observerPath_ie11, function () { callback(); }.bind(this));
  2192. }else{
  2193. o2.load([observerPath, observerPath_ie11], function () { callback(); }.bind(this));
  2194. }
  2195. },
  2196. createExportNode: function(){
  2197. if (this.options.export){
  2198. MWF.require("MWF.widget.Toolbar", function(){
  2199. this.toolbar = new MWF.widget.Toolbar(this.actionbarAreaNode, {"style": "simple"}, this); //this.exportAreaNode
  2200. var actionNode = new Element("div", {
  2201. "id": "",
  2202. "MWFnodetype": "MWFToolBarButton",
  2203. "MWFButtonImage": this.path+""+this.options.style+"/icon/export.png",
  2204. "title": this.lp.exportExcel,
  2205. "MWFButtonAction": "exportView",
  2206. "MWFButtonText": this.lp.exportExcel
  2207. }).inject(this.actionbarAreaNode); //this.exportAreaNode
  2208. this.toolbar.load();
  2209. }.bind(this));
  2210. //this.exportNode = new Element("button", {"text": this.lp.exportExcel}).inject(this.exportAreaNode);
  2211. }
  2212. },
  2213. getExportTotalCount: function(){
  2214. return ( this.bundleItems || [] ).length;
  2215. },
  2216. getExportMaxCount: function(){
  2217. return 2000;
  2218. },
  2219. exportView: function(){
  2220. var _self = this;
  2221. var total = this.getExportTotalCount();
  2222. var max = this.getExportMaxCount();
  2223. var lp = this.lp.viewExport;
  2224. var node = this.exportExcelDlgNode = new Element("div");
  2225. var html = "<div style=\"line-height: 30px; height: 30px; color: #333333; overflow: hidden;margin-top:20px;\">" + lp.fileName + ":" +
  2226. " <input class='filename' value='' style='margin-left: 14px;width: 350px;'><span>"+
  2227. "</div>";
  2228. html += "<div style=\"line-height: 30px; height: 30px; color: #333333; overflow: hidden;margin-top:20px;\">" + lp.exportRange + ":" +
  2229. " <input class='start' value='" + ( this.exportExcelStart || 1) + "'><span>"+ lp.to +"</span>" +
  2230. " <input class='end' value='"+ ( this.exportExcelEnd || Math.min( total, max ) ) +"' ><span>"+lp.item+"</span>" +
  2231. "</div>";
  2232. html += "<div style=\"clear:both; max-height: 300px; margin-bottom:10px; margin-top:10px; overflow-y:auto;\">"+( lp.description.replace("{count}", total ))+"</div>";
  2233. node.set("html", html);
  2234. var check = function () {
  2235. if(this.value.length == 1){
  2236. this.value = this.value.replace(/[^1-9]/g,'')
  2237. }else{
  2238. this.value = this.value.replace(/\D/g,'')
  2239. }
  2240. if( this.value.toInt() > total ){
  2241. this.value = total;
  2242. }
  2243. }
  2244. node.getElement(".start").addEvent( "keyup", function(){ check.call(this) } );
  2245. node.getElement(".end").addEvent( "keyup", function(){ check.call(this) } );
  2246. var dlg = o2.DL.open({
  2247. "title": this.lp.exportExcel,
  2248. "style": "user",
  2249. "isResize": false,
  2250. "content": node,
  2251. "width": 600,
  2252. "height" : 260,
  2253. "buttonList": [
  2254. {
  2255. "type": "ok",
  2256. "text": MWF.LP.process.button.ok,
  2257. "action": function (d, e) {
  2258. var start = node.getElement(".start").get("value");
  2259. var end = node.getElement(".end").get("value");
  2260. var filename = node.getElement(".filename").get("value");
  2261. if( !start || !end ){
  2262. MWF.xDesktop.notice("error", {"x": "left", "y": "top"}, lp.inputIntegerNotice, node, {"x": 0, "y": 85});
  2263. return false;
  2264. }
  2265. start = start.toInt();
  2266. end = end.toInt();
  2267. if( end < start ){
  2268. MWF.xDesktop.notice("error", {"x": "left", "y": "top"}, lp.startLargetThanEndNotice, node, {"x": 0, "y": 85});
  2269. return false;
  2270. }
  2271. this.exportExcelStart = start;
  2272. this.exportExcelEnd = end;
  2273. this._exportView(start, end, filename);
  2274. dlg.close();
  2275. }.bind(this)
  2276. },
  2277. {
  2278. "type": "cancel",
  2279. "text": MWF.LP.process.button.cancel,
  2280. "action": function () { dlg.close(); }
  2281. }
  2282. ]
  2283. });
  2284. },
  2285. // _exportView: function(start, end, filename){
  2286. //
  2287. // var bundleList = this.bundleItems.slice(start-1, end);
  2288. // var excelName = filename || (this.json.name + "(" + start + "-" + end + ").xlsx");
  2289. //
  2290. // var action = MWF.Actions.get("x_query_assemble_surface");
  2291. //
  2292. // var filterData = this.json.filter ? this.json.filter.clone() : [];
  2293. // if (this.filterItems.length){
  2294. // this.filterItems.each(function(filter){
  2295. // filterData.push(filter.data);
  2296. // }.bind(this));
  2297. // }
  2298. // var data = {"filterList": filterData};
  2299. // if( bundleList )data.bundleList = bundleList;
  2300. // if( excelName )data.excelName = excelName;
  2301. // data.key = this.bundleKey;
  2302. // action.exportViewWithQuery(this.json.viewName, this.json.application, data, function(json){
  2303. // var uri = action.action.actions.getViewExcel.uri;
  2304. // uri = uri.replace("{flag}", json.data.id);
  2305. // uri = o2.filterUrl( action.action.address+uri );
  2306. // var a = new Element("a", {"href": uri, "target":"_blank"});
  2307. // a.click();
  2308. // a.destroy();
  2309. // }.bind(this));
  2310. // },
  2311. _exportView: function(start, end, filename){
  2312. var excelName = filename || (this.json.name + "(" + start + "-" + end + ").xlsx");
  2313. // var p = this.currentPage;
  2314. // var d = {
  2315. // "filterList": this.filterList,
  2316. // "parameter": this.parameter
  2317. // };
  2318. this.createLoadding();
  2319. var exportArray = [];
  2320. var titleArray = [];
  2321. var colWidthArr = [];
  2322. var dateIndexArray = [];
  2323. var numberIndexArray = [];
  2324. var totalArray = [];
  2325. var idx = 0;
  2326. if (this.viewJson.isSequence === "yes") {
  2327. titleArray.push( this.lp.sequence );
  2328. colWidthArr.push(100);
  2329. totalArray.push('');
  2330. idx = idx + 1;
  2331. }
  2332. Object.each(this.entries, function (c, k) {
  2333. if (this.hideColumns.indexOf(k) === -1 && c.exportEnable !== false) {
  2334. titleArray.push(c.displayName);
  2335. colWidthArr.push(c.exportWidth || 200);
  2336. if( c.isTime )dateIndexArray.push(idx);
  2337. if( c.isNumber )numberIndexArray.push(idx);
  2338. totalArray.push( ['number', 'count'].contains(c.total) ? new Decimal(0) : '' );
  2339. idx++;
  2340. }
  2341. }.bind(this));
  2342. exportArray.push(titleArray);
  2343. this.loadExportData(start, end, function (dataList) {
  2344. var rowIndex = 0;
  2345. dataList.grid.each(function (data, i) {
  2346. // data.each(function (d, i) {
  2347. var d = data.data;
  2348. rowIndex = rowIndex + 1;
  2349. var columnIndex = 0;
  2350. var dataArray = [];
  2351. if (this.viewJson.isSequence === "yes") {
  2352. dataArray.push( (start-1)+rowIndex );
  2353. columnIndex++;
  2354. }
  2355. Object.each(this.entries, function (c, k) {
  2356. if (this.hideColumns.indexOf(k) === -1 && c.exportEnable !== false) {
  2357. var text = this.getExportText(c, k, d);
  2358. dataArray.push( text );
  2359. switch (c.total){
  2360. case 'number':
  2361. if( parseFloat(text).toString() !== "NaN" ) { //可以转成数字
  2362. totalArray[columnIndex] = totalArray[columnIndex].plus(text);
  2363. }
  2364. break;
  2365. case 'count':
  2366. totalArray[columnIndex] = totalArray[columnIndex].plus(1);
  2367. break;
  2368. }
  2369. columnIndex++;
  2370. }
  2371. }.bind(this));
  2372. //exportRow事件
  2373. var argu = {"index":rowIndex, "source": d, "data":dataArray};
  2374. this.fireEvent("exportRow", [argu]);
  2375. exportArray.push( argu.data || dataArray );
  2376. // }.bind(this));
  2377. }.bind(this));
  2378. var hasTotal = false;
  2379. totalArray = totalArray.map(function (d){
  2380. if( d ){
  2381. hasTotal = true;
  2382. return d.toString();
  2383. }else{
  2384. return '';
  2385. }
  2386. });
  2387. if( hasTotal ){
  2388. totalArray[0] = MWF.xApplication.query.Query.LP.total + " " + totalArray[0];
  2389. exportArray.push( totalArray );
  2390. }
  2391. var headTextScript = this.viewJson.exportHeadText;
  2392. var headText = headTextScript ? this.Macro.exec(headTextScript, this) : '';
  2393. var headStyleScript = this.viewJson.exportHeadStyle;
  2394. var headStyle = headStyleScript ? this.Macro.exec(headStyleScript, this) : null;
  2395. var titleStyleScript = this.viewJson.exportColumnTitleStyle;
  2396. var titleStyle = titleStyleScript ? this.Macro.exec(titleStyleScript, this) : null;
  2397. var contentStyleScript = this.viewJson.exportColumnContentStyle;
  2398. var contentStyle = contentStyleScript ? this.Macro.exec(contentStyleScript, this) : null;
  2399. //export事件
  2400. var arg = {
  2401. headText: headText,
  2402. headStyle: headStyle,
  2403. titleStyle: titleStyle,
  2404. contentStyle: contentStyle,
  2405. data : exportArray,
  2406. colWidthArray : colWidthArr,
  2407. title : excelName
  2408. };
  2409. this.fireEvent("export", [arg]);
  2410. if (this.loadingAreaNode) {
  2411. this.loadingAreaNode.destroy();
  2412. this.loadingAreaNode = null;
  2413. }
  2414. var options = {};
  2415. if( arg.headText )options.headText = arg.headText;
  2416. if( arg.headStyle )options.headStyle = arg.headStyle;
  2417. if( arg.titleStyle )options.columnTitleStyle = arg.titleStyle;
  2418. if( arg.contentStyle )options.columnContentStyle = arg.contentStyle;
  2419. new MWF.xApplication.query.Query.Viewer.ExcelUtils(
  2420. options
  2421. ).exportToExcel(
  2422. arg.data || exportArray,
  2423. arg.title || excelName,
  2424. arg.colWidthArray || colWidthArr,
  2425. dateIndexArray, //日期格式列下标
  2426. numberIndexArray //数字格式列下标
  2427. );
  2428. }.bind(this))
  2429. },
  2430. loadExportData: function(start, end, callback){
  2431. var bundleList = this.bundleItems.slice(start-1, end);
  2432. var filterData = this.json.filter ? this.json.filter.clone() : [];
  2433. if (this.filterItems.length){
  2434. this.filterItems.each(function(filter){
  2435. filterData.push(filter.data);
  2436. }.bind(this));
  2437. }
  2438. var data = {"filterList": filterData};
  2439. if( bundleList )data.bundleList = bundleList;
  2440. data.key = this.bundleKey;
  2441. var p = o2.Actions.load("x_query_assemble_surface").ViewAction.executeWithQuery(
  2442. this.json.viewName,
  2443. this.json.application,
  2444. data
  2445. );
  2446. Promise.resolve( p ).then(function (json) {
  2447. callback(json.data);
  2448. });
  2449. },
  2450. getExportText: function(column, key, data){
  2451. var text = data[key];
  2452. switch (typeOf(text)){
  2453. case 'string':
  2454. return text;
  2455. case 'array':
  2456. return text.join(',');
  2457. default:
  2458. return text;
  2459. }
  2460. }
  2461. });
  2462. /** @classdesc ViewerItem 数据中心的视图条目。本章节的脚本上下文请看<b>{@link module:queryView|queryView}。</b>
  2463. * @class
  2464. * @o2cn 视图条目(行)
  2465. * @o2category QueryView
  2466. * @o2range {QueryView}
  2467. * @hideconstructor
  2468. * @example
  2469. * //在视图中获取行
  2470. * var item = this.target.items[0];
  2471. */
  2472. MWF.xApplication.query.Query.Viewer.Item = new Class(
  2473. /** @lends MWF.xApplication.query.Query.Viewer.Item# */
  2474. {
  2475. initialize: function(view, data, prev, i, category, lazy){
  2476. /**
  2477. * 加载对应列的每个单元格后触发。可通过this.target获取以下对象:
  2478. * <pre><code class='language-js'>{
  2479. * "json ": {}, //当前行配置
  2480. * "data": "", //当前单元格数据,可能是字符串、数组、布尔值。
  2481. * "node": td, //当前单元格
  2482. * "view": view, //当前视图对象
  2483. * "row": {} //当前行的平台类对象
  2484. * }</code></pre>
  2485. * @event MWF.xApplication.query.Query.Viewer.Item#loadContent
  2486. */
  2487. /**
  2488. * 加载对应列的每个单元格后触发。可通过this.target获取以下对象:
  2489. * <pre><code class='language-js'>{
  2490. * "json ": {}, //当前行配置
  2491. * "data": "", //当前单元格数据,可能是字符串、数组、布尔值。
  2492. * "node": td, //当前单元格
  2493. * "view": view, //当前视图对象
  2494. * "row": {} //当前行的平台类对象
  2495. * }</code></pre>
  2496. * @event MWF.xApplication.query.Query.Viewer.Item#click
  2497. */
  2498. /**
  2499. * @summary 行所属视图.
  2500. * @member {Object}
  2501. */
  2502. this.view = view;
  2503. /**
  2504. * @summary 行数据.
  2505. * @member {Object}
  2506. */
  2507. this.data = data;
  2508. this.css = this.view.css;
  2509. /**
  2510. * @summary 行是否被选中.
  2511. * @member {Boolean}
  2512. */
  2513. this.isSelected = false;
  2514. /**
  2515. * @summary 如果视图有分类,获取分类对象。
  2516. * @member {Object}
  2517. */
  2518. this.category = category;
  2519. this.prev = prev;
  2520. this.idx = i;
  2521. this.clazzType = "item";
  2522. this.lazy = lazy;
  2523. this.odd = this.view.items.length % 2 === 1;
  2524. this.load();
  2525. },
  2526. load: function(){
  2527. if( this.lazy && this.view.io ){
  2528. this.view.fireEvent("queryLoadItemRow", [this]);
  2529. this.loadNode();
  2530. this.view.io.observe( this.node );
  2531. }else{
  2532. this._load();
  2533. }
  2534. },
  2535. active: function(){
  2536. if( !this.loaded && !this.loading ){
  2537. this._load();
  2538. }
  2539. },
  2540. loadNode: function(){
  2541. var viewStyles = this.view.viewJson.viewStyles;
  2542. var trStyle = ( viewStyles && viewStyles["contentTr"] ) ? viewStyles["contentTr"] : this.css.viewContentTrNode;
  2543. this.node = new Element("tr", {
  2544. "styles": trStyle
  2545. });
  2546. if (this.prev){
  2547. this.node.inject(this.prev.node, "after");
  2548. }else{
  2549. this.node.inject(this.view.viewTable);
  2550. }
  2551. this.node.store("item", this);
  2552. if( this.lazy && this.view.io ) {
  2553. var viewContentTdNode = ( viewStyles && viewStyles["contentTd"] ) ? viewStyles["contentTd"] : this.css.viewContentTdNode;
  2554. this.placeholderTd = new Element("td", {
  2555. "styles": viewContentTdNode
  2556. }).inject(this.node)
  2557. }
  2558. },
  2559. _load: function(){
  2560. this.loading = true;
  2561. if(!this.node)this.view.fireEvent("queryLoadItemRow", [this]);
  2562. var viewStyles = this.view.viewJson.viewStyles;
  2563. var viewContentTdNode = ( viewStyles && viewStyles["contentTd"] ) ? viewStyles["contentTd"] : this.css.viewContentTdNode;
  2564. if( this.odd ){
  2565. viewContentTdNode = ( viewStyles && viewStyles["zebraContentTd"] && Object.keys(viewStyles["zebraContentTd"].length > 0)) ? viewStyles["zebraContentTd"] : viewContentTdNode;
  2566. }
  2567. if(!this.node)this.loadNode();
  2568. //if (this.view.json.select==="single" || this.view.json.select==="multi"){
  2569. this.selectTd = new Element("td", { "styles": viewContentTdNode }).inject(this.node);
  2570. this.selectTd.setStyles({"cursor": "pointer"});
  2571. if (this.view.json.itemStyles) this.selectTd.setStyles(this.view.json.itemStyles);
  2572. //var selectFlag = this.view.json.select || this.view.viewJson.select || "none";
  2573. var selectFlag = this.view.getSelectFlag();
  2574. if ( this.data.$selectedEnable && ["multi","single"].contains(selectFlag) && this.view.viewJson.selectBoxShow==="always") {
  2575. var viewStyles = this.view.viewJson.viewStyles;
  2576. if (viewStyles) {
  2577. if (selectFlag === "single") {
  2578. this.selectTd.setStyles(viewStyles["radioNode"]);
  2579. } else {
  2580. this.selectTd.setStyles(viewStyles["checkboxNode"]);
  2581. }
  2582. } else {
  2583. var iconName = "checkbox";
  2584. if (selectFlag === "single") iconName = "radiobox";
  2585. this.selectTd.setStyles({"background": "url(" + "../x_component_query_Query/$Viewer/default/icon/" + iconName + ".png) center center no-repeat"});
  2586. }
  2587. }
  2588. if( this.view.isSelectTdHidden() ){
  2589. this.selectTd.hide();
  2590. }
  2591. //}
  2592. //序号
  2593. var sequence = 1+this.view.json.pageSize*(this.view.currentPage-1)+this.idx;
  2594. this.data["$sequence"] = sequence;
  2595. if (this.view.viewJson.isSequence==="yes"){
  2596. this.sequenceTd = new Element("td", {"styles": viewContentTdNode}).inject(this.node);
  2597. this.sequenceTd.setStyles({
  2598. "width": "30px",
  2599. "text-align": "center"
  2600. });
  2601. if (this.view.json.itemStyles) this.sequenceTd.setStyles(this.view.json.itemStyles);
  2602. this.sequenceTd.set("text", sequence);
  2603. }
  2604. Object.each(this.view.entries, function(c, k){
  2605. var cell = this.data.data[k];
  2606. if (cell === undefined) cell = "";
  2607. //if (cell){
  2608. if (this.view.hideColumns.indexOf(k)===-1){
  2609. var td = new Element("td", {"styles": viewContentTdNode}).inject(this.node);
  2610. if (k!== this.view.viewJson.group.column){
  2611. //var v = (this.view.entries[k].code) ? MWF.Macro.exec(this.view.entries[k].code, {"value": cell, "gridData": this.view.gridJson, "data": this.view.viewData, "entry": this.data}) : cell;
  2612. var v = cell;
  2613. if (c.isHtml){
  2614. td.set("html", v);
  2615. }else{
  2616. td.set("text", v);
  2617. }
  2618. if( typeOf(c.contentProperties) === "object" )td.setProperties(c.contentProperties);
  2619. if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
  2620. if( typeOf(c.contentStyles) === "object" )td.setStyles(c.contentStyles);
  2621. }else{
  2622. if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
  2623. }
  2624. if (this.view.openColumns.indexOf(k)!==-1){
  2625. this.setOpenWork(td, c)
  2626. }
  2627. if (k!== this.view.viewJson.group.column){
  2628. Object.each( c.events || {}, function (e , key) {
  2629. if(e.code){
  2630. if( key === "loadContent" ){
  2631. this.view.Macro.fire( e.code,
  2632. {"node" : td, "json" : c, "data" : v, "view": this.view, "row" : this});
  2633. }else if( key !== "loadTitle" ){
  2634. td.addEvent(key, function(event){
  2635. return this.view.Macro.fire(
  2636. e.code,
  2637. {"node" : td, "json" : c, "data" : v, "view": this.view, "row" : this},
  2638. event
  2639. );
  2640. }.bind(this));
  2641. }
  2642. }
  2643. }.bind(this));
  2644. }
  2645. }
  2646. //}
  2647. }.bind(this));
  2648. if(this.placeholderTd){
  2649. this.placeholderTd.destroy();
  2650. this.placeholderTd = null;
  2651. }
  2652. //默认选中
  2653. var selectedFlag;
  2654. var defaultSelectedScript = this.view.json.defaultSelectedScript || this.view.viewJson.defaultSelectedScript;
  2655. if( !this.isSelected && defaultSelectedScript ){
  2656. // var flag = this.view.json.select || this.view.viewJson.select || "none";
  2657. // if ( flag ==="single" || flag==="multi"){
  2658. //
  2659. // }
  2660. switch (typeOf(defaultSelectedScript)) {
  2661. case "string":
  2662. selectedFlag = this.view.Macro.exec( defaultSelectedScript,
  2663. {"node" : this.node, "data" : this.data, "view": this.view, "row" : this});
  2664. break;
  2665. case "function":
  2666. selectedFlag = defaultSelectedScript({"node" : this.node, "data" : this.data, "view": this.view, "row" : this});
  2667. break;
  2668. }
  2669. }
  2670. //判断是不是在selectedItems中,用户手工选择
  2671. if( !this.isSelected && this.view.selectedItems.length ){
  2672. for(var i=0; i<this.view.selectedItems.length; i++){
  2673. if( this.view.selectedItems[i].data.bundle === this.data.bundle ){
  2674. selectedFlag = "true";
  2675. break;
  2676. }
  2677. }
  2678. }
  2679. if( selectedFlag ){
  2680. if( selectedFlag === "multi" || selectedFlag === "single" ){
  2681. this.select( selectedFlag );
  2682. }else if( selectedFlag.toString() === "true" ){
  2683. var f = this.view.json.select || this.view.viewJson.select || "none";
  2684. if ( f ==="single" || f==="multi"){
  2685. this.select();
  2686. }
  2687. }
  2688. }
  2689. // Object.each(this.data.data, function(cell, k){
  2690. // if (this.view.hideColumns.indexOf(k)===-1){
  2691. // var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(this.node);
  2692. // if (k!== this.view.viewJson.group.column){
  2693. // var v = (this.view.entries[k].code) ? MWF.Macro.exec(this.view.entries[k].code, {"value": cell, "gridData": this.view.gridJson, "data": this.view.viewData, "entry": this.data}) : cell;
  2694. // td.set("text", v);
  2695. // }
  2696. // if (this.view.openColumns.indexOf(k)!==-1){
  2697. // this.setOpenWork(td)
  2698. // }
  2699. // if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
  2700. // }
  2701. // }.bind(this));
  2702. this.setEvent();
  2703. this.view.fireEvent("postLoadItemRow", [this]);
  2704. this.loading = false;
  2705. this.loaded = true;
  2706. },
  2707. setOpenWork: function(td, column){
  2708. td.setStyle("cursor", "pointer");
  2709. if( column.clickCode ){
  2710. // if( !this.view.Macro ){
  2711. // MWF.require("MWF.xScript.Macro", function () {
  2712. // this.view.businessData = {};
  2713. // this.view.Macro = new MWF.Macro.PageContext(this.view);
  2714. // }.bind(this), false);
  2715. // }
  2716. td.addEvent("click", function( ev ){
  2717. var result = this.view.Macro.fire(column.clickCode, this, ev);
  2718. ev.stopPropagation();
  2719. return result;
  2720. }.bind(this));
  2721. }else{
  2722. if (this.view.json.type==="cms"){
  2723. td.addEvent("click", function(ev){
  2724. this.openCms(ev)
  2725. ev.stopPropagation();
  2726. }.bind(this));
  2727. }else{
  2728. td.addEvent("click", function(ev){
  2729. this.openWorkAndCompleted(ev)
  2730. ev.stopPropagation();
  2731. }.bind(this));
  2732. }
  2733. }
  2734. },
  2735. openCms: function(e){
  2736. var options = {"documentId": this.data.bundle};
  2737. this.view.fireEvent("openDocument", [options, this]); //options 传入的事件
  2738. layout.desktop.openApplication(e, "cms.Document", options);
  2739. },
  2740. openWorkAndCompleted: function(e){
  2741. var options = {"jobId": this.data.bundle};
  2742. this.view.fireEvent("openDocument", [options, this]); //options 传入的事件
  2743. layout.desktop.openApplication(e, "process.Work", options);
  2744. // MWF.Actions.get("x_processplatform_assemble_surface").listWorkByJob(this.data.bundle, function(json){
  2745. // var workCompletedCount = json.data.workCompletedList.length;
  2746. // var workCount = json.data.workList.length;
  2747. // var count = workCount+workCompletedCount;
  2748. // if (count===1){
  2749. // if (workCompletedCount) {
  2750. // this.openWorkCompleted(json.data.workCompletedList[0].id, e);
  2751. // }else{
  2752. // this.openWork(json.data.workList[0].id, e);
  2753. // }
  2754. // }else if (count>1){
  2755. // var worksAreaNode = this.createWorksArea();
  2756. // json.data.workCompletedList.each(function(work){
  2757. // this.createWorkCompletedNode(work, worksAreaNode);
  2758. // }.bind(this));
  2759. // json.data.workList.each(function(work){
  2760. // this.createWorkNode(work, worksAreaNode);
  2761. // }.bind(this));
  2762. // this.showWorksArea(worksAreaNode, e);
  2763. // }else{
  2764. //
  2765. // }
  2766. // }.bind(this));
  2767. },
  2768. createWorkNode: function(work, worksAreaNode){
  2769. var worksAreaContentNode = worksAreaNode.getLast();
  2770. var node = new Element("div", {"styles": this.css.workAreaNode}).inject(worksAreaContentNode);
  2771. var actionNode = new Element("div", {"styles": this.css.workAreaActionNode, "text": this.view.lp.open}).inject(node);
  2772. actionNode.store("workId", work.id);
  2773. actionNode.addEvent("click", function(e){
  2774. this.openWork(e.target.retrieve("workId"), e);
  2775. this.mask.hide();
  2776. worksAreaNode.destroy();
  2777. }.bind(this));
  2778. var areaNode = new Element("div", {"styles": this.css.workAreaLeftNode}).inject(node);
  2779. var titleNode = new Element("div", {"styles": this.css.workAreaTitleNode, "text": work.title}).inject(areaNode);
  2780. var contentNode = new Element("div", {"styles": this.css.workAreaContentNode}).inject(areaNode);
  2781. new Element("div", {"styles": this.css.workAreaContentTitleNode, "text": this.view.lp.activity+": "}).inject(contentNode);
  2782. new Element("div", {"styles": this.css.workAreaContentTextNode, "text": work.activityName}).inject(contentNode);
  2783. var taskUsers = [];
  2784. MWF.Actions.get("x_processplatform_assemble_surface").listTaskByWork(work.id, function(json){
  2785. json.data.each(function(task){
  2786. taskUsers.push(MWF.name.cn(task.person));
  2787. }.bind(this));
  2788. new Element("div", {"styles": this.css.workAreaContentTitleNode, "text": this.view.lp.taskPeople+": "}).inject(contentNode);
  2789. new Element("div", {"styles": this.css.workAreaContentTextNode, "text": taskUsers.join(", ")}).inject(contentNode);
  2790. }.bind(this));
  2791. },
  2792. createWorkCompletedNode: function(work, worksAreaNode){
  2793. var worksAreaContentNode = worksAreaNode.getLast();
  2794. var node = new Element("div", {"styles": this.css.workAreaNode}).inject(worksAreaContentNode);
  2795. var actionNode = new Element("div", {"styles": this.css.workAreaActionNode, "text": this.view.lp.open}).inject(node);
  2796. actionNode.store("workId", work.id);
  2797. actionNode.addEvent("click", function(e){
  2798. this.mask.hide();
  2799. var id = e.target.retrieve("workId");
  2800. worksAreaNode.destroy();
  2801. this.openWorkCompleted(id, e);
  2802. }.bind(this));
  2803. var areaNode = new Element("div", {"styles": this.css.workAreaLeftNode}).inject(node);
  2804. var titleNode = new Element("div", {"styles": this.css.workAreaTitleNode, "text": work.title}).inject(areaNode);
  2805. var contentNode = new Element("div", {"styles": this.css.workAreaContentNode}).inject(areaNode);
  2806. new Element("div", {"styles": this.css.workAreaContentTitleNode, "text": this.view.lp.activity+": "}).inject(contentNode);
  2807. new Element("div", {"styles": this.css.workAreaContentTextNode, "text": this.view.lp.processCompleted}).inject(contentNode);
  2808. },
  2809. createWorksArea: function(){
  2810. var cssWorksArea = this.css.worksAreaNode
  2811. if (layout.mobile) {
  2812. cssWorksArea = this.css.worksAreaNodeMobile;
  2813. }
  2814. var worksAreaNode = new Element("div", {"styles": cssWorksArea});
  2815. var worksAreaTitleNode = new Element("div", {"styles": this.css.worksAreaTitleNode}).inject(worksAreaNode);
  2816. var worksAreaTitleCloseNode = new Element("div", {"styles": this.css.worksAreaTitleCloseNode}).inject(worksAreaTitleNode);
  2817. worksAreaTitleCloseNode.addEvent("click", function(e){
  2818. this.mask.hide();
  2819. e.target.getParent().getParent().destroy();
  2820. }.bind(this));
  2821. var worksAreaContentNode = new Element("div", {"styles": this.css.worksAreaContentNode}).inject(worksAreaNode);
  2822. return worksAreaNode;
  2823. },
  2824. showWorksArea: function(node, e){
  2825. MWF.require("MWF.widget.Mask", null, false);
  2826. this.mask = new MWF.widget.Mask({"style": "desktop", "loading": false});
  2827. this.mask.loadNode(this.view.container);
  2828. node.inject(this.view.node);
  2829. this.setWorksAreaPosition(node, e.target);
  2830. },
  2831. setWorksAreaPosition: function(node, td){
  2832. var p = td.getPosition(this.view.container);
  2833. var containerS = this.view.container.getSize();
  2834. var containerP = this.view.container.getPosition(this.view.container.getOffsetParent());
  2835. var s = node.getSize();
  2836. var offX = p.x+s.x-containerS.x;
  2837. offX = (offX>0) ? offX+20 : 0;
  2838. var offY = p.y+s.y-containerS.y;
  2839. offY = (offY>0) ? offY+5 : 0;
  2840. node.position({
  2841. "relativeTo": td,
  2842. "position": "lefttop",
  2843. "edge": "lefttop",
  2844. "offset": {
  2845. "x": 0-offX,
  2846. "y": 0-offY
  2847. }
  2848. });
  2849. },
  2850. openWork: function(id, e){
  2851. var options = {"workId": id};
  2852. this.view.fireEvent("openDocument", [options, this]); //options 传入的事件
  2853. layout.desktop.openApplication(e, "process.Work", options);
  2854. },
  2855. openWorkCompleted: function(id, e){
  2856. var options = {"workCompletedId": id};
  2857. this.view.fireEvent("openDocument", [options, this]); //options 传入的事件
  2858. layout.desktop.openApplication(e, "process.Work", options);
  2859. },
  2860. setEvent: function(){
  2861. var flag = this.view.getSelectFlag();
  2862. if ( this.data.$selectedEnable && (flag ==="single" || flag==="multi")){
  2863. this.node.addEvents({
  2864. "mouseover": function(){
  2865. if (!this.isSelected && this.view.viewJson.selectBoxShow !=="always" ){
  2866. var viewStyles = this.view.viewJson.viewStyles;
  2867. if( viewStyles ){
  2868. if( flag === "single" ){
  2869. this.selectTd.setStyles( viewStyles["radioNode"] );
  2870. }else{
  2871. this.selectTd.setStyles( viewStyles["checkboxNode"] );
  2872. }
  2873. }else{
  2874. var iconName = "checkbox";
  2875. if (flag==="single") iconName = "radiobox";
  2876. this.selectTd.setStyles({"background": "url("+"../x_component_query_Query/$Viewer/default/icon/"+iconName+".png) center center no-repeat"});
  2877. }
  2878. }
  2879. }.bind(this),
  2880. "mouseout": function(){
  2881. if (!this.isSelected && this.view.viewJson.selectBoxShow !=="always") this.selectTd.setStyles({"background": "transparent"});
  2882. }.bind(this),
  2883. "click": function(){this.select();}.bind(this)
  2884. });
  2885. }
  2886. },
  2887. select: function( force ){
  2888. // var flag = force || this.view.json.select || this.view.viewJson.select || "none";
  2889. var flag = force || this.view.getSelectFlag();
  2890. if (this.isSelected){
  2891. if (flag==="single"){
  2892. this.unSelectedSingle();
  2893. }else{
  2894. this.unSelected();
  2895. }
  2896. }else{
  2897. if (flag==="single"){
  2898. this.selectedSingle();
  2899. }else{
  2900. this.selected();
  2901. }
  2902. }
  2903. },
  2904. /**
  2905. * @summary 选中(多选)。
  2906. * @example
  2907. * item = this.target.items[0];
  2908. * item.selected();
  2909. */
  2910. selected: function( from ){
  2911. for(var i=0; i<this.view.selectedItems.length; i++){
  2912. var item = this.view.selectedItems[i];
  2913. if( item.data.bundle === this.data.bundle ){
  2914. this.view.selectedItems.erase(item);
  2915. break;
  2916. }
  2917. }
  2918. this.view.selectedItems.push(this);
  2919. var viewStyles = this.view.viewJson.viewStyles;
  2920. if( viewStyles ){
  2921. this.selectTd.setStyles( viewStyles["checkedCheckboxNode"] );
  2922. this.node.setStyles( viewStyles["contentSelectedTr"] );
  2923. }else{
  2924. this.selectTd.setStyles({"background": "url("+"../x_component_query_Query/$Viewer/default/icon/checkbox_checked.png) center center no-repeat"});
  2925. this.node.setStyles(this.css.viewContentTrNode_selected);
  2926. }
  2927. this.isSelected = true;
  2928. if( from !== "view" && from !=="category" && this.view.viewJson.allowSelectAll ){
  2929. this.view.checkSelectAllStatus();
  2930. if( this.category )this.category.checkSelectAllStatus();
  2931. }
  2932. this.view.fireEvent("selectRow", [this]);
  2933. this.view.fireEvent("select", [{
  2934. "selected": true,
  2935. "item": this,
  2936. "data": this.data
  2937. }]); //options 传入的事件
  2938. },
  2939. /**
  2940. * @summary 取消选中(多选)。
  2941. * @example
  2942. * item = this.target.items[0];
  2943. * item.unSelected();
  2944. */
  2945. unSelected: function( from ){
  2946. for(var i=0; i<this.view.selectedItems.length; i++){
  2947. var item = this.view.selectedItems[i];
  2948. if( item.data.bundle === this.data.bundle ){
  2949. this.view.selectedItems.erase(item);
  2950. break;
  2951. }
  2952. }
  2953. var viewStyles = this.view.viewJson.viewStyles;
  2954. if( this.view.viewJson.selectBoxShow !=="always" ){
  2955. this.selectTd.setStyles({"background": "transparent"});
  2956. }else{
  2957. if (viewStyles) {
  2958. this.selectTd.setStyles(viewStyles["checkboxNode"]);
  2959. }else{
  2960. this.selectTd.setStyles({"background": "url(" + "../x_component_query_Query/$Viewer/default/icon/checkbox.png) center center no-repeat"});
  2961. }
  2962. }
  2963. if( viewStyles ){
  2964. this.node.setStyles( viewStyles["contentTr"] );
  2965. }else{
  2966. this.node.setStyles(this.css.viewContentTrNode);
  2967. }
  2968. this.isSelected = false;
  2969. if( from !== "view" && from !=="category" && this.view.viewJson.allowSelectAll ){
  2970. this.view.checkSelectAllStatus();
  2971. if( this.category )this.category.checkSelectAllStatus();
  2972. }
  2973. this.view.fireEvent("unselectRow", [this]);
  2974. this.view.fireEvent("unselect", [{
  2975. "selected": false,
  2976. "item": this,
  2977. "data": this.data
  2978. }]); //options 传入的事件
  2979. },
  2980. /**
  2981. * @summary 选中(单选)。
  2982. * @example
  2983. * item = this.target.items[0];
  2984. * item.selectedSingle();
  2985. */
  2986. selectedSingle: function(){
  2987. if (this.view.currentSelectedItem) this.view.currentSelectedItem.unSelectedSingle();
  2988. this.view.selectedItems = [this];
  2989. this.view.currentSelectedItem = this;
  2990. var viewStyles = this.view.viewJson.viewStyles;
  2991. if( viewStyles ){
  2992. this.selectTd.setStyles( viewStyles["checkedRadioNode"] );
  2993. this.node.setStyles( viewStyles["contentSelectedTr"] );
  2994. }else {
  2995. this.selectTd.setStyles({"background": "url(" + "../x_component_query_Query/$Viewer/default/icon/radiobox_checked.png) center center no-repeat"});
  2996. this.node.setStyles(this.css.viewContentTrNode_selected);
  2997. }
  2998. this.isSelected = true;
  2999. this.view.fireEvent("selectRow", [this]);
  3000. this.view.fireEvent("select", [{
  3001. "selected": true,
  3002. "item": this,
  3003. "data": this.data
  3004. }]); //options 传入的事件
  3005. },
  3006. /**
  3007. * @summary 取消选中(单选)。
  3008. * @example
  3009. * item = this.target.items[0];
  3010. * item.unSelectedSingle();
  3011. */
  3012. unSelectedSingle: function(){
  3013. this.view.selectedItems = [];
  3014. this.view.currentSelectedItem = null;
  3015. var viewStyles = this.view.viewJson.viewStyles;
  3016. if( this.view.viewJson.selectBoxShow !=="always" ){
  3017. this.selectTd.setStyles({"background": "transparent"});
  3018. }else{
  3019. if (viewStyles) {
  3020. this.selectTd.setStyles(viewStyles["radioNode"]);
  3021. }else{
  3022. this.selectTd.setStyles({"background": "url(" + "../x_component_query_Query/$Viewer/default/icon/radiobox.png) center center no-repeat"});
  3023. }
  3024. }
  3025. if( viewStyles ){
  3026. this.node.setStyles( viewStyles["contentTr"] );
  3027. }else{
  3028. this.node.setStyles(this.css.viewContentTrNode);
  3029. }
  3030. this.isSelected = false;
  3031. this.view.fireEvent("unselectRow", [this]);
  3032. this.view.fireEvent("unselect", [{
  3033. "selected": false,
  3034. "item": this,
  3035. "data": this.data
  3036. }]); //options 传入的事件
  3037. }
  3038. });
  3039. MWF.xApplication.query.Query.Viewer.ItemCategory = new Class({
  3040. initialize: function(view, data, i){
  3041. this.view = view;
  3042. this.data = data;
  3043. this.css = this.view.css;
  3044. this.items = [];
  3045. this.loadChild = false;
  3046. this.idx = i;
  3047. this.clazzType = "category";
  3048. this.load();
  3049. },
  3050. load: function(){
  3051. this.view.fireEvent("queryLoadCategoryRow", [this]);
  3052. var viewStyles = this.view.viewJson.viewStyles;
  3053. var viewContentCategoryTdNode = ( viewStyles && viewStyles["contentGroupTd"] ) ? viewStyles["contentGroupTd"] : this.css.viewContentCategoryTdNode;
  3054. this.node = new Element("tr", {
  3055. "styles": (viewStyles && viewStyles["contentTr"]) ? viewStyles["contentTr"] : this.css.viewContentTrNode
  3056. }).inject(this.view.viewTable);
  3057. //if (this.view.json.select==="single" || this.view.json.select==="multi"){
  3058. this.selectTd = new Element("td", {"styles": viewContentCategoryTdNode}).inject(this.node);
  3059. if (this.view.json.itemStyles) this.selectTd.setStyles(this.view.json.itemStyles);
  3060. if( this.data.$selectedEnable && this.view.getSelectFlag() === "multi" && this.view.viewJson.allowSelectAll ){
  3061. this.selectAllNode = this.selectTd;
  3062. if( viewStyles && viewStyles["checkboxNode"] ){
  3063. this.selectAllNode.setStyles( viewStyles["checkboxNode"] )
  3064. // this.selectAllNode = new Element("span", {
  3065. // styles : viewStyles["checkboxNode"]
  3066. // }).inject( this.selectTd );
  3067. }else{
  3068. this.selectAllNode.set( "html", "<img src='../x_component_query_Query/$Viewer/"+this.options.style+"/icon/checkbox.png'/>"+"</span>" )
  3069. // this.selectAllNode = new Element("span",{
  3070. // html : "<img src='../x_component_query_Query/$Viewer/"+this.options.style+"/icon/checkbox.png'/>"+"</span>",
  3071. // style : "font-family: Webdings"
  3072. // }).inject( this.selectTd );
  3073. }
  3074. this.selectAllNode.setStyle("cursor", "pointer");
  3075. this.selectAllNode.addEvent("click", function (ev) {
  3076. if( this.getSelectAllStatus() === "all" ){
  3077. this.unSelectAll("category")
  3078. }else{
  3079. this.selectAll("category");
  3080. }
  3081. ev.stopPropagation();
  3082. }.bind(this));
  3083. }
  3084. // if( this.view.isSelectTdHidden() ){
  3085. // this.selectTd.hide();
  3086. // }
  3087. //}
  3088. this.categoryTd = new Element("td", {
  3089. "styles": viewContentCategoryTdNode,
  3090. "colspan": this.view.viewJson.selectList.length+1
  3091. }).inject(this.node);
  3092. this.groupColumn = null;
  3093. for (var c = 0; c<this.view.viewJson.selectList.length; c++){
  3094. if (this.view.viewJson.selectList[c].column === this.view.viewJson.group.column){
  3095. this.groupColumn = this.view.viewJson.selectList[c];
  3096. break;
  3097. }
  3098. }
  3099. if (this.groupColumn){
  3100. //var text = (this.groupColumn.code) ? MWF.Macro.exec(this.groupColumn.code, {"value": this.data.group, "gridData": this.view.gridJson, "data": this.view.viewData, "entry": this.data}) : this.data.group;
  3101. var text = this.data.group;
  3102. }else{
  3103. var text = this.data.group;
  3104. }
  3105. if( viewStyles && viewStyles["groupCollapseNode"] ){
  3106. this.expandNode = new Element("span", {
  3107. styles : viewStyles["groupCollapseNode"]
  3108. }).inject( this.categoryTd );
  3109. new Element("span", { text : text }).inject( this.categoryTd );
  3110. // this.categoryTd.set("text", text );
  3111. }else{
  3112. this.categoryTd.set("html", "<span style='font-family: Webdings'><img src='../x_component_query_Query/$Viewer/"+this.view.options.style+"/icon/expand.png'/></span> "+text);
  3113. }
  3114. this.expanded = false;
  3115. if (this.view.json.itemStyles) this.categoryTd.setStyles(this.view.json.itemStyles);
  3116. if( this.groupColumn ){
  3117. if( typeOf(this.groupColumn.contentStyles) === "object" )this.categoryTd.setStyles(this.groupColumn.contentStyles);
  3118. if( typeOf(this.groupColumn.contentProperties) === "object" )this.categoryTd.setProperties(this.groupColumn.contentProperties);
  3119. }
  3120. this.setEvent();
  3121. var column = this.groupColumn;
  3122. var td = this.categoryTd;
  3123. Object.each( column.events || {}, function (e , key) {
  3124. if(e.code){
  3125. if( key === "loadContent" ){
  3126. this.view.Macro.fire( e.code,
  3127. {"node" : td, "json" : column, "data" : this.data.group, "view": this.view, "row" : this});
  3128. }else if( key !== "loadTitle" ){
  3129. td.addEvent(key, function(event){
  3130. return this.view.Macro.fire(
  3131. e.code,
  3132. {"node" : td, "json" : column, "data" : this.data.group, "view": this.view, "row" : this},
  3133. event
  3134. );
  3135. }.bind(this));
  3136. }
  3137. }
  3138. }.bind(this));
  3139. this.view.fireEvent("postLoadCategoryRow", [this]);
  3140. },
  3141. getSelectAllStatus : function(){
  3142. if ( this.view.getSelectFlag()!=="multi")return;
  3143. if( !this.items.length )return "none";
  3144. var flag = "all";
  3145. var allFlag = true, noneFlag = true;
  3146. for( var i=0; i<this.items.length; i++ ){
  3147. var item = this.items[i];
  3148. if( item.data.$selectedEnable ){
  3149. item.isSelected ? ( noneFlag = false ) : (allFlag = false);
  3150. if( !allFlag && !noneFlag )return "some"
  3151. }
  3152. }
  3153. if( allFlag )return "all";
  3154. if( noneFlag )return "none";
  3155. return "some";
  3156. },
  3157. checkSelectAllStatus : function(){
  3158. if( !this.selectAllNode )return;
  3159. var status = this.getSelectAllStatus();
  3160. if( status === "all" ){
  3161. this.setSelectAllStyle()
  3162. }else{
  3163. this.setUnSelectAllStyle()
  3164. }
  3165. },
  3166. setSelectAllStyle : function () {
  3167. if( !this.selectAllNode )return;
  3168. if( this.view.viewJson.viewStyles && this.view.viewJson.viewStyles["checkedCheckboxNode"] ){
  3169. this.selectAllNode.setStyles( this.view.viewJson.viewStyles["checkedCheckboxNode"] );
  3170. }else {
  3171. this.selectAllNode.getElement("img").set("src",
  3172. '../x_component_query_Query/$Viewer/" + this.options.style + "/icon/checkbox_checked.png' )
  3173. }
  3174. },
  3175. setUnSelectAllStyle : function () {
  3176. if( !this.selectAllNode )return;
  3177. if( this.view.viewJson.viewStyles && this.view.viewJson.viewStyles["checkboxNode"] ){
  3178. this.selectAllNode.setStyles( this.view.viewJson.viewStyles["checkboxNode"] );
  3179. }else {
  3180. this.selectAllNode.getElement("img").set("src",
  3181. '../x_component_query_Query/$Viewer/" + this.options.style + "/icon/checkbox.png' )
  3182. }
  3183. },
  3184. selectAll : function( from ){
  3185. // var flag = this.json.select || this.viewJson.select || "none";
  3186. if ( this.view.getSelectFlag()==="multi"){
  3187. this.expand();
  3188. this.items.each( function (item) {
  3189. if( item.data.$selectedEnable ){
  3190. item.selected( from );
  3191. }
  3192. })
  3193. if( this.view.viewJson.allowSelectAll ){
  3194. this.setSelectAllStyle();
  3195. if( from !== "view" ){
  3196. this.view.checkSelectAllStatus();
  3197. }
  3198. }
  3199. }
  3200. },
  3201. unSelectAll : function( from ){
  3202. // var flag = this.json.select || this.viewJson.select || "none";
  3203. if ( this.view.getSelectFlag()==="multi"){
  3204. this.items.each( function (item) {
  3205. if( item.data.$selectedEnable ) {
  3206. item.unSelected(from);
  3207. }
  3208. })
  3209. if( this.view.viewJson.allowSelectAll ) {
  3210. this.setUnSelectAllStyle();
  3211. if (from !== "view") {
  3212. this.view.checkSelectAllStatus();
  3213. }
  3214. }
  3215. }
  3216. },
  3217. setEvent: function(){
  3218. //if (this.selectTd){
  3219. this.node.addEvents({
  3220. "click": function(){this.expandOrCollapse();}.bind(this)
  3221. });
  3222. //}
  3223. },
  3224. expandOrCollapse: function(){
  3225. // var t = this.node.getElement("span").get("html");
  3226. // if (t.indexOf("expand.png")===-1){
  3227. // this.collapse();
  3228. // }else{
  3229. // this.expand();
  3230. // }
  3231. if( this.expanded ){
  3232. this.collapse();
  3233. }else{
  3234. this.expand();
  3235. }
  3236. },
  3237. collapse: function( from ){
  3238. this.items.each(function(item){
  3239. item.node.setStyle("display", "none");
  3240. }.bind(this));
  3241. if( this.expandNode ){
  3242. this.expandNode.setStyles( this.view.viewJson.viewStyles["groupCollapseNode"] )
  3243. }else{
  3244. this.node.getElement("span").set("html", "<img src='../x_component_query_Query/$Viewer/"+this.view.options.style+"/icon/expand.png'/>");
  3245. }
  3246. this.expanded = false;
  3247. if( from !== "view" ){
  3248. this.view.checkExpandAllStatus();
  3249. }
  3250. },
  3251. expand: function( from ){
  3252. this.items.each(function(item){
  3253. item.node.setStyle("display", "table-row");
  3254. }.bind(this));
  3255. if( this.expandNode ){
  3256. this.expandNode.setStyles( this.view.viewJson.viewStyles["groupExpandNode"] )
  3257. }else{
  3258. this.node.getElement("span").set("html", "<img src='../x_component_query_Query/$Viewer/"+this.view.options.style+"/icon/down.png'/>");
  3259. }
  3260. this.expanded = true;
  3261. if (!this.loadChild){
  3262. //window.setTimeout(function(){
  3263. this.data.list.each(function(line, i){
  3264. var s = this.idx+i;
  3265. this.lastItem = new MWF.xApplication.query.Query.Viewer.Item(this.view, line, (this.lastItem || this), s, this, this.view.options.lazy);
  3266. this.items.push(this.lastItem);
  3267. }.bind(this));
  3268. this.loadChild = true;
  3269. //}.bind(this), 10);
  3270. }
  3271. if( from !== "view" ){
  3272. this.view.checkExpandAllStatus();
  3273. }
  3274. }
  3275. });
  3276. MWF.xApplication.query.Query.Viewer.Filter = new Class({
  3277. initialize: function(viewer, data, node){
  3278. this.viewer = viewer;
  3279. this.data = data;
  3280. this.css = this.viewer.css;
  3281. this.content = node;
  3282. this.load();
  3283. },
  3284. load: function(){
  3285. this.node = new Element("div", {"styles": this.css.viewSearchFilterNode}).inject(this.content);
  3286. if (this.viewer.filterItems.length){
  3287. this.logicNode = new Element("div", {"styles": this.css.viewSearchFilterSelectAreaNode}).inject(this.node);
  3288. this.logicSelectNode = new Element("div", {
  3289. "styles": this.css.viewSearchFilterSelectNode,
  3290. "text": this.viewer.lp.and,
  3291. "value": "and"
  3292. }).inject(this.logicNode);
  3293. this.logicSelectButtonNode = new Element("div", {"styles": this.css.viewSearchFilterSelectButtonNode}).inject(this.logicNode);
  3294. this.logicNode.addEvents({
  3295. "click": function(){
  3296. var v = this.logicSelectNode.get("value");
  3297. if (v==="and"){
  3298. this.logicSelectButtonNode.setStyle("float", "left");
  3299. this.logicSelectNode.setStyle("float", "right");
  3300. this.logicSelectNode.set({
  3301. "text": this.viewer.lp.or,
  3302. "value": "or"
  3303. });
  3304. this.data.logic = "or";
  3305. }else{
  3306. this.logicSelectButtonNode.setStyle("float", "right");
  3307. this.logicSelectNode.setStyle("float", "left");
  3308. this.logicSelectNode.set({
  3309. "text": this.viewer.lp.and,
  3310. "value": "and"
  3311. });
  3312. this.data.logic = "and";
  3313. }
  3314. this.viewer.searchCustomView();
  3315. }.bind(this)
  3316. });
  3317. }
  3318. this.titleNode = new Element("div", {"styles": this.css.viewSearchFilterTextNode, "text": this.data.title}).inject(this.node);
  3319. this.comparisonTitleNode = new Element("div", {"styles": this.css.viewSearchFilterTextNode, "text": this.data.comparisonTitle}).inject(this.node);
  3320. this.valueNode = new Element("div", {"styles": this.css.viewSearchFilterTextNode, "text": "\""+this.data.value+"\""}).inject(this.node);
  3321. this.deleteNode = new Element("div", {"styles": this.css.viewSearchFilterDeleteNode}).inject(this.node);
  3322. this.node.addEvents({
  3323. "mouseover": function(){
  3324. this.node.setStyles(this.css.viewSearchFilterNode_over);
  3325. this.deleteNode.setStyles(this.css.viewSearchFilterDeleteNode_over);
  3326. }.bind(this),
  3327. "mouseout": function(){
  3328. this.node.setStyles(this.css.viewSearchFilterNode);
  3329. this.deleteNode.setStyles(this.css.viewSearchFilterDeleteNode);
  3330. }.bind(this)
  3331. });
  3332. this.deleteNode.addEvent("click", function(){
  3333. this.viewer.searchViewRemoveFilter(this);
  3334. }.bind(this));
  3335. },
  3336. destroy: function(){
  3337. this.node.destroy();
  3338. MWF.release(this);
  3339. }
  3340. });
  3341. /** @class Actionbar 视图操作条组件。
  3342. * @o2cn 视图操作条
  3343. * @example
  3344. * //可以在视图中获取该组件
  3345. * var actionbar = this.target.actionbar; //在视图中获取操作条
  3346. * //方法2
  3347. * var actionbar = this.target; //在操作条和操作本身的事件脚本中获取
  3348. * @o2category QueryView
  3349. * @o2range {QueryView}
  3350. * @hideconstructor
  3351. */
  3352. MWF.xApplication.query.Query.Viewer.Actionbar = new Class(
  3353. /** @lends MWF.xApplication.query.Query.Viewer.Actionbar# */
  3354. {
  3355. Implements: [Events],
  3356. options: {
  3357. "style" : "default",
  3358. "moduleEvents": [
  3359. /**
  3360. * 视图操作条加载前触发。
  3361. * @event MWF.xApplication.query.Query.Viewer.Actionbar#queryLoad
  3362. */
  3363. "queryLoad",
  3364. /**
  3365. * 视图加载时触发。
  3366. * @event MWF.xApplication.query.Query.Viewer.Actionbar#load
  3367. */
  3368. "load",
  3369. /**
  3370. * 视图操作条加载后事件.由于加载过程中有异步处理,这个时候操作条有可能还未生成。
  3371. * @event MWF.xApplication.query.Query.Viewer.Actionbar#postLoad
  3372. */
  3373. "postLoad",
  3374. /**
  3375. * 视图操作条加载后事件。这个时候操作条已生成。
  3376. * @event MWF.xApplication.query.Query.Viewer.Actionbar#afterLoad
  3377. */
  3378. "afterLoad"
  3379. ]
  3380. },
  3381. initialize: function(node, json, form, options){
  3382. /**
  3383. * @summary 操作条组件容器.
  3384. * @member {Element}
  3385. */
  3386. this.node = $(node);
  3387. this.node.store("module", this);
  3388. /**
  3389. * @summary 操作条组件配置数据.
  3390. * @member {Object}
  3391. */
  3392. this.json = json;
  3393. this.form = form;
  3394. /**
  3395. * @summary 操作条组件所属视图.
  3396. * @member {Object}
  3397. */
  3398. this.view = form;
  3399. },
  3400. /**
  3401. * @summary 隐藏操作条。
  3402. */
  3403. hide: function(){
  3404. var dsp = this.node.getStyle("display");
  3405. if (dsp!=="none") this.node.store("mwf_display", dsp);
  3406. this.node.setStyle("display", "none");
  3407. },
  3408. /**
  3409. * @summary 显示操作条。
  3410. */
  3411. show: function(){
  3412. var dsp = this.node.retrieve("mwf_display", dsp);
  3413. this.node.setStyle("display", dsp);
  3414. },
  3415. load: function(){
  3416. this._loadModuleEvents();
  3417. if (this.fireEvent("queryLoad")){
  3418. //this._queryLoaded();
  3419. this._loadUserInterface();
  3420. this._loadStyles();
  3421. this._loadDomEvents();
  3422. //this._loadEvents();
  3423. //this._afterLoaded();
  3424. this.fireEvent("postLoad");
  3425. this.fireEvent("load");
  3426. }
  3427. },
  3428. _loadStyles: function(){
  3429. if (this.json.styles) Object.each(this.json.styles, function(value, key){
  3430. if ((value.indexOf("x_processplatform_assemble_surface")!=-1 || value.indexOf("x_portal_assemble_surface")!=-1 || value.indexOf("x_cms_assemble_control")!=-1)){
  3431. var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  3432. var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  3433. var host3 = MWF.Actions.getHost("x_cms_assemble_control");
  3434. if (value.indexOf("/x_processplatform_assemble_surface")!==-1){
  3435. value = value.replace("/x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  3436. }else if (value.indexOf("x_processplatform_assemble_surface")!==-1){
  3437. value = value.replace("x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  3438. }
  3439. if (value.indexOf("/x_portal_assemble_surface")!==-1){
  3440. value = value.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  3441. }else if (value.indexOf("x_portal_assemble_surface")!==-1){
  3442. value = value.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  3443. }
  3444. if (value.indexOf("/x_cms_assemble_control")!==-1){
  3445. value = value.replace("/x_cms_assemble_control", host3+"/x_cms_assemble_control");
  3446. }else if (value.indexOf("x_cms_assemble_control")!==-1){
  3447. value = value.replace("x_cms_assemble_control", host3+"/x_cms_assemble_control");
  3448. }
  3449. value = o2.filterUrl(value);
  3450. }
  3451. this.node.setStyle(key, value);
  3452. }.bind(this));
  3453. // if (["x_processplatform_assemble_surface", "x_portal_assemble_surface"].indexOf(root.toLowerCase())!==-1){
  3454. // var host = MWF.Actions.getHost(root);
  3455. // return (flag==="/") ? host+this.json.template : host+"/"+this.json.template
  3456. // }
  3457. //if (this.json.styles) this.node.setStyles(this.json.styles);
  3458. },
  3459. _loadModuleEvents : function(){
  3460. Object.each(this.json.events, function(e, key){
  3461. if (e.code){
  3462. if (this.options.moduleEvents.indexOf(key)!==-1){
  3463. this.addEvent(key, function(event){
  3464. return this.form.Macro.fire(e.code, this, event);
  3465. }.bind(this));
  3466. }
  3467. }
  3468. }.bind(this));
  3469. },
  3470. _loadDomEvents: function(){
  3471. Object.each(this.json.events, function(e, key){
  3472. if (e.code){
  3473. if (this.options.moduleEvents.indexOf(key)===-1){
  3474. this.node.addEvent(key, function(event){
  3475. return this.form.Macro.fire(e.code, this, event);
  3476. }.bind(this));
  3477. }
  3478. }
  3479. }.bind(this));
  3480. },
  3481. _loadEvents: function(){
  3482. Object.each(this.json.events, function(e, key){
  3483. if (e.code){
  3484. if (this.options.moduleEvents.indexOf(key)!==-1){
  3485. this.addEvent(key, function(event){
  3486. return this.form.Macro.fire(e.code, this, event);
  3487. }.bind(this));
  3488. }else{
  3489. this.node.addEvent(key, function(event){
  3490. return this.form.Macro.fire(e.code, this, event);
  3491. }.bind(this));
  3492. }
  3493. }
  3494. }.bind(this));
  3495. },
  3496. addModuleEvent: function(key, fun){
  3497. if (this.options.moduleEvents.indexOf(key)!==-1){
  3498. this.addEvent(key, function(event){
  3499. return (fun) ? fun(this, event) : null;
  3500. }.bind(this));
  3501. }else{
  3502. this.node.addEvent(key, function(event){
  3503. return (fun) ? fun(this, event) : null;
  3504. }.bind(this));
  3505. }
  3506. },
  3507. _loadUserInterface: function(){
  3508. // if (this.form.json.mode == "Mobile"){
  3509. // this.node.empty();
  3510. // }else if (COMMON.Browser.Platform.isMobile){
  3511. // this.node.empty();
  3512. // }else{
  3513. this.toolbarNode = this.node.getFirst("div");
  3514. if( !this.toolbarNode ){
  3515. this.toolbarNode = new Element("div").inject( this.node );
  3516. }
  3517. this.toolbarNode.empty();
  3518. MWF.require("MWF.widget.Toolbar", function(){
  3519. this.toolbarWidget = new MWF.widget.Toolbar(this.toolbarNode, {
  3520. "style": this.json.style,
  3521. "onPostLoad" : function(){
  3522. this.fireEvent("afterLoad");
  3523. }.bind(this)
  3524. }, this);
  3525. if (this.json.actionStyles) this.toolbarWidget.css = this.json.actionStyles;
  3526. //alert(this.readonly)
  3527. if( this.json.multiTools ){
  3528. // var jsonStr = JSON.stringify(this.json.multiTools);
  3529. // jsonStr = o2.bindJson(jsonStr, {"lp": MWF.xApplication.query.Query.LP.form});
  3530. // this.json.multiTools = JSON.parse(jsonStr);
  3531. this.json.multiTools.each( function (tool) {
  3532. if( tool.system ){
  3533. if( !this.json.hideSystemTools ){
  3534. this.setToolbars([tool], this.toolbarNode, this.readonly);
  3535. }
  3536. }else{
  3537. this.setCustomToolbars([tool], this.toolbarNode);
  3538. }
  3539. }.bind(this));
  3540. this.toolbarWidget.load();
  3541. }else{
  3542. if (this.json.hideSystemTools){
  3543. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  3544. this.toolbarWidget.load();
  3545. }else{
  3546. if (this.json.defaultTools){
  3547. this.setToolbars(this.json.defaultTools, this.toolbarNode, this.readonly);
  3548. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  3549. this.toolbarWidget.load();
  3550. }else{
  3551. MWF.getJSON(this.form.path+"toolbars.json", function(json){
  3552. this.setToolbars(json, this.toolbarNode, this.readonly, true);
  3553. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  3554. this.toolbarWidget.load();
  3555. }.bind(this), null);
  3556. }
  3557. }
  3558. }
  3559. }.bind(this));
  3560. // }
  3561. },
  3562. setCustomToolbars: function(tools, node){
  3563. var path = "../x_component_process_FormDesigner/Module/Actionbar/";
  3564. var iconPath = "";
  3565. if( this.json.customIconStyle ){
  3566. iconPath = this.json.customIconStyle+"/";
  3567. }
  3568. tools.each(function(tool){
  3569. var flag = true;
  3570. if (this.readonly){
  3571. flag = tool.readShow;
  3572. }else{
  3573. flag = tool.editShow;
  3574. }
  3575. if (flag){
  3576. flag = true;
  3577. // if (tool.control){
  3578. // flag = this.form.businessData.control[tool.control]
  3579. // }
  3580. if (tool.condition){
  3581. var hideFlag = this.form.Macro.exec(tool.condition, this);
  3582. flag = !hideFlag;
  3583. }
  3584. if (flag){
  3585. var actionNode = new Element("div", {
  3586. "id": tool.id,
  3587. "MWFnodetype": tool.type,
  3588. "MWFButtonImage": path+""+this.options.style+"/custom/"+iconPath+tool.img,
  3589. "title": tool.title,
  3590. "MWFButtonAction": "runCustomAction",
  3591. "MWFButtonText": tool.text
  3592. }).inject(node);
  3593. if( this.json.customIconOverStyle ){
  3594. actionNode.set("MWFButtonImageOver" , path+""+this.options.style +"/custom/"+this.json.customIconOverStyle+ "/" +tool.img );
  3595. }
  3596. if( tool.properties ){
  3597. actionNode.set(tool.properties);
  3598. }
  3599. if (tool.actionScript){
  3600. actionNode.store("script", tool.actionScript);
  3601. }
  3602. if (tool.sub){
  3603. var subNode = node.getLast();
  3604. this.setCustomToolbars(tool.sub, subNode);
  3605. }
  3606. }
  3607. }
  3608. }.bind(this));
  3609. },
  3610. setToolbarItem: function(tool, node, readonly, noCondition){
  3611. //var path = "../x_component_process_FormDesigner/Module/Actionbar/";
  3612. var path = "../x_component_query_ViewDesigner/$View/";
  3613. var flag = true;
  3614. // if (tool.control){
  3615. // flag = this.form.businessData.control[tool.control]
  3616. // }
  3617. if (!noCondition) if (tool.condition){
  3618. var hideFlag = this.form.Macro.exec(tool.condition, this);
  3619. flag = flag && (!hideFlag);
  3620. }
  3621. if (readonly) if (!tool.read) flag = false;
  3622. if (flag){
  3623. var actionNode = new Element("div", {
  3624. "id": tool.id,
  3625. "MWFnodetype": tool.type,
  3626. //"MWFButtonImage": this.form.path+""+this.form.options.style+"/actionbar/"+tool.img,
  3627. //"MWFButtonImage": path+(this.options.style||"default") +"/tools/"+ (this.json.style || "default") +"/"+tool.img,
  3628. "MWFButtonImage": path+this.options.style+"/actionbar/"+ ( this.json.iconStyle || "default" ) +"/"+tool.img,
  3629. "title": tool.title,
  3630. "MWFButtonAction": tool.action,
  3631. "MWFButtonText": tool.text
  3632. }).inject(node);
  3633. if( this.json.iconOverStyle ){
  3634. actionNode.set("MWFButtonImageOver" , path+""+this.options.style+"/actionbar/"+this.json.iconOverStyle+"/"+tool.img );
  3635. //actionNode.set("MWFButtonImageOver" , path+""+(this.options.style||"default")+"/tools/"+( this.json.iconOverStyle || "default" )+"/"+tool.img );
  3636. }
  3637. if( tool.properties ){
  3638. actionNode.set(tool.properties);
  3639. }
  3640. if (tool.sub){
  3641. var subNode = node.getLast();
  3642. this.setToolbars(tool.sub, subNode, readonly, noCondition);
  3643. }
  3644. }
  3645. },
  3646. setToolbars: function(tools, node, readonly, noCondition){
  3647. tools.each(function(tool){
  3648. this.setToolbarItem(tool, node, readonly, noCondition);
  3649. }.bind(this));
  3650. },
  3651. runCustomAction: function(bt){
  3652. var script = bt.node.retrieve("script");
  3653. this.form.Macro.exec(script, this);
  3654. },
  3655. exportView : function(){
  3656. this.form.exportView();
  3657. },
  3658. deleteWork: function(){
  3659. this.form.deleteWork();
  3660. }
  3661. });
  3662. /** @class Actionbar 视图分页组件。
  3663. * @o2cn 视图分页组件
  3664. * @example
  3665. * //可以在视图中获取该组件
  3666. * var actionbar = this.target.paging; //在视图中获取操作条
  3667. * //方法2
  3668. * var actionbar = this.target; //在分页组件本身的事件脚本中获取
  3669. * @o2category QueryView
  3670. * @o2range {QueryView}
  3671. * @hideconstructor
  3672. */
  3673. MWF.xApplication.query.Query.Viewer.Paging = new Class(
  3674. /** @lends MWF.xApplication.query.Query.Viewer.Paging# */
  3675. {
  3676. Implements: [Options, Events],
  3677. options: {
  3678. "style" : "default",
  3679. "useMainColor": false,
  3680. "moduleEvents": [
  3681. /**
  3682. * 分页加载前触发。
  3683. * @event MWF.xApplication.query.Query.Viewer.Paging#queryLoad
  3684. */
  3685. "queryLoad",
  3686. /**
  3687. * 分页加载时触发。
  3688. * @event MWF.xApplication.query.Query.Viewer.Paging#load
  3689. */
  3690. "load",
  3691. /**
  3692. * 分页加载后事件.由于加载过程中有异步处理,这个时候分页组件有可能还未生成。
  3693. * @event MWF.xApplication.query.Query.Viewer.Paging#postLoad
  3694. */
  3695. "postLoad",
  3696. /**
  3697. * 分页加载后事件。这个时候分页界面已生成。
  3698. * @event MWF.xApplication.query.Query.Viewer.Paging#afterLoad
  3699. */
  3700. "afterLoad",
  3701. /**
  3702. * 跳页或者分页后执行。
  3703. * @event MWF.xApplication.query.Query.Viewer.Paging#jump
  3704. */
  3705. "jump"
  3706. ]
  3707. },
  3708. initialize: function(node, json, form, options){
  3709. this.setOptions(options);
  3710. /**
  3711. * @summary 分页组件容器.
  3712. * @member {Element}
  3713. */
  3714. this.node = $(node);
  3715. this.node.store("module", this);
  3716. /**
  3717. * @summary 分页组件所属视图.
  3718. * @member {Object}
  3719. */
  3720. this.json = json;
  3721. this.form = form;
  3722. /**
  3723. * @summary 分页所属视图.
  3724. * @member {Object}
  3725. */
  3726. this.view = form;
  3727. },
  3728. /**
  3729. * @summary 隐藏分页。
  3730. */
  3731. hide: function(){
  3732. var dsp = this.node.getStyle("display");
  3733. if (dsp!=="none") this.node.store("mwf_display", dsp);
  3734. this.node.setStyle("display", "none");
  3735. },
  3736. /**
  3737. * @summary 显示分页。
  3738. */
  3739. show: function(){
  3740. var dsp = this.node.retrieve("mwf_display", dsp);
  3741. this.node.setStyle("display", dsp);
  3742. },
  3743. load: function(){
  3744. this._loadModuleEvents();
  3745. if (this.fireEvent("queryLoad")){
  3746. //this._queryLoaded();
  3747. this._loadUserInterface();
  3748. this._loadStyles();
  3749. this._loadDomEvents();
  3750. //this._loadEvents();
  3751. //this._afterLoaded();
  3752. this.fireEvent("postLoad");
  3753. }
  3754. },
  3755. _loadStyles: function(){
  3756. if (this.json.styles) Object.each(this.json.styles, function(value, key){
  3757. if ((value.indexOf("x_processplatform_assemble_surface")!=-1 || value.indexOf("x_portal_assemble_surface")!=-1 || value.indexOf("x_cms_assemble_control")!=-1)){
  3758. var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  3759. var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  3760. var host3 = MWF.Actions.getHost("x_cms_assemble_control");
  3761. if (value.indexOf("/x_processplatform_assemble_surface")!==-1){
  3762. value = value.replace("/x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  3763. }else if (value.indexOf("x_processplatform_assemble_surface")!==-1){
  3764. value = value.replace("x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  3765. }
  3766. if (value.indexOf("/x_portal_assemble_surface")!==-1){
  3767. value = value.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  3768. }else if (value.indexOf("x_portal_assemble_surface")!==-1){
  3769. value = value.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  3770. }
  3771. if (value.indexOf("/x_cms_assemble_control")!==-1){
  3772. value = value.replace("/x_cms_assemble_control", host3+"/x_cms_assemble_control");
  3773. }else if (value.indexOf("x_cms_assemble_control")!==-1){
  3774. value = value.replace("x_cms_assemble_control", host3+"/x_cms_assemble_control");
  3775. }
  3776. value = o2.filterUrl(value);
  3777. }
  3778. this.node.setStyle(key, value);
  3779. }.bind(this));
  3780. // if (["x_processplatform_assemble_surface", "x_portal_assemble_surface"].indexOf(root.toLowerCase())!==-1){
  3781. // var host = MWF.Actions.getHost(root);
  3782. // return (flag==="/") ? host+this.json.template : host+"/"+this.json.template
  3783. // }
  3784. //if (this.json.styles) this.node.setStyles(this.json.styles);
  3785. },
  3786. _loadModuleEvents : function(){
  3787. Object.each(this.json.events, function(e, key){
  3788. if (e.code){
  3789. if (this.options.moduleEvents.indexOf(key)!==-1){
  3790. this.addEvent(key, function(event){
  3791. return this.form.Macro.fire(e.code, this, event);
  3792. }.bind(this));
  3793. }
  3794. }
  3795. }.bind(this));
  3796. },
  3797. _loadDomEvents: function(){
  3798. Object.each(this.json.events, function(e, key){
  3799. if (e.code){
  3800. if (this.options.moduleEvents.indexOf(key)===-1){
  3801. this.node.addEvent(key, function(event){
  3802. return this.form.Macro.fire(e.code, this, event);
  3803. }.bind(this));
  3804. }
  3805. }
  3806. }.bind(this));
  3807. },
  3808. _loadEvents: function(){
  3809. Object.each(this.json.events, function(e, key){
  3810. if (e.code){
  3811. if (this.options.moduleEvents.indexOf(key)!==-1){
  3812. this.addEvent(key, function(event){
  3813. return this.form.Macro.fire(e.code, this, event);
  3814. }.bind(this));
  3815. }else{
  3816. this.node.addEvent(key, function(event){
  3817. return this.form.Macro.fire(e.code, this, event);
  3818. }.bind(this));
  3819. }
  3820. }
  3821. }.bind(this));
  3822. },
  3823. addModuleEvent: function(key, fun){
  3824. if (this.options.moduleEvents.indexOf(key)!==-1){
  3825. this.addEvent(key, function(event){
  3826. return (fun) ? fun(this, event) : null;
  3827. }.bind(this));
  3828. }else{
  3829. this.node.addEvent(key, function(event){
  3830. return (fun) ? fun(this, event) : null;
  3831. }.bind(this));
  3832. }
  3833. },
  3834. _loadUserInterface: function(){
  3835. // if (this.form.json.mode == "Mobile"){
  3836. // this.node.empty();
  3837. // }else if (COMMON.Browser.Platform.isMobile){
  3838. // this.node.empty();
  3839. // }else{
  3840. this.loadPaging( true )
  3841. },
  3842. reload : function(){
  3843. this.loadPaging( false )
  3844. },
  3845. loadPaging : function( firstLoading ){
  3846. // this.pagingNode = this.node.getFirst("div");
  3847. // if( !this.pagingNode ){
  3848. // this.pagingNode = new Element("div").inject( this.node );
  3849. // }
  3850. // this.pagingNode.empty();
  3851. this.node.empty();
  3852. this.paging = new o2.widget.Paging(this.node, {
  3853. //style : this.options.skin && this.options.skin.pagingBar ? this.options.skin.pagingBar : "default",
  3854. countPerPage: this.view.json.pageSize || this.view.options.perPageCount,
  3855. visiblePages: layout.mobile?5:(this.json.visiblePages ? this.json.visiblePages.toInt() : 9),
  3856. currentPage: this.view.currentPage,
  3857. itemSize: this.view.count,
  3858. pageSize: this.view.pages,
  3859. hasNextPage: typeOf( this.json.hasPreNextPage ) === "boolean" ? this.json.hasPreNextPage : true,
  3860. hasPrevPage: typeOf( this.json.hasPreNextPage ) === "boolean" ? this.json.hasPreNextPage : true,
  3861. hasTruningBar: typeOf( this.json.hasTruningBar ) === "boolean" ? this.json.hasTruningBar : true,
  3862. hasBatchTuring: typeOf( this.json.hasBatchTuring ) === "boolean" ? this.json.hasBatchTuring : true,
  3863. hasFirstPage: typeOf( this.json.hasFirstLastPage ) === "boolean" ? this.json.hasFirstLastPage : (layout.mobile?false:true),
  3864. hasLastPage: typeOf( this.json.hasFirstLastPage ) === "boolean" ? this.json.hasFirstLastPage : (layout.mobile?false:true),
  3865. hasJumper: typeOf( this.json.hasPageJumper ) === "boolean" ? this.json.hasPageJumper : (layout.mobile?false:true),
  3866. hiddenWithDisable: false,
  3867. hiddenWithNoItem: true,
  3868. hasInfor: this.json.showPagingInfor,
  3869. inforPosition: this.json.pagingPosition,
  3870. inforTextStyle: this.json.textStyle,
  3871. useMainColor: this.options.useMainColor,
  3872. text: {
  3873. prePage: this.json.prePageText,
  3874. nextPage: this.json.nextPageText,
  3875. firstPage: this.json.firstPageText,
  3876. lastPage: this.json.lastPageText
  3877. },
  3878. onJumpingPage : function( pageNum, itemNum ){
  3879. this.view.currentPage = pageNum;
  3880. this.fireEvent("jump");
  3881. this.view.loadCurrentPageData( null, false );
  3882. }.bind(this),
  3883. onPostLoad : function () {
  3884. if( firstLoading ){
  3885. if(this.view.setContentHeightFun)this.view.setContentHeightFun();
  3886. this.fireEvent("load");
  3887. }
  3888. this.fireEvent("afterLoad");
  3889. }.bind(this)
  3890. }, this.json.pagingStyles || {});
  3891. this.paging.load();
  3892. }
  3893. });
  3894. MWF.xApplication.query.Query.Viewer.AssociatedResultItem = new Class({
  3895. Extends: MWF.xApplication.query.Query.Viewer.Item,
  3896. _load: function(){
  3897. this.loading = true;
  3898. if(!this.node)this.view.fireEvent("queryLoadItemRow", [this]);
  3899. var viewStyles = this.view.viewJson.viewStyles;
  3900. var viewContentTdNode = ( viewStyles && viewStyles["contentTd"] ) ? viewStyles["contentTd"] : this.css.viewContentTdNode;
  3901. if(!this.node)this.loadNode();
  3902. //if (this.view.json.select==="single" || this.view.json.select==="multi"){
  3903. this.selectTd = new Element("td", { "styles": viewContentTdNode }).inject(this.node);
  3904. if (this.view.json.itemStyles) this.selectTd.setStyles(this.view.json.itemStyles);
  3905. this.selectTd.setStyles({"cursor": "default"});
  3906. if( this.data.$failure ){
  3907. this.selectTd.setStyles({"background": "url(" + "../x_component_query_Query/$Viewer/default/icon/" + "error" + ".png) center center no-repeat"});
  3908. }else{
  3909. this.selectTd.setStyles({"background": "url(" + "../x_component_query_Query/$Viewer/default/icon/" + "success" + ".png) center center no-repeat"});
  3910. }
  3911. //序号
  3912. var sequence = 1+this.idx;
  3913. this.data["$sequence"] = sequence;
  3914. if (this.view.viewJson.isSequence==="yes"){
  3915. this.sequenceTd = new Element("td", {"styles": viewContentTdNode}).inject(this.node);
  3916. this.sequenceTd.setStyles({
  3917. "width": "30px",
  3918. "text-align": "center"
  3919. });
  3920. this.sequenceTd.set("text", sequence);
  3921. }
  3922. Object.each(this.view.entries, function(c, k){
  3923. var cell = this.data.data[k];
  3924. if (cell === undefined) cell = "";
  3925. //if (cell){
  3926. if (this.view.hideColumns.indexOf(k)===-1){
  3927. var td = new Element("td", {"styles": viewContentTdNode}).inject(this.node);
  3928. //if (k!== this.view.viewJson.group.column){
  3929. var v = cell;
  3930. if (c.isHtml){
  3931. td.set("html", v);
  3932. }else{
  3933. td.set("text", v);
  3934. }
  3935. if( typeOf(c.contentProperties) === "object" )td.setProperties(c.contentProperties);
  3936. if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
  3937. if( typeOf(c.contentStyles) === "object" )td.setStyles(c.contentStyles);
  3938. // }else{
  3939. // if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
  3940. // }
  3941. if (this.view.openColumns.indexOf(k)!==-1){
  3942. this.setOpenWork(td, c)
  3943. }
  3944. if (k!== this.view.viewJson.group.column){
  3945. Object.each( c.events || {}, function (e , key) {
  3946. if(e.code){
  3947. if( key === "loadContent" ){
  3948. this.view.Macro.fire( e.code,
  3949. {"node" : td, "json" : c, "data" : v, "view": this.view, "row" : this});
  3950. }else if( key !== "loadTitle" ){
  3951. td.addEvent(key, function(event){
  3952. return this.view.Macro.fire(
  3953. e.code,
  3954. {"node" : td, "json" : c, "data" : v, "view": this.view, "row" : this},
  3955. event
  3956. );
  3957. }.bind(this));
  3958. }
  3959. }
  3960. }.bind(this));
  3961. }
  3962. }
  3963. //}
  3964. }.bind(this));
  3965. if(this.placeholderTd){
  3966. this.placeholderTd.destroy();
  3967. this.placeholderTd = null;
  3968. }
  3969. //默认选中
  3970. //判断是不是在selectedItems中,用户手工选择
  3971. this.setEvent();
  3972. this.view.fireEvent("postLoadItemRow", [this]);
  3973. this.loading = false;
  3974. this.loaded = true;
  3975. },
  3976. })
  3977. MWF.xDesktop.requireApp("Template", "utils.ExcelUtils", null, false);
  3978. MWF.xApplication.query.Query.Viewer.ExcelUtils = new Class({
  3979. Extends: MWF.xApplication.Template.utils.ExcelUtils
  3980. });