Unit.js 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909
  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){
  482. if (!this.children){
  483. this.children = new Element("div", {
  484. "styles": this.selector.css.selectorItemCategoryChildrenNode
  485. }).inject(this.node, "after");
  486. }
  487. this.children.setStyle("display", "block");
  488. // if (!this.selector.options.expand) this.children.setStyle("display", "none");
  489. this.selector.orgAction.listSubUnitDirect(function(subJson){
  490. subJson.data.each(function(subData){
  491. if( !this.selector.isExcluded( subData ) ) {
  492. var category = this.selector._newItem(subData, this.selector, this.children, this.level + 1, this);
  493. this.selector.items.push( category );
  494. if( !this.subItems )this.subItems = [];
  495. this.subItems.push( category );
  496. }
  497. }.bind(this));
  498. this.loaded = true;
  499. if(callback)callback();
  500. }.bind(this), null, this.data.distinguishedName);
  501. }else{
  502. this.children.setStyle("display", "block");
  503. }
  504. },
  505. getData: function(callback){
  506. if (callback) callback();
  507. },
  508. postLoad : function(){
  509. if( this.selector.options.style === "blue_flat" ) {
  510. if (this.level === 1) {
  511. var indent = 26;
  512. this.levelNode.setStyle("width", "" + indent + "px");
  513. } else {
  514. var indent = 26 + ( this.level - 1 ) * this.selector.options.indent;
  515. this.levelNode.setStyle("width", "" + indent + "px");
  516. }
  517. }
  518. //}else if( this.selector.options.style === "blue_flat_mobile" ){
  519. // if( this.level === 1 ){
  520. // var indent = 40;
  521. // this.levelNode.setStyle("width", ""+indent+"px");
  522. // }else{
  523. // var indent = 40 + ( this.level -1 ) * this.selector.options.indent ;
  524. // this.levelNode.setStyle("width", ""+indent+"px");
  525. // }
  526. //}
  527. },
  528. loadCategoryForFlatCategory : function(){
  529. this.selector.fireEvent("queryLoadCategory",[this]);
  530. if( !this.flatCategoryItemNode ){
  531. this.flatCategoryItemNode = new Element("div.flatCategoryItemNode", {
  532. "styles": this.selector.css.flatCategoryItemNode,
  533. "title" : this._getTtiteText()
  534. });
  535. this.flatCategoryItemNode.store( "category", this );
  536. this.flatCategoryItemNode.store( "dn", this.data.distinguishedName );
  537. this.flatCategoryItemTextNode = new Element("div", {
  538. "styles": this.selector.css.flatCategoryItemTextNode,
  539. "text": this._getShowName(),
  540. "title": this._getTtiteText()
  541. }).inject(this.flatCategoryItemNode);
  542. }
  543. this.children = new Element("div", {
  544. "styles": this.selector.css.selectorItemCategoryChildrenNode
  545. }).inject(this.selector.itemAreaNode);
  546. this.children.setStyle("display", "none");
  547. if( this.level === 1 ){
  548. this.loadForNormal(true, this.children);
  549. }
  550. if( !this.selectAllNode && this.selector.options.count.toInt() !== 1 ){
  551. var selectAllWrap = new Element("div",{
  552. styles : this.selector.css.flatCategory_selectAllWrap
  553. }).inject(this.children);
  554. this.selectAllNode = new Element("div", {
  555. "styles": this.selector.css.flatCategory_selectAll,
  556. "text" : "全选"
  557. }).inject(selectAllWrap);
  558. this.selectAllNode.addEvent( "click", function(ev){
  559. if( this.isSelectedAll ){
  560. this.unselectAll(ev);
  561. this.selector.fireEvent("unselectCatgory",[this])
  562. }else{
  563. this.selectAll(ev);
  564. this.selector.fireEvent("selectCatgory",[this])
  565. }
  566. ev.stopPropagation();
  567. }.bind(this));
  568. }
  569. //this.loadForNormal(true, this.children);
  570. this.flatCategoryItemNode.addEvents({
  571. //"mouseover": function(){
  572. // if (!this.isSelected )this.node.setStyles(this.selector.css.flatCategoryItemNode_over );
  573. //}.bind(this),
  574. //"mouseout": function(){
  575. // if (!this.isSelected )this.node.setStyles(this.selector.css.flatCategoryItemNode );
  576. //}.bind(this),
  577. "click": function(){
  578. if( this.selector.currentFlatCategory === this )return;
  579. if( this.selector.currentFlatCategory ){
  580. this.selector.currentFlatCategory.clickFlatCategoryItem(null, true); //取消原来选择的
  581. }
  582. this.selector.currentFlatCategory = this;
  583. this.clickFlatCategoryItem();
  584. }.bind(this)
  585. });
  586. //this.setEvent();
  587. var isCreateSubCategoryListNode = this.data.subDirectUnitCount ? this.data.subDirectUnitCount : true;
  588. var nodeContainer;
  589. if( this.nodeContainer ){
  590. nodeContainer = this.nodeContainer;
  591. }else{
  592. nodeContainer = (this.category && this.category.subCategoryListNode) ? this.category.subCategoryListNode : null;
  593. }
  594. this.subCategoryListNode = this.selector.addFlatCategoryItem( this.flatCategoryItemNode, this.data.subDirectUnitCount, nodeContainer, isCreateSubCategoryListNode );
  595. //this.check();
  596. if( this.loadCategoryChildren )this.loadCategoryChildren();
  597. //if(this.postLoad)this.postLoad();
  598. //this.setEvent();
  599. //this.check();
  600. this.selector.fireEvent("postLoadCategory",[this]);
  601. },
  602. clickFlatCategoryItem : function( callback, hidden ){
  603. //if (this._hasChildItem()){
  604. var firstLoaded = !this.itemLoaded;
  605. this.loadItemChildren(function(){
  606. if( hidden ){
  607. this.children.setStyles({ "display": "none" });
  608. this.flatCategoryItemNode.setStyles(this.selector.css.flatCategoryItemNode);
  609. this.isExpand = false;
  610. }else if( firstLoaded ){
  611. this.children.setStyles({"display": "block"});
  612. this.flatCategoryItemNode.setStyles( this.selector.css.flatCategoryItemNode_selected );
  613. this.isExpand = true;
  614. }else {
  615. var display = this.children.getStyle("display");
  616. if (display === "none") {
  617. this.children.setStyles({ "display": "block" });
  618. this.flatCategoryItemNode.setStyles(this.selector.css.flatCategoryItemNode_selected);
  619. this.isExpand = true;
  620. } else {
  621. this.children.setStyles({ "display": "none" });
  622. this.flatCategoryItemNode.setStyles(this.selector.css.flatCategoryItemNode);
  623. this.isExpand = false;
  624. }
  625. }
  626. if(callback)callback()
  627. }.bind(this));
  628. //}
  629. },
  630. loadCategoryChildren : function( callback ){
  631. if (!this.categoryLoaded){
  632. this.selector.orgAction.listSubUnitDirect(function(subJson){
  633. subJson.data.each(function(subData){
  634. if( !this.selector.isExcluded( subData ) ) {
  635. if( subData.subDirectUnitCount ){
  636. var category = this.selector._newItem(subData, this.selector, this.children, this.level + 1, this);
  637. //if( !this.subItems )this.subItems = [];
  638. //this.subItems.push( category );
  639. }
  640. }
  641. }.bind(this));
  642. this.categoryLoaded = true;
  643. if(callback)callback();
  644. }.bind(this), null, this.data.distinguishedName);
  645. }else{
  646. if(callback)callback();
  647. }
  648. },
  649. loadItemChildren : function( callback ){
  650. if (!this.itemLoaded){
  651. this.selector.orgAction.listSubUnitDirect(function(subJson){
  652. subJson.data.each(function(subData){
  653. if( !this.selector.isExcluded( subData ) ) {
  654. //if( !subData.subDirectUnitCount ){
  655. var category = this.selector._newItem(subData, this.selector, this.children, this.level + 1, this, true);
  656. category.justItem = true;
  657. category.load();
  658. this.selector.items.push( category );
  659. if( !this.subItems )this.subItems = [];
  660. this.subItems.push( category );
  661. //}
  662. }
  663. }.bind(this));
  664. this.itemLoaded = true;
  665. if(callback)callback();
  666. }.bind(this), null, this.data.distinguishedName);
  667. }else{
  668. if(callback)callback();
  669. }
  670. },
  671. _hasChild : function () {
  672. return this.data.subDirectUnitCount;
  673. }
  674. });
  675. MWF.xApplication.Selector.Unit.SearchItem = new Class({
  676. Extends: MWF.xApplication.Selector.Unit.Item,
  677. load : function(){
  678. this.loadForNormal();
  679. },
  680. _getShowName: function(){
  681. return this.data.levelName || this.data.name;
  682. },
  683. loadSubItems: function( callback ){
  684. //只是为了在isFlatCategory模式下,加载全称用的,否则用继承的就可以
  685. if (!this.loaded){
  686. if (!this.children){
  687. this.children = new Element("div", {
  688. "styles": this.selector.css.selectorItemCategoryChildrenNode
  689. }).inject(this.node, "after");
  690. }
  691. this.children.setStyle("display", "block");
  692. // if (!this.selector.options.expand) this.children.setStyle("display", "none");
  693. this.selector.orgAction.listSubUnitDirect(function(subJson){
  694. subJson.data.each(function(subData){
  695. if( !this.selector.isExcluded( subData ) ) {
  696. var category;
  697. if( this.selector.isFlatCategory ){
  698. category = this.selector._newItem(subData, this.selector, this.children, this.level + 1, this, true);
  699. category.isShowLevelName = true;
  700. category.load();
  701. }else{
  702. category = this.selector._newItem(subData, this.selector, this.children, this.level + 1, this);
  703. }
  704. this.selector.items.push( category );
  705. if( !this.subItems )this.subItems = [];
  706. this.subItems.push( category );
  707. }
  708. }.bind(this));
  709. this.loaded = true;
  710. if(callback)callback();
  711. }.bind(this), null, this.data.distinguishedName);
  712. }else{
  713. this.children.setStyle("display", "block");
  714. }
  715. }
  716. });
  717. MWF.xApplication.Selector.Unit.ItemSelected = new Class({
  718. Extends: MWF.xApplication.Selector.Identity.ItemSelected,
  719. getData: function(callback){
  720. if (callback) callback();
  721. },
  722. _getTtiteText: function(){
  723. return this.data.levelName || this.data.name;
  724. },
  725. _getShowName: function(){
  726. return this.data.name+((this.data.levelName) ? "("+this.data.levelName+")" : "");
  727. },
  728. _setIcon: function(){
  729. var style = this.selector.options.style;
  730. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/departmenticon.png)");
  731. }
  732. });
  733. MWF.xApplication.Selector.Unit.ItemCategory = new Class({
  734. Extends: MWF.xApplication.Selector.Identity.ItemCategory,
  735. loadSub: function(callback){
  736. if (!this.loaded){
  737. this.selector.orgAction.listSubUnitDirect(function(subJson){
  738. subJson.data.each(function(subData){
  739. if( !this.selector.isExcluded( subData ) ) {
  740. var category = this.selector._newItem(subData, this.selector, this.children, this.level+1, this);
  741. this.selector.items.push( category );
  742. if(this.subItems)this.subItems.push( category );
  743. this.subCategorys.push( category );
  744. }
  745. //var category = this.selector._newItemCategory("ItemCategory", subData, this.selector, this.children, this.level+1);
  746. }.bind(this));
  747. this.loaded = true;
  748. if (callback) callback();
  749. }.bind(this), null, this.data.distinguishedName);
  750. }else{
  751. if (callback) callback();
  752. }
  753. },
  754. _hasChild: function(){
  755. var uCount = (this.data.subDirectUnitCount) ? this.data.subDirectUnitCount : 0;
  756. //var iCount = (this.data.subDirectIdentityCount) ? this.data.subDirectIdentityCount : 0;
  757. return uCount;
  758. },
  759. _hasChildCategory: function(){
  760. var uCount = (this.data.subDirectUnitCount) ? this.data.subDirectUnitCount : 0;
  761. return uCount;
  762. },
  763. _hasChildItem: function(){
  764. var uCount = (this.data.subDirectUnitCount) ? this.data.subDirectUnitCount : 0;
  765. return uCount;
  766. },
  767. //for flat category start
  768. loadCategoryChildren: function(callback){
  769. if (!this.categoryLoaded){
  770. this.selector.orgAction.listSubUnitDirect(function(subJson){
  771. subJson.data.each(function(subData){
  772. if( !this.selector.isExcluded( subData ) ) {
  773. var category = this.selector._newItem(subData, this.selector, this.children, this.level+1, this, true);
  774. category.ignoreItem = true;
  775. category.load();
  776. //if(this.subItems)this.subItems.push( category );
  777. this.subCategorys.push( category );
  778. }
  779. //var category = this.selector._newItemCategory("ItemCategory", subData, this.selector, this.children, this.level+1);
  780. }.bind(this));
  781. this.categoryLoaded = true;
  782. if (callback) callback();
  783. }.bind(this), null, this.data.distinguishedName);
  784. }else{
  785. if (callback) callback( );
  786. }
  787. },
  788. loadItemChildren: function(callback){
  789. if (!this.itemLoaded){
  790. this.selector.orgAction.listSubUnitDirect(function(subJson){
  791. subJson.data.each(function(subData){
  792. if( !this.selector.isExcluded( subData ) ) {
  793. var category = this.selector._newItem(subData, this.selector, this.children, this.level+1, this, true);
  794. category.justItem = true;
  795. category.load();
  796. this.selector.items.push( category );
  797. if(this.subItems)this.subItems.push( category );
  798. //this.subCategorys.push( category );
  799. }
  800. //var category = this.selector._newItemCategory("ItemCategory", subData, this.selector, this.children, this.level+1);
  801. }.bind(this));
  802. this.itemLoaded = true;
  803. if (callback) callback();
  804. }.bind(this), null, this.data.distinguishedName);
  805. }else{
  806. if (callback) callback( );
  807. }
  808. }
  809. });
  810. MWF.xApplication.Selector.Unit.Filter = new Class({
  811. Implements: [Options, Events],
  812. options: {
  813. "style": "default",
  814. "units": []
  815. },
  816. initialize: function(value, options){
  817. this.setOptions(options);
  818. this.value = value;
  819. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  820. },
  821. filter: function(value, callback){
  822. this.value = value;
  823. var key = this.value;
  824. if (this.options.units.length){
  825. var units = [];
  826. this.options.units.each(function(u){
  827. if (typeOf(u)==="string"){
  828. units.push(u);
  829. }
  830. if (typeOf(u)==="object"){
  831. units.push(u.distinguishedName);
  832. }
  833. });
  834. key = {"key": key, "unitList": units};
  835. }
  836. this.orgAction.listUnitByKey(function(json){
  837. data = json.data;
  838. if (callback) callback(data)
  839. }.bind(this), null, key);
  840. }
  841. });