Identity.js 83 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837
  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. this.selector.orgAction.listIdentityWithUnit(function(idJson){
  918. idJson.data.each(function(idSubData){
  919. if( !this.selector.isExcluded( idSubData ) ) {
  920. var item = this.selector._newItem(idSubData, this.selector, this.children, this.level + 1, this);
  921. this.selector.items.push(item);
  922. if(this.subItems)this.subItems.push( item );
  923. }
  924. }.bind(this));
  925. if( this.selector.options.expandSubEnable ){
  926. this.selector.orgAction.listSubUnitDirect(function(json){
  927. json.data.each(function(subData){
  928. if( !this.selector.isExcluded( subData ) ) {
  929. var category = this.selector._newItemCategory("ItemUnitCategory", subData, this.selector, this.children, this.level + 1, this);
  930. this.subCategorys.push( category );
  931. }
  932. }.bind(this));
  933. this.loaded = true;
  934. if (callback) callback( true );
  935. }.bind(this), null, this.data.distinguishedName);
  936. }else{
  937. this.loaded = true;
  938. if (callback) callback( true );
  939. }
  940. }.bind(this), null, this.data.distinguishedName);
  941. // }
  942. }else{
  943. if (callback) callback( );
  944. }
  945. },
  946. _hasChild: function(){
  947. var uCount = (this.data.subDirectUnitCount) ? this.data.subDirectUnitCount : 0;
  948. var iCount = (this.data.subDirectIdentityCount) ? this.data.subDirectIdentityCount : 0;
  949. return uCount + iCount;
  950. },
  951. _hasChildCategory: function(){
  952. return (this.data.subDirectUnitCount) ? this.data.subDirectUnitCount : 0;
  953. },
  954. _hasChildItem: function(){
  955. return (this.data.subDirectIdentityCount) ? this.data.subDirectIdentityCount : 0;
  956. },
  957. afterLoad: function(){
  958. if (this.level===1) this.clickItem();
  959. if( this.selector.options.showSelectedCount || this.selector.options.isCheckStatus ){
  960. var count = this._getSelectedCount();
  961. this.checkCountAndStatus( count );
  962. }
  963. },
  964. //for flat category start
  965. clickFlatCategoryItem: function( callback, hidden ){
  966. if (this._hasChildItem()){
  967. var firstLoaded = !this.itemLoaded;
  968. this.loadItemChildren(function(){
  969. if( hidden ){
  970. //alert("hidden")
  971. this.children.setStyles({"display": "none", "height": "0px"});
  972. this.node.setStyles( this.selector.css.flatCategoryItemNode );
  973. this.isExpand = false;
  974. }else if( firstLoaded ){
  975. this.children.setStyles({"display": "block", "height": "auto"});
  976. this.node.setStyles( this.selector.css.flatCategoryItemNode_selected );
  977. this.isExpand = true;
  978. }else{
  979. var display = this.children.getStyle("display");
  980. if (display === "none"){
  981. this.children.setStyles({"display": "block", "height": "auto"});
  982. this.node.setStyles( this.selector.css.flatCategoryItemNode_selected );
  983. this.isExpand = true;
  984. }else{
  985. this.children.setStyles({"display": "none", "height": "0px"});
  986. this.node.setStyles( this.selector.css.flatCategoryItemNode );
  987. this.isExpand = false;
  988. }
  989. }
  990. if(callback)callback();
  991. }.bind(this));
  992. }
  993. },
  994. loadCategoryChildren: function(callback){
  995. if (!this.categoryLoaded){
  996. if( this.selector.options.expandSubEnable ){
  997. this.selector.orgAction.listSubUnitDirect(function(json){
  998. json.data.each(function(subData){
  999. if( !this.selector.isExcluded( subData ) ) {
  1000. var category = this.selector._newItemCategory("ItemUnitCategory", subData, this.selector, this.children, this.level + 1, this);
  1001. this.subCategorys.push( category );
  1002. }
  1003. }.bind(this));
  1004. this.categoryLoaded = true;
  1005. if (callback) callback();
  1006. }.bind(this), null, this.data.distinguishedName);
  1007. }else{
  1008. if (callback) callback();
  1009. }
  1010. }else{
  1011. if (callback) callback( );
  1012. }
  1013. },
  1014. loadItemChildren: function(callback){
  1015. if (!this.itemLoaded){
  1016. // if (this.selector.options.dutys && this.selector.options.dutys.length){
  1017. // var ids = [];
  1018. // var object = {};
  1019. // this.selector.options.dutys.each(function(duty){
  1020. // this.selector.orgAction.listIdentityWidthUnitWithDutyName(this.data.distinguishedName, duty, function(json){
  1021. // if (json.data && json.data.length){
  1022. // ids = ids.concat(json.data);
  1023. // }
  1024. // }.bind(this), null, false);
  1025. //
  1026. // ids.each(function(idSubData){
  1027. // if( !this.selector.isExcluded( idSubData ) && !object[ idSubData.id || idSubData.distinguishedName ]) {
  1028. // var item = this.selector._newItem(idSubData, this.selector, this.children, this.level + 1, this);
  1029. // this.selector.items.push(item);
  1030. // if(this.subItems)this.subItems.push( item );
  1031. // object[ idSubData.id || idSubData.distinguishedName ] = true;
  1032. // }
  1033. // this.itemLoaded = true;
  1034. // }.bind(this));
  1035. // }.bind(this));
  1036. // if (callback) callback();
  1037. // }else{
  1038. this.selector.orgAction.listIdentityWithUnit(function(idJson){
  1039. idJson.data.each(function(idSubData){
  1040. if( !this.selector.isExcluded( idSubData ) ) {
  1041. var item = this.selector._newItem(idSubData, this.selector, this.children, this.level + 1, this);
  1042. this.selector.items.push(item);
  1043. if(this.subItems)this.subItems.push( item );
  1044. }
  1045. this.itemLoaded = true;
  1046. }.bind(this));
  1047. if (callback) callback();
  1048. }.bind(this), null, this.data.distinguishedName);
  1049. // }
  1050. }else{
  1051. if (callback) callback( );
  1052. }
  1053. }
  1054. //for flat category end
  1055. });
  1056. MWF.xApplication.Selector.Identity.ItemUnitCategory = new Class({
  1057. Extends: MWF.xApplication.Selector.Identity.ItemCategory
  1058. });
  1059. MWF.xApplication.Selector.Identity.ItemGroupCategory = new Class({
  1060. Extends: MWF.xApplication.Selector.Identity.ItemCategory,
  1061. createNode: function(){
  1062. this.node = new Element("div", {
  1063. "styles": this.selector.css.selectorItemCategory
  1064. }).inject(this.container);
  1065. },
  1066. _setIcon: function(){
  1067. var style = this.selector.options.style;
  1068. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/groupicon.png)");
  1069. },
  1070. _getTotalCount : function(){
  1071. if( !this.selector.allGroupObjectByDn )return 0;
  1072. var group = this.selector.allGroupObjectByDn[this.data.distinguishedName];
  1073. var count = group ? group.subNestedIdentityCount : 0;
  1074. return count;
  1075. },
  1076. _getSelectedCount : function(){
  1077. debugger;
  1078. if( typeOf(this.selectedCount) === "number" )return this.selectedCount;
  1079. if( !this.selector.allGroupObjectByDn )return 0;
  1080. var group = this.selector.allGroupObjectByDn[this.data.distinguishedName];
  1081. var count = group ? group.selectedNestedIdentityCount : 0;
  1082. this.selectedCount = count;
  1083. return count;
  1084. },
  1085. loadSub: function(callback){
  1086. if (!this.loaded){
  1087. var personContainer, identityContainer, groupContainer, unitContainer;
  1088. if( this.data.personList )personContainer = new Element("div").inject( this.children );
  1089. if( this.data.identityList )identityContainer = new Element("div").inject( this.children );
  1090. if( this.data.groupList )groupContainer = new Element("div").inject( this.children );
  1091. if( this.data.unitList )unitContainer = new Element("div").inject( this.children );
  1092. var personLoadedCount = 0;
  1093. var identityLoadedCount = 0;
  1094. var unitLoadedCount = 0;
  1095. var groupLoadedCount = 0;
  1096. var checkCallback = function( type, count ){
  1097. var addCount = count || 1;
  1098. if( !this.selector.options.expandSubEnable ){
  1099. if( type === "person" )personLoadedCount += addCount;
  1100. if( type === "identity" )identityLoadedCount += addCount;
  1101. if(
  1102. (!this.data.personList || this.data.personList.length === 0 || this.data.personList.length == personLoadedCount) &&
  1103. (!this.data.identityList || this.data.identityList.length === 0 || this.data.identityList.length == identityLoadedCount)
  1104. ){
  1105. this.loaded = true;
  1106. if (callback) callback();
  1107. }
  1108. }else{
  1109. if( type === "person" )personLoadedCount += addCount;
  1110. if( type === "identity" )identityLoadedCount += addCount;
  1111. if( type === "unit" )unitLoadedCount += addCount;
  1112. if( type === "group" )groupLoadedCount += addCount;
  1113. if( ( !this.data.personList || this.data.personList.length === 0 || this.data.personList.length == personLoadedCount ) &&
  1114. ( !this.data.identityList || this.data.identityList.length === 0 || this.data.identityList.length == identityLoadedCount )&&
  1115. ( !this.data.unitList || this.data.unitList.length === 0 || this.data.unitList.length == unitLoadedCount ) &&
  1116. ( !this.data.groupList || this.data.groupList.length === 0 || this.data.groupList.length == groupLoadedCount ) ){
  1117. this.loaded = true;
  1118. if (callback) callback();
  1119. }
  1120. }
  1121. }.bind(this);
  1122. checkCallback();
  1123. if( this.data.identityList && this.data.identityList.length > 0 ){
  1124. if( this.selector.options.resultType === "person" ) {
  1125. //根据身份id批量获取人员对象
  1126. o2.Actions.load("x_organization_assemble_express").PersonAction.listWithIdentityObject({
  1127. identityList : this.data.identityList
  1128. }, function (json) {
  1129. this.selector.includeObject.loadPersonItem( json, identityContainer, this.level + 1, this);
  1130. checkCallback("identity", this.data.identityList.length )
  1131. }.bind(this), function () {
  1132. checkCallback("identity", this.data.identityList.length )
  1133. }.bind(this))
  1134. }else{
  1135. //根据身份id批量获取身份对象
  1136. o2.Actions.load("x_organization_assemble_express").IdentityAction.listObject({
  1137. identityList : this.data.identityList
  1138. }, function (json) {
  1139. this.selector.includeObject.loadIdentityItem( json, identityContainer, this.level + 1, this);
  1140. checkCallback("identity", this.data.identityList.length )
  1141. }.bind(this), function () {
  1142. checkCallback("identity", this.data.identityList.length )
  1143. }.bind(this))
  1144. }
  1145. }
  1146. if( this.data.personList && this.data.personList.length > 0 ){
  1147. if( this.selector.options.resultType === "person" ) {
  1148. //根据人员d批量获取人员对象
  1149. o2.Actions.load("x_organization_assemble_express").PersonAction.listObject({
  1150. personList : this.data.personList
  1151. }, function (json) {
  1152. this.selector.includeObject.loadPersonItem( json, personContainer, this.level + 1, this);
  1153. checkCallback("person", this.data.personList.length )
  1154. }.bind(this), function () {
  1155. checkCallback("person", this.data.personList.length )
  1156. }.bind(this))
  1157. }else{
  1158. //根据人员id批量获取身份对象
  1159. o2.Actions.load("x_organization_assemble_express").IdentityAction.listWithPersonObject({
  1160. personList : this.data.personList
  1161. }, function (json) {
  1162. this.selector.includeObject.loadIdentityItem( json, personContainer, this.level + 1, this);
  1163. checkCallback("person", this.data.personList.length )
  1164. }.bind(this), function () {
  1165. checkCallback("person", this.data.personList.length )
  1166. }.bind(this))
  1167. }
  1168. }
  1169. // ( this.data.personList || [] ).each( function(p){
  1170. // if( this.selector.options.resultType === "person" ){
  1171. // this.selector.orgAction.getPerson(function (json) {
  1172. // this.selector.includeObject.loadPersonItem(json, this.children, this.level + 1, this );
  1173. // checkCallback("person");
  1174. // }.bind(this), function(){ checkCallback("person") }, p );
  1175. // }else{
  1176. // this.selector.orgAction.listIdentityByPerson(function(json){
  1177. // this.selector.includeObject.loadIdentityItem(json, this.children, this.level + 1, this);
  1178. // checkCallback("person")
  1179. // }.bind(this), function(){ checkCallback("person") }, p );
  1180. // }
  1181. // }.bind(this));
  1182. //list 服务不能获取下级数量
  1183. // if( this.selector.options.expandSubEnable ){
  1184. // o2.Actions.load("x_organization_assemble_express").UnitAction.listObject({
  1185. // unitList : this.data.unitList
  1186. // }, function (json) {
  1187. // this.selector.includeObject.loadUnitItem( json, this.children, this.level + 1, this);
  1188. // checkCallback("unit", this.data.unitList.length )
  1189. // }.bind(this), function () {
  1190. // checkCallback("unit", this.data.unitList.length )
  1191. // }.bind(this))
  1192. //
  1193. //
  1194. // o2.Actions.load("x_organization_assemble_express").GroupAction.listObject({
  1195. // groupList : this.data.groupList
  1196. // }, function (json) {
  1197. // this.selector.includeObject.loadGroupItem(json, this.children, this.level + 1, this);
  1198. // checkCallback("group", this.data.groupList.length )
  1199. // }.bind(this), function () {
  1200. // checkCallback("group", this.data.groupList.length )
  1201. // }.bind(this))
  1202. // }
  1203. if( this.selector.options.expandSubEnable ){
  1204. ( this.data.unitList || [] ).each( function(u){
  1205. this.selector.orgAction.getUnit(function (json) {
  1206. this.selector.includeObject.loadUnitItem(json, unitContainer, this.level + 1, this);
  1207. checkCallback("unit");
  1208. }.bind(this), function(){ checkCallback("unit") }, u );
  1209. }.bind(this));
  1210. ( this.data.groupList || [] ).each( function(g){
  1211. this.selector.orgAction.getGroup(function (json) {
  1212. this.selector.includeObject.loadGroupItem(json, groupContainer, this.level + 1, this);
  1213. checkCallback("group");
  1214. }.bind(this), function(){ checkCallback("group") }, g );
  1215. }.bind(this));
  1216. }
  1217. }else{
  1218. if (callback) callback( );
  1219. }
  1220. },
  1221. loadCategoryChildren: function(callback){
  1222. if (!this.categoryLoaded){
  1223. var groupContainer, unitContainer;
  1224. if( this.data.groupList )groupContainer = new Element("div").inject( this.children );
  1225. if( this.data.unitList )unitContainer = new Element("div").inject( this.children );
  1226. var unitLoadedCount = 0;
  1227. var groupLoadedCount = 0;
  1228. var checkCallback = function( type, count ){
  1229. var addCount = count || 1;
  1230. if( !this.selector.options.expandSubEnable ){
  1231. this.categoryLoaded = true;
  1232. }else{
  1233. if( type === "unit" )unitLoadedCount += addCount;
  1234. if( type === "group" )groupLoadedCount += addCount;
  1235. if( ( !this.data.unitList || this.data.unitList.length === 0 || this.data.unitList.length == unitLoadedCount ) &&
  1236. ( !this.data.groupList || this.data.groupList.length === 0 || this.data.groupList.length == groupLoadedCount ) ){
  1237. this.categoryLoaded = true;
  1238. if (callback) callback();
  1239. }
  1240. }
  1241. }.bind(this);
  1242. checkCallback();
  1243. //list 服务不能获取下级数量
  1244. // if( this.selector.options.expandSubEnable ){
  1245. // o2.Actions.load("x_organization_assemble_express").UnitAction.listObject({
  1246. // unitList : this.data.unitList
  1247. // }, function (json) {
  1248. // this.selector.includeObject.loadUnitItem( json, this.children, this.level + 1, this);
  1249. // checkCallback("unit", this.data.unitList.length )
  1250. // }.bind(this), function () {
  1251. // checkCallback("unit", this.data.unitList.length )
  1252. // }.bind(this))
  1253. //
  1254. //
  1255. // o2.Actions.load("x_organization_assemble_express").GroupAction.listObject({
  1256. // groupList : this.data.groupList
  1257. // }, function (json) {
  1258. // this.selector.includeObject.loadGroupItem(json, this.children, this.level + 1, this);
  1259. // checkCallback("group", this.data.groupList.length )
  1260. // }.bind(this), function () {
  1261. // checkCallback("group", this.data.groupList.length )
  1262. // }.bind(this))
  1263. // }
  1264. if( this.selector.options.expandSubEnable ){
  1265. ( this.data.unitList || [] ).each( function(u){
  1266. this.selector.orgAction.getUnit(function (json) {
  1267. this.selector.includeObject.loadUnitItem(json, unitContainer, this.level + 1, this);
  1268. checkCallback("unit");
  1269. }.bind(this), function(){ checkCallback("unit") }, u );
  1270. }.bind(this));
  1271. ( this.data.groupList || [] ).each( function(g){
  1272. this.selector.orgAction.getGroup(function (json) {
  1273. this.selector.includeObject.loadGroupItem(json, groupContainer, this.level + 1, this);
  1274. checkCallback("group");
  1275. }.bind(this), function(){ checkCallback("group") }, g );
  1276. }.bind(this));
  1277. }
  1278. }else{
  1279. if (callback) callback( );
  1280. }
  1281. },
  1282. loadItemChildren: function(callback){
  1283. if (!this.itemLoaded){
  1284. var personContainer, identityContainer;
  1285. if( this.data.personList )personContainer = new Element("div").inject( this.children );
  1286. if( this.data.identityList )identityContainer = new Element("div").inject( this.children );
  1287. var personLoadedCount = 0;
  1288. var identityLoadedCount = 0;
  1289. var checkCallback = function( type, count ){
  1290. var addCount = count || 1;
  1291. if( type === "person" )personLoadedCount += addCount;
  1292. if( type === "identity" )identityLoadedCount += addCount;
  1293. if(
  1294. (!this.data.personList || this.data.personList.length === 0 || this.data.personList.length == personLoadedCount) &&
  1295. (!this.data.identityList || this.data.identityList.length === 0 || this.data.identityList.length == identityLoadedCount)
  1296. ){
  1297. this.itemLoaded = true;
  1298. if (callback) callback();
  1299. }
  1300. }.bind(this);
  1301. checkCallback();
  1302. if( this.data.identityList && this.data.identityList.length > 0 ){
  1303. if( this.selector.options.resultType === "person" ) {
  1304. //根据身份id批量获取人员对象
  1305. o2.Actions.load("x_organization_assemble_express").PersonAction.listWithIdentityObject({
  1306. identityList : this.data.identityList
  1307. }, function (json) {
  1308. this.selector.includeObject.loadPersonItem( json, identityContainer, this.level + 1, this);
  1309. checkCallback("identity", this.data.identityList.length )
  1310. }.bind(this), function () {
  1311. checkCallback("identity", this.data.identityList.length )
  1312. }.bind(this))
  1313. }else{
  1314. //根据身份id批量获取身份对象
  1315. o2.Actions.load("x_organization_assemble_express").IdentityAction.listObject({
  1316. identityList : this.data.identityList
  1317. }, function (json) {
  1318. this.selector.includeObject.loadIdentityItem( json, identityContainer, this.level + 1, this);
  1319. checkCallback("identity", this.data.identityList.length )
  1320. }.bind(this), function () {
  1321. checkCallback("identity", this.data.identityList.length )
  1322. }.bind(this))
  1323. }
  1324. }
  1325. if( this.data.personList && this.data.personList.length > 0 ){
  1326. if( this.selector.options.resultType === "person" ) {
  1327. //根据人员d批量获取人员对象
  1328. o2.Actions.load("x_organization_assemble_express").PersonAction.listObject({
  1329. personList : this.data.personList
  1330. }, function (json) {
  1331. this.selector.includeObject.loadPersonItem( json, personContainer, this.level + 1, this);
  1332. checkCallback("person", this.data.personList.length )
  1333. }.bind(this), function () {
  1334. checkCallback("person", this.data.personList.length )
  1335. }.bind(this))
  1336. }else{
  1337. //根据人员id批量获取身份对象
  1338. o2.Actions.load("x_organization_assemble_express").IdentityAction.listWithPersonObject({
  1339. personList : this.data.personList
  1340. }, function (json) {
  1341. this.selector.includeObject.loadIdentityItem( json, personContainer, this.level + 1, this);
  1342. checkCallback("person", this.data.personList.length )
  1343. }.bind(this), function () {
  1344. checkCallback("person", this.data.personList.length )
  1345. }.bind(this))
  1346. }
  1347. }
  1348. // ( this.data.personList || [] ).each( function(p){
  1349. // if( this.selector.options.resultType === "person" ){
  1350. // this.selector.orgAction.getPerson(function (json) {
  1351. // this.selector.includeObject.loadPersonItem(json, this.children, this.level + 1, this );
  1352. // checkCallback("person");
  1353. // }.bind(this), function(){ checkCallback("person") }, p );
  1354. // }else{
  1355. // this.selector.orgAction.listIdentityByPerson(function(json){
  1356. // this.selector.includeObject.loadIdentityItem(json, this.children, this.level + 1, this);
  1357. // checkCallback("person")
  1358. // }.bind(this), function(){ checkCallback("person") }, p );
  1359. // }
  1360. // }.bind(this));
  1361. }else{
  1362. if (callback) callback( );
  1363. }
  1364. },
  1365. _hasChild: function(){
  1366. var uCount = (this.data.unitList) ? this.data.unitList.length : 0;
  1367. var gCount = (this.data.groupList) ? this.data.groupList.length : 0;
  1368. var pCount = (this.data.personList) ? this.data.personList.length : 0;
  1369. var iCount = (this.data.identityList) ? this.data.identityList.length : 0;
  1370. return uCount + gCount + pCount + iCount;
  1371. },
  1372. _hasChildCategory: function(){
  1373. var uCount = (this.data.unitList) ? this.data.unitList.length : 0;
  1374. var gCount = (this.data.groupList) ? this.data.groupList.length : 0;
  1375. return uCount + gCount;
  1376. },
  1377. _hasChildItem: function(){
  1378. var pCount = (this.data.personList) ? this.data.personList.length : 0;
  1379. var iCount = (this.data.identityList) ? this.data.identityList.length : 0;
  1380. return pCount + iCount;
  1381. }
  1382. });
  1383. MWF.xApplication.Selector.Identity.ItemRoleCategory = new Class({
  1384. Extends: MWF.xApplication.Selector.Person.ItemCategory,
  1385. _getShowName: function(){
  1386. return this.data.name;
  1387. },
  1388. _setIcon: function(){
  1389. var style = this.selector.options.style;
  1390. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/roleicon.png)");
  1391. }
  1392. });
  1393. MWF.xApplication.Selector.Identity.Include = new Class({
  1394. Implements: [Options, Events],
  1395. options: {
  1396. "include" : [], //增加的可选项
  1397. "resultType" : "", //可以设置成个人,那么结果返回个人
  1398. "expandSubEnable" : true //是否允许展开下一层
  1399. },
  1400. initialize: function(selector, itemAreaNode, options){
  1401. this.setOptions(options);
  1402. this.selector = selector;
  1403. this.itemAreaNode = $(itemAreaNode);
  1404. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  1405. },
  1406. load : function( callback ){
  1407. if( !this.options.include || this.options.include.length === 0 ){
  1408. this.fireEvent("afterLoad");
  1409. if(callback)callback();
  1410. return;
  1411. }
  1412. var count = 0;
  1413. var checkCallback = function () {
  1414. count++;
  1415. if( count === this.options.include.length ){
  1416. this.fireEvent("afterLoad");
  1417. if(callback)callback();
  1418. }
  1419. }.bind(this);
  1420. this.includeAreaNode = new Element( "div.includeAreaNode").inject( this.itemAreaNode, "top" );
  1421. if( this.selector.isFlatCategory ){
  1422. this.flatCategoryAreaNode = new Element( "div.includeFlatCategoryAreaNode").inject( this.selector.flatCategoryNode, "top" );
  1423. }
  1424. //this.includeIdentityAreaNode = new Element( "div").inject( this.includeAreaNode );
  1425. //this.includePersonAreaNode = new Element( "div").inject( this.includeAreaNode );
  1426. //this.includeUnitAreaNode = new Element( "div").inject( this.includeAreaNode );
  1427. //this.includeGroupAreaNode = new Element( "div").inject( this.includeAreaNode );
  1428. this.options.include.each( function( d ){
  1429. var container = new Element("div").inject( this.includeAreaNode );
  1430. var flatCategoryContainer;
  1431. if( this.flatCategoryAreaNode ){
  1432. flatCategoryContainer = new Element("div").inject( this.flatCategoryAreaNode );
  1433. }
  1434. if (typeOf(d)==="string"){
  1435. var arr = d.split("@");
  1436. var flag = arr[ arr.length - 1].toLowerCase();
  1437. if( flag === "u" ){
  1438. this.orgAction.listUnitByKey(function(json){
  1439. this.loadUnitItem(json, container, null, null, flatCategoryContainer);
  1440. checkCallback();
  1441. }.bind(this), checkCallback, d);
  1442. }else if( flag === "i" ) {
  1443. this.orgAction.listIdentityByKey(function (json) {
  1444. this.loadIdentityItem(json, container, null, null, true );
  1445. checkCallback();
  1446. }.bind(this), checkCallback, d);
  1447. }else if( flag === "g" ){
  1448. this.orgAction.listGroupByKey(function(json){
  1449. this.loadGroupItem( json , container, null, null, flatCategoryContainer);
  1450. checkCallback();
  1451. }.bind(this), checkCallback, d);
  1452. }else if( flag === "p" ){
  1453. if( this.options.resultType === "person" ){
  1454. this.orgAction.getPerson(function (json){
  1455. this.loadPersonItem( json , container, null, null, true);
  1456. checkCallback();
  1457. }.bind(this), checkCallback, d);
  1458. }else{
  1459. this.orgAction.listIdentityByPerson(function(json){
  1460. this.loadIdentityItem(json, container , null, null, true);
  1461. checkCallback();
  1462. }.bind(this), checkCallback, d);
  1463. }
  1464. }else{
  1465. if( this.options.resultType === "person" ){
  1466. this.orgAction.listPersonByKey(function (json) {
  1467. this.loadPersonItem( json , container, null, null, true);
  1468. checkCallback();
  1469. }.bind(this), checkCallback, d);
  1470. }else{
  1471. this.orgAction.listIdentityByKey(function(json){
  1472. this.loadIdentityItem(json, container, null, null, true);
  1473. checkCallback();
  1474. }.bind(this), checkCallback, d);
  1475. }
  1476. }
  1477. }else{
  1478. var arr = d.distinguishedName.split("@");
  1479. var flag = arr[ arr.length - 1].toLowerCase();
  1480. if( flag === "u" ) {
  1481. this.orgAction.getUnit(function (json) {
  1482. this.loadUnitItem(json, container, null, null, flatCategoryContainer);
  1483. checkCallback();
  1484. }.bind(this), checkCallback, d.distinguishedName);
  1485. }else if( flag === "i" ){
  1486. this.orgAction.getIdentity(function (json) {
  1487. this.loadIdentityItem(json, container, null, null, true);
  1488. checkCallback();
  1489. }.bind(this), checkCallback, d.distinguishedName);
  1490. }else if( flag === "g" ){
  1491. this.orgAction.getGroup(function(json){
  1492. this.loadGroupItem( json , container, null, null, flatCategoryContainer);
  1493. checkCallback();
  1494. }.bind(this), checkCallback, d.distinguishedName, null, null, true);
  1495. }else if( flag === "p" ){
  1496. if( this.options.resultType === "person" ){
  1497. this.orgAction.getPerson(function (json) {
  1498. this.loadPersonItem(json, container, null, null, true);
  1499. checkCallback();
  1500. }.bind(this), checkCallback, d.distinguishedName);
  1501. }else{
  1502. this.orgAction.listIdentityByPerson(function(json){
  1503. this.loadIdentityItem(json, container, null, null, true);
  1504. checkCallback();
  1505. }.bind(this), checkCallback, d.distinguishedName);
  1506. }
  1507. }else{
  1508. if( this.options.resultType === "person" ){
  1509. this.orgAction.getPerson(function (json) {
  1510. this.loadPersonItem(json, container, null, null, true);
  1511. checkCallback();
  1512. }.bind(this), checkCallback, d.distinguishedName);
  1513. }else{
  1514. this.orgAction.getIdentity(function (json) {
  1515. this.loadIdentityItem(json, container, null, null, true);
  1516. checkCallback();
  1517. }.bind(this), checkCallback, d.distinguishedName);
  1518. }
  1519. }
  1520. //var category = this._newItemCategory("ItemCategory", unit, this, this.itemAreaNode);
  1521. }
  1522. }.bind(this))
  1523. },
  1524. loadPersonItem : function( json, container, level, category, isIncludedPerson ){
  1525. if( !json.data )return;
  1526. var array = typeOf( json.data ) === "array" ? json.data : [json.data];
  1527. array.each(function(data){
  1528. if( !this.selector.isExcluded( data ) ) {
  1529. if(!this.includePerson)this.includePerson = [];
  1530. if(isIncludedPerson)this.includePerson.push( data.distinguishedName );
  1531. if(!this.includePersonObject)this.includePersonObject = [];
  1532. if(isIncludedPerson)this.includePersonObject.push( data );
  1533. var item = this.selector._newItem(data, this.selector, container || this.includeAreaNode, level || 1, category);
  1534. this.selector.items.push(item);
  1535. if( category && category.subItems ){
  1536. category.subItems.push( item );
  1537. }
  1538. }
  1539. }.bind(this));
  1540. },
  1541. loadIdentityItem : function( json, container, level, category, isIncludedIdentity ){
  1542. if( !json.data )return;
  1543. var array = typeOf( json.data ) === "array" ? json.data : [json.data];
  1544. array.each(function(data){
  1545. if( !this.selector.isExcluded( data ) ) {
  1546. if(!this.includeIdentity)this.includeIdentity = [];
  1547. if(isIncludedIdentity)this.includeIdentity.push( data.distinguishedName );
  1548. if(!this.includeIdentityObject)this.includeIdentityObject = [];
  1549. if(isIncludedIdentity)this.includeIdentityObject.push( data );
  1550. var item = this.selector._newItem(data, this.selector, container || this.includeAreaNode, level || 1, category);
  1551. this.selector.items.push(item);
  1552. if( category && category.subItems ){
  1553. category.subItems.push( item );
  1554. }
  1555. }
  1556. }.bind(this));
  1557. },
  1558. loadUnitItem : function( json, container, level, parentCategory, flatCategoryContainer ){
  1559. if( !json.data )return;
  1560. var array = typeOf( json.data ) === "array" ? json.data : [json.data];
  1561. array.each(function(data){
  1562. if( !this.selector.isExcluded( data ) ) {
  1563. if(!this.includeUnit)this.includeUnit = [];
  1564. this.includeUnit.push( data.distinguishedName );
  1565. var category;
  1566. if( flatCategoryContainer ){
  1567. category = this.selector._newItemCategory("ItemUnitCategory", data, this.selector,
  1568. container || this.includeAreaNode, level, parentCategory, true);
  1569. category.nodeContainer = flatCategoryContainer;
  1570. category.load();
  1571. }else{
  1572. category = this.selector._newItemCategory("ItemUnitCategory", data, this.selector,
  1573. container || this.includeAreaNode, level, parentCategory);
  1574. }
  1575. if( parentCategory && parentCategory.subCategorys ){
  1576. parentCategory.subCategorys.push( category )
  1577. }else if(this.selector.subCategorys){
  1578. this.selector.subCategorys.push( category )
  1579. }
  1580. }
  1581. }.bind(this));
  1582. },
  1583. loadGroupItem : function( json, container, level, parentCategory, flatCategoryContainer ){
  1584. if( !json.data )return;
  1585. var array = typeOf( json.data ) === "array" ? json.data : [json.data];
  1586. array.each(function(data){
  1587. if( !this.selector.isExcluded( data ) ) {
  1588. if(!this.includeGroup)this.includeGroup = [];
  1589. this.includeGroup.push( data.distinguishedName );
  1590. var category;
  1591. if( flatCategoryContainer ){
  1592. category = this.selector._newItemCategory("ItemGroupCategory", data, this.selector, container || this.includeAreaNode, level, parentCategory, true);
  1593. category.nodeContainer = flatCategoryContainer;
  1594. category.load();
  1595. }else{
  1596. category = this.selector._newItemCategory("ItemGroupCategory", data, this.selector, container || this.includeAreaNode, level, parentCategory)
  1597. }
  1598. if( parentCategory && parentCategory.subCategorys ){
  1599. parentCategory.subCategorys.push( category )
  1600. }else if(this.selector.subCategorys){
  1601. this.selector.subCategorys.push( category )
  1602. }
  1603. }
  1604. }.bind(this));
  1605. },
  1606. listByFilter : function( type, key, callback ){
  1607. var arr1 = this.listByFilterPerson(key) || [];
  1608. this.listByFilterUnitAndGroup( type, key, function(arr2){
  1609. this.listByFilterGroup( type, key, function(arr3){
  1610. if (callback) callback( arr1.concat( arr2 || [] ).concat( arr3 || [] ) );
  1611. }.bind(this))
  1612. }.bind(this))
  1613. },
  1614. listByFilterPerson : function( key ){
  1615. var identitys = [];
  1616. var persons = [];
  1617. var keyString = typeOf( key )==="string" ? key.toLowerCase() : key.key.toLowerCase();
  1618. if( this.includeIdentityObject && this.includeIdentityObject.length ){
  1619. identitys = this.includeIdentityObject.filter( function(id) {
  1620. return ( id.pinyin || "" ).indexOf(keyString) > -1 || (id.pinyinInitial || "").indexOf(keyString) > -1 || (id.distinguishedName || "").indexOf(keyString) > -1;
  1621. })
  1622. }
  1623. if( this.includePersonObject && this.includePersonObject.length ){
  1624. persons = this.includePersonObject.filter( function(id) {
  1625. return ( id.pinyin || "" ).indexOf(keyString) > -1 || (id.pinyinInitial || "").indexOf(keyString) > -1 || (id.distinguishedName || "").indexOf(keyString) > -1;
  1626. })
  1627. }
  1628. return identitys.concat( persons);
  1629. },
  1630. listByFilterGroup : function( type, key, callback ){
  1631. //根据关键字获取群组内的人员,再转成身份
  1632. var keyString = typeOf( key )==="string" ? key.toLowerCase() : key.key.toLowerCase();
  1633. if( this.includeGroup && this.includeGroup.length ){
  1634. var keyObject = { "key" : keyString, "groupList" : this.includeGroup };
  1635. this.orgAction[ type === "pinyin" ? "listPersonByPinyin" : "listPersonByKey" ](function(json){
  1636. if( this.options.resultType === "person" ){
  1637. if (callback) callback( json.data );
  1638. }else{
  1639. var personList = (json.data || []).map( function(d){
  1640. return d.id
  1641. });
  1642. o2.Actions.get("x_organization_assemble_express").listIdentityWithPerson( { "personList" : personList }, function(js){
  1643. if (callback) callback(js.data);
  1644. }.bind(this), function(){
  1645. if (callback) callback();
  1646. }.bind(this))
  1647. }
  1648. }.bind(this), function(){
  1649. if (callback) callback();
  1650. }.bind(this), keyObject);
  1651. }else{
  1652. if (callback) callback();
  1653. }
  1654. },
  1655. listByFilterUnitAndGroup : function( type, key, callback ){
  1656. //根据关键字获取组织和群组内的身份
  1657. var keyString = typeOf( key )==="string" ? key.toLowerCase() : key.key.toLowerCase();
  1658. if ( this.includeUnit && this.includeUnit.length ){
  1659. key = this.getUnitFilterKey( key, this.includeUnit, this.includeGroup );
  1660. this.orgAction.listIdentityByKey(function(json){
  1661. if (callback) callback(json.data);
  1662. }.bind(this), function(){
  1663. if (callback) callback();
  1664. }, key);
  1665. }else{
  1666. if (callback) callback();
  1667. }
  1668. },
  1669. getUnitFilterKey : function( key, unitObject, groupObject ){
  1670. var unitObjects = unitObject || [];
  1671. var units = [];
  1672. unitObjects.each(function(u){
  1673. if (typeOf(u)==="string"){
  1674. units.push(u);
  1675. }
  1676. if (typeOf(u)==="object"){
  1677. units.push(u.distinguishedName);
  1678. }
  1679. });
  1680. var groupObjects = groupObject || [];
  1681. var groups = [];
  1682. groupObjects.each(function(g){
  1683. if (typeOf(g)==="string"){
  1684. groups.push(g);
  1685. }
  1686. if (typeOf(g)==="object"){
  1687. groups.push(g.distinguishedName);
  1688. }
  1689. });
  1690. if( !units.length && !groups.length ){
  1691. return key;
  1692. }else{
  1693. var result = { "key": key };
  1694. if( units.length )result.unitList = units;
  1695. if( groups.length )result.groupList = groups;
  1696. return result;
  1697. }
  1698. // return units.length ? {"key": key, "unitList": units, "groupList" : groups} : key;
  1699. }
  1700. });
  1701. MWF.xApplication.Selector.Identity.Filter = new Class({
  1702. Implements: [Options, Events],
  1703. options: {
  1704. "style": "default",
  1705. "units": [],
  1706. "resultType" : "" //可以设置成个人,那么结果返回个人
  1707. },
  1708. initialize: function(value, options){
  1709. this.setOptions(options);
  1710. this.value = value;
  1711. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  1712. },
  1713. filter: function(value, callback){
  1714. this.value = value;
  1715. var key = this.value;
  1716. if (this.options.units.length){
  1717. var units = [];
  1718. this.options.units.each(function(u){
  1719. if (typeOf(u)==="string"){
  1720. units.push(u);
  1721. }
  1722. if (typeOf(u)==="object"){
  1723. units.push(u.distinguishedName);
  1724. }
  1725. });
  1726. key = {"key": this.value, "unitList": units};
  1727. }
  1728. var data = null;
  1729. this.orgAction.listIdentityByKey(function(json){
  1730. data = json.data;
  1731. if (callback) callback(data)
  1732. }.bind(this), null, key);
  1733. }
  1734. });