NewProject.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. MWF.xApplication.TeamWork = MWF.xApplication.TeamWork || {};
  2. MWF.xApplication.TeamWork.NewProject = new Class({
  3. Extends: MWF.xApplication.TeamWork.Common.Popup,
  4. options:{
  5. "closeByClickMask" : false
  6. },
  7. open: function (e) {
  8. //设置css 和 lp等
  9. var css = this.css;
  10. this.cssPath = "../x_component_TeamWork/$NewProject/"+this.options.style+"/css.wcss";
  11. this._loadCss();
  12. if(css) this.css = Object.merge( css, this.css );
  13. this.lp = this.app.lp.newProject;
  14. this.fireEvent("queryOpen");
  15. this.isNew = false;
  16. this.isEdited = false;
  17. this._open();
  18. this.fireEvent("postOpen");
  19. },
  20. _createTableContent: function () {
  21. //var a = new Element("div.aaa",{styles:{"width":"100px","height":"100px","background-color":"#f00"},text:"f分分分f分分f分分分f分分分"}).inject(this.formTableArea);
  22. // alert(JSON.stringify(this.css.projectAdd))
  23. // alert(JSON.stringify(this.lp))
  24. this.newProjectTop = new Element("div.newProjectTop",{styles:this.css.newProjectTop}).inject(this.formTableArea);
  25. this.newProjectTopText = new Element("div.newProjectTopText",{styles:this.css.newProjectTopText,text:this.lp.title}).inject(this.newProjectTop);
  26. this.newProjectTopClose = new Element("div.newProjectTopClose",{styles:this.css.newProjectTopClose}).inject(this.newProjectTop);
  27. this.newProjectTopClose.addEvents({
  28. click:function(){this.close()}.bind(this)
  29. });
  30. this.newProjectContainer = new Element("div.newProjectInContainer",{styles:this.css.newProjectContainer}).inject(this.formTableArea);
  31. this.newProjectIn = new Element("input.newProjectIn",{styles:this.css.newProjectIn,type:"text",placeholder:this.lp.name}).inject(this.newProjectContainer);
  32. this.newProjectIn.addEvents({
  33. keyup:function(){
  34. var v = this.newProjectIn.get("value");
  35. if(v.trim()==""){
  36. this.newProjectAdd.setStyles({
  37. "cursor":"",
  38. "background-color":"#F0F0F0",
  39. "color":"#666666"
  40. });
  41. }else{
  42. this.newProjectAdd.setStyles({
  43. "cursor":"pointer",
  44. "background-color":"#4A90E2",
  45. "color":"#FFFFFF"
  46. });
  47. }
  48. }.bind(this),
  49. focus:function(){
  50. this.newProjectContainer.setStyles({"border":"1px solid #4A90E2"});
  51. }.bind(this),
  52. blur:function(){
  53. this.newProjectContainer.setStyles({"border":"1px solid #A6A6A6"});
  54. }.bind(this)
  55. });
  56. this.newProjectDesContainer = new Element("div.newProjectDesContainer",{styles:this.css.newProjectDesContainer}).inject(this.formTableArea);
  57. this.newProjectDesIn = new Element("textarea.newProjectDesIn",{styles:this.css.newProjectDesIn,placeholder:this.lp.description}).inject(this.newProjectDesContainer);
  58. this.newProjectDesIn.addEvents({
  59. focus:function(){ //32px
  60. var v = this.newProjectDesIn.get("value");
  61. if(v.trim()==""){
  62. this.newProjectDesIn.setStyle("line-height","");
  63. var _h = 36;
  64. this.newProjectDesContainer.setStyles({"height":(this.newProjectDesContainer.getHeight()+_h)+"px"});
  65. this.newProjectDesIn.setStyles({"height":(this.newProjectDesIn.getHeight()+_h-2)+"px"});
  66. this.formAreaNode.setStyles({"height":(this.formAreaNode.getHeight()+_h)+"px"});
  67. this.formNode.setStyles({"height":(this.formNode.getHeight()+_h)+"px"});
  68. this.formTableContainer.setStyles({"height":(this.formTableContainer.getHeight()+_h)+"px"});
  69. this.formTableArea.setStyles({"height":(this.formTableArea.getHeight()+_h)+"px"});
  70. this.formContentNode.setStyles({"height":(this.formContentNode.getHeight()+_h)+"px"});
  71. var pre = this.formTableContainer.getPrevious();
  72. if(pre){
  73. pre.destroy();
  74. }
  75. }
  76. this.newProjectDesContainer.setStyles({"border":"1px solid #4A90E2"});
  77. }.bind(this),
  78. blur:function(){
  79. var v = this.newProjectDesIn.get("value");
  80. if(v.trim()==""){
  81. this.newProjectDesIn.setStyle("line-height","32px");
  82. var _h = 36;
  83. this.newProjectDesContainer.setStyles({"height":(this.newProjectDesContainer.getHeight()-_h)+"px"});
  84. this.newProjectDesIn.setStyles({"height":(this.newProjectDesIn.getHeight()-_h-2)+"px"});
  85. this.formAreaNode.setStyles({"height":(this.formAreaNode.getHeight()-_h)+"px"});
  86. this.formNode.setStyles({"height":(this.formNode.getHeight()-_h)+"px"});
  87. this.formTableContainer.setStyles({"height":(this.formTableContainer.getHeight()-_h)+"px"});
  88. this.formTableArea.setStyles({"height":(this.formTableArea.getHeight()-_h)+"px"});
  89. this.formContentNode.setStyles({"height":(this.formContentNode.getHeight()-_h)+"px"});
  90. var pre = this.formTableContainer.getPrevious();
  91. if(pre){
  92. pre.destroy();
  93. }
  94. }
  95. this.newProjectDesContainer.setStyles({"border":"1px solid #A6A6A6"});
  96. }.bind(this)
  97. });
  98. this.newProjectGroupText = new Element("div.newProjectGroupText",{styles:this.css.newProjectGroupText,text:this.lp.group}).inject(this.formTableArea);
  99. this.newProjectGroupContainer = new Element("div.newProjectGroupContainer",{styles:this.css.newProjectGroupContainer}).inject(this.formTableArea);
  100. this.newProjectGroupValue = new Element("div.newProjectGroupValue",{styles:this.css.newProjectGroupValue,text:""}).inject(this.newProjectGroupContainer);
  101. this.newProjectGroupArrow = new Element("div.newProjectGroupArrow",{styles:this.css.newProjectGroupArrow}).inject(this.newProjectGroupContainer);
  102. this.newProjectGroupContainer.addEvents({
  103. click:function(){
  104. var node = this.newProjectGroupContainer;
  105. var data = {groups:this.selectGroup};
  106. //alert(JSON.stringify(this.selectGroup))
  107. MWF.xDesktop.requireApp("TeamWork", "GroupSelect", function(){
  108. var gs = new MWF.xApplication.TeamWork.GroupSelect(this.container, node, this.app, data, {
  109. axis : "y",
  110. nodeStyles : {
  111. "z-index" : "102"
  112. },
  113. onClose:function(d){
  114. this.newProjectGroupContainer.setStyles({"border":"1px solid #A6A6A6"});
  115. if(!d) return;
  116. this.refreshGroup(function(){
  117. var res = [];
  118. d.each(function(dd){
  119. this.groupSearch(dd,function(json){
  120. if(json) res.push(json);
  121. }.bind(this));
  122. }.bind(this));
  123. this.selectGroup = res;
  124. var resVal = [];
  125. res.each(function(dd){
  126. resVal.push(dd.name);
  127. }.bind(this));
  128. this.newProjectGroupValue.set("text",resVal.join(","));
  129. }.bind(this));
  130. }.bind(this)
  131. });
  132. gs.load()
  133. }.bind(this));
  134. this.newProjectGroupContainer.setStyles({"border":"1px solid #4A90E2"});
  135. }.bind(this)
  136. });
  137. this.newProjectTemplateText = new Element("div.newProjectTemplateText",{styles:this.css.newProjectTemplateText,text:this.lp.template}).inject(this.formTableArea);
  138. this.newProjectTemplateContainer = new Element("div.newProjectTemplateContainer",{styles:this.css.newProjectTemplateContainer}).inject(this.formTableArea);
  139. this.newProjectTemplateValue = new Element("div.newProjectTemplateValue",{styles:this.css.newProjectTemplateValue,text:""}).inject(this.newProjectTemplateContainer);
  140. this.newProjectTemplateArrow = new Element("div.newProjectTemplateArrow",{styles:this.css.newProjectTemplateArrow}).inject(this.newProjectTemplateContainer);
  141. this.newProjectTemplateContainer.addEvents({
  142. click:function(){
  143. var tm = new MWF.xApplication.TeamWork.NewProject.TemplateSelect(this.container, this.newProjectTemplateContainer, this.app, {}, {
  144. css:this.css, lp:this.lp, axis : "y",
  145. position : { //node 固定的位置
  146. x : "auto",
  147. y : "middle"
  148. },
  149. nodeStyles : {
  150. "min-width":"200px",
  151. "width":"265px",
  152. "padding":"2px",
  153. "border-radius":"5px",
  154. "box-shadow":"0px 0px 4px 0px #999999",
  155. "z-index" : "201"
  156. },
  157. onPostLoad:function(){
  158. tm.node.setStyles({"opacity":"0","top":(tm.node.getStyle("top").toInt()+4)+"px"});
  159. var fx = new Fx.Tween(tm.node,{duration:400});
  160. fx.start(["opacity"] ,"0", "1");
  161. },
  162. onClose:function(rd){
  163. this.newProjectTemplateContainer.setStyles({"border":"1px solid #cccccc"});
  164. if(!rd) return;
  165. this.newProjectTemplateValue.set("text",rd.title);
  166. this.templateId = rd.id;
  167. // if(rd.act == "remove"){
  168. // this.close(rd);
  169. // if(this.data.projectObj){ //reload project
  170. // this.data.projectObj.createTaskGroup()
  171. // }
  172. // }
  173. }.bind(this)
  174. },null,this);
  175. tm.load();
  176. this.newProjectTemplateContainer.setStyles({"border":"1px solid #4A90E2"});
  177. }.bind(this)
  178. });
  179. this.newProjectAdd = new Element("div.newProjectAdd",{styles:this.css.newProjectAdd,text:this.lp.add}).inject(this.formTableArea);
  180. this.newProjectAdd.addEvents({
  181. click:function(){
  182. var v = this.newProjectIn.get("value").trim();
  183. var des = this.newProjectDesIn.get("value");
  184. if(v=="") return;
  185. var groups = [];
  186. if(this.selectGroup){
  187. this.selectGroup.each(function(d){
  188. groups.push(d.id);
  189. });
  190. }
  191. var data = {
  192. "title":v,
  193. "description":des,
  194. "groups":groups,
  195. "templateId":this.templateId || ""
  196. };
  197. //this.actions.projectSave(data,function(json){
  198. this.rootActions.ProjectAction.save(data,function(json){
  199. this.close(json);
  200. }.bind(this));
  201. }.bind(this)
  202. });
  203. },
  204. groupSearch:function(id,callback){
  205. var res = null;
  206. this.allGroupList.each(function(d){
  207. if(d.id == id) res = d;
  208. }.bind(this));
  209. if(callback)callback(res);
  210. },
  211. refreshGroup:function(callback){
  212. //this.actions.groupList(function(json){
  213. this.rootActions.ProjectGroupAction.listGroups(function(json){
  214. this.allGroupList = json.data;
  215. if(callback)callback();
  216. }.bind(this))
  217. }
  218. });
  219. MWF.xApplication.TeamWork.NewProject.TemplateSelect = new Class({
  220. Extends: MWF.xApplication.TeamWork.Common.ToolTips,
  221. options : {
  222. // displayDelay : 300,
  223. hasArrow:false,
  224. event:"click"
  225. },
  226. _loadCustom : function( callback ){
  227. this.rootActions = this.app.rootActions;
  228. var _self = this;
  229. this.css = this.options.css;
  230. this.lp = this.options.lp;
  231. //this.data
  232. //this.contentNode
  233. //debugger;
  234. var topTemplateTitle = new Element("div.topTemplateTitle",{ styles:this.css.topTemplateTitle, text: this.lp.templateTitle }).inject(this.contentNode);
  235. this.tempateContainer = new Element("div.tempateContainer",{ styles:this.css.tempateContainer }).inject(this.contentNode);
  236. this.rootActions.ProjectTemplateAction.listNextWithFilter("(0)",100,{},function(json){
  237. //alert(json.data.length)
  238. json.data.each(function(data){
  239. this.templateItem(data)
  240. }.bind(this))
  241. }.bind(this));
  242. if(callback)callback();
  243. },
  244. templateItem:function(data){
  245. var _self = this;
  246. var templateItemContainer = new Element("div.templateItemContainer",{styles:this.css.templateItemContainer, id:data.id}).inject(this.tempateContainer);
  247. var templateItemIcon = new Element("div.templateItemIcon",{styles:this.css.templateItemIcon}).inject(templateItemContainer);
  248. var templateItemTitle = new Element("div.templateItemTitle",{styles:this.css.templateItemTitle,text:data.title}).inject(templateItemContainer);
  249. templateItemContainer.addEvents({
  250. mouseover:function(){
  251. this.setStyles({"background-color":"rgb(242,245,247)"});
  252. },
  253. mouseout:function(){
  254. this.setStyles({"background-color":"#ffffff"});
  255. },
  256. click:function(){
  257. var res = {};
  258. res.id = data.id;
  259. res.title = data.title;
  260. this.close(res)
  261. }.bind(this)
  262. });
  263. }
  264. });