Identity.js 62 KB

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