mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-07-22 05:44:16 +00:00
rewrite2: convert rootCtrl to js, add $rootScope.set() method.
This commit is contained in:
parent
893febf4d8
commit
aedb90176d
2 changed files with 33 additions and 15 deletions
|
|
@ -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 ""
|
||||
33
assets/js/controllers/rootCtrl.js
Normal file
33
assets/js/controllers/rootCtrl.js
Normal 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 !== "";
|
||||
};
|
||||
|
||||
});
|
||||
Loading…
Reference in a new issue