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', []) angular.module('toderp', [])
.factory('TaskListService', function() { .factory('TaskStorageService', function() {
return { return {
tasks: [ getTasks: function() {
{ text: 'Do this thing', created: new Date() } var tasks = window.localStorage['tasks'];
], try {
todaysTasks: [ return JSON.parse(tasks);
{ text: 'Do this thing', created: new Date() } } catch(e) {}
], return [];
addTask: function(task) {
this.tasks.push(task);
}, },
deleteTask: function($index) { addTask: function(task) {
this.tasks.splice($index, 1); 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) { .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) { .controller('TaskListCtrl', ['$scope', 'TaskListService', function($scope, TaskListService) {
$scope.tasks = TaskListService.tasks; $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 page = document.getElementById('page');
var leftPanel = document.getElementById('tasks-menu'); var leftPanel = document.getElementById('tasks-menu');

View File

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