Identity.js 65 KB

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