Identity.js 12 KB

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