-
Notifications
You must be signed in to change notification settings - Fork 23
/
script.js
82 lines (64 loc) · 2.33 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
(function(angular) {
'use strict';
var module = angular.module('todoApp', ['ngMaterial']);
angular.module('todoApp').controller('TodoController', TodoController);
//This is the application controller
function TodoController(storageService, $mdDialog) {
var vm = this;
vm.selectedItem = null;
vm.items = storageService.get() || [];
vm.notDone = function(item) {
return item.done == false;
}
vm.done = function(item) {
return item.done == true;
}
vm.all = function(item) {
return true;
}
//Delete the current selected item, if any
vm.deleteItem = function(ev) {
if (vm.selectedItem != null) {
var confirm = $mdDialog.confirm()
.textContent('The task "' + vm.selectedItem.title + '" will be deleted. Are you sure?')
.ariaLabel('Delete task')
.targetEvent(ev)
.ok('Yes')
.cancel('No');
$mdDialog.show(confirm).then(function(result) {
if (result) {
var index = vm.items.indexOf(vm.selectedItem);
if (index != -1) {
vm.items.splice(index, 1);
storageService.set(vm.items);
}
}
});
}
}
//Creates a new item with the given parameters
vm.createItem = function(title, priority, done, date) {
vm.items.push({
title: title,
done: done || false,
priority: priority || 0,
date: date || Date.now()
});
storageService.set(vm.items);
}
//Add a new task to the items list
vm.addTask = function(ev) {
var confirm = $mdDialog.prompt()
.title('Add new task')
.placeholder('Your task title...')
.ariaLabel('Your task title...')
.targetEvent(ev)
.ok('Add')
.cancel('Cancel');
$mdDialog.show(confirm).then(function(result) {
if (result)
vm.createItem(result);
});
};
}
})(window.angular);