IdentityWidthDutyCategoryByUnit.js 20 KB

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