Identity.js 91 KB

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