IdentityWidthDutyCategoryByUnit.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. MWF.xApplication.Selector = MWF.xApplication.Selector || {};
  2. MWF.xDesktop.requireApp("Selector", "IdentityWidthDuty", null, false);
  3. MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit = new Class({
  4. Extends: MWF.xApplication.Selector.IdentityWidthDuty,
  5. options: {
  6. "style": "default",
  7. "count": 0,
  8. "title": MWF.xApplication.Selector.LP.selectIdentity,
  9. "dutys": [],
  10. "units": [],
  11. "values": [],
  12. "zIndex": 1000,
  13. "expand": false,
  14. "noUnit" : false,
  15. "include" : [], //增加的可选项
  16. "resultType" : "", //可以设置成个人,那么结果返回个人
  17. "expandSubEnable": true,
  18. "selectAllEnable" : true, //分类是否允许全选下一层
  19. "exclude" : [],
  20. "dutyUnitLevelBy" : "duty", //组织层级是按身份所在群组还是职务,
  21. "selectType" : "identity"
  22. },
  23. loadSelectItems: function(addToNext){
  24. //根据组织分类展现职务
  25. if( this.options.resultType === "person" ){
  26. if( this.titleTextNode ){
  27. this.titleTextNode.set("text", MWF.xApplication.Selector.LP.selectPerson );
  28. }else{
  29. this.options.title = MWF.xApplication.Selector.LP.selectPerson;
  30. }
  31. }
  32. if (this.options.dutys.length){
  33. this.loadInclude( function () {
  34. this.includeLoaded = true;
  35. if( this.dutyLoaded ){
  36. this.afterLoadSelectItem();
  37. }
  38. }.bind(this));
  39. if( this.options.units.length ){
  40. var units = [];
  41. for( var i=0 ;i<this.options.units.length; i++ ){
  42. var unit = this.options.units[i];
  43. if( typeOf( unit ) === "string" ){
  44. units.push( unit )
  45. }else{
  46. units.push( unit.distinguishedName || unit.unique || unit.id || unit.levelName )
  47. }
  48. }
  49. this.unitStringList = units;
  50. var getAllIdentity = function( unitList ){
  51. o2.Actions.load("x_organization_assemble_express").UnitDutyAction.listIdentityWithUnitWithNameObject({
  52. nameList : this.options.dutys,
  53. unitList : unitList
  54. }, function( json ){
  55. this._loadSelectItems( json.data )
  56. }.bind(this))
  57. }.bind(this);
  58. if( this.options.expandSubEnable ){
  59. o2.Actions.load("x_organization_assemble_express").UnitAction.listWithUnitSubNested({
  60. unitList : units
  61. }, function( json ){
  62. getAllIdentity( units.combine( json.data ? json.data.unitList : [] ));
  63. }.bind(this))
  64. }else{
  65. getAllIdentity( units );
  66. }
  67. }else{
  68. var identityList = [];
  69. var count = 0;
  70. this.options.dutys.each( function( d ){
  71. this.orgAction.listIdentityWithDuty(function(json){
  72. count++;
  73. identityList = identityList.combine( json.data );
  74. if( this.options.dutys.length === count )this._loadSelectItems( identityList );
  75. }.bind(this), function(){
  76. count++;
  77. if( this.options.dutys.length === count )this._loadSelectItems( identityList );
  78. }.bind(this), d );
  79. }.bind(this));
  80. }
  81. //this.options.dutys.each(function(duty){
  82. // var data = {"name": duty, "id":duty};
  83. // var category = this._newItemCategory("ItemCategory",data, this, this.itemAreaNode);
  84. // this.subCategorys.push(category);
  85. //}.bind(this));
  86. }
  87. },
  88. _loadSelectItems : function( identityList ){
  89. //this.listAllIdentityInUnitObject( identityList );
  90. var unitTree = this.listNestedUnitByIdentity( identityList );
  91. if( this.options.dutyUnitLevelBy === "duty" ){
  92. this.level1Container = [];
  93. if( this.options.units && this.options.units.length ){
  94. var div = new Element( "div" ).inject(this.itemAreaNode);
  95. this.level1Container.push(div);
  96. }
  97. this._loadSelectItemsByDutyUnit(unitTree);
  98. }else{
  99. this._loadSelectItemsByIdentityUnit(unitTree);
  100. }
  101. this.dutyLoaded = true;
  102. if( this.includeLoaded ){
  103. this.afterLoadSelectItem();
  104. }
  105. },
  106. _loadSelectItemsByIdentityUnit : function( unitTree ){
  107. if( !unitTree.unitList )return;
  108. this.sortUnit( unitTree.unitList );
  109. for( var i=0; i< unitTree.unitList.length; i++ ){
  110. var unit = unitTree.unitList[i];
  111. if( !this.isExcluded( unit ) ) {
  112. var category = this._newItemCategory("ItemCategory",unit, this, this.itemAreaNode);
  113. this.subCategorys.push(category);
  114. }
  115. }
  116. },
  117. sortUnit : function( unitList ){
  118. if( this.options.dutyUnitLevelBy === "duty" ){
  119. if( this.options.units ){
  120. unitList.sort( function(a, b){
  121. var idxA = this.getIndexFromUnitOption( a );
  122. var idxB = this.getIndexFromUnitOption( b );
  123. idxA = idxA === -1 ? 9999999 + (a.orderNumber || 9999999) : idxA;
  124. idxB = idxB === -1 ? 9999999 + (b.orderNumber || 9999999) : idxB;
  125. return idxA - idxB;
  126. }.bind(this))
  127. }else{
  128. unitList.sort( function(a, b){
  129. return (a.orderNumber || 9999999) - (b.orderNumber || 9999999);
  130. }.bind(this))
  131. }
  132. }else{
  133. unitList.sort( function(a, b){
  134. return (a.orderNumber || 9999999) - (b.orderNumber || 9999999);
  135. }.bind(this))
  136. }
  137. },
  138. _loadSelectItemsByDutyUnit : function( unitTree ){
  139. if( !unitTree.unitList )return;
  140. // this.sortUnit( unitTree.unitList );
  141. for( var i=0; i< unitTree.unitList.length; i++ ){
  142. var unit = unitTree.unitList[i];
  143. if( this.isUnitContain( unit ) ){
  144. if( !this.isExcluded( unit ) ) {
  145. var container = this.itemAreaNode;
  146. if( this.level1Container && this.level1Container.length ){
  147. var index = this.getIndexFromUnitOption( unit );
  148. if( index > -1 && (this.level1Container.length > index) && this.level1Container[i] )container = this.level1Container[i];
  149. }
  150. var category = this._newItemCategory("ItemCategory",unit, this, container );
  151. this.subCategorys.push(category);
  152. }
  153. }else{
  154. this._loadSelectItemsByDutyUnit( unit );
  155. }
  156. }
  157. },
  158. getIndexFromUnitOption : function( unit ){
  159. if( !this.unitStringList || !this.unitStringList.length )return -1;
  160. var idx = -1;
  161. if(idx == -1 && unit.distinguishedName)idx = this.unitStringList.indexOf( unit.distinguishedName );
  162. if(idx == -1 && unit.id)idx = this.unitStringList.indexOf( unit.id );
  163. if(idx == -1 && unit.unique)idx = this.unitStringList.indexOf( unit.unique );
  164. if(idx == -1 && unit.levelName)idx = this.unitStringList.indexOf( unit.levelName );
  165. return idx
  166. },
  167. isUnitContain : function( d ){
  168. if( this.options.units.length === 0 )return true;
  169. if( !this.unitFlagMap ){
  170. this.unitFlagMap = {};
  171. this.options.units.each( function( e ){
  172. if( !e )return;
  173. this.unitFlagMap[ typeOf( e ) === "string" ? e : ( e.distinguishedName || e.id || e.unique || e.employee || e.levelName) ] = true;
  174. }.bind(this));
  175. }
  176. var map = this.unitFlagMap;
  177. return ( d.distinguishedName && map[ d.distinguishedName ] ) ||
  178. ( d.levelName && map[ d.levelName ] ) ||
  179. ( d.id && map[ d.id ] ) ||
  180. ( d.unique && map[ d.unique ] );
  181. },
  182. listAllIdentityInUnitObject : function(){
  183. var unitArray = [];
  184. for( var i=0; i<identityList.length; i++ ){
  185. unitArray.push( identityList[i].unit || identityList[i].unitLevelName );
  186. }
  187. o2.Actions.load("x_organization_assemble_express").UnitAction.listObject({
  188. unitList : unitArray
  189. }, function(json){
  190. this.allIdentityInUnitObject = {};
  191. json.data.each( function( u ){
  192. this.allIdentityInUnitObject[u.levelName] = u;
  193. }.bind(this));
  194. if(callback)callback();
  195. }.bind(this), null, false)
  196. },
  197. getUnitOrderNumber : function( unit ){
  198. return this.allIdentityInUnitObject[unit.levelName].orderNumber;
  199. },
  200. listAllUnitObject: function( identityList, callback ){
  201. var key = this.options.dutyUnitLevelBy === "duty" ? "matchUnitLevelName" : "unitLevelName";
  202. var unitArray = [];
  203. for( var i=0; i<identityList.length; i++ ){
  204. var levelNames = identityList[i][key];
  205. //if( !levelNames && key === "matchUnitLevelName" )levelNames = identityList[i].unitLevelName;
  206. var unitLevelNameList = levelNames.split("/");
  207. var nameList = [];
  208. for( var j=0; j<unitLevelNameList.length; j++ ){
  209. nameList.push( unitLevelNameList[j] );
  210. var name = nameList.join("/");
  211. if( !unitArray.contains( name ) ){
  212. unitArray.push( name );
  213. }
  214. }
  215. }
  216. o2.Actions.load("x_organization_assemble_express").UnitAction.listObject({
  217. unitList : unitArray
  218. }, function(json){
  219. this.allUnitObject = {};
  220. json.data.each( function( u ){
  221. this.allUnitObject[u.levelName] = u;
  222. }.bind(this));
  223. if(callback)callback();
  224. }.bind(this), null, false)
  225. },
  226. listNestedUnitByIdentity : function( identityList ){
  227. this.listAllUnitObject( identityList);
  228. return this._listNestedUnitByIdentity( identityList );
  229. },
  230. _listNestedUnitByIdentity : function( identityList ){
  231. debugger;
  232. //identityList = Array.unique(identityList);
  233. var key = this.options.dutyUnitLevelBy === "duty" ? "matchUnitLevelName" : "unitLevelName";
  234. //根据unitLevelName整合成组织树
  235. var unitTree = {};
  236. for( var i=0; i<identityList.length; i++ ){
  237. var levelNames = identityList[i][key];
  238. //if( !levelNames && key === "matchUnitLevelName" )levelNames = identityList[i].unitLevelName;
  239. var unitLevelNameList = levelNames.split("/");
  240. var nameList = [];
  241. var tree = unitTree;
  242. for( var j=0; j<unitLevelNameList.length; j++ ){
  243. nameList.push( unitLevelNameList[j] );
  244. var name = nameList.join("/");
  245. if( !tree.unitList )tree.unitList = [];
  246. var found = false;
  247. for( var k=0; k<tree.unitList.length; k++ ){
  248. if( tree.unitList[k].levelName == name ){
  249. tree = tree.unitList[k];
  250. found = true;
  251. break;
  252. }
  253. }
  254. if( !found ){
  255. var obj = {};
  256. tree.unitList.push( obj );
  257. tree = obj;
  258. }
  259. if( !tree.distinguishedName ){
  260. tree = Object.merge( tree, this.allUnitObject[name] );
  261. }
  262. if( !tree.identityList )tree.identityList = [];
  263. }
  264. tree.identityList.push( identityList[i] );
  265. }
  266. return unitTree;
  267. },
  268. //listNestedUnitByIdentity : function( identityList ){
  269. // debugger;
  270. // this.unitArray = [];
  271. // var key = this.options.dutyUnitLevelBy === "duty" ? "matchUnitLevelName" : "unitLevelName";
  272. // //根据unitLevelName整合成组织树
  273. // var unitTree = {};
  274. // for( var i=0; i<identityList.length; i++ ){
  275. // var levelNames = identityList[i][key];
  276. // //if( !levelNames && key === "matchUnitLevelName" )levelNames = identityList[i].unitLevelName;
  277. // var unitLevelNameList = levelNames.split("/");
  278. // var nameList = [];
  279. // var tree = unitTree;
  280. // for( var j=0; j<unitLevelNameList.length; j++ ){
  281. // nameList.push( unitLevelNameList[j] );
  282. // var name = nameList.join("/");
  283. // if( !tree[ name ] ){
  284. // tree[ name ] = {
  285. // name : unitLevelNameList[j],
  286. // levelName : name,
  287. // identityList : []
  288. // };
  289. // this.unitArray.push( name );
  290. // }
  291. // tree = tree[name];
  292. // }
  293. // tree.identityList.push( identityList[i] );
  294. // }
  295. // return unitTree;
  296. //},
  297. _scrollEvent: function(y){
  298. return true;
  299. },
  300. _getChildrenItemIds: function(){
  301. return null;
  302. },
  303. _newItemCategory: function(type, data, selector, item, level, category, delay){
  304. return new MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit[type](data, selector, item, level, category, delay)
  305. },
  306. _listItemByKey: function(callback, failure, key){
  307. if (this.options.units.length) key = {"key": key, "unitList": this.options.units};
  308. this.orgAction.listIdentityByKey(function(json){
  309. if (callback) callback.apply(this, [json]);
  310. }.bind(this), failure, key);
  311. },
  312. _getItem: function(callback, failure, id, async){
  313. if( typeOf(id) === "string" ){
  314. this.orgAction.getIdentity(function(json){
  315. if (callback) callback.apply(this, [json]);
  316. }.bind(this), failure, ((typeOf(id)==="string") ? id : id.distinguishedName), async);
  317. }else{
  318. if (callback) callback.apply(this, [id]);
  319. }
  320. //this.orgAction.getIdentity(function(json){
  321. // if (callback) callback.apply(this, [json]);
  322. //}.bind(this), failure, ((typeOf(id)==="string") ? id : id.distinguishedName), async);
  323. },
  324. _newItemSelected: function(data, selector, item, selectedNode){
  325. return new MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.ItemSelected(data, selector, item, selectedNode)
  326. },
  327. _listItemByPinyin: function(callback, failure, key){
  328. if (this.options.units.length) key = {"key": key, "unitList": this.options.units};
  329. this.orgAction.listIdentityByPinyin(function(json){
  330. if (callback) callback.apply(this, [json]);
  331. }.bind(this), failure, key);
  332. },
  333. _newItem: function(data, selector, container, level, category){
  334. return new MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.Item(data, selector, container, level, category);
  335. },
  336. _newItemSearch: function(data, selector, container, level){
  337. return new MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.SearchItem(data, selector, container, level);
  338. }
  339. //_listItemNext: function(last, count, callback){
  340. // this.action.listRoleNext(last, count, function(json){
  341. // if (callback) callback.apply(this, [json]);
  342. // }.bind(this));
  343. //}
  344. });
  345. MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.Item = new Class({
  346. Extends: MWF.xApplication.Selector.IdentityWidthDuty.Item
  347. });
  348. MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.SearchItem = new Class({
  349. Extends: MWF.xApplication.Selector.IdentityWidthDuty.SearchItem
  350. });
  351. MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.ItemSelected = new Class({
  352. Extends: MWF.xApplication.Selector.IdentityWidthDuty.ItemSelected
  353. });
  354. MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.ItemCategory = new Class({
  355. Extends: MWF.xApplication.Selector.IdentityWidthDuty.ItemCategory,
  356. isExisted : function( d ){
  357. if( !d )return true;
  358. if( !this.createdItemObject )this.createdItemObject = {};
  359. var map = this.createdItemObject;
  360. if(( d.distinguishedName && map[ d.distinguishedName ] ) ||
  361. ( d.levelName && map[ d.levelName ] ) ||
  362. ( d.id && map[ d.id ] ) ||
  363. ( d.unique && map[ d.unique ] )){
  364. return true;
  365. }else{
  366. //if( typeOf( d ) === "string" ){
  367. // this.createdItemObject[ d ] = true;
  368. //}else{
  369. // if( d.distinguishedName )this.createdItemObject[ d.distinguishedName ] = true;
  370. // if( d.id )this.createdItemObject[ d.id ] = true;
  371. // if( d.unique )this.createdItemObject[ d.unique ] = true;
  372. // if( d.employee )this.createdItemObject[ d.employee ] = true;
  373. // if( d.levelName )this.createdItemObject[ d.levelName ] = true;
  374. //}
  375. this.createdItemObject[ typeOf( d ) === "string" ? d : ( d.distinguishedName || d.id || d.unique || d.employee || d.levelName) ] = true;
  376. return false;
  377. }
  378. },
  379. loadSub: function(callback){
  380. if (!this.loaded){
  381. if( this.data.identityList && this.data.identityList.length>0 ){
  382. debugger;
  383. this.data.identityList.sort( function(a, b){
  384. //this.selector.getUnitOrderNumber( a.unitLevelName )
  385. return (a.orderNumber || 9999999) - (b.orderNumber || 9999999);
  386. });
  387. this.data.identityList.each( function( identity ){
  388. if( !this.selector.isExcluded( identity ) ) {
  389. if( !this.isExisted( identity ) ){
  390. var item = this.selector._newItem(identity, this.selector, this.children, this.level + 1, this);
  391. this.selector.items.push(item);
  392. if(this.subItems)this.subItems.push( item );
  393. }
  394. }
  395. }.bind(this))
  396. }
  397. if( this.data.unitList && this.data.unitList.length ){
  398. this.data.unitList.sort( function(a, b){
  399. return (a.orderNumber || 9999999) - (b.orderNumber || 9999999);
  400. });
  401. this.data.unitList.each( function( subData ){
  402. if( !this.selector.isExcluded( subData ) ) {
  403. var category = this.selector._newItemCategory("ItemCategory", subData, this.selector, this.children, this.level + 1, this);
  404. this.subCategorys.push( category );
  405. category.loadSub()
  406. }
  407. }.bind(this));
  408. }
  409. this.loaded = true;
  410. if (callback) callback( );
  411. }else{
  412. if (callback) callback( );
  413. }
  414. },
  415. loadCategoryChildren: function(callback){
  416. if (!this.categoryLoaded){
  417. //if( this.data.unitList && this.data.unitList.length ){
  418. // this.data.unitList.sort( function(a, b){
  419. // return (a.orderNumber || 9999999) - (b.orderNumber || 9999999);
  420. // });
  421. // this.data.unitList.each( function( subData ){
  422. // if( !this.selector.isExcluded( subData ) ) {
  423. // var category = this.selector._newItemCategory("ItemCategory", subData, this.selector, this.children, this.level + 1, this);
  424. // this.subCategorys.push( category );
  425. // category.loadCategoryChildren()
  426. // }
  427. // }.bind(this));
  428. //}
  429. this.loadSub();
  430. this.categoryLoaded = true;
  431. this.itemLoaded = true;
  432. if (callback) callback( );
  433. }else{
  434. if (callback) callback( );
  435. }
  436. },
  437. loadItemChildren: function(callback){
  438. if (!this.itemLoaded){
  439. if( this.data.identityList && this.data.identityList.length>0 ){
  440. this.data.identityList.sort( function(a, b){
  441. //this.selector.getUnitOrderNumber( a.unitLevelName )
  442. return (a.orderNumber || 9999999) - (b.orderNumber || 9999999);
  443. });
  444. this.data.identityList.each( function( identity ){
  445. if( !this.selector.isExcluded( identity ) ) {
  446. if( !this.isExisted( identity ) ){
  447. var item = this.selector._newItem(identity, this.selector, this.children, this.level + 1, this);
  448. this.selector.items.push(item);
  449. if(this.subItems)this.subItems.push( item );
  450. }
  451. }
  452. }.bind(this))
  453. }
  454. this.itemLoaded = true;
  455. if (callback) callback( );
  456. }else{
  457. if (callback) callback( );
  458. }
  459. },
  460. _hasChild: function(){
  461. return (this.data.unitList && this.data.unitList.length > 0) ||
  462. (this.data.identityList && this.data.identityList.length > 0);
  463. },
  464. _hasChildCategory : function(){
  465. return (this.data.unitList && this.data.unitList.length > 0);
  466. },
  467. _hasChildItem: function(){
  468. return this.data.identityList && this.data.identityList.length > 0;
  469. }
  470. });
  471. MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.ItemUnitCategory = new Class({
  472. Extends: MWF.xApplication.Selector.IdentityWidthDuty.ItemUnitCategory
  473. });
  474. MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.ItemGroupCategory = new Class({
  475. Extends: MWF.xApplication.Selector.IdentityWidthDuty.ItemGroupCategory
  476. });
  477. MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.Filter = new Class({
  478. Extends: MWF.xApplication.Selector.IdentityWidthDuty.Filter
  479. });