Identity.js 62 KB

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