| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885 |
- 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,
- "level1Indent" : 10,
- "indent" : 10,
- "hasLetter" : true, //字母
- "hasTop" : false, //可选、已选的标题
- "hasShuttle" : false, //穿梭按钮
- "searchbarInTopNode" : true, //搜索框在标题上还是另起一行
- "hasSelectedSearchbar" : false
- },
- initialize: function(container, options){
- 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);
- 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 = []; //直接的选择项
- },
- load: function(){
- this.fireEvent("queryLoad",[this]);
- 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.css.containerNode, //(this.options.count.toInt()===1) ? this.css.containerNodeSingle : this.css.containerNode,
- "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();
- }
- },
- 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]);
- 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;
- }
- MWF.release(this);
- delete this;
- },
- loadAction: function(){
- this.okActionNode = new Element("button", {
- "styles": this.css.okActionNode,
- "text": MWF.SelectorLP.ok
- }).inject(this.actionNode);
- 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]);
- this.close();
- }.bind(this));
- this.cancelActionNode.addEvent("click", function(){this.fireEvent("cancel"); this.close();}.bind(this));
- },
- loadContent: function( contentNode ){
- if( contentNode )this.contentNode = contentNode;
- if (layout.mobile){
- if (this.options.count.toInt()!==1) this.loadSelectedNodeMobile();
- this.loadSelectNodeMobile();
- }else{
- this.loadSelectNode();
- if( this.options.hasShuttle ){
- this.loadShuttleNode();
- }
- //if (this.options.count.toInt()!==1) this.loadSelectedNode();
- this.loadSelectedNode();
- }
- },
- loadSelectNodeMobile: function(){
- this.selectNode = new Element("div", {
- "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", {
- "styles": this.css.searchInputDiv
- }).inject(this.selectNode);
- this.searchInput = new Element("input", {
- "styles": (this.options.count.toInt()===1) ? 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();
- 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", {
- "styles": this.css.itemAreaNode
- }).inject(this.itemAreaScrollNode);
- this.itemSearchAreaNode = new Element("div", {
- "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();
- },
- checkLoadSelectItems: function(){
- if (!this.options.groups.length && !this.options.roles.length){
- this.loadSelectItems();
- }else{
- this.loadSelectItemsByCondition();
- }
- },
- loadShuttleNode : function(){
- 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");
- this.itemSearchAreaNode.setStyle("display", "block");
- }else{
- this.itemAreaNode.setStyle("display", "block");
- this.itemSearchAreaNode.setStyle("display", "none");
- }
- },
- search: function(){
- if (!this.options.groups.length && !this.options.roles.length){
- 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;
- if (text.indexOf(word)!==-1){
- if (createdId.indexOf(obj.data.distinguishedName)===-1){
- this._newItem(obj.data, this, this.itemSearchAreaNode);
- createdId.push(obj.data.distinguishedName);
- }
- }
- }.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){
- if (initIds.indexOf(item.data.distinguishedName)==-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(item.data.distinguishedName);
- }
- }.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(){
- this.selectedContainerNode = new Element("div", {
- "styles": this.css.selectedContainerNode
- }).inject(this.contentNode);
- //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", {
- "styles": this.css.itemAreaNode
- }).inject(this.selectedScrollNode);
- this.selectedItemSearchAreaNode.setStyle("display", "none");
- }
- this.setSelectedItem();
- this.loadSelectedNodeScroll();
- },
- 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", {
- "styles": this.css.selectedScrollNode
- }).inject(this.contentNode);
- this.selectedNode = new Element("div", {
- "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"];
- if (layout.mobile){
- var size = this.container.getSize();
- var w = (layout.mobile) ? (size.x-18)/13 : (size.x-20-4-18)/13;
- //letterNode.setStyle("width", ""+w+"px");
- this.css.letterNode.width = ""+w+"px";
- this.css.letterNode_over.width = ""+w+"px";
- }
- letters.each(function(l){
- var letterNode = new Element("div", {
- "styles": this.css.letterNode,
- "text": l
- }).inject(this.letterAreaNode);
- if (layout.mobile){
- letterNode.addEvents({
- "click": function(){
- _self.listPersonByPinyin(this);
- }
- });
- }else{
- letterNode.addEvents({
- "mouseover": function(e){
- e.target.setStyles(this.css.letterNode_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(this.css.letterNode);
- }.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;
- }
- }.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){
- return new MWF.xApplication.Selector.Person.ItemSelected(data, selector, item)
- },
- _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();
- }
- }
- },
- setSize : function(){
- 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 = Math.floor(width / 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 );
- 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])
- }
- });
- MWF.xApplication.Selector.Person.Item = new Class({
- initialize: function(data, selector, container, level, category){
- 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 = [];
- 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(){
- this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/default/icon/personicon.png)");
- },
- load: function(){
- 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);
- 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);
- this.textNode = new Element("div", {
- "styles": this.selector.css.selectorItemTextNode,
- "text": this._getShowName(),
- "title": this._getTtiteText()
- }).inject(this.node);
- var m = this.textNode.getStyle("margin-left").toFloat()+indent;
- this.textNode.setStyle("margin-left", ""+m+"px");
- if(this.postLoad)this.postLoad();
- this.loadSubItem();
- this.setEvent();
- this.check();
- this.selector.fireEvent("postLoadItem",[this]);
- },
- loadSubItem: function(){},
- 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();
- }
- },
- setSelected: function(){
- this.isSelected = true;
- this.node.setStyles(this.selector.css.selectorItem_selected);
- this.textNode.setStyles(this.selector.css.selectorItemTextNode_selected);
- this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected);
- },
- setEvent: function(){
- this.node.addEvents({
- "mouseover": function(){
- this.overItem();
- }.bind(this),
- "mouseout": function(){
- this.outItem();
- }.bind(this),
- "click": function(){
- this.clickItem();
- }.bind(this)
- });
- },
- clickItem: function(){
- if ( layout.mobile && this.selector.options.count.toInt()===1){
- this.selectedSingle();
- }else{
- if (this.isSelected){
- this.unSelected();
- this.selector.fireEvent("unselectItem",[this])
- }else{
- this.selected();
- this.selector.fireEvent("selectItem",[this])
- }
- }
- },
- 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);
- }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);
- }else if( this.selector.css.selectorItemActionNode_over_force ){
- this.node.setStyles(this.selector.css.selectorItemActionNode_selected);
- }
- },
- selectedSingle: function(){
- if (!this.isSelected){
- if (this.selector.currentItem) this.selector.currentItem.unSelectedSingle();
- 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.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected);
- }.bind(this));
- }else {
- this.unSelectedSingle();
- }
- },
- getData: function(callback){
- if (callback) callback();
- },
- unSelectedSingle: function(){
- 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.actionNode.setStyles(this.selector.css.selectorItemActionNode);
- },
- selected: function(){
- var count = this.selector.options.maxCount || this.selector.options.count;
- if (!count) count = 0;
- if( count == 1 && this.selector.emptySelectedItems){
- this.selector.emptySelectedItems();
- }
- if ((count.toInt()===0) || (this.selector.selectedItems.length+1)<=count) {
- this.isSelected = true;
- this.node.setStyles(this.selector.css.selectorItem_selected);
- this.textNode.setStyles(this.selector.css.selectorItemTextNode_selected);
- this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected);
- this.selectedItem = this.selector._newItemSelected(this.data, this.selector, this);
- this.selectedItem.check();
- this.selector.selectedItems.push(this.selectedItem);
- }else{
- MWF.xDesktop.notice("error", {x: "right", y:"top"}, "最多可选择"+count+"个选项", this.node);
- }
- },
- unSelected: function(){
- this.isSelected = false;
- this.node.setStyles(this.selector.css.selectorItem);
- this.textNode.setStyles(this.selector.css.selectorItemTextNode);
- this.actionNode.setStyles(this.selector.css.selectorItemActionNode);
- if( this.category ){
- this.category.checkSelectAll();
- }
- 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);
- itemSearch.actionNode.setStyles(this.selector.css.selectorItemActionNode);
- }
- }.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);
- item.actionNode.setStyles(this.selector.css.selectorItemActionNode);
- }
- }.bind(this));
- this.selectedItem.destroy();
- this.selectedItem = null;
- }
- },
- 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){
- this.data = data;
- this.selector = selector;
- this.container = this.selector.selectedNode;
- this.isSelected = false;
- 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.css.selectorSelectedItemTextNode ){
- this.textNode.setStyles(this.selector.css.selectorSelectedItemTextNode);
- }
- },
- getData: function(callback){
- if (callback) callback();
- },
- clickItem: function(){
- if (this.items.length){
- this.items.each(function(item){
- item.unSelected();
- });
- }else{
- //this.item.selectedItem = null;
- //this.item.isSelected = false;
- this.destroy();
- this.selector.selectedItems.erase(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);
- }
- },
- 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);
- }else if( this.selector.css.selectorItemActionNode_over_force ){
- this.node.setStyles(this.selector.css.selectorItemActionNode_selected);
- }
- },
- addItem: function(item){
- if (this.items.indexOf(item)===-1) this.items.push(item);
- },
- check: function(){
- 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();
- }.bind(this));
- }
- }
- },
- destroy: function(){
- if(this.node)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){
- 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 = [];
- this.load();
- },
- createNode: function(){
- this.node = new Element("div", {
- "styles": this.selector.css.selectorItemCategory,
- "title" : this._getTtiteText()
- }).inject(this.container);
- },
- load: function(){
- this.selector.fireEvent("queryLoadCategory",[this]);
- this.createNode();
- this.levelNode = new Element("div", {
- "styles": this.selector.css.selectorItemLevelNode
- }).inject(this.node);
- 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.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.fireEvent("unselectCatgory",[this])
- }else{
- this.selectAll(ev);
- 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.selectAllNode.setStyles( this.selector.css.selectorItemCategoryActionNode_selectAll_over );
- //ev.stopPropagation();
- }.bind(this),
- "mouseout" : function(ev){
- if( !this.isSelectedAll )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");
- this.children = new Element("div", {
- "styles": this.selector.css.selectorItemCategoryChildrenNode
- }).inject(this.node, "after");
- if (!this.selector.options.expand) this.children.setStyle("display", "none");
- var subIdList = this.selector._getChildrenItemIds(this.data);
- if (subIdList){
- var count = subIdList.length;
- this.childrenHeight = count*29;
- this.children.setStyle("height", ""+this.childrenHeight+"px");
- }
- if (!this._hasChild()){
- this.actionNode.setStyle("background", "transparent");
- this.textNode.setStyle("color", "#777");
- }
- if( this.selectAllNode && !this._hasChildItem() ){
- this.selectAllNode.setStyle("display", "none");
- }
- this.setEvent();
- this.check();
- this.afterLoad();
- this.selector.fireEvent("postLoadCategory",[this]);
- },
- unselectAll : function(ev, exclude){
- var excludeList = exclude || [];
- if( exclude && typeOf(exclude) !== "array" )excludeList = [exclude];
- ( this.subItems || [] ).each( function(item){
- if(item.isSelected && !excludeList.contains(item) ){
- item.unSelected();
- }
- }.bind(this));
- if( this.selectAllNode && this.selector.css.selectorItemCategoryActionNode_selectAll ){
- this.selectAllNode.setStyles( this.selector.css.selectorItemCategoryActionNode_selectAll );
- }
- this.isSelectedAll = false;
- },
- unselectAllNested : function( ev, exclude ){
- this.unselectAll(ev, exclude );
- if( this.subCategorys && this.subCategorys.length ){
- this.subCategorys.each( function( category ){
- category.unselectAllNested( ev, exclude )
- })
- }
- },
- selectAllNested : function(){
- this.selectAll();
- if( this.subCategorys && this.subCategorys.length ){
- this.subCategorys.each( function( category ){
- category.selectAllNested()
- })
- }
- },
- selectAll: function(ev){
- if( this.loaded ){
- this._selectAll( ev );
- }else{
- this.clickItem( function(){
- this._selectAll( ev );
- //this.children.setStyles({
- // "display": "none",
- // "height": "0px"
- //});
- //this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_collapse);
- }.bind(this));
- }
- },
- _selectAll : function( ev ){
- if( !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){
- this.subItems.each( function(item){
- if(!item.isSelected)item.selected();
- }.bind(this))
- if( this.selectAllNode && this.selector.css.selectorItemCategoryActionNode_selectAll_selected ){
- this.selectAllNode.setStyles( this.selector.css.selectorItemCategoryActionNode_selectAll_selected );
- }
- this.isSelectedAll = true;
- }else{
- MWF.xDesktop.notice("error", {x: "right", y:"top"}, "最多可选择"+count+"个选项", this.node);
- }
- },
- checkSelectAll : function(){
- if( !this.isSelectedAll )return;
- if( !this.selectAllNode || !this.selector.css.selectorItemCategoryActionNode_selectAll)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 ){
- this.selectAllNode.setStyles( this.selector.css.selectorItemCategoryActionNode_selectAll );
- this.isSelectedAll = false;
- }
- },
- afterLoad: function(){
- if (this.level===1) this.clickItem();
- },
- clickItem: function( callback ){
- if (this._hasChild()){
- 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.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{
- 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;
- },
- _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(){
- this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/default/icon/groupicon.png)");
- }
- });
- MWF.xApplication.Selector.Person.ItemRoleCategory = new Class({
- Extends: MWF.xApplication.Selector.Person.ItemCategory,
- _getShowName: function(){
- return this.data.name;
- },
- _setIcon: function(){
- this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/default/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);
- }
- });
|