Unit.js 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861
  1. MWF.xApplication.Selector = MWF.xApplication.Selector || {};
  2. MWF.xDesktop.requireApp("Selector", "Identity", null, false);
  3. MWF.xApplication.Selector.Unit = new Class({
  4. Extends: MWF.xApplication.Selector.Identity,
  5. options: {
  6. "style": "default",
  7. "count": 0,
  8. "title": MWF.xApplication.Selector.LP.selectUnit,
  9. "units": [],
  10. //"unitTypes": [],
  11. "values": [],
  12. "zIndex": 1000,
  13. "expand": true,
  14. "exclude" : [],
  15. "expandSubEnable" : true, //是否允许展开下一层
  16. "selectAllEnable" : true //分类是否允许全选下一层
  17. },
  18. loadSelectItems: function(addToNext){
  19. var afterLoadSelectItemFun = this.afterLoadSelectItem.bind(this);
  20. if (this.options.units.length){
  21. var unitLoaded = 0;
  22. var loadUnitSuccess = function () {
  23. unitLoaded++;
  24. if( unitLoaded === this.options.units.length ){
  25. afterLoadSelectItemFun();
  26. }
  27. }.bind(this);
  28. var loadUnitFailure = loadUnitSuccess;
  29. this.options.units.each(function(unit){
  30. var container = new Element("div").inject( this.itemAreaNode );
  31. // this.action.listUnitByKey(function(json){
  32. // if (json.data.length){
  33. // json.data.each(function(data){
  34. // if (data.subDirectUnitCount) var category = this._newItemCategory("ItemCategory", data, this, this.itemAreaNode);
  35. // }.bind(this));
  36. // }
  37. // }.bind(this), null, comp);
  38. if (typeOf(unit)==="string"){
  39. // this.orgAction.listUnitByKey(function(json){
  40. // if (json.data.length){
  41. // json.data.each(function(data){
  42. // if (data.subDirectUnitCount) var category = this._newItemCategory("ItemCategory", data, this, this.itemAreaNode);
  43. // }.bind(this));
  44. // }
  45. // }.bind(this), null, unit);
  46. this.orgAction.getUnit(function(json){
  47. json.data = typeOf( json.data ) == "object" ? [json.data] : json.data;
  48. if (json.data.length){
  49. json.data.each( function(data){
  50. if( this.options.expandSubEnable ){
  51. if (data.subDirectUnitCount){
  52. var category = this._newItemCategory("ItemCategory", data, this, container );
  53. this.subCategorys.push(category);
  54. }
  55. }else{
  56. var item = this._newItem( data, this, container );
  57. this.items.push( item );
  58. this.subItems.push(item);
  59. }
  60. }.bind(this));
  61. }
  62. loadUnitSuccess();
  63. }.bind(this), loadUnitFailure, unit);
  64. }else{
  65. this.orgAction.getUnit(function(json){
  66. json.data = typeOf( json.data ) == "object" ? [json.data] : json.data;
  67. if (json.data.length){
  68. json.data.each( function(data){
  69. if( this.options.expandSubEnable ) {
  70. if (data.subDirectUnitCount){
  71. var category = this._newItemCategory("ItemCategory", data, this, container );
  72. this.subCategorys.push(category);
  73. }
  74. }else{
  75. var item = this._newItem(data, this, container );
  76. this.items.push( item );
  77. this.subItems.push(item);
  78. }
  79. }.bind(this));
  80. }
  81. loadUnitSuccess();
  82. }.bind(this), loadUnitFailure, unit.id);
  83. //if (unit.subDirectUnitCount) var category = this._newItemCategory("ItemCategory", unit, this, this.itemAreaNode);
  84. }
  85. }.bind(this));
  86. }else{
  87. this.orgAction.listTopUnit(function(json){
  88. json.data.each(function(data){
  89. // var flag = true;
  90. // if (this.options.unitTypes.length){
  91. // flag = data.typeList.some(function(item){
  92. // return (!this.options.unitTypes.length) || (this.options.unitTypes.indexOf(item)!==-1)
  93. // }.bind(this));
  94. // }
  95. // if (flag){
  96. if( !this.isExcluded( data ) ) {
  97. var unit = this._newItem(data, this, this.itemAreaNode, 1);
  98. this.items.push( unit );
  99. this.subItems.push(unit);
  100. }
  101. //unit.loadSubItem();
  102. // }else{
  103. // var category = this._newItemCategory("ItemCategory", data, this, this.itemAreaNode);
  104. // }
  105. }.bind(this));
  106. afterLoadSelectItemFun();
  107. }.bind(this));
  108. }
  109. },
  110. _scrollEvent: function(y){
  111. return true;
  112. },
  113. _getChildrenItemIds: function(){
  114. return null;
  115. },
  116. _newItemCategory: function(type, data, selector, item, level, category, delay){
  117. return new MWF.xApplication.Selector.Unit[type](data, selector, item, level, category, delay)
  118. },
  119. _listItemByKey: function(callback, failure, key){
  120. if (this.options.units.length){
  121. var units = [];
  122. this.options.units.each(function(u){
  123. if (typeOf(u)==="string"){
  124. units.push(u);
  125. }
  126. if (typeOf(u)==="object"){
  127. units.push(u.distinguishedName);
  128. }
  129. });
  130. key = {"key": key, "unitList": units};
  131. }
  132. this.orgAction.listUnitByKey(function(json){
  133. if (callback) callback.apply(this, [json]);
  134. }.bind(this), failure, key);
  135. },
  136. _getItem: function(callback, failure, id, async){
  137. this.orgAction.getUnit(function(json){
  138. if (callback) callback.apply(this, [json]);
  139. }.bind(this), failure, ((typeOf(id)==="string") ? id : id.distinguishedName), async);
  140. },
  141. _newItemSelected: function(data, selector, item){
  142. return new MWF.xApplication.Selector.Unit.ItemSelected(data, selector, item)
  143. },
  144. _listItemByPinyin: function(callback, failure, key){
  145. if (this.options.units.length){
  146. var units = [];
  147. this.options.units.each(function(u){
  148. if (typeOf(u)==="string"){
  149. units.push(u);
  150. }
  151. if (typeOf(u)==="object"){
  152. units.push(u.distinguishedName);
  153. }
  154. });
  155. key = {"key": key, "unitList": units};
  156. }
  157. this.orgAction.listUnitByPinyininitial(function(json){
  158. if (callback) callback.apply(this, [json]);
  159. }.bind(this), failure, key);
  160. },
  161. _newItem: function(data, selector, container, level, category, delay){
  162. return new MWF.xApplication.Selector.Unit.Item(data, selector, container, level, category, delay);
  163. },
  164. _newItemSearch: function(data, selector, container, level){
  165. return new MWF.xApplication.Selector.Unit.SearchItem(data, selector, container, level);
  166. }
  167. });
  168. MWF.xApplication.Selector.Unit.Item = new Class({
  169. Extends: MWF.xApplication.Selector.Identity.Item,
  170. load : function(){
  171. if( this.selector.isFlatCategory ){
  172. if( !this.justItem && this.selector.options.expandSubEnable && this.data.subDirectUnitCount ){
  173. this.loadCategoryForFlatCategory();
  174. }else if(!this.ignoreItem){
  175. this.loadForNormal(true);
  176. }
  177. }else{
  178. this.loadForNormal();
  179. }
  180. },
  181. loadForNormal : function( isNotLoadSubItem, container ){
  182. this.selector.fireEvent("queryLoadItem",[this]);
  183. if( !this.node )this.node = new Element("div", {
  184. "styles": this.selector.css.selectorItem
  185. }).inject(container || this.container);
  186. this.levelNode = new Element("div", {
  187. "styles": this.selector.css.selectorItemLevelNode
  188. }).inject(this.node);
  189. var indent = this.selector.options.level1Indent + (this.level-1)*this.selector.options.indent;
  190. this.levelNode.setStyle("width", ""+indent+"px");
  191. this.iconNode = new Element("div", {
  192. "styles": this.selector.css.selectorItemIconNode
  193. }).inject(this.node);
  194. this._setIcon();
  195. this.actionNode = new Element("div", {
  196. "styles": this.selector.css.selectorItemActionNode
  197. }).inject(this.node);
  198. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single ){
  199. this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single );
  200. }
  201. this.textNode = new Element("div", {
  202. "styles": this.selector.css.selectorItemTextNode,
  203. "text": this._getShowName(),
  204. "title": this._getTtiteText()
  205. }).inject(this.node);
  206. this.textNode.store("indent", indent);
  207. var m = this.textNode.getStyle("margin-left").toFloat()+indent;
  208. this.textNode.setStyle("margin-left", ""+m+"px");
  209. if(this.postLoad)this.postLoad();
  210. if(!isNotLoadSubItem)this.loadSubItem();
  211. this.setEvent();
  212. this.check();
  213. if(this.afterLoad)this.afterLoad();
  214. this.selector.fireEvent("postLoadItem",[this]);
  215. },
  216. _getShowName: function(){
  217. return (this.isShowLevelName && this.data.levelName) ? this.data.levelName : this.data.name;
  218. },
  219. _getTtiteText: function(){
  220. return this.data.levelName || this.data.name;
  221. },
  222. _setIcon: function(){
  223. var style = this.selector.options.style;
  224. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/departmenticon.png)");
  225. },
  226. loadSubItem: function(){
  227. if( !this.selector.options.expandSubEnable )return;
  228. this.isExpand = (this.selector.options.expand);
  229. if ( this._hasChild() || this.selector.options.expandEmptyCategory ){
  230. if (this.selector.options.expand){
  231. if( typeOf(this.selector.options.defaultExpandLevel) === "number" ){
  232. if (this.level <= this.selector.options.defaultExpandLevel && this._hasChild() ){
  233. this.levelNode.setStyles(this.selector.css.selectorItemLevelNode_expand);
  234. this.loadSubItems();
  235. }else{
  236. this.isExpand = false;
  237. this.levelNode.setStyles(this.selector.css.selectorItemLevelNode_collapse);
  238. }
  239. }else if (this.level===1 && this._hasChild() ){
  240. this.levelNode.setStyles(this.selector.css.selectorItemLevelNode_expand);
  241. this.loadSubItems();
  242. }else{
  243. this.isExpand = false;
  244. this.levelNode.setStyles(this.selector.css.selectorItemLevelNode_collapse);
  245. }
  246. }else{
  247. this.levelNode.setStyles(this.selector.css.selectorItemLevelNode_collapse);
  248. }
  249. this.levelNode.addEvent("click", function(e){
  250. if (this.isExpand){
  251. this.selector.fireEvent("collapse", [this] );
  252. this.children.setStyle("display", "none");
  253. this.levelNode.setStyles(this.selector.css.selectorItemLevelNode_collapse);
  254. this.isExpand = false;
  255. }else{
  256. this.selector.fireEvent("expand", [this] );
  257. this.loadSubItems();
  258. this.levelNode.setStyles(this.selector.css.selectorItemLevelNode_expand);
  259. this.isExpand = true;
  260. }
  261. e.stopPropagation();
  262. }.bind(this));
  263. if( this.selector.css.selectorItemLevelNode_expand_over && this.selector.css.selectorItemLevelNode_collapse_over ){
  264. this.levelNode.addEvents({
  265. mouseover : function(e){
  266. var styles = this.isExpand ? this.selector.css.selectorItemLevelNode_expand_over : this.selector.css.selectorItemLevelNode_collapse_over;
  267. this.levelNode.setStyles(styles);
  268. }.bind(this),
  269. mouseout : function(e){
  270. var styles = this.isExpand ? this.selector.css.selectorItemLevelNode_expand : this.selector.css.selectorItemLevelNode_collapse;
  271. this.levelNode.setStyles(styles);
  272. }.bind(this)
  273. })
  274. }
  275. if( !this.selectAllNode && this.selector.options.count.toInt() !== 1 &&
  276. ( this.selector.options.style!=="blue_flat" && this.selector.options.style!=="blue_flat_mobile")){
  277. this.selectAllNode = new Element("div", {
  278. "styles": this.selector.css.selectorItemCategoryActionNode_selectAll,
  279. "title" : "全选下级"
  280. }).inject(this.textNode, "before");
  281. this.selectAllNode.addEvent( "click", function(ev){
  282. if( this.isSelectedAll ){
  283. // this.unselectAll(ev);
  284. this.selector.options.selectAllRange === "all" ? this.unselectAllNested(ev) : this.unselectAll(ev);
  285. this.selector.fireEvent("unselectCatgory",[this])
  286. }else{
  287. // this.selectAll(ev);
  288. this.selector.options.selectAllRange === "all" ? this.selectAllNested(ev) : this.selectAll(ev);
  289. this.selector.fireEvent("selectCatgory",[this])
  290. }
  291. ev.stopPropagation();
  292. }.bind(this));
  293. if( this.selector.css.selectorItemCategoryActionNode_selectAll_over ){
  294. this.selectAllNode.addEvents( {
  295. "mouseover" : function(ev){
  296. if( !this.isSelectedAll )this.selectAllNode.setStyles( this.selector.css.selectorItemCategoryActionNode_selectAll_over );
  297. //ev.stopPropagation();
  298. }.bind(this),
  299. "mouseout" : function(ev){
  300. if( !this.isSelectedAll )this.selectAllNode.setStyles( this.selector.css.selectorItemCategoryActionNode_selectAll );
  301. //ev.stopPropagation();
  302. }.bind(this)
  303. })
  304. }
  305. }
  306. }
  307. //this.actionNode.setStyles((this.selector.options.expand) ? this.selector.css.selectorItemCategoryActionNode_expand : this.selector.css.selectorItemCategoryActionNode_collapse);
  308. },
  309. unselectAll : function(ev, exclude){
  310. //( this.subItems || [] ).each( function(item){
  311. // if(item.isSelected)item.unSelected();
  312. //}.bind(this));
  313. var excludeList = exclude || [];
  314. if( exclude && typeOf(exclude) !== "array" )excludeList = [exclude];
  315. ( this.subItems || [] ).each( function(item){
  316. if(item.isSelected && !excludeList.contains(item) ){
  317. item.unSelected();
  318. }
  319. }.bind(this));
  320. if( this.selectAllNode ){
  321. if( this.selector.isFlatCategory ){
  322. this.selectAllNode.setStyles( this.selector.css.flatCategory_selectAll );
  323. }else if(this.selector.css.selectorItemCategoryActionNode_selectAll){
  324. this.selectAllNode.setStyles( this.selector.css.selectorItemCategoryActionNode_selectAll );
  325. }
  326. }
  327. this.isSelectedAll = false;
  328. },
  329. unselectAllNested : function( ev, exclude ){
  330. this.unselectAll(ev, exclude );
  331. if( this.subCategorys && this.subCategorys.length ){
  332. this.subCategorys.each( function( category ){
  333. if(category.unselectAllNested)category.unselectAllNested( ev, exclude )
  334. })
  335. }
  336. if( this.subItems && this.subItems.length ){
  337. this.subItems.each( function( item ){
  338. if(item.unselectAllNested)item.unselectAllNested( ev, exclude )
  339. })
  340. }
  341. },
  342. selectAllNested : function(){
  343. this.selectAll();
  344. if( this.subCategorys && this.subCategorys.length ){
  345. this.subCategorys.each( function( category ){
  346. if(category.selectAllNested)category.selectAllNested()
  347. })
  348. }
  349. if( this.subItems && this.subItems.length ){
  350. this.subItems.each( function( item ){
  351. if(item.selectAllNested)item.selectAllNested()
  352. })
  353. }
  354. },
  355. selectAll: function(ev){
  356. if( this.loaded || this.selector.isFlatCategory ){
  357. this._selectAll( ev )
  358. }else{
  359. this.loadSubItems(function(){
  360. this._selectAll( ev )
  361. }.bind(this));
  362. this.levelNode.setStyles(this.selector.css.selectorItemLevelNode_expand);
  363. this.isExpand = true;
  364. }
  365. },
  366. _selectAll : function( ev ){
  367. if( !this.subItems || !this.subItems.length )return;
  368. var count = this.selector.options.maxCount || this.selector.options.count;
  369. if (!count) count = 0;
  370. var selectedSubItemCount = 0;
  371. this.subItems.each( function(item){
  372. if(item.isSelected)selectedSubItemCount++
  373. }.bind(this));
  374. if ((count.toInt()===0) || (this.selector.selectedItems.length+(this.subItems.length-selectedSubItemCount))<=count){
  375. this.subItems.each( function(item){
  376. if(!item.isSelected)item.selected();
  377. }.bind(this));
  378. if( this.selectAllNode ){
  379. if( this.selector.isFlatCategory ){
  380. this.selectAllNode.setStyles( this.selector.css.flatCategory_selectAll_selected );
  381. }else if(this.selector.css.selectorItemCategoryActionNode_selectAll_selected){
  382. this.selectAllNode.setStyles( this.selector.css.selectorItemCategoryActionNode_selectAll_selected );
  383. }
  384. }
  385. this.isSelectedAll = true;
  386. }else{
  387. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "最多可选择"+count+"个选项", this.node);
  388. }
  389. },
  390. checkSelectAll : function(){
  391. if( this.isSelectedAll )return;
  392. if( !this.selectAllNode )return;
  393. if( !this.subItems )return;
  394. var isAllItemSelected = true;
  395. for( var i=0; i< this.subItems.length; i++ ){
  396. if( !this.subItems[i].isSelected ){
  397. isAllItemSelected = false;
  398. break;
  399. }
  400. }
  401. if( isAllItemSelected ){
  402. if( this.selector.isFlatCategory ){
  403. this.selectAllNode.setStyles( this.selector.css.flatCategory_selectAll_selected );
  404. }else if( this.selector.css.selectorItemCategoryActionNode_selectAll_selected ){
  405. this.selectAllNode.setStyles( this.selector.css.selectorItemCategoryActionNode_selectAll_selected );
  406. }
  407. this.isSelectedAll = true;
  408. }
  409. },
  410. checkUnselectAll : function(){
  411. if( !this.isSelectedAll )return;
  412. if( !this.selectAllNode )return;
  413. if( ! this.subItems )return;
  414. var hasSelectedItem = false;
  415. for( var i=0; i< this.subItems.length; i++ ){
  416. if( this.subItems[i].isSelected ){
  417. hasSelectedItem = true;
  418. break;
  419. }
  420. }
  421. if( !hasSelectedItem ){
  422. if( this.selector.isFlatCategory ){
  423. this.selectAllNode.setStyles( this.selector.css.flatCategory_selectAll );
  424. }else if( this.selector.css.selectorItemCategoryActionNode_selectAll ){
  425. this.selectAllNode.setStyles( this.selector.css.selectorItemCategoryActionNode_selectAll );
  426. }
  427. this.isSelectedAll = false;
  428. }
  429. },
  430. loadSubItems: function( callback ){
  431. if (!this.loaded){
  432. if (!this.children){
  433. this.children = new Element("div", {
  434. "styles": this.selector.css.selectorItemCategoryChildrenNode
  435. }).inject(this.node, "after");
  436. }
  437. this.children.setStyle("display", "block");
  438. // if (!this.selector.options.expand) this.children.setStyle("display", "none");
  439. this.selector.orgAction.listSubUnitDirect(function(subJson){
  440. subJson.data.each(function(subData){
  441. if( !this.selector.isExcluded( subData ) ) {
  442. var category = this.selector._newItem(subData, this.selector, this.children, this.level + 1, this);
  443. this.selector.items.push( category );
  444. if( !this.subItems )this.subItems = [];
  445. this.subItems.push( category );
  446. }
  447. }.bind(this));
  448. this.loaded = true;
  449. if(callback)callback();
  450. }.bind(this), null, this.data.distinguishedName);
  451. }else{
  452. this.children.setStyle("display", "block");
  453. }
  454. },
  455. getData: function(callback){
  456. if (callback) callback();
  457. },
  458. postLoad : function(){
  459. if( this.selector.options.style === "blue_flat" ) {
  460. if (this.level === 1) {
  461. var indent = 26;
  462. this.levelNode.setStyle("width", "" + indent + "px");
  463. } else {
  464. var indent = 26 + ( this.level - 1 ) * this.selector.options.indent;
  465. this.levelNode.setStyle("width", "" + indent + "px");
  466. }
  467. }
  468. //}else if( this.selector.options.style === "blue_flat_mobile" ){
  469. // if( this.level === 1 ){
  470. // var indent = 40;
  471. // this.levelNode.setStyle("width", ""+indent+"px");
  472. // }else{
  473. // var indent = 40 + ( this.level -1 ) * this.selector.options.indent ;
  474. // this.levelNode.setStyle("width", ""+indent+"px");
  475. // }
  476. //}
  477. },
  478. loadCategoryForFlatCategory : function(){
  479. this.selector.fireEvent("queryLoadCategory",[this]);
  480. if( !this.flatCategoryItemNode ){
  481. this.flatCategoryItemNode = new Element("div.flatCategoryItemNode", {
  482. "styles": this.selector.css.flatCategoryItemNode,
  483. "title" : this._getTtiteText()
  484. });
  485. this.flatCategoryItemNode.store( "category", this );
  486. this.flatCategoryItemNode.store( "dn", this.data.distinguishedName );
  487. this.flatCategoryItemTextNode = new Element("div", {
  488. "styles": this.selector.css.flatCategoryItemTextNode,
  489. "text": this._getShowName(),
  490. "title": this._getTtiteText()
  491. }).inject(this.flatCategoryItemNode);
  492. }
  493. this.children = new Element("div", {
  494. "styles": this.selector.css.selectorItemCategoryChildrenNode
  495. }).inject(this.selector.itemAreaNode);
  496. this.children.setStyle("display", "none");
  497. if( this.level === 1 ){
  498. this.loadForNormal(true, this.children);
  499. }
  500. if( !this.selectAllNode && this.selector.options.count.toInt() !== 1 ){
  501. var selectAllWrap = new Element("div",{
  502. styles : this.selector.css.flatCategory_selectAllWrap
  503. }).inject(this.children);
  504. this.selectAllNode = new Element("div", {
  505. "styles": this.selector.css.flatCategory_selectAll,
  506. "text" : "全选"
  507. }).inject(selectAllWrap);
  508. this.selectAllNode.addEvent( "click", function(ev){
  509. if( this.isSelectedAll ){
  510. this.unselectAll(ev);
  511. this.selector.fireEvent("unselectCatgory",[this])
  512. }else{
  513. this.selectAll(ev);
  514. this.selector.fireEvent("selectCatgory",[this])
  515. }
  516. ev.stopPropagation();
  517. }.bind(this));
  518. }
  519. //this.loadForNormal(true, this.children);
  520. this.flatCategoryItemNode.addEvents({
  521. //"mouseover": function(){
  522. // if (!this.isSelected )this.node.setStyles(this.selector.css.flatCategoryItemNode_over );
  523. //}.bind(this),
  524. //"mouseout": function(){
  525. // if (!this.isSelected )this.node.setStyles(this.selector.css.flatCategoryItemNode );
  526. //}.bind(this),
  527. "click": function(){
  528. if( this.selector.currentFlatCategory === this )return;
  529. if( this.selector.currentFlatCategory ){
  530. this.selector.currentFlatCategory.clickFlatCategoryItem(null, true); //取消原来选择的
  531. }
  532. this.selector.currentFlatCategory = this;
  533. this.clickFlatCategoryItem();
  534. }.bind(this)
  535. });
  536. //this.setEvent();
  537. var isCreateSubCategoryListNode = this.data.subDirectUnitCount ? this.data.subDirectUnitCount : true;
  538. var nodeContainer;
  539. if( this.nodeContainer ){
  540. nodeContainer = this.nodeContainer;
  541. }else{
  542. nodeContainer = (this.category && this.category.subCategoryListNode) ? this.category.subCategoryListNode : null;
  543. }
  544. this.subCategoryListNode = this.selector.addFlatCategoryItem( this.flatCategoryItemNode, this.data.subDirectUnitCount, nodeContainer, isCreateSubCategoryListNode );
  545. //this.check();
  546. if( this.loadCategoryChildren )this.loadCategoryChildren();
  547. //if(this.postLoad)this.postLoad();
  548. //this.setEvent();
  549. //this.check();
  550. this.selector.fireEvent("postLoadCategory",[this]);
  551. },
  552. clickFlatCategoryItem : function( callback, hidden ){
  553. //if (this._hasChildItem()){
  554. var firstLoaded = !this.itemLoaded;
  555. this.loadItemChildren(function(){
  556. if( hidden ){
  557. this.children.setStyles({ "display": "none" });
  558. this.flatCategoryItemNode.setStyles(this.selector.css.flatCategoryItemNode);
  559. this.isExpand = false;
  560. }else if( firstLoaded ){
  561. this.children.setStyles({"display": "block"});
  562. this.flatCategoryItemNode.setStyles( this.selector.css.flatCategoryItemNode_selected );
  563. this.isExpand = true;
  564. }else {
  565. var display = this.children.getStyle("display");
  566. if (display === "none") {
  567. this.children.setStyles({ "display": "block" });
  568. this.flatCategoryItemNode.setStyles(this.selector.css.flatCategoryItemNode_selected);
  569. this.isExpand = true;
  570. } else {
  571. this.children.setStyles({ "display": "none" });
  572. this.flatCategoryItemNode.setStyles(this.selector.css.flatCategoryItemNode);
  573. this.isExpand = false;
  574. }
  575. }
  576. if(callback)callback()
  577. }.bind(this));
  578. //}
  579. },
  580. loadCategoryChildren : function( callback ){
  581. if (!this.categoryLoaded){
  582. this.selector.orgAction.listSubUnitDirect(function(subJson){
  583. subJson.data.each(function(subData){
  584. if( !this.selector.isExcluded( subData ) ) {
  585. if( subData.subDirectUnitCount ){
  586. var category = this.selector._newItem(subData, this.selector, this.children, this.level + 1, this);
  587. //if( !this.subItems )this.subItems = [];
  588. //this.subItems.push( category );
  589. }
  590. }
  591. }.bind(this));
  592. this.categoryLoaded = true;
  593. if(callback)callback();
  594. }.bind(this), null, this.data.distinguishedName);
  595. }else{
  596. if(callback)callback();
  597. }
  598. },
  599. loadItemChildren : function( callback ){
  600. if (!this.itemLoaded){
  601. this.selector.orgAction.listSubUnitDirect(function(subJson){
  602. subJson.data.each(function(subData){
  603. if( !this.selector.isExcluded( subData ) ) {
  604. //if( !subData.subDirectUnitCount ){
  605. var category = this.selector._newItem(subData, this.selector, this.children, this.level + 1, this, true);
  606. category.justItem = true;
  607. category.load();
  608. this.selector.items.push( category );
  609. if( !this.subItems )this.subItems = [];
  610. this.subItems.push( category );
  611. //}
  612. }
  613. }.bind(this));
  614. this.itemLoaded = true;
  615. if(callback)callback();
  616. }.bind(this), null, this.data.distinguishedName);
  617. }else{
  618. if(callback)callback();
  619. }
  620. },
  621. _hasChild : function () {
  622. return this.data.subDirectUnitCount;
  623. }
  624. });
  625. MWF.xApplication.Selector.Unit.SearchItem = new Class({
  626. Extends: MWF.xApplication.Selector.Unit.Item,
  627. load : function(){
  628. this.loadForNormal();
  629. },
  630. _getShowName: function(){
  631. return this.data.levelName || this.data.name;
  632. },
  633. loadSubItems: function( callback ){
  634. //只是为了在isFlatCategory模式下,加载全称用的,否则用继承的就可以
  635. if (!this.loaded){
  636. if (!this.children){
  637. this.children = new Element("div", {
  638. "styles": this.selector.css.selectorItemCategoryChildrenNode
  639. }).inject(this.node, "after");
  640. }
  641. this.children.setStyle("display", "block");
  642. // if (!this.selector.options.expand) this.children.setStyle("display", "none");
  643. this.selector.orgAction.listSubUnitDirect(function(subJson){
  644. subJson.data.each(function(subData){
  645. if( !this.selector.isExcluded( subData ) ) {
  646. var category;
  647. if( this.selector.isFlatCategory ){
  648. category = this.selector._newItem(subData, this.selector, this.children, this.level + 1, this, true);
  649. category.isShowLevelName = true;
  650. category.load();
  651. }else{
  652. category = this.selector._newItem(subData, this.selector, this.children, this.level + 1, this);
  653. }
  654. this.selector.items.push( category );
  655. if( !this.subItems )this.subItems = [];
  656. this.subItems.push( category );
  657. }
  658. }.bind(this));
  659. this.loaded = true;
  660. if(callback)callback();
  661. }.bind(this), null, this.data.distinguishedName);
  662. }else{
  663. this.children.setStyle("display", "block");
  664. }
  665. }
  666. });
  667. MWF.xApplication.Selector.Unit.ItemSelected = new Class({
  668. Extends: MWF.xApplication.Selector.Identity.ItemSelected,
  669. getData: function(callback){
  670. if (callback) callback();
  671. },
  672. _getTtiteText: function(){
  673. return this.data.levelName || this.data.name;
  674. },
  675. _getShowName: function(){
  676. return this.data.name+((this.data.levelName) ? "("+this.data.levelName+")" : "");
  677. },
  678. _setIcon: function(){
  679. var style = this.selector.options.style;
  680. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/departmenticon.png)");
  681. }
  682. });
  683. MWF.xApplication.Selector.Unit.ItemCategory = new Class({
  684. Extends: MWF.xApplication.Selector.Identity.ItemCategory,
  685. loadSub: function(callback){
  686. if (!this.loaded){
  687. this.selector.orgAction.listSubUnitDirect(function(subJson){
  688. subJson.data.each(function(subData){
  689. if( !this.selector.isExcluded( subData ) ) {
  690. var category = this.selector._newItem(subData, this.selector, this.children, this.level+1, this);
  691. this.selector.items.push( category );
  692. if(this.subItems)this.subItems.push( category );
  693. this.subCategorys.push( category );
  694. }
  695. //var category = this.selector._newItemCategory("ItemCategory", subData, this.selector, this.children, this.level+1);
  696. }.bind(this));
  697. this.loaded = true;
  698. if (callback) callback();
  699. }.bind(this), null, this.data.distinguishedName);
  700. }else{
  701. if (callback) callback();
  702. }
  703. },
  704. _hasChild: function(){
  705. var uCount = (this.data.subDirectUnitCount) ? this.data.subDirectUnitCount : 0;
  706. //var iCount = (this.data.subDirectIdentityCount) ? this.data.subDirectIdentityCount : 0;
  707. return uCount;
  708. },
  709. _hasChildCategory: function(){
  710. var uCount = (this.data.subDirectUnitCount) ? this.data.subDirectUnitCount : 0;
  711. return uCount;
  712. },
  713. _hasChildItem: function(){
  714. var uCount = (this.data.subDirectUnitCount) ? this.data.subDirectUnitCount : 0;
  715. return uCount;
  716. },
  717. //for flat category start
  718. loadCategoryChildren: function(callback){
  719. if (!this.categoryLoaded){
  720. this.selector.orgAction.listSubUnitDirect(function(subJson){
  721. subJson.data.each(function(subData){
  722. if( !this.selector.isExcluded( subData ) ) {
  723. var category = this.selector._newItem(subData, this.selector, this.children, this.level+1, this, true);
  724. category.ignoreItem = true;
  725. category.load();
  726. //if(this.subItems)this.subItems.push( category );
  727. this.subCategorys.push( category );
  728. }
  729. //var category = this.selector._newItemCategory("ItemCategory", subData, this.selector, this.children, this.level+1);
  730. }.bind(this));
  731. this.categoryLoaded = true;
  732. if (callback) callback();
  733. }.bind(this), null, this.data.distinguishedName);
  734. }else{
  735. if (callback) callback( );
  736. }
  737. },
  738. loadItemChildren: function(callback){
  739. if (!this.itemLoaded){
  740. this.selector.orgAction.listSubUnitDirect(function(subJson){
  741. subJson.data.each(function(subData){
  742. if( !this.selector.isExcluded( subData ) ) {
  743. var category = this.selector._newItem(subData, this.selector, this.children, this.level+1, this, true);
  744. category.justItem = true;
  745. category.load();
  746. this.selector.items.push( category );
  747. if(this.subItems)this.subItems.push( category );
  748. //this.subCategorys.push( category );
  749. }
  750. //var category = this.selector._newItemCategory("ItemCategory", subData, this.selector, this.children, this.level+1);
  751. }.bind(this));
  752. this.itemLoaded = true;
  753. if (callback) callback();
  754. }.bind(this), null, this.data.distinguishedName);
  755. }else{
  756. if (callback) callback( );
  757. }
  758. }
  759. });
  760. MWF.xApplication.Selector.Unit.Filter = new Class({
  761. Implements: [Options, Events],
  762. options: {
  763. "style": "default",
  764. "units": []
  765. },
  766. initialize: function(value, options){
  767. this.setOptions(options);
  768. this.value = value;
  769. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  770. },
  771. filter: function(value, callback){
  772. this.value = value;
  773. var key = this.value;
  774. if (this.options.units.length){
  775. var units = [];
  776. this.options.units.each(function(u){
  777. if (typeOf(u)==="string"){
  778. units.push(u);
  779. }
  780. if (typeOf(u)==="object"){
  781. units.push(u.distinguishedName);
  782. }
  783. });
  784. key = {"key": key, "unitList": units};
  785. }
  786. this.orgAction.listUnitByKey(function(json){
  787. data = json.data;
  788. if (callback) callback(data)
  789. }.bind(this), null, key);
  790. }
  791. });