IdentityWidthDutyCategoryByUnit.js 21 KB

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