Identity.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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. "exclude" : [],
  15. "expandSubEnable" : true //是否允许展开下一层
  16. },
  17. loadSelectItems: function(addToNext){
  18. if (this.options.units.length){
  19. this.options.units.each(function(unit){
  20. if (typeOf(unit)==="string"){
  21. this.orgAction.listUnitByKey(function(json){
  22. if (json.data.length){
  23. json.data.each(function(data){
  24. var category = this._newItemCategory("ItemCategory", data, this, this.itemAreaNode);
  25. }.bind(this));
  26. }
  27. }.bind(this), null, unit);
  28. }else{
  29. this.orgAction.getUnit(function(json){
  30. if (json.data){
  31. var category = this._newItemCategory("ItemCategory", json.data, this, this.itemAreaNode);
  32. }
  33. }.bind(this), null, unit.distinguishedName);
  34. //var category = this._newItemCategory("ItemCategory", unit, this, this.itemAreaNode);
  35. }
  36. }.bind(this));
  37. }else{
  38. this.orgAction.listTopUnit(function(json){
  39. json.data.each(function(data){
  40. if( !this.isExcluded( data ) ){
  41. var category = this._newItemCategory("ItemCategory", data, this, this.itemAreaNode);
  42. }
  43. }.bind(this));
  44. }.bind(this));
  45. }
  46. },
  47. checkLoadSelectItems: function(){
  48. if (!this.options.units.length){
  49. this.loadSelectItems();
  50. }else{
  51. this.loadSelectItems();
  52. }
  53. },
  54. _scrollEvent: function(y){
  55. return true;
  56. },
  57. _getChildrenItemIds: function(){
  58. return null;
  59. },
  60. _newItemCategory: function(type, data, selector, item, level){
  61. return new MWF.xApplication.Selector.Identity[type](data, selector, item, level)
  62. },
  63. _listItemByKey: function(callback, failure, key){
  64. if (this.options.units.length){
  65. var units = [];
  66. this.options.units.each(function(u){
  67. if (typeOf(u)==="string"){
  68. units.push(u);
  69. }
  70. if (typeOf(u)==="object"){
  71. units.push(u.distinguishedName);
  72. }
  73. });
  74. key = {"key": key, "unitList": units};
  75. }
  76. this.orgAction.listIdentityByKey(function(json){
  77. if (callback) callback.apply(this, [json]);
  78. }.bind(this), failure, key);
  79. },
  80. _getItem: function(callback, failure, id, async){
  81. this.orgAction.getIdentity(function(json){
  82. if (callback) callback.apply(this, [json]);
  83. }.bind(this), failure, ((typeOf(id)==="string") ? id : id.distinguishedName), async);
  84. },
  85. _newItemSelected: function(data, selector, item){
  86. return new MWF.xApplication.Selector.Identity.ItemSelected(data, selector, item)
  87. },
  88. _listItemByPinyin: function(callback, failure, key){
  89. if (this.options.units.length){
  90. var units = [];
  91. this.options.units.each(function(u){
  92. if (typeOf(u)==="string"){
  93. units.push(u);
  94. }
  95. if (typeOf(u)==="object"){
  96. units.push(u.distinguishedName);
  97. }
  98. });
  99. key = {"key": key, "unitList": units};
  100. }
  101. this.orgAction.listIdentityByPinyin(function(json){
  102. if (callback) callback.apply(this, [json]);
  103. }.bind(this), failure, key);
  104. },
  105. _newItem: function(data, selector, container, level){
  106. return new MWF.xApplication.Selector.Identity.Item(data, selector, container, level);
  107. },
  108. _newItemSearch: function(data, selector, container, level){
  109. return new MWF.xApplication.Selector.Identity.SearchItem(data, selector, container, level);
  110. }
  111. //_listItemNext: function(last, count, callback){
  112. // this.action.listRoleNext(last, count, function(json){
  113. // if (callback) callback.apply(this, [json]);
  114. // }.bind(this));
  115. //}
  116. });
  117. MWF.xApplication.Selector.Identity.Item = new Class({
  118. Extends: MWF.xApplication.Selector.Person.Item,
  119. _getShowName: function(){
  120. return this.data.name;
  121. },
  122. _getTtiteText: function(){
  123. return this.data.name+((this.data.unitLevelName) ? "("+this.data.unitLevelName+")" : "");
  124. },
  125. _setIcon: function(){
  126. this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/default/icon/personicon.png)");
  127. },
  128. getData: function(callback){
  129. if (!this.data.woPerson){
  130. this.selector.orgAction.getPerson(function(json){
  131. this.data.woPerson = json.data;
  132. if (callback) callback();
  133. }.bind(this), null, this.data.person)
  134. }else{
  135. if (callback) callback();
  136. }
  137. }
  138. });
  139. MWF.xApplication.Selector.Identity.SearchItem = new Class({
  140. Extends: MWF.xApplication.Selector.Identity.Item,
  141. _getShowName: function(){
  142. return this.data.name+((this.data.unitLevelName) ? "("+this.data.unitLevelName+")" : "");
  143. }
  144. });
  145. MWF.xApplication.Selector.Identity.ItemSelected = new Class({
  146. Extends: MWF.xApplication.Selector.Person.ItemSelected,
  147. getData: function(callback){
  148. if (!this.data.woPerson){
  149. if (this.data.person){
  150. this.selector.orgAction.getPerson(function(json){
  151. this.data.woPerson = json.data;
  152. if (callback) callback();
  153. }.bind(this), function(xhr, text, error){
  154. var errorText = error;
  155. if (xhr){
  156. var json = JSON.decode(xhr.responseText);
  157. if (json){
  158. errorText = json.message.trim() || "request json error";
  159. }else{
  160. errorText = "request json error: "+xhr.responseText;
  161. }
  162. }
  163. MWF.xDesktop.notice("error", {x: "right", y:"top"}, errorText);
  164. if (callback) callback();
  165. }.bind(this), this.data.person)
  166. }else{
  167. MWF.xDesktop.notice("error", {x: "right", y:"top"}, MWF.SelectorLP.noPerson.replace(/{name}/g, this.data.name));
  168. if (callback) callback();
  169. }
  170. }else{
  171. if (callback) callback();
  172. }
  173. },
  174. _getShowName: function(){
  175. return this.data.name+((this.data.unitLevelName) ? "("+this.data.unitLevelName+")" : "");
  176. },
  177. _getTtiteText: function(){
  178. return this.data.name+((this.data.unitLevelName) ? "("+this.data.unitLevelName+")" : "");
  179. },
  180. _setIcon: function(){
  181. this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/default/icon/personicon.png)");
  182. }
  183. });
  184. MWF.xApplication.Selector.Identity.ItemCategory = new Class({
  185. Extends: MWF.xApplication.Selector.Person.ItemCategory,
  186. createNode: function(){
  187. this.node = new Element("div", {
  188. "styles": this.selector.css.selectorItemCategory_department
  189. }).inject(this.container);
  190. },
  191. _getShowName: function(){
  192. return this.data.name;
  193. },
  194. _setIcon: function(){
  195. this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/default/icon/companyicon.png)");
  196. },
  197. clickItem: function(){
  198. if (this._hasChild()){
  199. var firstLoaded = !this.loaded;
  200. this.loadSub(function(){
  201. if( firstLoaded ){
  202. this.children.setStyles({"display": "block", "height": "auto"});
  203. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_expand);
  204. }else{
  205. var display = this.children.getStyle("display");
  206. if (display === "none"){
  207. this.children.setStyles({"display": "block", "height": "auto"});
  208. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_expand);
  209. }else{
  210. this.children.setStyles({"display": "none", "height": "0px"});
  211. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_collapse);
  212. }
  213. }
  214. }.bind(this));
  215. }
  216. },
  217. loadSub: function(callback){
  218. if (!this.loaded){
  219. debugger;
  220. if (this.selector.options.dutys && this.selector.options.dutys.length){
  221. var ids = [];
  222. this.selector.options.dutys.each(function(duty){
  223. this.selector.orgAction.listIdentityWidthUnitWithDutyName(this.data.distinguishedName, duty, function(json){
  224. if (json.data && json.data.length) ids = ids.concat(json.data)
  225. }.bind(this), null, false);
  226. ids.each(function(idSubData){
  227. if( !this.selector.isExcluded( idSubData ) ) {
  228. var item = this.selector._newItem(idSubData, this.selector, this.children, this.level + 1);
  229. this.selector.items.push(item);
  230. }
  231. if( !this.selector.options.expandSubEnable ){
  232. this.loaded = true;
  233. if (callback) callback();
  234. }
  235. }.bind(this));
  236. }.bind(this));
  237. if( this.selector.options.expandSubEnable ){
  238. this.selector.orgAction.listSubUnitDirect(function(json){
  239. json.data.each(function(subData){
  240. if( !this.selector.isExcluded( subData ) ) {
  241. var category = this.selector._newItemCategory("ItemCategory", subData, this.selector, this.children, this.level + 1);
  242. }
  243. }.bind(this));
  244. this.loaded = true;
  245. if (callback) callback();
  246. }.bind(this), null, this.data.distinguishedName);
  247. }
  248. }else{
  249. this.selector.orgAction.listIdentityWithUnit(function(idJson){
  250. idJson.data.each(function(idSubData){
  251. if( !this.selector.isExcluded( idSubData ) ) {
  252. var item = this.selector._newItem(idSubData, this.selector, this.children, this.level + 1);
  253. this.selector.items.push(item);
  254. }
  255. if( !this.selector.options.expandSubEnable ){
  256. this.loaded = true;
  257. if (callback) callback();
  258. }
  259. }.bind(this));
  260. if( this.selector.options.expandSubEnable ){
  261. this.selector.orgAction.listSubUnitDirect(function(json){
  262. json.data.each(function(subData){
  263. if( !this.selector.isExcluded( subData ) ) {
  264. var category = this.selector._newItemCategory("ItemCategory", subData, this.selector, this.children, this.level + 1);
  265. }
  266. }.bind(this));
  267. this.loaded = true;
  268. if (callback) callback();
  269. }.bind(this), null, this.data.distinguishedName);
  270. }
  271. }.bind(this), null, this.data.distinguishedName);
  272. }
  273. }else{
  274. if (callback) callback( );
  275. }
  276. },
  277. _hasChild: function(){
  278. var uCount = (this.data.subDirectUnitCount) ? this.data.subDirectUnitCount : 0;
  279. var iCount = (this.data.subDirectIdentityCount) ? this.data.subDirectIdentityCount : 0;
  280. return uCount + iCount;
  281. }
  282. });
  283. MWF.xApplication.Selector.Identity.Filter = new Class({
  284. Implements: [Options, Events],
  285. options: {
  286. "style": "default",
  287. "units": []
  288. },
  289. initialize: function(value, options){
  290. this.setOptions(options);
  291. this.value = value;
  292. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  293. },
  294. filter: function(value, callback){
  295. this.value = value;
  296. var key = this.value;
  297. if (this.options.units.length){
  298. var units = [];
  299. this.options.units.each(function(u){
  300. if (typeOf(u)==="string"){
  301. units.push(u);
  302. }
  303. if (typeOf(u)==="object"){
  304. units.push(u.distinguishedName);
  305. }
  306. });
  307. key = {"key": this.value, "unitList": units};
  308. }
  309. var data = null;
  310. this.orgAction.listIdentityByKey(function(json){
  311. data = json.data;
  312. if (callback) callback(data)
  313. }.bind(this), null, key);
  314. }
  315. });