GroupSelect.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. MWF.xApplication.TeamWork = MWF.xApplication.TeamWork || {};
  2. MWF.xApplication.TeamWork.GroupSelect = new Class({
  3. Extends: MWF.xApplication.TeamWork.Common.ToolTips,
  4. options : {
  5. // displayDelay : 300,
  6. hasArrow:false,
  7. event:"click"
  8. },
  9. _loadCustom : function( callback ){
  10. this.css = this.css.tooltip.groupSelect;
  11. this.lp = this.lp.groupSelect;
  12. this.createFirstPage();
  13. if(callback)callback();
  14. },
  15. createFirstPage:function(data){ //alert(JSON.stringify(this.data))
  16. var _self = this;
  17. if(this.contentNode)this.contentNode.empty();
  18. this.topBar = new Element("div.topBar",{styles:this.css.topBar}).inject(this.contentNode);
  19. this.topBarText = new Element("div.topBarText",{styles:this.css.topBarText,text:this.lp.name}).inject(this.topBar);
  20. this.topBarClose = new Element("div.topBarClose",{styles:this.css.topBarClose}).inject(this.topBar);
  21. this.topBarClose.addEvents({
  22. click:function(){this.hide()}.bind(this)
  23. });
  24. // this.groupInContainer = new Element("div.groupInContainer",{styles:this.css.groupInContainer}).inject(this.contentNode);
  25. // this.groupIn = new Element("input.groupIn",{styles:this.css.groupIn,type:"text",placeholder:this.lp.groupIn}).inject(this.groupInContainer);
  26. // this.groupIn.addEvents({
  27. // keyup:function(){
  28. // var v = this.groupIn.get("value");
  29. // //this.allProjectGroup
  30. // var searchRes = [];
  31. // this.allProjectGroup.each(function(d){
  32. // if(d.title.indexOf(v)>-1) searchRes.push(d);
  33. // });
  34. //
  35. // }.bind(this)
  36. // });
  37. this.dynamicLayout = new Element("div.dynamicLayout",{styles:this.css.dynamicLayout}).inject(this.contentNode);
  38. this.dynamicLayout.setStyle("display","none");
  39. this.commonGroup = new Element("div.commonGroup",{styles:this.css.commonGroup,text:this.lp.select}).inject(this.contentNode);
  40. this.commonGroupContainer = new Element("div.commonGroupContainer",{styles:this.css.commonGroupContainer}).inject(this.contentNode);
  41. this.app.setScrollBar(this.commonGroupContainer);
  42. this.createCommonGroup();
  43. this.newGroupContainer = new Element("div.newGroupContainer",{styles:this.css.newGroupContainer}).inject(this.contentNode);
  44. this.newGroupContainer.addEvents({
  45. click:function(){
  46. this.createNewGroup();
  47. }.bind(this)
  48. });
  49. this.newGroupIcon = new Element("div.newGroupIcon",{styles:this.css.newGroupIcon}).inject(this.newGroupContainer);
  50. this.newGroupText = new Element("div.newGroupText",{styles:this.css.newGroupText,text:this.lp.add}).inject(this.newGroupContainer);
  51. this.groupAdd = new Element("div.groupAdd",{styles:this.css.groupAdd,text:this.lp.confirm}).inject(this.contentNode);
  52. this.groupAdd.addEvents({
  53. click:function(){
  54. var dd = [];
  55. this.commonGroupContainer.getElements(".groupItemIcon").each(function(d){
  56. // if(d.get("cc")=="yes") dd.push($(d).getNext().get("text"))
  57. if(d.get("cc")=="yes") dd.push($(d).get("id"))
  58. });
  59. if(this.dynamicGroupIcon && this.dynamicGroupIcon.get("cc")=="yes") dd.push(this.dynamicGroupIcon.get("id"));
  60. this.close(dd)
  61. //if(dd.length>0)this.close(dd);
  62. }.bind(this)
  63. });
  64. //加载可能新建的组
  65. if(data){
  66. this.dynamicLayout.setStyle("display","");
  67. this.dynamicGroupIcon = new Element("div.dynamicGroupIcon",{styles:this.css.dynamicGroupIcon,id:data.id}).inject(this.dynamicLayout);
  68. this.dynamicGroupIcon.addEvents({
  69. click:function(){
  70. _self.selectGroupIcon(this);
  71. }
  72. });
  73. var dynamicGroupText = new Element("div.dynamicGroupText",{styles:this.css.dynamicGroupText,text:data.name}).inject(this.dynamicLayout);
  74. this.dynamicGroupIcon.click();
  75. }
  76. },
  77. createSecondPage:function(){
  78. if(this.contentNode)this.contentNode.empty();
  79. this.topBar = new Element("div.topBar",{styles:this.css.topBar}).inject(this.contentNode);
  80. this.topBarBack = new Element("div.topBarBack",{styles:this.css.topBarBack}).inject(this.topBar);
  81. this.topBarBack.addEvent("click",function(){this.secondPageClose()}.bind(this));
  82. this.topBarText = new Element("div.topBarText",{styles:this.css.topBarText,text:this.lp.newGroup}).inject(this.topBar);
  83. this.topBarClose = new Element("div.topBarClose",{styles:this.css.topBarClose}).inject(this.topBar);
  84. this.topBarClose.addEvent("click",function(){this.secondPageClose()}.bind(this));
  85. this.groupInContainer = new Element("div.groupInContainer",{styles:this.css.groupInContainer}).inject(this.contentNode);
  86. this.groupIn = new Element("input.groupIn",{styles:this.css.groupIn,type:"text",placeholder:this.lp.groupTextTip}).inject(this.groupInContainer);
  87. this.groupIn.addEvents({
  88. keyup:function(){
  89. var v = this.groupIn.get("value");
  90. if(v.trim()==""){
  91. this.groupAdd.setStyles({
  92. "cursor":"",
  93. "background-color":"#F0F0F0",
  94. "color":"#666666"
  95. })
  96. }else{
  97. this.groupAdd.setStyles({
  98. "cursor":"pointer",
  99. "background-color":"#4A90E2",
  100. "color":"#FFFFFF"
  101. })
  102. }
  103. }.bind(this)
  104. });
  105. this.groupAdd = new Element("div.groupAdd",{styles:this.css.groupAdd,text:this.lp.confirm}).inject(this.contentNode);
  106. this.groupAdd.addEvents({
  107. click:function(){
  108. if(this.groupIn.get("value").trim()=="") return;
  109. //创建新分组
  110. this.secondPageClose();
  111. }.bind(this)
  112. });
  113. },
  114. secondPageClose:function(){
  115. var data = null;
  116. if(this.groupIn.get("value").trim()!=""){
  117. data = {
  118. "name":this.groupIn.get("value").trim()
  119. };
  120. }
  121. if(!data){
  122. this.createFirstPage();
  123. return;
  124. }
  125. //this.actions.groupSave(data,function(json){
  126. this.rootActions.ProjectGroupAction.save(data,function(json){
  127. if(json.data && json.data.id){
  128. this.rootActions.ProjectGroupAction.listGroups(function(resData){ debugger;
  129. var resD = null;
  130. resData.data.each(function(dd){
  131. if(dd.id == json.data.id) resD = dd;
  132. }.bind(this));
  133. if(resD)this.createFirstPage(resD);
  134. else this.createFirstPage();
  135. }.bind(this))
  136. }else{
  137. this.createFirstPage();
  138. }
  139. }.bind(this));
  140. },
  141. createCommonGroup:function(){
  142. var _self = this;
  143. this.app.setLoading(this.commonGroupContainer);
  144. this.rootActions.ProjectGroupAction.listGroups(function(json){
  145. //this.actions.groupList(function(json){
  146. this.commonGroupContainer.empty();
  147. var data = json.data;
  148. this.allProjectGroup = json.data;
  149. if(data){
  150. data.each(function (d,i) {
  151. if(i<100){
  152. var groupItemContainer = new Element("div.groupItemContainer",{styles:this.css.groupItemContainer}).inject(this.commonGroupContainer);
  153. var groupItemIcon = new Element("div.groupItemIcon",{styles:this.css.groupItemIcon,id:d.id}).inject(groupItemContainer);
  154. groupItemIcon.addEvents({
  155. click:function(){
  156. _self.selectGroupIcon(this);
  157. }
  158. });
  159. var groupItemText = new Element("div.groupItemText",{styles:this.css.groupItemText,text:d.name}).inject(groupItemContainer);
  160. if(_self.getIdInArr(d.id)){
  161. groupItemIcon.setStyle("background-image",groupItemIcon.getStyle("background-image").replace("icon_circle.png","icon_renwu_ywc_click.png"));
  162. groupItemIcon.set("cc","yes");
  163. }
  164. }
  165. }.bind(this))
  166. }
  167. }.bind(this));
  168. },
  169. selectGroupIcon:function(obj){
  170. var _this = obj;
  171. var url = _this.getStyle("background-image");
  172. if(url.indexOf("icon_circle.png")>0){
  173. _this.setStyle("background-image",url.replace("icon_circle.png","icon_renwu_ywc_click.png"));
  174. _this.set("cc","yes")
  175. }else{
  176. _this.setStyle("background-image",url.replace("icon_renwu_ywc_click.png","icon_circle.png"));
  177. _this.set("cc","no")
  178. }
  179. //循环常用分组+新建的分组
  180. var flag = false;
  181. this.commonGroupContainer.getElements(".groupItemIcon").each(function(d){
  182. if(d.get("cc")=="yes") flag = true;
  183. });
  184. if(!flag){
  185. if(this.dynamicGroupIcon && this.dynamicGroupIcon.get("cc")=="yes") flag = true;
  186. }
  187. if(flag){
  188. this.groupAdd.setStyles({"color":"#ffffff","background-color":"#4A90E2","cursor":"pointer"});
  189. }else{
  190. this.groupAdd.setStyles({"color":"#666666","background-color":"#F0F0F0","cursor":""});
  191. }
  192. },
  193. createNewGroup:function(){
  194. this.createSecondPage();
  195. },
  196. getIdInArr:function(id){
  197. var res = false;
  198. if(this.data.groups){
  199. this.data.groups.each(function(data){
  200. if(data.id == id) res = true;
  201. });
  202. }
  203. return res;
  204. }
  205. });