Identity.js 62 KB

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