Identity.js 12 KB

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