Identity.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. MWF.xApplication.Organization.Selector = MWF.xApplication.Organization.Selector || {};
  2. MWF.xDesktop.requireApp("Organization", "Actions.RestActions", null, false);
  3. MWF.xDesktop.requireApp("Organization", "Selector.Person", null, false);
  4. MWF.xApplication.Organization.Selector.Identity = new Class({
  5. Extends: MWF.xApplication.Organization.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_Organization/Selector/$Selector/";
  21. this.cssPath = "/x_component_Organization/Selector/$Selector/"+this.options.style+"/css.wcss";
  22. this._loadCss();
  23. this.container = $(container);
  24. this.action = new MWF.xApplication.Organization.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.Organization.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.Organization.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.Organization.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.Organization.Selector.Identity.Item = new Class({
  116. Extends: MWF.xApplication.Organization.Selector.Person.Item,
  117. _getShowName: function(){
  118. return this.data.name;
  119. },
  120. _setIcon: function(){
  121. this.iconNode.setStyle("background-image", "url("+"/x_component_Organization/Selector/$Selector/default/icon/personicon.png)");
  122. }
  123. });
  124. MWF.xApplication.Organization.Selector.Identity.ItemSelected = new Class({
  125. Extends: MWF.xApplication.Organization.Selector.Person.ItemSelected,
  126. _getShowName: function(){
  127. return this.data.name;
  128. },
  129. _setIcon: function(){
  130. this.iconNode.setStyle("background-image", "url("+"/x_component_Organization/Selector/$Selector/default/icon/personicon.png)");
  131. }
  132. });
  133. MWF.xApplication.Organization.Selector.Identity.ItemCompanyCategory = new Class({
  134. Extends: MWF.xApplication.Organization.Selector.Person.ItemCategory,
  135. _getShowName: function(){
  136. return this.data.name;
  137. },
  138. _setIcon: function(){
  139. this.iconNode.setStyle("background-image", "url("+"/x_component_Organization/Selector/$Selector/default/icon/companyicon.png)");
  140. },
  141. clickItem: function(){
  142. if (this._hasChild()){
  143. var firstLoaded = !this.loaded;
  144. this.loadSub(function(){
  145. if( firstLoaded ){
  146. this.children.setStyles({"display": "block", "height": "auto"});
  147. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_expand);
  148. }else{
  149. var display = this.children.getStyle("display");
  150. if (display == "none"){
  151. this.children.setStyles({"display": "block", "height": "auto"});
  152. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_expand);
  153. }else{
  154. this.children.setStyles({"display": "none", "height": "0px"});
  155. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_collapse);
  156. }
  157. }
  158. }.bind(this));
  159. }
  160. },
  161. loadSub: function(callback){
  162. if (!this.loaded){
  163. this.selector.action.listSubComplexDirect(function(subJson){
  164. subJson.data.companyList.each(function(subData){
  165. var category = this.selector._newItemCategory("ItemCompanyCategory", subData, this.selector, this.children, this.level+1);
  166. }.bind(this));
  167. subJson.data.departmentList.each(function(subData){
  168. var category = this.selector._newItemCategory("ItemDepartmentCategory", subData, this.selector, this.children, this.level+1);
  169. }.bind(this));
  170. this.loaded = true;
  171. if (callback) callback( );
  172. }.bind(this), null, this.data.id);
  173. }else{
  174. if (callback) callback( );
  175. }
  176. },
  177. _hasChild: function(){
  178. var cCount = (this.data.companySubDirectCount) ? this.data.companySubDirectCount : 0;
  179. var dCount = (this.data.departmentSubDirectCount) ? this.data.departmentSubDirectCount : 0;
  180. var count = cCount + dCount;
  181. if (count) return true;
  182. return false;
  183. }
  184. });
  185. MWF.xApplication.Organization.Selector.Identity.ItemDepartmentCategory = new Class({
  186. Extends: MWF.xApplication.Organization.Selector.Identity.ItemCompanyCategory,
  187. createNode: function(){
  188. this.node = new Element("div", {
  189. "styles": this.selector.css.selectorItemCategory_department
  190. }).inject(this.container);
  191. },
  192. loadSub: function(callback){
  193. if (!this.loaded){
  194. if (this.data.departmentSubDirectCount){
  195. this.selector.action.listSubDepartment(function(subJson){
  196. subJson.data.each(function(subData){
  197. var category = this.selector._newItemCategory("ItemDepartmentCategory", subData, this.selector, this.children, this.level+1);
  198. }.bind(this));
  199. }.bind(this), null, this.data.id);
  200. }
  201. if (this.data.identitySubDirectCount){
  202. this.selector.action.listIdentity(function(subJson){
  203. subJson.data.each(function(subData){
  204. var item = this.selector._newItem(subData, this.selector, this.children, this.level+1);
  205. this.selector.items.push(item);
  206. }.bind(this));
  207. }.bind(this), null, this.data.id);
  208. }
  209. this.loaded = true;
  210. if (callback) callback();
  211. }else{
  212. if (callback) callback();
  213. }
  214. },
  215. _hasChild: function(){
  216. var cCount = (this.data.companySubDirectCount) ? this.data.companySubDirectCount : 0;
  217. var dCount = (this.data.departmentSubDirectCount) ? this.data.departmentSubDirectCount : 0;
  218. var iCount = (this.data.identitySubDirectCount) ? this.data.identitySubDirectCount : 0;
  219. var count = cCount + dCount + iCount;
  220. if (count) return true;
  221. return false;
  222. },
  223. _getShowName: function(){
  224. return this.data.name;
  225. },
  226. _setIcon: function(){
  227. this.iconNode.setStyle("background-image", "url("+"/x_component_Organization/Selector/$Selector/default/icon/departmenticon.png)");
  228. }
  229. });