From eaa770561f33484089124d7dc41dbbfcc4e815d5 Mon Sep 17 00:00:00 2001 From: ksamykandil Date: Thu, 4 Sep 2014 04:28:59 +0300 Subject: [PATCH] Option to edit/delete a project #4 Project name/description took the previous created project values #48 Project description is not saved #49 --- .../resources/static/js/models/project.js | 2 +- .../resources/static/js/views/app-view.js | 12 ++++++++ .../static/js/views/main-menu-view.js | 26 +++++++++++++++-- .../resources/static/js/views/project-view.js | 3 +- .../resources/static/js/views/tree-view.js | 29 +++++++------------ src/main/webapp/WEB-INF/jsp/home.jsp | 20 +++++++++++++ 6 files changed, 68 insertions(+), 24 deletions(-) diff --git a/src/main/resources/static/js/models/project.js b/src/main/resources/static/js/models/project.js index e565754..5415f4f 100644 --- a/src/main/resources/static/js/models/project.js +++ b/src/main/resources/static/js/models/project.js @@ -14,7 +14,7 @@ define(function(require) { description : '' }, sync : function(method, model, options){ - if(method == 'create'){ + if(method == 'create' || method == 'update'){ model.urlRoot = APP.config.baseUrl + "/workspaces/" + APP.appView.getCurrentWorkspaceId() + "/projects"; model.unset('projectRef'); return Backbone.sync(method, model, options); diff --git a/src/main/resources/static/js/views/app-view.js b/src/main/resources/static/js/views/app-view.js index b67d14d..cf22916 100644 --- a/src/main/resources/static/js/views/app-view.js +++ b/src/main/resources/static/js/views/app-view.js @@ -46,6 +46,18 @@ define(function(require) { }, handleProjectChange : function(id){ console.log('project changed :'+ id); + + $.ajax({ + url : APP.config.baseUrl + '/workspaces/' + this.workspaceId + '/projects/' + id, + type : 'get', + dataType : 'json', + contentType : "application/json", + success : function(project) { + $("#editProjectTextField").val(project.name); + $("#editProjectTextArea").val(project.description); + } + }); + this.projectId = id; }, handleConversationChange : function(id){ diff --git a/src/main/resources/static/js/views/main-menu-view.js b/src/main/resources/static/js/views/main-menu-view.js index 06aba8b..7792c18 100644 --- a/src/main/resources/static/js/views/main-menu-view.js +++ b/src/main/resources/static/js/views/main-menu-view.js @@ -9,20 +9,40 @@ define(function(require) { $("#saveProjectBtn").unbind("click").bind("click", function(){ var project = new ProjectModel({ - name : $("#projectTextField").val() + name : $("#projectTextField").val(), + description: $("#projectTextArea").val() }); project.save(null, { success : function(response) { var projectView = new ProjectView(); projectView.addOne(project); - $('#projectModal').modal("hide"); + $('#projectModal').modal("hide"); + $("#projectTextField").val(""); + $("#projectTextArea").val(""); + }, + error : function(e) { + alert('Some unexpected error occured Please try later.'); + } + }); + }); + + $("#editProjectBtn").unbind("click").bind("click", function(){ + var project = new ProjectModel({ + id: APP.appView.getCurrentProjectId(), + name: $("#editProjectTextField").val(), + description: $("#editProjectTextArea").val() + }); + project.save(null, { + success : function(response) { + $("#editProjectTextField").val(""); + $("#editProjectTextArea").val(""); + location.reload(); }, error : function(e) { alert('Some unexpected error occured Please try later.'); } }); }); - $("#saveWorkspaceBtn").bind("click", saveWorkspace); diff --git a/src/main/resources/static/js/views/project-view.js b/src/main/resources/static/js/views/project-view.js index e698c9c..f669efa 100644 --- a/src/main/resources/static/js/views/project-view.js +++ b/src/main/resources/static/js/views/project-view.js @@ -26,8 +26,8 @@ define(function(require) { } },this); } - }); + var ProjectListView = Backbone.View.extend({ tagName : 'li', events : { @@ -49,7 +49,6 @@ define(function(require) { console.log('current project id is ' + APP.appView.getCurrentProjectId()); tree.showTree(this.$el.find('a').data('project-ref-id')); }, - render : function() { this.$el.html(this.template({project : this.model.toJSON()})); return this; diff --git a/src/main/resources/static/js/views/tree-view.js b/src/main/resources/static/js/views/tree-view.js index 7b2ef87..950a3fd 100644 --- a/src/main/resources/static/js/views/tree-view.js +++ b/src/main/resources/static/js/views/tree-view.js @@ -100,23 +100,15 @@ define(function(require) { }); $("#deleteProjectBtn").bind("click", function() { - -// $("#deleteProjectModal").modal("hide"); - location.reload(); - alert(node); - -// alert(node); -// alert(node.data.id); -// -// $.ajax({ -// url : APP.config.baseUrl + '/nodes/' + APP.appView.getCurrentProjectId(), -// type : 'delete', -// dataType : 'json', -// contentType : "application/json", -// success : function(data) { -//// node.remove(); -// } -// }); + $.ajax({ + url : APP.config.baseUrl + '/workspaces/' + APP.appView.getCurrentWorkspaceId() + "/projects/" + APP.appView.getCurrentProjectId(), + type : 'delete', + dataType : 'json', + contentType : "application/json", + success : function(data) { + location.reload(); + } + }); }); $('.col-1-toggle-btn').toggle(function() { @@ -349,6 +341,7 @@ define(function(require) { return null; } }; + tree.showTree = function(projectRefNodeId) { $.ajax({ url : APP.config.baseUrl + '/nodes/' + projectRefNodeId + '/tree', @@ -368,6 +361,6 @@ define(function(require) { } }); }; - + return tree; }); \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/jsp/home.jsp b/src/main/webapp/WEB-INF/jsp/home.jsp index c652314..1a5ce5e 100644 --- a/src/main/webapp/WEB-INF/jsp/home.jsp +++ b/src/main/webapp/WEB-INF/jsp/home.jsp @@ -158,6 +158,7 @@
  • Delete Project
  • Delete Request
  • +
  • Edit Project
  • @@ -436,6 +437,25 @@ +