This commit is contained in:
Max Lynch
2013-09-01 19:25:36 -05:00
parent 66979e11fe
commit 527e0d3f51
2 changed files with 110 additions and 23 deletions

View File

@ -1,33 +1,122 @@
angular.module('toderp', [])
.factory('TaskListService', function() {
.factory('TaskStorageService', function() {
return {
tasks: [
{ text: 'Do this thing', created: new Date() }
],
todaysTasks: [
{ text: 'Do this thing', created: new Date() }
],
addTask: function(task) {
this.tasks.push(task);
getTasks: function() {
var tasks = window.localStorage['tasks'];
try {
return JSON.parse(tasks);
} catch(e) {}
return [];
},
deleteTask: function($index) {
this.tasks.splice($index, 1);
addTask: function(task) {
var tasks = window.localStorage['tasks'] || "[]";
try {
var taskObj = JSON.parse(tasks);
taskObj && taskObj.push(task);
this.setTasks(taskObj);
} catch(e) {}
},
deleteTask: function(index) {
var tasks = window.localStorage['tasks'] || "[]";
try {
var taskObj = JSON.parse(tasks);
taskObj && taskObj.splice(index);
this.setTasks(taskObj);
} catch(e) {}
},
setTasks: function(tasks) {
window.localStorage.setItem('tasks', JSON.stringify(tasks));
}
}
};
})
.filter('todaysTasks', function() {
return function(value) {
return value.sort(function(a, b) {
if(a.priority > b.priority) return 1;
if(a.priority < b.priority) return -1;
return 0;
});
}
})
.factory('TaskListService', ['TaskStorageService', function(TaskStorageService) {
var tasks = Array.prototype.slice.call(TaskStorageService.getTasks());
return {
tasks: tasks,
todaysTasks: [ ],
addTask: function(task) {
this.tasks.push(task);
TaskStorageService.addTask(task);
return task;
},
deleteTask: function($index) {
var last = this.tasks.splice($index, 1);
TaskStorageService.deleteTask(task);
return last;
},
getTasks: function() {
return this.tasks;
}
};
}])
.controller('TodaysTaskListCtrl', ['$scope', 'TaskListService', function($scope, TaskListService) {
$scope.todaysTasks = TaskListService.todaysTasks;
//$scope.getTodaysTasks = TaskListService.getTodaysTasks;
$scope.tasks = TaskListService.tasks;
$scope.promptNewTask = function() {
var data = prompt('What do you need to do?')
TaskListService.addTask({
text: data
});
};
}])
.controller('TaskListCtrl', ['$scope', 'TaskListService', function($scope, TaskListService) {
$scope.tasks = TaskListService.tasks;
}])
.controller('TasksCtrl', ['$scope', function($scope) {
}]);
var ListViewController = function(options) {
var _this = this;
this.list = options.list;
window.ion.onGesture('release', function(e) {
_this._endDrag(e);
}, this.list);
window.ion.onGesture('swiperight', function(e) {
_this._handleSwipeRight(e);
}, this.list);
window.ion.onGesture('drag', function(e) {
_this._handleDrag(e);
}, this.list);
};
ListViewController.prototype = {
_endDrag: function(e) {
},
_handleDrag: function(e) {
},
_handleSwipeRight: function(e) {
console.log('SWIPRIGHT', e);
}
};
var list = document.getElementById('tasks');
var listViewController = new ListViewController({
list: list
});
var page = document.getElementById('page');
var leftPanel = document.getElementById('tasks-menu');

View File

@ -18,7 +18,7 @@
</head>
<body ng-app="toderp">
<div id="page" class="page">
<div id="page" class="page" ng-controller="TodaysTaskListCtrl">
<div class="bar bar-header bar-dark">
<div class="buttons">
<a id="menu-button" class="button button-dark" href="#">
@ -27,30 +27,28 @@
</div>
<h1 class="title">Today's Tasks</h1>
<div class="buttons">
<button id="right-button" class="button button-dark">
<button id="right-button" class="button button-dark" ng-click="promptNewTask()">
<i class="icon-plus"></i>
</button>
</div>
</div>
<div class="content has-header">
<ul class="list todays-tasks" ng-controller="TodaysTaskListCtrl">
<li class="list-item" ng-repeat="task in todaysTasks">
{{task.text}}
<ul class="list todays-tasks">
<li class="list-item" ng-repeat="task in tasks | todaysTasks">
<input type="checkbox" ng-model="task.isDone"> {{task.text}}
</li>
</ul>
</div>
</div>
<div id="tasks-menu" class="menu menu-left" ng-controller="TaskListCtrl">
<ul class="list">
<ul id="tasks" class="list">
<li class="list-divider">Tasks</li>
<li class="list-item" ng-repeat="task in tasks">
<a href="#">{{task.text}}</a>
</li>
</ul>
</div>
<div class="menu menu-right">
</div>
<script src="app.js"></script>
</body>
</html>