Unit.js 40 KB

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