| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832 |
- MWF.xApplication.Selector = MWF.xApplication.Selector || {};
- MWF.xDesktop.requireApp("Selector", "lp."+MWF.language, null, false);
- //MWF.xDesktop.requireApp("Selector", "Actions.RestActions", null, false);
- MWF.xApplication.Selector.Person = new Class({
- Extends: MWF.widget.Common,
- Implements: [Options, Events],
- options: {
- "style": "default",
- "count": 0,
- "title": MWF.xApplication.Selector.LP.selectPerson,
- "groups": [],
- "roles": [],
- "values": [],
- "exclude" : [],
- "zIndex": 1000,
- "expand": true,
- "embedded" : false, //是否嵌入在其他容器中
- "selectAllEnable" : false, //是否允许全选
- "selectAllRange" : "direct", //全选直属人员 还是 所有下级人员
- "level1Indent" : 10, //第一级的缩进
- "indent" : 10, //后续的缩进
- "hasLetter" : true, //字母
- "hasTop" : false, //可选、已选的标题
- "hasShuttle" : false, //穿梭按钮
- "searchbarInTopNode" : true, //搜索框在标题上还是另起一行
- "hasSelectedSearchbar" : false, //已选是不是有搜索框
- "noSelectedContainer" : false, //是否隐藏右侧已选区域
- "contentUrl" : "", //和默认的页面布局不一样的话,可以传入页面布局HTML URL
- "injectToBody" : false, //当传入HTML URL的时候是否插入到document.body, false的时候插入到this.container
- "selectSingleItem" : false, //当只有一个候选项的时候,是否默认选中
- "flatCategory" : false, //扁平化展现分类,
- "selectType" : "person",
- "isCheckStatus" : false,
- "showSelectedCount" : false,
- "itemHeight" : 29,
- "identityItemWidth" : 0, //选项宽度,如果不为0,设置为float:left,
- "showEmptyText" : true
- },
- initialize: function(container, options){
- this.active = true;
- this.setOptions(options);
- this.path = "../x_component_Selector/$Selector/";
- this.cssPath = "../x_component_Selector/$Selector/"+this.options.style+"/css.wcss";
- this._loadCss(true);
- this.container = $(container);
- Object.defineProperties(this, {
- "orgAction": {"get": function(){return o2.Actions.get("x_organization_assemble_control");}},
- "processAction": {"get": function(){return o2.Actions.get("x_processplatform_assemble_surface");}},
- "designerAction": {"get": function(){return o2.Actions.get("x_processplatform_assemble_designer");}},
- "portalAction": {"get": function(){return o2.Actions.get("x_portal_assemble_surface");}},
- "portalDesignerAction": {"get": function(){return o2.Actions.get("x_portal_assemble_designer");}},
- "cmsAction": {"get": function(){return o2.Actions.get("x_cms_assemble_control");}},
- "queryAction": {"get": function(){return o2.Actions.get("x_query_assemble_designer");}}
- });
- // this.orgAction = MWF.Actions.get("x_organization_assemble_control");
- // //this.org2Action = MWF.Actions.get("x_organization_assemble_express");
- // this.processAction = MWF.Actions.get("x_processplatform_assemble_surface");
- // this.designerAction = MWF.Actions.get("x_processplatform_assemble_designer");
- // this.portalAction = MWF.Actions.get("x_portal_assemble_surface");
- // this.portalDesignerAction = MWF.Actions.get("x_portal_assemble_designer");
- // this.cmsAction = MWF.Actions.get("x_cms_assemble_control");
- // this.queryAction = MWF.Actions.get("x_query_assemble_designer");
- //this.action = new MWF.xApplication.Selector.Actions.RestActions();
- this.lastPeople = "";
- this.pageCount = "13";
- this.selectedItems = []; //所有已选项
- this.items = []; //所有选择项
- this.subCategorys = []; //直接的分类
- this.subItems = []; //直接的选择项
- if( !this.options.values ){
- this.options.values = [];
- }
- this._init();
- },
- _init : function(){
- this.selectType = "person";
- this.className = "Person"
- },
- load: function(){
- this.fireEvent("queryLoad",[this]);
- if( this.options.contentUrl ){
- this.loadWithUrl()
- }else{
- if (layout.mobile){
- this.loadMobile();
- }else{
- this.loadPc();
- }
- this.fireEvent("load");
- }
- },
- loadMobile: function(){
- this.maskRelativeNode = $(document.body);
- this.maskRelativeNode.mask({
- "destroyOnHide": true,
- "style": this.css.maskNode
- });
- this.node = new Element("div", {"styles": this.css.containerNodeMobile});
- this.node.setStyle("z-index", this.options.zIndex.toInt()+1);
- this.node.setStyle("height", ( $(document.body).getSize().y ) + "px");
- this.titleNode = new Element("div", {
- "styles": this.css.titleNodeMobile
- }).inject(this.node);
- this.titleCancelActionNode = new Element("div", {
- "styles": this.css.titleCancelActionNodeMobile,
- "text": MWF.SelectorLP.back
- }).inject(this.titleNode);
- this.titleOkActionNode = new Element("div", {
- "styles": this.css.titleOkActionNodeMobile,
- "text": MWF.SelectorLP.ok
- }).inject(this.titleNode);
- this.titleTextNode = new Element("div", {
- "styles": this.css.titleTextNodeMobile,
- "text": this.options.title
- }).inject(this.titleNode);
- this.contentNode = new Element("div", {
- "styles": this.css.contentNode
- }).inject(this.node);
- var size = $(document.body).getSize();
- var height = size.y-40;
- //var height = size.y;
- this.contentNode.setStyle("height", ""+height+"px");
- this.loadContent();
- this.node.inject($(document.body));
- this.node.setStyles({
- "top": "0px",
- "left": "0px"
- });
- this.setEvent();
- },
- setMaskResize: function(){
- var size = this.container.getSize();
- this.mask.resize();
- this.maskInterval = window.setInterval(function(){
- var resize = this.container.getSize();
- if ((size.x!==resize.x) || (size.y!==resize.y)){
- this.mask.position();
- this.mask.resize();
- size.x = resize.x;
- size.y = resize.y;
- }
- }.bind(this), 66);
- },
- loadPc: function(){
- if( this.options.embedded ){
- this.node = new Element("div", {
- "styles": this.css.containerNode_embedded, //(this.options.count.toInt()===1) ? this.css.containerNodeSingle_embedded : this.css.containerNode_embedded,
- "events": {
- "click": function(e){e.stopPropagation();},
- "mousedown": function(e){e.stopPropagation();},
- "mouseover": function(e){e.stopPropagation();},
- "mouseout": function(e){e.stopPropagation();},
- "keydown": function(e){e.stopPropagation();}
- }
- });
- this.contentNode = new Element("div", {
- "styles": this.css.contentNode_embedded ? this.css.contentNode_embedded : this.css.contentNode
- }).inject(this.node);
- this.loadContent();
- if( this.options.width || this.options.height ){
- this.setSize()
- }
- this.node.inject(this.container);
- } else {
- this.css.maskNode["z-index"] = this.options.zIndex;
- var position = this.container.getPosition(this.container.getOffsetParent());
- this.mask = new Mask(this.container, {
- "destroyOnHide": true,
- "style": this.css.maskNode,
- "useIframeShim": true,
- "iframeShimOptions": {"browsers": true},
- "onShow": function () {
- this.shim.shim.setStyles({
- "opacity": 0,
- "top": "" + position.y + "px",
- "left": "" + position.x + "px"
- });
- }
- //
- // "destroyOnHide": true,
- // "style": this.css.maskNode,
- // "useIframeShim": true,
- // "iframeShimOptions": {"browsers": true},
- // "onShow": function(){
- // this.shim.shim.setStyles({
- // "opacity": 0,
- // "top": ""+position.y+"px",
- // "left": ""+position.x+"px"
- // });
- // }
- });
- this.mask.show();
- this.setMaskResize();
- // this.container.setStyle("z-index", this.options.zIndex);
- this.node = new Element("div", {
- "styles": this.options.noSelectedContainer ? this.css.containerNodeSingle : this.css.containerNode, //(this.options.count.toInt()===1)
- "events": {
- "click": function(e){e.stopPropagation();},
- "mousedown": function(e){e.stopPropagation();},
- "mouseover": function(e){e.stopPropagation();},
- "mouseout": function(e){e.stopPropagation();},
- "keydown": function(e){e.stopPropagation();}
- }
- });
- this.node.setStyle("z-index", this.options.zIndex.toInt()+1);
- this.titleNode = new Element("div.titleNode", {
- "styles": this.css.titleNode
- }).inject(this.node);
- this.titleActionNode = new Element("div", {
- "styles": this.css.titleActionNode
- }).inject(this.titleNode);
- this.titleTextNode = new Element("div", {
- "styles": this.css.titleTextNode,
- "text": this.options.title
- }).inject(this.titleNode);
- this.contentNode = new Element("div", {
- "styles": this.css.contentNode
- }).inject(this.node);
- this.loadContent();
- this.actionNode = new Element("div", {
- "styles": this.css.actionNode
- }).inject(this.node);
- //if (this.options.count.toInt() === 1) this.actionNode.setStyle("text-align", "center");
- this.loadAction();
- this.node.inject(this.container);
- this.node.position({
- relativeTo: this.container,
- position: "center",
- edge: "center"
- });
- var size = this.container.getSize();
- var nodeSize = this.node.getSize();
- this.node.makeDraggable({
- "handle": this.titleNode,
- "limit": {
- "x": [0, size.x - nodeSize.x],
- "y": [0, size.y - nodeSize.y]
- }
- });
- if( this.options.width || this.options.height ){
- this.setSize()
- }
- this.setEvent();
- }
- },
- loadWithUrl : function(){
- var request = new Request.HTML({
- url: this.options.contentUrl,
- method: "GET",
- async: false,
- onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript){
- this.node = responseTree[0];
- this.loadContentWithHTML();
- this.fireEvent("load");
- }.bind(this),
- onFailure: function(xhr){
- alert(xhr);
- }
- });
- request.send();
- },
- loadContentWithHTML : function(){
- var container = this.options.injectToBody ? $(document.body) : this.container;
- if( !this.options.embedded ){
- this.maskRelativeNode = container;
- this.css.maskNode["z-index"] = this.options.zIndex;
- this.maskRelativeNode.mask({
- "destroyOnHide": true,
- "style": this.css.maskNode
- });
- }
- if( !this.options.embedded ) {
- this.node.setStyles(this.css.containerNodeMobile);
- this.node.setStyle("z-index", this.options.zIndex.toInt() + 1);
- }
- this.node.setStyle("height", ( container.getSize().y ) + "px");
- this.titleNode = this.node.getElement(".MWF_selector_titleNode");
- this.titleTextNode = this.node.getElement(".MWF_selector_titleTextNode");
- this.titleCancelActionNode = this.node.getElement(".MWF_selector_titleCancelActionNode");
- this.titleOkActionNode = this.node.getElement(".MWF_selector_titleOkActionNode");
- this.contentNode = this.node.getElement(".MWF_selector_contentNode");
- this.selectNode = this.node.getElement(".MWF_selector_selectNode");
- this.searchInputDiv = this.node.getElement(".MWF_selector_searchInputDiv");
- this.searchInput = this.node.getElement(".MWF_selector_searchInput");
- this.flatCategoryScrollNode = this.node.getElement(".MWF_selector_flatCategoryScrollNode");
- this.flatCategoryNode = this.node.getElement(".MWF_selector_flatCategoryNode");
- if( this.options.flatCategory && this.flatCategoryScrollNode ){
- this.isFlatCategory = true;
- this.flatSubCategoryNodeList = [];
- }
- this.letterAreaNode = this.node.getElement(".MWF_selector_letterAreaNode");
- this.itemAreaScrollNode = this.node.getElement(".MWF_selector_itemAreaScrollNode");
- this.itemAreaNode = this.node.getElement(".MWF_selector_itemAreaNode");
- this.itemSearchAreaScrollNode = this.node.getElement(".MWF_selector_itemSearchAreaScrollNode");
- this.itemSearchAreaNode = this.node.getElement(".MWF_selector_itemSearchAreaNode");
- this.selectedScrollNode = this.node.getElement(".MWF_selector_selectedScrollNode");
- this.selectedNode = this.node.getElement(".MWF_selector_selectedNode");
- this.selectedItemSearchAreaNode = this.node.getElement(".MWF_selector_selectedItemSearchAreaNode");
- this.actionNode = this.node.getElement(".MWF_selector_actionNode");
- this.okActionNode = this.node.getElement(".MWF_selector_okActionNode");
- this.cancelActionNode = this.node.getElement(".MWF_selector_cancelActionNode");
- if (this.titleNode) this.titleNode.setStyles(this.css.titleNodeMobile);
- if (this.titleTextNode){
- this.titleTextNode.setStyles(this.css.titleTextNodeMobile);
- if(this.options.title)this.titleTextNode.set("text", this.options.title);
- }
- if (this.titleCancelActionNode) this.titleCancelActionNode.setStyles(this.css.titleCancelActionNodeMobile);
- if (this.titleOkActionNode) this.titleOkActionNode.setStyles(this.css.titleOkActionNodeMobile);
- if (this.contentNode) this.contentNode.setStyles(this.css.contentNode);
- if (this.selectNode) this.selectNode.setStyles(this.css.selectNodeMobile);
- if (this.searchInputDiv) this.searchInputDiv.setStyles(this.css.searchInputDiv);
- if (this.searchInput) this.searchInput.setStyles( (this.options.count.toInt()===1 || this.options.noSelectedContainer) ? this.css.searchInputSingle : this.css.searchInput );
- if (this.letterAreaNode) this.letterAreaNode.setStyles(this.css.letterAreaNode);
- if (this.itemAreaScrollNode) this.itemAreaScrollNode.setStyles(this.css.itemAreaScrollNode);
- if (this.itemAreaNode) this.itemAreaNode.setStyles(this.css.itemAreaNode);
- if (this.itemSearchAreaScrollNode) this.itemSearchAreaScrollNode.setStyles(this.css.itemSearchAreaScrollNode);
- if (this.itemSearchAreaNode) this.itemSearchAreaNode.setStyles(this.css.itemAreaNode);
- if (this.selectedScrollNode) this.selectedScrollNode.setStyles(this.css.selectedScrollNode);
- if (this.selectedNode) this.selectedNode.setStyles(this.css.selectedNode);
- if (this.selectedItemSearchAreaNode) this.selectedItemSearchAreaNode.setStyles(this.css.itemAreaNode);
- if (this.actionNode) this.actionNode.setStyles(this.css.actionNode);
- if (this.okActionNode) {
- this.okActionNode.setStyles(this.css.okActionNode);
- this.okActionNode.set("text", MWF.SelectorLP.ok);
- }
- if (this.cancelActionNode) {
- this.cancelActionNode.setStyles(this.css.cancelActionNode);
- this.cancelActionNode.set("text", MWF.SelectorLP.cancel);
- }
- this.loadContent();
- if( this.actionNode ){
- this.loadAction();
- }
- this.node.inject( container );
- if( !this.options.embedded ){
- this.node.setStyles({
- "top": "0px",
- "left": "0px"
- });
- }
- this.setEvent();
- },
- getUnitIdentityCount : function(){
- },
- getUnitSelecteIndentityCount : function( unitLevelName ){ //根据组织获取已选身份数
- var count;
- this.selectedItems.each( function (item) {
- if( item.data.unitLevelName.indexOf( unitLevelName ) === 0 )count++;
- }.bind(this));
- return count;
- },
- getGroupNestCount : function(){
- // o2.Actions.load("x_organization_assemble_express").
- },
- getGroupSelecteIndentityCount : function( groupName ){ //根据组织获取已选身份数
- var count;
- this.selectedItems.each( function (item) {
- if( item.data.unitLevelName.indexOf( unitLevelName ) === 0 )count++;
- }.bind(this));
- return count;
- },
- setEvent: function(){
- if (this.titleActionNode){
- this.titleActionNode.addEvent("click", function(){
- this.fireEvent("cancel");
- this.close();
- }.bind(this));
- }
- if (this.titleCancelActionNode){
- this.titleCancelActionNode.addEvent("click", function(){
- this.fireEvent("cancel");
- this.close();
- }.bind(this));
- }
- if (this.titleOkActionNode){
- this.titleOkActionNode.addEvent("click", function(){
- this.fireEvent("complete", [this.selectedItems]);
- if( this.options.closeOnclickOk !== false )this.close();
- }.bind(this));
- }
- },
- close: function(){
- this.fireEvent("close");
- this.node.destroy();
- //if (this.mask) this.mask.hide();
- if( !this.options.embedded ){
- (this.maskRelativeNode || this.container).unmask();
- }
- if (this.maskInterval){
- window.clearInterval(this.maskInterval);
- this.maskInterval = null;
- }
- this.active = false;
- MWF.release(this);
- delete this;
- },
- loadAction: function(){
- if( !this.okActionNode ){
- this.okActionNode = new Element("button", {
- "styles": this.css.okActionNode,
- "text": MWF.SelectorLP.ok
- }).inject(this.actionNode);
- }
- if( !this.cancelActionNode ){
- this.cancelActionNode = new Element("button", {
- "styles": this.css.cancelActionNode,
- "text": MWF.SelectorLP.cancel
- }).inject(this.actionNode);
- }
- this.okActionNode.addEvent("click", function(){
- this.fireEvent("complete", [this.selectedItems]);
- if( this.options.closeOnclickOk !== false )this.close();
- }.bind(this));
- this.cancelActionNode.addEvent("click", function(){this.fireEvent("cancel"); this.close();}.bind(this));
- },
- loadContent: function( contentNode, isHTML ){
- this.fireEvent("queryLoadContent",[this]);
- if( contentNode )this.contentNode = contentNode;
- if( this.options.contentUrl || isHTML ){
- // if (this.options.count.toInt()!==1){
- // this.loadSelectedNodeHTML();
- // this.loadSelectNodeHTML(contentNode);
- // }else{
- // this.setSelectedItem();
- // this.loadSelectNodeHTML(contentNode);
- // }
- this.loadSelectedNodeHTML();
- this.loadSelectNodeHTML(contentNode);
- }else{
- if (layout.mobile){
- // if (this.options.count.toInt()!==1) this.loadSelectedNodeMobile();
- this.loadSelectedNodeMobile();
- this.loadSelectNodeMobile();
- }else{
- this.loadSelectNode();
- if( this.options.hasShuttle ){
- this.loadShuttleNode();
- }
- //if (this.options.count.toInt()!==1) this.loadSelectedNode();
- this.loadSelectedNode();
- }
- }
- this.fireEvent("postLoadContent", [this]);
- },
- getOffsetX : function(node){
- return (node.getStyle("margin-left").toInt() || 0 )+
- (node.getStyle("margin-right").toInt() || 0 ) +
- (node.getStyle("padding-left").toInt() || 0 ) +
- (node.getStyle("padding-right").toInt() || 0 ) +
- (node.getStyle("border-left-width").toInt() || 0 ) +
- (node.getStyle("border-right-width").toInt() || 0 );
- },
- getOffsetY : function(node){
- return (node.getStyle("margin-top").toInt() || 0 ) +
- (node.getStyle("margin-bottom").toInt() || 0 ) +
- (node.getStyle("padding-top").toInt() || 0 ) +
- (node.getStyle("padding-bottom").toInt() || 0 )+
- (node.getStyle("border-top-width").toInt() || 0 ) +
- (node.getStyle("border-bottom-width").toInt() || 0 );
- },
- loadSelectNodeHTML: function(contentNode){
- var size;
- var height;
- if( contentNode ){
- size = contentNode.getSize();
- height = size.y;
- if( height === 0 ){
- height = contentNode.getStyle("height").toInt();
- }
- }else{
- var container = this.options.injectToBody ? $(document.body) : this.container;
- //var containerSize = this.container.getSize();
- //var bodySize = $(document.body).getSize();
- size = container.getSize();
- if(size.y === 0){
- size.y = $(document.body).getSize().y
- }
- //size = {
- // "x" : Math.min( containerSize.x, bodySize.x ),
- // "y" : Math.min( containerSize.y, bodySize.y )
- //};
- if(this.node){
- var zoom = this.node.getStyle("zoom").toInt() || 0;
- if( zoom ){
- size.x = size.x * 100 / zoom;
- size.y = size.y * 100 / zoom;
- }
- this.node.setStyles({
- "width" : size.x+"px",
- "height" : size.y+"px"
- })
- }
- height = size.y-this.getOffsetY( this.contentNode );
- if( this.titleNode ){
- height = height - this.getOffsetY( this.titleNode ) - ( this.titleNode.getStyle("height").toInt() || 0 )
- }
- if( this.actionNode ){
- height = height - this.getOffsetY( this.actionNode ) - ( this.actionNode.getStyle("height").toInt() || 0 )
- }
- this.contentNode.setStyle("height", ""+height+"px");
- }
- var isFormWithAction = window.location.href.toLowerCase().indexOf("workmobilewithaction.html") > -1;
- this.selectNode.setStyle("height", ""+height+"px");
- if( this.searchInput ){
- this.initSearchInput();
- height = height - this.getOffsetY( this.searchInputDiv ) - ( this.searchInputDiv.getStyle("height").toInt() || 0 )
- }
- if( this.options.hasLetter && this.letterAreaNode ){
- width = size.x - 18;
- this.letterAreaNode.setStyle("width", "" + width + "px");
- this.loadLetters();
- height = height - this.getOffsetY( this.letterAreaNode ) - ( this.letterAreaNode.getStyle("height").toInt() || 0 )
- }
- this.itemAreaScrollNode.setStyle("height", ""+height+"px");
- this.itemAreaScrollNode.setStyle("overflow", "auto");
- if(this.itemSearchAreaScrollNode){
- this.itemSearchAreaScrollNode.setStyles({
- "display": "none",
- "height": ""+height+"px",
- "overflow" : "hidden"
- });
- }
- this.itemSearchAreaNode.setStyle("display", "none");
- this.initLoadSelectItems();
- this.checkLoadSelectItems();
- },
- loadSelectNodeMobile: function(){
- this.selectNode = new Element("div.selectNode", {
- "styles": this.css.selectNodeMobile
- }).inject(this.contentNode);
- var containerSize = this.container.getSize();
- var bodySize = $(document.body).getSize();
- var size = {
- "x" : Math.min( containerSize.x, bodySize.x ),
- "y" : Math.min( containerSize.y, bodySize.y )
- };
- var isFormWithAction = window.location.href.toLowerCase().indexOf("workmobilewithaction.html") > -1;
- var height;
- if( isFormWithAction ){
- height = size.y-40-20-6-20;
- }else{
- height = size.y;
- }
- this.selectNode.setStyle("height", ""+height+"px");
- this.searchInputDiv = new Element("div.searchInputDiv", {
- "styles": this.css.searchInputDiv
- }).inject(this.selectNode);
- this.searchInput = new Element("input.searchInput", {
- "styles": (this.options.count.toInt()===1 || this.options.noSelectedContainer) ? this.css.searchInputSingle : this.css.searchInput,
- "type": "text"
- }).inject(this.searchInputDiv);
- var width = size.x-20-18;
- this.searchInput.setStyle("width", ""+width+"px");
- this.searchInput.setStyle("height", "20px");
- this.initSearchInput();
- if( this.options.hasLetter ) {
- this.letterAreaNode = new Element("div", {
- "styles": this.css.letterAreaMobileNode
- }).inject(this.selectNode);
- width = size.x - 18;
- this.letterAreaNode.setStyle("width", "" + width + "px");
- this.loadLetters();
- }
- this.itemAreaScrollNode = new Element("div.itemAreaScrollNode", {
- "styles": this.css.itemAreaScrollNode
- }).inject(this.selectNode);
- if( isFormWithAction ){
- height = size.y-40-20-78-20;
- }else{
- height = size.y-42-31-40;
- }
- this.itemAreaScrollNode.setStyle("height", ""+height+"px");
- this.itemAreaScrollNode.setStyle("overflow", "auto");
- this.itemAreaNode = new Element("div.itemAreaNode", {
- "styles": this.css.itemAreaNode
- }).inject(this.itemAreaScrollNode);
- this.itemSearchAreaNode = new Element("div.itemSearchAreaNode", {
- "styles": this.css.itemAreaNode
- }).inject(this.itemAreaScrollNode);
- this.itemSearchAreaNode.setStyle("display", "none");
- //MWF.require("MWF.widget.ScrollBar", function(){
- // var _self = this;
- // new MWF.widget.ScrollBar(this.itemAreaScrollNode, {
- // "style":"xApp_Organization_Explorer",
- // "where": "before",
- // "distance": 30,
- // "friction": 4,
- // "axis": {"x": false, "y": true},
- // "onScroll": function(y){
- // _self._scrollEvent(y);
- // }
- // });
- //}.bind(this));
- this.initLoadSelectItems();
- this.checkLoadSelectItems();
- },
- loadSelectedNodeHTML: function(){
- this.setSelectedItem();
- //MWF.require("MWF.widget.ScrollBar", function(){
- // var _self = this;
- // new MWF.widget.ScrollBar(this.selectedScrollNode, {
- // "style":"xApp_Organization_Explorer", "where": "before", "distance": 100, "friction": 4,"axis": {"x": false, "y": true}
- // });
- //}.bind(this));
- if(this.selectedScrollNode)this.selectedScrollNode.setStyle("display", "none");
- },
- checkLoadSelectItems: function(){
- if (!this.options.groups.length && !this.options.roles.length){
- this.loadSelectItems();
- }else{
- this.loadSelectItemsByCondition();
- }
- },
- loadShuttleNode : function(){
- if(this.shuttleNode)return;
- this.shuttleNode = new Element("div.shuttleNode", {
- "styles": this.css.shuttleNode
- }).inject(this.contentNode);
- this.shuttleInnerNode = new Element("div.shuttleInnerNode", {
- "styles": this.css.shuttleInnerNode
- }).inject(this.shuttleNode);
- this.goRightNode = new Element("div.goRightNode", {
- "styles": this.css.goRightNode
- }).inject(this.shuttleInnerNode);
- this.goLeftNode = new Element("div.goLeftNode", {
- "styles": this.css.goLeftNode
- }).inject(this.shuttleInnerNode);
- },
- loadSelectNode: function(){
- this.selectNode = new Element("div.selectNode", {
- "styles": this.css.selectNode //(this.options.count.toInt()===1) ? this.css.selectNodeSingle : this.css.selectNode
- }).inject(this.contentNode);
- if( this.options.hasTop ){ //if( this.options.embedded && this.options.count.toInt()!==1 ){
- this.selectTopNode = new Element("div.selectTopNode",{
- "styles" : this.css.selectTopNode
- }).inject( this.selectNode );
- this.selectTopTextNode = new Element("div",{
- "text" : MWF.SelectorLP.waitingSelect,
- "styles" : this.css.selectTopTextNode
- }).inject( this.selectTopNode );
- }
- if( this.options.searchbarInTopNode ){
- this.searchInputDiv = new Element("div", {
- "styles": this.css.searchInputDiv
- }).inject( this.selectTopNode || this.selectNode);
- }else{
- this.searchInputDiv = new Element("div.searchInputDiv", {
- "styles": this.css.searchInputDiv
- }).inject( this.selectNode);
- }
- this.searchInput = new Element("input", {
- "styles": this.css.searchInput, //(this.options.count.toInt()===1) ? this.css.searchInputSingle : this.css.searchInput,
- "placeholder" : MWF.SelectorLP.searchDescription,
- "type": "text"
- }).inject(this.searchInputDiv);
- this.initSearchInput();
- if( this.options.hasLetter ){
- this.letterAreaNode = new Element("div", {
- "styles": this.css.letterAreaNode
- }).inject(this.selectNode);
- this.loadLetters();
- }
- this.itemAreaScrollNode = new Element("div", {
- "styles": this.css.itemAreaScrollNode
- }).inject(this.selectNode);
- this.itemAreaNode = new Element("div", {
- "styles": this.css.itemAreaNode
- }).inject(this.itemAreaScrollNode);
- this.itemSearchAreaNode = new Element("div", {
- "styles": this.css.itemAreaNode
- }).inject(this.itemAreaScrollNode);
- this.itemSearchAreaNode.setStyle("display", "none");
- this.loadSelectNodeScroll();
- this.initLoadSelectItems();
- this.checkLoadSelectItems();
- },
- loadSelectNodeScroll: function(){
- var overflowY = this.itemAreaScrollNode.getStyle("overflow-y");
- if( typeOf(overflowY)==="string" && (overflowY.toLowerCase() === "auto" || overflowY.toLowerCase() === "scroll") )return;
- MWF.require("MWF.widget.ScrollBar", function(){
- var _self = this;
- new MWF.widget.ScrollBar(this.itemAreaScrollNode, {
- "style":"xApp_Organization_Explorer",
- "where": "before",
- "distance": 30,
- "friction": 4,
- "axis": {"x": false, "y": true},
- "onScroll": function(y){
- _self._scrollEvent(y);
- }
- });
- }.bind(this));
- },
- initSearchInput: function(){
- this.searchInput.addEvents({
- "keydown": function(e){
- var iTimerID = this.searchInput.retrieve("searchTimer", null);
- if (iTimerID){
- window.clearTimeout(iTimerID);
- this.searchInput.eliminate("searchTimer");
- }
- iTimerID = window.setTimeout(function(){
- this.search();
- }.bind(this), 800);
- this.searchInput.store("searchTimer", iTimerID);
- }.bind(this),
- "change": function(e){
- var key = this.searchInput.get("value");
- if (!key) this.initSearchArea(false);
- }.bind(this),
- "blur": function(){
- var key = this.searchInput.get("value");
- if (!key) this.initSearchArea(false);
- }.bind(this)
- });
- },
- initSearchArea: function(flag){
- this.searchItems = [];
- if (flag){
- this.itemSearchAreaNode.empty();
- this.itemAreaNode.setStyle("display", "none");
- if( this.itemSearchAreaNode.getParent() !== this.itemAreaScrollNode ){
- this.itemAreaScrollNode.setStyle("display", "none");
- }
- if(this.flatCategoryScrollNode){
- this.flatCategoryScrollNode.setStyle("display", "none");
- }
- if( this.itemSearchAreaScrollNode )this.itemSearchAreaScrollNode.setStyle("display", "block");
- this.itemSearchAreaNode.setStyle("display", "block");
- }else{
- this.itemAreaScrollNode.setStyle("display", "block");
- this.itemAreaNode.setStyle("display", "block");
- if(this.flatCategoryScrollNode && this.flatSubCategoryNodeList && this.flatSubCategoryNodeList.length > 1 ){
- this.flatCategoryScrollNode.setStyle("display", "block");
- }
- if( this.itemSearchAreaScrollNode )this.itemSearchAreaScrollNode.setStyle("display", "none");
- this.itemSearchAreaNode.setStyle("display", "none");
- }
- },
- search: function(){
- if (!this.options.groups.length && !this.options.roles.length && !this.options.forceSearchInItem ){
- var key = this.searchInput.get("value");
- if (key){
- this._listItemByKey(function(json){
- this.initSearchArea(true);
- json.data.each(function(data){
- if( !this.isExcluded( data ) ) {
- var itemSearch = this._newItemSearch(data, this, this.itemSearchAreaNode);
- this.searchItems.push( itemSearch );
- }
- //this._newItem(data, this, this.itemSearchAreaNode);
- }.bind(this));
- }.bind(this), null, key);
- }else{
- this.initSearchArea(false);
- }
- }else{
- var key = this.searchInput.get("value");
- if (key){
- this.initSearchArea(true);
- this.searchInItems(key);
- }else{
- this.initSearchArea(false);
- }
- }
- },
- searchInItems: function(key){
- var createdId = [];
- this.createItemsSearchData(function(){
- var word = key.toLowerCase();
- this.itemsSearchData.each(function(obj){
- var text = obj.text+"#"+obj.pinyin+"#"+obj.firstPY;
- var id = obj.data.distinguishedName || obj.data.id || obj.data.name || obj.data.text;
- if (text.indexOf(word)!==-1){
- if (createdId.indexOf( id )===-1){
- this._newItem(obj.data, this, this.itemSearchAreaNode);
- createdId.push( id );
- }
- }
- }.bind(this));
- //delete createdId;
- }.bind(this));
- return createdId;
- },
- createItemsSearchData: function(callback){
- if (!this.itemsSearchData){
- this.itemsSearchData = [];
- MWF.require("MWF.widget.PinYin", function(){
- var initIds = [];
- this.items.each(function(item){
- var id = item.data.distinguishedName || item.data.id || item.data.name || item.data.text;
- if (initIds.indexOf( id )==-1){
- var text = item._getShowName().toLowerCase();
- var pinyin = text.toPY().toLowerCase();
- var firstPY = text.toPYFirst().toLowerCase();
- this.itemsSearchData.push({
- "text": text,
- "pinyin": pinyin,
- "firstPY": firstPY,
- "data": item.data
- });
- initIds.push( id );
- }
- }.bind(this));
- delete initIds;
- if (callback) callback();
- }.bind(this));
- }else{
- if (callback) callback();
- }
- },
- initSelectedSearchInput: function(){
- this.selectedSearchInput.addEvents({
- "keydown": function(e){
- var iTimerID = this.selectedSearchInput.retrieve("searchTimer", null);
- if (iTimerID){
- window.clearTimeout(iTimerID);
- this.selectedSearchInput.eliminate("searchTimer");
- }
- iTimerID = window.setTimeout(function(){
- this.selectedSearch();
- }.bind(this), 800);
- this.selectedSearchInput.store("searchTimer", iTimerID);
- }.bind(this),
- "change": function(e){
- var key = this.selectedSearchInput.get("value");
- if (!key) this.selectedSearch();
- }.bind(this),
- "blur": function(){
- var key = this.selectedSearchInput.get("value");
- if (!key) this.selectedSearch();
- }.bind(this)
- });
- },
- selectedSearch: function(){
- var key = this.selectedSearchInput.get("value");
- if (key){
- this.selectedSearchInItems(key);
- }else{
- this.showAllSelectedItem()
- }
- },
- selectedSearchInItems: function(key){
- var word = key.toLowerCase();
- MWF.require("MWF.widget.PinYin", function() {
- this.selectedItems.each(function (item) {
- if (!item.searchedText) {
- var text = item._getShowName().toLowerCase();
- var pinyin = text.toPY().toLowerCase();
- var firstPY = text.toPYFirst().toLowerCase();
- item.searchedText = text + "#" + pinyin + "#" + firstPY
- }
- if (item.searchedText.indexOf(word) !== -1) {
- item.node.show()
- } else {
- item.node.hide()
- }
- }.bind(this));
- }.bind(this), null, false);
- },
- showAllSelectedItem: function(){
- this.selectedItems.each(function(item){
- item.node.show()
- })
- },
- loadSelectedNode: function( callback ){
- if( this.selectedContainerNode )return;
- this.selectedContainerNode = new Element("div", {
- "styles": this.css.selectedContainerNode
- }).inject(this.contentNode);
- if( this.options.noSelectedContainer ){
- this.selectedContainerNode.hide();
- }
- //if( this.options.embedded && this.options.count.toInt()!==1 ){
- if( this.options.hasTop ){
- this.selectedTopNode = new Element("div",{
- "styles" : this.css.selectedTopNode
- }).inject( this.selectedContainerNode );
- this.selectedTopTextNode = new Element("div",{
- "text" : MWF.SelectorLP.selected,
- "styles" : this.css.selectedTopTextNode
- }).inject( this.selectedTopNode );
- this.emptySelectedNode = new Element("div",{
- "text" : MWF.SelectorLP.empty,
- "styles" : this.css.selectedTopActionNode,
- "events" : {
- "click" : function(){
- this.emptySelectedItems()
- }.bind(this)
- }
- }).inject( this.selectedTopNode );
- }
- if( this.options.hasSelectedSearchbar ){
- if( this.options.searchbarInTopNode ){
- this.selectedSearchInputDiv = new Element("div", {
- "styles": this.css.searchInputDiv
- }).inject( this.selectedTopNode || this.selectedContainerNode);
- }else{
- this.selectedSearchInputDiv = new Element("div.selectedSearchInputDiv", {
- "styles": this.css.searchInputDiv
- }).inject( this.selectedContainerNode);
- }
- this.selectedSearchInput = new Element("input", {
- "styles": this.css.searchInput, //(this.options.count.toInt()===1) ? this.css.searchInputSingle : this.css.searchInput,
- "placeholder" : MWF.SelectorLP.searchDescription,
- "type": "text"
- }).inject(this.selectedSearchInputDiv);
- this.initSelectedSearchInput();
- }
- this.selectedScrollNode = new Element("div.selectedScrollNode", {
- "styles": this.css.selectedScrollNode
- }).inject(this.selectedContainerNode);
- this.selectedNode = new Element("div.selectedNode", {
- "styles": this.css.selectedNode
- }).inject(this.selectedScrollNode);
- if( this.options.hasSelectedSearchbar ){
- this.selectedItemSearchAreaNode = new Element("div.selectedItemSearchAreaNode", {
- "styles": this.css.itemAreaNode
- }).inject(this.selectedScrollNode);
- this.selectedItemSearchAreaNode.setStyle("display", "none");
- }
- this.setSelectedItem();
- this.loadSelectedNodeScroll();
- if(callback)callback();
- },
- emptySelectedItems : function(){
- while (this.selectedItems.length){
- this.selectedItems[0].clickItem();
- }
- },
- loadSelectedNodeScroll: function(){
- var overflowY = this.selectedScrollNode.getStyle("overflow-y");
- if( typeOf(overflowY)==="string" && (overflowY.toLowerCase() === "auto" || overflowY.toLowerCase() === "scroll") )return;
- MWF.require("MWF.widget.ScrollBar", function(){
- var _self = this;
- new MWF.widget.ScrollBar(this.selectedScrollNode, {
- "style":"xApp_Organization_Explorer", "where": "before", "distance": 100, "friction": 4,"axis": {"x": false, "y": true}
- });
- }.bind(this));
- },
- loadSelectedNodeMobile: function(){
- this.selectedScrollNode = new Element("div.selectedScrollNode", {
- "styles": this.css.selectedScrollNode
- }).inject(this.contentNode);
- this.selectedNode = new Element("div.selectedNode", {
- "styles": this.css.selectedNode
- }).inject(this.selectedScrollNode);
- this.setSelectedItem();
- // MWF.require("MWF.widget.ScrollBar", function(){
- // var _self = this;
- // new MWF.widget.ScrollBar(this.selectedScrollNode, {
- // "style":"xApp_Organization_Explorer", "where": "before", "distance": 100, "friction": 4,"axis": {"x": false, "y": true}
- // });
- // }.bind(this));
- this.selectedScrollNode.setStyle("display", "none");
- },
- setSelectedItem: function(){
- if (this.options.values.length){
- this.options.values.each(function(v, i){
- if (typeOf(v)==="object"){
- this.selectedItems.push(this._newItemSelected(v, this, null));
- }else{
- this._getItem(function(json){
- this.options.values[i] = json.data;
- this.selectedItems.push(this._newItemSelected(json.data, this, null));
- }.bind(this), null, v, false);
- }
- // this._getItem(function(json){
- // this.selectedItems.push(this._newItemSelected(json.data, this, null));
- // }.bind(this), null, v, false);
- }.bind(this));
- }
- },
- loadLetters: function(){
- var _self = this;
- letters = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];
- var letterNodeCss = this.css.letterNode;
- var letterNodeCss_over = this.css.letterNode_over;
- if (layout.mobile){
- letterNodeCss = this.css.letterNode_mobile || letterNodeCss;
- letterNodeCss_over = this.css.letterNode_mobile_over || letterNodeCss_over;
- var size = this.container.getSize();
- var w = (layout.mobile) ? (size.x-18)/13 : (size.x-20-4-18)/13;
- //letterNode.setStyle("width", ""+w+"px");
- letterNodeCss.width = ""+w+"px";
- letterNodeCss_over.width = ""+w+"px";
- }
- letters.each(function(l){
- var letterNode = new Element("div", {
- "styles": letterNodeCss,
- "text": l
- }).inject(this.letterAreaNode);
- if (layout.mobile){
- letterNode.addEvents({
- "click": function(){
- _self.listPersonByPinyin(this);
- }
- });
- }else{
- letterNode.addEvents({
- "mouseover": function(e){
- e.target.setStyles(letterNodeCss_over);
- var showNode = new Element("div", {
- "styles": this.css.letterShowNode,
- "text": e.target.get("text")
- }).inject(this.selectNode);
- showNode.position({
- relativeTo: this.itemAreaScrollNode,
- position: "center",
- edge: "center"
- });
- e.target.store("showNode", showNode);
- }.bind(this),
- "mouseout": function(e){
- var showNode = e.target.retrieve("showNode");
- showNode.destroy();
- e.target.setStyles(letterNodeCss);
- }.bind(this),
- "click": function(){
- _self.listPersonByPinyin(this);
- }
- });
- }
- }.bind(this));
- },
- listPersonByPinyin: function(node){
- this.searchInput.focus();
- var pinyin = this.searchInput.get("value");
- pinyin = pinyin+node.get("text");
- this.searchInput.set("value", pinyin);
- if (!this.options.groups.length && !this.options.roles.length){
- if (pinyin){
- this._listItemByPinyin(function(json){
- this.initSearchArea(true);
- json.data.each(function(data){
- // var flag = true;
- // if (this.options.departments){
- // if (this.options.departments.length){
- // if (this.options.departments.indexOf(data.departmentName)==-1) flag = false;
- // }
- // }
- // if (this.options.companys){
- // if (this.options.companys.length){
- // if (this.options.companys.indexOf(data.company)==-1) flag = false;
- // }
- // }
- if( !this.isExcluded( data ) ) {
- this._newItemSearch(data, this, this.itemSearchAreaNode);
- }
- //this._newItem(data, this, this.itemSearchAreaNode);
- //this._newItem(data, this, this.itemSearchAreaNode);
- }.bind(this));
- }.bind(this), null, pinyin.toLowerCase());
- }
- }else{
- if (pinyin){
- this.initSearchArea(true);
- this.searchInItems(pinyin);
- }else{
- this.initSearchArea(false);
- }
- }
- },
- initLoadSelectItems: function(){
- this.loaddingItems = false;
- this.isItemLoaded = false;
- this.loadItemsQueue = 0;
- this.initSearchArea(false);
- },
- //loadSelectItems: function(addToNext){
- // if (!this.isItemLoaded){
- // if (!this.loaddingItems){
- // this.loaddingItems = true;
- // var count = 20;
- // this._listItemNext(this.getLastLoadedItemId(), count, function(json){
- // if (json.data.length){
- // json.data.each(function(data){
- // var item = this._newItem(data, this, this.itemAreaNode);
- // this.items.push(item);
- // }.bind(this));
- // this.loaddingItems = false;
- //
- // if (json.data.length<count){
- // this.isItemLoaded = true;
- // }else{
- // if (this.loadItemsQueue>0){
- // this.loadItemsQueue--;
- // this.loadSelectItems();
- // }
- // }
- // }else{
- // this.isItemLoaded = true;
- // this.loaddingItems = false;
- // }
- // }.bind(this));
- // }else{
- // if (addToNext) this.loadItemsQueue++;
- // }
- // }
- //},
- loadSelectItems: function(addToNext, lastExcludeCount ){
- //lastExcludeCount 参数:表示本次加载是为了补足上次load的时候被排除的数量
- if (!this.isItemLoaded){
- if (!this.loaddingItems){
- this.loaddingItems = true;
- var count = 20;
- this._listItemNext(this.getLastLoadedItemId(), count, function(json){
- if (json.data.length){
- var excludedCount = 0;
- json.data.each(function(data, i){
- if( this.isExcluded( data ) ){
- excludedCount++;
- if( i+1 === count )this.tailExcludeItemId = data.distinguishedName
- }else{
- var item = this._newItem(data, this, this.itemAreaNode);
- this.items.push(item);
- if( i+1 === count )this.tailExcludeItemId = null;
- }
- }.bind(this));
- this.loaddingItems = false;
- if( lastExcludeCount ){ //如果是因为上次load的时候被排除而加载的
- if( count - lastExcludeCount - excludedCount < 0 ){ //如果本次load的数量还不够补足排除的数量,需要再次load
- excludedCount = lastExcludeCount + excludedCount - count; //把不足的数量作为再次load的参数
- this.loadItemsQueue++
- }
- }else if( excludedCount > 0 ){ //把排除的数量作为再次load的参数
- this.loadItemsQueue++
- }
- if (json.data.length<count){
- this.isItemLoaded = true;
- }else{
- if (this.loadItemsQueue>0){
- this.loadItemsQueue--;
- this.loadSelectItems( addToNext, excludedCount );
- }
- }
- }else{
- this.isItemLoaded = true;
- this.loaddingItems = false;
- }
- if( this.afterLoadSelectItem )this.afterLoadSelectItem();
- }.bind(this));
- }else{
- if (addToNext) this.loadItemsQueue++;
- }
- }
- },
- getLastLoadedItemId: function(){
- if( this.tailExcludeItemId )return this.tailExcludeItemId;
- return (this.items.length) ? this.items[this.items.length-1].data.distinguishedName : "(0)";
- },
- //loadSelectItemsByCondition: function(){
- // this.options.groups.each(function(group){
- //
- // this.orgAction.listGroupByKey(function(json){
- // if (json.data.length){
- // var groupData = json.data[0];
- // var category = this._newItemCategory("ItemGroupCategory", groupData, this, this.itemAreaNode);
- // this._getChildrenItemIds(groupData).each(function(id){
- // this._getItem(function(json){
- // var item = this._newItem(json.data, this, category.children);
- // this.items.push(item);
- // }.bind(this), null, id);
- // }.bind(this));
- // }
- // }.bind(this), null, group);
- // }.bind(this));
- //
- // this.options.roles.each(function(role){
- // this.orgAction.listRoleByKey(function(json){
- // if (json.data.length){
- // var roleData = json.data[0];
- // var category = this._newItemCategory("ItemRoleCategory", roleData, this, this.itemAreaNode);
- // this._getChildrenItemIds(roleData).each(function(id){
- // this._getItem(function(json){
- // var item = this._newItem(json.data, this, category.children);
- // this.items.push(item);
- // }.bind(this), null, id)
- // }.bind(this));
- // }
- // }.bind(this), null, role);
- // }.bind(this));
- //},
- loadSelectItemsByCondition: function(){
- this.options.groups.each(function(group){
- this.orgAction.listGroupByKey(function(json){
- if (json.data.length){
- var groupData = json.data[0];
- var category = this._newItemCategory("ItemGroupCategory", groupData, this, this.itemAreaNode);
- this.subCategorys.push(category);
- this._getChildrenItemIds(groupData).each(function(id){
- this._getItem(function(json){
- if( !this.isExcluded( json.data ) ) {
- var item = this._newItem(json.data, this, category.children);
- this.items.push(item);
- }
- }.bind(this), null, id);
- }.bind(this));
- }
- }.bind(this), null, group);
- }.bind(this));
- this.options.roles.each(function(role){
- this.orgAction.listRoleByKey(function(json){
- if (json.data.length){
- var roleData = json.data[0];
- var category = this._newItemCategory("ItemRoleCategory", roleData, this, this.itemAreaNode);
- this.subCategorys.push(category);
- this._getChildrenItemIds(roleData).each(function(id){
- this._getItem(function(json){
- if( !this.isExcluded( json.data ) ) {
- var item = this._newItem(json.data, this, category.children);
- this.items.push(item);
- }
- }.bind(this), null, id)
- }.bind(this));
- }
- }.bind(this), null, role);
- }.bind(this));
- },
- isExcluded : function( d ){
- if( this.options.exclude.length === 0 )return false;
- if( !this.excludeFlagMap ){
- this.excludeFlagMap = {};
- this.options.exclude.each( function( e ){
- if( !e )return;
- this.excludeFlagMap[ typeOf( e ) === "string" ? e : ( e.distinguishedName || e.id || e.unique || e.employee || e.levelName) ] = true;
- }.bind(this));
- }
- var map = this.excludeFlagMap;
- return ( d.distinguishedName && map[ d.distinguishedName ] ) ||
- ( d.id && map[ d.id ] ) ||
- ( d.unique && map[ d.unique ] ) ||
- ( d.employee && map[ d.employee ] ) ||
- ( d.levelName && map[ d.levelName ] );
- },
- _getChildrenItemIds: function(data){
- return data.personList;
- },
- _newItemCategory: function(type, data, selector, item){
- return new MWF.xApplication.Selector.Person[type](data, selector, item)
- },
- _listItemByKey: function(callback, failure, key){
- this.orgAction.listPersonByKey(function(json){
- if (callback) callback.apply(this, [json]);
- }.bind(this), failure, key);
- },
- _getItem: function(callback, failure, id, async){
- this.orgAction.getPerson(function(json){
- if (callback) callback.apply(this, [json]);
- }.bind(this), failure, ((typeOf(id)==="string") ? id : id.distinguishedName), async);
- },
- _newItemSelected: function(data, selector, item, selectedNode){
- return new MWF.xApplication.Selector.Person.ItemSelected(data, selector, item, selectedNode)
- },
- _listItemByPinyin: function(callback, failure, key){
- this.orgAction.listPersonByPinyin(function(json){
- if (callback) callback.apply(this, [json]);
- }.bind(this), failure, key);
- },
- _newItem: function(data, selector, container){
- return new MWF.xApplication.Selector.Person.Item(data, selector, container);
- },
- _newItemSearch: function(data, selector, container){
- return this._newItem(data, selector, container);
- },
- _listItemNext: function(last, count, callback){
- this.orgAction.listPersonNext(last, count, function(json){
- if (callback) callback.apply(this, [json]);
- }.bind(this));
- },
- _scrollEvent: function(y){
- if (!this.options.groups.length && !this.options.roles.length){
- var scrollSize = this.itemAreaScrollNode.getScrollSize();
- var clientSize = this.itemAreaScrollNode.getSize();
- var scrollHeight = scrollSize.y-clientSize.y;
- if (y+30>scrollHeight) {
- if (!this.isItemLoaded) this.loadSelectItems();
- }
- }
- },
- afterLoadSelectItem : function(){
- if( this.items.length === 0 && this.subItems.length === 0 && this.subCategorys.length === 0 ){
- this.noSelectableItemTextDiv = new Element("div", {
- text : MWF.SelectorLP.noSelectableItemText,
- styles : this.css.noSelectableItemText
- }).inject( this.itemAreaNode );
- }
- if( this.options.selectSingleItem ){
- this.selectSingleItem()
- }
- this.fireEvent("afterLoadSelectItem", [this]);
- },
- selectSingleItem: function(){
- if( !this.options.contentUrl && !layout.mobile){
- if( this.options.hasShuttle && !this.shuttleNode ){
- this.loadShuttleNode();
- }
- if( !this.selectedContainerNode ) {
- this.loadSelectedNode(function () {
- this._selectSingleItem();
- }.bind(this));
- }else{
- this._selectSingleItem();
- }
- }else{
- this._selectSingleItem();
- }
- },
- _selectSingleItem : function(){
- var checkItem = function () {
- if(this.items.length === 1 || this.subItems.length === 1 ){
- if( this.items.length === 1 && this.subItems.length === 0 ){
- if( !this.items[0].isSelected )this.items[0].clickItem();
- }else if( this.items.length === 0 && this.subItems.length === 1 ){
- if( !this.items[0].isSelected )this.subItems[0].clickItem();
- }else if( this.items.length === 1 && this.subItems.length === 1 ){
- if( this.items[0] === this.subItems[0] ){
- if( !this.items[0].isSelected )this.items[0].clickItem();
- }
- }
- }
- }.bind(this);
- var checkCategoryItem = function (category) {
- if( !category.subCategorys || category.subCategorys.length === 0 ){
- if( category.subItems && category.subItems.length === 1 ){
- if( !category.subItems[0].isSelected )category.subItems[0].clickItem();
- }
- }else if(category.subCategorys.length === 1){
- if( category.subItems && category.subItems.length > 0 ){
- }else if( !category.subCategorys[0]._hasChild || !category.subCategorys[0]._hasChild() ){ //category.subCategorys[0].isItem &&
- if( !category.subItems[0].isSelected )category.subItems[0].clickItem();
- }else{
- checkCategory( category.subCategorys[0] )
- }
- }else{
- var list = [];
- for( var i=0; i<category.subCategorys.length; i++ ){
- if( category.subCategorys[i]._hasChild && category.subCategorys[i]._hasChild() ){
- list.push( category.subCategorys[i] );
- }
- }
- if( list.length === 1 ){
- if( !category.subItems || category.subItems.length === 0 ){
- checkCategory( list[0] );
- }
- }
- if( list.length === 0 ){
- if( category.subItems && category.subItems.length === 1 ){
- if( !category.subItems[0].isSelected )category.subItems[0].clickItem();
- }
- }
- }
- };
- var checkCategory = function ( category ) {
- if( category.loaded ){
- checkCategoryItem( category )
- }else if( category.loading ){
- window.setTimeout( function () {
- checkCategory( category )
- }, 100 )
- }
- };
- if( this.subCategorys.length === 1 ) {
- checkCategory( this.subCategorys[0] );
- }else if( this.subCategorys.length === 0 ){
- checkItem();
- }
- },
- setSize : function(){
- debugger;
- if( !this.options.width && !this.options.height )return;
- var getOffsetX = function(node){
- return (node.getStyle("margin-left").toInt() || 0 )+
- (node.getStyle("margin-right").toInt() || 0 ) +
- (node.getStyle("padding-left").toInt() || 0 ) +
- (node.getStyle("padding-right").toInt() || 0 ) +
- (node.getStyle("border-left-width").toInt() || 0 ) +
- (node.getStyle("border-right-width").toInt() || 0 );
- };
- var getOffsetY = function(node){
- return (node.getStyle("margin-top").toInt() || 0 ) +
- (node.getStyle("margin-bottom").toInt() || 0 ) +
- (node.getStyle("padding-top").toInt() || 0 ) +
- (node.getStyle("padding-bottom").toInt() || 0 )+
- (node.getStyle("border-top-width").toInt() || 0 ) +
- (node.getStyle("border-bottom-width").toInt() || 0 );
- };
- if( this.options.width && this.options.width === "auto" ){
- //if (this.options.count.toInt() !== 1){
- if( this.node )this.node.setStyle("width", "auto");
- this.selectNode.setStyles({
- "width": "50%",
- "float" : "left"
- });
- //this.searchInput.setStyle("width", "99%");
- if(this.letterAreaNode ){
- this.letterAreaNode.setStyle("width", "auto");
- }
- this.selectedContainerNode.setStyle("width", "auto");
- var overflowY = this.selectedScrollNode.getStyle("overflow-y");
- if( typeOf(overflowY)==="string" && (overflowY.toLowerCase() === "auto" || overflowY.toLowerCase() === "scroll") ){
- this.selectedScrollNode.setStyle("width", "auto");
- }else{
- this.selectedScrollNode.setStyle("margin-right", "8px");
- }
- //}else{
- // this.node.setStyle("width", "auto");
- // this.selectNode.setStyle("width", "auto");
- //}
- }else if( this.options.width && typeOf( this.options.width.toInt() ) === "number" ){
- var nodeWidth;
- if( this.node ){
- nodeWidth = this.options.width.toInt() - getOffsetX(this.node);
- this.node.setStyle("width", nodeWidth);
- }else{
- nodeWidth = this.options.width.toInt();
- }
- nodeWidth = nodeWidth - getOffsetX( this.contentNode );
- if( this.shuttleNode ){
- nodeWidth = nodeWidth - getOffsetX(this.shuttleNode) - this.shuttleNode.getStyle("width").toInt();
- }
- //if (this.options.count.toInt() !== 1){
- var width = nodeWidth - getOffsetX(this.selectNode) - getOffsetX(this.selectedContainerNode);
- var halfWidth = this.options.noSelectedContainer ? width : ( Math.floor(width / 2) - 2);
- this.selectNode.setStyle("width", halfWidth);
- //this.searchInput.setStyle("width", halfWidth - 6);
- if(this.letterAreaNode ){
- this.letterAreaNode.setStyle("width", halfWidth - 19);
- }
- this.selectedContainerNode.setStyle("width", halfWidth);
- var overflowY = this.selectedScrollNode.getStyle("overflow-y");
- if( typeOf(overflowY)==="string" && (overflowY.toLowerCase() === "auto" || overflowY.toLowerCase() === "scroll") ){
- this.selectedScrollNode.setStyle("width", halfWidth);
- }else{
- this.selectedScrollNode.setStyle("width", halfWidth - 8);
- }
- //}else{
- // var width = nodeWidth - getOffsetX(this.selectNode);
- // this.selectNode.setStyle("width", width);
- //}
- }
- if( this.options.height && typeOf( this.options.height.toInt() ) === "number" ){
- var nodeHeight;
- if( this.node ){
- nodeHeight = this.options.height.toInt() - getOffsetY(this.node);
- this.node.setStyle("height", nodeHeight);
- }else{
- nodeHeight = this.options.height.toInt();
- }
- nodeHeight = nodeHeight - getOffsetY( this.contentNode ) - 1;
- if( this.titleNode ){
- nodeHeight = nodeHeight - getOffsetY( this.titleNode ) - this.titleNode.getStyle("height").toInt();
- }
- if( this.actionNode ){
- nodeHeight = nodeHeight - getOffsetY( this.actionNode ) - this.actionNode.getStyle("height").toInt();
- }
- var selectNodeHeight = nodeHeight - getOffsetY(this.selectNode);
- this.selectNode.setStyle("height", selectNodeHeight);
- if( this.shuttleNode ){
- this.shuttleNode.setStyle("height", selectNodeHeight);
- var shuttleInnerHieght = getOffsetY( this.shuttleInnerNode ) + this.shuttleInnerNode.getStyle("height").toInt();
- this.shuttleInnerNode.setStyle("margin-top", (selectNodeHeight-shuttleInnerHieght)/2 +"px" )
- }
- var itemAreaScrollNodeHeight = selectNodeHeight - getOffsetY( this.searchInputDiv ) - this.searchInputDiv.getStyle("height").toInt();
- if( !this.options.searchbarInTopNode && this.selectTopNode ){
- itemAreaScrollNodeHeight = itemAreaScrollNodeHeight - getOffsetY( this.selectTopNode ) - this.selectTopNode.getStyle("height").toInt();
- }
- if(this.letterAreaNode ){
- itemAreaScrollNodeHeight = itemAreaScrollNodeHeight - getOffsetY( this.letterAreaNode ) - this.letterAreaNode.getStyle("height").toInt();
- }
- itemAreaScrollNodeHeight = itemAreaScrollNodeHeight - getOffsetY( this.itemAreaScrollNode );
- this.itemAreaScrollNode.setStyle("height", itemAreaScrollNodeHeight);
- var selectedContainerNodeHeight = nodeHeight - getOffsetY(this.selectedContainerNode);
- this.selectedContainerNode.setStyle("height", selectedContainerNodeHeight);
- var selectedScrollNodeHeight = selectedContainerNodeHeight;
- if( this.selectedTopNode ) {
- selectedScrollNodeHeight = selectedScrollNodeHeight - getOffsetY(this.selectedTopNode) - this.selectedTopNode.getStyle("height").toInt();
- }
- if( !this.options.searchbarInTopNode && this.selectedSearchInputDiv ){
- selectedScrollNodeHeight = selectedScrollNodeHeight - getOffsetY( this.selectedSearchInputDiv ) - this.selectedSearchInputDiv.getStyle("height").toInt();
- }
- this.selectedScrollNode.setStyle("height", selectedScrollNodeHeight);
- }
- this.fireEvent("setSize",[this])
- },
- addFlatCategoryItem : function( categoryItemNode, hasChildrenItem, itemNodeContainer, isCreateSubCategoryListNode ){
- if(!this.flatSubCategoryNodeList)this.flatSubCategoryNodeList = [];
- if( hasChildrenItem )this.flatSubCategoryNodeList.push( categoryItemNode );
- if( !this.isFlatCategoryLoaded && this.flatSubCategoryNodeList.length > 1 ){
- this.flatCategoryScrollNode.show();
- this.flatCategoryScrollNode.setStyles( this.css.flatCategoryScrollNode );
- var height = this.itemAreaScrollNode.getStyle("height").toInt();
- this.flatCategoryScrollNode.setStyle("height", ""+height+"px");
- this.flatCategoryNode.setStyles( this.css.flatCategoryNode );
- this.isFlatCategoryLoaded = true;
- this.itemAreaScrollNode.setStyles( this.css.itemAreaScrollNode_flatCategory );
- //alert(this.flatSubCategoryNodeList[0].outerHTML)
- }
- if( hasChildrenItem )categoryItemNode.inject( itemNodeContainer || this.flatCategoryNode );
- var subCategoryListNode;
- if( isCreateSubCategoryListNode ){
- subCategoryListNode = new Element("div.subCategoryListNode").inject( itemNodeContainer || this.flatCategoryNode );
- }
- //this.setFlatCategorySequence(categoryItemNode, itemNodeContainer, subCategoryListNode);
- if( hasChildrenItem ){
- //if( this.checkClickFlatCategoryItem(categoryItemNode, itemNodeContainer) ){
- // categoryItemNode.click();
- //}
- if( !this.currentCategoryItemNode ){
- categoryItemNode.click();
- this.currentCategoryItemNode = categoryItemNode
- }else{
- //var date = new Date();
- var first = this.flatCategoryNode.getElement(".flatCategoryItemNode");
- //if(first)console.log(first.get("title"));
- //console.log(new Date() - date );
- //console.log(" " );
- if( first ){
- var dn1 = first.retrieve("dn");
- var dn2 = this.currentCategoryItemNode.retrieve("dn");
- if( dn1 && dn2 ){
- if( dn1 != dn2 ){
- categoryItemNode.click();
- this.currentCategoryItemNode = categoryItemNode
- }
- }else{
- var title1 = first.get("title");
- var title2 = this.currentCategoryItemNode.get("title");
- if( title1 && title1 ){
- if( title1 != title2 ){
- categoryItemNode.click();
- this.currentCategoryItemNode = categoryItemNode
- }
- }else{
- var text1 = first.get("text");
- var text2 = this.currentCategoryItemNode.get("text");
- if( text1 != text2 ){
- categoryItemNode.click();
- this.currentCategoryItemNode = categoryItemNode
- }
- }
- }
- }
- }
- }
- return subCategoryListNode;
- }
- //checkClickFlatCategoryItem : function(categoryItemNode, itemNodeContainer){
- // if( !this.flatCategorySeqObj_current ){
- // this.flatCategorySeqObj_current = categoryItemNode.retrieve("seq");
- // //console.log(this.flatCategorySeqObj_current)
- // return true;
- // }
- // var seq_cur = this.flatCategorySeqObj_current;
- // var seq = categoryItemNode ? categoryItemNode.retrieve("seq") : [];
- // for( var i=0; i<seq.length; i++ ){
- // if( seq_cur[i] && seq[i] < seq_cur[i] ){
- // //console.log(seq)
- // this.flatCategorySeqObj_current = seq;
- // return true;
- // }else if( !seq_cur[i] || seq[i] > seq_cur[i] ){
- // return false;
- // }
- // }
- // return false;
- //},
- //setFlatCategorySequence: function(categoryItemNode, itemNodeContainer, subCategoryListNode){
- // if( !this.flatCategorySeqObj )this.flatCategorySeqObj = {};
- // var parentSeq = itemNodeContainer ? itemNodeContainer.retrieve("seq") : [];
- // var seq = Array.clone( parentSeq );
- // if( this.flatCategorySeqObj[ parentSeq.length ] ){
- // seq.push( this.flatCategorySeqObj[ parentSeq.length ] + 1 );
- // this.flatCategorySeqObj[parentSeq.length] = this.flatCategorySeqObj[parentSeq.length]+1;
- //
- // categoryItemNode.store( "seq", seq );
- // categoryItemNode.set( "seq", seq );
- //
- // if(subCategoryListNode){
- // seq = Array.clone( seq );
- // seq[ seq.length - 1 ] = seq[ seq.length - 1 ]+1;
- // this.flatCategorySeqObj[parentSeq.length] = this.flatCategorySeqObj[parentSeq.length]+1;
- // subCategoryListNode.store("seq", seq );
- // subCategoryListNode.set( "seq", seq );
- // }
- // }else{
- // seq.push( 1 );
- // this.flatCategorySeqObj[ parentSeq.length ] = 1;
- // categoryItemNode.store( "seq", seq );
- // categoryItemNode.set( "seq", seq );
- //
- // if(subCategoryListNode) {
- // seq = Array.clone(seq);
- // seq[seq.length - 1] = seq[seq.length - 1]+1;
- // this.flatCategorySeqObj[parentSeq.length] = this.flatCategorySeqObj[parentSeq.length]+1;
- // subCategoryListNode.store("seq", seq);
- // subCategoryListNode.set("seq", seq);
- // }
- // }
- //}
- });
- MWF.xApplication.Selector.Person.Item = new Class({
- initialize: function(data, selector, container, level, category, delay){
- this.clazz = "Item";
- this.data = data;
- this.selector = selector;
- this.container = container;
- this.isSelected = false;
- this.level = (level) ? level.toInt() : 1;
- this.category = category;
- this.subItems = [];
- this.subCategorys = [];
- if(!delay)this.load();
- },
- _getShowName: function(){
- return this.data.name + ( this.data.employee ? ("("+this.data.employee+")") : "" );
- },
- _getTtiteText: function(){
- return this.data.name + ( this.data.employee ? ("("+this.data.employee+")") : "" );
- },
- _setIcon: function(){
- var style = this.selector.options.style;
- this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/personicon.png)");
- },
- load: function(){
- if( this.clazz === "Item" ){
- this.selector.fireEvent("queryLoadItem",[this]);
- }
- if( !this.node )this.node = new Element("div", {
- "styles": this.selector.css.selectorItem
- }).inject(this.container);
- this.levelNode = new Element("div", {
- "styles": this.selector.css.selectorItemLevelNode
- }).inject(this.node);
- if( this.selector.selectType !== "identity" || this.selector.options.identityItemWidth === 0 ) {
- var indent = this.selector.options.level1Indent + (this.level - 1) * this.selector.options.indent;
- this.levelNode.setStyle("width", "" + indent + "px");
- }
- this.iconNode = new Element("div", {
- "styles": this.selector.css.selectorItemIconNode
- }).inject(this.node);
- this._setIcon();
- this.actionNode = new Element("div", {
- "styles": this.selector.css.selectorItemActionNode
- }).inject(this.node);
- if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single ){
- this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single );
- }
- this.textNode = new Element("div", {
- "styles": this.selector.css.selectorItemTextNode,
- "text": this._getShowName(),
- "title": this._getTtiteText()
- }).inject(this.node);
- this.textNode.store("indent", indent);
- var m = this.textNode.getStyle("margin-left").toFloat()+indent;
- this.textNode.setStyle("margin-left", ""+m+"px");
- if( this.selector.options.identityItemWidth && this.selector.selectType === "identity"){
- this.node.setStyles({
- "float" : "left",
- "min-width" : this.selector.options.identityItemWidth + "px"
- })
- }
- if(this.postLoad)this.postLoad();
- this.loadSubItem();
- this.setEvent();
- this.check();
- if( this.clazz === "Item" ) {
- this.selector.fireEvent("postLoadItem", [this]);
- }
- },
- loadSubItem: function(){},
- disable : function(){
- this.node.hide();
- this.disabled = true;
- },
- enable : function(){
- this.node.show();
- this.disabled = false;
- },
- check: function(){
- //if (this.selector.options.count.toInt()===1){
- // this.checkSelectedSingle();
- //}else{
- this.checkSelected();
- //}
- },
- checkSelectedSingle: function(){
- var selectedItem = this.selector.options.values.filter(function(item, index){
- if (typeOf(item)==="object") return this.data.distinguishedName === item.distinguishedName;
- if (typeOf(item)==="string") return this.data.distinguishedName === item;
- return false;
- }.bind(this));
- if (selectedItem.length){
- this.selectedSingle();
- }
- },
- checkSelected: function(){
- var selectedItem = this.selector.selectedItems.filter(function(item, index){
- return item.data.distinguishedName === this.data.distinguishedName;
- }.bind(this));
- if (selectedItem.length){
- //selectedItem[0].item = this;
- selectedItem[0].addItem(this);
- this.selectedItem = selectedItem[0];
- this.setSelected();
- }
- },
- checkTextNodeIndent : function( textNode, styles ){
- var indent = textNode.retrieve("indent");
- if( indent && styles && styles["margin-left"] ){
- var m = styles["margin-left"].toFloat()+indent;
- textNode.setStyle("margin-left", ""+m+"px");
- }
- },
- setSelected: function(){
- this.isSelected = true;
- this.node.setStyles(this.selector.css.selectorItem_selected);
- this.textNode.setStyles(this.selector.css.selectorItemTextNode_selected);
- this.checkTextNodeIndent( this.textNode, this.selector.css.selectorItemTextNode_selected );
- this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected);
- if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single_selected ){
- this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single_selected );
- }
- // if( this.category ){
- // this.category.checkSelectAll();
- // }
- },
- setEvent: function(){
- this.node.addEvents({
- "mouseover": function(){
- this.overItem();
- }.bind(this),
- "mouseout": function(){
- this.outItem();
- }.bind(this),
- "click": function(){
- this.clickItem( null, true );
- }.bind(this)
- });
- },
- clickItem: function( callback, checkValid ){
- if ( layout.mobile && this.selector.options.count.toInt()===1){
- this.selectedSingle( checkValid );
- }else{
- if (this.isSelected){
- this.unSelected( checkValid );
- }else{
- this.selected( checkValid );
- }
- }
- },
- overItem: function(){
- if (!this.isSelected ){
- this.node.setStyles(this.selector.css.selectorItem_over);
- }else if( this.selector.css.selectorItem_over_force ){
- this.node.setStyles(this.selector.css.selectorItem_over_force);
- }
- if (!this.isSelected){
- this.actionNode.setStyles(this.selector.css.selectorItemActionNode_over);
- if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single_over ){
- this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single_over );
- }
- }else if( this.selector.css.selectorItemActionNode_over_force ){
- this.node.setStyles(this.selector.css.selectorItemActionNode_over_force);
- }
- },
- outItem: function(){
- if (!this.isSelected){
- this.node.setStyles(this.selector.css.selectorItem);
- }else if( this.selector.css.selectorItem_over_force ){
- this.node.setStyles(this.selector.css.selectorItem_selected);
- }
- if (!this.isSelected){
- this.actionNode.setStyles(this.selector.css.selectorItemActionNode);
- if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single ){
- this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single );
- }
- }else if( this.selector.css.selectorItemActionNode_over_force ){
- this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected);
- if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single_selected ){
- this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single_selected );
- }
- }
- },
- selectedSingle: function( checkValid ){
- if (!this.isSelected){
- if (this.selector.currentItem) this.selector.currentItem.unSelectedSingle();
- this.selector.emptySelectedItems();
- this.getData(function(){
- this.selector.currentItem = this;
- this.isSelected = true;
- this.selector.selectedItems.push(this);
- this.node.setStyles(this.selector.css.selectorItem_selected);
- this.textNode.setStyles(this.selector.css.selectorItemTextNode_selected);
- this.checkTextNodeIndent( this.textNode, this.selector.css.selectorItemTextNode_selected );
- this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected);
- if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single_selected ){
- this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single_selected );
- }
- this.selector.fireEvent("selectItem",[this]);
- if( checkValid )this.selector.fireEvent("valid", [this.selector, this]);
- }.bind(this));
- }else {
- this.unSelectedSingle( checkValid );
- }
- },
- getData: function(callback){
- if (callback) callback();
- },
- unSelectedSingle: function(checkValid){
- this.selector.currentItem = null;
- this.isSelected = false;
- this.selector.selectedItems.erase(this);
- this.node.setStyles(this.selector.css.selectorItem);
- this.textNode.setStyles(this.selector.css.selectorItemTextNode);
- this.checkTextNodeIndent( this.textNode, this.selector.css.selectorItemTextNode );
- this.actionNode.setStyles(this.selector.css.selectorItemActionNode);
- if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single ){
- this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single );
- }
- this.selector.fireEvent("unselectItem",[this]);
- if( checkValid )this.selector.fireEvent("valid", [this.selector, this]);
- },
- selected: function( checkValid, callback, selectedNode, byelectAll ){
- debugger;
- var count = this.selector.options.maxCount || this.selector.options.count;
- count = count.toInt();
- if (!count) count = 0;
- if( count == 1 && this.selector.emptySelectedItems){
- this.selector.emptySelectedItems();
- }
- if ((count===0) || (this.selector.selectedItems.length+1)<=count) {
- this.isSelected = true;
- if( this.node ){
- this.node.setStyles(this.selector.css.selectorItem_selected);
- this.textNode.setStyles(this.selector.css.selectorItemTextNode_selected);
- this.checkTextNodeIndent( this.textNode, this.selector.css.selectorItemTextNode_selected );
- this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected);
- if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single_selected ){
- this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single_selected );
- }
- }
- this.selectedItem = this.selector._newItemSelected(this.data, this.selector, this, selectedNode);
- // this.selectedItem.check();
- this.selector.selectedItems.push(this.selectedItem);
- // if( this.category ){
- // this.category.checkSelectAll();
- // }
- this.selector.fireEvent("selectItem",[this]);
- if( checkValid )this.selector.fireEvent("valid", [this.selector, this]);
- if(callback)callback();
- }else{
- MWF.xDesktop.notice("error", {x: "right", y:"top"}, "最多可选择"+count+"个选项", this.node);
- }
- },
- unSelected: function( checkValid, callback ){
- this.isSelected = false;
- if( this.node ){
- this.node.setStyles(this.selector.css.selectorItem);
- this.textNode.setStyles(this.selector.css.selectorItemTextNode);
- this.checkTextNodeIndent( this.textNode, this.selector.css.selectorItemTextNode );
- this.actionNode.setStyles(this.selector.css.selectorItemActionNode);
- if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single ){
- this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single );
- }
- }
- if( this.category ){
- this.category.checkUnselectAll();
- }
- if( this.selector.searchItems && this.selector.searchItems.length ){
- this.selector.searchItems.each( function(itemSearch){
- var sd = itemSearch.data;
- var d = this.data;
- if(
- ( sd.distinguishedName && (sd.distinguishedName === d.distinguishedName) ) ||
- ( sd.id && (sd.id === d.id) ) ||
- ( sd.unique && (sd.unique === d.unique) ) ||
- ( sd.employee && (sd.employee === d.employee) ) ||
- ( sd.levelName && (sd.levelName === d.levelName) )
- ){
- itemSearch.isSelected = false;
- itemSearch.node.setStyles(this.selector.css.selectorItem);
- itemSearch.textNode.setStyles(this.selector.css.selectorItemTextNode);
- this.checkTextNodeIndent( itemSearch.textNode, this.selector.css.selectorItemTextNode );
- itemSearch.actionNode.setStyles(this.selector.css.selectorItemActionNode);
- if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single ){
- itemSearch.actionNode.setStyles( this.selector.css.selectorItemActionNode_single );
- }
- }
- }.bind(this))
- }
- if (this.selectedItem){
- this.selector.selectedItems.erase(this.selectedItem);
- this.selectedItem.items.each(function(item){
- if (item != this){
- item.isSelected = false;
- item.node.setStyles(this.selector.css.selectorItem);
- item.textNode.setStyles(this.selector.css.selectorItemTextNode);
- this.checkTextNodeIndent( item.textNode, this.selector.css.selectorItemTextNode );
- item.actionNode.setStyles(this.selector.css.selectorItemActionNode);
- if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single ){
- item.actionNode.setStyles( this.selector.css.selectorItemActionNode_single );
- }
- }
- if( this.selector.selectType == "identity" && ( this.selector.options.showSelectedCount || this.selector.options.isCheckStatus ) ){
- if(item.category && item.category._addSelectedCount )item.category._addSelectedCount( -1, true );
- }
- }.bind(this));
- this.selectedItem.destroy();
- this.selectedItem = null;
- }
- this.selector.fireEvent("unselectItem",[this]);
- if( checkValid )this.selector.fireEvent("valid", [this.selector, this]);
- if(callback)callback();
- },
- postLoad : function(){},
- getParentCategoryByLevel : function( level ){
- var category = this.category;
- do{
- if( category.level === level ){
- return category;
- }else{
- category = category.category;
- }
- }while( category )
- }
- });
- MWF.xApplication.Selector.Person.ItemSelected = new Class({
- Extends: MWF.xApplication.Selector.Person.Item,
- initialize: function(data, selector, item, selectedNode){
- this.data = data;
- this.selector = selector;
- this.container = selectedNode || this.selector.selectedNode;
- this.isSelected = false;
- this.clazz = "ItemSelected";
- this.items = [];
- if (item) this.items.push(item);
- this.level = 0;
- this.node = new Element("div", {
- "styles": this.selector.css.selectorItem
- }).inject(this.container);
- this.node.setStyle("display","none");
- this.getData(function(){
- this.node.setStyle("display","");
- this.load();
- }.bind(this));
- },
- postLoad : function(){
- if( this.selector.css.selectorSelectedItemActionNode ){
- this.actionNode.setStyles( this.selector.css.selectorSelectedItemActionNode );
- if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorSelectedItemActionNode_single ){
- this.actionNode.setStyles( this.selector.css.selectorSelectedItemActionNode_single );
- }
- }
- if( this.selector.css.selectorSelectedItemTextNode ){
- this.textNode.setStyles(this.selector.css.selectorSelectedItemTextNode);
- }
- },
- getData: function(callback){
- if (callback) callback();
- },
- clickItem: function( callback, checkValid ){
- if (this.items.length){
- this.items.each(function(item){
- item.unSelected( checkValid );
- });
- if( checkValid )this.selector.fireEvent("valid", [this.selector, this])
- }else{
- //this.item.selectedItem = null;
- //this.item.isSelected = false;
- this.destroy();
- this.selector.selectedItems.erase(this);
- if( checkValid )this.selector.fireEvent("valid", [this.selector, this])
- }
- },
- //overItem: function(){
- // if (!this.isSelected){
- // this.node.setStyles(this.selector.css.selectorItem_over);
- // this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected_over);
- // }
- //},
- overItem: function(){
- if (!this.isSelected ){
- if( this.selector.css.selectorItem_selected_over ){
- this.node.setStyles(this.selector.css.selectorItem_selected_over);
- }else{
- this.node.setStyles(this.selector.css.selectorItem_over);
- }
- this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected_over);
- if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single_selected_over ){
- this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single_selected_over );
- }
- }
- },
- outItem: function(){
- if (!this.isSelected){
- var styles = this.selector.css.selectorSelectedItem || this.selector.css.selectorItem;
- this.node.setStyles(styles);
- }else if( this.selector.css.selectorItem_over_force ){
- this.node.setStyles(this.selector.css.selectorItem_selected);
- }
- if (!this.isSelected){
- var styles = this.selector.css.selectorSelectedItemActionNode || this.selector.css.selectorItemActionNode;
- this.actionNode.setStyles(styles);
- if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) &&
- ( this.selector.css.selectorSelectedItemActionNode_single || this.selector.css.selectorItemActionNode_single ) ){
- this.actionNode.setStyles( this.selector.css.selectorSelectedItemActionNode_single || this.selector.css.selectorItemActionNode_single );
- }
- }else if( this.selector.css.selectorItemActionNode_over_force ){
- this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected);
- if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single_selected ){
- this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single_selected );
- }
- }
- },
- addItem: function(item){
- if (this.items.indexOf(item)===-1) this.items.push(item);
- },
- check: function(){
- debugger;
- if (this.selector.items.length){
- var items = this.selector.items.filter(function(item, index){
- return item.data.distinguishedName === this.data.distinguishedName;
- }.bind(this));
- this.items = items;
- if (items.length){
- items.each(function(item){
- item.selectedItem = this;
- item.setSelected();
- // if( this.selector.options.showSelectedCount ){
- // if(item.category)item.category._addSelectedCount( 1, true );
- // }
- }.bind(this));
- }
- }
- if( this.afterCheck )this.afterCheck();
- },
- destroy: function(){
- if(this.node){
- // var parent = this.node.getParent(".categorySelectedNode");
- // if( parent && !this.node.getPrevious() && !this.node.getNext() ){ //parent.getChildren().length <= 1
- // parent.destroy();
- // }else{
- this.node.destroy();
- // }
- }
- delete this;
- }
- });
- MWF.xApplication.Selector.Person.ItemCategory = new Class({
- Extends: MWF.xApplication.Selector.Person.Item,
- initialize: function(data, selector, container, level, parentCategory, delay){
- this.data = data;
- this.selector = selector;
- this.container = container;
- this.isSelected = false;
- this.level = (level) ? level.toInt() : 1;
- this.category = parentCategory;
- this.subItems = [];
- this.subCategorys = [];
- if(!delay)this.load();
- },
- load : function(){
- if( this.selector.isFlatCategory ){
- this.loadForFlat();
- }else{
- this.loadForNormal();
- }
- },
- loadForFlat : function(){
- this.selector.fireEvent("queryLoadCategory",[this]);
- //this.createNode();
- this.node = new Element("div.flatCategoryItemNode", {
- "styles": this.selector.css.flatCategoryItemNode,
- "title" : this._getTtiteText()
- });
- this.node.store( "category", this );
- this.node.store( "dn", this.data.distinguishedName );
- this.textNode = new Element("div", {
- "styles": this.selector.css.flatCategoryItemTextNode,
- "text": this._getShowName()
- }).inject(this.node);
- //var level = this.level;
- //var category = this;
- //while( category.category ){
- // level = category.category + "_" + level;
- // category = category.category;
- //}
- this.children = new Element("div", {
- "styles": this.selector.css.selectorItemCategoryChildrenNode
- }).inject(this.selector.itemAreaNode); //this.container
- //if (!this.selector.options.expand)
- this.children.setStyle("display", "none");
- if( this.selector.options.selectAllEnable && this.selector.options.count.toInt()!==1 ){
- var selectAllWrap = new Element("div",{
- styles : this.selector.css.flatCategory_selectAllWrap
- }).inject(this.children);
- this.selectAllNode = new Element("div", {
- "styles": this.selector.css.flatCategory_selectAll,
- "text" : "全选"
- }).inject(selectAllWrap);
- this.selectAllNode.addEvent( "click", function(ev){
- if( this.isSelectedAll ){
- this.selector.options.selectAllRange === "all" ? this.unselectAllNested(ev, null, true ) : this.unselectAll(ev, null, true);
- this.selector.fireEvent("unselectCatgory",[this])
- }else{
- this.selector.options.selectAllRange === "all" ? this.selectAllNested(ev, true) : this.selectAll(ev, true);
- this.selector.fireEvent("selectCatgory",[this])
- }
- ev.stopPropagation();
- }.bind(this));
- }
- // var subIdList = this.selector._getChildrenItemIds(this.data);
- // if (subIdList){
- // var count = subIdList.length;
- // this.childrenHeight = count*this.selector.options.itemHeight;
- // this.children.setStyle("height", ""+this.childrenHeight+"px");
- // }
- //if (!this._hasChild()){
- // this.textNode.setStyle("color", "#333");
- //}
- if( this.selectAllNode ){
- if( this.selector.options.selectAllRange === "direct" && !this._hasChildItem() ){
- this.selectAllNode.setStyle("display", "none");
- }
- }
- this.node.addEvents({
- //"mouseover": function(){
- // if (!this.isSelected )this.node.setStyles(this.selector.css.flatCategoryItemNode_over );
- //}.bind(this),
- //"mouseout": function(){
- // if (!this.isSelected )this.node.setStyles(this.selector.css.flatCategoryItemNode );
- //}.bind(this),
- "click": function(){
- if( this.selector.currentFlatCategory === this )return;
- if( this.selector.currentFlatCategory ){
- this.selector.currentFlatCategory.clickFlatCategoryItem(null, true); //取消原来选择的
- }
- this.selector.currentFlatCategory = this;
- this.clickFlatCategoryItem();
- }.bind(this)
- });
- //this.setEvent();
- var isCreateSubCategoryListNode = this._hasChildCategory ? this._hasChildCategory() : true;
- var nodeContainer;
- if( this.nodeContainer ){
- nodeContainer = this.nodeContainer;
- }else{
- nodeContainer = (this.category && this.category.subCategoryListNode) ? this.category.subCategoryListNode : null;
- }
- this.subCategoryListNode = this.selector.addFlatCategoryItem( this.node, this._hasChildItem(), nodeContainer, isCreateSubCategoryListNode );
- this.check();
- if( this.loadCategoryChildren )this.loadCategoryChildren();
- //this.afterLoad();
- this.selector.fireEvent("postLoadCategory",[this]);
- },
- loadForNormal : function(){
- this.selector.fireEvent("queryLoadCategory",[this]);
- this.createNode();
- this.levelNode = new Element("div", {
- "styles": this.selector.css.selectorItemLevelNode
- }).inject(this.node);
- if(this.selector.selectType !== "identity" || this.selector.options.identityItemWidth === 0 ){
- var indent = this.selector.options.level1Indent + (this.level - 1) * this.selector.options.indent;
- this.levelNode.setStyle("width", "" + indent + "px");
- }else{
- this.node.setStyle("clear","both");
- }
- this.iconNode = new Element("div", {
- "styles": this.selector.css.selectorItemCategoryIconNode || this.selector.css.selectorItemIconNode
- }).inject(this.node);
- this._setIcon();
- this.actionNode = new Element("div", {
- "styles": (this.selector.options.expand) ? this.selector.css.selectorItemCategoryActionNode_expand : this.selector.css.selectorItemCategoryActionNode_collapse
- }).inject(this.node);
- if( this.selector.options.selectAllEnable && this.selector.options.count.toInt()!==1 ){
- this.selectAllNode = new Element("div", {
- "styles": this.selector.css.selectorItemCategoryActionNode_selectAll,
- "title" : "全选下级"
- }).inject(this.node);
- this.selectAllNode.addEvent( "click", function(ev){
- if( this.isSelectedAll ){
- // this.unselectAll(ev);
- this.selector.options.selectAllRange === "all" ? this.unselectAllNested(ev, null, true ) : this.unselectAll(ev, null, true);
- this.selector.fireEvent("unselectCatgory",[this]);
- }else{
- // this.selectAll(ev);
- if( this.selector.options.selectAllRange === "all" ){
- var node = new Element("div.categorySelectedNode").inject( this.selector.selectedNode );
- this.selectAllNested(ev, true, node );
- }else{
- this.selectAll(ev, true)
- }
- this.selector.fireEvent("selectCatgory",[this]);
- }
- ev.stopPropagation();
- }.bind(this));
- if( this.selector.css.selectorItemCategoryActionNode_selectAll_over ){
- this.selectAllNode.addEvents( {
- "mouseover" : function(ev){
- if( !this.isSelectedAll && !this.isSelectedSome )this.selectAllNode.setStyles( this.selector.css.selectorItemCategoryActionNode_selectAll_over );
- //ev.stopPropagation();
- }.bind(this),
- "mouseout" : function(ev){
- if( !this.isSelectedAll && !this.isSelectedSome )this.selectAllNode.setStyles( this.selector.css.selectorItemCategoryActionNode_selectAll );
- //ev.stopPropagation();
- }.bind(this)
- })
- }
- }
- this.textNode = new Element("div", {
- "styles": this.selector.css.selectorItemCategoryTextNode,
- "text": this._getShowName()
- }).inject(this.node);
- var m = this.textNode.getStyle("margin-left").toFloat()+indent;
- this.textNode.setStyle("margin-left", ""+m+"px");
- if( this.selector.options.showSelectedCount && this.selector.selectType == "identity" ){
- this.selectedCountNode = new Element("span").inject(this.textNode);
- }
- this.children = new Element("div.children", {
- "styles": this.selector.css.selectorItemCategoryChildrenNode
- }).inject(this.node, "after");
- if (!this.selector.options.expand) this.children.setStyle("display", "none");
- if( this.selector.options.expandEmptyCategory && !this._hasChildItem() ){ //点击允许展开空分类
- this.children.hide();
- this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_collapse);
- this.isExpand = false;
- }else{
- var subIdList = this.selector._getChildrenItemIds(this.data);
- if (subIdList){
- var count = subIdList.length;
- this.childrenHeight = count*this.selector.options.itemHeight;
- this.children.setStyle("height", ""+this.childrenHeight+"px");
- }
- if(this.selector.options.identityItemWidth && this.selector.selectType === "identity"){
- var indent = this.level === 0 ? this.selector.options.level1Indent : this.selector.options.indent;
- this.children.setStyles({
- "padding-left": "" + indent + "px",
- "overflow" : "hidden"
- });
- }
- if ( !this._hasChild()){
- this.actionNode.setStyle("background", "transparent");
- this.textNode.setStyle("color", "#777");
- }
- if( this.selectAllNode ){
- if( this.selector.options.selectAllRange === "direct" && !this._hasChildItem() ){
- this.selectAllNode.setStyle("display", "none");
- }
- }
- }
- this.setEvent();
- this.check();
- this.afterLoad();
- this.selector.fireEvent("postLoadCategory",[this]);
- },
- createNode: function(){
- this.node = new Element("div", {
- "styles": this.selector.css.selectorItemCategory,
- "title" : this._getTtiteText()
- }).inject(this.container);
- },
- unselectAll : function(ev, exclude, checkValid ){
- var fun = function(){
- var excludeList = exclude || [];
- if( exclude && typeOf(exclude) !== "array" )excludeList = [exclude];
- ( this.subItems || [] ).each( function(item){
- if(item.isSelected && !excludeList.contains(item) ){
- item.unSelected( checkValid );
- }
- }.bind(this));
- if( this.selectAllNode ){
- if( this.selector.isFlatCategory ){
- this.selectAllNode.setStyles( this.selector.css.flatCategory_selectAll );
- }else if(this.selector.css.selectorItemCategoryActionNode_selectAll){
- this.selectAllNode.setStyles( this.selector.css.selectorItemCategoryActionNode_selectAll );
- }
- }
- this.isSelectedAll = false;
- }.bind(this);
- if( this.loaded ){
- fun();
- }else{
- this.clickItem( function(){
- fun();
- }.bind(this))
- }
- },
- unselectAllNested : function( ev, exclude, checkValid ){
- this.unselectAll(ev, exclude, checkValid);
- if( this.subCategorys && this.subCategorys.length ){
- this.subCategorys.each( function( category ){
- category.unselectAllNested( ev, exclude, checkValid )
- })
- }
- },
- selectAllNested : function( ev, checkValid, selectedNode ){
- var node;
- if(selectedNode)node = new Element("div.categorySelectedNode").inject( selectedNode );
- this.selectAll(ev, checkValid, node, function () {
- if( this.subCategorys && this.subCategorys.length ){
- this.subCategorys.each( function( category ){
- if(selectedNode)var node = new Element("div.categorySelectedNode").inject( selectedNode );
- category.selectAllNested(ev, checkValid, node)
- })
- }
- }.bind(this));
- },
- selectAll: function(ev, checkValid, selectedNode, callback){
- if( this.loaded || this.selector.isFlatCategory ){
- this._selectAll( ev, checkValid, selectedNode );
- if(callback)callback();
- }else{
- this.clickItem( function(){
- this._selectAll( ev, checkValid, selectedNode );
- if(callback)callback();
- //this.children.setStyles({
- // "display": "none",
- // "height": "0px"
- //});
- //this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_collapse);
- }.bind(this));
- }
- },
- _selectAll : function( ev, checkValid, selectedNode ){
- if( this.selector.options.selectAllRange === "direct" && ( !this.subItems || !this.subItems.length ) )return;
- var count = this.selector.options.maxCount || this.selector.options.count;
- if (!count) count = 0;
- var selectedSubItemCount = 0;
- this.subItems.each( function(item){
- if(item.isSelected)selectedSubItemCount++
- }.bind(this));
- if ((count.toInt()===0) || (this.selector.selectedItems.length+(this.subItems.length-selectedSubItemCount))<=count){
- var checkedCount = 0;
- var doSelectAll = function () {
- this.subItems.each( function(item){
- if(!item.isSelected && !item.disabled )item.selected( false, function () {
- checkedCount++;
- if( this.subItems.length === checkedCount ){
- if( checkValid )this.selector.fireEvent("valid", [this.selector, this]);
- }
- }.bind(this), selectedNode);
- }.bind(this));
- if( this.selectAllNode ){
- if( this.selector.isFlatCategory ){
- this.selectAllNode.setStyles( this.selector.css.flatCategory_selectAll_selected );
- }else if(this.selector.css.selectorItemCategoryActionNode_selectAll_selected){
- var styles = this.selector.css.selectorItemCategoryActionNode_selectAll_selected;
- if( this.selector.options.isCheckStatus && this.selector.selectType === "identity" ){
- if( this._getSelectedCount() < this._getTotalCount() ){
- styles = this.selector.css.selectorItemCategoryActionNode_selectsome_selected;
- }
- }
- this.selectAllNode.setStyles( styles );
- }
- }
- this.isSelectedAll = true;
- }.bind(this);
- if( this._beforeSelectAll ){
- this._beforeSelectAll( doSelectAll );
- }else{
- doSelectAll();
- }
- }else{
- MWF.xDesktop.notice("error", {x: "right", y:"top"}, "最多可选择"+count+"个选项", this.node);
- }
- },
- checkSelectAll : function(){
- if( this.isSelectedAll )return;
- if( !this.selectAllNode )return;
- if( !this.subItems )return;
- var isAllItemSelected = true;
- for( var i=0; i< this.subItems.length; i++ ){
- if( !this.subItems[i].isSelected ){
- isAllItemSelected = false;
- break;
- }
- }
- if( isAllItemSelected ){
- if( this.selector.isFlatCategory ){
- this.selectAllNode.setStyles( this.selector.css.flatCategory_selectAll_selected );
- }else if( this.selector.css.selectorItemCategoryActionNode_selectAll_selected ){
- this.selectAllNode.setStyles( this.selector.css.selectorItemCategoryActionNode_selectAll_selected );
- }
- this.isSelectedAll = true;
- }
- },
- checkUnselectAll : function(){
- if( !this.isSelectedAll )return;
- if( !this.selectAllNode )return;
- if( !this.subItems )return;
- var hasSelectedItem = false;
- for( var i=0; i< this.subItems.length; i++ ){
- if( this.subItems[i].isSelected ){
- hasSelectedItem = true;
- break;
- }
- }
- if( !hasSelectedItem ){
- if( this.selector.isFlatCategory ){
- this.selectAllNode.setStyles( this.selector.css.flatCategory_selectAll );
- }else if( this.selector.css.selectorItemCategoryActionNode_selectAll ){
- this.selectAllNode.setStyles( this.selector.css.selectorItemCategoryActionNode_selectAll );
- }
- this.isSelectedAll = false;
- }
- },
- afterLoad: function(){
- if (this.level===1) this.clickItem();
- },
- clickFlatCategoryItem : function( callback, hidden ){
- if (this._hasChildItem()){
- var display = this.children.getStyle("display");
- if( hidden ){
- this.children.setStyles({ "display": "none" });
- this.node.setStyles( this.selector.css.flatCategoryItemNode );
- this.isExpand = false;
- }else if (display === "none"){
- this.children.setStyles({
- "display": "block",
- "height": "auto"
- });
- this.node.setStyles( this.selector.css.flatCategoryItemNode_selected );
- this.isExpand = true;
- }else{
- this.children.setStyles({
- "display": "none"
- });
- this.node.setStyles( this.selector.css.flatCategoryItemNode );
- this.isExpand = false;
- }
- if(callback)callback()
- }
- },
- clickItem: function( callback ){
- if (this._hasChild() || this.selector.options.expandEmptyCategory ){
- if (!this.fx){
- this.fx = new Fx.Tween(this.children, {
- "duration": 200
- // "transition": Fx.Transitions.Cubic.easeIn
- });
- }
- if (!this.fx.isRunning()){
- var display = this.children.getStyle("display");
- if (display === "none"){
- this.selector.fireEvent("expand", [this] );
- this.children.setStyles({
- "display": "block",
- "height": "0px"
- });
- this.fx.start("height", "0px", ""+this.childrenHeight+"px");
- this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_expand);
- this.isExpand = true;
- }else{
- this.selector.fireEvent("collapse", [this] );
- if (!this.childrenHeight) this.childrenHeight = this.children.getStyle("height").toFloat();
- this.fx.start("height", ""+this.childrenHeight+"px", "0px").chain(function(){
- this.children.setStyles({
- "display": "none",
- "height": "0px"
- });
- }.bind(this));
- this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_collapse);
- this.isExpand = false;
- }
- }
- if(callback)callback()
- }
- },
- overItem: function(){
- //if (!this.isSelected){
- // this.node.setStyles(this.selector.css.selectorItem_over);
- // this.actionNode.setStyles(this.selector.css.selectorItemActionNode_over);
- //}
- if( this.selector.css.selectorItemCategory_over ){
- this.node.setStyles(this.selector.css.selectorItemCategory_over);
- }
- var display = this.children.getStyle("display");
- if( display === "none" ){
- if( this._hasChild() && this.selector.css.selectorItemCategoryActionNode_collapse_over ){
- this.actionNode.setStyles( this.selector.css.selectorItemCategoryActionNode_collapse_over )
- }
- }else{
- if( this._hasChild() && this.selector.css.selectorItemCategoryActionNode_expand_over ){
- this.actionNode.setStyles( this.selector.css.selectorItemCategoryActionNode_expand_over )
- }
- }
- },
- outItem: function(){
- //if (!this.isSelected){
- // this.node.setStyles(this.selector.css.selectorItem);
- // this.actionNode.setStyles(this.selector.css.selectorItemActionNode);
- //}
- if( this.selector.css.selectorItemCategory_over ){
- this.node.setStyles(this.selector.css.selectorItemCategory);
- }
- var display = this.children.getStyle("display");
- if( display === "none" ){
- if( this._hasChild() && this.selector.css.selectorItemCategoryActionNode_collapse_over ){
- this.actionNode.setStyles( this.selector.css.selectorItemCategoryActionNode_collapse )
- }
- }else{
- if( this._hasChild() && this.selector.css.selectorItemCategoryActionNode_expand_over ){
- this.actionNode.setStyles( this.selector.css.selectorItemCategoryActionNode_expand )
- }
- }
- },
- _hasChild: function(){
- var subIdList = this.selector._getChildrenItemIds(this.data);
- if (subIdList) if (subIdList.length) return true;
- return false;
- },
- _hasChildCategory: function(){
- return null;
- },
- _hasChildItem: function(){
- return this._hasChild();
- },
- _getTtiteText: function(){
- if( this.data.levelName ){
- return this.data.name+"("+ this.data.levelName +")";
- }else{
- return this.data.name;
- }
- }
- });
- MWF.xApplication.Selector.Person.ItemGroupCategory = new Class({
- Extends: MWF.xApplication.Selector.Person.ItemCategory,
- _getShowName: function(){
- return this.data.name;
- },
- _setIcon: function(){
- var style = this.selector.options.style;
- this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/groupicon.png)");
- }
- });
- MWF.xApplication.Selector.Person.ItemRoleCategory = new Class({
- Extends: MWF.xApplication.Selector.Person.ItemCategory,
- _getShowName: function(){
- return this.data.name;
- },
- _setIcon: function(){
- var style = this.selector.options.style;
- this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/roleicon.png)");
- }
- });
- MWF.xApplication.Selector.Person.Filter = new Class({
- Implements: [Options, Events],
- options: {
- "style": "default",
- "groups": [],
- "roles": []
- },
- initialize: function(value, options){
- this.setOptions(options);
- this.value = value;
- this.orgAction = MWF.Actions.get("x_organization_assemble_control");
- },
- filter: function(value, callback){
- this.value = value;
- var key = this.value;
- if (this.options.groups.length || this.options.roles.length) key = {"key": key, "groupList": this.options.groupList, "roleList": this.options.roleList};
- this.orgAction.listPersonByKey(function(json){
- data = json.data;
- if (callback) callback(data)
- }.bind(this), null, key);
- }
- });
|