Identity.js 74 KB

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