IdentityWidthDutyCategoryByUnit.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  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. this.uniqueIdentity( unitTree );
  92. if( this.options.dutyUnitLevelBy === "duty" ){
  93. this.level1Container = [];
  94. if( this.options.units && this.options.units.length ){
  95. var div = new Element( "div" ).inject(this.itemAreaNode);
  96. this.level1Container.push(div);
  97. }
  98. this._loadSelectItemsByDutyUnit(unitTree);
  99. }else{
  100. this._loadSelectItemsByIdentityUnit(unitTree);
  101. }
  102. this.dutyLoaded = true;
  103. if( this.includeLoaded ){
  104. this.afterLoadSelectItem();
  105. }
  106. },
  107. _loadSelectItemsByIdentityUnit : function( unitTree ){
  108. if( !unitTree.unitList )return;
  109. this.sortUnit( unitTree.unitList );
  110. for( var i=0; i< unitTree.unitList.length; i++ ){
  111. var unit = unitTree.unitList[i];
  112. // if( !this.isExcluded( unit ) ) {
  113. var category = this._newItemCategory("ItemCategory",unit, this, this.itemAreaNode);
  114. this.subCategorys.push(category);
  115. // }
  116. }
  117. },
  118. sortUnit : function( unitList ){
  119. if( this.options.dutyUnitLevelBy === "duty" ){
  120. if( this.options.units ){
  121. unitList.sort( function(a, b){
  122. var idxA = this.getIndexFromUnitOption( a );
  123. var idxB = this.getIndexFromUnitOption( b );
  124. idxA = idxA === -1 ? 9999999 + (a.orderNumber || 9999999) : idxA;
  125. idxB = idxB === -1 ? 9999999 + (b.orderNumber || 9999999) : idxB;
  126. return idxA - idxB;
  127. }.bind(this))
  128. }else{
  129. unitList.sort( function(a, b){
  130. return (a.orderNumber || 9999999) - (b.orderNumber || 9999999);
  131. }.bind(this))
  132. }
  133. }else{
  134. unitList.sort( function(a, b){
  135. return (a.orderNumber || 9999999) - (b.orderNumber || 9999999);
  136. }.bind(this))
  137. }
  138. },
  139. _loadSelectItemsByDutyUnit : function( unitTree ){
  140. if( !unitTree.unitList )return;
  141. // this.sortUnit( unitTree.unitList );
  142. for( var i=0; i< unitTree.unitList.length; i++ ){
  143. var unit = unitTree.unitList[i];
  144. if( this.isUnitContain( unit ) ){
  145. // if( !this.isExcluded( unit ) ) {
  146. var container = this.itemAreaNode;
  147. if( this.level1Container && this.level1Container.length ){
  148. var index = this.getIndexFromUnitOption( unit );
  149. if( index > -1 && (this.level1Container.length > index) && this.level1Container[i] )container = this.level1Container[i];
  150. }
  151. var category = this._newItemCategory("ItemCategory",unit, this, container );
  152. this.subCategorys.push(category);
  153. // }
  154. }else{
  155. this._loadSelectItemsByDutyUnit( unit );
  156. }
  157. }
  158. },
  159. getIndexFromUnitOption : function( unit ){
  160. if( !this.unitStringList || !this.unitStringList.length )return -1;
  161. var idx = -1;
  162. if(idx == -1 && unit.distinguishedName)idx = this.unitStringList.indexOf( unit.distinguishedName );
  163. if(idx == -1 && unit.id)idx = this.unitStringList.indexOf( unit.id );
  164. if(idx == -1 && unit.unique)idx = this.unitStringList.indexOf( unit.unique );
  165. if(idx == -1 && unit.levelName)idx = this.unitStringList.indexOf( unit.levelName );
  166. return idx
  167. },
  168. isUnitContain : function( d ){
  169. if( this.options.units.length === 0 )return true;
  170. if( !this.unitFlagMap ){
  171. this.unitFlagMap = {};
  172. this.options.units.each( function( e ){
  173. if( !e )return;
  174. this.unitFlagMap[ typeOf( e ) === "string" ? e : ( e.distinguishedName || e.id || e.unique || e.employee || e.levelName) ] = true;
  175. }.bind(this));
  176. }
  177. var map = this.unitFlagMap;
  178. return ( d.distinguishedName && map[ d.distinguishedName ] ) ||
  179. ( d.levelName && map[ d.levelName ] ) ||
  180. ( d.id && map[ d.id ] ) ||
  181. ( d.unique && map[ d.unique ] );
  182. },
  183. listAllIdentityInUnitObject : function(){
  184. var unitArray = [];
  185. for( var i=0; i<identityList.length; i++ ){
  186. unitArray.push( identityList[i].unit || identityList[i].unitLevelName );
  187. }
  188. o2.Actions.load("x_organization_assemble_express").UnitAction.listObject({
  189. unitList : unitArray
  190. }, function(json){
  191. this.allIdentityInUnitObject = {};
  192. json.data.each( function( u ){
  193. this.allIdentityInUnitObject[u.levelName] = u;
  194. }.bind(this));
  195. if(callback)callback();
  196. }.bind(this), null, false)
  197. },
  198. getUnitOrderNumber : function( unit ){
  199. return this.allIdentityInUnitObject[unit.levelName].orderNumber;
  200. },
  201. listAllUnitObject: function( identityList, callback ){
  202. var key = this.options.dutyUnitLevelBy === "duty" ? "matchUnitLevelName" : "unitLevelName";
  203. var unitArray = [];
  204. for( var i=0; i<identityList.length; i++ ){
  205. var levelNames = identityList[i][key];
  206. //if( !levelNames && key === "matchUnitLevelName" )levelNames = identityList[i].unitLevelName;
  207. var unitLevelNameList = levelNames.split("/");
  208. var nameList = [];
  209. for( var j=0; j<unitLevelNameList.length; j++ ){
  210. nameList.push( unitLevelNameList[j] );
  211. var name = nameList.join("/");
  212. if( !unitArray.contains( name ) ){
  213. unitArray.push( name );
  214. }
  215. }
  216. }
  217. o2.Actions.load("x_organization_assemble_express").UnitAction.listObject({
  218. unitList : unitArray
  219. }, function(json){
  220. this.allUnitObject = {};
  221. json.data.each( function( u ){
  222. this.allUnitObject[u.levelName] = u;
  223. }.bind(this));
  224. if(callback)callback();
  225. }.bind(this), null, false)
  226. },
  227. listNestedUnitByIdentity : function( identityList ){
  228. this.listAllUnitObject( identityList);
  229. return this._listNestedUnitByIdentity( identityList );
  230. },
  231. _listNestedUnitByIdentity : function( identityList ){
  232. debugger;
  233. //identityList = Array.unique(identityList);
  234. var key = this.options.dutyUnitLevelBy === "duty" ? "matchUnitLevelName" : "unitLevelName";
  235. //根据unitLevelName整合成组织树
  236. var unitTree = {};
  237. for( var i=0; i<identityList.length; i++ ){
  238. var flag = true;
  239. if( this.isExcluded( identityList[i] ) )continue;
  240. var levelNames = identityList[i][key];
  241. //if( !levelNames && key === "matchUnitLevelName" )levelNames = identityList[i].unitLevelName;
  242. var unitLevelNameList = levelNames.split("/");
  243. var nameList = [];
  244. var tree = unitTree;
  245. for( var j=0; j<unitLevelNameList.length; j++ ){
  246. nameList.push( unitLevelNameList[j] );
  247. var name = nameList.join("/");
  248. if( this.isExcluded( this.allUnitObject[name] || {} ) ){
  249. flag = false;
  250. break;
  251. }
  252. if( !tree.unitList )tree.unitList = [];
  253. var found = false;
  254. for( var k=0; k<tree.unitList.length; k++ ){
  255. if( tree.unitList[k].levelName == name ){
  256. tree = tree.unitList[k];
  257. found = true;
  258. break;
  259. }
  260. }
  261. if( !found ){
  262. // var obj = {};
  263. var obj = this.allUnitObject[name] || {};
  264. obj.matchLevelName = name;
  265. tree.unitList.push( obj );
  266. tree = obj;
  267. }
  268. // if( !tree.distinguishedName ){
  269. // tree = Object.merge( tree, this.allUnitObject[name] );
  270. // }
  271. if( !tree.identityList )tree.identityList = [];
  272. }
  273. if(flag)tree.identityList.push( identityList[i] );
  274. }
  275. return unitTree;
  276. },
  277. uniqueIdentity : function( tree ){
  278. var map = {};
  279. var isExist = function ( d ) {
  280. if(( d.distinguishedName && map[ d.distinguishedName ] ) ||
  281. ( d.levelName && map[ d.levelName ] ) ||
  282. ( d.id && map[ d.id ] ) ||
  283. ( d.unique && map[ d.unique ] )){
  284. return true;
  285. }else{
  286. map[ typeOf( d ) === "string" ? d : ( d.distinguishedName || d.id || d.unique || d.employee || d.levelName) ] = true;
  287. return false;
  288. }
  289. };
  290. var identityList = [];
  291. if( tree.identityList ){
  292. for( var i=0; i<tree.identityList.length; i++ ){
  293. if( !isExist( tree.identityList[i] ) )identityList.push( tree.identityList[i] );
  294. }
  295. }
  296. tree.identityList = identityList;
  297. if( this.options.isCheckStatus ){
  298. var names = (tree.matchLevelName || tree.levelName || "").split("/");
  299. var nameList = [];
  300. for( var i=0; i<names.length; i++ ){
  301. nameList.push( names[i] );
  302. var name = nameList.join("/");
  303. var obj = this.allUnitObject[name];
  304. if( obj ){
  305. obj.subNestedIdentityCount = ( obj.subNestedIdentityCount || 0 ) + identityList.length;
  306. }
  307. }
  308. }
  309. if( tree.unitList ){
  310. for( var i=0; i<tree.unitList.length; i++ ){
  311. this.uniqueIdentity( tree.unitList[i] );
  312. }
  313. }
  314. },
  315. //listNestedUnitByIdentity : function( identityList ){
  316. // debugger;
  317. // this.unitArray = [];
  318. // var key = this.options.dutyUnitLevelBy === "duty" ? "matchUnitLevelName" : "unitLevelName";
  319. // //根据unitLevelName整合成组织树
  320. // var unitTree = {};
  321. // for( var i=0; i<identityList.length; i++ ){
  322. // var levelNames = identityList[i][key];
  323. // //if( !levelNames && key === "matchUnitLevelName" )levelNames = identityList[i].unitLevelName;
  324. // var unitLevelNameList = levelNames.split("/");
  325. // var nameList = [];
  326. // var tree = unitTree;
  327. // for( var j=0; j<unitLevelNameList.length; j++ ){
  328. // nameList.push( unitLevelNameList[j] );
  329. // var name = nameList.join("/");
  330. // if( !tree[ name ] ){
  331. // tree[ name ] = {
  332. // name : unitLevelNameList[j],
  333. // levelName : name,
  334. // identityList : []
  335. // };
  336. // this.unitArray.push( name );
  337. // }
  338. // tree = tree[name];
  339. // }
  340. // tree.identityList.push( identityList[i] );
  341. // }
  342. // return unitTree;
  343. //},
  344. _scrollEvent: function(y){
  345. return true;
  346. },
  347. _getChildrenItemIds: function(){
  348. return null;
  349. },
  350. _newItemCategory: function(type, data, selector, item, level, category, delay){
  351. return new MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit[type](data, selector, item, level, category, delay)
  352. },
  353. _listItemByKey: function(callback, failure, key){
  354. if (this.options.units.length) key = {"key": key, "unitList": this.options.units};
  355. this.orgAction.listIdentityByKey(function(json){
  356. if (callback) callback.apply(this, [json]);
  357. }.bind(this), failure, key);
  358. },
  359. _getItem: function(callback, failure, id, async){
  360. if( typeOf(id) === "string" ){
  361. this.orgAction.getIdentity(function(json){
  362. if (callback) callback.apply(this, [json]);
  363. }.bind(this), failure, ((typeOf(id)==="string") ? id : id.distinguishedName), async);
  364. }else{
  365. if (callback) callback.apply(this, [id]);
  366. }
  367. //this.orgAction.getIdentity(function(json){
  368. // if (callback) callback.apply(this, [json]);
  369. //}.bind(this), failure, ((typeOf(id)==="string") ? id : id.distinguishedName), async);
  370. },
  371. _newItemSelected: function(data, selector, item, selectedNode){
  372. return new MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.ItemSelected(data, selector, item, selectedNode)
  373. },
  374. _listItemByPinyin: function(callback, failure, key){
  375. if (this.options.units.length) key = {"key": key, "unitList": this.options.units};
  376. this.orgAction.listIdentityByPinyin(function(json){
  377. if (callback) callback.apply(this, [json]);
  378. }.bind(this), failure, key);
  379. },
  380. _newItem: function(data, selector, container, level, category){
  381. return new MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.Item(data, selector, container, level, category);
  382. },
  383. _newItemSearch: function(data, selector, container, level){
  384. return new MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.SearchItem(data, selector, container, level);
  385. }
  386. //_listItemNext: function(last, count, callback){
  387. // this.action.listRoleNext(last, count, function(json){
  388. // if (callback) callback.apply(this, [json]);
  389. // }.bind(this));
  390. //}
  391. });
  392. MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.Item = new Class({
  393. Extends: MWF.xApplication.Selector.IdentityWidthDuty.Item
  394. });
  395. MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.SearchItem = new Class({
  396. Extends: MWF.xApplication.Selector.IdentityWidthDuty.SearchItem
  397. });
  398. MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.ItemSelected = new Class({
  399. Extends: MWF.xApplication.Selector.IdentityWidthDuty.ItemSelected
  400. });
  401. MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.ItemCategory = new Class({
  402. Extends: MWF.xApplication.Selector.IdentityWidthDuty.ItemCategory,
  403. _getSelectedCount : function(){
  404. if( typeOf( this.selectedCount ) === "number" )return this.selectedCount;
  405. },
  406. _getNestItemCount : function(){
  407. return this.data.subNestedIdentityCount;
  408. },
  409. _checkStatus : function(){
  410. },
  411. isExisted : function( d ){
  412. if( !d )return true;
  413. if( !this.createdItemObject )this.createdItemObject = {};
  414. var map = this.createdItemObject;
  415. if(( d.distinguishedName && map[ d.distinguishedName ] ) ||
  416. ( d.levelName && map[ d.levelName ] ) ||
  417. ( d.id && map[ d.id ] ) ||
  418. ( d.unique && map[ d.unique ] )){
  419. return true;
  420. }else{
  421. //if( typeOf( d ) === "string" ){
  422. // this.createdItemObject[ d ] = true;
  423. //}else{
  424. // if( d.distinguishedName )this.createdItemObject[ d.distinguishedName ] = true;
  425. // if( d.id )this.createdItemObject[ d.id ] = true;
  426. // if( d.unique )this.createdItemObject[ d.unique ] = true;
  427. // if( d.employee )this.createdItemObject[ d.employee ] = true;
  428. // if( d.levelName )this.createdItemObject[ d.levelName ] = true;
  429. //}
  430. this.createdItemObject[ typeOf( d ) === "string" ? d : ( d.distinguishedName || d.id || d.unique || d.employee || d.levelName) ] = true;
  431. return false;
  432. }
  433. },
  434. loadSub: function(callback){
  435. if (!this.loaded){
  436. if( this.data.identityList && this.data.identityList.length>0 ){
  437. this.data.identityList.sort( function(a, b){
  438. //this.selector.getUnitOrderNumber( a.unitLevelName )
  439. return (a.orderNumber || 9999999) - (b.orderNumber || 9999999);
  440. });
  441. this.data.identityList.each( function( identity ){
  442. // if( !this.selector.isExcluded( identity ) ) {
  443. // if( !this.isExisted( identity ) ){
  444. var item = this.selector._newItem(identity, this.selector, this.children, this.level + 1, this);
  445. this.selector.items.push(item);
  446. if(this.subItems)this.subItems.push( item );
  447. // }
  448. // }
  449. }.bind(this))
  450. }
  451. if( this.data.unitList && this.data.unitList.length ){
  452. this.data.unitList.sort( function(a, b){
  453. return (a.orderNumber || 9999999) - (b.orderNumber || 9999999);
  454. });
  455. this.data.unitList.each( function( subData ){
  456. // if( !this.selector.isExcluded( subData ) ) {
  457. var category = this.selector._newItemCategory("ItemCategory", subData, this.selector, this.children, this.level + 1, this);
  458. this.subCategorys.push( category );
  459. category.loadSub()
  460. // }
  461. }.bind(this));
  462. }
  463. this.loaded = true;
  464. if (callback) callback( );
  465. }else{
  466. if (callback) callback( );
  467. }
  468. },
  469. loadCategoryChildren: function(callback){
  470. if (!this.categoryLoaded){
  471. this.loadSub();
  472. this.categoryLoaded = true;
  473. this.itemLoaded = true;
  474. if (callback) callback( );
  475. }else{
  476. if (callback) callback( );
  477. }
  478. },
  479. loadItemChildren: function(callback){
  480. if (!this.itemLoaded){
  481. if( this.data.identityList && this.data.identityList.length>0 ){
  482. this.data.identityList.sort( function(a, b){
  483. //this.selector.getUnitOrderNumber( a.unitLevelName )
  484. return (a.orderNumber || 9999999) - (b.orderNumber || 9999999);
  485. });
  486. this.data.identityList.each( function( identity ){
  487. // if( !this.selector.isExcluded( identity ) ) {
  488. // if( !this.isExisted( identity ) ){
  489. var item = this.selector._newItem(identity, this.selector, this.children, this.level + 1, this);
  490. this.selector.items.push(item);
  491. if(this.subItems)this.subItems.push( item );
  492. // }
  493. // }
  494. }.bind(this))
  495. }
  496. this.itemLoaded = true;
  497. if (callback) callback( );
  498. }else{
  499. if (callback) callback( );
  500. }
  501. },
  502. _hasChild: function(){
  503. return (this.data.unitList && this.data.unitList.length > 0) ||
  504. (this.data.identityList && this.data.identityList.length > 0);
  505. },
  506. _hasChildCategory : function(){
  507. return (this.data.unitList && this.data.unitList.length > 0);
  508. },
  509. _hasChildItem: function(){
  510. return this.data.identityList && this.data.identityList.length > 0;
  511. }
  512. });
  513. MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.ItemUnitCategory = new Class({
  514. Extends: MWF.xApplication.Selector.IdentityWidthDuty.ItemUnitCategory
  515. });
  516. MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.ItemGroupCategory = new Class({
  517. Extends: MWF.xApplication.Selector.IdentityWidthDuty.ItemGroupCategory
  518. });
  519. MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.Filter = new Class({
  520. Extends: MWF.xApplication.Selector.IdentityWidthDuty.Filter
  521. });