Unit.js 40 KB

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