diff --git a/example/toderp/app.js b/example/toderp/app.js index 33013fd112..c7235eed93 100644 --- a/example/toderp/app.js +++ b/example/toderp/app.js @@ -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'); diff --git a/example/toderp/index.html b/example/toderp/index.html index d3d2fc6046..b068752750 100644 --- a/example/toderp/index.html +++ b/example/toderp/index.html @@ -18,7 +18,7 @@
-