Identity.js 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889
  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){
  112. return new MWF.xApplication.Selector.Identity[type](data, selector, item, level, category)
  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. this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/default/icon/personicon.png)");
  217. },
  218. getData: function(callback){
  219. if( this.selector.options.resultType === "person" ){
  220. var isPerson = false;
  221. if( this.data && this.data.distinguishedName ){
  222. var dn = this.data.distinguishedName;
  223. if( dn.substr(dn.length-1, 1).toLowerCase() === "p" )isPerson = true;
  224. }
  225. if( isPerson ) {
  226. if (callback) callback();
  227. }else if( this.data.woPerson ){
  228. this.data == this.data.woPerson;
  229. if (callback) callback();
  230. }else if( this.data.person ){
  231. this.selector.orgAction.getPerson(function(json){
  232. this.data = json.data;
  233. if (callback) callback();
  234. }.bind(this), null, this.data.person)
  235. }else{
  236. if (callback) callback();
  237. }
  238. }else{
  239. if (!this.data.woPerson){
  240. this.selector.orgAction.getPerson(function(json){
  241. this.data.woPerson = json.data;
  242. if (callback) callback();
  243. }.bind(this), null, this.data.person)
  244. }else{
  245. if (callback) callback();
  246. }
  247. }
  248. },
  249. checkSelectedSingle: function(){
  250. var isPerson = this.selector.options.resultType === "person";
  251. var selectedItem = this.selector.options.values.filter(function(item, index){
  252. if( isPerson ){
  253. if (typeOf(item)==="object") return (item.id && item.id === this.data.person) ||
  254. ( item.person && item.person === this.data.id ) ||
  255. ( this.data.distinguishedName && this.data.distinguishedName === item.distinguishedName);
  256. return false;
  257. }else{
  258. if (typeOf(item)==="object") return this.data.distinguishedName === item.distinguishedName;
  259. if (typeOf(item)==="string") return this.data.distinguishedName === item;
  260. return false;
  261. }
  262. }.bind(this));
  263. if (selectedItem.length){
  264. this.selectedSingle();
  265. }
  266. },
  267. checkSelected: function(){
  268. var isPerson = this.selector.options.resultType === "person";
  269. var selectedItem = this.selector.selectedItems.filter(function(item, index){
  270. if( isPerson ){
  271. return ( item.data.id && item.data.id === this.data.person ) ||
  272. ( item.data.person && item.data.person === this.data.id ) ||
  273. ( item.data.distinguishedName && item.data.distinguishedName === this.data.distinguishedName );
  274. }else{
  275. return item.data.distinguishedName === this.data.distinguishedName;
  276. }
  277. }.bind(this));
  278. if (selectedItem.length){
  279. //selectedItem[0].item = this;
  280. selectedItem[0].addItem(this);
  281. this.selectedItem = selectedItem[0];
  282. this.setSelected();
  283. }
  284. }
  285. });
  286. MWF.xApplication.Selector.Identity.SearchItem = new Class({
  287. Extends: MWF.xApplication.Selector.Identity.Item,
  288. _getShowName: function(){
  289. return this.data.name+((this.data.unitLevelName) ? "("+this.data.unitLevelName+")" : "");
  290. }
  291. });
  292. MWF.xApplication.Selector.Identity.ItemSelected = new Class({
  293. Extends: MWF.xApplication.Selector.Person.ItemSelected,
  294. getData: function(callback){
  295. if( this.selector.options.resultType === "person" ){
  296. var isPerson = false;
  297. if( this.data && this.data.distinguishedName ){
  298. var dn = this.data.distinguishedName;
  299. if( dn.substr(dn.length-1, 1).toLowerCase() === "p" )isPerson = true;
  300. }
  301. if( isPerson ){
  302. if (callback) callback();
  303. }else if( this.data.woPerson ){
  304. this.data = this.data.woPerson;
  305. if (callback) callback();
  306. }else if( this.data.person ){
  307. this.selector.orgAction.getPerson(function(json){
  308. this.data = json.data;
  309. if (callback) callback();
  310. }.bind(this), null, this.data.person )
  311. }else{
  312. if (callback) callback();
  313. }
  314. }else if (!this.data.woPerson){
  315. if (this.data.person){
  316. this.selector.orgAction.getPerson(function(json){
  317. this.data.woPerson = json.data;
  318. if (callback) callback();
  319. }.bind(this), function(xhr, text, error){
  320. var errorText = error;
  321. if (xhr){
  322. var json = JSON.decode(xhr.responseText);
  323. if (json){
  324. errorText = json.message.trim() || "request json error";
  325. }else{
  326. errorText = "request json error: "+xhr.responseText;
  327. }
  328. }
  329. MWF.xDesktop.notice("error", {x: "right", y:"top"}, errorText);
  330. if (callback) callback();
  331. }.bind(this), this.data.person)
  332. }else{
  333. MWF.xDesktop.notice("error", {x: "right", y:"top"}, MWF.SelectorLP.noPerson.replace(/{name}/g, this.data.name));
  334. if (callback) callback();
  335. }
  336. }else{
  337. if (callback) callback();
  338. }
  339. },
  340. _getShowName: function(){
  341. return this.data.name+((this.data.unitLevelName) ? "("+this.data.unitLevelName+")" : "");
  342. },
  343. _getTtiteText: function(){
  344. return this.data.name+((this.data.unitLevelName) ? "("+this.data.unitLevelName+")" : "");
  345. },
  346. _setIcon: function(){
  347. this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/default/icon/personicon.png)");
  348. },
  349. check: function(){
  350. if (this.selector.items.length){
  351. var isPerson = this.selector.options.resultType === "person";
  352. var items = this.selector.items.filter(function(item, index){
  353. if( isPerson ){
  354. return item.data.person === this.data.id ||
  355. item.data.id === this.data.person ||
  356. item.data.distinguishedName === this.data.distinguishedName;
  357. }else{
  358. return item.data.distinguishedName === this.data.distinguishedName;
  359. }
  360. }.bind(this));
  361. this.items = items;
  362. if (items.length){
  363. items.each(function(item){
  364. item.selectedItem = this;
  365. item.setSelected();
  366. }.bind(this));
  367. }
  368. }
  369. }
  370. });
  371. MWF.xApplication.Selector.Identity.ItemCategory = new Class({
  372. Extends: MWF.xApplication.Selector.Person.ItemCategory,
  373. createNode: function(){
  374. this.node = new Element("div", {
  375. "styles": this.selector.css.selectorItemCategory_department,
  376. "title" : this._getTtiteText()
  377. }).inject(this.container);
  378. },
  379. _getShowName: function(){
  380. return this.data.name;
  381. },
  382. _setIcon: function(){
  383. this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/default/icon/companyicon.png)");
  384. },
  385. clickItem: function( callback ){
  386. if (this._hasChild()){
  387. var firstLoaded = !this.loaded;
  388. this.loadSub(function(){
  389. if( firstLoaded ){
  390. this.children.setStyles({"display": "block", "height": "auto"});
  391. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_expand);
  392. this.isExpand = true;
  393. }else{
  394. var display = this.children.getStyle("display");
  395. if (display === "none"){
  396. this.children.setStyles({"display": "block", "height": "auto"});
  397. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_expand);
  398. this.isExpand = true;
  399. }else{
  400. this.children.setStyles({"display": "none", "height": "0px"});
  401. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_collapse);
  402. this.isExpand = false;
  403. }
  404. }
  405. if(callback)callback();
  406. }.bind(this));
  407. }
  408. },
  409. loadSub: function(callback){
  410. if (!this.loaded){
  411. if (this.selector.options.dutys && this.selector.options.dutys.length){
  412. var ids = [];
  413. var object = {};
  414. this.selector.options.dutys.each(function(duty){
  415. this.selector.orgAction.listIdentityWidthUnitWithDutyName(this.data.distinguishedName, duty, function(json){
  416. if (json.data && json.data.length){
  417. ids = ids.concat(json.data);
  418. }
  419. }.bind(this), null, false);
  420. ids.each(function(idSubData){
  421. if( !this.selector.isExcluded( idSubData ) && !object[ idSubData.id || idSubData.distinguishedName ]) {
  422. var item = this.selector._newItem(idSubData, this.selector, this.children, this.level + 1, this);
  423. this.selector.items.push(item);
  424. if(this.subItems)this.subItems.push( item );
  425. object[ idSubData.id || idSubData.distinguishedName ] = true;
  426. }
  427. if( !this.selector.options.expandSubEnable ){
  428. this.loaded = true;
  429. if (callback) callback();
  430. }
  431. }.bind(this));
  432. }.bind(this));
  433. if( this.selector.options.expandSubEnable ){
  434. this.selector.orgAction.listSubUnitDirect(function(json){
  435. json.data.each(function(subData){
  436. if( !this.selector.isExcluded( subData ) ) {
  437. var category = this.selector._newItemCategory("ItemUnitCategory", subData, this.selector, this.children, this.level + 1, this);
  438. this.subCategorys.push( category );
  439. }
  440. }.bind(this));
  441. this.loaded = true;
  442. if (callback) callback();
  443. }.bind(this), null, this.data.distinguishedName);
  444. }
  445. }else{
  446. this.selector.orgAction.listIdentityWithUnit(function(idJson){
  447. idJson.data.each(function(idSubData){
  448. if( !this.selector.isExcluded( idSubData ) ) {
  449. var item = this.selector._newItem(idSubData, this.selector, this.children, this.level + 1, this);
  450. this.selector.items.push(item);
  451. if(this.subItems)this.subItems.push( item );
  452. }
  453. if( !this.selector.options.expandSubEnable ){
  454. this.loaded = true;
  455. if (callback) callback();
  456. }
  457. }.bind(this));
  458. if( this.selector.options.expandSubEnable ){
  459. this.selector.orgAction.listSubUnitDirect(function(json){
  460. json.data.each(function(subData){
  461. if( !this.selector.isExcluded( subData ) ) {
  462. var category = this.selector._newItemCategory("ItemUnitCategory", subData, this.selector, this.children, this.level + 1, this);
  463. this.subCategorys.push( category );
  464. }
  465. }.bind(this));
  466. this.loaded = true;
  467. if (callback) callback();
  468. }.bind(this), null, this.data.distinguishedName);
  469. }
  470. }.bind(this), null, this.data.distinguishedName);
  471. }
  472. }else{
  473. if (callback) callback( );
  474. }
  475. },
  476. _hasChild: function(){
  477. var uCount = (this.data.subDirectUnitCount) ? this.data.subDirectUnitCount : 0;
  478. var iCount = (this.data.subDirectIdentityCount) ? this.data.subDirectIdentityCount : 0;
  479. return uCount + iCount;
  480. },
  481. _hasChildItem: function(){
  482. return (this.data.subDirectIdentityCount) ? this.data.subDirectIdentityCount : 0;
  483. }
  484. });
  485. MWF.xApplication.Selector.Identity.ItemUnitCategory = new Class({
  486. Extends: MWF.xApplication.Selector.Identity.ItemCategory
  487. });
  488. MWF.xApplication.Selector.Identity.ItemGroupCategory = new Class({
  489. Extends: MWF.xApplication.Selector.Identity.ItemCategory,
  490. createNode: function(){
  491. this.node = new Element("div", {
  492. "styles": this.selector.css.selectorItemCategory
  493. }).inject(this.container);
  494. },
  495. _setIcon: function(){
  496. this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/default/icon/groupicon.png)");
  497. },
  498. loadSub: function(callback){
  499. if (!this.loaded){
  500. var personLoadedCount = 0;
  501. var unitLoadedCount = 0;
  502. var groupLoadedCount = 0;
  503. var checkCallback = function( type ){
  504. if( !this.selector.options.expandSubEnable ){
  505. if( type === "person" )personLoadedCount++;
  506. if( !this.data.personList || this.data.personList.length === 0 || this.data.personList.length == personLoadedCount){
  507. this.loaded = true;
  508. if (callback) callback();
  509. }
  510. }else{
  511. if( type === "person" )personLoadedCount++;
  512. if( type === "unit" )unitLoadedCount++;
  513. if( type === "group" )groupLoadedCount++;
  514. if( ( !this.data.personList || this.data.personList.length === 0 || this.data.personList.length == personLoadedCount ) &&
  515. ( !this.data.unitList || this.data.unitList.length === 0 || this.data.unitList.length == unitLoadedCount ) &&
  516. ( !this.data.groupList || this.data.groupList.length === 0 || this.data.groupList.length == groupLoadedCount ) ){
  517. this.loaded = true;
  518. if (callback) callback();
  519. }
  520. }
  521. }.bind(this);
  522. checkCallback();
  523. ( this.data.personList || [] ).each( function(p){
  524. if( this.selector.options.resultType === "person" ){
  525. this.selector.orgAction.getPerson(function (json) {
  526. this.selector.includeObject.loadPersonItem(json, this.children, this.level + 1, this );
  527. checkCallback("person");
  528. }.bind(this), function(){ checkCallback("person") }, p );
  529. }else{
  530. this.selector.orgAction.listIdentityByPerson(function(json){
  531. this.selector.includeObject.loadIdentityItem(json, this.children, this.level + 1, this);
  532. checkCallback("person")
  533. }.bind(this), function(){ checkCallback("person") }, p );
  534. }
  535. }.bind(this));
  536. if( this.selector.options.expandSubEnable ){
  537. ( this.data.unitList || [] ).each( function(u){
  538. this.selector.orgAction.getUnit(function (json) {
  539. this.selector.includeObject.loadUnitItem(json, this.children, this.level + 1, this);
  540. checkCallback("unit");
  541. }.bind(this), function(){ checkCallback("unit") }, u );
  542. }.bind(this));
  543. ( this.data.groupList || [] ).each( function(g){
  544. this.selector.orgAction.getGroup(function (json) {
  545. this.selector.includeObject.loadGroupItem(json, this.children, this.level + 1, this);
  546. checkCallback("group");
  547. }.bind(this), function(){ checkCallback("group") }, g );
  548. }.bind(this));
  549. }
  550. }else{
  551. if (callback) callback( );
  552. }
  553. },
  554. _hasChild: function(){
  555. var uCount = (this.data.unitList) ? this.data.unitList.length : 0;
  556. var gCount = (this.data.groupList) ? this.data.groupList.length : 0;
  557. var pCount = (this.data.personList) ? this.data.personList.length : 0;
  558. return uCount + gCount + pCount;
  559. },
  560. _hasChildItem: function(){
  561. return (this.data.personList) ? this.data.personList.length : 0;
  562. }
  563. });
  564. MWF.xApplication.Selector.Identity.ItemRoleCategory = new Class({
  565. Extends: MWF.xApplication.Selector.Person.ItemCategory,
  566. _getShowName: function(){
  567. return this.data.name;
  568. },
  569. _setIcon: function(){
  570. this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/default/icon/roleicon.png)");
  571. }
  572. });
  573. MWF.xApplication.Selector.Identity.Include = new Class({
  574. Implements: [Options, Events],
  575. options: {
  576. "include" : [], //增加的可选项
  577. "resultType" : "", //可以设置成个人,那么结果返回个人
  578. "expandSubEnable" : true //是否允许展开下一层
  579. },
  580. initialize: function(selector, itemAreaNode, options){
  581. this.setOptions(options);
  582. this.selector = selector;
  583. this.itemAreaNode = $(itemAreaNode);
  584. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  585. },
  586. load : function(){
  587. if( !this.options.include || this.options.include.length === 0 )return;
  588. this.includeAreaNode = new Element( "div").inject( this.itemAreaNode, "top" );
  589. //this.includeIdentityAreaNode = new Element( "div").inject( this.includeAreaNode );
  590. //this.includePersonAreaNode = new Element( "div").inject( this.includeAreaNode );
  591. //this.includeUnitAreaNode = new Element( "div").inject( this.includeAreaNode );
  592. //this.includeGroupAreaNode = new Element( "div").inject( this.includeAreaNode );
  593. this.options.include.each( function( d ){
  594. var container = new Element("div").inject( this.includeAreaNode );
  595. if (typeOf(d)==="string"){
  596. var arr = d.split("@");
  597. var flag = arr[ arr.length - 1].toLowerCase();
  598. if( flag === "u" ){
  599. this.orgAction.listUnitByKey(function(json){
  600. this.loadUnitItem(json, container);
  601. }.bind(this), null, d);
  602. }else if( flag === "i" ) {
  603. this.orgAction.listIdentityByKey(function (json) {
  604. this.loadIdentityItem(json, container)
  605. }.bind(this), null, d);
  606. }else if( flag === "g" ){
  607. this.orgAction.listGroupByKey(function(json){
  608. this.loadGroupItem( json , container)
  609. }.bind(this), null, d);
  610. }else if( flag === "p" ){
  611. if( this.options.resultType === "person" ){
  612. this.orgAction.getPerson(function (json){
  613. this.loadPersonItem( json , container)
  614. }.bind(this), null, d);
  615. }else{
  616. this.orgAction.listIdentityByPerson(function(json){
  617. this.loadIdentityItem(json, container)
  618. }.bind(this), null, d);
  619. }
  620. }else{
  621. if( this.options.resultType === "person" ){
  622. this.orgAction.listPersonByKey(function (json) {
  623. this.loadPersonItem( json , container)
  624. }.bind(this), null, d);
  625. }else{
  626. this.orgAction.listIdentityByKey(function(json){
  627. this.loadIdentityItem(json, container)
  628. }.bind(this), null, d);
  629. }
  630. }
  631. }else{
  632. var arr = d.distinguishedName.split("@");
  633. var flag = arr[ arr.length - 1].toLowerCase();
  634. if( flag === "u" ) {
  635. this.orgAction.getUnit(function (json) {
  636. this.loadUnitItem(json, container);
  637. }.bind(this), null, d.distinguishedName);
  638. }else if( flag === "i" ){
  639. this.orgAction.getIdentity(function (json) {
  640. this.loadIdentityItem(json, container)
  641. }.bind(this), null, d.distinguishedName);
  642. }else if( flag === "g" ){
  643. this.orgAction.getGroup(function(json){
  644. this.loadGroupItem( json , container)
  645. }.bind(this), null, d.distinguishedName);
  646. }else if( flag === "p" ){
  647. if( this.options.resultType === "person" ){
  648. this.orgAction.getPerson(function (json) {
  649. this.loadPersonItem(json, container)
  650. }.bind(this), null, d.distinguishedName);
  651. }else{
  652. this.orgAction.listIdentityByPerson(function(json){
  653. this.loadIdentityItem(json, container)
  654. }.bind(this), null, d.distinguishedName);
  655. }
  656. }else{
  657. if( this.options.resultType === "person" ){
  658. this.orgAction.getPerson(function (json) {
  659. this.loadPersonItem(json, container)
  660. }.bind(this), null, d.distinguishedName);
  661. }else{
  662. this.orgAction.getIdentity(function (json) {
  663. this.loadIdentityItem(json, container)
  664. }.bind(this), null, d.distinguishedName);
  665. }
  666. }
  667. //var category = this._newItemCategory("ItemCategory", unit, this, this.itemAreaNode);
  668. }
  669. }.bind(this))
  670. },
  671. loadPersonItem : function( json, container, level, category ){
  672. if( !json.data )return;
  673. var array = typeOf( json.data ) === "array" ? json.data : [json.data];
  674. array.each(function(data){
  675. if( !this.selector.isExcluded( data ) ) {
  676. if(!this.includePerson)this.includePerson = [];
  677. this.includePerson.push( data.distinguishedName );
  678. if(!this.includePersonObject)this.includePersonObject = [];
  679. this.includePersonObject.push( data );
  680. var item = this.selector._newItem(data, this.selector, container || this.includeAreaNode, level || 1, category);
  681. this.selector.items.push(item);
  682. if( category && category.subItems ){
  683. category.subItems.push( item );
  684. }
  685. }
  686. }.bind(this));
  687. },
  688. loadIdentityItem : function( json, container, level, category ){
  689. if( !json.data )return;
  690. var array = typeOf( json.data ) === "array" ? json.data : [json.data];
  691. array.each(function(data){
  692. if( !this.selector.isExcluded( data ) ) {
  693. if(!this.includeIdentity)this.includeIdentity = [];
  694. this.includeIdentity.push( data.distinguishedName );
  695. if(!this.includeIdentityObject)this.includeIdentityObject = [];
  696. this.includeIdentityObject.push( data );
  697. var item = this.selector._newItem(data, this.selector, container || this.includeAreaNode, level || 1, category);
  698. this.selector.items.push(item);
  699. if( category && category.subItems ){
  700. category.subItems.push( item );
  701. }
  702. }
  703. }.bind(this));
  704. },
  705. loadUnitItem : function( json, container, level, parentCategory ){
  706. if( !json.data )return;
  707. var array = typeOf( json.data ) === "array" ? json.data : [json.data];
  708. array.each(function(data){
  709. if( !this.selector.isExcluded( data ) ) {
  710. if(!this.includeUnit)this.includeUnit = [];
  711. this.includeUnit.push( data.distinguishedName );
  712. var category = this.selector._newItemCategory("ItemUnitCategory", data, this.selector, container || this.includeAreaNode, level, parentCategory);
  713. if( parentCategory && parentCategory.subCategorys ){
  714. parentCategory.subCategorys.push( category )
  715. }else{
  716. this.selector.subCategorys.push( category )
  717. }
  718. }
  719. }.bind(this));
  720. },
  721. loadGroupItem : function( json, container, level, parentCategory ){
  722. if( !json.data )return;
  723. var array = typeOf( json.data ) === "array" ? json.data : [json.data];
  724. array.each(function(data){
  725. if( !this.selector.isExcluded( data ) ) {
  726. if(!this.includeGroup)this.includeGroup = [];
  727. this.includeGroup.push( data.distinguishedName );
  728. var category = this.selector._newItemCategory("ItemGroupCategory", data, this.selector, container || this.includeAreaNode, level, parentCategory);
  729. if( parentCategory && parentCategory.subCategorys ){
  730. parentCategory.subCategorys.push( category )
  731. }else{
  732. this.selector.subCategorys.push( category )
  733. }
  734. }
  735. }.bind(this));
  736. },
  737. listByFilter : function( type, key, callback ){
  738. var arr1 = this.listByFilterPerson(key) || [];
  739. this.listByFilterUnit( type, key, function(arr2){
  740. this.listByFilterGroup( type, key, function(arr3){
  741. if (callback) callback( arr1.concat( arr2 || [] ).concat( arr3 || [] ) );
  742. }.bind(this))
  743. }.bind(this))
  744. },
  745. listByFilterPerson : function( key ){
  746. var identitys = [];
  747. var persons = [];
  748. var keyString = typeOf( key )==="string" ? key.toLowerCase() : key.key.toLowerCase();
  749. if( this.includeIdentityObject && this.includeIdentityObject.length ){
  750. identitys = this.includeIdentityObject.filter( function(id) {
  751. return ( id.pinyin || "" ).indexOf(keyString) > -1 || (id.pinyinInitial || "").indexOf(keyString) > -1 || (id.distinguishedName || "").indexOf(keyString) > -1;
  752. })
  753. }
  754. if( this.includePersonObject && this.includePersonObject.length ){
  755. persons = this.includePersonObject.filter( function(id) {
  756. return ( id.pinyin || "" ).indexOf(keyString) > -1 || (id.pinyinInitial || "").indexOf(keyString) > -1 || (id.distinguishedName || "").indexOf(keyString) > -1;
  757. })
  758. }
  759. return identitys.concat( persons);
  760. },
  761. listByFilterGroup : function( type, key, callback ){
  762. var keyString = typeOf( key )==="string" ? key.toLowerCase() : key.key.toLowerCase();
  763. if( this.includeGroup && this.includeGroup.length ){
  764. var keyObject = { "key" : keyString, "groupList" : this.includeGroup };
  765. this.orgAction[ type === "pinyin" ? "listPersonByPinyin" : "listPersonByKey" ](function(json){
  766. if( this.options.resultType === "person" ){
  767. if (callback) callback( json.data );
  768. }else{
  769. var personList = (json.data || []).map( function(d){
  770. return d.id
  771. });
  772. o2.Actions.get("x_organization_assemble_express").listIdentityWithPerson( personList, function(js){
  773. if (callback) callback(js.data);
  774. }.bind(this), function(){
  775. if (callback) callback();
  776. }.bind(this))
  777. }
  778. }.bind(this), function(){
  779. if (callback) callback();
  780. }.bind(this), keyObject);
  781. }else{
  782. if (callback) callback();
  783. }
  784. },
  785. listByFilterUnit : function( type, key, callback ){
  786. var keyString = typeOf( key )==="string" ? key.toLowerCase() : key.key.toLowerCase();
  787. if ( this.includeUnit && this.includeUnit.length ){
  788. key = this.getUnitFilterKey( key, this.includeUnit );
  789. this.orgAction.listIdentityByPinyin(function(json){
  790. if (callback) callback(json.data);
  791. }.bind(this), function(){
  792. if (callback) callback();
  793. }, key);
  794. }else{
  795. if (callback) callback();
  796. }
  797. },
  798. getUnitFilterKey : function( key, unitObjects ){
  799. var unitObjects = unitObjects || [];
  800. var units = [];
  801. unitObjects.each(function(u){
  802. if (typeOf(u)==="string"){
  803. units.push(u);
  804. }
  805. if (typeOf(u)==="object"){
  806. units.push(u.distinguishedName);
  807. }
  808. });
  809. return units.length ? {"key": key, "unitList": units} : key;
  810. }
  811. });
  812. MWF.xApplication.Selector.Identity.Filter = new Class({
  813. Implements: [Options, Events],
  814. options: {
  815. "style": "default",
  816. "units": [],
  817. "resultType" : "" //可以设置成个人,那么结果返回个人
  818. },
  819. initialize: function(value, options){
  820. this.setOptions(options);
  821. this.value = value;
  822. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  823. },
  824. filter: function(value, callback){
  825. this.value = value;
  826. var key = this.value;
  827. if (this.options.units.length){
  828. var units = [];
  829. this.options.units.each(function(u){
  830. if (typeOf(u)==="string"){
  831. units.push(u);
  832. }
  833. if (typeOf(u)==="object"){
  834. units.push(u.distinguishedName);
  835. }
  836. });
  837. key = {"key": this.value, "unitList": units};
  838. }
  839. var data = null;
  840. this.orgAction.listIdentityByKey(function(json){
  841. data = json.data;
  842. if (callback) callback(data)
  843. }.bind(this), null, key);
  844. }
  845. });