Identity.js 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411
  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, selectedNode){
  197. return new MWF.xApplication.Selector.Identity.ItemSelected(data, selector, item, selectedNode)
  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. _beforeSelectAll : function( _selectAllFun ){
  440. if( this.selector.options.ignorePerson ){
  441. _selectAllFun();
  442. return;
  443. }
  444. //批量获取个人
  445. var object = {};
  446. if( this.selector.options.resultType === "person" ){
  447. this.subItems.each( function(item){
  448. var isPerson = false;
  449. if( item.data && item.data.distinguishedName ){
  450. var dn = item.data.distinguishedName;
  451. if( dn.substr(dn.length-1, 1).toLowerCase() === "p" )isPerson = true;
  452. }
  453. if( !isPerson && !item.data.woPerson && item.data.person ){
  454. object[ item.data.person ] = item;
  455. }
  456. }.bind(this))
  457. }else{
  458. this.subItems.each( function (item) {
  459. if (!item.data.woPerson && item.data.person ){
  460. object[ item.data.person ] = item;
  461. }
  462. }.bind(this))
  463. }
  464. var keys = Object.keys( object );
  465. if( keys.length > 0 ){
  466. o2.Actions.load("x_organization_assemble_express").PersonAction.listObject({"personList":keys}, function (json) {
  467. json.data.each( function ( p ){
  468. if(object[ p.id ])object[ p.id ].data.woPerson = p;
  469. }.bind(this));
  470. _selectAllFun();
  471. })
  472. }else{
  473. _selectAllFun();
  474. }
  475. },
  476. clickItem: function( callback ){
  477. if (this._hasChild() && !this.loading){
  478. var firstLoaded = !this.loaded;
  479. this.loading = true;
  480. this.loadSub(function(){
  481. this.loading = false;
  482. if( firstLoaded ){
  483. if( !this.selector.isFlatCategory ){
  484. this.children.setStyles({"display": "block", "height": "auto"});
  485. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_expand);
  486. this.isExpand = true;
  487. }
  488. // this.checkSelectAll();
  489. }else{
  490. var display = this.children.getStyle("display");
  491. if (display === "none"){
  492. this.children.setStyles({"display": "block", "height": "auto"});
  493. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_expand);
  494. this.isExpand = true;
  495. }else{
  496. this.children.setStyles({"display": "none", "height": "0px"});
  497. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_collapse);
  498. this.isExpand = false;
  499. }
  500. }
  501. if(callback)callback();
  502. }.bind(this));
  503. }
  504. },
  505. loadSub: function(callback){
  506. if (!this.loaded){
  507. if (this.selector.options.dutys && this.selector.options.dutys.length){
  508. var ids = [];
  509. var object = {};
  510. this.selector.options.dutys.each(function(duty){
  511. this.selector.orgAction.listIdentityWidthUnitWithDutyName(this.data.distinguishedName, duty, function(json){
  512. if (json.data && json.data.length){
  513. ids = ids.concat(json.data);
  514. }
  515. }.bind(this), null, false);
  516. ids.each(function(idSubData){
  517. if( !this.selector.isExcluded( idSubData ) && !object[ idSubData.id || idSubData.distinguishedName ]) {
  518. var item = this.selector._newItem(idSubData, this.selector, this.children, this.level + 1, this);
  519. this.selector.items.push(item);
  520. if(this.subItems)this.subItems.push( item );
  521. object[ idSubData.id || idSubData.distinguishedName ] = true;
  522. }
  523. }.bind(this));
  524. }.bind(this));
  525. if( this.selector.options.expandSubEnable ){
  526. this.selector.orgAction.listSubUnitDirect(function(json){
  527. json.data.each(function(subData){
  528. if( !this.selector.isExcluded( subData ) ) {
  529. var category = this.selector._newItemCategory("ItemUnitCategory", subData, this.selector, this.children, this.level + 1, this);
  530. this.subCategorys.push( category );
  531. }
  532. }.bind(this));
  533. this.loaded = true;
  534. if(callback)callback();
  535. }.bind(this), null, this.data.distinguishedName);
  536. }else{
  537. this.loaded = true;
  538. if(callback)callback();
  539. }
  540. }else{
  541. this.selector.orgAction.listIdentityWithUnit(function(idJson){
  542. idJson.data.each(function(idSubData){
  543. if( !this.selector.isExcluded( idSubData ) ) {
  544. var item = this.selector._newItem(idSubData, this.selector, this.children, this.level + 1, this);
  545. this.selector.items.push(item);
  546. if(this.subItems)this.subItems.push( item );
  547. }
  548. }.bind(this));
  549. if( this.selector.options.expandSubEnable ){
  550. this.selector.orgAction.listSubUnitDirect(function(json){
  551. json.data.each(function(subData){
  552. if( !this.selector.isExcluded( subData ) ) {
  553. var category = this.selector._newItemCategory("ItemUnitCategory", subData, this.selector, this.children, this.level + 1, this);
  554. this.subCategorys.push( category );
  555. }
  556. }.bind(this));
  557. this.loaded = true;
  558. if (callback) callback();
  559. }.bind(this), null, this.data.distinguishedName);
  560. }else{
  561. this.loaded = true;
  562. if (callback) callback();
  563. }
  564. }.bind(this), null, this.data.distinguishedName);
  565. }
  566. }else{
  567. if (callback) callback( );
  568. }
  569. },
  570. _hasChild: function(){
  571. var uCount = (this.data.subDirectUnitCount) ? this.data.subDirectUnitCount : 0;
  572. var iCount = (this.data.subDirectIdentityCount) ? this.data.subDirectIdentityCount : 0;
  573. return uCount + iCount;
  574. },
  575. _hasChildCategory: function(){
  576. return (this.data.subDirectUnitCount) ? this.data.subDirectUnitCount : 0;
  577. },
  578. _hasChildItem: function(){
  579. return (this.data.subDirectIdentityCount) ? this.data.subDirectIdentityCount : 0;
  580. },
  581. //for flat category start
  582. clickFlatCategoryItem: function( callback, hidden ){
  583. if (this._hasChildItem()){
  584. var firstLoaded = !this.itemLoaded;
  585. this.loadItemChildren(function(){
  586. if( hidden ){
  587. //alert("hidden")
  588. this.children.setStyles({"display": "none", "height": "0px"});
  589. this.node.setStyles( this.selector.css.flatCategoryItemNode );
  590. this.isExpand = false;
  591. }else if( firstLoaded ){
  592. this.children.setStyles({"display": "block", "height": "auto"});
  593. this.node.setStyles( this.selector.css.flatCategoryItemNode_selected );
  594. this.isExpand = true;
  595. }else{
  596. var display = this.children.getStyle("display");
  597. if (display === "none"){
  598. this.children.setStyles({"display": "block", "height": "auto"});
  599. this.node.setStyles( this.selector.css.flatCategoryItemNode_selected );
  600. this.isExpand = true;
  601. }else{
  602. this.children.setStyles({"display": "none", "height": "0px"});
  603. this.node.setStyles( this.selector.css.flatCategoryItemNode );
  604. this.isExpand = false;
  605. }
  606. }
  607. if(callback)callback();
  608. }.bind(this));
  609. }
  610. },
  611. loadCategoryChildren: function(callback){
  612. if (!this.categoryLoaded){
  613. if( this.selector.options.expandSubEnable ){
  614. this.selector.orgAction.listSubUnitDirect(function(json){
  615. json.data.each(function(subData){
  616. if( !this.selector.isExcluded( subData ) ) {
  617. var category = this.selector._newItemCategory("ItemUnitCategory", subData, this.selector, this.children, this.level + 1, this);
  618. this.subCategorys.push( category );
  619. }
  620. }.bind(this));
  621. this.categoryLoaded = true;
  622. if (callback) callback();
  623. }.bind(this), null, this.data.distinguishedName);
  624. }else{
  625. if (callback) callback();
  626. }
  627. }else{
  628. if (callback) callback( );
  629. }
  630. },
  631. loadItemChildren: function(callback){
  632. if (!this.itemLoaded){
  633. if (this.selector.options.dutys && this.selector.options.dutys.length){
  634. var ids = [];
  635. var object = {};
  636. this.selector.options.dutys.each(function(duty){
  637. this.selector.orgAction.listIdentityWidthUnitWithDutyName(this.data.distinguishedName, duty, function(json){
  638. if (json.data && json.data.length){
  639. ids = ids.concat(json.data);
  640. }
  641. }.bind(this), null, false);
  642. ids.each(function(idSubData){
  643. if( !this.selector.isExcluded( idSubData ) && !object[ idSubData.id || idSubData.distinguishedName ]) {
  644. var item = this.selector._newItem(idSubData, this.selector, this.children, this.level + 1, this);
  645. this.selector.items.push(item);
  646. if(this.subItems)this.subItems.push( item );
  647. object[ idSubData.id || idSubData.distinguishedName ] = true;
  648. }
  649. this.itemLoaded = true;
  650. }.bind(this));
  651. }.bind(this));
  652. if (callback) callback();
  653. }else{
  654. this.selector.orgAction.listIdentityWithUnit(function(idJson){
  655. idJson.data.each(function(idSubData){
  656. if( !this.selector.isExcluded( idSubData ) ) {
  657. var item = this.selector._newItem(idSubData, this.selector, this.children, this.level + 1, this);
  658. this.selector.items.push(item);
  659. if(this.subItems)this.subItems.push( item );
  660. }
  661. this.itemLoaded = true;
  662. }.bind(this));
  663. if (callback) callback();
  664. }.bind(this), null, this.data.distinguishedName);
  665. }
  666. }else{
  667. if (callback) callback( );
  668. }
  669. }
  670. //for flat category end
  671. });
  672. MWF.xApplication.Selector.Identity.ItemUnitCategory = new Class({
  673. Extends: MWF.xApplication.Selector.Identity.ItemCategory
  674. });
  675. MWF.xApplication.Selector.Identity.ItemGroupCategory = new Class({
  676. Extends: MWF.xApplication.Selector.Identity.ItemCategory,
  677. createNode: function(){
  678. this.node = new Element("div", {
  679. "styles": this.selector.css.selectorItemCategory
  680. }).inject(this.container);
  681. },
  682. _setIcon: function(){
  683. var style = this.selector.options.style;
  684. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/groupicon.png)");
  685. },
  686. loadSub: function(callback){
  687. if (!this.loaded){
  688. debugger;
  689. var personContainer, identityContainer, groupContainer, unitContainer;
  690. if( this.data.personList )personContainer = new Element("div").inject( this.children );
  691. if( this.data.identityList )identityContainer = new Element("div").inject( this.children );
  692. if( this.data.groupList )groupContainer = new Element("div").inject( this.children );
  693. if( this.data.unitList )unitContainer = new Element("div").inject( this.children );
  694. var personLoadedCount = 0;
  695. var identityLoadedCount = 0;
  696. var unitLoadedCount = 0;
  697. var groupLoadedCount = 0;
  698. var checkCallback = function( type, count ){
  699. var addCount = count || 1;
  700. if( !this.selector.options.expandSubEnable ){
  701. if( type === "person" )personLoadedCount += addCount;
  702. if( type === "identity" )identityLoadedCount += addCount;
  703. if(
  704. (!this.data.personList || this.data.personList.length === 0 || this.data.personList.length == personLoadedCount) &&
  705. (!this.data.identityList || this.data.identityList.length === 0 || this.data.identityList.length == identityLoadedCount)
  706. ){
  707. this.loaded = true;
  708. if (callback) callback();
  709. }
  710. }else{
  711. if( type === "person" )personLoadedCount += addCount;
  712. if( type === "identity" )identityLoadedCount += addCount;
  713. if( type === "unit" )unitLoadedCount += addCount;
  714. if( type === "group" )groupLoadedCount += addCount;
  715. if( ( !this.data.personList || this.data.personList.length === 0 || this.data.personList.length == personLoadedCount ) &&
  716. ( !this.data.identityList || this.data.identityList.length === 0 || this.data.identityList.length == identityLoadedCount )&&
  717. ( !this.data.unitList || this.data.unitList.length === 0 || this.data.unitList.length == unitLoadedCount ) &&
  718. ( !this.data.groupList || this.data.groupList.length === 0 || this.data.groupList.length == groupLoadedCount ) ){
  719. this.loaded = true;
  720. if (callback) callback();
  721. }
  722. }
  723. }.bind(this);
  724. checkCallback();
  725. if( this.data.identityList && this.data.identityList.length > 0 ){
  726. if( this.selector.options.resultType === "person" ) {
  727. //根据身份id批量获取人员对象
  728. o2.Actions.load("x_organization_assemble_express").PersonAction.listWithIdentityObject({
  729. identityList : this.data.identityList
  730. }, function (json) {
  731. this.selector.includeObject.loadPersonItem( json, identityContainer, this.level + 1, this);
  732. checkCallback("identity", this.data.identityList.length )
  733. }.bind(this), function () {
  734. checkCallback("identity", this.data.identityList.length )
  735. }.bind(this))
  736. }else{
  737. //根据身份id批量获取身份对象
  738. o2.Actions.load("x_organization_assemble_express").IdentityAction.listObject({
  739. identityList : this.data.identityList
  740. }, function (json) {
  741. this.selector.includeObject.loadIdentityItem( json, identityContainer, this.level + 1, this);
  742. checkCallback("identity", this.data.identityList.length )
  743. }.bind(this), function () {
  744. checkCallback("identity", this.data.identityList.length )
  745. }.bind(this))
  746. }
  747. }
  748. if( this.data.personList && this.data.personList.length > 0 ){
  749. if( this.selector.options.resultType === "person" ) {
  750. //根据人员d批量获取人员对象
  751. o2.Actions.load("x_organization_assemble_express").PersonAction.listObject({
  752. personList : this.data.personList
  753. }, function (json) {
  754. this.selector.includeObject.loadPersonItem( json, personContainer, this.level + 1, this);
  755. checkCallback("person", this.data.personList.length )
  756. }.bind(this), function () {
  757. checkCallback("person", this.data.personList.length )
  758. }.bind(this))
  759. }else{
  760. //根据人员id批量获取身份对象
  761. o2.Actions.load("x_organization_assemble_express").IdentityAction.listWithPersonObject({
  762. personList : this.data.personList
  763. }, function (json) {
  764. this.selector.includeObject.loadIdentityItem( json, personContainer, this.level + 1, this);
  765. checkCallback("person", this.data.personList.length )
  766. }.bind(this), function () {
  767. checkCallback("person", this.data.personList.length )
  768. }.bind(this))
  769. }
  770. }
  771. // ( this.data.personList || [] ).each( function(p){
  772. // if( this.selector.options.resultType === "person" ){
  773. // this.selector.orgAction.getPerson(function (json) {
  774. // this.selector.includeObject.loadPersonItem(json, this.children, this.level + 1, this );
  775. // checkCallback("person");
  776. // }.bind(this), function(){ checkCallback("person") }, p );
  777. // }else{
  778. // this.selector.orgAction.listIdentityByPerson(function(json){
  779. // this.selector.includeObject.loadIdentityItem(json, this.children, this.level + 1, this);
  780. // checkCallback("person")
  781. // }.bind(this), function(){ checkCallback("person") }, p );
  782. // }
  783. // }.bind(this));
  784. //list 服务不能获取下级数量
  785. // if( this.selector.options.expandSubEnable ){
  786. // o2.Actions.load("x_organization_assemble_express").UnitAction.listObject({
  787. // unitList : this.data.unitList
  788. // }, function (json) {
  789. // this.selector.includeObject.loadUnitItem( json, this.children, this.level + 1, this);
  790. // checkCallback("unit", this.data.unitList.length )
  791. // }.bind(this), function () {
  792. // checkCallback("unit", this.data.unitList.length )
  793. // }.bind(this))
  794. //
  795. //
  796. // o2.Actions.load("x_organization_assemble_express").GroupAction.listObject({
  797. // groupList : this.data.groupList
  798. // }, function (json) {
  799. // this.selector.includeObject.loadGroupItem(json, this.children, this.level + 1, this);
  800. // checkCallback("group", this.data.groupList.length )
  801. // }.bind(this), function () {
  802. // checkCallback("group", this.data.groupList.length )
  803. // }.bind(this))
  804. // }
  805. if( this.selector.options.expandSubEnable ){
  806. ( this.data.unitList || [] ).each( function(u){
  807. this.selector.orgAction.getUnit(function (json) {
  808. this.selector.includeObject.loadUnitItem(json, unitContainer, this.level + 1, this);
  809. checkCallback("unit");
  810. }.bind(this), function(){ checkCallback("unit") }, u );
  811. }.bind(this));
  812. ( this.data.groupList || [] ).each( function(g){
  813. this.selector.orgAction.getGroup(function (json) {
  814. this.selector.includeObject.loadGroupItem(json, groupContainer, this.level + 1, this);
  815. checkCallback("group");
  816. }.bind(this), function(){ checkCallback("group") }, g );
  817. }.bind(this));
  818. }
  819. }else{
  820. if (callback) callback( );
  821. }
  822. },
  823. loadCategoryChildren: function(callback){
  824. if (!this.categoryLoaded){
  825. var groupContainer, unitContainer;
  826. if( this.data.groupList )groupContainer = new Element("div").inject( this.children );
  827. if( this.data.unitList )unitContainer = new Element("div").inject( this.children );
  828. var unitLoadedCount = 0;
  829. var groupLoadedCount = 0;
  830. var checkCallback = function( type, count ){
  831. var addCount = count || 1;
  832. if( !this.selector.options.expandSubEnable ){
  833. this.categoryLoaded = true;
  834. }else{
  835. if( type === "unit" )unitLoadedCount += addCount;
  836. if( type === "group" )groupLoadedCount += addCount;
  837. if( ( !this.data.unitList || this.data.unitList.length === 0 || this.data.unitList.length == unitLoadedCount ) &&
  838. ( !this.data.groupList || this.data.groupList.length === 0 || this.data.groupList.length == groupLoadedCount ) ){
  839. this.categoryLoaded = true;
  840. if (callback) callback();
  841. }
  842. }
  843. }.bind(this);
  844. checkCallback();
  845. //list 服务不能获取下级数量
  846. // if( this.selector.options.expandSubEnable ){
  847. // o2.Actions.load("x_organization_assemble_express").UnitAction.listObject({
  848. // unitList : this.data.unitList
  849. // }, function (json) {
  850. // this.selector.includeObject.loadUnitItem( json, this.children, this.level + 1, this);
  851. // checkCallback("unit", this.data.unitList.length )
  852. // }.bind(this), function () {
  853. // checkCallback("unit", this.data.unitList.length )
  854. // }.bind(this))
  855. //
  856. //
  857. // o2.Actions.load("x_organization_assemble_express").GroupAction.listObject({
  858. // groupList : this.data.groupList
  859. // }, function (json) {
  860. // this.selector.includeObject.loadGroupItem(json, this.children, this.level + 1, this);
  861. // checkCallback("group", this.data.groupList.length )
  862. // }.bind(this), function () {
  863. // checkCallback("group", this.data.groupList.length )
  864. // }.bind(this))
  865. // }
  866. if( this.selector.options.expandSubEnable ){
  867. ( this.data.unitList || [] ).each( function(u){
  868. this.selector.orgAction.getUnit(function (json) {
  869. this.selector.includeObject.loadUnitItem(json, unitContainer, this.level + 1, this);
  870. checkCallback("unit");
  871. }.bind(this), function(){ checkCallback("unit") }, u );
  872. }.bind(this));
  873. ( this.data.groupList || [] ).each( function(g){
  874. this.selector.orgAction.getGroup(function (json) {
  875. this.selector.includeObject.loadGroupItem(json, groupContainer, this.level + 1, this);
  876. checkCallback("group");
  877. }.bind(this), function(){ checkCallback("group") }, g );
  878. }.bind(this));
  879. }
  880. }else{
  881. if (callback) callback( );
  882. }
  883. },
  884. loadItemChildren: function(callback){
  885. if (!this.itemLoaded){
  886. var personContainer, identityContainer;
  887. if( this.data.personList )personContainer = new Element("div").inject( this.children );
  888. if( this.data.identityList )identityContainer = new Element("div").inject( this.children );
  889. var personLoadedCount = 0;
  890. var identityLoadedCount = 0;
  891. var checkCallback = function( type, count ){
  892. var addCount = count || 1;
  893. if( type === "person" )personLoadedCount += addCount;
  894. if( type === "identity" )identityLoadedCount += addCount;
  895. if(
  896. (!this.data.personList || this.data.personList.length === 0 || this.data.personList.length == personLoadedCount) &&
  897. (!this.data.identityList || this.data.identityList.length === 0 || this.data.identityList.length == identityLoadedCount)
  898. ){
  899. this.itemLoaded = true;
  900. if (callback) callback();
  901. }
  902. }.bind(this);
  903. checkCallback();
  904. if( this.data.identityList && this.data.identityList.length > 0 ){
  905. if( this.selector.options.resultType === "person" ) {
  906. //根据身份id批量获取人员对象
  907. o2.Actions.load("x_organization_assemble_express").PersonAction.listWithIdentityObject({
  908. identityList : this.data.identityList
  909. }, function (json) {
  910. this.selector.includeObject.loadPersonItem( json, identityContainer, this.level + 1, this);
  911. checkCallback("identity", this.data.identityList.length )
  912. }.bind(this), function () {
  913. checkCallback("identity", this.data.identityList.length )
  914. }.bind(this))
  915. }else{
  916. //根据身份id批量获取身份对象
  917. o2.Actions.load("x_organization_assemble_express").IdentityAction.listObject({
  918. identityList : this.data.identityList
  919. }, function (json) {
  920. this.selector.includeObject.loadIdentityItem( json, identityContainer, this.level + 1, this);
  921. checkCallback("identity", this.data.identityList.length )
  922. }.bind(this), function () {
  923. checkCallback("identity", this.data.identityList.length )
  924. }.bind(this))
  925. }
  926. }
  927. if( this.data.personList && this.data.personList.length > 0 ){
  928. if( this.selector.options.resultType === "person" ) {
  929. //根据人员d批量获取人员对象
  930. o2.Actions.load("x_organization_assemble_express").PersonAction.listObject({
  931. personList : this.data.personList
  932. }, function (json) {
  933. this.selector.includeObject.loadPersonItem( json, personContainer, this.level + 1, this);
  934. checkCallback("person", this.data.personList.length )
  935. }.bind(this), function () {
  936. checkCallback("person", this.data.personList.length )
  937. }.bind(this))
  938. }else{
  939. //根据人员id批量获取身份对象
  940. o2.Actions.load("x_organization_assemble_express").IdentityAction.listWithPersonObject({
  941. personList : this.data.personList
  942. }, function (json) {
  943. this.selector.includeObject.loadIdentityItem( json, personContainer, this.level + 1, this);
  944. checkCallback("person", this.data.personList.length )
  945. }.bind(this), function () {
  946. checkCallback("person", this.data.personList.length )
  947. }.bind(this))
  948. }
  949. }
  950. // ( this.data.personList || [] ).each( function(p){
  951. // if( this.selector.options.resultType === "person" ){
  952. // this.selector.orgAction.getPerson(function (json) {
  953. // this.selector.includeObject.loadPersonItem(json, this.children, this.level + 1, this );
  954. // checkCallback("person");
  955. // }.bind(this), function(){ checkCallback("person") }, p );
  956. // }else{
  957. // this.selector.orgAction.listIdentityByPerson(function(json){
  958. // this.selector.includeObject.loadIdentityItem(json, this.children, this.level + 1, this);
  959. // checkCallback("person")
  960. // }.bind(this), function(){ checkCallback("person") }, p );
  961. // }
  962. // }.bind(this));
  963. }else{
  964. if (callback) callback( );
  965. }
  966. },
  967. _hasChild: function(){
  968. var uCount = (this.data.unitList) ? this.data.unitList.length : 0;
  969. var gCount = (this.data.groupList) ? this.data.groupList.length : 0;
  970. var pCount = (this.data.personList) ? this.data.personList.length : 0;
  971. var iCount = (this.data.identityList) ? this.data.identityList.length : 0;
  972. return uCount + gCount + pCount + iCount;
  973. },
  974. _hasChildCategory: function(){
  975. var uCount = (this.data.unitList) ? this.data.unitList.length : 0;
  976. var gCount = (this.data.groupList) ? this.data.groupList.length : 0;
  977. return uCount + gCount;
  978. },
  979. _hasChildItem: function(){
  980. var pCount = (this.data.personList) ? this.data.personList.length : 0;
  981. var iCount = (this.data.identityList) ? this.data.identityList.length : 0;
  982. return pCount + iCount;
  983. }
  984. });
  985. MWF.xApplication.Selector.Identity.ItemRoleCategory = new Class({
  986. Extends: MWF.xApplication.Selector.Person.ItemCategory,
  987. _getShowName: function(){
  988. return this.data.name;
  989. },
  990. _setIcon: function(){
  991. var style = this.selector.options.style;
  992. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/roleicon.png)");
  993. }
  994. });
  995. MWF.xApplication.Selector.Identity.Include = new Class({
  996. Implements: [Options, Events],
  997. options: {
  998. "include" : [], //增加的可选项
  999. "resultType" : "", //可以设置成个人,那么结果返回个人
  1000. "expandSubEnable" : true //是否允许展开下一层
  1001. },
  1002. initialize: function(selector, itemAreaNode, options){
  1003. this.setOptions(options);
  1004. this.selector = selector;
  1005. this.itemAreaNode = $(itemAreaNode);
  1006. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  1007. },
  1008. load : function( callback ){
  1009. if( !this.options.include || this.options.include.length === 0 ){
  1010. this.fireEvent("afterLoad");
  1011. if(callback)callback();
  1012. return;
  1013. }
  1014. var count = 0;
  1015. var checkCallback = function () {
  1016. count++;
  1017. if( count === this.options.include.length ){
  1018. this.fireEvent("afterLoad");
  1019. if(callback)callback();
  1020. }
  1021. }.bind(this);
  1022. this.includeAreaNode = new Element( "div.includeAreaNode").inject( this.itemAreaNode, "top" );
  1023. if( this.selector.isFlatCategory ){
  1024. this.flatCategoryAreaNode = new Element( "div.includeFlatCategoryAreaNode").inject( this.selector.flatCategoryNode, "top" );
  1025. }
  1026. //this.includeIdentityAreaNode = new Element( "div").inject( this.includeAreaNode );
  1027. //this.includePersonAreaNode = new Element( "div").inject( this.includeAreaNode );
  1028. //this.includeUnitAreaNode = new Element( "div").inject( this.includeAreaNode );
  1029. //this.includeGroupAreaNode = new Element( "div").inject( this.includeAreaNode );
  1030. this.options.include.each( function( d ){
  1031. var container = new Element("div").inject( this.includeAreaNode );
  1032. var flatCategoryContainer;
  1033. if( this.flatCategoryAreaNode ){
  1034. flatCategoryContainer = new Element("div").inject( this.flatCategoryAreaNode );
  1035. }
  1036. if (typeOf(d)==="string"){
  1037. var arr = d.split("@");
  1038. var flag = arr[ arr.length - 1].toLowerCase();
  1039. if( flag === "u" ){
  1040. this.orgAction.listUnitByKey(function(json){
  1041. this.loadUnitItem(json, container, null, null, flatCategoryContainer);
  1042. checkCallback();
  1043. }.bind(this), checkCallback, d);
  1044. }else if( flag === "i" ) {
  1045. this.orgAction.listIdentityByKey(function (json) {
  1046. this.loadIdentityItem(json, container, null, null, true );
  1047. checkCallback();
  1048. }.bind(this), checkCallback, d);
  1049. }else if( flag === "g" ){
  1050. this.orgAction.listGroupByKey(function(json){
  1051. this.loadGroupItem( json , container, null, null, flatCategoryContainer);
  1052. checkCallback();
  1053. }.bind(this), checkCallback, d);
  1054. }else if( flag === "p" ){
  1055. if( this.options.resultType === "person" ){
  1056. this.orgAction.getPerson(function (json){
  1057. this.loadPersonItem( json , container, null, null, true);
  1058. checkCallback();
  1059. }.bind(this), checkCallback, d);
  1060. }else{
  1061. this.orgAction.listIdentityByPerson(function(json){
  1062. this.loadIdentityItem(json, container , null, null, true);
  1063. checkCallback();
  1064. }.bind(this), checkCallback, d);
  1065. }
  1066. }else{
  1067. if( this.options.resultType === "person" ){
  1068. this.orgAction.listPersonByKey(function (json) {
  1069. this.loadPersonItem( json , container, null, null, true);
  1070. checkCallback();
  1071. }.bind(this), checkCallback, d);
  1072. }else{
  1073. this.orgAction.listIdentityByKey(function(json){
  1074. this.loadIdentityItem(json, container, null, null, true);
  1075. checkCallback();
  1076. }.bind(this), checkCallback, d);
  1077. }
  1078. }
  1079. }else{
  1080. var arr = d.distinguishedName.split("@");
  1081. var flag = arr[ arr.length - 1].toLowerCase();
  1082. if( flag === "u" ) {
  1083. this.orgAction.getUnit(function (json) {
  1084. this.loadUnitItem(json, container, null, null, flatCategoryContainer);
  1085. checkCallback();
  1086. }.bind(this), checkCallback, d.distinguishedName);
  1087. }else if( flag === "i" ){
  1088. this.orgAction.getIdentity(function (json) {
  1089. this.loadIdentityItem(json, container, null, null, true);
  1090. checkCallback();
  1091. }.bind(this), checkCallback, d.distinguishedName);
  1092. }else if( flag === "g" ){
  1093. this.orgAction.getGroup(function(json){
  1094. this.loadGroupItem( json , container, null, null, flatCategoryContainer);
  1095. checkCallback();
  1096. }.bind(this), checkCallback, d.distinguishedName, null, null, true);
  1097. }else if( flag === "p" ){
  1098. if( this.options.resultType === "person" ){
  1099. this.orgAction.getPerson(function (json) {
  1100. this.loadPersonItem(json, container, null, null, true);
  1101. checkCallback();
  1102. }.bind(this), checkCallback, d.distinguishedName);
  1103. }else{
  1104. this.orgAction.listIdentityByPerson(function(json){
  1105. this.loadIdentityItem(json, container, null, null, true);
  1106. checkCallback();
  1107. }.bind(this), checkCallback, d.distinguishedName);
  1108. }
  1109. }else{
  1110. if( this.options.resultType === "person" ){
  1111. this.orgAction.getPerson(function (json) {
  1112. this.loadPersonItem(json, container, null, null, true);
  1113. checkCallback();
  1114. }.bind(this), checkCallback, d.distinguishedName);
  1115. }else{
  1116. this.orgAction.getIdentity(function (json) {
  1117. this.loadIdentityItem(json, container, null, null, true);
  1118. checkCallback();
  1119. }.bind(this), checkCallback, d.distinguishedName);
  1120. }
  1121. }
  1122. //var category = this._newItemCategory("ItemCategory", unit, this, this.itemAreaNode);
  1123. }
  1124. }.bind(this))
  1125. },
  1126. loadPersonItem : function( json, container, level, category, isIncludedPerson ){
  1127. if( !json.data )return;
  1128. var array = typeOf( json.data ) === "array" ? json.data : [json.data];
  1129. array.each(function(data){
  1130. if( !this.selector.isExcluded( data ) ) {
  1131. if(!this.includePerson)this.includePerson = [];
  1132. if(isIncludedPerson)this.includePerson.push( data.distinguishedName );
  1133. if(!this.includePersonObject)this.includePersonObject = [];
  1134. if(isIncludedPerson)this.includePersonObject.push( data );
  1135. var item = this.selector._newItem(data, this.selector, container || this.includeAreaNode, level || 1, category);
  1136. this.selector.items.push(item);
  1137. if( category && category.subItems ){
  1138. category.subItems.push( item );
  1139. }
  1140. }
  1141. }.bind(this));
  1142. },
  1143. loadIdentityItem : function( json, container, level, category, isIncludedIdentity ){
  1144. if( !json.data )return;
  1145. var array = typeOf( json.data ) === "array" ? json.data : [json.data];
  1146. array.each(function(data){
  1147. if( !this.selector.isExcluded( data ) ) {
  1148. if(!this.includeIdentity)this.includeIdentity = [];
  1149. if(isIncludedIdentity)this.includeIdentity.push( data.distinguishedName );
  1150. if(!this.includeIdentityObject)this.includeIdentityObject = [];
  1151. if(isIncludedIdentity)this.includeIdentityObject.push( data );
  1152. var item = this.selector._newItem(data, this.selector, container || this.includeAreaNode, level || 1, category);
  1153. this.selector.items.push(item);
  1154. if( category && category.subItems ){
  1155. category.subItems.push( item );
  1156. }
  1157. }
  1158. }.bind(this));
  1159. },
  1160. loadUnitItem : function( json, container, level, parentCategory, flatCategoryContainer ){
  1161. if( !json.data )return;
  1162. var array = typeOf( json.data ) === "array" ? json.data : [json.data];
  1163. array.each(function(data){
  1164. if( !this.selector.isExcluded( data ) ) {
  1165. if(!this.includeUnit)this.includeUnit = [];
  1166. this.includeUnit.push( data.distinguishedName );
  1167. var category;
  1168. if( flatCategoryContainer ){
  1169. category = this.selector._newItemCategory("ItemUnitCategory", data, this.selector,
  1170. container || this.includeAreaNode, level, parentCategory, true);
  1171. category.nodeContainer = flatCategoryContainer;
  1172. category.load();
  1173. }else{
  1174. category = this.selector._newItemCategory("ItemUnitCategory", data, this.selector,
  1175. container || this.includeAreaNode, level, parentCategory);
  1176. }
  1177. if( parentCategory && parentCategory.subCategorys ){
  1178. parentCategory.subCategorys.push( category )
  1179. }else if(this.selector.subCategorys){
  1180. this.selector.subCategorys.push( category )
  1181. }
  1182. }
  1183. }.bind(this));
  1184. },
  1185. loadGroupItem : function( json, container, level, parentCategory, flatCategoryContainer ){
  1186. if( !json.data )return;
  1187. var array = typeOf( json.data ) === "array" ? json.data : [json.data];
  1188. array.each(function(data){
  1189. if( !this.selector.isExcluded( data ) ) {
  1190. if(!this.includeGroup)this.includeGroup = [];
  1191. this.includeGroup.push( data.distinguishedName );
  1192. var category;
  1193. if( flatCategoryContainer ){
  1194. category = this.selector._newItemCategory("ItemGroupCategory", data, this.selector, container || this.includeAreaNode, level, parentCategory, true);
  1195. category.nodeContainer = flatCategoryContainer;
  1196. category.load();
  1197. }else{
  1198. category = this.selector._newItemCategory("ItemGroupCategory", data, this.selector, container || this.includeAreaNode, level, parentCategory)
  1199. }
  1200. if( parentCategory && parentCategory.subCategorys ){
  1201. parentCategory.subCategorys.push( category )
  1202. }else if(this.selector.subCategorys){
  1203. this.selector.subCategorys.push( category )
  1204. }
  1205. }
  1206. }.bind(this));
  1207. },
  1208. listByFilter : function( type, key, callback ){
  1209. var arr1 = this.listByFilterPerson(key) || [];
  1210. this.listByFilterUnitAndGroup( type, key, function(arr2){
  1211. this.listByFilterGroup( type, key, function(arr3){
  1212. if (callback) callback( arr1.concat( arr2 || [] ).concat( arr3 || [] ) );
  1213. }.bind(this))
  1214. }.bind(this))
  1215. },
  1216. listByFilterPerson : function( key ){
  1217. var identitys = [];
  1218. var persons = [];
  1219. var keyString = typeOf( key )==="string" ? key.toLowerCase() : key.key.toLowerCase();
  1220. if( this.includeIdentityObject && this.includeIdentityObject.length ){
  1221. identitys = this.includeIdentityObject.filter( function(id) {
  1222. return ( id.pinyin || "" ).indexOf(keyString) > -1 || (id.pinyinInitial || "").indexOf(keyString) > -1 || (id.distinguishedName || "").indexOf(keyString) > -1;
  1223. })
  1224. }
  1225. if( this.includePersonObject && this.includePersonObject.length ){
  1226. persons = this.includePersonObject.filter( function(id) {
  1227. return ( id.pinyin || "" ).indexOf(keyString) > -1 || (id.pinyinInitial || "").indexOf(keyString) > -1 || (id.distinguishedName || "").indexOf(keyString) > -1;
  1228. })
  1229. }
  1230. return identitys.concat( persons);
  1231. },
  1232. listByFilterGroup : function( type, key, callback ){
  1233. //根据关键字获取群组内的人员,再转成身份
  1234. var keyString = typeOf( key )==="string" ? key.toLowerCase() : key.key.toLowerCase();
  1235. if( this.includeGroup && this.includeGroup.length ){
  1236. var keyObject = { "key" : keyString, "groupList" : this.includeGroup };
  1237. this.orgAction[ type === "pinyin" ? "listPersonByPinyin" : "listPersonByKey" ](function(json){
  1238. if( this.options.resultType === "person" ){
  1239. if (callback) callback( json.data );
  1240. }else{
  1241. var personList = (json.data || []).map( function(d){
  1242. return d.id
  1243. });
  1244. o2.Actions.get("x_organization_assemble_express").listIdentityWithPerson( { "personList" : personList }, function(js){
  1245. if (callback) callback(js.data);
  1246. }.bind(this), function(){
  1247. if (callback) callback();
  1248. }.bind(this))
  1249. }
  1250. }.bind(this), function(){
  1251. if (callback) callback();
  1252. }.bind(this), keyObject);
  1253. }else{
  1254. if (callback) callback();
  1255. }
  1256. },
  1257. listByFilterUnitAndGroup : function( type, key, callback ){
  1258. //根据关键字获取组织和群组内的身份
  1259. var keyString = typeOf( key )==="string" ? key.toLowerCase() : key.key.toLowerCase();
  1260. if ( this.includeUnit && this.includeUnit.length ){
  1261. key = this.getUnitFilterKey( key, this.includeUnit, this.includeGroup );
  1262. this.orgAction.listIdentityByKey(function(json){
  1263. if (callback) callback(json.data);
  1264. }.bind(this), function(){
  1265. if (callback) callback();
  1266. }, key);
  1267. }else{
  1268. if (callback) callback();
  1269. }
  1270. },
  1271. getUnitFilterKey : function( key, unitObject, groupObject ){
  1272. var unitObjects = unitObject || [];
  1273. var units = [];
  1274. unitObjects.each(function(u){
  1275. if (typeOf(u)==="string"){
  1276. units.push(u);
  1277. }
  1278. if (typeOf(u)==="object"){
  1279. units.push(u.distinguishedName);
  1280. }
  1281. });
  1282. var groupObjects = groupObject || [];
  1283. var groups = [];
  1284. groupObjects.each(function(g){
  1285. if (typeOf(g)==="string"){
  1286. groups.push(g);
  1287. }
  1288. if (typeOf(g)==="object"){
  1289. groups.push(g.distinguishedName);
  1290. }
  1291. });
  1292. if( !units.length && !groups.length ){
  1293. return key;
  1294. }else{
  1295. var result = { "key": key };
  1296. if( units.length )result.unitList = units;
  1297. if( groups.length )result.groupList = groups;
  1298. return result;
  1299. }
  1300. // return units.length ? {"key": key, "unitList": units, "groupList" : groups} : key;
  1301. }
  1302. });
  1303. MWF.xApplication.Selector.Identity.Filter = new Class({
  1304. Implements: [Options, Events],
  1305. options: {
  1306. "style": "default",
  1307. "units": [],
  1308. "resultType" : "" //可以设置成个人,那么结果返回个人
  1309. },
  1310. initialize: function(value, options){
  1311. this.setOptions(options);
  1312. this.value = value;
  1313. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  1314. },
  1315. filter: function(value, callback){
  1316. this.value = value;
  1317. var key = this.value;
  1318. if (this.options.units.length){
  1319. var units = [];
  1320. this.options.units.each(function(u){
  1321. if (typeOf(u)==="string"){
  1322. units.push(u);
  1323. }
  1324. if (typeOf(u)==="object"){
  1325. units.push(u.distinguishedName);
  1326. }
  1327. });
  1328. key = {"key": this.value, "unitList": units};
  1329. }
  1330. var data = null;
  1331. this.orgAction.listIdentityByKey(function(json){
  1332. data = json.data;
  1333. if (callback) callback(data)
  1334. }.bind(this), null, key);
  1335. }
  1336. });