| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933 |
- MWF.xApplication.Selector = MWF.xApplication.Selector || {};
- 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": "Select Person",
- "groups": [],
- "roles": [],
- "values": [],
- "names": [],
- "zIndex": 100,
- "expand": true
- },
- 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();
-
- this.container = $(container);
- this.action = new MWF.xApplication.Selector.Actions.RestActions();
-
- this.lastPeople = "";
- this.pageCount = "13";
- this.selectedItems = [];
- this.items = [];
- },
- load: function(){
- this.container.mask({
- "destroyOnHide": true,
- "style": this.css.maskNode
- });
- this.container.setStyle("z-index", this.options.zIndex);
- this.node = new Element("div", {
- "styles": (this.options.count.toInt()==1) ? this.css.containerNodeSingle : this.css.containerNode
- });
- this.node.setStyle("z-index", this.options.zIndex.toInt()+1);
- this.titleNode = new Element("div", {
- "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]
- }
- });
-
- this.setEvent();
- },
- setEvent: function(){
- this.titleActionNode.addEvent("click", function(){
- this.close();
- }.bind(this));
-
- },
- close: function(){
- this.node.destroy();
- this.container.unmask();
- delete this;
- },
- loadAction: function(){
- this.okActionNode = new Element("button", {
- "styles": this.css.okActionNode,
- "text": "确 定"
- }).inject(this.actionNode);
- this.cancelActionNode = new Element("button", {
- "styles": this.css.cancelActionNode,
- "text": "取 消"
- }).inject(this.actionNode);
- this.okActionNode.addEvent("click", function(){
- this.fireEvent("complete", [this.selectedItems]);
- this.close();
- }.bind(this));
- this.cancelActionNode.addEvent("click", function(){this.close();}.bind(this));
- },
- loadContent: function(){
- if (this.options.count.toInt()!=1) this.loadSelectedNode();
- this.loadSelectNode();
- },
- loadSelectNode: function(){
- this.selectNode = new Element("div", {
- "styles": (this.options.count.toInt()==1) ? this.css.selectNodeSingle : this.css.selectNode
- }).inject(this.contentNode);
- 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);
- this.initSearchInput();
-
- 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");
- 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();
- if (!this.options.groups.length && !this.options.roles.length){
- this.loadSelectItems();
- }else{
- this.loadSelectItemsByCondition();
- }
- },
- 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){
- 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){
- 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 (flag) 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){
- this.createItemsSearchData(function(){
- var word = key.toLowerCase();
- var createdId = [];
- this.itemsSearchData.each(function(obj){
- var text = obj.text+"#"+obj.pinyin+"#"+obj.firstPY;
- if (text.indexOf(word)!=-1){
- if (createdId.indexOf(obj.data.name)==-1){
- this._newItem(obj.data, this, this.itemSearchAreaNode);
- createdId.push(obj.data.name);
- }
- }
- }.bind(this));
- //this.searchItemsData(this.itemsSearchData.name, word, createdId);
- //this.searchItemsData(this.itemsSearchData.pinyin, word, createdId);
- //this.searchItemsData(this.itemsSearchData.firstPY, word, createdId);
- delete createdId;
- }.bind(this));
- },
- 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.name)==-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.name);
- }
- }.bind(this));
- delete initIds;
- if (callback) callback();
- }.bind(this));
- }else{
- if (callback) callback();
- }
- },
- //searchItemsData: function(str, key, createdId){
- // var name = str;
- // var idx = name.indexOf(key);
- // var position = 0;
- // while (idx !=-1){
- // var left = name.substr(0, idx);
- // var i = left.split("#").length-1;
- //
- // var index = i+position;
- // position = i+1;
- // var data = this.itemsSearchData.data[index];
- // if (createdId.indexOf(data.id)==-1){
- // this._newItem(data, this, this.itemSearchAreaNode);
- // createdId.push(data.id);
- // }
- //
- //
- // name = name.substr(idx+key.length, name.length);
- // var si = name.indexOf("#");
- // if (si!=-1){
- // name = name.substr(si+1, name.length);
- // idx = name.indexOf(key);
- // }else{
- // idx = -1;
- // }
- // }
- //},
- //createItemsSearchData: function(callback){
- // if (!this.itemsSearchData){
- // this.itemsSearchData = {};
- // MWF.require("MWF.widget.PinYin", function(){
- // this.itemsSearchData.name = "";
- // this.itemsSearchData.pinyin = "";
- // this.itemsSearchData.firstPY = "";
- // this.itemsSearchData.data = [];
- //
- // var initIds = [];
- // this.items.each(function(item){
- // if (initIds.indexOf(item.data.id)==-1){
- // var text = item._getShowName();
- // var pinyin = text.toPY().toLowerCase();
- // var firstPY = text.toPYFirst().toLowerCase();
- // this.itemsSearchData.name = (this.itemsSearchData.name) ? this.itemsSearchData.name+"#"+text : text;
- // this.itemsSearchData.pinyin = (this.itemsSearchData.pinyin) ? this.itemsSearchData.pinyin+"#"+pinyin : pinyin;
- // this.itemsSearchData.firstPY = (this.itemsSearchData.firstPY) ? this.itemsSearchData.firstPY+"#"+firstPY : firstPY;
- // this.itemsSearchData.data.push(item.data);
- // initIds.push(item.data.id);
- // }
- // }.bind(this));
- // delete initIds;
- // if (callback) callback();
- // }.bind(this));
- // }else{
- // if (callback) callback();
- // }
- //},
-
- loadSelectedNode: 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));
- },
- setSelectedItem: function(){
- if (this.options.values.length){
- this.options.values.each(function(v){
- this._getItem(function(json){
- this.selectedItems.push(this._newItemSelected(json.data, this, null));
- }.bind(this), null, v, false);
- }.bind(this));
- }else if (this.options.names.length){
- this.options.names.each(function(v){
- this._listItemByKey(function(json){
- var data = "";
- if (json.data.length) data = json.data[0];
- if (data){
- this.selectedItems.push(this._newItemSelected(data, this, null));
- }
-
- }.bind(this), null, v);
- }.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"];
- letters.each(function(l){
- var letterNode = new Element("div", {
- "styles": this.css.letterNode,
- "text": l
- }).inject(this.letterAreaNode);
- 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 (flag) 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++;
- }
- }
- },
- getLastLoadedItemId: function(){
- return (this.items.length) ? this.items[this.items.length-1].data.name : "(0)";
- },
- loadSelectItemsByCondition: function(){
- this.options.groups.each(function(group){
- this.action.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.action.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));
- },
- _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.action.listPersonByKey(function(json){
- if (callback) callback.apply(this, [json]);
- }.bind(this), failure, key);
- },
- _getItem: function(callback, failure, id, async){
- this.action.getPerson(function(json){
- if (callback) callback.apply(this, [json]);
- }.bind(this), failure, id, async);
- },
- _newItemSelected: function(data, selector, item){
- return new MWF.xApplication.Selector.Person.ItemSelected(data, selector, item)
- },
- _listItemByPinyin: function(callback, failure, key){
- this.action.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);
- },
- _listItemNext: function(last, count, callback){
- this.action.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();
- }
- }
- }
- });
- MWF.xApplication.Selector.Person.Item = new Class({
- initialize: function(data, selector, container, level){
- this.data = data;
- this.selector = selector;
- this.container = container;
- this.isSelected = false;
- this.level = (level) ? level.toInt() : 1;
- this.load();
- },
- _getShowName: function(){
- return this.data.display+"("+this.data.employee+")";
- },
- _setIcon: function(){
- this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/default/icon/personicon.png)");
- },
- load: function(){
- 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.level*10;
- 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()
- }).inject(this.node);
- var m = this.textNode.getStyle("margin-left").toFloat()+indent;
- this.textNode.setStyle("margin-left", ""+m+"px");
- this.loadSubItem();
- this.setEvent();
-
- this.check();
- },
- 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){
- return this.data.name == item;
- }.bind(this));
- if (selectedItem.length){
- this.selectedSingle();
- }
- },
- checkSelected: function(){
- var selectedItem = this.selector.selectedItems.filter(function(item, index){
- return item.data.name == this.data.name;
- }.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 (this.selector.options.count.toInt()==1){
- this.selectedSingle();
- }else{
- if (this.isSelected){
- this.unSelected();
- }else{
- this.selected();
- }
- }
- },
- overItem: function(){
- if (!this.isSelected){
- this.node.setStyles(this.selector.css.selectorItem_over);
- this.actionNode.setStyles(this.selector.css.selectorItemActionNode_over);
- }
- },
- outItem: function(){
- if (!this.isSelected){
- this.node.setStyles(this.selector.css.selectorItem);
- this.actionNode.setStyles(this.selector.css.selectorItemActionNode);
- }
- },
- selectedSingle: function(){
- if (!this.isSelected){
- if (this.selector.currentItem) this.selector.currentItem.unSelectedSingle();
- 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);
- }else {
- this.unSelectedSingle();
- }
- },
- 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(){
- debugger;
- if ((this.selector.options.count==0) || (this.selector.selectedItems.length+1)<=this.selector.options.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"}, "最多可选择"+this.selector.options.count+"个选项", this.selector.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.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;
- }
- }
-
- });
- 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.load();
- },
- 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);
- }
- },
- 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.name == this.data.name;
- }.bind(this));
- this.items = items
- if (items.length){
- items.each(function(item){
- item.selectedItem = this;
- item.setSelected();
- }.bind(this));
- }
- }
- },
- destroy: function(){
- this.node.destroy();
- delete this;
- }
- });
- MWF.xApplication.Selector.Person.ItemCategory = new Class({
- Extends: MWF.xApplication.Selector.Person.Item,
- initialize: function(data, selector, container, level){
- this.data = data;
- this.selector = selector;
- this.container = container;
- this.isSelected = false;
- this.level = (level) ? level.toInt() : 1;
- this.load();
- },
- createNode: function(){
- this.node = new Element("div", {
- "styles": this.selector.css.selectorItemCategory
- }).inject(this.container);
- },
- load: function(){
- this.createNode();
- this.levelNode = new Element("div", {
- "styles": this.selector.css.selectorItemLevelNode
- }).inject(this.node);
- var indent = this.level*10;
- 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);
- 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");
- }
- this.setEvent();
- this.check();
- },
- clickItem: function(){
- 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);
- }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);
- }
- }
- }
- },
- overItem: function(){
- //if (!this.isSelected){
- // this.node.setStyles(this.selector.css.selectorItem_over);
- // this.actionNode.setStyles(this.selector.css.selectorItemActionNode_over);
- //}
- },
- outItem: function(){
- //if (!this.isSelected){
- // this.node.setStyles(this.selector.css.selectorItem);
- // this.actionNode.setStyles(this.selector.css.selectorItemActionNode);
- //}
- },
- _hasChild: function(){
- var subIdList = this.selector._getChildrenItemIds(this.data);
- if (subIdList) if (subIdList.length) return true;
- return false;
- }
- });
- 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)");
- }
- });
|