Ensure Bailey always displays the most recent message.

* Added a Grunt task to precompile website/views/shared/new-stuff.jade to a
  static html file.

* Updated the new-stuff.jade modal template to use a $rootScope property.

* Added a special case to openModal for the newStuff template, by which it
  fetches the flat file, marks it as trusted HTML, and sets it to the
  $rootScope property before rendering the modal.
This commit is contained in:
Kevin Gisi
2015-03-31 20:38:15 -04:00
parent edb50f7081
commit 79606736a1
4 changed files with 34 additions and 6 deletions

View File

@@ -3,8 +3,8 @@
/* Make user and settings available for everyone through root scope.
*/
habitrpg.controller("RootCtrl", ['$scope', '$rootScope', '$location', 'User', '$http', '$state', '$stateParams', 'Notification', 'Groups', 'Shared', 'Content', '$modal', '$timeout', 'ApiUrl', 'Payments',
function($scope, $rootScope, $location, User, $http, $state, $stateParams, Notification, Groups, Shared, Content, $modal, $timeout, ApiUrl, Payments) {
habitrpg.controller("RootCtrl", ['$scope', '$rootScope', '$location', 'User', '$http', '$state', '$stateParams', 'Notification', 'Groups', 'Shared', 'Content', '$modal', '$timeout', 'ApiUrl', 'Payments','$sce',
function($scope, $rootScope, $location, User, $http, $state, $stateParams, Notification, Groups, Shared, Content, $modal, $timeout, ApiUrl, Payments,$sce) {
var user = User.user;
var initSticky = _.once(function(){
@@ -105,11 +105,29 @@ habitrpg.controller("RootCtrl", ['$scope', '$rootScope', '$location', 'User', '$
$rootScope.set = User.set;
$rootScope.authenticated = User.authenticated;
var forceLoadBailey = function(template, options) {
$http.get('/new-stuff.html')
.success(function(data) {
$rootScope.latestBaileyMessage = $sce.trustAsHtml(data);
$modal.open({
templateUrl: 'modals/' + template + '.html',
controller: options.controller, // optional
scope: options.scope, // optional
resolve: options.resolve, // optional
keyboard: (options.keyboard === undefined ? true : options.keyboard), // optional
backdrop: (options.backdrop === undefined ? true : options.backdrop), // optional
size: options.size, // optional, 'sm' or 'lg'
windowClass: options.windowClass // optional
});
});
};
// Open a modal from a template expression (like ng-click,...)
// Otherwise use the proper $modal.open
$rootScope.openModal = function(template, options){//controller, scope, keyboard, backdrop){
if (!options) options = {};
if (options.track) window.ga && ga('send', 'event', 'button', 'click', options.track);
if(template === 'newStuff') return forceLoadBailey(template, options);
return $modal.open({
templateUrl: 'modals/' + template + '.html',
controller: options.controller, // optional