Unit.js 40 KB

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