Unit.js 40 KB

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