diff --git a/public/js/app.js b/public/js/app.js index 516379a444..ae9b2b0bdd 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -115,18 +115,12 @@ window.habitrpg = angular.module('habitrpg', .state('options.challenges.detail', { url: '/:cid', templateUrl: 'partials/options.challenges.detail.html', -// resolve: { -// challenge: ['$scope', 'Challenges', '$stateParams', '$q', -// function($scope, Challenges, $stateParams, $q){ -// // FIXME does ui-router not work with ng-resource by default? -// var challenge = $q.defer(); -// Challenges.Challenge.get({cid:$stateParams.cid}, function(_challenge){ -// challenge._locked = true; -// challenge.resolve(_challenge); -// }); -// return challenge.promise; -// }] -// } + controller: ['$scope', 'Challenges', '$stateParams', + function($scope, Challenges, $stateParams){ + $scope.obj = $scope.challenge = Challenges.Challenge.get({cid:$stateParams.cid}, function(){ + $scope.challenge._locked = true; + }); + }] }) // Options > Settings diff --git a/public/js/controllers/challengesCtrl.js b/public/js/controllers/challengesCtrl.js index d6608ce581..c8989b1c35 100644 --- a/public/js/controllers/challengesCtrl.js +++ b/public/js/controllers/challengesCtrl.js @@ -73,11 +73,11 @@ habitrpg.controller("ChallengesCtrl", ['$scope', 'User', 'Challenges', 'Notifica // Tasks //------------------------------------------------------------ - $scope.addTask = function(list) { - var task = window.habitrpgShared.helpers.taskDefaults({text: list.newTask, type: list.type}, User.user.filters); - list.tasks.unshift(task); + $scope.addTask = function(addTo, listDef) { + var task = window.habitrpgShared.helpers.taskDefaults({text: listDef.newTask, type: listDef.type}); + addTo.unshift(task); //User.log({op: "addTask", data: task}); //TODO persist - delete list.newTask; + delete listDef.newTask; }; $scope.removeTask = function(list, $index) { diff --git a/public/js/controllers/tasksCtrl.js b/public/js/controllers/tasksCtrl.js index a4a72e8849..b3142b5a69 100644 --- a/public/js/controllers/tasksCtrl.js +++ b/public/js/controllers/tasksCtrl.js @@ -2,6 +2,8 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User', 'Algos', 'Helpers', 'Notification', '$http', 'API_URL', function($scope, $rootScope, $location, User, Algos, Helpers, Notification, $http, API_URL) { + $scope.obj = User.user; // used for task-lists + $scope.score = function(task, direction) { if (task.type === "reward" && User.user.stats.gp < task.value){ return Notification.text('Not enough GP.'); @@ -11,11 +13,11 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User', ' }; - $scope.addTask = function(list) { - var task = window.habitrpgShared.helpers.taskDefaults({text: list.newTask, type: list.type}, User.user.filters); - list.tasks.unshift(task); + $scope.addTask = function(addTo, listDef) { + var task = window.habitrpgShared.helpers.taskDefaults({text: listDef.newTask, type: listDef.type}, User.user.filters); + addTo.unshift(task); User.log({op: "addTask", data: task}); - delete list.newTask; + delete listDef.newTask; }; /** diff --git a/public/js/directives/directives.js b/public/js/directives/directives.js index b8618c7545..548ad9a213 100644 --- a/public/js/directives/directives.js +++ b/public/js/directives/directives.js @@ -29,15 +29,15 @@ habitrpg.directive('habitrpgAdsense', function() { }) habitrpg.directive('whenScrolled', function() { - return function(scope, elm, attr) { - var raw = elm[0]; - - elm.bind('scroll', function() { - if (raw.scrollTop + raw.offsetHeight >= raw.scrollHeight) { - scope.$apply(attr.whenScrolled); - } - }); - }; + return function(scope, elm, attr) { + var raw = elm[0]; + + elm.bind('scroll', function() { + if (raw.scrollTop + raw.offsetHeight >= raw.scrollHeight) { + scope.$apply(attr.whenScrolled); + } + }); + }; }); /** @@ -127,32 +127,28 @@ habitrpg }; }, link: function(scope, element, attrs) { - scope.obj = scope[attrs.obj]; + // $scope.obj needs to come from controllers, so we can pass by ref scope.main = attrs.main; - - scope.lists = [ + $rootScope.lists = [ { header: 'Habits', type: 'habit', - placeHolder: 'New Habit', - tasks: scope.obj.habits + placeHolder: 'New Habit' }, { header: 'Dailies', type: 'daily', - placeHolder: 'New Daily', - tasks: scope.obj.dailys + placeHolder: 'New Daily' }, { header: 'Todos', type: 'todo', - placeHolder: 'New Todo', - tasks: scope.obj.todos + placeHolder: 'New Todo' }, { header: 'Rewards', type: 'reward', - placeHolder: 'New Reward', - tasks: scope.obj.rewards + placeHolder: 'New Reward' } ]; + } } }]); diff --git a/views/options/challenges.jade b/views/options/challenges.jade index 5c56c6c6b5..3593abab3d 100644 --- a/views/options/challenges.jade +++ b/views/options/challenges.jade @@ -18,9 +18,9 @@ script(type='text/ng-template', id='partials/options.challenges.detail.html') div(ng-if='challenge.description') {{challenge.description}} habitrpg-tasks(obj='challenge', main=false) h3 Statistics - div(ng-repeat='member in challenge.members', ng-init='member._locked = true') + div(ng-repeat='member in challenge.members', ng-init='member._locked = true; obj=member') h4 {{member.profile.name}} - habitrpg-tasks(main=false, obj='member') + habitrpg-tasks(main=false) script(type='text/ng-template', id='partials/options.challenges.html') .row-fluid diff --git a/views/shared/tasks/lists.jade b/views/shared/tasks/lists.jade index daf81e96ed..bbb1675c6b 100644 --- a/views/shared/tasks/lists.jade +++ b/views/shared/tasks/lists.jade @@ -31,7 +31,7 @@ script(id='templates/habitrpg-tasks.html', type="text/ng-template") .todos-chart(ng-if='list.type == "todo"', ng-show='charts.todos') // Add New - form.addtask-form.form-inline.new-task-form(name='new{{list.type}}form', ng-hide='obj._locked || (list.showCompleted && list.type=="todo")', ng-submit='addTask(list)') + form.addtask-form.form-inline.new-task-form(name='new{{list.type}}form', ng-hide='obj._locked || (list.showCompleted && list.type=="todo")', ng-submit='addTask(obj[list.type+"s"],list)') span.addtask-field input(type='text', ng-model='list.newTask', placeholder='{{list.placeHolder}}', required) input.addtask-btn(type='submit', value='+', ng-disabled='new{{list.type}}form.$invalid') diff --git a/views/shared/tasks/task.jade b/views/shared/tasks/task.jade index 3961ab5700..c0c1c6557a 100644 --- a/views/shared/tasks/task.jade +++ b/views/shared/tasks/task.jade @@ -1,4 +1,4 @@ -li(ng-repeat='task in list.tasks', class='task {{taskClasses(task, user.filters, user.preferences.dayStart, user.lastCron, list.showCompleted, main)}}', data-id='{{task.id}}') +li(ng-repeat='task in obj[list.type+"s"]', class='task {{taskClasses(task, user.filters, user.preferences.dayStart, user.lastCron, list.showCompleted, main)}}', data-id='{{task.id}}') // right-hand side control buttons .task-meta-controls @@ -26,7 +26,7 @@ li(ng-repeat='task in list.tasks', class='task {{taskClasses(task, user.filters, span(ng-if='!task.challenge.broken') i.icon-bullhorn(tooltip="Challenge Task") // delete - a(ng-if='!task.challenge.id', ng-click='removeTask(list.tasks, $index)', tooltip='Delete') + a(ng-if='!task.challenge.id', ng-click='removeTask(obj[list.type+"s"], $index)', tooltip='Delete') i.icon-trash // chart