IdentityWidthDutyCategoryByUnit.js 19 KB

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