Identity.js 83 KB

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