Identity.js 84 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849
  1. MWF.xApplication.Selector = MWF.xApplication.Selector || {};
  2. MWF.xDesktop.requireApp("Selector", "Person", null, false);
  3. MWF.xApplication.Selector.Identity = new Class({
  4. Extends: MWF.xApplication.Selector.Person,
  5. options: {
  6. "style": "default",
  7. "count": 0,
  8. "title": MWF.xApplication.Selector.LP.selectIdentity,
  9. "units": [],
  10. "values": [],
  11. "dutys": [],
  12. "zIndex": 1000,
  13. "expand": false,
  14. "noUnit" : false,
  15. "include" : [], //增加的可选项
  16. "exclude" : [], //排除的可选项
  17. "resultType" : "", //可以设置成个人,那么结果返回个人
  18. "expandSubEnable" : true, //是否允许展开下一层,
  19. "selectAllEnable" : true //分类是否允许全选下一层
  20. },
  21. _init : function(){
  22. this.selectType = "identity";
  23. this.className = "Identity";
  24. },
  25. loadSelectItems : function(){
  26. if( this.options.disabled ){
  27. this.afterLoadSelectItem();
  28. return;
  29. }
  30. if( this.className === "Identity" && (this.options.isCheckStatus || this.options.showSelectedCount )) {
  31. var unitList = [];
  32. var groupList = [];
  33. var parseInclude = function () {
  34. if (this.options.include.length > 0) {
  35. this.options.include.each(function (d) {
  36. var dn = typeOf(d) === "string" ? d : d.distinguishedName;
  37. var flag = dn.split("@").getLast().toLowerCase();
  38. if (flag === "u") {
  39. unitList.push(dn);
  40. } else if (flag === "g") {
  41. groupList.push(dn)
  42. }
  43. })
  44. }
  45. }.bind(this);
  46. var load = function () {
  47. var unitLoaded, groupLoaded, selectedIdentityLoaded, excludeIdentityLoaded;
  48. var unitTree, groupTree;
  49. this.unitExcludedIdentityCount = {};
  50. this.groupExcludedIdentityCount = {};
  51. this.unitSelectedIdentityCount = {};
  52. this.groupSelectedIdentityCount = {};
  53. var caculate = function () {
  54. if (unitLoaded && groupLoaded && selectedIdentityLoaded && excludeIdentityLoaded) {
  55. this.caculateNestedSubCount(unitTree, groupTree, function () {
  56. debugger;
  57. this._loadSelectItems()
  58. }.bind(this))
  59. }
  60. }.bind(this);
  61. this.getIdentityCountMap(this.options.values, groupList && groupList.length > 0, function (result) {
  62. this.unitSelectedIdentityCount = result.unitMap;
  63. this.groupSelectedIdentityCount = result.groupMap;
  64. selectedIdentityLoaded = true;
  65. caculate();
  66. }.bind(this));
  67. this.getIdentityCountMap(this.options.exclude, groupList && groupList.length > 0, function (result) {
  68. this.unitExcludedIdentityCount = result.unitMap;
  69. this.groupExcludedIdentityCount = result.groupMap;
  70. excludeIdentityLoaded = true;
  71. caculate();
  72. }.bind(this));
  73. if (unitList && unitList.length > 0) {
  74. o2.Actions.load("x_organization_assemble_express").UnitAction.listWithUnitTree({"unitList": unitList}, function (json) {
  75. unitTree = json.data;
  76. unitLoaded = true;
  77. caculate();
  78. }.bind(this))
  79. } else {
  80. unitLoaded = true;
  81. caculate();
  82. }
  83. if (groupList && groupList.length > 0) {
  84. o2.Actions.load("x_organization_assemble_express").GroupAction.listWithGroupTree({"groupList": groupList}, function (json) {
  85. groupTree = json.data;
  86. groupLoaded = true;
  87. caculate();
  88. }.bind(this))
  89. } else {
  90. groupLoaded = true;
  91. caculate();
  92. }
  93. }.bind(this);
  94. if (this.options.noUnit) {
  95. parseInclude();
  96. load();
  97. } else if (this.options.units.length) {
  98. parseInclude();
  99. this.options.units.each(function (u) {
  100. unitList.push(typeOf(u) === "string" ? u : (u.distinguishedName || u.id || u.unique || u.levelName))
  101. }.bind(this));
  102. load();
  103. } else {
  104. this.orgAction.listTopUnit(function (json) {
  105. this.topUnitObj = json.data;
  106. this.topUnitObj.each(function (u) {
  107. unitList.push(u.distinguishedName)
  108. }.bind(this));
  109. load();
  110. }.bind(this))
  111. }
  112. }else{
  113. this._loadSelectItems()
  114. }
  115. },
  116. _loadSelectItems: function(addToNext){
  117. var afterLoadSelectItemFun = this.afterLoadSelectItem.bind(this);
  118. if( this.options.resultType === "person" ){
  119. if( this.titleTextNode ){
  120. this.titleTextNode.set("text", MWF.xApplication.Selector.LP.selectPerson );
  121. }else{
  122. this.options.title = MWF.xApplication.Selector.LP.selectPerson;
  123. }
  124. }
  125. if(this.options.noUnit){
  126. this.loadInclude(afterLoadSelectItemFun);
  127. }else if (this.options.units.length){
  128. var loadUnitSuccess = function () {
  129. this.unitLoaded = true;
  130. if( this.includeLoaded ){
  131. afterLoadSelectItemFun();
  132. }
  133. }.bind(this);
  134. var loadUnitFailure = loadUnitSuccess;
  135. this.loadInclude( function () {
  136. this.includeLoaded = true;
  137. if( this.unitLoaded ){
  138. afterLoadSelectItemFun();
  139. }
  140. }.bind(this));
  141. var unitList = [];
  142. for( var i=0 ; i<this.options.units.length; i++ ){
  143. var unit = this.options.units[i];
  144. if( typeOf( unit ) === "string" ){
  145. unitList.push(unit);
  146. }else if( typeOf(unit)==="object"){
  147. unitList.push(unit.id || unit.distinguishedName || unit.unique || unit.levelName);
  148. }
  149. }
  150. o2.Actions.load("x_organization_assemble_express").UnitAction.listObject( {"unitList" : unitList} , function (json) {
  151. if (json.data.length){
  152. json.data.each( function(data){
  153. var category = this._newItemCategory("ItemUnitCategory", data, this, this.itemAreaNode );
  154. this.subCategorys.push(category);
  155. }.bind(this));
  156. }
  157. loadUnitSuccess();
  158. }.bind(this), loadUnitFailure );
  159. // var unitLoaded = 0;
  160. //
  161. // var loadUnitSuccess = function () {
  162. // unitLoaded++;
  163. // if( unitLoaded === this.options.units.length ){
  164. // this.unitLoaded = true;
  165. // if( this.includeLoaded ){
  166. // afterLoadSelectItemFun();
  167. // }
  168. // }
  169. // }.bind(this);
  170. // var loadUnitFailure = loadUnitSuccess;
  171. //
  172. // this.loadInclude( function () {
  173. // this.includeLoaded = true;
  174. // if( this.unitLoaded ){
  175. // afterLoadSelectItemFun();
  176. // }
  177. // }.bind(this));
  178. // this.options.units.each(function(unit){
  179. //
  180. // var container = new Element("div").inject( this.itemAreaNode );
  181. //
  182. // if (typeOf(unit)==="string"){
  183. // this.orgAction.getUnit(unit, function(json){
  184. // if (json.data){
  185. // var category = this._newItemCategory("ItemUnitCategory", json.data, this, container);
  186. // this.subCategorys.push( category );
  187. // }
  188. // loadUnitSuccess();
  189. // }.bind(this), function(){
  190. // this.orgAction.listUnitByKey(function(json){
  191. // if (json.data.length){
  192. // json.data.each(function(data){
  193. // var category = this._newItemCategory("ItemUnitCategory", data, this, container);
  194. // this.subCategorys.push( category );
  195. // }.bind(this))
  196. // }
  197. // loadUnitSuccess();
  198. // }.bind(this), loadUnitFailure, unit);
  199. // }.bind(this));
  200. // }else{
  201. // this.orgAction.getUnit(function(json){
  202. // if (json.data){
  203. // var category = this._newItemCategory("ItemUnitCategory", json.data, this, container);
  204. // this.subCategorys.push( category );
  205. // }
  206. // loadUnitSuccess();
  207. // }.bind(this), loadUnitFailure, unit.distinguishedName);
  208. // }
  209. //
  210. // }.bind(this));
  211. }else{
  212. // this.loadInclude( function () {
  213. // this.includeLoaded = true;
  214. // if( this.unitLoaded ){
  215. // afterLoadSelectItemFun();
  216. // }
  217. // }.bind(this));
  218. var load = function ( topUnit ) {
  219. topUnit.each(function(data){
  220. if( !this.isExcluded( data ) ){
  221. var category = this._newItemCategory("ItemUnitCategory", data, this, this.itemAreaNode);
  222. this.subCategorys.push( category );
  223. }
  224. }.bind(this));
  225. // this.unitLoaded = true;
  226. // if( this.includeLoaded ){
  227. afterLoadSelectItemFun();
  228. // }
  229. }.bind(this);
  230. if( this.topUnitObj ){
  231. load( this.topUnitObj );
  232. }else{
  233. this.orgAction.listTopUnit(function(json){
  234. load( json.data );
  235. }.bind(this));
  236. }
  237. }
  238. },
  239. loadInclude: function(afterLoadFun) {
  240. if (!this.includeObject){
  241. this.includeObject = new MWF.xApplication.Selector.Identity.Include(this, this.itemAreaNode, {
  242. "include": this.options.include, //增加的可选项
  243. "resultType": this.options.resultType, //可以设置成个人,那么结果返回个人
  244. "expandSubEnable": this.options.expandSubEnable, //是否允许展开下一层
  245. "onAfterLoad" : afterLoadFun
  246. });
  247. }
  248. this.includeObject.load();
  249. },
  250. checkLoadSelectItems: function(){
  251. if (!this.options.units.length){
  252. this.loadSelectItems();
  253. }else{
  254. this.loadSelectItems();
  255. }
  256. },
  257. _scrollEvent: function(y){
  258. return true;
  259. },
  260. _getChildrenItemIds: function(){
  261. return null;
  262. },
  263. _newItemCategory: function(type, data, selector, item, level, category, delay){
  264. return new MWF.xApplication.Selector.Identity[type](data, selector, item, level, category, delay)
  265. },
  266. _listItem : function( filterType, callback, failure, key ){
  267. if( this.options.noUnit ){
  268. this.includeObject.listByFilter( filterType, key, function( array ){
  269. var json = {"data" : array} ;
  270. if (callback) callback.apply(this, [json]);
  271. }.bind(this))
  272. }else{
  273. var action = filterType === "key" ? "listIdentityByKey" : "listIdentityByPinyin";
  274. if ( this.options.units.length ){
  275. key = this.getLikeKey( key, this.options.units );
  276. this.orgAction[action](function(json){ //搜若units内的组织
  277. this.includeObject.listByFilter( filterType, key, function( array ){
  278. json.data = array.concat( json.data || [] );
  279. if (callback) callback.apply(this, [json]);
  280. }.bind(this));
  281. }.bind(this), failure, key);
  282. }else{ //搜索所有人
  283. this.orgAction[action](function(json){
  284. if (callback) callback.apply(this, [json]);
  285. }.bind(this), failure, key);
  286. }
  287. }
  288. },
  289. _listItemByKey: function(callback, failure, key){
  290. this._listItem( "key", callback, failure, key );
  291. },
  292. _getItem: function(callback, failure, id, async){
  293. this.orgAction.getIdentity(function(json){
  294. if (callback) callback.apply(this, [json]);
  295. }.bind(this), failure, ((typeOf(id)==="string") ? id : id.distinguishedName), async);
  296. },
  297. _newItemSelected: function(data, selector, item, selectedNode){
  298. return new MWF.xApplication.Selector.Identity.ItemSelected(data, selector, item, selectedNode)
  299. },
  300. _listItemByPinyin: function(callback, failure, key){
  301. this._listItem( "pinyin", callback, failure, key );
  302. },
  303. _newItem: function(data, selector, container, level, category, delay){
  304. return new MWF.xApplication.Selector.Identity.Item(data, selector, container, level, category, delay);
  305. },
  306. _newItemSearch: function(data, selector, container, level){
  307. return new MWF.xApplication.Selector.Identity.SearchItem(data, selector, container, level);
  308. },
  309. getLikeKey : function( key, unitObjects ){
  310. var unitObjects = unitObjects || [];
  311. var units = [];
  312. unitObjects.each(function(u){
  313. if (typeOf(u)==="string"){
  314. units.push(u);
  315. }
  316. if (typeOf(u)==="object"){
  317. units.push(u.distinguishedName);
  318. }
  319. });
  320. var keyObj = { "key": key, "unitList": units };
  321. if( !this.dutyDnList ){
  322. var dutyDnList = [];
  323. var dutyNameList = [];
  324. ( this.options.dutys || [] ).each(function(d){
  325. if (typeOf(d)==="string"){
  326. var ds = d.split("@");
  327. if( ds[ ds.length - 1].toUpperCase() === "UD" ){
  328. dutyDnList.push( d )
  329. }else{
  330. dutyNameList.push( d );
  331. }
  332. }
  333. if (typeOf(d)==="object"){
  334. if( d.distinguishedName ){
  335. dutyDnList.push(d.distinguishedName);
  336. }else if( d.name ){
  337. dutyNameList.push(d.name);
  338. }
  339. }
  340. });
  341. if( dutyNameList.length ){
  342. o2.Actions.get("x_organization_assemble_express").listDutyWithName( { nameList : dutyNameList }, function(json){
  343. if( json.data && json.data.unitDutyList ){
  344. dutyDnList = dutyDnList.concat( json.data.unitDutyList )
  345. }
  346. }.bind(this), null, false);
  347. }
  348. this.dutyDnList = dutyDnList;
  349. }
  350. if( this.dutyDnList.length )keyObj.unitDutyList = this.dutyDnList;
  351. return units.length ? keyObj : key;
  352. },
  353. //_listItemNext: function(last, count, callback){
  354. // this.action.listRoleNext(last, count, function(json){
  355. // if (callback) callback.apply(this, [json]);
  356. // }.bind(this));
  357. //}
  358. getIdentityAllLevelName : function(identityList, byGroup, callback){
  359. var result = {
  360. unitMap : {},
  361. groupMap : {}
  362. };
  363. this.listIndetityObject( identityList, function ( list, map ) {
  364. list.each( function (id) {
  365. if(id.unitLevelName){
  366. result.unitMap[ id.unitLevelName ] = ( result.unitMap[ id.unitLevelName ] || 0 )+1;
  367. }
  368. }.bind(this));
  369. if( byGroup ) {
  370. this.listLevelNameGroupMap(list, function ( levelNameGroupMap ) {
  371. for( var key in levelNameGroupMap ){
  372. var group = levelNameGroupMap[key]
  373. var identityCount = group["identityList"].length;
  374. if(identityCount)result.groupMap[key] = identityCount;
  375. }
  376. if( callback )callback( result );
  377. }.bind(this));
  378. }else{
  379. if( callback )callback( result );
  380. }
  381. }.bind(this));
  382. },
  383. getIdentityCountMap : function( identityList, byGroup, callback ){
  384. var result = {
  385. unitMap : {},
  386. groupMap : {}
  387. };
  388. this.listIndetityObject( identityList, function ( list, map ) {
  389. list.each( function (id) {
  390. if(id.unitLevelName){
  391. result.unitMap[ id.unitLevelName ] = ( result.unitMap[ id.unitLevelName ] || 0 )+1;
  392. }
  393. }.bind(this));
  394. if( byGroup ) {
  395. this.listLevelNameGroupMap(list, function ( levelNameGroupMap ) {
  396. for( var key in levelNameGroupMap ){
  397. var group = levelNameGroupMap[key]
  398. var identityCount = group["identityList"].length;
  399. if(identityCount)result.groupMap[key] = identityCount;
  400. }
  401. if( callback )callback( result );
  402. }.bind(this));
  403. }else{
  404. if( callback )callback( result );
  405. }
  406. }.bind(this));
  407. },
  408. listIndetityObject : function( identityList, callback ){
  409. var list = [];
  410. identityList.each( function (d) {
  411. if( typeOf( d ) === "object"){
  412. if( !d.unitLevelName || !d.distinguishedName )list.push( d.distinguishedName || d.id || d.unique )
  413. }else{
  414. list.push( d )
  415. }
  416. });
  417. if( list.length > 0 ){
  418. o2.Actions.load("x_organization_assemble_express").IdentityAction.listObject({ identityList : list }, function (json) {
  419. var map = {};
  420. json.data.each( function (d) { map[ d.matchKey ] = d; });
  421. var result = [];
  422. identityList.each( function (d) {
  423. var key = typeOf( d ) === "object" ? ( d.distinguishedName || d.id || d.unique ) : d;
  424. result.push( map[key] ? map[key] : d );
  425. });
  426. if( callback )callback( result, map );
  427. }.bind(this))
  428. }else{
  429. if( callback )callback( identityList, {} );
  430. }
  431. },
  432. listLevelNameGroupMap : function(identityList, callback, referenceFlag, recursiveOrgFlag){
  433. var list = identityList.map( function (d) { return d.distinguishedName; }).clean();
  434. if( list.length > 0 ){
  435. o2.Actions.load("x_organization_assemble_express").GroupAction.listWithIdentityObject( {
  436. recursiveGroupFlag : true, identityList : list, referenceFlag : !!referenceFlag, recursiveOrgFlag : !!recursiveOrgFlag
  437. }, function (json) {
  438. var map = {};
  439. var groupList = json.data;
  440. groupList.each( function (d) { map[ d.distinguishedName ] = d; });
  441. groupList.each( function (d) {
  442. d.identityList = d.identityList.filter( function (id) { return list.contains(id) });
  443. d.groupObjectList = [];
  444. d.groupList.each( function (g) { if(map[g])d.groupObjectList.push( map[g] ) })
  445. });
  446. var groupIdentityMap = {};
  447. var fun = function ( group, parentName ) {
  448. var levelName = parentName ? ( parentName + "/" + group.name ) : group.name;
  449. groupIdentityMap[ levelName ] = group;
  450. group.groupObjectList.each( function( g ){
  451. fun( g, levelName );
  452. })
  453. };
  454. groupList.each( function (d) { fun(d) });
  455. if( callback )callback( groupIdentityMap );
  456. }.bind(this))
  457. }else{
  458. if( callback )callback({});
  459. }
  460. },
  461. caculateNestedSubCount : function(unitTree, groupTree, callback){
  462. if( !this.allUnitObject )this.allUnitObject = {};
  463. if( !this.allGroupObject )this.allGroupObject = {};
  464. if( !this.allGroupObjectByDn )this.allGroupObjectByDn = {};
  465. if( groupTree && groupTree.length ){
  466. groupTree.each( function ( tree ) {
  467. this.caculateGroupNestedCount( tree );
  468. }.bind(this) );
  469. }
  470. if( unitTree && unitTree.length ){
  471. unitTree.each( function ( tree ) {
  472. if( !this.allUnitObject[ tree.levelName ] ){
  473. this.caculateUnitNestedCount( tree );
  474. }
  475. }.bind(this) );
  476. }
  477. if( this.allGroupObject ){
  478. for( var k in this.allGroupObject ){
  479. var obj = this.allGroupObject[k];
  480. this.allGroupObjectByDn[ obj.distinguishedName ] = obj;
  481. }
  482. }
  483. if(callback)callback();
  484. },
  485. caculateGroupNestedCount : function( tree, parentLevelName ){
  486. if( this.isExcluded( tree ) )return;
  487. var groupLevelName = parentLevelName ? ( parentLevelName + "/" + tree.distinguishedName.split("@")[0] ) : tree.distinguishedName.split("@")[0];
  488. if(!this.allGroupObject[ groupLevelName ]){
  489. this.allGroupObject[ groupLevelName ] = tree;
  490. }else{
  491. return;
  492. }
  493. // tree.subDirectIdentityCount
  494. var count = tree.subDirectIdentityCount;
  495. if( this.groupExcludedIdentityCount && this.groupExcludedIdentityCount[ groupLevelName ] ){
  496. count = (count || 0) - this.groupExcludedIdentityCount[ groupLevelName ];
  497. }
  498. var selectedCount = 0;
  499. if( this.groupSelectedIdentityCount && this.groupSelectedIdentityCount[ groupLevelName ] ){
  500. selectedCount = this.groupSelectedIdentityCount[ groupLevelName ];
  501. }
  502. var nameList = groupLevelName.split("/");
  503. var names = [];
  504. nameList.each( function (n) {
  505. names.push( n );
  506. var levelName = names.join("/");
  507. var groupObject = this.allGroupObject[levelName];
  508. if( groupObject ){
  509. groupObject.subNestedIdentityCount = (groupObject.subNestedIdentityCount || 0) + count;
  510. groupObject.selectedNestedIdentityCount = (groupObject.selectedNestedIdentityCount || 0) + selectedCount;
  511. }
  512. }.bind(this));
  513. tree.subGroups.each( function (group) {
  514. this.caculateGroupNestedCount( group, groupLevelName );
  515. }.bind(this));
  516. tree.subUnits.each( function (unit) {
  517. var flag = this.allUnitObject[ unit.levelName ];
  518. this.caculateUnitNestedCount( unit, groupLevelName, !!flag )
  519. }.bind(this))
  520. },
  521. caculateUnitNestedCount : function ( tree, groupLevelName, flag ) {
  522. if( this.isExcluded( tree ) )return;
  523. var count;
  524. var selectedCount;
  525. if(!this.allUnitObject[ tree.levelName ]){
  526. this.allUnitObject[ tree.levelName ] = tree;
  527. count = tree.subDirectIdentityCount;
  528. if( this.unitExcludedIdentityCount && this.unitExcludedIdentityCount[ tree.levelName ] ){
  529. count = (count || 0) - this.unitExcludedIdentityCount[ tree.levelName ];
  530. }
  531. selectedCount = 0;
  532. if( this.unitSelectedIdentityCount && this.unitSelectedIdentityCount[ tree.levelName ] ){
  533. selectedCount = this.unitSelectedIdentityCount[ tree.levelName ];
  534. }
  535. }else if( !flag ){
  536. return;
  537. }else{
  538. count = this.allUnitObject[ tree.levelName ].subNestedIdentityCount || 0;
  539. count = this.allUnitObject[ tree.levelName ].selectedNestedIdentityCount || 0;
  540. }
  541. if( groupLevelName ){
  542. var groupNameList = groupLevelName.split("/");
  543. var groupNames = [];
  544. groupNameList.each( function (n) {
  545. groupNames.push( n );
  546. var levelName = groupNames.join("/");
  547. var groupObject = this.allGroupObject[levelName];
  548. if( groupObject ){
  549. groupObject.subNestedIdentityCount = (groupObject.subNestedIdentityCount || 0) + count;
  550. groupObject.selectedNestedIdentityCount = (groupObject.selectedNestedIdentityCount || 0) + selectedCount;
  551. }
  552. }.bind(this));
  553. }
  554. if( !flag ){
  555. var nameList = tree.levelName.split("/");
  556. var names = [];
  557. nameList.each( function (n) {
  558. names.push( n );
  559. var levelName = names.join("/");
  560. var unitObject = this.allUnitObject[levelName];
  561. if( unitObject ){
  562. unitObject.subNestedIdentityCount = (unitObject.subNestedIdentityCount || 0) + count;
  563. unitObject.selectedNestedIdentityCount = (unitObject.selectedNestedIdentityCount || 0) + selectedCount;
  564. }
  565. }.bind(this));
  566. tree.subUnits.each( function (unit) {
  567. this.caculateUnitNestedCount( unit, groupLevelName )
  568. }.bind(this))
  569. }
  570. }
  571. });
  572. MWF.xApplication.Selector.Identity.Item = new Class({
  573. Extends: MWF.xApplication.Selector.Person.Item,
  574. _getShowName: function(){
  575. return this.data.name;
  576. },
  577. _getTtiteText: function(){
  578. return this.data.name+((this.data.unitLevelName) ? "("+this.data.unitLevelName+")" : "");
  579. },
  580. _setIcon: function(){
  581. var style = this.selector.options.style;
  582. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/personicon.png)");
  583. },
  584. getData: function(callback){
  585. if( this.selector.options.resultType === "person" ){
  586. var isPerson = false;
  587. if( this.data && this.data.distinguishedName ){
  588. var dn = this.data.distinguishedName;
  589. if( dn.substr(dn.length-1, 1).toLowerCase() === "p" )isPerson = true;
  590. }
  591. if( isPerson ) {
  592. if (callback) callback();
  593. }else if( this.data.woPerson ){
  594. this.data == this.data.woPerson;
  595. if (callback) callback();
  596. }else if( this.data.person ){
  597. this.selector.orgAction.getPerson(function(json){
  598. this.data = json.data;
  599. if (callback) callback();
  600. }.bind(this), null, this.data.person)
  601. }else{
  602. if (callback) callback();
  603. }
  604. }else{
  605. if (!this.data.woPerson && (!this.data.personDn || !this.data.personEmployee || !this.data.personUnique)){
  606. this.selector.orgAction.getPerson(function(json){
  607. this.data.woPerson = json.data;
  608. if (callback) callback();
  609. }.bind(this), null, this.data.person)
  610. }else{
  611. if (callback) callback();
  612. }
  613. }
  614. },
  615. checkSelectedSingle: function(){
  616. var isPerson = this.selector.options.resultType === "person";
  617. var selectedItem = this.selector.options.values.filter(function(item, index){
  618. if( isPerson ){
  619. if (typeOf(item)==="object") return (item.id && item.id === this.data.person) ||
  620. ( item.person && item.person === this.data.id ) ||
  621. ( this.data.distinguishedName && this.data.distinguishedName === item.distinguishedName);
  622. return false;
  623. }else{
  624. if (typeOf(item)==="object") return this.data.distinguishedName === item.distinguishedName;
  625. if (typeOf(item)==="string") return this.data.distinguishedName === item;
  626. return false;
  627. }
  628. }.bind(this));
  629. if (selectedItem.length){
  630. this.selectedSingle();
  631. }
  632. },
  633. checkSelected: function(){
  634. var isPerson = this.selector.options.resultType === "person";
  635. var selectedItem = this.selector.selectedItems.filter(function(item, index){
  636. if( isPerson ){
  637. return ( item.data.id && item.data.id === this.data.person ) ||
  638. ( item.data.person && item.data.person === this.data.id ) ||
  639. ( item.data.distinguishedName && item.data.distinguishedName === this.data.distinguishedName );
  640. }else{
  641. return item.data.distinguishedName === this.data.distinguishedName;
  642. }
  643. }.bind(this));
  644. if (selectedItem.length){
  645. //selectedItem[0].item = this;
  646. selectedItem[0].addItem(this);
  647. this.selectedItem = selectedItem[0];
  648. this.setSelected();
  649. }
  650. }
  651. });
  652. MWF.xApplication.Selector.Identity.SearchItem = new Class({
  653. Extends: MWF.xApplication.Selector.Identity.Item,
  654. _getShowName: function(){
  655. return this.data.name+((this.data.unitLevelName) ? "("+this.data.unitLevelName+")" : "");
  656. }
  657. });
  658. MWF.xApplication.Selector.Identity.ItemSelected = new Class({
  659. Extends: MWF.xApplication.Selector.Person.ItemSelected,
  660. getData: function(callback){
  661. if( this.selector.options.resultType === "person" ){
  662. var isPerson = false;
  663. if( this.data && this.data.distinguishedName ){
  664. var dn = this.data.distinguishedName;
  665. if( dn.substr(dn.length-1, 1).toLowerCase() === "p" )isPerson = true;
  666. }
  667. if( isPerson ){
  668. if (callback) callback();
  669. }else if( this.data.woPerson ){
  670. this.data = this.data.woPerson;
  671. if (callback) callback();
  672. }else if( this.data.person ){
  673. this.selector.orgAction.getPerson(function(json){
  674. this.data = json.data;
  675. if (callback) callback();
  676. }.bind(this), null, this.data.person )
  677. }else{
  678. if (callback) callback();
  679. }
  680. }else if (!this.data.woPerson && (!this.data.personDn || !this.data.personEmployee || !this.data.personUnique) ){
  681. if (this.data.person){
  682. this.selector.orgAction.getPerson(function(json){
  683. this.data.woPerson = json.data;
  684. if (callback) callback();
  685. }.bind(this), function(xhr, text, error){
  686. var errorText = error;
  687. if (xhr){
  688. var json = JSON.decode(xhr.responseText);
  689. if (json){
  690. errorText = json.message.trim() || "request json error";
  691. }else{
  692. errorText = "request json error: "+xhr.responseText;
  693. }
  694. }
  695. MWF.xDesktop.notice("error", {x: "right", y:"top"}, errorText);
  696. if (callback) callback();
  697. }.bind(this), this.data.person)
  698. }else{
  699. MWF.xDesktop.notice("error", {x: "right", y:"top"}, MWF.SelectorLP.noPerson.replace(/{name}/g, this.data.name));
  700. if (callback) callback();
  701. }
  702. }else{
  703. if (callback) callback();
  704. }
  705. },
  706. _getShowName: function(){
  707. return this.data.name+((this.data.unitLevelName) ? "("+this.data.unitLevelName+")" : "");
  708. },
  709. _getTtiteText: function(){
  710. return this.data.name+((this.data.unitLevelName) ? "("+this.data.unitLevelName+")" : "");
  711. },
  712. _setIcon: function(){
  713. var style = this.selector.options.style;
  714. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/personicon.png)");
  715. },
  716. check: function(){
  717. if (this.selector.items.length){
  718. var isPerson = this.selector.options.resultType === "person";
  719. var items = this.selector.items.filter(function(item, index){
  720. if( isPerson ){
  721. return (item.data.person && item.data.person === this.data.id) ||
  722. ( item.data.id && item.data.id === this.data.person) ||
  723. ( item.data.distinguishedName && item.data.distinguishedName === this.data.distinguishedName );
  724. }else{
  725. return item.data.distinguishedName === this.data.distinguishedName;
  726. }
  727. }.bind(this));
  728. this.items = items;
  729. if (items.length){
  730. items.each(function(item){
  731. item.selectedItem = this;
  732. item.setSelected();
  733. if( this.selector.selectType == "identity" && ( this.selector.options.showSelectedCount || this.selector.options.isCheckStatus ) ){
  734. if(item.category && item.category._addSelectedCount )item.category._addSelectedCount( 1, true );
  735. }
  736. }.bind(this));
  737. }
  738. }
  739. if( this.afterCheck )this.afterCheck();
  740. }
  741. });
  742. MWF.xApplication.Selector.Identity.ItemCategory = new Class({
  743. Extends: MWF.xApplication.Selector.Person.ItemCategory,
  744. createNode: function(){
  745. this.node = new Element("div", {
  746. "styles": this.selector.css.selectorItemCategory_department,
  747. "title" : this._getTtiteText()
  748. }).inject(this.container);
  749. },
  750. _addSelectedCount : function( count, nested ){
  751. var c = ( this._getSelectedCount() || 0 ) + count;
  752. this.selectedCount = c;
  753. this.checkCountAndStatus( c );
  754. if( nested && this.category && this.category._addSelectedCount ){
  755. this.category._addSelectedCount(count, nested);
  756. }
  757. },
  758. checkCountAndStatus: function( count ){
  759. if( this.selector.options.showSelectedCount ){
  760. this.selectedCountNode.set("text", count ? "(" + count + ")" : "" );
  761. }
  762. if( this.selector.options.isCheckStatus && this.selectAllNode ){
  763. var total = this._getTotalCount();
  764. if( total ){
  765. var styles;
  766. if( count >= total ){
  767. styles = this.selector.css.selectorItemCategoryActionNode_selectAll_selected;
  768. this.isSelectedSome = false;
  769. this.isSelectedAll = true;
  770. }else if( count > 0 ){
  771. styles = this.selector.css.selectorItemCategoryActionNode_selectsome_selected;
  772. this.isSelectedSome = true;
  773. this.isSelectedAll = false;
  774. }else{
  775. styles = this.selector.css.selectorItemCategoryActionNode_selectAll;
  776. this.isSelectedSome = false;
  777. this.isSelectedAll = false;
  778. }
  779. this.selectAllNode.setStyles( styles );
  780. }
  781. }
  782. },
  783. _getShowName: function(){
  784. // if( this._getTotalCount && this._getSelectedCount ){
  785. // return "" + this._getTotalCount() + "-" + this._getSelectedCount() + "-" + this.data.name ;
  786. // }else{
  787. return this.data.name;
  788. // }
  789. },
  790. _getTotalCount : function(){
  791. if( !this.selector.allUnitObject )return 0;
  792. var unit = this.selector.allUnitObject[this.data.levelName];
  793. var count = unit ? unit.subNestedIdentityCount : 0;
  794. return count;
  795. },
  796. _getSelectedCount : function(){
  797. if( typeOf(this.selectedCount) === "number" )return this.selectedCount;
  798. if( !this.selector.allUnitObject )return 0;
  799. var unit = this.selector.allUnitObject[this.data.levelName];
  800. var count = unit ? unit.selectedNestedIdentityCount : 0;
  801. this.selectedCount = count;
  802. return count;
  803. },
  804. _setIcon: function(){
  805. var style = this.selector.options.style;
  806. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/companyicon.png)");
  807. },
  808. _beforeSelectAll : function( _selectAllFun ){
  809. if( this.selector.options.ignorePerson ){
  810. _selectAllFun();
  811. return;
  812. }
  813. //批量获取个人
  814. var object = {};
  815. if( this.selector.options.resultType === "person" ){
  816. this.subItems.each( function(item){
  817. var isPerson = false;
  818. if( item.data && item.data.distinguishedName ){
  819. var dn = item.data.distinguishedName;
  820. if( dn.substr(dn.length-1, 1).toLowerCase() === "p" )isPerson = true;
  821. }
  822. if( !isPerson && !item.data.woPerson && item.data.person ){
  823. object[ item.data.person ] = item;
  824. }
  825. }.bind(this))
  826. }else{
  827. this.subItems.each( function (item) {
  828. if (!item.data.woPerson && item.data.person ){
  829. object[ item.data.person ] = item;
  830. }
  831. }.bind(this))
  832. }
  833. var keys = Object.keys( object );
  834. if( keys.length > 0 ){
  835. o2.Actions.load("x_organization_assemble_express").PersonAction.listObject({"personList":keys}, function (json) {
  836. json.data.each( function ( p ){
  837. if(object[ p.id ])object[ p.id ].data.woPerson = p;
  838. }.bind(this));
  839. _selectAllFun();
  840. })
  841. }else{
  842. _selectAllFun();
  843. }
  844. },
  845. clickItem: function( callback ){
  846. if (this._hasChild() && !this.loading){
  847. var firstLoaded = !this.loaded;
  848. this.loading = true;
  849. this.loadSub(function(){
  850. this.loading = false;
  851. if( firstLoaded ){
  852. if( !this.selector.isFlatCategory ){
  853. this.children.setStyles({"display": "block", "height": "auto"});
  854. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_expand);
  855. this.isExpand = true;
  856. }
  857. // this.checkSelectAll();
  858. }else{
  859. var display = this.children.getStyle("display");
  860. if (display === "none"){
  861. this.children.setStyles({"display": "block", "height": "auto"});
  862. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_expand);
  863. this.isExpand = true;
  864. }else{
  865. this.children.setStyles({"display": "none", "height": "0px"});
  866. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_collapse);
  867. this.isExpand = false;
  868. }
  869. }
  870. if(callback)callback();
  871. }.bind(this));
  872. }
  873. },
  874. loadSub: function(callback){
  875. this._loadSub( function( firstLoad ) {
  876. if(callback)callback();
  877. }.bind(this))
  878. },
  879. _loadSub: function(callback){
  880. if (!this.loaded){
  881. // if (this.selector.options.dutys && this.selector.options.dutys.length){
  882. // var ids = [];
  883. // var object = {};
  884. // this.selector.options.dutys.each(function(duty){
  885. // this.selector.orgAction.listIdentityWidthUnitWithDutyName(this.data.distinguishedName, duty, function(json){
  886. // if (json.data && json.data.length){
  887. // ids = ids.concat(json.data);
  888. // }
  889. // }.bind(this), null, false);
  890. //
  891. // ids.each(function(idSubData){
  892. // if( !this.selector.isExcluded( idSubData ) && !object[ idSubData.id || idSubData.distinguishedName ]) {
  893. // var item = this.selector._newItem(idSubData, this.selector, this.children, this.level + 1, this);
  894. // this.selector.items.push(item);
  895. // if(this.subItems)this.subItems.push( item );
  896. // object[ idSubData.id || idSubData.distinguishedName ] = true;
  897. // }
  898. // }.bind(this));
  899. // }.bind(this));
  900. //
  901. // if( this.selector.options.expandSubEnable ){
  902. // this.selector.orgAction.listSubUnitDirect(function(json){
  903. // json.data.each(function(subData){
  904. // if( !this.selector.isExcluded( subData ) ) {
  905. // var category = this.selector._newItemCategory("ItemUnitCategory", subData, this.selector, this.children, this.level + 1, this);
  906. // this.subCategorys.push( category );
  907. // }
  908. // }.bind(this));
  909. // this.loaded = true;
  910. // if(callback)callback();
  911. // }.bind(this), null, this.data.distinguishedName);
  912. // }else{
  913. // this.loaded = true;
  914. // if(callback)callback();
  915. // }
  916. // }else{
  917. var loadSubUnit = function () {
  918. if( this.selector.options.expandSubEnable && !this.categoryLoaded ){
  919. this.selector.orgAction.listSubUnitDirect(function(json){
  920. json.data.each(function(subData){
  921. if( !this.selector.isExcluded( subData ) ) {
  922. var category = this.selector._newItemCategory("ItemUnitCategory", subData, this.selector, this.children, this.level + 1, this);
  923. this.subCategorys.push( category );
  924. }
  925. }.bind(this));
  926. this.loaded = true;
  927. if (callback) callback( true );
  928. }.bind(this), null, this.data.distinguishedName);
  929. }else{
  930. this.loaded = true;
  931. if (callback) callback( true );
  932. }
  933. }.bind(this);
  934. if( !this.itemLoaded ){
  935. this.selector.orgAction.listIdentityWithUnit(function(idJson){
  936. idJson.data.each(function(idSubData){
  937. if( !this.selector.isExcluded( idSubData ) ) {
  938. var item = this.selector._newItem(idSubData, this.selector, this.children, this.level + 1, this);
  939. this.selector.items.push(item);
  940. if(this.subItems)this.subItems.push( item );
  941. }
  942. }.bind(this));
  943. loadSubUnit();
  944. }.bind(this), null, this.data.distinguishedName);
  945. }else{
  946. loadSubUnit();
  947. }
  948. // }
  949. }else{
  950. if (callback) callback( );
  951. }
  952. },
  953. _hasChild: function(){
  954. var uCount = (this.data.subDirectUnitCount) ? this.data.subDirectUnitCount : 0;
  955. var iCount = (this.data.subDirectIdentityCount) ? this.data.subDirectIdentityCount : 0;
  956. return uCount + iCount;
  957. },
  958. _hasChildCategory: function(){
  959. return (this.data.subDirectUnitCount) ? this.data.subDirectUnitCount : 0;
  960. },
  961. _hasChildItem: function(){
  962. return (this.data.subDirectIdentityCount) ? this.data.subDirectIdentityCount : 0;
  963. },
  964. afterLoad: function(){
  965. if (this.level===1) this.clickItem();
  966. if( this.selector.options.showSelectedCount || this.selector.options.isCheckStatus ){
  967. var count = this._getSelectedCount();
  968. this.checkCountAndStatus( count );
  969. }
  970. },
  971. //for flat category start
  972. clickFlatCategoryItem: function( callback, hidden ){
  973. if (this._hasChildItem()){
  974. var firstLoaded = !this.itemLoaded;
  975. this.loadItemChildren(function(){
  976. if( hidden ){
  977. //alert("hidden")
  978. this.children.setStyles({"display": "none", "height": "0px"});
  979. this.node.setStyles( this.selector.css.flatCategoryItemNode );
  980. this.isExpand = false;
  981. }else if( firstLoaded ){
  982. this.children.setStyles({"display": "block", "height": "auto"});
  983. this.node.setStyles( this.selector.css.flatCategoryItemNode_selected );
  984. this.isExpand = true;
  985. }else{
  986. var display = this.children.getStyle("display");
  987. if (display === "none"){
  988. this.children.setStyles({"display": "block", "height": "auto"});
  989. this.node.setStyles( this.selector.css.flatCategoryItemNode_selected );
  990. this.isExpand = true;
  991. }else{
  992. this.children.setStyles({"display": "none", "height": "0px"});
  993. this.node.setStyles( this.selector.css.flatCategoryItemNode );
  994. this.isExpand = false;
  995. }
  996. }
  997. if(callback)callback();
  998. }.bind(this));
  999. }
  1000. },
  1001. loadCategoryChildren: function(callback){
  1002. if (!this.categoryLoaded){
  1003. if( this.selector.options.expandSubEnable ){
  1004. this.selector.orgAction.listSubUnitDirect(function(json){
  1005. json.data.each(function(subData){
  1006. if( !this.selector.isExcluded( subData ) ) {
  1007. var category = this.selector._newItemCategory("ItemUnitCategory", subData, this.selector, this.children, this.level + 1, this);
  1008. this.subCategorys.push( category );
  1009. }
  1010. }.bind(this));
  1011. this.categoryLoaded = true;
  1012. if (callback) callback();
  1013. }.bind(this), null, this.data.distinguishedName);
  1014. }else{
  1015. if (callback) callback();
  1016. }
  1017. }else{
  1018. if (callback) callback( );
  1019. }
  1020. },
  1021. loadItemChildren: function(callback){
  1022. if (!this.itemLoaded){
  1023. // if (this.selector.options.dutys && this.selector.options.dutys.length){
  1024. // var ids = [];
  1025. // var object = {};
  1026. // this.selector.options.dutys.each(function(duty){
  1027. // this.selector.orgAction.listIdentityWidthUnitWithDutyName(this.data.distinguishedName, duty, function(json){
  1028. // if (json.data && json.data.length){
  1029. // ids = ids.concat(json.data);
  1030. // }
  1031. // }.bind(this), null, false);
  1032. //
  1033. // ids.each(function(idSubData){
  1034. // if( !this.selector.isExcluded( idSubData ) && !object[ idSubData.id || idSubData.distinguishedName ]) {
  1035. // var item = this.selector._newItem(idSubData, this.selector, this.children, this.level + 1, this);
  1036. // this.selector.items.push(item);
  1037. // if(this.subItems)this.subItems.push( item );
  1038. // object[ idSubData.id || idSubData.distinguishedName ] = true;
  1039. // }
  1040. // this.itemLoaded = true;
  1041. // }.bind(this));
  1042. // }.bind(this));
  1043. // if (callback) callback();
  1044. // }else{
  1045. this.selector.orgAction.listIdentityWithUnit(function(idJson){
  1046. idJson.data.each(function(idSubData){
  1047. if( !this.selector.isExcluded( idSubData ) ) {
  1048. var item = this.selector._newItem(idSubData, this.selector, this.children, this.level + 1, this);
  1049. this.selector.items.push(item);
  1050. if(this.subItems)this.subItems.push( item );
  1051. }
  1052. this.itemLoaded = true;
  1053. }.bind(this));
  1054. if (callback) callback();
  1055. }.bind(this), null, this.data.distinguishedName);
  1056. // }
  1057. }else{
  1058. if (callback) callback( );
  1059. }
  1060. }
  1061. //for flat category end
  1062. });
  1063. MWF.xApplication.Selector.Identity.ItemUnitCategory = new Class({
  1064. Extends: MWF.xApplication.Selector.Identity.ItemCategory
  1065. });
  1066. MWF.xApplication.Selector.Identity.ItemGroupCategory = new Class({
  1067. Extends: MWF.xApplication.Selector.Identity.ItemCategory,
  1068. createNode: function(){
  1069. this.node = new Element("div", {
  1070. "styles": this.selector.css.selectorItemCategory
  1071. }).inject(this.container);
  1072. },
  1073. _setIcon: function(){
  1074. var style = this.selector.options.style;
  1075. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/groupicon.png)");
  1076. },
  1077. _getTotalCount : function(){
  1078. if( !this.selector.allGroupObjectByDn )return 0;
  1079. var group = this.selector.allGroupObjectByDn[this.data.distinguishedName];
  1080. var count = group ? group.subNestedIdentityCount : 0;
  1081. return count;
  1082. },
  1083. _getSelectedCount : function(){
  1084. debugger;
  1085. if( typeOf(this.selectedCount) === "number" )return this.selectedCount;
  1086. if( !this.selector.allGroupObjectByDn )return 0;
  1087. var group = this.selector.allGroupObjectByDn[this.data.distinguishedName];
  1088. var count = group ? group.selectedNestedIdentityCount : 0;
  1089. this.selectedCount = count;
  1090. return count;
  1091. },
  1092. loadSub: function(callback){
  1093. if (!this.loaded){
  1094. var personContainer, identityContainer, groupContainer, unitContainer;
  1095. if( this.data.personList )personContainer = new Element("div").inject( this.children );
  1096. if( this.data.identityList )identityContainer = new Element("div").inject( this.children );
  1097. if( this.data.groupList )groupContainer = new Element("div").inject( this.children );
  1098. if( this.data.unitList )unitContainer = new Element("div").inject( this.children );
  1099. var personLoadedCount = 0;
  1100. var identityLoadedCount = 0;
  1101. var unitLoadedCount = 0;
  1102. var groupLoadedCount = 0;
  1103. var checkCallback = function( type, count ){
  1104. var addCount = count || 1;
  1105. if( !this.selector.options.expandSubEnable ){
  1106. if( type === "person" )personLoadedCount += addCount;
  1107. if( type === "identity" )identityLoadedCount += addCount;
  1108. if(
  1109. (!this.data.personList || this.data.personList.length === 0 || this.data.personList.length == personLoadedCount) &&
  1110. (!this.data.identityList || this.data.identityList.length === 0 || this.data.identityList.length == identityLoadedCount)
  1111. ){
  1112. this.loaded = true;
  1113. if (callback) callback();
  1114. }
  1115. }else{
  1116. if( type === "person" )personLoadedCount += addCount;
  1117. if( type === "identity" )identityLoadedCount += addCount;
  1118. if( type === "unit" )unitLoadedCount += addCount;
  1119. if( type === "group" )groupLoadedCount += addCount;
  1120. if( ( !this.data.personList || this.data.personList.length === 0 || this.data.personList.length == personLoadedCount ) &&
  1121. ( !this.data.identityList || this.data.identityList.length === 0 || this.data.identityList.length == identityLoadedCount )&&
  1122. ( !this.data.unitList || this.data.unitList.length === 0 || this.data.unitList.length == unitLoadedCount ) &&
  1123. ( !this.data.groupList || this.data.groupList.length === 0 || this.data.groupList.length == groupLoadedCount ) ){
  1124. this.loaded = true;
  1125. if (callback) callback();
  1126. }
  1127. }
  1128. }.bind(this);
  1129. checkCallback();
  1130. if( this.data.identityList && this.data.identityList.length > 0 ){
  1131. if( this.selector.options.resultType === "person" ) {
  1132. //根据身份id批量获取人员对象
  1133. o2.Actions.load("x_organization_assemble_express").PersonAction.listWithIdentityObject({
  1134. identityList : this.data.identityList
  1135. }, function (json) {
  1136. this.selector.includeObject.loadPersonItem( json, identityContainer, this.level + 1, this);
  1137. checkCallback("identity", this.data.identityList.length )
  1138. }.bind(this), function () {
  1139. checkCallback("identity", this.data.identityList.length )
  1140. }.bind(this))
  1141. }else{
  1142. //根据身份id批量获取身份对象
  1143. o2.Actions.load("x_organization_assemble_express").IdentityAction.listObject({
  1144. identityList : this.data.identityList
  1145. }, function (json) {
  1146. this.selector.includeObject.loadIdentityItem( json, identityContainer, this.level + 1, this);
  1147. checkCallback("identity", this.data.identityList.length )
  1148. }.bind(this), function () {
  1149. checkCallback("identity", this.data.identityList.length )
  1150. }.bind(this))
  1151. }
  1152. }
  1153. if( this.data.personList && this.data.personList.length > 0 ){
  1154. if( this.selector.options.resultType === "person" ) {
  1155. //根据人员d批量获取人员对象
  1156. o2.Actions.load("x_organization_assemble_express").PersonAction.listObject({
  1157. personList : this.data.personList
  1158. }, function (json) {
  1159. this.selector.includeObject.loadPersonItem( json, personContainer, this.level + 1, this);
  1160. checkCallback("person", this.data.personList.length )
  1161. }.bind(this), function () {
  1162. checkCallback("person", this.data.personList.length )
  1163. }.bind(this))
  1164. }else{
  1165. //根据人员id批量获取身份对象
  1166. o2.Actions.load("x_organization_assemble_express").IdentityAction.listWithPersonObject({
  1167. personList : this.data.personList
  1168. }, function (json) {
  1169. this.selector.includeObject.loadIdentityItem( json, personContainer, this.level + 1, this);
  1170. checkCallback("person", this.data.personList.length )
  1171. }.bind(this), function () {
  1172. checkCallback("person", this.data.personList.length )
  1173. }.bind(this))
  1174. }
  1175. }
  1176. // ( this.data.personList || [] ).each( function(p){
  1177. // if( this.selector.options.resultType === "person" ){
  1178. // this.selector.orgAction.getPerson(function (json) {
  1179. // this.selector.includeObject.loadPersonItem(json, this.children, this.level + 1, this );
  1180. // checkCallback("person");
  1181. // }.bind(this), function(){ checkCallback("person") }, p );
  1182. // }else{
  1183. // this.selector.orgAction.listIdentityByPerson(function(json){
  1184. // this.selector.includeObject.loadIdentityItem(json, this.children, this.level + 1, this);
  1185. // checkCallback("person")
  1186. // }.bind(this), function(){ checkCallback("person") }, p );
  1187. // }
  1188. // }.bind(this));
  1189. //list 服务不能获取下级数量
  1190. // if( this.selector.options.expandSubEnable ){
  1191. // o2.Actions.load("x_organization_assemble_express").UnitAction.listObject({
  1192. // unitList : this.data.unitList
  1193. // }, function (json) {
  1194. // this.selector.includeObject.loadUnitItem( json, this.children, this.level + 1, this);
  1195. // checkCallback("unit", this.data.unitList.length )
  1196. // }.bind(this), function () {
  1197. // checkCallback("unit", this.data.unitList.length )
  1198. // }.bind(this))
  1199. //
  1200. //
  1201. // o2.Actions.load("x_organization_assemble_express").GroupAction.listObject({
  1202. // groupList : this.data.groupList
  1203. // }, function (json) {
  1204. // this.selector.includeObject.loadGroupItem(json, this.children, this.level + 1, this);
  1205. // checkCallback("group", this.data.groupList.length )
  1206. // }.bind(this), function () {
  1207. // checkCallback("group", this.data.groupList.length )
  1208. // }.bind(this))
  1209. // }
  1210. if( this.selector.options.expandSubEnable ){
  1211. ( this.data.unitList || [] ).each( function(u){
  1212. this.selector.orgAction.getUnit(function (json) {
  1213. this.selector.includeObject.loadUnitItem(json, unitContainer, this.level + 1, this);
  1214. checkCallback("unit");
  1215. }.bind(this), function(){ checkCallback("unit") }, u );
  1216. }.bind(this));
  1217. ( this.data.groupList || [] ).each( function(g){
  1218. this.selector.orgAction.getGroup(function (json) {
  1219. this.selector.includeObject.loadGroupItem(json, groupContainer, this.level + 1, this);
  1220. checkCallback("group");
  1221. }.bind(this), function(){ checkCallback("group") }, g );
  1222. }.bind(this));
  1223. }
  1224. }else{
  1225. if (callback) callback( );
  1226. }
  1227. },
  1228. loadCategoryChildren: function(callback){
  1229. if (!this.categoryLoaded){
  1230. var groupContainer, unitContainer;
  1231. if( this.data.groupList )groupContainer = new Element("div").inject( this.children );
  1232. if( this.data.unitList )unitContainer = new Element("div").inject( this.children );
  1233. var unitLoadedCount = 0;
  1234. var groupLoadedCount = 0;
  1235. var checkCallback = function( type, count ){
  1236. var addCount = count || 1;
  1237. if( !this.selector.options.expandSubEnable ){
  1238. this.categoryLoaded = true;
  1239. }else{
  1240. if( type === "unit" )unitLoadedCount += addCount;
  1241. if( type === "group" )groupLoadedCount += addCount;
  1242. if( ( !this.data.unitList || this.data.unitList.length === 0 || this.data.unitList.length == unitLoadedCount ) &&
  1243. ( !this.data.groupList || this.data.groupList.length === 0 || this.data.groupList.length == groupLoadedCount ) ){
  1244. this.categoryLoaded = true;
  1245. if (callback) callback();
  1246. }
  1247. }
  1248. }.bind(this);
  1249. checkCallback();
  1250. //list 服务不能获取下级数量
  1251. // if( this.selector.options.expandSubEnable ){
  1252. // o2.Actions.load("x_organization_assemble_express").UnitAction.listObject({
  1253. // unitList : this.data.unitList
  1254. // }, function (json) {
  1255. // this.selector.includeObject.loadUnitItem( json, this.children, this.level + 1, this);
  1256. // checkCallback("unit", this.data.unitList.length )
  1257. // }.bind(this), function () {
  1258. // checkCallback("unit", this.data.unitList.length )
  1259. // }.bind(this))
  1260. //
  1261. //
  1262. // o2.Actions.load("x_organization_assemble_express").GroupAction.listObject({
  1263. // groupList : this.data.groupList
  1264. // }, function (json) {
  1265. // this.selector.includeObject.loadGroupItem(json, this.children, this.level + 1, this);
  1266. // checkCallback("group", this.data.groupList.length )
  1267. // }.bind(this), function () {
  1268. // checkCallback("group", this.data.groupList.length )
  1269. // }.bind(this))
  1270. // }
  1271. if( this.selector.options.expandSubEnable ){
  1272. ( this.data.unitList || [] ).each( function(u){
  1273. this.selector.orgAction.getUnit(function (json) {
  1274. this.selector.includeObject.loadUnitItem(json, unitContainer, this.level + 1, this);
  1275. checkCallback("unit");
  1276. }.bind(this), function(){ checkCallback("unit") }, u );
  1277. }.bind(this));
  1278. ( this.data.groupList || [] ).each( function(g){
  1279. this.selector.orgAction.getGroup(function (json) {
  1280. this.selector.includeObject.loadGroupItem(json, groupContainer, this.level + 1, this);
  1281. checkCallback("group");
  1282. }.bind(this), function(){ checkCallback("group") }, g );
  1283. }.bind(this));
  1284. }
  1285. }else{
  1286. if (callback) callback( );
  1287. }
  1288. },
  1289. loadItemChildren: function(callback){
  1290. if (!this.itemLoaded){
  1291. var personContainer, identityContainer;
  1292. if( this.data.personList )personContainer = new Element("div").inject( this.children );
  1293. if( this.data.identityList )identityContainer = new Element("div").inject( this.children );
  1294. var personLoadedCount = 0;
  1295. var identityLoadedCount = 0;
  1296. var checkCallback = function( type, count ){
  1297. var addCount = count || 1;
  1298. if( type === "person" )personLoadedCount += addCount;
  1299. if( type === "identity" )identityLoadedCount += addCount;
  1300. if(
  1301. (!this.data.personList || this.data.personList.length === 0 || this.data.personList.length == personLoadedCount) &&
  1302. (!this.data.identityList || this.data.identityList.length === 0 || this.data.identityList.length == identityLoadedCount)
  1303. ){
  1304. this.itemLoaded = true;
  1305. if (callback) callback();
  1306. }
  1307. }.bind(this);
  1308. checkCallback();
  1309. if( this.data.identityList && this.data.identityList.length > 0 ){
  1310. if( this.selector.options.resultType === "person" ) {
  1311. //根据身份id批量获取人员对象
  1312. o2.Actions.load("x_organization_assemble_express").PersonAction.listWithIdentityObject({
  1313. identityList : this.data.identityList
  1314. }, function (json) {
  1315. this.selector.includeObject.loadPersonItem( json, identityContainer, this.level + 1, this);
  1316. checkCallback("identity", this.data.identityList.length )
  1317. }.bind(this), function () {
  1318. checkCallback("identity", this.data.identityList.length )
  1319. }.bind(this))
  1320. }else{
  1321. //根据身份id批量获取身份对象
  1322. o2.Actions.load("x_organization_assemble_express").IdentityAction.listObject({
  1323. identityList : this.data.identityList
  1324. }, function (json) {
  1325. this.selector.includeObject.loadIdentityItem( json, identityContainer, this.level + 1, this);
  1326. checkCallback("identity", this.data.identityList.length )
  1327. }.bind(this), function () {
  1328. checkCallback("identity", this.data.identityList.length )
  1329. }.bind(this))
  1330. }
  1331. }
  1332. if( this.data.personList && this.data.personList.length > 0 ){
  1333. if( this.selector.options.resultType === "person" ) {
  1334. //根据人员d批量获取人员对象
  1335. o2.Actions.load("x_organization_assemble_express").PersonAction.listObject({
  1336. personList : this.data.personList
  1337. }, function (json) {
  1338. this.selector.includeObject.loadPersonItem( json, personContainer, this.level + 1, this);
  1339. checkCallback("person", this.data.personList.length )
  1340. }.bind(this), function () {
  1341. checkCallback("person", this.data.personList.length )
  1342. }.bind(this))
  1343. }else{
  1344. //根据人员id批量获取身份对象
  1345. o2.Actions.load("x_organization_assemble_express").IdentityAction.listWithPersonObject({
  1346. personList : this.data.personList
  1347. }, function (json) {
  1348. this.selector.includeObject.loadIdentityItem( json, personContainer, this.level + 1, this);
  1349. checkCallback("person", this.data.personList.length )
  1350. }.bind(this), function () {
  1351. checkCallback("person", this.data.personList.length )
  1352. }.bind(this))
  1353. }
  1354. }
  1355. // ( this.data.personList || [] ).each( function(p){
  1356. // if( this.selector.options.resultType === "person" ){
  1357. // this.selector.orgAction.getPerson(function (json) {
  1358. // this.selector.includeObject.loadPersonItem(json, this.children, this.level + 1, this );
  1359. // checkCallback("person");
  1360. // }.bind(this), function(){ checkCallback("person") }, p );
  1361. // }else{
  1362. // this.selector.orgAction.listIdentityByPerson(function(json){
  1363. // this.selector.includeObject.loadIdentityItem(json, this.children, this.level + 1, this);
  1364. // checkCallback("person")
  1365. // }.bind(this), function(){ checkCallback("person") }, p );
  1366. // }
  1367. // }.bind(this));
  1368. }else{
  1369. if (callback) callback( );
  1370. }
  1371. },
  1372. _hasChild: function(){
  1373. var uCount = (this.data.unitList) ? this.data.unitList.length : 0;
  1374. var gCount = (this.data.groupList) ? this.data.groupList.length : 0;
  1375. var pCount = (this.data.personList) ? this.data.personList.length : 0;
  1376. var iCount = (this.data.identityList) ? this.data.identityList.length : 0;
  1377. return uCount + gCount + pCount + iCount;
  1378. },
  1379. _hasChildCategory: function(){
  1380. var uCount = (this.data.unitList) ? this.data.unitList.length : 0;
  1381. var gCount = (this.data.groupList) ? this.data.groupList.length : 0;
  1382. return uCount + gCount;
  1383. },
  1384. _hasChildItem: function(){
  1385. var pCount = (this.data.personList) ? this.data.personList.length : 0;
  1386. var iCount = (this.data.identityList) ? this.data.identityList.length : 0;
  1387. return pCount + iCount;
  1388. }
  1389. });
  1390. MWF.xApplication.Selector.Identity.ItemRoleCategory = new Class({
  1391. Extends: MWF.xApplication.Selector.Person.ItemCategory,
  1392. _getShowName: function(){
  1393. return this.data.name;
  1394. },
  1395. _setIcon: function(){
  1396. var style = this.selector.options.style;
  1397. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/roleicon.png)");
  1398. }
  1399. });
  1400. MWF.xApplication.Selector.Identity.Include = new Class({
  1401. Implements: [Options, Events],
  1402. options: {
  1403. "include" : [], //增加的可选项
  1404. "resultType" : "", //可以设置成个人,那么结果返回个人
  1405. "expandSubEnable" : true //是否允许展开下一层
  1406. },
  1407. initialize: function(selector, itemAreaNode, options){
  1408. this.setOptions(options);
  1409. this.selector = selector;
  1410. this.itemAreaNode = $(itemAreaNode);
  1411. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  1412. },
  1413. load : function( callback ){
  1414. if( !this.options.include || this.options.include.length === 0 ){
  1415. this.fireEvent("afterLoad");
  1416. if(callback)callback();
  1417. return;
  1418. }
  1419. var count = 0;
  1420. var checkCallback = function () {
  1421. count++;
  1422. if( count === this.options.include.length ){
  1423. this.fireEvent("afterLoad");
  1424. if(callback)callback();
  1425. }
  1426. }.bind(this);
  1427. this.includeAreaNode = new Element( "div.includeAreaNode").inject( this.itemAreaNode, "top" );
  1428. if( this.selector.isFlatCategory ){
  1429. this.flatCategoryAreaNode = new Element( "div.includeFlatCategoryAreaNode").inject( this.selector.flatCategoryNode, "top" );
  1430. }
  1431. //this.includeIdentityAreaNode = new Element( "div").inject( this.includeAreaNode );
  1432. //this.includePersonAreaNode = new Element( "div").inject( this.includeAreaNode );
  1433. //this.includeUnitAreaNode = new Element( "div").inject( this.includeAreaNode );
  1434. //this.includeGroupAreaNode = new Element( "div").inject( this.includeAreaNode );
  1435. this.options.include.each( function( d ){
  1436. var container = new Element("div").inject( this.includeAreaNode );
  1437. var flatCategoryContainer;
  1438. if( this.flatCategoryAreaNode ){
  1439. flatCategoryContainer = new Element("div").inject( this.flatCategoryAreaNode );
  1440. }
  1441. if (typeOf(d)==="string"){
  1442. var arr = d.split("@");
  1443. var flag = arr[ arr.length - 1].toLowerCase();
  1444. if( flag === "u" ){
  1445. this.orgAction.listUnitByKey(function(json){
  1446. this.loadUnitItem(json, container, null, null, flatCategoryContainer);
  1447. checkCallback();
  1448. }.bind(this), checkCallback, d);
  1449. }else if( flag === "i" ) {
  1450. this.orgAction.listIdentityByKey(function (json) {
  1451. this.loadIdentityItem(json, container, null, null, true );
  1452. checkCallback();
  1453. }.bind(this), checkCallback, d);
  1454. }else if( flag === "g" ){
  1455. this.orgAction.listGroupByKey(function(json){
  1456. this.loadGroupItem( json , container, null, null, flatCategoryContainer);
  1457. checkCallback();
  1458. }.bind(this), checkCallback, d);
  1459. }else if( flag === "p" ){
  1460. if( this.options.resultType === "person" ){
  1461. this.orgAction.getPerson(function (json){
  1462. this.loadPersonItem( json , container, null, null, true);
  1463. checkCallback();
  1464. }.bind(this), checkCallback, d);
  1465. }else{
  1466. this.orgAction.listIdentityByPerson(function(json){
  1467. this.loadIdentityItem(json, container , null, null, true);
  1468. checkCallback();
  1469. }.bind(this), checkCallback, d);
  1470. }
  1471. }else{
  1472. if( this.options.resultType === "person" ){
  1473. this.orgAction.listPersonByKey(function (json) {
  1474. this.loadPersonItem( json , container, null, null, true);
  1475. checkCallback();
  1476. }.bind(this), checkCallback, d);
  1477. }else{
  1478. this.orgAction.listIdentityByKey(function(json){
  1479. this.loadIdentityItem(json, container, null, null, true);
  1480. checkCallback();
  1481. }.bind(this), checkCallback, d);
  1482. }
  1483. }
  1484. }else{
  1485. var arr = d.distinguishedName.split("@");
  1486. var flag = arr[ arr.length - 1].toLowerCase();
  1487. if( flag === "u" ) {
  1488. this.orgAction.getUnit(function (json) {
  1489. this.loadUnitItem(json, container, null, null, flatCategoryContainer);
  1490. checkCallback();
  1491. }.bind(this), checkCallback, d.distinguishedName);
  1492. }else if( flag === "i" ){
  1493. this.orgAction.getIdentity(function (json) {
  1494. this.loadIdentityItem(json, container, null, null, true);
  1495. checkCallback();
  1496. }.bind(this), checkCallback, d.distinguishedName);
  1497. }else if( flag === "g" ){
  1498. this.orgAction.getGroup(function(json){
  1499. this.loadGroupItem( json , container, null, null, flatCategoryContainer);
  1500. checkCallback();
  1501. }.bind(this), checkCallback, d.distinguishedName, null, null, true);
  1502. }else if( flag === "p" ){
  1503. if( this.options.resultType === "person" ){
  1504. this.orgAction.getPerson(function (json) {
  1505. this.loadPersonItem(json, container, null, null, true);
  1506. checkCallback();
  1507. }.bind(this), checkCallback, d.distinguishedName);
  1508. }else{
  1509. this.orgAction.listIdentityByPerson(function(json){
  1510. this.loadIdentityItem(json, container, null, null, true);
  1511. checkCallback();
  1512. }.bind(this), checkCallback, d.distinguishedName);
  1513. }
  1514. }else{
  1515. if( this.options.resultType === "person" ){
  1516. this.orgAction.getPerson(function (json) {
  1517. this.loadPersonItem(json, container, null, null, true);
  1518. checkCallback();
  1519. }.bind(this), checkCallback, d.distinguishedName);
  1520. }else{
  1521. this.orgAction.getIdentity(function (json) {
  1522. this.loadIdentityItem(json, container, null, null, true);
  1523. checkCallback();
  1524. }.bind(this), checkCallback, d.distinguishedName);
  1525. }
  1526. }
  1527. //var category = this._newItemCategory("ItemCategory", unit, this, this.itemAreaNode);
  1528. }
  1529. }.bind(this))
  1530. },
  1531. loadPersonItem : function( json, container, level, category, isIncludedPerson ){
  1532. if( !json.data )return;
  1533. var array = typeOf( json.data ) === "array" ? json.data : [json.data];
  1534. array.each(function(data){
  1535. if( !this.selector.isExcluded( data ) ) {
  1536. if(!this.includePerson)this.includePerson = [];
  1537. if(isIncludedPerson)this.includePerson.push( data.distinguishedName );
  1538. if(!this.includePersonObject)this.includePersonObject = [];
  1539. if(isIncludedPerson)this.includePersonObject.push( data );
  1540. var item = this.selector._newItem(data, this.selector, container || this.includeAreaNode, level || 1, category);
  1541. this.selector.items.push(item);
  1542. if( category && category.subItems ){
  1543. category.subItems.push( item );
  1544. }else if(this.selector.subItems){
  1545. this.selector.subItems.push( item )
  1546. }
  1547. }
  1548. }.bind(this));
  1549. },
  1550. loadIdentityItem : function( json, container, level, category, isIncludedIdentity ){
  1551. if( !json.data )return;
  1552. var array = typeOf( json.data ) === "array" ? json.data : [json.data];
  1553. array.each(function(data){
  1554. if( !this.selector.isExcluded( data ) ) {
  1555. if(!this.includeIdentity)this.includeIdentity = [];
  1556. if(isIncludedIdentity)this.includeIdentity.push( data.distinguishedName );
  1557. if(!this.includeIdentityObject)this.includeIdentityObject = [];
  1558. if(isIncludedIdentity)this.includeIdentityObject.push( data );
  1559. var item = this.selector._newItem(data, this.selector, container || this.includeAreaNode, level || 1, category);
  1560. this.selector.items.push(item);
  1561. if( category && category.subItems ){
  1562. category.subItems.push( item );
  1563. }else if(this.selector.subItems){
  1564. this.selector.subItems.push( item )
  1565. }
  1566. }
  1567. }.bind(this));
  1568. },
  1569. loadUnitItem : function( json, container, level, parentCategory, flatCategoryContainer ){
  1570. if( !json.data )return;
  1571. var array = typeOf( json.data ) === "array" ? json.data : [json.data];
  1572. array.each(function(data){
  1573. if( !this.selector.isExcluded( data ) ) {
  1574. if(!this.includeUnit)this.includeUnit = [];
  1575. this.includeUnit.push( data.distinguishedName );
  1576. var category;
  1577. if( flatCategoryContainer ){
  1578. category = this.selector._newItemCategory("ItemUnitCategory", data, this.selector,
  1579. container || this.includeAreaNode, level, parentCategory, true);
  1580. category.nodeContainer = flatCategoryContainer;
  1581. category.load();
  1582. }else{
  1583. category = this.selector._newItemCategory("ItemUnitCategory", data, this.selector,
  1584. container || this.includeAreaNode, level, parentCategory);
  1585. }
  1586. if( parentCategory && parentCategory.subCategorys ){
  1587. parentCategory.subCategorys.push( category )
  1588. }else if(this.selector.subCategorys){
  1589. this.selector.subCategorys.push( category )
  1590. }
  1591. }
  1592. }.bind(this));
  1593. },
  1594. loadGroupItem : function( json, container, level, parentCategory, flatCategoryContainer ){
  1595. if( !json.data )return;
  1596. var array = typeOf( json.data ) === "array" ? json.data : [json.data];
  1597. array.each(function(data){
  1598. if( !this.selector.isExcluded( data ) ) {
  1599. if(!this.includeGroup)this.includeGroup = [];
  1600. this.includeGroup.push( data.distinguishedName );
  1601. var category;
  1602. if( flatCategoryContainer ){
  1603. category = this.selector._newItemCategory("ItemGroupCategory", data, this.selector, container || this.includeAreaNode, level, parentCategory, true);
  1604. category.nodeContainer = flatCategoryContainer;
  1605. category.load();
  1606. }else{
  1607. category = this.selector._newItemCategory("ItemGroupCategory", data, this.selector, container || this.includeAreaNode, level, parentCategory)
  1608. }
  1609. if( parentCategory && parentCategory.subCategorys ){
  1610. parentCategory.subCategorys.push( category )
  1611. }else if(this.selector.subCategorys){
  1612. this.selector.subCategorys.push( category )
  1613. }
  1614. }
  1615. }.bind(this));
  1616. },
  1617. listByFilter : function( type, key, callback ){
  1618. var arr1 = this.listByFilterPerson(key) || [];
  1619. this.listByFilterUnitAndGroup( type, key, function(arr2){
  1620. this.listByFilterGroup( type, key, function(arr3){
  1621. if (callback) callback( arr1.concat( arr2 || [] ).concat( arr3 || [] ) );
  1622. }.bind(this))
  1623. }.bind(this))
  1624. },
  1625. listByFilterPerson : function( key ){
  1626. var identitys = [];
  1627. var persons = [];
  1628. var keyString = typeOf( key )==="string" ? key.toLowerCase() : key.key.toLowerCase();
  1629. if( this.includeIdentityObject && this.includeIdentityObject.length ){
  1630. identitys = this.includeIdentityObject.filter( function(id) {
  1631. return ( id.pinyin || "" ).indexOf(keyString) > -1 || (id.pinyinInitial || "").indexOf(keyString) > -1 || (id.distinguishedName || "").indexOf(keyString) > -1;
  1632. })
  1633. }
  1634. if( this.includePersonObject && this.includePersonObject.length ){
  1635. persons = this.includePersonObject.filter( function(id) {
  1636. return ( id.pinyin || "" ).indexOf(keyString) > -1 || (id.pinyinInitial || "").indexOf(keyString) > -1 || (id.distinguishedName || "").indexOf(keyString) > -1;
  1637. })
  1638. }
  1639. return identitys.concat( persons);
  1640. },
  1641. listByFilterGroup : function( type, key, callback ){
  1642. //根据关键字获取群组内的人员,再转成身份
  1643. var keyString = typeOf( key )==="string" ? key.toLowerCase() : key.key.toLowerCase();
  1644. if( this.includeGroup && this.includeGroup.length ){
  1645. var keyObject = { "key" : keyString, "groupList" : this.includeGroup };
  1646. this.orgAction[ type === "pinyin" ? "listPersonByPinyin" : "listPersonByKey" ](function(json){
  1647. if( this.options.resultType === "person" ){
  1648. if (callback) callback( json.data );
  1649. }else{
  1650. var personList = (json.data || []).map( function(d){
  1651. return d.id
  1652. });
  1653. o2.Actions.get("x_organization_assemble_express").listIdentityWithPerson( { "personList" : personList }, function(js){
  1654. if (callback) callback(js.data);
  1655. }.bind(this), function(){
  1656. if (callback) callback();
  1657. }.bind(this))
  1658. }
  1659. }.bind(this), function(){
  1660. if (callback) callback();
  1661. }.bind(this), keyObject);
  1662. }else{
  1663. if (callback) callback();
  1664. }
  1665. },
  1666. listByFilterUnitAndGroup : function( type, key, callback ){
  1667. //根据关键字获取组织和群组内的身份
  1668. var keyString = typeOf( key )==="string" ? key.toLowerCase() : key.key.toLowerCase();
  1669. if ( this.includeUnit && this.includeUnit.length ){
  1670. key = this.getUnitFilterKey( key, this.includeUnit, this.includeGroup );
  1671. this.orgAction.listIdentityByKey(function(json){
  1672. if (callback) callback(json.data);
  1673. }.bind(this), function(){
  1674. if (callback) callback();
  1675. }, key);
  1676. }else{
  1677. if (callback) callback();
  1678. }
  1679. },
  1680. getUnitFilterKey : function( key, unitObject, groupObject ){
  1681. var unitObjects = unitObject || [];
  1682. var units = [];
  1683. unitObjects.each(function(u){
  1684. if (typeOf(u)==="string"){
  1685. units.push(u);
  1686. }
  1687. if (typeOf(u)==="object"){
  1688. units.push(u.distinguishedName);
  1689. }
  1690. });
  1691. var groupObjects = groupObject || [];
  1692. var groups = [];
  1693. groupObjects.each(function(g){
  1694. if (typeOf(g)==="string"){
  1695. groups.push(g);
  1696. }
  1697. if (typeOf(g)==="object"){
  1698. groups.push(g.distinguishedName);
  1699. }
  1700. });
  1701. if( !units.length && !groups.length ){
  1702. return key;
  1703. }else{
  1704. var result = { "key": key };
  1705. if( units.length )result.unitList = units;
  1706. if( groups.length )result.groupList = groups;
  1707. return result;
  1708. }
  1709. // return units.length ? {"key": key, "unitList": units, "groupList" : groups} : key;
  1710. }
  1711. });
  1712. MWF.xApplication.Selector.Identity.Filter = new Class({
  1713. Implements: [Options, Events],
  1714. options: {
  1715. "style": "default",
  1716. "units": [],
  1717. "resultType" : "" //可以设置成个人,那么结果返回个人
  1718. },
  1719. initialize: function(value, options){
  1720. this.setOptions(options);
  1721. this.value = value;
  1722. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  1723. },
  1724. filter: function(value, callback){
  1725. this.value = value;
  1726. var key = this.value;
  1727. if (this.options.units.length){
  1728. var units = [];
  1729. this.options.units.each(function(u){
  1730. if (typeOf(u)==="string"){
  1731. units.push(u);
  1732. }
  1733. if (typeOf(u)==="object"){
  1734. units.push(u.distinguishedName);
  1735. }
  1736. });
  1737. key = {"key": this.value, "unitList": units};
  1738. }
  1739. var data = null;
  1740. this.orgAction.listIdentityByKey(function(json){
  1741. data = json.data;
  1742. if (callback) callback(data)
  1743. }.bind(this), null, key);
  1744. }
  1745. });