Unit.js 34 KB

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