Identity.js 81 KB

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