Identity.js 85 KB

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