Department.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. MWF.xApplication.Organization.Selector = MWF.xApplication.Organization.Selector || {};
  2. MWF.xDesktop.requireApp("Organization", "Actions.RestActions", null, false);
  3. MWF.xDesktop.requireApp("Organization", "Selector.Identity", null, false);
  4. MWF.xApplication.Organization.Selector.Department = new Class({
  5. Extends: MWF.xApplication.Organization.Selector.Identity,
  6. options: {
  7. "style": "default",
  8. "count": 0,
  9. "title": "Select Department",
  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. loadSelectItems: function(addToNext){
  31. if (this.options.companys.length){
  32. this.options.companys.each(function(comp){
  33. this.action.listCompanyByKey(function(json){
  34. if (json.data.length){
  35. json.data.each(function(data){
  36. var category = this._newItemCategory("ItemCompanyCategory", data, this, this.itemAreaNode);
  37. }.bind(this));
  38. }
  39. }.bind(this), null, comp);
  40. }.bind(this));
  41. }else{
  42. this.action.listTopCompany(function(json){
  43. json.data.each(function(data){
  44. var category = this._newItemCategory("ItemCompanyCategory", data, this, this.itemAreaNode);
  45. }.bind(this));
  46. }.bind(this));
  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.Organization.Selector.Department[type](data, selector, item, level)
  57. },
  58. _listItemByKey: function(callback, failure, key){
  59. this.action.listDepartmentByKey(function(json){
  60. if (callback) callback.apply(this, [json]);
  61. }.bind(this), failure, key);
  62. },
  63. _getItem: function(callback, failure, id, async){
  64. this.action.getDepartment(function(json){
  65. if (callback) callback.apply(this, [json]);
  66. }.bind(this), failure, id, async);
  67. },
  68. _newItemSelected: function(data, selector, item){
  69. return new MWF.xApplication.Organization.Selector.Department.ItemSelected(data, selector, item)
  70. },
  71. _listItemByPinyin: function(callback, failure, key){
  72. this.action.listDepartmentByKey(function(json){
  73. if (callback) callback.apply(this, [json]);
  74. }.bind(this), failure, key);
  75. },
  76. _newItem: function(data, selector, container, level){
  77. return new MWF.xApplication.Organization.Selector.Department.Item(data, selector, container, level);
  78. }
  79. });
  80. MWF.xApplication.Organization.Selector.Department.Item = new Class({
  81. Extends: MWF.xApplication.Organization.Selector.Person.Item,
  82. _getShowName: function(){
  83. return this.data.name;
  84. },
  85. _setIcon: function(){
  86. this.iconNode.setStyle("background-image", "url("+"/x_component_Organization/Selector/$Selector/default/icon/departmenticon.png)");
  87. },
  88. loadSubItem: function(){
  89. this.children = new Element("div", {
  90. "styles": this.selector.css.selectorItemCategoryChildrenNode,
  91. }).inject(this.node, "after");
  92. this.children.setStyle("display", "block");
  93. // if (!this.selector.options.expand) this.children.setStyle("display", "none");
  94. this.selector.action.listSubDepartment(function(subJson){
  95. subJson.data.each(function(subData){
  96. var category = this.selector._newItem(subData, this.selector, this.children, this.level+1);
  97. }.bind(this));
  98. }.bind(this), null, this.data.id);
  99. },
  100. });
  101. MWF.xApplication.Organization.Selector.Department.ItemSelected = new Class({
  102. Extends: MWF.xApplication.Organization.Selector.Person.ItemSelected,
  103. _getShowName: function(){
  104. return this.data.name;
  105. },
  106. _setIcon: function(){
  107. this.iconNode.setStyle("background-image", "url("+"/x_component_Organization/Selector/$Selector/default/icon/departmenticon.png)");
  108. }
  109. });
  110. MWF.xApplication.Organization.Selector.Department.ItemCompanyCategory = new Class({
  111. Extends: MWF.xApplication.Organization.Selector.Identity.ItemCompanyCategory,
  112. loadSub: function(callback){
  113. if (!this.loaded){
  114. this.selector.action.listSubComplexDirect(function(subJson){
  115. subJson.data.companyList.each(function(subData){
  116. var category = this.selector._newItemCategory("ItemCompanyCategory", subData, this.selector, this.children, this.level+1);
  117. }.bind(this));
  118. subJson.data.departmentList.each(function(subData){
  119. var category = this.selector._newItem(subData, this.selector, this.children, this.level+1);
  120. }.bind(this));
  121. this.loaded = true;
  122. if (callback) callback();
  123. }.bind(this), null, this.data.id);
  124. }else{
  125. if (callback) callback();
  126. }
  127. },
  128. });
  129. MWF.xApplication.Organization.Selector.Department.ItemDepartmentCategory = new Class({
  130. Extends: MWF.xApplication.Organization.Selector.Identity.ItemCompanyCategory,
  131. createNode: function(){
  132. this.node = new Element("div", {
  133. "styles": this.selector.css.selectorItemCategory_department
  134. }).inject(this.container);
  135. },
  136. loadSub: function(callback){
  137. if (!this.loaded){
  138. this.selector.action.listSubDepartment(function(subJson){
  139. subJson.data.each(function(subData){
  140. // var category = this.selector._newItemCategory("ItemDepartmentCategory", subData, this.selector, this.children, this.level+1);
  141. var item = this.selector._newItem(subData, this.selector, this.children, this.level+1);
  142. }.bind(this));
  143. }.bind(this), null, this.data.id);
  144. //this.selector.action.listIdentity(function(subJson){
  145. // subJson.data.each(function(subData){
  146. // var item = this.selector._newItem(subData, this.selector, this.children, this.level+1);
  147. // this.selector.items.push(item);
  148. // }.bind(this));
  149. //}.bind(this), null, this.data.id);
  150. this.loaded = true;
  151. if (callback) callback();
  152. }else{
  153. if (callback) callback();
  154. }
  155. },
  156. _hasChild: function(){
  157. var cCount = (this.data.companySubDirectCount) ? this.data.companySubDirectCount : 0;
  158. var dCount = (this.data.departmentSubDirectCount) ? this.data.departmentSubDirectCount : 0;
  159. // var iCount = (this.data.identitySubDirectCount) ? this.data.identitySubDirectCount : 0;
  160. // var count = cCount + dCount + iCount;
  161. var count = cCount + dCount
  162. if (count) return true;
  163. return false;
  164. },
  165. _getShowName: function(){
  166. return this.data.name;
  167. },
  168. _setIcon: function(){
  169. this.iconNode.setStyle("background-image", "url("+"/x_component_Organization/Selector/$Selector/default/icon/departmenticon.png)");
  170. }
  171. });