Unit.js 37 KB

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