Identity.js 65 KB

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