-
Notifications
You must be signed in to change notification settings - Fork 0
/
controllers.js
54 lines (41 loc) · 1.27 KB
/
controllers.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
;(function() {
"use strict";
angular.module('myApp.controllers', [
"myApp.services"
])
.controller('MyCtrl', ['$scope', '$interval', 'taskService', 'setDefaultValues', 'makeDate', function($scope, $interval ,taskService, setDefaultValues, makeDate){
//inception
var additionalTime = 600000; // 10 min in milliseconds
setDefaultValues($scope);
function addTask(e) {
var date, remaining, expire, id, obj, task;
if (!$scope.title || !$scope.date || !$scope.time) {
return false;
}
date = makeDate($scope.date, $scope.time);
if (date - new Date <= 0) {
return false;
}
remaining = new Date(date - new Date()).getTime(),
expire = date.getTime();
id = ( "" + Math.random() ).slice(2);
obj = {
title: $scope.title,
description: $scope.description,
remaining: remaining,
expire: expire,
id: id
};
task = new taskService.createTask(obj);
// set default scope values (e.g title, date, time)
setDefaultValues($scope);
}
function addTimeToTask(task) {
taskService.setExpireOfTask(task, additionalTime);
}
$scope.tasks = taskService.getTasks();
$scope.removeTask = taskService.removeTask;
$scope.addTask = addTask;
$scope.addTimeToTask = addTimeToTask;
}]);
})()