-
Notifications
You must be signed in to change notification settings - Fork 23
/
customList.directive.js
70 lines (63 loc) · 2.76 KB
/
customList.directive.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
(function() {
'use strict';
angular
.module('todoApp')
.directive('customList', directive);
function directive() {
return {
scope: {},
bindToController: {
items: '=',
selectedItem: '=',
filterFunction: '=',
},
controller: customListController,
controllerAs: 'customListCtrl',
transclude: true,
restrict: 'E',
template: '' +
' <md-content class="md-padding scroll tab-content">' +
' <md-list>' +
' <md-list-item class="md-2-line" ng-repeat="item in customListCtrl.items | filter: customListCtrl.filterFunction" ng-class="customListCtrl.selectedItem == item ? \'selected\':\'\'" ng-click="customListCtrl.toggleSelection(item)">'
+
' <md-button ng-click="customListCtrl.changePriority(item)" class="md-icon-button" aria-label="Priority">' +
' <md-icon style="color: green" ng-if="item.priority == -1">low_priority</md-icon>' +
' <md-icon ng-if="item.priority == 0">label</md-icon>' +
' <md-icon style="color: red" ng-if="item.priority == 1">priority_high</md-icon>' +
' </md-button>' +
' <div class="md-list-item-text">' +
' <h3>{{item.title}}</h3>' +
' <p> {{item.date | date: "dd-MM-yyyy HH:mm"}}</p>' +
' </div>' +
' <md-checkbox ng-model="item.done" ng-change="customListCtrl.checkStateChanged()" class="md-primary md-align-top-right">' +
' </md-checkbox>' +
' <md-divider></md-divider>' +
' </md-list-item>' +
' </md-list>' +
'</md-content>'
};
}
//Directive controller
function customListController(storageService) {
var vm = this;
//Changes the priority of the given item
vm.changePriority = function(item) {
if (item.priority <= 0)
item.priority++;
else
item.priority = -1;
storageService.set(vm.items);
}
//Occurs when the status of an items changes
vm.checkStateChanged = function() {
storageService.set(vm.items);
}
//Select or deselect the given item
vm.toggleSelection = function(item) {
if (vm.selectedItem == null || vm.selectedItem != item)
vm.selectedItem = item;
else
vm.selectedItem = null;
}
}
})();