Identity.js 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290
  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. loadSelectItems: function(addToNext){
  22. if( this.options.resultType === "person" ){
  23. if( this.titleTextNode ){
  24. this.titleTextNode.set("text", MWF.xApplication.Selector.LP.selectPerson );
  25. }else{
  26. this.options.title = MWF.xApplication.Selector.LP.selectPerson;
  27. }
  28. }
  29. if(this.options.noUnit){
  30. this.loadInclude();
  31. }else if (this.options.units.length){
  32. // var units = [];
  33. // this.options.units.each(function(u){
  34. // if (typeOf(u)==="string"){
  35. // units.push(u);
  36. // }else{
  37. // units.push(u.distinguishedName)
  38. // }
  39. // });
  40. // this.org2Action.listUnit({"unitList":units}, function(json){
  41. // json.data.each(function(d){
  42. // var category = this._newItemCategory("ItemUnitCategory", d, this, this.itemAreaNode);
  43. // this.subCategorys.push( category );
  44. // }.bind(this));
  45. // }.bind(this));
  46. this.options.units.each(function(unit){
  47. if (typeOf(unit)==="string"){
  48. this.orgAction.getUnit(unit, function(json){
  49. if (json.data){
  50. var category = this._newItemCategory("ItemUnitCategory", json.data, this, this.itemAreaNode);
  51. this.subCategorys.push( category );
  52. }
  53. this.loadInclude();
  54. }.bind(this), function(){
  55. this.orgAction.listUnitByKey(function(json){
  56. if (json.data.length){
  57. json.data.each(function(data){
  58. var category = this._newItemCategory("ItemUnitCategory", data, this, this.itemAreaNode);
  59. this.subCategorys.push( category );
  60. }.bind(this))
  61. }
  62. this.loadInclude();
  63. }.bind(this), null, unit);
  64. }.bind(this));
  65. }else{
  66. this.orgAction.getUnit(function(json){
  67. if (json.data){
  68. var category = this._newItemCategory("ItemUnitCategory", json.data, this, this.itemAreaNode);
  69. this.subCategorys.push( category );
  70. }
  71. this.loadInclude();
  72. }.bind(this), null, unit.distinguishedName);
  73. //var category = this._newItemCategory("ItemCategory", unit, this, this.itemAreaNode);
  74. }
  75. }.bind(this));
  76. }else{
  77. this.orgAction.listTopUnit(function(json){
  78. json.data.each(function(data){
  79. if( !this.isExcluded( data ) ){
  80. var category = this._newItemCategory("ItemUnitCategory", data, this, this.itemAreaNode);
  81. this.subCategorys.push( category );
  82. }
  83. }.bind(this));
  84. this.loadInclude();
  85. }.bind(this));
  86. }
  87. },
  88. loadInclude: function() {
  89. if (!this.includeObject){
  90. this.includeObject = new MWF.xApplication.Selector.Identity.Include(this, this.itemAreaNode, {
  91. "include": this.options.include, //增加的可选项
  92. "resultType": this.options.resultType, //可以设置成个人,那么结果返回个人
  93. "expandSubEnable": this.options.expandSubEnable //是否允许展开下一层
  94. });
  95. }
  96. this.includeObject.load();
  97. },
  98. checkLoadSelectItems: function(){
  99. if (!this.options.units.length){
  100. this.loadSelectItems();
  101. }else{
  102. this.loadSelectItems();
  103. }
  104. },
  105. _scrollEvent: function(y){
  106. return true;
  107. },
  108. _getChildrenItemIds: function(){
  109. return null;
  110. },
  111. _newItemCategory: function(type, data, selector, item, level, category, delay){
  112. return new MWF.xApplication.Selector.Identity[type](data, selector, item, level, category, delay)
  113. },
  114. _listItem : function( filterType, callback, failure, key ){
  115. if( this.options.noUnit ){
  116. this.includeObject.listByFilter( filterType, key, function( array ){
  117. var json = {"data" : array} ;
  118. if (callback) callback.apply(this, [json]);
  119. }.bind(this))
  120. }else{
  121. var action = filterType === "key" ? "listIdentityByKey" : "listIdentityByPinyin";
  122. if ( this.options.units.length ){
  123. key = this.getLikeKey( key, this.options.units );
  124. this.orgAction[action](function(json){ //搜若units内的组织
  125. this.includeObject.listByFilter( filterType, key, function( array ){
  126. json.data = array.concat( json.data || [] );
  127. if (callback) callback.apply(this, [json]);
  128. }.bind(this));
  129. }.bind(this), failure, key);
  130. }else{ //搜索所有人
  131. this.orgAction[action](function(json){
  132. if (callback) callback.apply(this, [json]);
  133. }.bind(this), failure, key);
  134. }
  135. }
  136. },
  137. _listItemByKey: function(callback, failure, key){
  138. this._listItem( "key", callback, failure, key );
  139. },
  140. _getItem: function(callback, failure, id, async){
  141. this.orgAction.getIdentity(function(json){
  142. if (callback) callback.apply(this, [json]);
  143. }.bind(this), failure, ((typeOf(id)==="string") ? id : id.distinguishedName), async);
  144. },
  145. _newItemSelected: function(data, selector, item){
  146. return new MWF.xApplication.Selector.Identity.ItemSelected(data, selector, item)
  147. },
  148. _listItemByPinyin: function(callback, failure, key){
  149. this._listItem( "pinyin", callback, failure, key );
  150. },
  151. _newItem: function(data, selector, container, level, category){
  152. return new MWF.xApplication.Selector.Identity.Item(data, selector, container, level, category);
  153. },
  154. _newItemSearch: function(data, selector, container, level){
  155. return new MWF.xApplication.Selector.Identity.SearchItem(data, selector, container, level);
  156. },
  157. getLikeKey : function( key, unitObjects ){
  158. var unitObjects = unitObjects || [];
  159. var units = [];
  160. unitObjects.each(function(u){
  161. if (typeOf(u)==="string"){
  162. units.push(u);
  163. }
  164. if (typeOf(u)==="object"){
  165. units.push(u.distinguishedName);
  166. }
  167. });
  168. var keyObj = { "key": key, "unitList": units };
  169. if( !this.dutyDnList ){
  170. var dutyDnList = [];
  171. var dutyNameList = [];
  172. ( this.options.dutys || [] ).each(function(d){
  173. if (typeOf(d)==="string"){
  174. var ds = d.split("@");
  175. if( ds[ ds.length - 1].toUpperCase() === "UD" ){
  176. dutyDnList.push( d )
  177. }else{
  178. dutyNameList.push( d );
  179. }
  180. }
  181. if (typeOf(d)==="object"){
  182. if( d.distinguishedName ){
  183. dutyDnList.push(d.distinguishedName);
  184. }else if( d.name ){
  185. dutyNameList.push(d.name);
  186. }
  187. }
  188. });
  189. if( dutyNameList.length ){
  190. o2.Actions.get("x_organization_assemble_express").listDutyWithName( { nameList : dutyNameList }, function(json){
  191. if( json.data && json.data.unitDutyList ){
  192. dutyDnList = dutyDnList.concat( json.data.unitDutyList )
  193. }
  194. }.bind(this), null, false);
  195. }
  196. this.dutyDnList = dutyDnList;
  197. }
  198. if( this.dutyDnList.length )keyObj.unitDutyList = this.dutyDnList;
  199. return units.length ? keyObj : key;
  200. }
  201. //_listItemNext: function(last, count, callback){
  202. // this.action.listRoleNext(last, count, function(json){
  203. // if (callback) callback.apply(this, [json]);
  204. // }.bind(this));
  205. //}
  206. });
  207. MWF.xApplication.Selector.Identity.Item = new Class({
  208. Extends: MWF.xApplication.Selector.Person.Item,
  209. _getShowName: function(){
  210. return this.data.name;
  211. },
  212. _getTtiteText: function(){
  213. return this.data.name+((this.data.unitLevelName) ? "("+this.data.unitLevelName+")" : "");
  214. },
  215. _setIcon: function(){
  216. var style = this.selector.options.style;
  217. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/personicon.png)");
  218. },
  219. getData: function(callback){
  220. if( this.selector.options.resultType === "person" ){
  221. var isPerson = false;
  222. if( this.data && this.data.distinguishedName ){
  223. var dn = this.data.distinguishedName;
  224. if( dn.substr(dn.length-1, 1).toLowerCase() === "p" )isPerson = true;
  225. }
  226. if( isPerson ) {
  227. if (callback) callback();
  228. }else if( this.data.woPerson ){
  229. this.data == this.data.woPerson;
  230. if (callback) callback();
  231. }else if( this.data.person ){
  232. this.selector.orgAction.getPerson(function(json){
  233. this.data = json.data;
  234. if (callback) callback();
  235. }.bind(this), null, this.data.person)
  236. }else{
  237. if (callback) callback();
  238. }
  239. }else{
  240. if (!this.data.woPerson){
  241. this.selector.orgAction.getPerson(function(json){
  242. this.data.woPerson = json.data;
  243. if (callback) callback();
  244. }.bind(this), null, this.data.person)
  245. }else{
  246. if (callback) callback();
  247. }
  248. }
  249. },
  250. checkSelectedSingle: function(){
  251. var isPerson = this.selector.options.resultType === "person";
  252. var selectedItem = this.selector.options.values.filter(function(item, index){
  253. if( isPerson ){
  254. if (typeOf(item)==="object") return (item.id && item.id === this.data.person) ||
  255. ( item.person && item.person === this.data.id ) ||
  256. ( this.data.distinguishedName && this.data.distinguishedName === item.distinguishedName);
  257. return false;
  258. }else{
  259. if (typeOf(item)==="object") return this.data.distinguishedName === item.distinguishedName;
  260. if (typeOf(item)==="string") return this.data.distinguishedName === item;
  261. return false;
  262. }
  263. }.bind(this));
  264. if (selectedItem.length){
  265. this.selectedSingle();
  266. }
  267. },
  268. checkSelected: function(){
  269. var isPerson = this.selector.options.resultType === "person";
  270. var selectedItem = this.selector.selectedItems.filter(function(item, index){
  271. if( isPerson ){
  272. return ( item.data.id && item.data.id === this.data.person ) ||
  273. ( item.data.person && item.data.person === this.data.id ) ||
  274. ( item.data.distinguishedName && item.data.distinguishedName === this.data.distinguishedName );
  275. }else{
  276. return item.data.distinguishedName === this.data.distinguishedName;
  277. }
  278. }.bind(this));
  279. if (selectedItem.length){
  280. //selectedItem[0].item = this;
  281. selectedItem[0].addItem(this);
  282. this.selectedItem = selectedItem[0];
  283. this.setSelected();
  284. }
  285. }
  286. });
  287. MWF.xApplication.Selector.Identity.SearchItem = new Class({
  288. Extends: MWF.xApplication.Selector.Identity.Item,
  289. _getShowName: function(){
  290. return this.data.name+((this.data.unitLevelName) ? "("+this.data.unitLevelName+")" : "");
  291. }
  292. });
  293. MWF.xApplication.Selector.Identity.ItemSelected = new Class({
  294. Extends: MWF.xApplication.Selector.Person.ItemSelected,
  295. getData: function(callback){
  296. if( this.selector.options.resultType === "person" ){
  297. var isPerson = false;
  298. if( this.data && this.data.distinguishedName ){
  299. var dn = this.data.distinguishedName;
  300. if( dn.substr(dn.length-1, 1).toLowerCase() === "p" )isPerson = true;
  301. }
  302. if( isPerson ){
  303. if (callback) callback();
  304. }else if( this.data.woPerson ){
  305. this.data = this.data.woPerson;
  306. if (callback) callback();
  307. }else if( this.data.person ){
  308. this.selector.orgAction.getPerson(function(json){
  309. this.data = json.data;
  310. if (callback) callback();
  311. }.bind(this), null, this.data.person )
  312. }else{
  313. if (callback) callback();
  314. }
  315. }else if (!this.data.woPerson){
  316. if (this.data.person){
  317. this.selector.orgAction.getPerson(function(json){
  318. this.data.woPerson = json.data;
  319. if (callback) callback();
  320. }.bind(this), function(xhr, text, error){
  321. var errorText = error;
  322. if (xhr){
  323. var json = JSON.decode(xhr.responseText);
  324. if (json){
  325. errorText = json.message.trim() || "request json error";
  326. }else{
  327. errorText = "request json error: "+xhr.responseText;
  328. }
  329. }
  330. MWF.xDesktop.notice("error", {x: "right", y:"top"}, errorText);
  331. if (callback) callback();
  332. }.bind(this), this.data.person)
  333. }else{
  334. MWF.xDesktop.notice("error", {x: "right", y:"top"}, MWF.SelectorLP.noPerson.replace(/{name}/g, this.data.name));
  335. if (callback) callback();
  336. }
  337. }else{
  338. if (callback) callback();
  339. }
  340. },
  341. _getShowName: function(){
  342. return this.data.name+((this.data.unitLevelName) ? "("+this.data.unitLevelName+")" : "");
  343. },
  344. _getTtiteText: function(){
  345. return this.data.name+((this.data.unitLevelName) ? "("+this.data.unitLevelName+")" : "");
  346. },
  347. _setIcon: function(){
  348. var style = this.selector.options.style;
  349. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/personicon.png)");
  350. },
  351. check: function(){
  352. if (this.selector.items.length){
  353. var isPerson = this.selector.options.resultType === "person";
  354. var items = this.selector.items.filter(function(item, index){
  355. if( isPerson ){
  356. return (item.data.person && item.data.person === this.data.id) ||
  357. ( item.data.id && item.data.id === this.data.person) ||
  358. ( item.data.distinguishedName && item.data.distinguishedName === this.data.distinguishedName );
  359. }else{
  360. return item.data.distinguishedName === this.data.distinguishedName;
  361. }
  362. }.bind(this));
  363. this.items = items;
  364. if (items.length){
  365. items.each(function(item){
  366. item.selectedItem = this;
  367. item.setSelected();
  368. }.bind(this));
  369. }
  370. }
  371. }
  372. });
  373. MWF.xApplication.Selector.Identity.ItemCategory = new Class({
  374. Extends: MWF.xApplication.Selector.Person.ItemCategory,
  375. createNode: function(){
  376. this.node = new Element("div", {
  377. "styles": this.selector.css.selectorItemCategory_department,
  378. "title" : this._getTtiteText()
  379. }).inject(this.container);
  380. },
  381. _getShowName: function(){
  382. return this.data.name;
  383. },
  384. _setIcon: function(){
  385. var style = this.selector.options.style;
  386. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/companyicon.png)");
  387. },
  388. clickItem: function( callback ){
  389. if (this._hasChild()){
  390. var firstLoaded = !this.loaded;
  391. this.loadSub(function(){
  392. if( firstLoaded ){
  393. if( !this.selector.isFlatCategory ){
  394. this.children.setStyles({"display": "block", "height": "auto"});
  395. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_expand);
  396. this.isExpand = true;
  397. }
  398. }else{
  399. var display = this.children.getStyle("display");
  400. if (display === "none"){
  401. this.children.setStyles({"display": "block", "height": "auto"});
  402. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_expand);
  403. this.isExpand = true;
  404. }else{
  405. this.children.setStyles({"display": "none", "height": "0px"});
  406. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_collapse);
  407. this.isExpand = false;
  408. }
  409. }
  410. if(callback)callback();
  411. }.bind(this));
  412. }
  413. },
  414. loadSub: function(callback){
  415. if (!this.loaded){
  416. if (this.selector.options.dutys && this.selector.options.dutys.length){
  417. var ids = [];
  418. var object = {};
  419. this.selector.options.dutys.each(function(duty){
  420. this.selector.orgAction.listIdentityWidthUnitWithDutyName(this.data.distinguishedName, duty, function(json){
  421. if (json.data && json.data.length){
  422. ids = ids.concat(json.data);
  423. }
  424. }.bind(this), null, false);
  425. ids.each(function(idSubData){
  426. if( !this.selector.isExcluded( idSubData ) && !object[ idSubData.id || idSubData.distinguishedName ]) {
  427. var item = this.selector._newItem(idSubData, this.selector, this.children, this.level + 1, this);
  428. this.selector.items.push(item);
  429. if(this.subItems)this.subItems.push( item );
  430. object[ idSubData.id || idSubData.distinguishedName ] = true;
  431. }
  432. if( !this.selector.options.expandSubEnable ){
  433. this.loaded = true;
  434. if (callback) callback();
  435. }
  436. }.bind(this));
  437. }.bind(this));
  438. if( this.selector.options.expandSubEnable ){
  439. this.selector.orgAction.listSubUnitDirect(function(json){
  440. json.data.each(function(subData){
  441. if( !this.selector.isExcluded( subData ) ) {
  442. var category = this.selector._newItemCategory("ItemUnitCategory", subData, this.selector, this.children, this.level + 1, this);
  443. this.subCategorys.push( category );
  444. }
  445. }.bind(this));
  446. this.loaded = true;
  447. if (callback) callback();
  448. }.bind(this), null, this.data.distinguishedName);
  449. }
  450. }else{
  451. this.selector.orgAction.listIdentityWithUnit(function(idJson){
  452. idJson.data.each(function(idSubData){
  453. if( !this.selector.isExcluded( idSubData ) ) {
  454. var item = this.selector._newItem(idSubData, this.selector, this.children, this.level + 1, this);
  455. this.selector.items.push(item);
  456. if(this.subItems)this.subItems.push( item );
  457. }
  458. if( !this.selector.options.expandSubEnable ){
  459. this.loaded = true;
  460. if (callback) callback();
  461. }
  462. }.bind(this));
  463. if( this.selector.options.expandSubEnable ){
  464. this.selector.orgAction.listSubUnitDirect(function(json){
  465. json.data.each(function(subData){
  466. if( !this.selector.isExcluded( subData ) ) {
  467. var category = this.selector._newItemCategory("ItemUnitCategory", subData, this.selector, this.children, this.level + 1, this);
  468. this.subCategorys.push( category );
  469. }
  470. }.bind(this));
  471. this.loaded = true;
  472. if (callback) callback();
  473. }.bind(this), null, this.data.distinguishedName);
  474. }
  475. }.bind(this), null, this.data.distinguishedName);
  476. }
  477. }else{
  478. if (callback) callback( );
  479. }
  480. },
  481. _hasChild: function(){
  482. var uCount = (this.data.subDirectUnitCount) ? this.data.subDirectUnitCount : 0;
  483. var iCount = (this.data.subDirectIdentityCount) ? this.data.subDirectIdentityCount : 0;
  484. return uCount + iCount;
  485. },
  486. _hasChildCategory: function(){
  487. return (this.data.subDirectUnitCount) ? this.data.subDirectUnitCount : 0;
  488. },
  489. _hasChildItem: function(){
  490. return (this.data.subDirectIdentityCount) ? this.data.subDirectIdentityCount : 0;
  491. },
  492. //for flat category start
  493. clickFlatCategoryItem: function( callback, hidden ){
  494. if (this._hasChildItem()){
  495. var firstLoaded = !this.itemLoaded;
  496. this.loadItemChildren(function(){
  497. if( hidden ){
  498. //alert("hidden")
  499. this.children.setStyles({"display": "none", "height": "0px"});
  500. this.node.setStyles( this.selector.css.flatCategoryItemNode );
  501. this.isExpand = false;
  502. }else if( firstLoaded ){
  503. this.children.setStyles({"display": "block", "height": "auto"});
  504. this.node.setStyles( this.selector.css.flatCategoryItemNode_selected );
  505. this.isExpand = true;
  506. }else{
  507. var display = this.children.getStyle("display");
  508. if (display === "none"){
  509. this.children.setStyles({"display": "block", "height": "auto"});
  510. this.node.setStyles( this.selector.css.flatCategoryItemNode_selected );
  511. this.isExpand = true;
  512. }else{
  513. this.children.setStyles({"display": "none", "height": "0px"});
  514. this.node.setStyles( this.selector.css.flatCategoryItemNode );
  515. this.isExpand = false;
  516. }
  517. }
  518. if(callback)callback();
  519. }.bind(this));
  520. }
  521. },
  522. loadCategoryChildren: function(callback){
  523. if (!this.categoryLoaded){
  524. if( this.selector.options.expandSubEnable ){
  525. this.selector.orgAction.listSubUnitDirect(function(json){
  526. json.data.each(function(subData){
  527. if( !this.selector.isExcluded( subData ) ) {
  528. var category = this.selector._newItemCategory("ItemUnitCategory", subData, this.selector, this.children, this.level + 1, this);
  529. this.subCategorys.push( category );
  530. }
  531. }.bind(this));
  532. this.categoryLoaded = true;
  533. if (callback) callback();
  534. }.bind(this), null, this.data.distinguishedName);
  535. }else{
  536. if (callback) callback();
  537. }
  538. }else{
  539. if (callback) callback( );
  540. }
  541. },
  542. loadItemChildren: function(callback){
  543. if (!this.itemLoaded){
  544. if (this.selector.options.dutys && this.selector.options.dutys.length){
  545. var ids = [];
  546. var object = {};
  547. this.selector.options.dutys.each(function(duty){
  548. this.selector.orgAction.listIdentityWidthUnitWithDutyName(this.data.distinguishedName, duty, function(json){
  549. if (json.data && json.data.length){
  550. ids = ids.concat(json.data);
  551. }
  552. }.bind(this), null, false);
  553. ids.each(function(idSubData){
  554. if( !this.selector.isExcluded( idSubData ) && !object[ idSubData.id || idSubData.distinguishedName ]) {
  555. var item = this.selector._newItem(idSubData, this.selector, this.children, this.level + 1, this);
  556. this.selector.items.push(item);
  557. if(this.subItems)this.subItems.push( item );
  558. object[ idSubData.id || idSubData.distinguishedName ] = true;
  559. }
  560. this.itemLoaded = true;
  561. }.bind(this));
  562. if (callback) callback();
  563. }.bind(this));
  564. }else{
  565. this.selector.orgAction.listIdentityWithUnit(function(idJson){
  566. idJson.data.each(function(idSubData){
  567. if( !this.selector.isExcluded( idSubData ) ) {
  568. var item = this.selector._newItem(idSubData, this.selector, this.children, this.level + 1, this);
  569. this.selector.items.push(item);
  570. if(this.subItems)this.subItems.push( item );
  571. }
  572. this.itemLoaded = true;
  573. }.bind(this));
  574. if (callback) callback();
  575. }.bind(this), null, this.data.distinguishedName);
  576. }
  577. }else{
  578. if (callback) callback( );
  579. }
  580. }
  581. //for flat category end
  582. });
  583. MWF.xApplication.Selector.Identity.ItemUnitCategory = new Class({
  584. Extends: MWF.xApplication.Selector.Identity.ItemCategory
  585. });
  586. MWF.xApplication.Selector.Identity.ItemGroupCategory = new Class({
  587. Extends: MWF.xApplication.Selector.Identity.ItemCategory,
  588. createNode: function(){
  589. this.node = new Element("div", {
  590. "styles": this.selector.css.selectorItemCategory
  591. }).inject(this.container);
  592. },
  593. _setIcon: function(){
  594. var style = this.selector.options.style;
  595. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/groupicon.png)");
  596. },
  597. loadSub: function(callback){
  598. if (!this.loaded){
  599. debugger;
  600. var personContainer, identityContainer, groupContainer, unitContainer;
  601. if( this.data.personList )personContainer = new Element("div").inject( this.children );
  602. if( this.data.identityList )identityContainer = new Element("div").inject( this.children );
  603. if( this.data.groupList )groupContainer = new Element("div").inject( this.children );
  604. if( this.data.unitList )unitContainer = new Element("div").inject( this.children );
  605. var personLoadedCount = 0;
  606. var identityLoadedCount = 0;
  607. var unitLoadedCount = 0;
  608. var groupLoadedCount = 0;
  609. var checkCallback = function( type, count ){
  610. var addCount = count || 1;
  611. if( !this.selector.options.expandSubEnable ){
  612. if( type === "person" )personLoadedCount += addCount;
  613. if( type === "identity" )identityLoadedCount += addCount;
  614. if(
  615. (!this.data.personList || this.data.personList.length === 0 || this.data.personList.length == personLoadedCount) &&
  616. (!this.data.identityList || this.data.identityList.length === 0 || this.data.identityList.length == identityLoadedCount)
  617. ){
  618. this.loaded = true;
  619. if (callback) callback();
  620. }
  621. }else{
  622. if( type === "person" )personLoadedCount += addCount;
  623. if( type === "identity" )identityLoadedCount += addCount;
  624. if( type === "unit" )unitLoadedCount += addCount;
  625. if( type === "group" )groupLoadedCount += addCount;
  626. if( ( !this.data.personList || this.data.personList.length === 0 || this.data.personList.length == personLoadedCount ) &&
  627. ( !this.data.identityList || this.data.identityList.length === 0 || this.data.identityList.length == identityLoadedCount )&&
  628. ( !this.data.unitList || this.data.unitList.length === 0 || this.data.unitList.length == unitLoadedCount ) &&
  629. ( !this.data.groupList || this.data.groupList.length === 0 || this.data.groupList.length == groupLoadedCount ) ){
  630. this.loaded = true;
  631. if (callback) callback();
  632. }
  633. }
  634. }.bind(this);
  635. checkCallback();
  636. if( this.data.identityList && this.data.identityList.length > 0 ){
  637. if( this.selector.options.resultType === "person" ) {
  638. //根据身份id批量获取人员对象
  639. o2.Actions.load("x_organization_assemble_express").PersonAction.listWithIdentityObject({
  640. identityList : this.data.identityList
  641. }, function (json) {
  642. this.selector.includeObject.loadPersonItem( json, identityContainer, this.level + 1, this);
  643. checkCallback("identity", this.data.identityList.length )
  644. }.bind(this), function () {
  645. checkCallback("identity", this.data.identityList.length )
  646. }.bind(this))
  647. }else{
  648. //根据身份id批量获取身份对象
  649. o2.Actions.load("x_organization_assemble_express").IdentityAction.listObject({
  650. identityList : this.data.identityList
  651. }, function (json) {
  652. this.selector.includeObject.loadIdentityItem( json, identityContainer, this.level + 1, this);
  653. checkCallback("identity", this.data.identityList.length )
  654. }.bind(this), function () {
  655. checkCallback("identity", this.data.identityList.length )
  656. }.bind(this))
  657. }
  658. }
  659. if( this.data.personList && this.data.personList.length > 0 ){
  660. if( this.selector.options.resultType === "person" ) {
  661. //根据人员d批量获取人员对象
  662. o2.Actions.load("x_organization_assemble_express").PersonAction.listObject({
  663. personList : this.data.personList
  664. }, function (json) {
  665. this.selector.includeObject.loadPersonItem( json, personContainer, this.level + 1, this);
  666. checkCallback("person", this.data.personList.length )
  667. }.bind(this), function () {
  668. checkCallback("person", this.data.personList.length )
  669. }.bind(this))
  670. }else{
  671. //根据人员id批量获取身份对象
  672. o2.Actions.load("x_organization_assemble_express").IdentityAction.listWithPersonObject({
  673. personList : this.data.personList
  674. }, function (json) {
  675. this.selector.includeObject.loadIdentityItem( json, personContainer, this.level + 1, this);
  676. checkCallback("person", this.data.personList.length )
  677. }.bind(this), function () {
  678. checkCallback("person", this.data.personList.length )
  679. }.bind(this))
  680. }
  681. }
  682. // ( this.data.personList || [] ).each( function(p){
  683. // if( this.selector.options.resultType === "person" ){
  684. // this.selector.orgAction.getPerson(function (json) {
  685. // this.selector.includeObject.loadPersonItem(json, this.children, this.level + 1, this );
  686. // checkCallback("person");
  687. // }.bind(this), function(){ checkCallback("person") }, p );
  688. // }else{
  689. // this.selector.orgAction.listIdentityByPerson(function(json){
  690. // this.selector.includeObject.loadIdentityItem(json, this.children, this.level + 1, this);
  691. // checkCallback("person")
  692. // }.bind(this), function(){ checkCallback("person") }, p );
  693. // }
  694. // }.bind(this));
  695. //list 服务不能获取下级数量
  696. // if( this.selector.options.expandSubEnable ){
  697. // o2.Actions.load("x_organization_assemble_express").UnitAction.listObject({
  698. // unitList : this.data.unitList
  699. // }, function (json) {
  700. // this.selector.includeObject.loadUnitItem( json, this.children, this.level + 1, this);
  701. // checkCallback("unit", this.data.unitList.length )
  702. // }.bind(this), function () {
  703. // checkCallback("unit", this.data.unitList.length )
  704. // }.bind(this))
  705. //
  706. //
  707. // o2.Actions.load("x_organization_assemble_express").GroupAction.listObject({
  708. // groupList : this.data.groupList
  709. // }, function (json) {
  710. // this.selector.includeObject.loadGroupItem(json, this.children, this.level + 1, this);
  711. // checkCallback("group", this.data.groupList.length )
  712. // }.bind(this), function () {
  713. // checkCallback("group", this.data.groupList.length )
  714. // }.bind(this))
  715. // }
  716. if( this.selector.options.expandSubEnable ){
  717. ( this.data.unitList || [] ).each( function(u){
  718. this.selector.orgAction.getUnit(function (json) {
  719. this.selector.includeObject.loadUnitItem(json, unitContainer, this.level + 1, this);
  720. checkCallback("unit");
  721. }.bind(this), function(){ checkCallback("unit") }, u );
  722. }.bind(this));
  723. ( this.data.groupList || [] ).each( function(g){
  724. this.selector.orgAction.getGroup(function (json) {
  725. this.selector.includeObject.loadGroupItem(json, groupContainer, this.level + 1, this);
  726. checkCallback("group");
  727. }.bind(this), function(){ checkCallback("group") }, g );
  728. }.bind(this));
  729. }
  730. }else{
  731. if (callback) callback( );
  732. }
  733. },
  734. loadCategoryChildren: function(callback){
  735. if (!this.categoryLoaded){
  736. var groupContainer, unitContainer;
  737. if( this.data.groupList )groupContainer = new Element("div").inject( this.children );
  738. if( this.data.unitList )unitContainer = new Element("div").inject( this.children );
  739. var unitLoadedCount = 0;
  740. var groupLoadedCount = 0;
  741. var checkCallback = function( type, count ){
  742. var addCount = count || 1;
  743. if( !this.selector.options.expandSubEnable ){
  744. this.categoryLoaded = true;
  745. }else{
  746. if( type === "unit" )unitLoadedCount += addCount;
  747. if( type === "group" )groupLoadedCount += addCount;
  748. if( ( !this.data.unitList || this.data.unitList.length === 0 || this.data.unitList.length == unitLoadedCount ) &&
  749. ( !this.data.groupList || this.data.groupList.length === 0 || this.data.groupList.length == groupLoadedCount ) ){
  750. this.categoryLoaded = true;
  751. if (callback) callback();
  752. }
  753. }
  754. }.bind(this);
  755. checkCallback();
  756. //list 服务不能获取下级数量
  757. // if( this.selector.options.expandSubEnable ){
  758. // o2.Actions.load("x_organization_assemble_express").UnitAction.listObject({
  759. // unitList : this.data.unitList
  760. // }, function (json) {
  761. // this.selector.includeObject.loadUnitItem( json, this.children, this.level + 1, this);
  762. // checkCallback("unit", this.data.unitList.length )
  763. // }.bind(this), function () {
  764. // checkCallback("unit", this.data.unitList.length )
  765. // }.bind(this))
  766. //
  767. //
  768. // o2.Actions.load("x_organization_assemble_express").GroupAction.listObject({
  769. // groupList : this.data.groupList
  770. // }, function (json) {
  771. // this.selector.includeObject.loadGroupItem(json, this.children, this.level + 1, this);
  772. // checkCallback("group", this.data.groupList.length )
  773. // }.bind(this), function () {
  774. // checkCallback("group", this.data.groupList.length )
  775. // }.bind(this))
  776. // }
  777. if( this.selector.options.expandSubEnable ){
  778. ( this.data.unitList || [] ).each( function(u){
  779. this.selector.orgAction.getUnit(function (json) {
  780. this.selector.includeObject.loadUnitItem(json, unitContainer, this.level + 1, this);
  781. checkCallback("unit");
  782. }.bind(this), function(){ checkCallback("unit") }, u );
  783. }.bind(this));
  784. ( this.data.groupList || [] ).each( function(g){
  785. this.selector.orgAction.getGroup(function (json) {
  786. this.selector.includeObject.loadGroupItem(json, groupContainer, this.level + 1, this);
  787. checkCallback("group");
  788. }.bind(this), function(){ checkCallback("group") }, g );
  789. }.bind(this));
  790. }
  791. }else{
  792. if (callback) callback( );
  793. }
  794. },
  795. loadItemChildren: function(callback){
  796. if (!this.itemLoaded){
  797. var personContainer, identityContainer;
  798. if( this.data.personList )personContainer = new Element("div").inject( this.children );
  799. if( this.data.identityList )identityContainer = new Element("div").inject( this.children );
  800. var personLoadedCount = 0;
  801. var identityLoadedCount = 0;
  802. var checkCallback = function( type, count ){
  803. var addCount = count || 1;
  804. if( type === "person" )personLoadedCount += addCount;
  805. if( type === "identity" )identityLoadedCount += addCount;
  806. if(
  807. (!this.data.personList || this.data.personList.length === 0 || this.data.personList.length == personLoadedCount) &&
  808. (!this.data.identityList || this.data.identityList.length === 0 || this.data.identityList.length == identityLoadedCount)
  809. ){
  810. this.itemLoaded = true;
  811. if (callback) callback();
  812. }
  813. }.bind(this);
  814. checkCallback();
  815. if( this.data.identityList && this.data.identityList.length > 0 ){
  816. if( this.selector.options.resultType === "person" ) {
  817. //根据身份id批量获取人员对象
  818. o2.Actions.load("x_organization_assemble_express").PersonAction.listWithIdentityObject({
  819. identityList : this.data.identityList
  820. }, function (json) {
  821. this.selector.includeObject.loadPersonItem( json, identityContainer, this.level + 1, this);
  822. checkCallback("identity", this.data.identityList.length )
  823. }.bind(this), function () {
  824. checkCallback("identity", this.data.identityList.length )
  825. }.bind(this))
  826. }else{
  827. //根据身份id批量获取身份对象
  828. o2.Actions.load("x_organization_assemble_express").IdentityAction.listObject({
  829. identityList : this.data.identityList
  830. }, function (json) {
  831. this.selector.includeObject.loadIdentityItem( json, identityContainer, this.level + 1, this);
  832. checkCallback("identity", this.data.identityList.length )
  833. }.bind(this), function () {
  834. checkCallback("identity", this.data.identityList.length )
  835. }.bind(this))
  836. }
  837. }
  838. if( this.data.personList && this.data.personList.length > 0 ){
  839. if( this.selector.options.resultType === "person" ) {
  840. //根据人员d批量获取人员对象
  841. o2.Actions.load("x_organization_assemble_express").PersonAction.listObject({
  842. personList : this.data.personList
  843. }, function (json) {
  844. this.selector.includeObject.loadPersonItem( json, personContainer, this.level + 1, this);
  845. checkCallback("person", this.data.personList.length )
  846. }.bind(this), function () {
  847. checkCallback("person", this.data.personList.length )
  848. }.bind(this))
  849. }else{
  850. //根据人员id批量获取身份对象
  851. o2.Actions.load("x_organization_assemble_express").IdentityAction.listWithPersonObject({
  852. personList : this.data.personList
  853. }, function (json) {
  854. this.selector.includeObject.loadIdentityItem( json, personContainer, this.level + 1, this);
  855. checkCallback("person", this.data.personList.length )
  856. }.bind(this), function () {
  857. checkCallback("person", this.data.personList.length )
  858. }.bind(this))
  859. }
  860. }
  861. // ( this.data.personList || [] ).each( function(p){
  862. // if( this.selector.options.resultType === "person" ){
  863. // this.selector.orgAction.getPerson(function (json) {
  864. // this.selector.includeObject.loadPersonItem(json, this.children, this.level + 1, this );
  865. // checkCallback("person");
  866. // }.bind(this), function(){ checkCallback("person") }, p );
  867. // }else{
  868. // this.selector.orgAction.listIdentityByPerson(function(json){
  869. // this.selector.includeObject.loadIdentityItem(json, this.children, this.level + 1, this);
  870. // checkCallback("person")
  871. // }.bind(this), function(){ checkCallback("person") }, p );
  872. // }
  873. // }.bind(this));
  874. }else{
  875. if (callback) callback( );
  876. }
  877. },
  878. _hasChild: function(){
  879. var uCount = (this.data.unitList) ? this.data.unitList.length : 0;
  880. var gCount = (this.data.groupList) ? this.data.groupList.length : 0;
  881. var pCount = (this.data.personList) ? this.data.personList.length : 0;
  882. var iCount = (this.data.identityList) ? this.data.identityList.length : 0;
  883. return uCount + gCount + pCount + iCount;
  884. },
  885. _hasChildCategory: function(){
  886. var uCount = (this.data.unitList) ? this.data.unitList.length : 0;
  887. var gCount = (this.data.groupList) ? this.data.groupList.length : 0;
  888. return uCount + gCount;
  889. },
  890. _hasChildItem: function(){
  891. var pCount = (this.data.personList) ? this.data.personList.length : 0;
  892. var iCount = (this.data.identityList) ? this.data.identityList.length : 0;
  893. return pCount + iCount;
  894. }
  895. });
  896. MWF.xApplication.Selector.Identity.ItemRoleCategory = new Class({
  897. Extends: MWF.xApplication.Selector.Person.ItemCategory,
  898. _getShowName: function(){
  899. return this.data.name;
  900. },
  901. _setIcon: function(){
  902. var style = this.selector.options.style;
  903. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/roleicon.png)");
  904. }
  905. });
  906. MWF.xApplication.Selector.Identity.Include = new Class({
  907. Implements: [Options, Events],
  908. options: {
  909. "include" : [], //增加的可选项
  910. "resultType" : "", //可以设置成个人,那么结果返回个人
  911. "expandSubEnable" : true //是否允许展开下一层
  912. },
  913. initialize: function(selector, itemAreaNode, options){
  914. this.setOptions(options);
  915. this.selector = selector;
  916. this.itemAreaNode = $(itemAreaNode);
  917. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  918. },
  919. load : function(){
  920. if( !this.options.include || this.options.include.length === 0 )return;
  921. this.includeAreaNode = new Element( "div.includeAreaNode").inject( this.itemAreaNode, "top" );
  922. if( this.selector.isFlatCategory ){
  923. this.flatCategoryAreaNode = new Element( "div.includeFlatCategoryAreaNode").inject( this.selector.flatCategoryNode, "top" );
  924. }
  925. //this.includeIdentityAreaNode = new Element( "div").inject( this.includeAreaNode );
  926. //this.includePersonAreaNode = new Element( "div").inject( this.includeAreaNode );
  927. //this.includeUnitAreaNode = new Element( "div").inject( this.includeAreaNode );
  928. //this.includeGroupAreaNode = new Element( "div").inject( this.includeAreaNode );
  929. this.options.include.each( function( d ){
  930. var container = new Element("div").inject( this.includeAreaNode );
  931. var flatCategoryContainer;
  932. if( this.flatCategoryAreaNode ){
  933. flatCategoryContainer = new Element("div").inject( this.flatCategoryAreaNode );
  934. }
  935. if (typeOf(d)==="string"){
  936. var arr = d.split("@");
  937. var flag = arr[ arr.length - 1].toLowerCase();
  938. if( flag === "u" ){
  939. this.orgAction.listUnitByKey(function(json){
  940. this.loadUnitItem(json, container, null, null, flatCategoryContainer);
  941. }.bind(this), null, d);
  942. }else if( flag === "i" ) {
  943. this.orgAction.listIdentityByKey(function (json) {
  944. this.loadIdentityItem(json, container, null, null, true )
  945. }.bind(this), null, d);
  946. }else if( flag === "g" ){
  947. this.orgAction.listGroupByKey(function(json){
  948. this.loadGroupItem( json , container, null, null, flatCategoryContainer)
  949. }.bind(this), null, d);
  950. }else if( flag === "p" ){
  951. if( this.options.resultType === "person" ){
  952. this.orgAction.getPerson(function (json){
  953. this.loadPersonItem( json , container, null, null, true)
  954. }.bind(this), null, d);
  955. }else{
  956. this.orgAction.listIdentityByPerson(function(json){
  957. this.loadIdentityItem(json, container , null, null, true)
  958. }.bind(this), null, d);
  959. }
  960. }else{
  961. if( this.options.resultType === "person" ){
  962. this.orgAction.listPersonByKey(function (json) {
  963. this.loadPersonItem( json , container, null, null, true)
  964. }.bind(this), null, d);
  965. }else{
  966. this.orgAction.listIdentityByKey(function(json){
  967. this.loadIdentityItem(json, container, null, null, true)
  968. }.bind(this), null, d);
  969. }
  970. }
  971. }else{
  972. var arr = d.distinguishedName.split("@");
  973. var flag = arr[ arr.length - 1].toLowerCase();
  974. if( flag === "u" ) {
  975. this.orgAction.getUnit(function (json) {
  976. this.loadUnitItem(json, container, null, null, flatCategoryContainer);
  977. }.bind(this), null, d.distinguishedName);
  978. }else if( flag === "i" ){
  979. this.orgAction.getIdentity(function (json) {
  980. this.loadIdentityItem(json, container, null, null, true)
  981. }.bind(this), null, d.distinguishedName);
  982. }else if( flag === "g" ){
  983. this.orgAction.getGroup(function(json){
  984. this.loadGroupItem( json , container, null, null, flatCategoryContainer)
  985. }.bind(this), null, d.distinguishedName, null, null, true);
  986. }else if( flag === "p" ){
  987. if( this.options.resultType === "person" ){
  988. this.orgAction.getPerson(function (json) {
  989. this.loadPersonItem(json, container, null, null, true)
  990. }.bind(this), null, d.distinguishedName);
  991. }else{
  992. this.orgAction.listIdentityByPerson(function(json){
  993. this.loadIdentityItem(json, container, null, null, true)
  994. }.bind(this), null, d.distinguishedName);
  995. }
  996. }else{
  997. if( this.options.resultType === "person" ){
  998. this.orgAction.getPerson(function (json) {
  999. this.loadPersonItem(json, container, null, null, true)
  1000. }.bind(this), null, d.distinguishedName);
  1001. }else{
  1002. this.orgAction.getIdentity(function (json) {
  1003. this.loadIdentityItem(json, container, null, null, true)
  1004. }.bind(this), null, d.distinguishedName);
  1005. }
  1006. }
  1007. //var category = this._newItemCategory("ItemCategory", unit, this, this.itemAreaNode);
  1008. }
  1009. }.bind(this))
  1010. },
  1011. loadPersonItem : function( json, container, level, category, isIncludedPerson ){
  1012. if( !json.data )return;
  1013. var array = typeOf( json.data ) === "array" ? json.data : [json.data];
  1014. array.each(function(data){
  1015. if( !this.selector.isExcluded( data ) ) {
  1016. if(!this.includePerson)this.includePerson = [];
  1017. if(isIncludedPerson)this.includePerson.push( data.distinguishedName );
  1018. if(!this.includePersonObject)this.includePersonObject = [];
  1019. if(isIncludedPerson)this.includePersonObject.push( data );
  1020. var item = this.selector._newItem(data, this.selector, container || this.includeAreaNode, level || 1, category);
  1021. this.selector.items.push(item);
  1022. if( category && category.subItems ){
  1023. category.subItems.push( item );
  1024. }
  1025. }
  1026. }.bind(this));
  1027. },
  1028. loadIdentityItem : function( json, container, level, category, isIncludedIdentity ){
  1029. if( !json.data )return;
  1030. var array = typeOf( json.data ) === "array" ? json.data : [json.data];
  1031. array.each(function(data){
  1032. if( !this.selector.isExcluded( data ) ) {
  1033. if(!this.includeIdentity)this.includeIdentity = [];
  1034. if(isIncludedIdentity)this.includeIdentity.push( data.distinguishedName );
  1035. if(!this.includeIdentityObject)this.includeIdentityObject = [];
  1036. if(isIncludedIdentity)this.includeIdentityObject.push( data );
  1037. var item = this.selector._newItem(data, this.selector, container || this.includeAreaNode, level || 1, category);
  1038. this.selector.items.push(item);
  1039. if( category && category.subItems ){
  1040. category.subItems.push( item );
  1041. }
  1042. }
  1043. }.bind(this));
  1044. },
  1045. loadUnitItem : function( json, container, level, parentCategory, flatCategoryContainer ){
  1046. if( !json.data )return;
  1047. var array = typeOf( json.data ) === "array" ? json.data : [json.data];
  1048. array.each(function(data){
  1049. if( !this.selector.isExcluded( data ) ) {
  1050. if(!this.includeUnit)this.includeUnit = [];
  1051. this.includeUnit.push( data.distinguishedName );
  1052. var category;
  1053. if( flatCategoryContainer ){
  1054. category = this.selector._newItemCategory("ItemUnitCategory", data, this.selector,
  1055. container || this.includeAreaNode, level, parentCategory, true);
  1056. category.nodeContainer = flatCategoryContainer;
  1057. category.load();
  1058. }else{
  1059. category = this.selector._newItemCategory("ItemUnitCategory", data, this.selector,
  1060. container || this.includeAreaNode, level, parentCategory);
  1061. }
  1062. if( parentCategory && parentCategory.subCategorys ){
  1063. parentCategory.subCategorys.push( category )
  1064. }else if(this.selector.subCategorys){
  1065. this.selector.subCategorys.push( category )
  1066. }
  1067. }
  1068. }.bind(this));
  1069. },
  1070. loadGroupItem : function( json, container, level, parentCategory, flatCategoryContainer ){
  1071. if( !json.data )return;
  1072. var array = typeOf( json.data ) === "array" ? json.data : [json.data];
  1073. array.each(function(data){
  1074. if( !this.selector.isExcluded( data ) ) {
  1075. if(!this.includeGroup)this.includeGroup = [];
  1076. this.includeGroup.push( data.distinguishedName );
  1077. var category;
  1078. if( flatCategoryContainer ){
  1079. category = this.selector._newItemCategory("ItemGroupCategory", data, this.selector, container || this.includeAreaNode, level, parentCategory, true);
  1080. category.nodeContainer = flatCategoryContainer;
  1081. category.load();
  1082. }else{
  1083. category = this.selector._newItemCategory("ItemGroupCategory", data, this.selector, container || this.includeAreaNode, level, parentCategory)
  1084. }
  1085. if( parentCategory && parentCategory.subCategorys ){
  1086. parentCategory.subCategorys.push( category )
  1087. }else if(this.selector.subCategorys){
  1088. this.selector.subCategorys.push( category )
  1089. }
  1090. }
  1091. }.bind(this));
  1092. },
  1093. listByFilter : function( type, key, callback ){
  1094. var arr1 = this.listByFilterPerson(key) || [];
  1095. this.listByFilterUnitAndGroup( type, key, function(arr2){
  1096. this.listByFilterGroup( type, key, function(arr3){
  1097. if (callback) callback( arr1.concat( arr2 || [] ).concat( arr3 || [] ) );
  1098. }.bind(this))
  1099. }.bind(this))
  1100. },
  1101. listByFilterPerson : function( key ){
  1102. var identitys = [];
  1103. var persons = [];
  1104. var keyString = typeOf( key )==="string" ? key.toLowerCase() : key.key.toLowerCase();
  1105. if( this.includeIdentityObject && this.includeIdentityObject.length ){
  1106. identitys = this.includeIdentityObject.filter( function(id) {
  1107. return ( id.pinyin || "" ).indexOf(keyString) > -1 || (id.pinyinInitial || "").indexOf(keyString) > -1 || (id.distinguishedName || "").indexOf(keyString) > -1;
  1108. })
  1109. }
  1110. if( this.includePersonObject && this.includePersonObject.length ){
  1111. persons = this.includePersonObject.filter( function(id) {
  1112. return ( id.pinyin || "" ).indexOf(keyString) > -1 || (id.pinyinInitial || "").indexOf(keyString) > -1 || (id.distinguishedName || "").indexOf(keyString) > -1;
  1113. })
  1114. }
  1115. return identitys.concat( persons);
  1116. },
  1117. listByFilterGroup : function( type, key, callback ){
  1118. //根据关键字获取群组内的人员,再转成身份
  1119. var keyString = typeOf( key )==="string" ? key.toLowerCase() : key.key.toLowerCase();
  1120. if( this.includeGroup && this.includeGroup.length ){
  1121. var keyObject = { "key" : keyString, "groupList" : this.includeGroup };
  1122. this.orgAction[ type === "pinyin" ? "listPersonByPinyin" : "listPersonByKey" ](function(json){
  1123. if( this.options.resultType === "person" ){
  1124. if (callback) callback( json.data );
  1125. }else{
  1126. var personList = (json.data || []).map( function(d){
  1127. return d.id
  1128. });
  1129. o2.Actions.get("x_organization_assemble_express").listIdentityWithPerson( { "personList" : personList }, function(js){
  1130. if (callback) callback(js.data);
  1131. }.bind(this), function(){
  1132. if (callback) callback();
  1133. }.bind(this))
  1134. }
  1135. }.bind(this), function(){
  1136. if (callback) callback();
  1137. }.bind(this), keyObject);
  1138. }else{
  1139. if (callback) callback();
  1140. }
  1141. },
  1142. listByFilterUnitAndGroup : function( type, key, callback ){
  1143. //根据关键字获取组织和群组内的身份
  1144. var keyString = typeOf( key )==="string" ? key.toLowerCase() : key.key.toLowerCase();
  1145. if ( this.includeUnit && this.includeUnit.length ){
  1146. key = this.getUnitFilterKey( key, this.includeUnit, this.includeGroup );
  1147. this.orgAction.listIdentityByKey(function(json){
  1148. if (callback) callback(json.data);
  1149. }.bind(this), function(){
  1150. if (callback) callback();
  1151. }, key);
  1152. }else{
  1153. if (callback) callback();
  1154. }
  1155. },
  1156. getUnitFilterKey : function( key, unitObject, groupObject ){
  1157. var unitObjects = unitObject || [];
  1158. var units = [];
  1159. unitObjects.each(function(u){
  1160. if (typeOf(u)==="string"){
  1161. units.push(u);
  1162. }
  1163. if (typeOf(u)==="object"){
  1164. units.push(u.distinguishedName);
  1165. }
  1166. });
  1167. var groupObjects = groupObject || [];
  1168. var groups = [];
  1169. groupObjects.each(function(g){
  1170. if (typeOf(g)==="string"){
  1171. groups.push(g);
  1172. }
  1173. if (typeOf(g)==="object"){
  1174. groups.push(g.distinguishedName);
  1175. }
  1176. });
  1177. if( !units.length && !groups.length ){
  1178. return key;
  1179. }else{
  1180. var result = { "key": key };
  1181. if( units.length )result.unitList = units;
  1182. if( groups.length )result.groupList = groups;
  1183. return result;
  1184. }
  1185. // return units.length ? {"key": key, "unitList": units, "groupList" : groups} : key;
  1186. }
  1187. });
  1188. MWF.xApplication.Selector.Identity.Filter = new Class({
  1189. Implements: [Options, Events],
  1190. options: {
  1191. "style": "default",
  1192. "units": [],
  1193. "resultType" : "" //可以设置成个人,那么结果返回个人
  1194. },
  1195. initialize: function(value, options){
  1196. this.setOptions(options);
  1197. this.value = value;
  1198. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  1199. },
  1200. filter: function(value, callback){
  1201. this.value = value;
  1202. var key = this.value;
  1203. if (this.options.units.length){
  1204. var units = [];
  1205. this.options.units.each(function(u){
  1206. if (typeOf(u)==="string"){
  1207. units.push(u);
  1208. }
  1209. if (typeOf(u)==="object"){
  1210. units.push(u.distinguishedName);
  1211. }
  1212. });
  1213. key = {"key": this.value, "unitList": units};
  1214. }
  1215. var data = null;
  1216. this.orgAction.listIdentityByKey(function(json){
  1217. data = json.data;
  1218. if (callback) callback(data)
  1219. }.bind(this), null, key);
  1220. }
  1221. });