Unit.js 34 KB

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