Identity.js 85 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873
  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, isWait){
  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 (!isWait && callback) callback();
  606. if (!this.data.woPerson && (!this.data.personDn || !this.data.personEmployee || !this.data.personUnique)){
  607. this.selector.orgAction.getPerson(function(json){
  608. this.data.woPerson = json.data;
  609. if (isWait && callback) callback();
  610. }.bind(this), null, this.data.person)
  611. }else{
  612. if (isWait && callback) callback();
  613. }
  614. }
  615. },
  616. checkSelectedSingle: function(){
  617. var isPerson = this.selector.options.resultType === "person";
  618. var selectedItem = this.selector.options.values.filter(function(item, index){
  619. if( isPerson ){
  620. if (typeOf(item)==="object") return (item.id && item.id === this.data.person) ||
  621. ( item.person && item.person === this.data.id ) ||
  622. ( this.data.distinguishedName && this.data.distinguishedName === item.distinguishedName);
  623. return false;
  624. }else{
  625. if (typeOf(item)==="object") return this.data.distinguishedName === item.distinguishedName;
  626. if (typeOf(item)==="string") return this.data.distinguishedName === item;
  627. return false;
  628. }
  629. }.bind(this));
  630. if (selectedItem.length){
  631. this.selectedSingle();
  632. }
  633. },
  634. checkSelected: function(){
  635. var isPerson = this.selector.options.resultType === "person";
  636. var selectedItem = this.selector.selectedItems.filter(function(item, index){
  637. if( isPerson ){
  638. return ( item.data.id && item.data.id === this.data.person ) ||
  639. ( item.data.person && item.data.person === this.data.id ) ||
  640. ( item.data.distinguishedName && item.data.distinguishedName === this.data.distinguishedName );
  641. }else{
  642. return item.data.distinguishedName === this.data.distinguishedName;
  643. }
  644. }.bind(this));
  645. if (selectedItem.length){
  646. //selectedItem[0].item = this;
  647. selectedItem[0].addItem(this);
  648. this.selectedItem = selectedItem[0];
  649. this.setSelected();
  650. var flag = this.selector.options.selectAllRange === "all" ||
  651. ( this.selector.selectType == "identity" && ( this.selector.options.showSelectedCount || this.selector.options.isCheckStatus ));
  652. if( flag ){
  653. if(this.category && this.category._addSelectedCount )this.category._addSelectedCount( 1, true );
  654. }
  655. }
  656. }
  657. });
  658. MWF.xApplication.Selector.Identity.SearchItem = new Class({
  659. Extends: MWF.xApplication.Selector.Identity.Item,
  660. _getShowName: function(){
  661. return this.data.name+((this.data.unitLevelName) ? "("+this.data.unitLevelName+")" : "");
  662. }
  663. });
  664. MWF.xApplication.Selector.Identity.ItemSelected = new Class({
  665. Extends: MWF.xApplication.Selector.Person.ItemSelected,
  666. getData: function(callback, isWait){
  667. if( this.selector.options.resultType === "person" ){
  668. var isPerson = false;
  669. if( this.data && this.data.distinguishedName ){
  670. var dn = this.data.distinguishedName;
  671. if( dn.substr(dn.length-1, 1).toLowerCase() === "p" )isPerson = true;
  672. }
  673. if( isPerson ){
  674. if (callback) callback();
  675. }else if( this.data.woPerson ){
  676. this.data = this.data.woPerson;
  677. if (callback) callback();
  678. }else if( this.data.person ){
  679. this.selector.orgAction.getPerson(function(json){
  680. this.data = json.data;
  681. if (callback) callback();
  682. }.bind(this), null, this.data.person )
  683. }else{
  684. if (callback) callback();
  685. }
  686. }else if (!this.data.woPerson && (!this.data.personDn || !this.data.personEmployee || !this.data.personUnique) ){
  687. if (!isWait && callback) callback();
  688. if (this.data.person){
  689. this.selector.orgAction.getPerson(function(json){
  690. this.data.woPerson = json.data;
  691. if (isWait && callback) callback();
  692. }.bind(this), function(xhr, text, error){
  693. var errorText = error;
  694. if (xhr){
  695. var json = JSON.decode(xhr.responseText);
  696. if (json){
  697. errorText = json.message.trim() || "request json error";
  698. }else{
  699. errorText = "request json error: "+xhr.responseText;
  700. }
  701. }
  702. MWF.xDesktop.notice("error", {x: "right", y:"top"}, errorText);
  703. if (isWait && callback) callback();
  704. }.bind(this), this.data.person)
  705. }else{
  706. MWF.xDesktop.notice("error", {x: "right", y:"top"}, MWF.SelectorLP.noPerson.replace(/{name}/g, this.data.name));
  707. if (isWait && callback) callback();
  708. }
  709. }else{
  710. if (callback) callback();
  711. }
  712. },
  713. _getShowName: function(){
  714. return this.data.name+((this.data.unitLevelName) ? "("+this.data.unitLevelName+")" : "");
  715. },
  716. _getTtiteText: function(){
  717. return this.data.name+((this.data.unitLevelName) ? "("+this.data.unitLevelName+")" : "");
  718. },
  719. _setIcon: function(){
  720. var style = this.selector.options.style;
  721. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/personicon.png)");
  722. },
  723. check: function(){
  724. if (this.selector.items.length){
  725. var isPerson = this.selector.options.resultType === "person";
  726. var items = this.selector.items.filter(function(item, index){
  727. if( isPerson ){
  728. return (item.data.person && item.data.person === this.data.id) ||
  729. ( item.data.id && item.data.id === this.data.person) ||
  730. ( item.data.distinguishedName && item.data.distinguishedName === this.data.distinguishedName );
  731. }else{
  732. return item.data.distinguishedName === this.data.distinguishedName;
  733. }
  734. }.bind(this));
  735. this.items = items;
  736. if (items.length){
  737. items.each(function(item){
  738. item.selectedItem = this;
  739. item.setSelected();
  740. var flag = this.selector.options.selectAllRange === "all" ||
  741. ( this.selector.selectType == "identity" && ( this.selector.options.showSelectedCount || this.selector.options.isCheckStatus ) );
  742. if( flag ){
  743. if(item.category && item.category._addSelectedCount )item.category._addSelectedCount( 1, true );
  744. }
  745. }.bind(this));
  746. }
  747. }
  748. if( this.afterCheck )this.afterCheck();
  749. }
  750. });
  751. MWF.xApplication.Selector.Identity.ItemCategory = new Class({
  752. Extends: MWF.xApplication.Selector.Person.ItemCategory,
  753. createNode: function(){
  754. this.node = new Element("div", {
  755. "styles": this.selector.css.selectorItemCategory_department,
  756. "title" : this._getTtiteText()
  757. }).inject(this.container);
  758. },
  759. _addSelectedCount : function( count, nested ){
  760. var c = ( this._getSelectedCount() || 0 ) + count;
  761. this.selectedCount = c;
  762. this.checkCountAndStatus( c );
  763. if( nested && this.category && this.category._addSelectedCount ){
  764. this.category._addSelectedCount(count, nested);
  765. }
  766. },
  767. checkCountAndStatus: function( count ){
  768. if( this.selector.options.showSelectedCount ){
  769. this.selectedCountNode.set("text", count ? "(" + count + ")" : "" );
  770. }
  771. if( this.selector.options.isCheckStatus && this.selectAllNode ){
  772. var total = this._getTotalCount();
  773. if( total ){
  774. var styles;
  775. if( count >= total ){
  776. styles = this.selector.css.selectorItemCategoryActionNode_selectAll_selected;
  777. this.isSelectedSome = false;
  778. this.isSelectedAll = true;
  779. }else if( count > 0 ){
  780. styles = this.selector.css.selectorItemCategoryActionNode_selectsome_selected;
  781. this.isSelectedSome = true;
  782. this.isSelectedAll = false;
  783. }else{
  784. styles = this.selector.css.selectorItemCategoryActionNode_selectAll;
  785. this.isSelectedSome = false;
  786. this.isSelectedAll = false;
  787. }
  788. this.selectAllNode.setStyles( styles );
  789. }
  790. }else if( count === 0 && this.selector.options.selectAllRange === "all" && this.selectAllNode ){
  791. styles = this.selector.css.selectorItemCategoryActionNode_selectAll;
  792. this.isSelectedSome = false;
  793. this.isSelectedAll = false;
  794. this.selectAllNode.setStyles( styles );
  795. }
  796. // if( !this.selectedCountNode1 ){
  797. // this.selectedCountNode1 = new Element("span").inject(this.textNode);
  798. // }
  799. // this.selectedCountNode1.set("text",count);
  800. },
  801. _getShowName: function(){
  802. // if( this._getTotalCount && this._getSelectedCount ){
  803. // return "" + this._getTotalCount() + "-" + this._getSelectedCount() + "-" + this.data.name ;
  804. // }else{
  805. return this.data.name;
  806. // }
  807. },
  808. _getTotalCount : function(){
  809. if( !this.selector.allUnitObject )return 0;
  810. var unit = this.selector.allUnitObject[this.data.levelName];
  811. var count = unit ? unit.subNestedIdentityCount : 0;
  812. return count;
  813. },
  814. _getSelectedCount : function(){
  815. if( typeOf(this.selectedCount) === "number" )return this.selectedCount;
  816. if( !this.selector.allUnitObject )return 0;
  817. var unit = this.selector.allUnitObject[this.data.levelName];
  818. var count = unit ? unit.selectedNestedIdentityCount : 0;
  819. this.selectedCount = count;
  820. return count;
  821. },
  822. _setIcon: function(){
  823. var style = this.selector.options.style;
  824. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/companyicon.png)");
  825. },
  826. _beforeSelectAll : function( _selectAllFun ){
  827. if( this.selector.options.ignorePerson ){
  828. _selectAllFun();
  829. return;
  830. }
  831. //批量获取个人
  832. var object = {};
  833. if( this.selector.options.resultType === "person" ){
  834. this.subItems.each( function(item){
  835. var isPerson = false;
  836. if( item.data && item.data.distinguishedName ){
  837. var dn = item.data.distinguishedName;
  838. if( dn.substr(dn.length-1, 1).toLowerCase() === "p" )isPerson = true;
  839. }
  840. if( !isPerson && !item.data.woPerson && item.data.person ){
  841. object[ item.data.person ] = item;
  842. }
  843. }.bind(this))
  844. }else{
  845. this.subItems.each( function (item) {
  846. if (!item.data.woPerson && item.data.person ){
  847. object[ item.data.person ] = item;
  848. }
  849. }.bind(this))
  850. }
  851. var keys = Object.keys( object );
  852. if( keys.length > 0 ){
  853. o2.Actions.load("x_organization_assemble_express").PersonAction.listObject({"personList":keys}, function (json) {
  854. json.data.each( function ( p ){
  855. if(object[ p.id ])object[ p.id ].data.woPerson = p;
  856. }.bind(this));
  857. _selectAllFun();
  858. })
  859. }else{
  860. _selectAllFun();
  861. }
  862. },
  863. clickItem: function( callback ){
  864. if (this._hasChild() && !this.loading){
  865. var firstLoaded = !this.loaded;
  866. this.loading = true;
  867. this.loadSub(function(){
  868. this.loading = false;
  869. if( firstLoaded ){
  870. if( !this.selector.isFlatCategory ){
  871. this.children.setStyles({"display": "block", "height": "auto"});
  872. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_expand);
  873. this.isExpand = true;
  874. }
  875. this.selector.fireEvent("expand", [this] );
  876. // this.checkSelectAll();
  877. }else{
  878. var display = this.children.getStyle("display");
  879. if (display === "none"){
  880. this.selector.fireEvent("expand", [this] );
  881. this.children.setStyles({"display": "block", "height": "auto"});
  882. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_expand);
  883. this.isExpand = true;
  884. this.selector.fireEvent("expand", [this] );
  885. }else{
  886. this.selector.fireEvent("collapse", [this] );
  887. this.children.setStyles({"display": "none", "height": "0px"});
  888. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_collapse);
  889. this.isExpand = false;
  890. this.selector.fireEvent("expand", [this] );
  891. }
  892. }
  893. if(callback)callback();
  894. }.bind(this));
  895. }
  896. },
  897. loadSub: function(callback){
  898. this._loadSub( function( firstLoad ) {
  899. if(callback)callback();
  900. }.bind(this))
  901. },
  902. _loadSub: function(callback){
  903. if (!this.loaded){
  904. // if (this.selector.options.dutys && this.selector.options.dutys.length){
  905. // var ids = [];
  906. // var object = {};
  907. // this.selector.options.dutys.each(function(duty){
  908. // this.selector.orgAction.listIdentityWidthUnitWithDutyName(this.data.distinguishedName, duty, function(json){
  909. // if (json.data && json.data.length){
  910. // ids = ids.concat(json.data);
  911. // }
  912. // }.bind(this), null, false);
  913. //
  914. // ids.each(function(idSubData){
  915. // if( !this.selector.isExcluded( idSubData ) && !object[ idSubData.id || idSubData.distinguishedName ]) {
  916. // var item = this.selector._newItem(idSubData, this.selector, this.children, this.level + 1, this);
  917. // this.selector.items.push(item);
  918. // if(this.subItems)this.subItems.push( item );
  919. // object[ idSubData.id || idSubData.distinguishedName ] = true;
  920. // }
  921. // }.bind(this));
  922. // }.bind(this));
  923. //
  924. // if( this.selector.options.expandSubEnable ){
  925. // this.selector.orgAction.listSubUnitDirect(function(json){
  926. // json.data.each(function(subData){
  927. // if( !this.selector.isExcluded( subData ) ) {
  928. // var category = this.selector._newItemCategory("ItemUnitCategory", subData, this.selector, this.children, this.level + 1, this);
  929. // this.subCategorys.push( category );
  930. // }
  931. // }.bind(this));
  932. // this.loaded = true;
  933. // if(callback)callback();
  934. // }.bind(this), null, this.data.distinguishedName);
  935. // }else{
  936. // this.loaded = true;
  937. // if(callback)callback();
  938. // }
  939. // }else{
  940. var loadSubUnit = function () {
  941. if( this.selector.options.expandSubEnable && !this.categoryLoaded ){
  942. this.selector.orgAction.listSubUnitDirect(function(json){
  943. json.data.each(function(subData){
  944. if( !this.selector.isExcluded( subData ) ) {
  945. var category = this.selector._newItemCategory("ItemUnitCategory", subData, this.selector, this.children, this.level + 1, this);
  946. this.subCategorys.push( category );
  947. }
  948. }.bind(this));
  949. this.loaded = true;
  950. if (callback) callback( true );
  951. }.bind(this), null, this.data.distinguishedName);
  952. }else{
  953. this.loaded = true;
  954. if (callback) callback( true );
  955. }
  956. }.bind(this);
  957. if( !this.itemLoaded ){
  958. this.selector.orgAction.listIdentityWithUnit(function(idJson){
  959. idJson.data.each(function(idSubData){
  960. if( !this.selector.isExcluded( idSubData ) ) {
  961. var item = this.selector._newItem(idSubData, this.selector, this.children, this.level + 1, this);
  962. this.selector.items.push(item);
  963. if(this.subItems)this.subItems.push( item );
  964. }
  965. }.bind(this));
  966. loadSubUnit();
  967. }.bind(this), null, this.data.distinguishedName);
  968. }else{
  969. loadSubUnit();
  970. }
  971. // }
  972. }else{
  973. if (callback) callback( );
  974. }
  975. },
  976. _hasChild: function(){
  977. var uCount = (this.data.subDirectUnitCount) ? this.data.subDirectUnitCount : 0;
  978. var iCount = (this.data.subDirectIdentityCount) ? this.data.subDirectIdentityCount : 0;
  979. return uCount + iCount;
  980. },
  981. _hasChildCategory: function(){
  982. return (this.data.subDirectUnitCount) ? this.data.subDirectUnitCount : 0;
  983. },
  984. _hasChildItem: function(){
  985. return (this.data.subDirectIdentityCount) ? this.data.subDirectIdentityCount : 0;
  986. },
  987. afterLoad: function(){
  988. if (this.level===1) this.clickItem();
  989. if( this.selector.options.showSelectedCount || this.selector.options.isCheckStatus ){
  990. var count = this._getSelectedCount();
  991. this.checkCountAndStatus( count );
  992. }
  993. },
  994. //for flat category start
  995. clickFlatCategoryItem: function( callback, hidden ){
  996. if (this._hasChildItem()){
  997. var firstLoaded = !this.itemLoaded;
  998. this.loadItemChildren(function(){
  999. if( hidden ){
  1000. //alert("hidden")
  1001. this.children.setStyles({"display": "none", "height": "0px"});
  1002. this.node.setStyles( this.selector.css.flatCategoryItemNode );
  1003. this.isExpand = false;
  1004. }else if( firstLoaded ){
  1005. this.children.setStyles({"display": "block", "height": "auto"});
  1006. this.node.setStyles( this.selector.css.flatCategoryItemNode_selected );
  1007. this.isExpand = true;
  1008. }else{
  1009. var display = this.children.getStyle("display");
  1010. if (display === "none"){
  1011. this.children.setStyles({"display": "block", "height": "auto"});
  1012. this.node.setStyles( this.selector.css.flatCategoryItemNode_selected );
  1013. this.isExpand = true;
  1014. }else{
  1015. this.children.setStyles({"display": "none", "height": "0px"});
  1016. this.node.setStyles( this.selector.css.flatCategoryItemNode );
  1017. this.isExpand = false;
  1018. }
  1019. }
  1020. if(callback)callback();
  1021. }.bind(this));
  1022. }
  1023. },
  1024. loadCategoryChildren: function(callback){
  1025. if (!this.categoryLoaded){
  1026. if( this.selector.options.expandSubEnable ){
  1027. this.selector.orgAction.listSubUnitDirect(function(json){
  1028. json.data.each(function(subData){
  1029. if( !this.selector.isExcluded( subData ) ) {
  1030. var category = this.selector._newItemCategory("ItemUnitCategory", subData, this.selector, this.children, this.level + 1, this);
  1031. this.subCategorys.push( category );
  1032. }
  1033. }.bind(this));
  1034. this.categoryLoaded = true;
  1035. if (callback) callback();
  1036. }.bind(this), null, this.data.distinguishedName);
  1037. }else{
  1038. if (callback) callback();
  1039. }
  1040. }else{
  1041. if (callback) callback( );
  1042. }
  1043. },
  1044. loadItemChildren: function(callback){
  1045. if (!this.itemLoaded){
  1046. // if (this.selector.options.dutys && this.selector.options.dutys.length){
  1047. // var ids = [];
  1048. // var object = {};
  1049. // this.selector.options.dutys.each(function(duty){
  1050. // this.selector.orgAction.listIdentityWidthUnitWithDutyName(this.data.distinguishedName, duty, function(json){
  1051. // if (json.data && json.data.length){
  1052. // ids = ids.concat(json.data);
  1053. // }
  1054. // }.bind(this), null, false);
  1055. //
  1056. // ids.each(function(idSubData){
  1057. // if( !this.selector.isExcluded( idSubData ) && !object[ idSubData.id || idSubData.distinguishedName ]) {
  1058. // var item = this.selector._newItem(idSubData, this.selector, this.children, this.level + 1, this);
  1059. // this.selector.items.push(item);
  1060. // if(this.subItems)this.subItems.push( item );
  1061. // object[ idSubData.id || idSubData.distinguishedName ] = true;
  1062. // }
  1063. // this.itemLoaded = true;
  1064. // }.bind(this));
  1065. // }.bind(this));
  1066. // if (callback) callback();
  1067. // }else{
  1068. this.selector.orgAction.listIdentityWithUnit(function(idJson){
  1069. idJson.data.each(function(idSubData){
  1070. if( !this.selector.isExcluded( idSubData ) ) {
  1071. var item = this.selector._newItem(idSubData, this.selector, this.children, this.level + 1, this);
  1072. this.selector.items.push(item);
  1073. if(this.subItems)this.subItems.push( item );
  1074. }
  1075. this.itemLoaded = true;
  1076. }.bind(this));
  1077. if (callback) callback();
  1078. }.bind(this), null, this.data.distinguishedName);
  1079. // }
  1080. }else{
  1081. if (callback) callback( );
  1082. }
  1083. }
  1084. //for flat category end
  1085. });
  1086. MWF.xApplication.Selector.Identity.ItemUnitCategory = new Class({
  1087. Extends: MWF.xApplication.Selector.Identity.ItemCategory
  1088. });
  1089. MWF.xApplication.Selector.Identity.ItemGroupCategory = new Class({
  1090. Extends: MWF.xApplication.Selector.Identity.ItemCategory,
  1091. createNode: function(){
  1092. this.node = new Element("div", {
  1093. "styles": this.selector.css.selectorItemCategory
  1094. }).inject(this.container);
  1095. },
  1096. _setIcon: function(){
  1097. var style = this.selector.options.style;
  1098. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/groupicon.png)");
  1099. },
  1100. _getTotalCount : function(){
  1101. if( !this.selector.allGroupObjectByDn )return 0;
  1102. var group = this.selector.allGroupObjectByDn[this.data.distinguishedName];
  1103. var count = group ? group.subNestedIdentityCount : 0;
  1104. return count;
  1105. },
  1106. _getSelectedCount : function(){
  1107. if( typeOf(this.selectedCount) === "number" )return this.selectedCount;
  1108. if( !this.selector.allGroupObjectByDn )return 0;
  1109. var group = this.selector.allGroupObjectByDn[this.data.distinguishedName];
  1110. var count = group ? group.selectedNestedIdentityCount : 0;
  1111. this.selectedCount = count;
  1112. return count;
  1113. },
  1114. loadSub: function(callback){
  1115. if (!this.loaded){
  1116. var personContainer, identityContainer, groupContainer, unitContainer;
  1117. if( this.data.personList )personContainer = new Element("div").inject( this.children );
  1118. if( this.data.identityList )identityContainer = new Element("div").inject( this.children );
  1119. if( this.data.groupList )groupContainer = new Element("div").inject( this.children );
  1120. if( this.data.unitList )unitContainer = new Element("div").inject( this.children );
  1121. var personLoadedCount = 0;
  1122. var identityLoadedCount = 0;
  1123. var unitLoadedCount = 0;
  1124. var groupLoadedCount = 0;
  1125. var checkCallback = function( type, count ){
  1126. var addCount = count || 1;
  1127. if( !this.selector.options.expandSubEnable ){
  1128. if( type === "person" )personLoadedCount += addCount;
  1129. if( type === "identity" )identityLoadedCount += addCount;
  1130. if(
  1131. (!this.data.personList || this.data.personList.length === 0 || this.data.personList.length == personLoadedCount) &&
  1132. (!this.data.identityList || this.data.identityList.length === 0 || this.data.identityList.length == identityLoadedCount)
  1133. ){
  1134. this.loaded = true;
  1135. if (callback) callback();
  1136. }
  1137. }else{
  1138. if( type === "person" )personLoadedCount += addCount;
  1139. if( type === "identity" )identityLoadedCount += addCount;
  1140. if( type === "unit" )unitLoadedCount += addCount;
  1141. if( type === "group" )groupLoadedCount += addCount;
  1142. if( ( !this.data.personList || this.data.personList.length === 0 || this.data.personList.length == personLoadedCount ) &&
  1143. ( !this.data.identityList || this.data.identityList.length === 0 || this.data.identityList.length == identityLoadedCount )&&
  1144. ( !this.data.unitList || this.data.unitList.length === 0 || this.data.unitList.length == unitLoadedCount ) &&
  1145. ( !this.data.groupList || this.data.groupList.length === 0 || this.data.groupList.length == groupLoadedCount ) ){
  1146. this.loaded = true;
  1147. if (callback) callback();
  1148. }
  1149. }
  1150. }.bind(this);
  1151. checkCallback();
  1152. if( this.data.identityList && this.data.identityList.length > 0 ){
  1153. if( this.selector.options.resultType === "person" ) {
  1154. //根据身份id批量获取人员对象
  1155. o2.Actions.load("x_organization_assemble_express").PersonAction.listWithIdentityObject({
  1156. identityList : this.data.identityList
  1157. }, function (json) {
  1158. this.selector.includeObject.loadPersonItem( json, identityContainer, this.level + 1, this);
  1159. checkCallback("identity", this.data.identityList.length )
  1160. }.bind(this), function () {
  1161. checkCallback("identity", this.data.identityList.length )
  1162. }.bind(this))
  1163. }else{
  1164. //根据身份id批量获取身份对象
  1165. o2.Actions.load("x_organization_assemble_express").IdentityAction.listObject({
  1166. identityList : this.data.identityList
  1167. }, function (json) {
  1168. this.selector.includeObject.loadIdentityItem( json, identityContainer, this.level + 1, this);
  1169. checkCallback("identity", this.data.identityList.length )
  1170. }.bind(this), function () {
  1171. checkCallback("identity", this.data.identityList.length )
  1172. }.bind(this))
  1173. }
  1174. }
  1175. if( this.data.personList && this.data.personList.length > 0 ){
  1176. if( this.selector.options.resultType === "person" ) {
  1177. //根据人员d批量获取人员对象
  1178. o2.Actions.load("x_organization_assemble_express").PersonAction.listObject({
  1179. personList : this.data.personList
  1180. }, function (json) {
  1181. this.selector.includeObject.loadPersonItem( json, personContainer, this.level + 1, this);
  1182. checkCallback("person", this.data.personList.length )
  1183. }.bind(this), function () {
  1184. checkCallback("person", this.data.personList.length )
  1185. }.bind(this))
  1186. }else{
  1187. //根据人员id批量获取身份对象
  1188. o2.Actions.load("x_organization_assemble_express").IdentityAction.listWithPersonObject({
  1189. personList : this.data.personList
  1190. }, function (json) {
  1191. this.selector.includeObject.loadIdentityItem( json, personContainer, this.level + 1, this);
  1192. checkCallback("person", this.data.personList.length )
  1193. }.bind(this), function () {
  1194. checkCallback("person", this.data.personList.length )
  1195. }.bind(this))
  1196. }
  1197. }
  1198. // ( this.data.personList || [] ).each( function(p){
  1199. // if( this.selector.options.resultType === "person" ){
  1200. // this.selector.orgAction.getPerson(function (json) {
  1201. // this.selector.includeObject.loadPersonItem(json, this.children, this.level + 1, this );
  1202. // checkCallback("person");
  1203. // }.bind(this), function(){ checkCallback("person") }, p );
  1204. // }else{
  1205. // this.selector.orgAction.listIdentityByPerson(function(json){
  1206. // this.selector.includeObject.loadIdentityItem(json, this.children, this.level + 1, this);
  1207. // checkCallback("person")
  1208. // }.bind(this), function(){ checkCallback("person") }, p );
  1209. // }
  1210. // }.bind(this));
  1211. //list 服务不能获取下级数量
  1212. // if( this.selector.options.expandSubEnable ){
  1213. // o2.Actions.load("x_organization_assemble_express").UnitAction.listObject({
  1214. // unitList : this.data.unitList
  1215. // }, function (json) {
  1216. // this.selector.includeObject.loadUnitItem( json, this.children, this.level + 1, this);
  1217. // checkCallback("unit", this.data.unitList.length )
  1218. // }.bind(this), function () {
  1219. // checkCallback("unit", this.data.unitList.length )
  1220. // }.bind(this))
  1221. //
  1222. //
  1223. // o2.Actions.load("x_organization_assemble_express").GroupAction.listObject({
  1224. // groupList : this.data.groupList
  1225. // }, function (json) {
  1226. // this.selector.includeObject.loadGroupItem(json, this.children, this.level + 1, this);
  1227. // checkCallback("group", this.data.groupList.length )
  1228. // }.bind(this), function () {
  1229. // checkCallback("group", this.data.groupList.length )
  1230. // }.bind(this))
  1231. // }
  1232. if( this.selector.options.expandSubEnable ){
  1233. ( this.data.unitList || [] ).each( function(u){
  1234. this.selector.orgAction.getUnit(function (json) {
  1235. this.selector.includeObject.loadUnitItem(json, unitContainer, this.level + 1, this);
  1236. checkCallback("unit");
  1237. }.bind(this), function(){ checkCallback("unit") }, u );
  1238. }.bind(this));
  1239. ( this.data.groupList || [] ).each( function(g){
  1240. this.selector.orgAction.getGroup(function (json) {
  1241. this.selector.includeObject.loadGroupItem(json, groupContainer, this.level + 1, this);
  1242. checkCallback("group");
  1243. }.bind(this), function(){ checkCallback("group") }, g );
  1244. }.bind(this));
  1245. }
  1246. }else{
  1247. if (callback) callback( );
  1248. }
  1249. },
  1250. loadCategoryChildren: function(callback){
  1251. if (!this.categoryLoaded){
  1252. var groupContainer, unitContainer;
  1253. if( this.data.groupList )groupContainer = new Element("div").inject( this.children );
  1254. if( this.data.unitList )unitContainer = new Element("div").inject( this.children );
  1255. var unitLoadedCount = 0;
  1256. var groupLoadedCount = 0;
  1257. var checkCallback = function( type, count ){
  1258. var addCount = count || 1;
  1259. if( !this.selector.options.expandSubEnable ){
  1260. this.categoryLoaded = true;
  1261. }else{
  1262. if( type === "unit" )unitLoadedCount += addCount;
  1263. if( type === "group" )groupLoadedCount += addCount;
  1264. if( ( !this.data.unitList || this.data.unitList.length === 0 || this.data.unitList.length == unitLoadedCount ) &&
  1265. ( !this.data.groupList || this.data.groupList.length === 0 || this.data.groupList.length == groupLoadedCount ) ){
  1266. this.categoryLoaded = true;
  1267. if (callback) callback();
  1268. }
  1269. }
  1270. }.bind(this);
  1271. checkCallback();
  1272. //list 服务不能获取下级数量
  1273. // if( this.selector.options.expandSubEnable ){
  1274. // o2.Actions.load("x_organization_assemble_express").UnitAction.listObject({
  1275. // unitList : this.data.unitList
  1276. // }, function (json) {
  1277. // this.selector.includeObject.loadUnitItem( json, this.children, this.level + 1, this);
  1278. // checkCallback("unit", this.data.unitList.length )
  1279. // }.bind(this), function () {
  1280. // checkCallback("unit", this.data.unitList.length )
  1281. // }.bind(this))
  1282. //
  1283. //
  1284. // o2.Actions.load("x_organization_assemble_express").GroupAction.listObject({
  1285. // groupList : this.data.groupList
  1286. // }, function (json) {
  1287. // this.selector.includeObject.loadGroupItem(json, this.children, this.level + 1, this);
  1288. // checkCallback("group", this.data.groupList.length )
  1289. // }.bind(this), function () {
  1290. // checkCallback("group", this.data.groupList.length )
  1291. // }.bind(this))
  1292. // }
  1293. if( this.selector.options.expandSubEnable ){
  1294. ( this.data.unitList || [] ).each( function(u){
  1295. this.selector.orgAction.getUnit(function (json) {
  1296. this.selector.includeObject.loadUnitItem(json, unitContainer, this.level + 1, this);
  1297. checkCallback("unit");
  1298. }.bind(this), function(){ checkCallback("unit") }, u );
  1299. }.bind(this));
  1300. ( this.data.groupList || [] ).each( function(g){
  1301. this.selector.orgAction.getGroup(function (json) {
  1302. this.selector.includeObject.loadGroupItem(json, groupContainer, this.level + 1, this);
  1303. checkCallback("group");
  1304. }.bind(this), function(){ checkCallback("group") }, g );
  1305. }.bind(this));
  1306. }
  1307. }else{
  1308. if (callback) callback( );
  1309. }
  1310. },
  1311. loadItemChildren: function(callback){
  1312. if (!this.itemLoaded){
  1313. var personContainer, identityContainer;
  1314. if( this.data.personList )personContainer = new Element("div").inject( this.children );
  1315. if( this.data.identityList )identityContainer = new Element("div").inject( this.children );
  1316. var personLoadedCount = 0;
  1317. var identityLoadedCount = 0;
  1318. var checkCallback = function( type, count ){
  1319. var addCount = count || 1;
  1320. if( type === "person" )personLoadedCount += addCount;
  1321. if( type === "identity" )identityLoadedCount += addCount;
  1322. if(
  1323. (!this.data.personList || this.data.personList.length === 0 || this.data.personList.length == personLoadedCount) &&
  1324. (!this.data.identityList || this.data.identityList.length === 0 || this.data.identityList.length == identityLoadedCount)
  1325. ){
  1326. this.itemLoaded = true;
  1327. if (callback) callback();
  1328. }
  1329. }.bind(this);
  1330. checkCallback();
  1331. if( this.data.identityList && this.data.identityList.length > 0 ){
  1332. if( this.selector.options.resultType === "person" ) {
  1333. //根据身份id批量获取人员对象
  1334. o2.Actions.load("x_organization_assemble_express").PersonAction.listWithIdentityObject({
  1335. identityList : this.data.identityList
  1336. }, function (json) {
  1337. this.selector.includeObject.loadPersonItem( json, identityContainer, this.level + 1, this);
  1338. checkCallback("identity", this.data.identityList.length )
  1339. }.bind(this), function () {
  1340. checkCallback("identity", this.data.identityList.length )
  1341. }.bind(this))
  1342. }else{
  1343. //根据身份id批量获取身份对象
  1344. o2.Actions.load("x_organization_assemble_express").IdentityAction.listObject({
  1345. identityList : this.data.identityList
  1346. }, function (json) {
  1347. this.selector.includeObject.loadIdentityItem( json, identityContainer, this.level + 1, this);
  1348. checkCallback("identity", this.data.identityList.length )
  1349. }.bind(this), function () {
  1350. checkCallback("identity", this.data.identityList.length )
  1351. }.bind(this))
  1352. }
  1353. }
  1354. if( this.data.personList && this.data.personList.length > 0 ){
  1355. if( this.selector.options.resultType === "person" ) {
  1356. //根据人员d批量获取人员对象
  1357. o2.Actions.load("x_organization_assemble_express").PersonAction.listObject({
  1358. personList : this.data.personList
  1359. }, function (json) {
  1360. this.selector.includeObject.loadPersonItem( json, personContainer, this.level + 1, this);
  1361. checkCallback("person", this.data.personList.length )
  1362. }.bind(this), function () {
  1363. checkCallback("person", this.data.personList.length )
  1364. }.bind(this))
  1365. }else{
  1366. //根据人员id批量获取身份对象
  1367. o2.Actions.load("x_organization_assemble_express").IdentityAction.listWithPersonObject({
  1368. personList : this.data.personList
  1369. }, function (json) {
  1370. this.selector.includeObject.loadIdentityItem( json, personContainer, this.level + 1, this);
  1371. checkCallback("person", this.data.personList.length )
  1372. }.bind(this), function () {
  1373. checkCallback("person", this.data.personList.length )
  1374. }.bind(this))
  1375. }
  1376. }
  1377. // ( this.data.personList || [] ).each( function(p){
  1378. // if( this.selector.options.resultType === "person" ){
  1379. // this.selector.orgAction.getPerson(function (json) {
  1380. // this.selector.includeObject.loadPersonItem(json, this.children, this.level + 1, this );
  1381. // checkCallback("person");
  1382. // }.bind(this), function(){ checkCallback("person") }, p );
  1383. // }else{
  1384. // this.selector.orgAction.listIdentityByPerson(function(json){
  1385. // this.selector.includeObject.loadIdentityItem(json, this.children, this.level + 1, this);
  1386. // checkCallback("person")
  1387. // }.bind(this), function(){ checkCallback("person") }, p );
  1388. // }
  1389. // }.bind(this));
  1390. }else{
  1391. if (callback) callback( );
  1392. }
  1393. },
  1394. _hasChild: function(){
  1395. var uCount = (this.data.unitList) ? this.data.unitList.length : 0;
  1396. var gCount = (this.data.groupList) ? this.data.groupList.length : 0;
  1397. var pCount = (this.data.personList) ? this.data.personList.length : 0;
  1398. var iCount = (this.data.identityList) ? this.data.identityList.length : 0;
  1399. return uCount + gCount + pCount + iCount;
  1400. },
  1401. _hasChildCategory: function(){
  1402. var uCount = (this.data.unitList) ? this.data.unitList.length : 0;
  1403. var gCount = (this.data.groupList) ? this.data.groupList.length : 0;
  1404. return uCount + gCount;
  1405. },
  1406. _hasChildItem: function(){
  1407. var pCount = (this.data.personList) ? this.data.personList.length : 0;
  1408. var iCount = (this.data.identityList) ? this.data.identityList.length : 0;
  1409. return pCount + iCount;
  1410. }
  1411. });
  1412. MWF.xApplication.Selector.Identity.ItemRoleCategory = new Class({
  1413. Extends: MWF.xApplication.Selector.Person.ItemCategory,
  1414. _getShowName: function(){
  1415. return this.data.name;
  1416. },
  1417. _setIcon: function(){
  1418. var style = this.selector.options.style;
  1419. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/roleicon.png)");
  1420. }
  1421. });
  1422. MWF.xApplication.Selector.Identity.Include = new Class({
  1423. Implements: [Options, Events],
  1424. options: {
  1425. "include" : [], //增加的可选项
  1426. "resultType" : "", //可以设置成个人,那么结果返回个人
  1427. "expandSubEnable" : true //是否允许展开下一层
  1428. },
  1429. initialize: function(selector, itemAreaNode, options){
  1430. this.setOptions(options);
  1431. this.selector = selector;
  1432. this.itemAreaNode = $(itemAreaNode);
  1433. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  1434. },
  1435. load : function( callback ){
  1436. if( !this.options.include || this.options.include.length === 0 ){
  1437. this.fireEvent("afterLoad");
  1438. if(callback)callback();
  1439. return;
  1440. }
  1441. var count = 0;
  1442. var checkCallback = function () {
  1443. count++;
  1444. if( count === this.options.include.length ){
  1445. this.fireEvent("afterLoad");
  1446. if(callback)callback();
  1447. }
  1448. }.bind(this);
  1449. this.includeAreaNode = new Element( "div.includeAreaNode").inject( this.itemAreaNode, "top" );
  1450. if( this.selector.isFlatCategory ){
  1451. this.flatCategoryAreaNode = new Element( "div.includeFlatCategoryAreaNode").inject( this.selector.flatCategoryNode, "top" );
  1452. }
  1453. //this.includeIdentityAreaNode = new Element( "div").inject( this.includeAreaNode );
  1454. //this.includePersonAreaNode = new Element( "div").inject( this.includeAreaNode );
  1455. //this.includeUnitAreaNode = new Element( "div").inject( this.includeAreaNode );
  1456. //this.includeGroupAreaNode = new Element( "div").inject( this.includeAreaNode );
  1457. this.options.include.each( function( d ){
  1458. var container = new Element("div").inject( this.includeAreaNode );
  1459. var flatCategoryContainer;
  1460. if( this.flatCategoryAreaNode ){
  1461. flatCategoryContainer = new Element("div").inject( this.flatCategoryAreaNode );
  1462. }
  1463. if (typeOf(d)==="string"){
  1464. var arr = d.split("@");
  1465. var flag = arr[ arr.length - 1].toLowerCase();
  1466. if( flag === "u" ){
  1467. this.orgAction.listUnitByKey(function(json){
  1468. this.loadUnitItem(json, container, null, null, flatCategoryContainer);
  1469. checkCallback();
  1470. }.bind(this), checkCallback, d);
  1471. }else if( flag === "i" ) {
  1472. this.orgAction.listIdentityByKey(function (json) {
  1473. this.loadIdentityItem(json, container, null, null, true );
  1474. checkCallback();
  1475. }.bind(this), checkCallback, d);
  1476. }else if( flag === "g" ){
  1477. this.orgAction.listGroupByKey(function(json){
  1478. this.loadGroupItem( json , container, null, null, flatCategoryContainer);
  1479. checkCallback();
  1480. }.bind(this), checkCallback, d);
  1481. }else if( flag === "p" ){
  1482. if( this.options.resultType === "person" ){
  1483. this.orgAction.getPerson(function (json){
  1484. this.loadPersonItem( json , container, null, null, true);
  1485. checkCallback();
  1486. }.bind(this), checkCallback, d);
  1487. }else{
  1488. this.orgAction.listIdentityByPerson(function(json){
  1489. this.loadIdentityItem(json, container , null, null, true);
  1490. checkCallback();
  1491. }.bind(this), checkCallback, d);
  1492. }
  1493. }else{
  1494. if( this.options.resultType === "person" ){
  1495. this.orgAction.listPersonByKey(function (json) {
  1496. this.loadPersonItem( json , container, null, null, true);
  1497. checkCallback();
  1498. }.bind(this), checkCallback, d);
  1499. }else{
  1500. this.orgAction.listIdentityByKey(function(json){
  1501. this.loadIdentityItem(json, container, null, null, true);
  1502. checkCallback();
  1503. }.bind(this), checkCallback, d);
  1504. }
  1505. }
  1506. }else{
  1507. var arr = d.distinguishedName.split("@");
  1508. var flag = arr[ arr.length - 1].toLowerCase();
  1509. if( flag === "u" ) {
  1510. this.orgAction.getUnit(function (json) {
  1511. this.loadUnitItem(json, container, null, null, flatCategoryContainer);
  1512. checkCallback();
  1513. }.bind(this), checkCallback, d.distinguishedName);
  1514. }else if( flag === "i" ){
  1515. this.orgAction.getIdentity(function (json) {
  1516. this.loadIdentityItem(json, container, null, null, true);
  1517. checkCallback();
  1518. }.bind(this), checkCallback, d.distinguishedName);
  1519. }else if( flag === "g" ){
  1520. this.orgAction.getGroup(function(json){
  1521. this.loadGroupItem( json , container, null, null, flatCategoryContainer);
  1522. checkCallback();
  1523. }.bind(this), checkCallback, d.distinguishedName, null, null, true);
  1524. }else if( flag === "p" ){
  1525. if( this.options.resultType === "person" ){
  1526. this.orgAction.getPerson(function (json) {
  1527. this.loadPersonItem(json, container, null, null, true);
  1528. checkCallback();
  1529. }.bind(this), checkCallback, d.distinguishedName);
  1530. }else{
  1531. this.orgAction.listIdentityByPerson(function(json){
  1532. this.loadIdentityItem(json, container, null, null, true);
  1533. checkCallback();
  1534. }.bind(this), checkCallback, d.distinguishedName);
  1535. }
  1536. }else{
  1537. if( this.options.resultType === "person" ){
  1538. this.orgAction.getPerson(function (json) {
  1539. this.loadPersonItem(json, container, null, null, true);
  1540. checkCallback();
  1541. }.bind(this), checkCallback, d.distinguishedName);
  1542. }else{
  1543. this.orgAction.getIdentity(function (json) {
  1544. this.loadIdentityItem(json, container, null, null, true);
  1545. checkCallback();
  1546. }.bind(this), checkCallback, d.distinguishedName);
  1547. }
  1548. }
  1549. //var category = this._newItemCategory("ItemCategory", unit, this, this.itemAreaNode);
  1550. }
  1551. }.bind(this))
  1552. },
  1553. loadPersonItem : function( json, container, level, category, isIncludedPerson ){
  1554. if( !json.data )return;
  1555. var array = typeOf( json.data ) === "array" ? json.data : [json.data];
  1556. array.each(function(data){
  1557. if( !this.selector.isExcluded( data ) ) {
  1558. if(!this.includePerson)this.includePerson = [];
  1559. if(isIncludedPerson)this.includePerson.push( data.distinguishedName );
  1560. if(!this.includePersonObject)this.includePersonObject = [];
  1561. if(isIncludedPerson)this.includePersonObject.push( data );
  1562. var item = this.selector._newItem(data, this.selector, container || this.includeAreaNode, level || 1, category);
  1563. this.selector.items.push(item);
  1564. if( category && category.subItems ){
  1565. category.subItems.push( item );
  1566. }else if(this.selector.subItems){
  1567. this.selector.subItems.push( item )
  1568. }
  1569. }
  1570. }.bind(this));
  1571. },
  1572. loadIdentityItem : function( json, container, level, category, isIncludedIdentity ){
  1573. if( !json.data )return;
  1574. var array = typeOf( json.data ) === "array" ? json.data : [json.data];
  1575. array.each(function(data){
  1576. if( !this.selector.isExcluded( data ) ) {
  1577. if(!this.includeIdentity)this.includeIdentity = [];
  1578. if(isIncludedIdentity)this.includeIdentity.push( data.distinguishedName );
  1579. if(!this.includeIdentityObject)this.includeIdentityObject = [];
  1580. if(isIncludedIdentity)this.includeIdentityObject.push( data );
  1581. var item = this.selector._newItem(data, this.selector, container || this.includeAreaNode, level || 1, category);
  1582. this.selector.items.push(item);
  1583. if( category && category.subItems ){
  1584. category.subItems.push( item );
  1585. }else if(this.selector.subItems){
  1586. this.selector.subItems.push( item )
  1587. }
  1588. }
  1589. }.bind(this));
  1590. },
  1591. loadUnitItem : function( json, container, level, parentCategory, flatCategoryContainer ){
  1592. if( !json.data )return;
  1593. var array = typeOf( json.data ) === "array" ? json.data : [json.data];
  1594. array.each(function(data){
  1595. if( !this.selector.isExcluded( data ) ) {
  1596. if(!this.includeUnit)this.includeUnit = [];
  1597. this.includeUnit.push( data.distinguishedName );
  1598. var category;
  1599. if( flatCategoryContainer ){
  1600. category = this.selector._newItemCategory("ItemUnitCategory", data, this.selector,
  1601. container || this.includeAreaNode, level, parentCategory, true);
  1602. category.nodeContainer = flatCategoryContainer;
  1603. category.load();
  1604. }else{
  1605. category = this.selector._newItemCategory("ItemUnitCategory", data, this.selector,
  1606. container || this.includeAreaNode, level, parentCategory);
  1607. }
  1608. if( parentCategory && parentCategory.subCategorys ){
  1609. parentCategory.subCategorys.push( category )
  1610. }else if(this.selector.subCategorys){
  1611. this.selector.subCategorys.push( category )
  1612. }
  1613. }
  1614. }.bind(this));
  1615. },
  1616. loadGroupItem : function( json, container, level, parentCategory, flatCategoryContainer ){
  1617. if( !json.data )return;
  1618. var array = typeOf( json.data ) === "array" ? json.data : [json.data];
  1619. array.each(function(data){
  1620. if( !this.selector.isExcluded( data ) ) {
  1621. if(!this.includeGroup)this.includeGroup = [];
  1622. this.includeGroup.push( data.distinguishedName );
  1623. var category;
  1624. if( flatCategoryContainer ){
  1625. category = this.selector._newItemCategory("ItemGroupCategory", data, this.selector, container || this.includeAreaNode, level, parentCategory, true);
  1626. category.nodeContainer = flatCategoryContainer;
  1627. category.load();
  1628. }else{
  1629. category = this.selector._newItemCategory("ItemGroupCategory", data, this.selector, container || this.includeAreaNode, level, parentCategory)
  1630. }
  1631. if( parentCategory && parentCategory.subCategorys ){
  1632. parentCategory.subCategorys.push( category )
  1633. }else if(this.selector.subCategorys){
  1634. this.selector.subCategorys.push( category )
  1635. }
  1636. }
  1637. }.bind(this));
  1638. },
  1639. listByFilter : function( type, key, callback ){
  1640. var arr1 = this.listByFilterPerson(key) || [];
  1641. this.listByFilterUnitAndGroup( type, key, function(arr2){
  1642. this.listByFilterGroup( type, key, function(arr3){
  1643. if (callback) callback( arr1.concat( arr2 || [] ).concat( arr3 || [] ) );
  1644. }.bind(this))
  1645. }.bind(this))
  1646. },
  1647. listByFilterPerson : function( key ){
  1648. var identitys = [];
  1649. var persons = [];
  1650. var keyString = typeOf( key )==="string" ? key.toLowerCase() : key.key.toLowerCase();
  1651. if( this.includeIdentityObject && this.includeIdentityObject.length ){
  1652. identitys = this.includeIdentityObject.filter( function(id) {
  1653. return ( id.pinyin || "" ).indexOf(keyString) > -1 || (id.pinyinInitial || "").indexOf(keyString) > -1 || (id.distinguishedName || "").indexOf(keyString) > -1;
  1654. })
  1655. }
  1656. if( this.includePersonObject && this.includePersonObject.length ){
  1657. persons = this.includePersonObject.filter( function(id) {
  1658. return ( id.pinyin || "" ).indexOf(keyString) > -1 || (id.pinyinInitial || "").indexOf(keyString) > -1 || (id.distinguishedName || "").indexOf(keyString) > -1;
  1659. })
  1660. }
  1661. return identitys.concat( persons);
  1662. },
  1663. listByFilterGroup : function( type, key, callback ){
  1664. //根据关键字获取群组内的人员,再转成身份
  1665. var keyString = typeOf( key )==="string" ? key.toLowerCase() : key.key.toLowerCase();
  1666. if( this.includeGroup && this.includeGroup.length ){
  1667. var keyObject = { "key" : keyString, "groupList" : this.includeGroup };
  1668. this.orgAction[ type === "pinyin" ? "listPersonByPinyin" : "listPersonByKey" ](function(json){
  1669. if( this.options.resultType === "person" ){
  1670. if (callback) callback( json.data );
  1671. }else{
  1672. var personList = (json.data || []).map( function(d){
  1673. return d.id
  1674. });
  1675. o2.Actions.get("x_organization_assemble_express").listIdentityWithPerson( { "personList" : personList }, function(js){
  1676. if (callback) callback(js.data);
  1677. }.bind(this), function(){
  1678. if (callback) callback();
  1679. }.bind(this))
  1680. }
  1681. }.bind(this), function(){
  1682. if (callback) callback();
  1683. }.bind(this), keyObject);
  1684. }else{
  1685. if (callback) callback();
  1686. }
  1687. },
  1688. listByFilterUnitAndGroup : function( type, key, callback ){
  1689. //根据关键字获取组织和群组内的身份
  1690. var keyString = typeOf( key )==="string" ? key.toLowerCase() : key.key.toLowerCase();
  1691. if ( this.includeUnit && this.includeUnit.length ){
  1692. key = this.getUnitFilterKey( key, this.includeUnit, this.includeGroup );
  1693. this.orgAction.listIdentityByKey(function(json){
  1694. if (callback) callback(json.data);
  1695. }.bind(this), function(){
  1696. if (callback) callback();
  1697. }, key);
  1698. }else{
  1699. if (callback) callback();
  1700. }
  1701. },
  1702. getUnitFilterKey : function( key, unitObject, groupObject ){
  1703. var unitObjects = unitObject || [];
  1704. var units = [];
  1705. unitObjects.each(function(u){
  1706. if (typeOf(u)==="string"){
  1707. units.push(u);
  1708. }
  1709. if (typeOf(u)==="object"){
  1710. units.push(u.distinguishedName);
  1711. }
  1712. });
  1713. var groupObjects = groupObject || [];
  1714. var groups = [];
  1715. groupObjects.each(function(g){
  1716. if (typeOf(g)==="string"){
  1717. groups.push(g);
  1718. }
  1719. if (typeOf(g)==="object"){
  1720. groups.push(g.distinguishedName);
  1721. }
  1722. });
  1723. if( !units.length && !groups.length ){
  1724. return key;
  1725. }else{
  1726. var result = { "key": key };
  1727. if( units.length )result.unitList = units;
  1728. if( groups.length )result.groupList = groups;
  1729. return result;
  1730. }
  1731. // return units.length ? {"key": key, "unitList": units, "groupList" : groups} : key;
  1732. }
  1733. });
  1734. MWF.xApplication.Selector.Identity.Filter = new Class({
  1735. Implements: [Options, Events],
  1736. options: {
  1737. "style": "default",
  1738. "units": [],
  1739. "resultType" : "" //可以设置成个人,那么结果返回个人
  1740. },
  1741. initialize: function(value, options){
  1742. this.setOptions(options);
  1743. this.value = value;
  1744. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  1745. },
  1746. filter: function(value, callback){
  1747. this.value = value;
  1748. var key = this.value;
  1749. if (this.options.units.length){
  1750. var units = [];
  1751. this.options.units.each(function(u){
  1752. if (typeOf(u)==="string"){
  1753. units.push(u);
  1754. }
  1755. if (typeOf(u)==="object"){
  1756. units.push(u.distinguishedName);
  1757. }
  1758. });
  1759. key = {"key": this.value, "unitList": units};
  1760. }
  1761. var data = null;
  1762. this.orgAction.listIdentityByKey(function(json){
  1763. data = json.data;
  1764. if (callback) callback(data)
  1765. }.bind(this), null, key);
  1766. }
  1767. });