Skip to content

Commit

Permalink
Option to edit/delete a project #4
Browse files Browse the repository at this point in the history
Project name/description took the previous created project values #48
Project description is not saved #49
  • Loading branch information
ksamykandil committed Sep 4, 2014
1 parent 79e0336 commit eaa7705
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/main/resources/static/js/models/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 12 additions & 0 deletions src/main/resources/static/js/views/app-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
26 changes: 23 additions & 3 deletions src/main/resources/static/js/views/main-menu-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 1 addition & 2 deletions src/main/resources/static/js/views/project-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ define(function(require) {
}
},this);
}

});

var ProjectListView = Backbone.View.extend({
tagName : 'li',
events : {
Expand All @@ -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;
Expand Down
29 changes: 11 additions & 18 deletions src/main/resources/static/js/views/tree-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -349,6 +341,7 @@ define(function(require) {
return null;
}
};

tree.showTree = function(projectRefNodeId) {
$.ajax({
url : APP.config.baseUrl + '/nodes/' + projectRefNodeId + '/tree',
Expand All @@ -368,6 +361,6 @@ define(function(require) {
}
});
};

return tree;
});
20 changes: 20 additions & 0 deletions src/main/webapp/WEB-INF/jsp/home.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
<li class="divider"></li>
<li><a style="font-size: 12px;" data-toggle="modal" data-target="#deleteProjectModal">Delete Project</a></li>
<li><a style="font-size: 12px;" data-toggle="modal" data-target="#deleteRequestModal">Delete Request</a></li>
<li><a style="font-size: 12px;" data-toggle="modal" data-target="#editProjectModal">Edit Project</a></li>
</ul>
</div>

Expand Down Expand Up @@ -436,6 +437,25 @@
</div>
</div>
</div>
<div class="modal fade" id="editProjectModal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title" id="editProjectModalLabel">Edit Project</h4>
</div>
<div class="modal-body">
<input type="text" id="editProjectTextField" class="form-control" placeholder="Enter Project Name"> <br>
<textarea id="editProjectTextArea" class="form-control" rows="3" placeholder="Enter Description"></textarea>
<br>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button id="editProjectBtn" type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="switchWorkspaceModal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
Expand Down

0 comments on commit eaa7705

Please sign in to comment.