IdentityWidthDutyCategoryByUnit.js 21 KB

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