challenges: back to dealing with taskLists from scopes, rather than the

habitrpg-tasks directive. Was having trouble accessing it by reference
otherwise. Would love to move off of the directive entirely and use
ng-include instead, but some scope issues with lists
This commit is contained in:
Tyler Renelle
2013-10-29 19:07:39 -07:00
parent 02ebc536ca
commit 6e71a76e22
7 changed files with 37 additions and 45 deletions

View File

@@ -115,18 +115,12 @@ window.habitrpg = angular.module('habitrpg',
.state('options.challenges.detail', { .state('options.challenges.detail', {
url: '/:cid', url: '/:cid',
templateUrl: 'partials/options.challenges.detail.html', templateUrl: 'partials/options.challenges.detail.html',
// resolve: { controller: ['$scope', 'Challenges', '$stateParams',
// challenge: ['$scope', 'Challenges', '$stateParams', '$q', function($scope, Challenges, $stateParams){
// function($scope, Challenges, $stateParams, $q){ $scope.obj = $scope.challenge = Challenges.Challenge.get({cid:$stateParams.cid}, function(){
// // FIXME does ui-router not work with ng-resource by default? $scope.challenge._locked = true;
// var challenge = $q.defer(); });
// Challenges.Challenge.get({cid:$stateParams.cid}, function(_challenge){ }]
// challenge._locked = true;
// challenge.resolve(_challenge);
// });
// return challenge.promise;
// }]
// }
}) })
// Options > Settings // Options > Settings

View File

@@ -73,11 +73,11 @@ habitrpg.controller("ChallengesCtrl", ['$scope', 'User', 'Challenges', 'Notifica
// Tasks // Tasks
//------------------------------------------------------------ //------------------------------------------------------------
$scope.addTask = function(list) { $scope.addTask = function(addTo, listDef) {
var task = window.habitrpgShared.helpers.taskDefaults({text: list.newTask, type: list.type}, User.user.filters); var task = window.habitrpgShared.helpers.taskDefaults({text: listDef.newTask, type: listDef.type});
list.tasks.unshift(task); addTo.unshift(task);
//User.log({op: "addTask", data: task}); //TODO persist //User.log({op: "addTask", data: task}); //TODO persist
delete list.newTask; delete listDef.newTask;
}; };
$scope.removeTask = function(list, $index) { $scope.removeTask = function(list, $index) {

View File

@@ -2,6 +2,8 @@
habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User', 'Algos', 'Helpers', 'Notification', '$http', 'API_URL', habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User', 'Algos', 'Helpers', 'Notification', '$http', 'API_URL',
function($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) { $scope.score = function(task, direction) {
if (task.type === "reward" && User.user.stats.gp < task.value){ if (task.type === "reward" && User.user.stats.gp < task.value){
return Notification.text('Not enough GP.'); return Notification.text('Not enough GP.');
@@ -11,11 +13,11 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User', '
}; };
$scope.addTask = function(list) { $scope.addTask = function(addTo, listDef) {
var task = window.habitrpgShared.helpers.taskDefaults({text: list.newTask, type: list.type}, User.user.filters); var task = window.habitrpgShared.helpers.taskDefaults({text: listDef.newTask, type: listDef.type}, User.user.filters);
list.tasks.unshift(task); addTo.unshift(task);
User.log({op: "addTask", data: task}); User.log({op: "addTask", data: task});
delete list.newTask; delete listDef.newTask;
}; };
/** /**

View File

@@ -127,32 +127,28 @@ habitrpg
}; };
}, },
link: function(scope, element, attrs) { 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.main = attrs.main;
$rootScope.lists = [
scope.lists = [
{ {
header: 'Habits', header: 'Habits',
type: 'habit', type: 'habit',
placeHolder: 'New Habit', placeHolder: 'New Habit'
tasks: scope.obj.habits
}, { }, {
header: 'Dailies', header: 'Dailies',
type: 'daily', type: 'daily',
placeHolder: 'New Daily', placeHolder: 'New Daily'
tasks: scope.obj.dailys
}, { }, {
header: 'Todos', header: 'Todos',
type: 'todo', type: 'todo',
placeHolder: 'New Todo', placeHolder: 'New Todo'
tasks: scope.obj.todos
}, { }, {
header: 'Rewards', header: 'Rewards',
type: 'reward', type: 'reward',
placeHolder: 'New Reward', placeHolder: 'New Reward'
tasks: scope.obj.rewards
} }
]; ];
} }
} }
}]); }]);

View File

@@ -18,9 +18,9 @@ script(type='text/ng-template', id='partials/options.challenges.detail.html')
div(ng-if='challenge.description') {{challenge.description}} div(ng-if='challenge.description') {{challenge.description}}
habitrpg-tasks(obj='challenge', main=false) habitrpg-tasks(obj='challenge', main=false)
h3 Statistics 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}} h4 {{member.profile.name}}
habitrpg-tasks(main=false, obj='member') habitrpg-tasks(main=false)
script(type='text/ng-template', id='partials/options.challenges.html') script(type='text/ng-template', id='partials/options.challenges.html')
.row-fluid .row-fluid

View File

@@ -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') .todos-chart(ng-if='list.type == "todo"', ng-show='charts.todos')
// Add New // 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 span.addtask-field
input(type='text', ng-model='list.newTask', placeholder='{{list.placeHolder}}', required) input(type='text', ng-model='list.newTask', placeholder='{{list.placeHolder}}', required)
input.addtask-btn(type='submit', value='', ng-disabled='new{{list.type}}form.$invalid') input.addtask-btn(type='submit', value='', ng-disabled='new{{list.type}}form.$invalid')

View File

@@ -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 // right-hand side control buttons
.task-meta-controls .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') span(ng-if='!task.challenge.broken')
i.icon-bullhorn(tooltip="Challenge Task") i.icon-bullhorn(tooltip="Challenge Task")
// delete // 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 i.icon-trash
// chart // chart