Identity.js 61 KB

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