Viewer.js 173 KB

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