Identity.js 84 KB

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