Unit.js 40 KB

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