Unit.js 38 KB

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