Identity.js 85 KB

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