Unit.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802
  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.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() ){
  214. if (this.selector.options.expand){
  215. if (this.level===1){
  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.children.setStyle("display", "none");
  228. this.levelNode.setStyles(this.selector.css.selectorItemLevelNode_collapse);
  229. this.isExpand = false;
  230. }else{
  231. this.loadSubItems();
  232. this.levelNode.setStyles(this.selector.css.selectorItemLevelNode_expand);
  233. this.isExpand = true;
  234. }
  235. e.stopPropagation();
  236. }.bind(this));
  237. if( this.selector.css.selectorItemLevelNode_expand_over && this.selector.css.selectorItemLevelNode_collapse_over ){
  238. this.levelNode.addEvents({
  239. mouseover : function(e){
  240. var styles = this.isExpand ? this.selector.css.selectorItemLevelNode_expand_over : this.selector.css.selectorItemLevelNode_collapse_over;
  241. this.levelNode.setStyles(styles);
  242. }.bind(this),
  243. mouseout : function(e){
  244. var styles = this.isExpand ? this.selector.css.selectorItemLevelNode_expand : this.selector.css.selectorItemLevelNode_collapse;
  245. this.levelNode.setStyles(styles);
  246. }.bind(this)
  247. })
  248. }
  249. if( !this.selectAllNode && this.selector.options.count.toInt() !== 1 &&
  250. ( this.selector.options.style!=="blue_flat" && this.selector.options.style!=="blue_flat_mobile")){
  251. this.selectAllNode = new Element("div", {
  252. "styles": this.selector.css.selectorItemCategoryActionNode_selectAll,
  253. "title" : "全选下级"
  254. }).inject(this.textNode, "before");
  255. this.selectAllNode.addEvent( "click", function(ev){
  256. if( this.isSelectedAll ){
  257. this.unselectAll(ev);
  258. this.selector.fireEvent("unselectCatgory",[this])
  259. }else{
  260. this.selectAll(ev);
  261. this.selector.fireEvent("selectCatgory",[this])
  262. }
  263. ev.stopPropagation();
  264. }.bind(this));
  265. if( this.selector.css.selectorItemCategoryActionNode_selectAll_over ){
  266. this.selectAllNode.addEvents( {
  267. "mouseover" : function(ev){
  268. if( !this.isSelectedAll )this.selectAllNode.setStyles( this.selector.css.selectorItemCategoryActionNode_selectAll_over );
  269. //ev.stopPropagation();
  270. }.bind(this),
  271. "mouseout" : function(ev){
  272. if( !this.isSelectedAll )this.selectAllNode.setStyles( this.selector.css.selectorItemCategoryActionNode_selectAll );
  273. //ev.stopPropagation();
  274. }.bind(this)
  275. })
  276. }
  277. }
  278. }
  279. //this.actionNode.setStyles((this.selector.options.expand) ? this.selector.css.selectorItemCategoryActionNode_expand : this.selector.css.selectorItemCategoryActionNode_collapse);
  280. },
  281. unselectAll : function(ev, exclude){
  282. //( this.subItems || [] ).each( function(item){
  283. // if(item.isSelected)item.unSelected();
  284. //}.bind(this));
  285. var excludeList = exclude || [];
  286. if( exclude && typeOf(exclude) !== "array" )excludeList = [exclude];
  287. ( this.subItems || [] ).each( function(item){
  288. if(item.isSelected && !excludeList.contains(item) ){
  289. item.unSelected();
  290. }
  291. }.bind(this));
  292. if( this.selectAllNode ){
  293. if( this.selector.isFlatCategory ){
  294. this.selectAllNode.setStyles( this.selector.css.flatCategory_selectAll );
  295. }else if(this.selector.css.selectorItemCategoryActionNode_selectAll){
  296. this.selectAllNode.setStyles( this.selector.css.selectorItemCategoryActionNode_selectAll );
  297. }
  298. }
  299. this.isSelectedAll = false;
  300. },
  301. unselectAllNested : function( ev, exclude ){
  302. this.unselectAll(ev, exclude );
  303. if( this.subCategorys && this.subCategorys.length ){
  304. this.subCategorys.each( function( category ){
  305. if(category.unselectAllNested)category.unselectAllNested( ev, exclude )
  306. })
  307. }
  308. if( this.subItems && this.subItems.length ){
  309. this.subItems.each( function( item ){
  310. if(item.unselectAllNested)item.unselectAllNested( ev, exclude )
  311. })
  312. }
  313. },
  314. selectAllNested : function(){
  315. this.selectAll();
  316. if( this.subCategorys && this.subCategorys.length ){
  317. this.subCategorys.each( function( category ){
  318. if(category.selectAllNested)category.selectAllNested()
  319. })
  320. }
  321. if( this.subItems && this.subItems.length ){
  322. this.subItems.each( function( item ){
  323. if(item.selectAllNested)item.selectAllNested()
  324. })
  325. }
  326. },
  327. selectAll: function(ev){
  328. if( this.loaded || this.selector.isFlatCategory ){
  329. this._selectAll( ev )
  330. }else{
  331. this.loadSubItems(function(){
  332. this._selectAll( ev )
  333. }.bind(this));
  334. this.levelNode.setStyles(this.selector.css.selectorItemLevelNode_expand);
  335. this.isExpand = true;
  336. }
  337. },
  338. _selectAll : function( ev ){
  339. if( !this.subItems || !this.subItems.length )return;
  340. var count = this.selector.options.maxCount || this.selector.options.count;
  341. if (!count) count = 0;
  342. var selectedSubItemCount = 0;
  343. this.subItems.each( function(item){
  344. if(item.isSelected)selectedSubItemCount++
  345. }.bind(this));
  346. if ((count.toInt()===0) || (this.selector.selectedItems.length+(this.subItems.length-selectedSubItemCount))<=count){
  347. this.subItems.each( function(item){
  348. if(!item.isSelected)item.selected();
  349. }.bind(this));
  350. if( this.selectAllNode ){
  351. if( this.selector.isFlatCategory ){
  352. this.selectAllNode.setStyles( this.selector.css.flatCategory_selectAll_selected );
  353. }else if(this.selector.css.selectorItemCategoryActionNode_selectAll_selected){
  354. this.selectAllNode.setStyles( this.selector.css.selectorItemCategoryActionNode_selectAll_selected );
  355. }
  356. }
  357. this.isSelectedAll = true;
  358. }else{
  359. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "最多可选择"+count+"个选项", this.node);
  360. }
  361. },
  362. checkSelectAll : function(){
  363. if( !this.isSelectedAll )return;
  364. if( !this.selectAllNode )return;
  365. if( ! this.subItems )return;
  366. var hasSelectedItem = false;
  367. for( var i=0; i< this.subItems.length; i++ ){
  368. if( this.subItems[i].isSelected ){
  369. hasSelectedItem = true;
  370. break;
  371. }
  372. }
  373. if( !hasSelectedItem ){
  374. if( this.selector.isFlatCategory ){
  375. this.selectAllNode.setStyles( this.selector.css.flatCategory_selectAll );
  376. }else if( this.selector.css.selectorItemCategoryActionNode_selectAll ){
  377. this.selectAllNode.setStyles( this.selector.css.selectorItemCategoryActionNode_selectAll );
  378. }
  379. this.isSelectedAll = false;
  380. }
  381. },
  382. loadSubItems: function( callback ){
  383. if (!this.loaded){
  384. if (!this.children){
  385. this.children = new Element("div", {
  386. "styles": this.selector.css.selectorItemCategoryChildrenNode
  387. }).inject(this.node, "after");
  388. }
  389. this.children.setStyle("display", "block");
  390. // if (!this.selector.options.expand) this.children.setStyle("display", "none");
  391. this.selector.orgAction.listSubUnitDirect(function(subJson){
  392. subJson.data.each(function(subData){
  393. if( !this.selector.isExcluded( subData ) ) {
  394. var category = this.selector._newItem(subData, this.selector, this.children, this.level + 1, this);
  395. if( !this.subItems )this.subItems = [];
  396. this.subItems.push( category );
  397. }
  398. }.bind(this));
  399. this.loaded = true;
  400. if(callback)callback();
  401. }.bind(this), null, this.data.distinguishedName);
  402. }else{
  403. this.children.setStyle("display", "block");
  404. }
  405. },
  406. getData: function(callback){
  407. if (callback) callback();
  408. },
  409. postLoad : function(){
  410. if( this.selector.options.style === "blue_flat" ) {
  411. if (this.level === 1) {
  412. var indent = 26;
  413. this.levelNode.setStyle("width", "" + indent + "px");
  414. } else {
  415. var indent = 26 + ( this.level - 1 ) * this.selector.options.indent;
  416. this.levelNode.setStyle("width", "" + indent + "px");
  417. }
  418. }
  419. //}else if( this.selector.options.style === "blue_flat_mobile" ){
  420. // if( this.level === 1 ){
  421. // var indent = 40;
  422. // this.levelNode.setStyle("width", ""+indent+"px");
  423. // }else{
  424. // var indent = 40 + ( this.level -1 ) * this.selector.options.indent ;
  425. // this.levelNode.setStyle("width", ""+indent+"px");
  426. // }
  427. //}
  428. },
  429. loadCategoryForFlatCategory : function(){
  430. this.selector.fireEvent("queryLoadCategory",[this]);
  431. if( !this.flatCategoryItemNode ){
  432. this.flatCategoryItemNode = new Element("div.flatCategoryItemNode", {
  433. "styles": this.selector.css.flatCategoryItemNode,
  434. "title" : this._getTtiteText()
  435. });
  436. this.flatCategoryItemNode.store( "category", this );
  437. this.flatCategoryItemNode.store( "dn", this.data.distinguishedName );
  438. this.flatCategoryItemTextNode = new Element("div", {
  439. "styles": this.selector.css.flatCategoryItemTextNode,
  440. "text": this._getShowName(),
  441. "title": this._getTtiteText()
  442. }).inject(this.flatCategoryItemNode);
  443. }
  444. this.children = new Element("div", {
  445. "styles": this.selector.css.selectorItemCategoryChildrenNode
  446. }).inject(this.selector.itemAreaNode);
  447. this.children.setStyle("display", "none");
  448. if( this.level === 1 ){
  449. this.loadForNormal(true, this.children);
  450. }
  451. if( !this.selectAllNode && this.selector.options.count.toInt() !== 1 ){
  452. var selectAllWrap = new Element("div",{
  453. styles : this.selector.css.flatCategory_selectAllWrap
  454. }).inject(this.children);
  455. this.selectAllNode = new Element("div", {
  456. "styles": this.selector.css.flatCategory_selectAll,
  457. "text" : "全选"
  458. }).inject(selectAllWrap);
  459. this.selectAllNode.addEvent( "click", function(ev){
  460. if( this.isSelectedAll ){
  461. this.unselectAll(ev);
  462. this.selector.fireEvent("unselectCatgory",[this])
  463. }else{
  464. this.selectAll(ev);
  465. this.selector.fireEvent("selectCatgory",[this])
  466. }
  467. ev.stopPropagation();
  468. }.bind(this));
  469. }
  470. //this.loadForNormal(true, this.children);
  471. this.flatCategoryItemNode.addEvents({
  472. //"mouseover": function(){
  473. // if (!this.isSelected )this.node.setStyles(this.selector.css.flatCategoryItemNode_over );
  474. //}.bind(this),
  475. //"mouseout": function(){
  476. // if (!this.isSelected )this.node.setStyles(this.selector.css.flatCategoryItemNode );
  477. //}.bind(this),
  478. "click": function(){
  479. if( this.selector.currentFlatCategory === this )return;
  480. if( this.selector.currentFlatCategory ){
  481. this.selector.currentFlatCategory.clickFlatCategoryItem(null, true); //取消原来选择的
  482. }
  483. this.selector.currentFlatCategory = this;
  484. this.clickFlatCategoryItem();
  485. }.bind(this)
  486. });
  487. //this.setEvent();
  488. var isCreateSubCategoryListNode = this.data.subDirectUnitCount ? this.data.subDirectUnitCount : true;
  489. var nodeContainer;
  490. if( this.nodeContainer ){
  491. nodeContainer = this.nodeContainer;
  492. }else{
  493. nodeContainer = (this.category && this.category.subCategoryListNode) ? this.category.subCategoryListNode : null;
  494. }
  495. this.subCategoryListNode = this.selector.addFlatCategoryItem( this.flatCategoryItemNode, this.data.subDirectUnitCount, nodeContainer, isCreateSubCategoryListNode );
  496. //this.check();
  497. if( this.loadCategoryChildren )this.loadCategoryChildren();
  498. //if(this.postLoad)this.postLoad();
  499. //this.setEvent();
  500. //this.check();
  501. this.selector.fireEvent("postLoadCategory",[this]);
  502. },
  503. clickFlatCategoryItem : function( callback, hidden ){
  504. //if (this._hasChildItem()){
  505. var firstLoaded = !this.itemLoaded;
  506. this.loadItemChildren(function(){
  507. if( hidden ){
  508. this.children.setStyles({ "display": "none" });
  509. this.flatCategoryItemNode.setStyles(this.selector.css.flatCategoryItemNode);
  510. this.isExpand = false;
  511. }else if( firstLoaded ){
  512. this.children.setStyles({"display": "block"});
  513. this.flatCategoryItemNode.setStyles( this.selector.css.flatCategoryItemNode_selected );
  514. this.isExpand = true;
  515. }else {
  516. var display = this.children.getStyle("display");
  517. if (display === "none") {
  518. this.children.setStyles({ "display": "block" });
  519. this.flatCategoryItemNode.setStyles(this.selector.css.flatCategoryItemNode_selected);
  520. this.isExpand = true;
  521. } else {
  522. this.children.setStyles({ "display": "none" });
  523. this.flatCategoryItemNode.setStyles(this.selector.css.flatCategoryItemNode);
  524. this.isExpand = false;
  525. }
  526. }
  527. if(callback)callback()
  528. }.bind(this));
  529. //}
  530. },
  531. loadCategoryChildren : function( callback ){
  532. if (!this.categoryLoaded){
  533. this.selector.orgAction.listSubUnitDirect(function(subJson){
  534. subJson.data.each(function(subData){
  535. if( !this.selector.isExcluded( subData ) ) {
  536. if( subData.subDirectUnitCount ){
  537. var category = this.selector._newItem(subData, this.selector, this.children, this.level + 1, this);
  538. //if( !this.subItems )this.subItems = [];
  539. //this.subItems.push( category );
  540. }
  541. }
  542. }.bind(this));
  543. this.categoryLoaded = true;
  544. if(callback)callback();
  545. }.bind(this), null, this.data.distinguishedName);
  546. }else{
  547. if(callback)callback();
  548. }
  549. },
  550. loadItemChildren : function( callback ){
  551. if (!this.itemLoaded){
  552. this.selector.orgAction.listSubUnitDirect(function(subJson){
  553. subJson.data.each(function(subData){
  554. if( !this.selector.isExcluded( subData ) ) {
  555. //if( !subData.subDirectUnitCount ){
  556. var category = this.selector._newItem(subData, this.selector, this.children, this.level + 1, this, true);
  557. category.justItem = true;
  558. category.load();
  559. if( !this.subItems )this.subItems = [];
  560. this.subItems.push( category );
  561. //}
  562. }
  563. }.bind(this));
  564. this.itemLoaded = true;
  565. if(callback)callback();
  566. }.bind(this), null, this.data.distinguishedName);
  567. }else{
  568. if(callback)callback();
  569. }
  570. },
  571. _hasChild : function () {
  572. return this.data.subDirectUnitCount;
  573. }
  574. });
  575. MWF.xApplication.Selector.Unit.SearchItem = new Class({
  576. Extends: MWF.xApplication.Selector.Unit.Item,
  577. load : function(){
  578. this.loadForNormal();
  579. },
  580. _getShowName: function(){
  581. return this.data.levelName || this.data.name;
  582. },
  583. loadSubItems: function( callback ){
  584. //只是为了在isFlatCategory模式下,加载全称用的,否则用继承的就可以
  585. if (!this.loaded){
  586. if (!this.children){
  587. this.children = new Element("div", {
  588. "styles": this.selector.css.selectorItemCategoryChildrenNode
  589. }).inject(this.node, "after");
  590. }
  591. this.children.setStyle("display", "block");
  592. // if (!this.selector.options.expand) this.children.setStyle("display", "none");
  593. this.selector.orgAction.listSubUnitDirect(function(subJson){
  594. subJson.data.each(function(subData){
  595. if( !this.selector.isExcluded( subData ) ) {
  596. var category;
  597. if( this.selector.isFlatCategory ){
  598. category = this.selector._newItem(subData, this.selector, this.children, this.level + 1, this, true);
  599. category.isShowLevelName = true;
  600. category.load();
  601. }else{
  602. category = this.selector._newItem(subData, this.selector, this.children, this.level + 1, this);
  603. }
  604. if( !this.subItems )this.subItems = [];
  605. this.subItems.push( category );
  606. }
  607. }.bind(this));
  608. this.loaded = true;
  609. if(callback)callback();
  610. }.bind(this), null, this.data.distinguishedName);
  611. }else{
  612. this.children.setStyle("display", "block");
  613. }
  614. }
  615. });
  616. MWF.xApplication.Selector.Unit.ItemSelected = new Class({
  617. Extends: MWF.xApplication.Selector.Identity.ItemSelected,
  618. getData: function(callback){
  619. if (callback) callback();
  620. },
  621. _getTtiteText: function(){
  622. return this.data.levelName || this.data.name;
  623. },
  624. _getShowName: function(){
  625. return this.data.name+((this.data.levelName) ? "("+this.data.levelName+")" : "");
  626. },
  627. _setIcon: function(){
  628. var style = this.selector.options.style;
  629. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/departmenticon.png)");
  630. }
  631. });
  632. MWF.xApplication.Selector.Unit.ItemCategory = new Class({
  633. Extends: MWF.xApplication.Selector.Identity.ItemCategory,
  634. loadSub: function(callback){
  635. if (!this.loaded){
  636. this.selector.orgAction.listSubUnitDirect(function(subJson){
  637. subJson.data.each(function(subData){
  638. if( !this.selector.isExcluded( subData ) ) {
  639. var category = this.selector._newItem(subData, this.selector, this.children, this.level+1, this);
  640. if(this.subItems)this.subItems.push( category );
  641. this.subCategorys.push( category );
  642. }
  643. //var category = this.selector._newItemCategory("ItemCategory", subData, this.selector, this.children, this.level+1);
  644. }.bind(this));
  645. this.loaded = true;
  646. if (callback) callback();
  647. }.bind(this), null, this.data.distinguishedName);
  648. }else{
  649. if (callback) callback();
  650. }
  651. },
  652. _hasChild: function(){
  653. var uCount = (this.data.subDirectUnitCount) ? this.data.subDirectUnitCount : 0;
  654. //var iCount = (this.data.subDirectIdentityCount) ? this.data.subDirectIdentityCount : 0;
  655. return uCount;
  656. },
  657. _hasChildCategory: function(){
  658. var uCount = (this.data.subDirectUnitCount) ? this.data.subDirectUnitCount : 0;
  659. return uCount;
  660. },
  661. _hasChildItem: function(){
  662. var uCount = (this.data.subDirectUnitCount) ? this.data.subDirectUnitCount : 0;
  663. return uCount;
  664. },
  665. //for flat category start
  666. loadCategoryChildren: function(callback){
  667. if (!this.categoryLoaded){
  668. this.selector.orgAction.listSubUnitDirect(function(subJson){
  669. subJson.data.each(function(subData){
  670. if( !this.selector.isExcluded( subData ) ) {
  671. var category = this.selector._newItem(subData, this.selector, this.children, this.level+1, this, true);
  672. category.ignoreItem = true;
  673. category.load();
  674. //if(this.subItems)this.subItems.push( category );
  675. this.subCategorys.push( category );
  676. }
  677. //var category = this.selector._newItemCategory("ItemCategory", subData, this.selector, this.children, this.level+1);
  678. }.bind(this));
  679. this.categoryLoaded = true;
  680. if (callback) callback();
  681. }.bind(this), null, this.data.distinguishedName);
  682. }else{
  683. if (callback) callback( );
  684. }
  685. },
  686. loadItemChildren: function(callback){
  687. if (!this.itemLoaded){
  688. this.selector.orgAction.listSubUnitDirect(function(subJson){
  689. subJson.data.each(function(subData){
  690. if( !this.selector.isExcluded( subData ) ) {
  691. var category = this.selector._newItem(subData, this.selector, this.children, this.level+1, this, true);
  692. category.justItem = true;
  693. category.load();
  694. if(this.subItems)this.subItems.push( category );
  695. //this.subCategorys.push( category );
  696. }
  697. //var category = this.selector._newItemCategory("ItemCategory", subData, this.selector, this.children, this.level+1);
  698. }.bind(this));
  699. this.itemLoaded = true;
  700. if (callback) callback();
  701. }.bind(this), null, this.data.distinguishedName);
  702. }else{
  703. if (callback) callback( );
  704. }
  705. }
  706. });
  707. MWF.xApplication.Selector.Unit.Filter = new Class({
  708. Implements: [Options, Events],
  709. options: {
  710. "style": "default",
  711. "units": []
  712. },
  713. initialize: function(value, options){
  714. this.setOptions(options);
  715. this.value = value;
  716. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  717. },
  718. filter: function(value, callback){
  719. this.value = value;
  720. var key = this.value;
  721. if (this.options.units.length){
  722. var units = [];
  723. this.options.units.each(function(u){
  724. if (typeOf(u)==="string"){
  725. units.push(u);
  726. }
  727. if (typeOf(u)==="object"){
  728. units.push(u.distinguishedName);
  729. }
  730. });
  731. key = {"key": key, "unitList": units};
  732. }
  733. this.orgAction.listUnitByKey(function(json){
  734. data = json.data;
  735. if (callback) callback(data)
  736. }.bind(this), null, key);
  737. }
  738. });