Unit.js 39 KB

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