Unit.js 35 KB

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