Skip to content

Commit

Permalink
adding deletion for todos
Browse files Browse the repository at this point in the history
  • Loading branch information
kensuka21 committed Jun 8, 2016
1 parent 07e0ce5 commit 8117d19
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 29 deletions.
1 change: 1 addition & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

<script src="app.js"></script>
<script src="app.state.js"></script>
<script src="utils.js"></script>

<script src="login/login.state.js"></script>
<script src="login/login.controller.js"></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,61 @@ angular.module('todoApp')
.directive('myTodoCreateModal', myTodoCreateModal)
.directive('myTodoCreateModalBtn', myTodoCreateModalBtn);

function myTodoCreateModal(){
function myTodoCreateModal() {
return {
scope : {
todoModalId : '@',
onSuccess : '&'
scope: {
todoModalId: '@',
onSuccess: '&'
},
templateUrl : 'sections/todo/directives/create/todo.create.modal.html',
controller : ['$scope', 'Todo', myTodoCreateModalController]
templateUrl: 'sections/todo/directives/create/todo.create.modal.html',
controller: ['$scope', 'Todo', 'Auth', myTodoCreateModalController]
}
}

function myTodoCreateModalBtn(){
function myTodoCreateModalBtn() {
return {
scope : {
todoModalId : '@',
classes : '@?'
scope: {
todoModalId: '@',
classes: '@?'
},
transclude : true,
templateUrl : 'sections/todo/directives/create/todo.create.modal.btn.html',
controller : ['$scope', myTodoCreateModalBtnController]
transclude: true,
templateUrl: 'sections/todo/directives/create/todo.create.modal.btn.html',
controller: ['$scope', myTodoCreateModalBtnController]
}
}

function myTodoCreateModalBtnController($scope){
function myTodoCreateModalBtnController($scope) {
$scope.openModal = openModal;

function openModal(){
function openModal() {
$('#' + $scope.todoModalId).openModal();
}
}

function myTodoCreateModalController($scope, Todo){
function myTodoCreateModalController($scope, Todo, Auth) {

$scope.create = create;

$scope.todo = {
name : ''
name: ''
};

function refreshTodo(){
function refreshTodo() {
$scope.todo.name = '';
}

function create(){
console.log($scope.todo)
Todo.save($scope.todo, function(data){
if($scope.onSuccess){
function create() {
var todo = $scope.todo;

Todo.save(todo, function (data) {
if ($scope.onSuccess) {
$scope.onSuccess(data);
}
refreshTodo();
Materialize.toast('The Task was created succesful !', 4000)
}, function(err){
Materialize.toast('There was an Error: ' + err, 4000);
});
}, handleError);
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function myTodoDetailModalController($scope, Todo) {
$scope.onSuccess();
}
Materialize.toast('The Task "' + doc.name + '" was updated succesful', 4000);
})
}, handleError);
}

function initMaterializeDesign() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function myTodoEditColorModaController($scope, Todo){
}
Materialize.toast('The Color was Updated for Task: ' + doc.name, 4000)
closeModal();
});
}, handleError);
}

function closeModal(){
Expand Down
7 changes: 7 additions & 0 deletions public/sections/todo/todo.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ function TodoController($scope, Todo) {
self.refreshList = refreshList;
self.openEditModal = openEditModal;
self.openDetailModal = openDetailModal;
self.deleteTodo = deleteTodo;

refreshList();

Expand All @@ -28,6 +29,12 @@ function TodoController($scope, Todo) {
self.todoToDetailId = todo._id;
}

function deleteTodo(todo) {
Todo.delete({id : todo._id}, function(){
Materialize.toast('Task deleted', 4000);
refreshList();
}, handleError);
}

}

Expand Down
1 change: 1 addition & 0 deletions public/sections/todo/todo.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ <h4><strong>TODO's List</strong></h4>
<a href="javascript:void(0);" style="background-color : {{todo.color}}; " class="material-icons tiny btn-floating" ng-click="ctrl.openEditModal(todo);"></a>
<strong> {{todo.name}}</strong>
<a href="javascript:void(0);" class="secondary-content padding-edit-button" ng-click="ctrl.openDetailModal(todo);"><i class="material-icons">edit</i></a>
<a href="javascript:void(0);" class="secondary-content padding-edit-button" ng-click="ctrl.deleteTodo(todo);"><i class="material-icons">delete</i></a>
</li>
</ul>

Expand Down
1 change: 0 additions & 1 deletion public/sections/todo/todo.state.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ function TodoStateConfig($stateProvider) {
parent : 'app',
templateUrl : 'sections/todo/todo.html',
controller : 'TodoController as ctrl'

});

}
3 changes: 3 additions & 0 deletions public/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function handleError(err) {
Materialize.toast('There was an Error: ' + err.data, 4000);
}

0 comments on commit 8117d19

Please sign in to comment.