rewrite2: convert rootCtrl to js, add $rootScope.set() method.

This commit is contained in:
Tyler Renelle 2013-08-27 19:59:53 -04:00
parent 893febf4d8
commit aedb90176d
2 changed files with 33 additions and 15 deletions

View file

@ -1,15 +0,0 @@
"use strict"
# Make user and settings available for everyone through root scope.
habitrpg.controller "RootCtrl", ($scope, $rootScope, $location, User) ->
$rootScope.modals = {}
$rootScope.User = User
$rootScope.user = User.user
$rootScope.settings = User.settings
# FIXME this is dangerous, organize helpers.coffee better, so we can group them by which controller needs them,
# and then simply _.defaults($scope, Helpers.user) kinda thing
_.defaults $rootScope, window.habitrpgShared.algos
_.defaults $rootScope, window.habitrpgShared.helpers
$rootScope.authenticated = ->
User.settings.auth.apiId isnt ""

View file

@ -0,0 +1,33 @@
"use strict";
/* Make user and settings available for everyone through root scope.
*/
habitrpg.controller("RootCtrl", function($scope, $rootScope, $location, User) {
$rootScope.modals = {};
$rootScope.User = User;
$rootScope.user = User.user;
$rootScope.settings = User.settings;
/*
FIXME this is dangerous, organize helpers.coffee better, so we can group them by which controller needs them,
and then simply _.defaults($scope, Helpers.user) kinda thing
*/
_.defaults($rootScope, window.habitrpgShared.algos);
_.defaults($rootScope, window.habitrpgShared.helpers);
/*
Very simple path-set. `set('preferences.gender','m')` for example. We'll deprecate this once we have a complete API
*/
$rootScope.set = function(k, v) {
var log = { op: 'set' };
window.helpers.dotSet(k, v, User.user);
log[k] = v;
User.log(log);
};
$rootScope.authenticated = function() {
User.settings.auth.apiId !== "";
};
});