Identity.js 85 KB

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