GroupSelect.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. focus:function(){
  105. this.groupInContainer.setStyles({"border":"1px solid #4A90E2"});
  106. }.bind(this),
  107. blur:function(){
  108. this.groupInContainer.setStyles({"border":"1px solid #A6A6A6"});
  109. }.bind(this)
  110. });
  111. this.groupAdd = new Element("div.groupAdd",{styles:this.css.groupAdd,text:this.lp.confirm}).inject(this.contentNode);
  112. this.groupAdd.addEvents({
  113. click:function(){
  114. if(this.groupIn.get("value").trim()=="") return;
  115. //创建新分组
  116. this.secondPageClose();
  117. }.bind(this)
  118. });
  119. },
  120. secondPageClose:function(){
  121. var data = null;
  122. if(this.groupIn.get("value").trim()!=""){
  123. data = {
  124. "name":this.groupIn.get("value").trim()
  125. };
  126. }
  127. if(!data){
  128. this.createFirstPage();
  129. return;
  130. }
  131. //this.actions.groupSave(data,function(json){
  132. this.rootActions.ProjectGroupAction.save(data,function(json){
  133. if(json.data && json.data.id){
  134. this.rootActions.ProjectGroupAction.listGroups(function(resData){ debugger;
  135. var resD = null;
  136. resData.data.each(function(dd){
  137. if(dd.id == json.data.id) resD = dd;
  138. }.bind(this));
  139. if(resD)this.createFirstPage(resD);
  140. else this.createFirstPage();
  141. }.bind(this))
  142. }else{
  143. this.createFirstPage();
  144. }
  145. }.bind(this));
  146. },
  147. createCommonGroup:function(){
  148. var _self = this;
  149. this.app.setLoading(this.commonGroupContainer);
  150. this.rootActions.ProjectGroupAction.listGroups(function(json){
  151. //this.actions.groupList(function(json){
  152. this.commonGroupContainer.empty();
  153. var data = json.data;
  154. this.allProjectGroup = json.data;
  155. if(data){
  156. data.each(function (d,i) {
  157. if(i<100){
  158. var groupItemContainer = new Element("div.groupItemContainer",{styles:this.css.groupItemContainer}).inject(this.commonGroupContainer);
  159. var groupItemIcon = new Element("div.groupItemIcon",{styles:this.css.groupItemIcon,id:d.id}).inject(groupItemContainer);
  160. groupItemIcon.addEvents({
  161. click:function(){
  162. _self.selectGroupIcon(this);
  163. }
  164. });
  165. var groupItemText = new Element("div.groupItemText",{styles:this.css.groupItemText,text:d.name}).inject(groupItemContainer);
  166. if(_self.getIdInArr(d.id)){
  167. groupItemIcon.setStyle("background-image",groupItemIcon.getStyle("background-image").replace("icon_circle.png","icon_renwu_ywc_click.png"));
  168. groupItemIcon.set("cc","yes");
  169. }
  170. }
  171. }.bind(this))
  172. }
  173. }.bind(this));
  174. },
  175. selectGroupIcon:function(obj){
  176. var _this = obj;
  177. var url = _this.getStyle("background-image");
  178. if(url.indexOf("icon_circle.png")>0){
  179. _this.setStyle("background-image",url.replace("icon_circle.png","icon_renwu_ywc_click.png"));
  180. _this.set("cc","yes")
  181. }else{
  182. _this.setStyle("background-image",url.replace("icon_renwu_ywc_click.png","icon_circle.png"));
  183. _this.set("cc","no")
  184. }
  185. //循环常用分组+新建的分组
  186. var flag = false;
  187. this.commonGroupContainer.getElements(".groupItemIcon").each(function(d){
  188. if(d.get("cc")=="yes") flag = true;
  189. });
  190. if(!flag){
  191. if(this.dynamicGroupIcon && this.dynamicGroupIcon.get("cc")=="yes") flag = true;
  192. }
  193. if(flag){
  194. this.groupAdd.setStyles({"color":"#ffffff","background-color":"#4A90E2","cursor":"pointer"});
  195. }else{
  196. this.groupAdd.setStyles({"color":"#666666","background-color":"#F0F0F0","cursor":""});
  197. }
  198. },
  199. createNewGroup:function(){
  200. this.createSecondPage();
  201. },
  202. getIdInArr:function(id){
  203. var res = false;
  204. if(this.data.groups){
  205. this.data.groups.each(function(data){
  206. if(data.id == id) res = true;
  207. });
  208. }
  209. return res;
  210. }
  211. });