Unit.js 35 KB

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