Skip to content

Commit 96f35fe

Browse files
committed
Fixes to update note feature
1 parent 379e6f9 commit 96f35fe

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

public/controllers/dashboard-controller.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
notes.controller('dashboardCtrl', function dashboardCtrl($scope, $window, $http) {
22

3-
$scope.updateNote = false;
3+
$scope.editNote = false;
44
$scope.createNote = true;
55
$http.post('/getNote', {"email": sessionStorage.user_email})
66
.success(function(data) {
@@ -38,7 +38,7 @@ notes.controller('dashboardCtrl', function dashboardCtrl($scope, $window, $http)
3838
html += '<a class="col-md-2" id="deleteNote" ng-click="deleteNote('+data._id+')">Delete</a>';
3939
html += '</div>';
4040
html += '<h1>'+$scope.noteHeading+'</h1>';
41-
html += '<div class="col-md-12">'+$scope.note+'</div>';
41+
html += '<div class="col-md-12" id="noteBody">'+$scope.note+'</div>';
4242
angular.element('#notes').append(html);
4343
$scope.name = data.firstname + data.lastname;
4444
$('#myModal').modal('hide');
@@ -61,7 +61,7 @@ notes.controller('dashboardCtrl', function dashboardCtrl($scope, $window, $http)
6161
}
6262

6363
$scope.getNoteById = function(noteId) {
64-
$scope.updateNote = true;
64+
$scope.editNote = true;
6565
$scope.createNote = false;
6666
$http.post('/getNoteById', {"noteId": noteId})
6767
.success(function(data) {
@@ -79,14 +79,15 @@ notes.controller('dashboardCtrl', function dashboardCtrl($scope, $window, $http)
7979
$http.post('/updateNote', {"noteId": $scope.noteId, "noteTitle": $scope.noteHeading,"noteBody": $scope.note})
8080
.success(function(data) {
8181
$('#myModal').modal('hide');
82-
$scope.updateNote = true;
82+
angular.element('#'+$scope.noteId).children('h1').html($scope.noteHeading);
83+
angular.element('#'+$scope.noteId).children('#noteBody').html($scope.note);
84+
$scope.editNote = true;
8385
$scope.createNote = false;
8486
})
8587
.error(function(data) {
8688
alert("Cannot be updated");
87-
$scope.updateNote = true;
89+
$scope.editNote = true;
8890
$scope.createNote = false;
8991
});
9092
}
91-
9293
});

public/views/dashboard.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ <h2 style="color: #fff">Welcome <span ng-bind="name.firstname"></span>!</h2>
3131
<div class="panel-body" id="notes">
3232
<div class="col-md-3 currentNote" id={{note._id}} ng-repeat="note in notes">
3333
<div class="row">
34-
<a class="col-md-2" id="editNotedeleteNote" ng-click="getNoteById(note._id)" data-target="#pModal">Edit</a>
34+
<a class="col-md-2" id="editNotedeleteNote" ng-click="getNoteById(note._id)" data-target="#myModal">Edit</a>
3535
<a class="col-md-2" id="deleteNote" ng-click="deleteNote(note._id)">Delete</a>
3636
</div>
3737
<h1>{{note.noteTitle}}</h1>
38-
<div class="col-md-12">{{note.noteBody}}</div>
38+
<div class="col-md-12" id="noteBody">{{note.noteBody}}</div>
3939
</div>
4040
</div>
4141
</div>
@@ -56,7 +56,7 @@ <h4 class="modal-title">Create a new note</h4>
5656
</form>
5757
</div>
5858
<div class="modal-footer">
59-
<button type="button" class="btn btn-primary" ng-show="updateNote" ng-click="updateNote()">Update</button>
59+
<button type="button" class="btn btn-primary" ng-show="editNote" ng-click="updateNote()">Update</button>
6060
<button type="button" class="btn btn-primary" ng-show="createNote" ng-click="createNote()">Create</button>
6161
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
6262
</div>

0 commit comments

Comments
 (0)