Identity.js 49 KB

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