Identity.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. MWF.xApplication.Selector = MWF.xApplication.Selector || {};
  2. MWF.xDesktop.requireApp("Selector", "Actions.RestActions", null, false);
  3. MWF.xDesktop.requireApp("Selector", "Person", null, false);
  4. MWF.xApplication.Selector.Identity = new Class({
  5. Extends: MWF.xApplication.Selector.Person,
  6. options: {
  7. "style": "default",
  8. "count": 0,
  9. "title": "Select Identity",
  10. "companys": [],
  11. "departments": [],
  12. "values": [],
  13. "names": [],
  14. "expand": false
  15. },
  16. initialize: function(container, options){
  17. this.setOptions(options);
  18. this.options.groups = [];
  19. this.options.roles = [];
  20. this.path = "/x_component_Selector/$Selector/";
  21. this.cssPath = "/x_component_Selector/$Selector/"+this.options.style+"/css.wcss";
  22. this._loadCss();
  23. this.container = $(container);
  24. this.action = new MWF.xApplication.Selector.Actions.RestActions();
  25. this.lastPeople = "";
  26. this.pageCount = "13";
  27. this.selectedItems = [];
  28. this.items = [];
  29. },
  30. //loadCompanylevel: function(parent){
  31. //
  32. // this.action.listSubComplexDirect(function(subJson){
  33. // subJson.data.companyList.each(function(subData){
  34. // var category = this._newItemCategory("ItemCompanyCategory", subData, this, parent.children, parent.level+1);
  35. // this.loadCompanylevel(category);
  36. // }.bind(this));
  37. // subJson.data.departmentList.each(function(subData){
  38. // var category = this._newItemCategory("ItemDepartmentCategory", subData, this, parent.children, parent.level+1);
  39. // this.loadDepartmentlevel(category);
  40. // }.bind(this));
  41. // }.bind(this), null, parent.data.id);
  42. //},
  43. //loadDepartmentlevel: function(parent){
  44. // this.action.listSubDepartment(function(subJson){
  45. // subJson.data.each(function(subData){
  46. // var category = this._newItemCategory("ItemDepartmentCategory", subData, this, parent.children, parent.level+1);
  47. // this.loadDepartmentlevel(category);
  48. // }.bind(this));
  49. // }.bind(this), null, parent.data.id);
  50. //},
  51. loadSelectItems: function(addToNext){
  52. if (this.options.companys.length || this.options.departments.length){
  53. this.options.companys.each(function(comp){
  54. this.action.listCompanyByKey(function(json){
  55. if (json.data.length){
  56. json.data.each(function(data){
  57. var category = this._newItemCategory("ItemCompanyCategory", data, this, this.itemAreaNode);
  58. }.bind(this));
  59. }
  60. }.bind(this), null, comp);
  61. }.bind(this));
  62. this.options.departments.each(function(depart){
  63. this.action.listDepartmentByKey(function(json){
  64. if (json.data.length){
  65. json.data.each(function(data){
  66. var category = this._newItemCategory("ItemDepartmentCategory", data, this, this.itemAreaNode);
  67. }.bind(this));
  68. }
  69. }.bind(this), null, depart);
  70. }.bind(this));
  71. }else{
  72. this.action.listTopCompany(function(json){
  73. json.data.each(function(data){
  74. var category = this._newItemCategory("ItemCompanyCategory", data, this, this.itemAreaNode);
  75. }.bind(this));
  76. }.bind(this));
  77. }
  78. },
  79. _scrollEvent: function(y){
  80. return true;
  81. },
  82. _getChildrenItemIds: function(){
  83. return null;
  84. },
  85. _newItemCategory: function(type, data, selector, item, level){
  86. return new MWF.xApplication.Selector.Identity[type](data, selector, item, level)
  87. },
  88. _listItemByKey: function(callback, failure, key){
  89. this.action.listIdentityByKey(function(json){
  90. if (callback) callback.apply(this, [json]);
  91. }.bind(this), failure, key);
  92. },
  93. _getItem: function(callback, failure, id, async){
  94. this.action.getIdentity(function(json){
  95. if (callback) callback.apply(this, [json]);
  96. }.bind(this), failure, id, async);
  97. },
  98. _newItemSelected: function(data, selector, item){
  99. return new MWF.xApplication.Selector.Identity.ItemSelected(data, selector, item)
  100. },
  101. _listItemByPinyin: function(callback, failure, key){
  102. this.action.listIdentityByPinyin(function(json){
  103. if (callback) callback.apply(this, [json]);
  104. }.bind(this), failure, key);
  105. },
  106. _newItem: function(data, selector, container, level){
  107. return new MWF.xApplication.Selector.Identity.Item(data, selector, container, level);
  108. }
  109. //_listItemNext: function(last, count, callback){
  110. // this.action.listRoleNext(last, count, function(json){
  111. // if (callback) callback.apply(this, [json]);
  112. // }.bind(this));
  113. //}
  114. });
  115. MWF.xApplication.Selector.Identity.Item = new Class({
  116. Extends: MWF.xApplication.Selector.Person.Item,
  117. _getShowName: function(){
  118. return this.data.name;
  119. },
  120. _setIcon: function(){
  121. this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/default/icon/personicon.png)");
  122. }
  123. });
  124. MWF.xApplication.Selector.Identity.ItemSelected = new Class({
  125. Extends: MWF.xApplication.Selector.Person.ItemSelected,
  126. _getShowName: function(){
  127. return this.data.name;
  128. },
  129. _setIcon: function(){
  130. this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/default/icon/personicon.png)");
  131. }
  132. });
  133. MWF.xApplication.Selector.Identity.ItemCompanyCategory = new Class({
  134. Extends: MWF.xApplication.Selector.Person.ItemCategory,
  135. _getShowName: function(){
  136. return this.data.name;
  137. },
  138. _setIcon: function(){
  139. this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/default/icon/companyicon.png)");
  140. },
  141. clickItem: function(){
  142. if (this._hasChild()){
  143. this.loadSub(function(){
  144. var display = this.children.getStyle("display");
  145. if (display == "none"){
  146. this.children.setStyles({"display": "block", "height": "auto"});
  147. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_expand);
  148. }else{
  149. this.children.setStyles({"display": "none", "height": "0px"});
  150. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_collapse);
  151. }
  152. }.bind(this));
  153. }
  154. },
  155. loadSub: function(callback){
  156. if (!this.loaded){
  157. this.selector.action.listSubComplexDirect(function(subJson){
  158. subJson.data.companyList.each(function(subData){
  159. var category = this.selector._newItemCategory("ItemCompanyCategory", subData, this.selector, this.children, this.level+1);
  160. }.bind(this));
  161. subJson.data.departmentList.each(function(subData){
  162. var category = this.selector._newItemCategory("ItemDepartmentCategory", subData, this.selector, this.children, this.level+1);
  163. }.bind(this));
  164. this.loaded = true;
  165. if (callback) callback();
  166. }.bind(this), null, this.data.name);
  167. }else{
  168. if (callback) callback();
  169. }
  170. },
  171. _hasChild: function(){
  172. var cCount = (this.data.companySubDirectCount) ? this.data.companySubDirectCount : 0;
  173. var dCount = (this.data.departmentSubDirectCount) ? this.data.departmentSubDirectCount : 0;
  174. var count = cCount + dCount;
  175. if (count) return true;
  176. return true;
  177. }
  178. });
  179. MWF.xApplication.Selector.Identity.ItemDepartmentCategory = new Class({
  180. Extends: MWF.xApplication.Selector.Identity.ItemCompanyCategory,
  181. createNode: function(){
  182. this.node = new Element("div", {
  183. "styles": this.selector.css.selectorItemCategory_department
  184. }).inject(this.container);
  185. },
  186. loadSub: function(callback){
  187. if (!this.loaded){
  188. // if (this.data.departmentSubDirectCount){
  189. this.selector.action.listSubDepartment(function(subJson){
  190. subJson.data.each(function(subData){
  191. var category = this.selector._newItemCategory("ItemDepartmentCategory", subData, this.selector, this.children, this.level+1);
  192. }.bind(this));
  193. }.bind(this), null, this.data.name);
  194. // }
  195. // if (this.data.identitySubDirectCount){
  196. this.selector.action.listIdentity(function(subJson){
  197. subJson.data.each(function(subData){
  198. var item = this.selector._newItem(subData, this.selector, this.children, this.level+1);
  199. this.selector.items.push(item);
  200. }.bind(this));
  201. }.bind(this), null, this.data.name);
  202. // }
  203. this.loaded = true;
  204. if (callback) callback();
  205. }else{
  206. if (callback) callback();
  207. }
  208. },
  209. _hasChild: function(){
  210. var cCount = (this.data.companySubDirectCount) ? this.data.companySubDirectCount : 0;
  211. var dCount = (this.data.departmentSubDirectCount) ? this.data.departmentSubDirectCount : 0;
  212. var iCount = (this.data.identitySubDirectCount) ? this.data.identitySubDirectCount : 0;
  213. var count = cCount + dCount + iCount;
  214. if (count) return true;
  215. return true;
  216. },
  217. _getShowName: function(){
  218. return this.data.name;
  219. },
  220. _setIcon: function(){
  221. this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/default/icon/departmenticon.png)");
  222. }
  223. });