Identity.js 83 KB

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