Unit.js 34 KB

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