Identity.js 64 KB

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