Identity.js 38 KB

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