diff --git a/public/js/controllers/authCtrl.js b/public/js/controllers/authCtrl.js index 1312b40d35..9c65ee3541 100644 --- a/public/js/controllers/authCtrl.js +++ b/public/js/controllers/authCtrl.js @@ -5,8 +5,8 @@ */ angular.module('authCtrl', []) - .controller("AuthCtrl", ['$scope', '$rootScope', 'User', '$http', '$location', '$window','API_URL', '$modal', - function($scope, $rootScope, User, $http, $location, $window, API_URL, $modal) { + .controller("AuthCtrl", ['$scope', '$rootScope', 'User', '$http', '$location', '$window','API_URL', + function($scope, $rootScope, User, $http, $location, $window, API_URL) { var runAuth; var showedFacebookMessage; @@ -71,10 +71,8 @@ angular.module('authCtrl', []) if (User.authenticated()) { window.location.href = '/#/tasks'; } else { - $modal.open({ - templateUrl: 'modals/login.html' - // Using controller: 'AuthCtrl' it causes problems - }); + // Using controller: 'AuthCtrl' it causes problems + $rootScope.openModal('login'); } } diff --git a/public/js/controllers/groupsCtrl.js b/public/js/controllers/groupsCtrl.js index d1f97a8a08..c3910a9030 100644 --- a/public/js/controllers/groupsCtrl.js +++ b/public/js/controllers/groupsCtrl.js @@ -1,7 +1,7 @@ "use strict"; -habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Shared', 'Groups', '$http', 'API_URL', '$q', 'User', 'Members', '$state', '$modal', - function($scope, $rootScope, Shared, Groups, $http, API_URL, $q, User, Members, $state, $modal) { +habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Shared', 'Groups', '$http', 'API_URL', '$q', 'User', 'Members', '$state', + function($scope, $rootScope, Shared, Groups, $http, API_URL, $q, User, Members, $state) { $scope.isMember = function(user, group){ return ~(group.members.indexOf(user._id)); @@ -29,10 +29,7 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Shared', 'Groups', ' // We need the member information up top here, but then we pass it down to the modal controller // down below. Better way of handling this? Members.selectMember(uid); - $modal.open({ - templateUrl: 'modals/member.html', - controller: 'MemberModalCtrl' - }); + $rootScope.openModal('member', 'MemberModalCtrl'); } } diff --git a/public/js/controllers/inventoryCtrl.js b/public/js/controllers/inventoryCtrl.js index 4710b3a9c7..96f81644aa 100644 --- a/public/js/controllers/inventoryCtrl.js +++ b/public/js/controllers/inventoryCtrl.js @@ -1,5 +1,5 @@ -habitrpg.controller("InventoryCtrl", ['$rootScope', '$scope', '$window', 'User', 'Content', '$modal', - function($rootScope, $scope, $window, User, Content, $modal) { +habitrpg.controller("InventoryCtrl", ['$rootScope', '$scope', '$window', 'User', 'Content', + function($rootScope, $scope, $window, User, Content) { var user = User.user; @@ -127,10 +127,7 @@ habitrpg.controller("InventoryCtrl", ['$rootScope', '$scope', '$window', 'User', if (item.lvl && item.lvl > user.stats.lvl) return alert("You must be level " + item.lvl + '.'); $rootScope.selectedQuest = item; - $modal.open({ - templateUrl: 'modals/showQuest.html', - controller: 'InventoryCtrl' - }); + $rootScope.openModal('showQuest', 'InventoryCtrl'); } $scope.closeQuest = function(){ $rootScope.selectedQuest = undefined; @@ -149,10 +146,7 @@ habitrpg.controller("InventoryCtrl", ['$rootScope', '$scope', '$window', 'User', if (!completedPrevious) return $scope.purchase("quests", item); $rootScope.selectedQuest = item; - $modal.open({ - templateUrl: 'modals/buyQuest.html', - controller: 'InventoryCtrl' - }); + $rootScope.openModal('showQuest', 'buyQuest'); } } ]); diff --git a/public/js/controllers/notificationCtrl.js b/public/js/controllers/notificationCtrl.js index a8f4ece386..d72a11546f 100644 --- a/public/js/controllers/notificationCtrl.js +++ b/public/js/controllers/notificationCtrl.js @@ -1,16 +1,12 @@ 'use strict'; habitrpg.controller('NotificationCtrl', - ['$scope', '$rootScope', 'Shared', 'User', 'Guide', 'Notification', '$modal', - function ($scope, $rootScope, Shared, User, Guide, Notification, $modal) { + ['$scope', '$rootScope', 'Shared', 'User', 'Guide', 'Notification', + function ($scope, $rootScope, Shared, User, Guide, Notification) { $rootScope.$watch('user.stats.hp', function(after, before) { if (after <= 0){ - $modal.open({ - templateUrl: 'modals/death.html', - keyboard: false, - backdrop: 'static' - }); + $rootScope.openModal('death', undefined, undefined, false, 'static'); } if (after == before) return; if (User.user.stats.lvl == 0) return; @@ -69,39 +65,29 @@ habitrpg.controller('NotificationCtrl', $rootScope.$watch('user.achievements.streak', function(after, before){ if(before == undefined || after == before || after < before) return; - $modal.open({ - templateUrl: 'modals/achievements/streak.html' - }); + $rootScope.openModal('achievements/streak'); }); $rootScope.$watch('user.achievements.ultimateGear', function(after, before){ if (after === before || after !== true) return; - $modal.open({ - templateUrl: 'modals/achievements/ultimateGear.html' - }); + $rootScope.openModal('achievements/ultimateGear'); }); $rootScope.$watch('user.items.pets', function(after, before){ if(_.size(after) === _.size(before) || Shared.countPets(null, after) < 90) return; User.user.achievements.beastMaster = true; - $modal.open({ - templateUrl: 'modals/achievements/beastMaster.html' - }); + $rootScope.openModal('achievements/beastMaster'); }, true); $rootScope.$watch('user.achievements.rebirths', function(after, before){ if(after === before) return; - $modal.open({ - templateUrl: 'modals/achievements/rebirth.html' - }); + $rootScope.openModal('achievements/rebirth'); }); $rootScope.$watch('user.flags.contributor', function(after, before){ if (after === before || after !== true) return; - $modal.open({ - templateUrl: 'modals/achievements/contributor.html' - }); + $rootScope.openModal('achievements/contributor'); }); /*_.each(['weapon', 'head', 'chest', 'shield'], function(watched){ @@ -119,10 +105,7 @@ habitrpg.controller('NotificationCtrl', // Classes modal $rootScope.$watch('!user.flags.classSelected && user.stats.lvl >= 10', function(after, before){ if(after){ - $modal.open({ - templateUrl: 'modals/chooseClass.html', - controller: 'UserCtrl' - }); + $rootScope.openModal('chooseClass', 'UserCtrl'); } }); @@ -136,25 +119,18 @@ habitrpg.controller('NotificationCtrl', // Math updates modal $rootScope.$watch('!user.flags.mathUpdates', function(after, before){ if (after == before || after != true) return; - $modal.open({ - templateUrl: 'modals/mathUpdates.html' - }); + $rootScope.openModal('mathUpdates'); }); // Completed quest modal $rootScope.$watch('user.party.quest.completed', function(after, before){ if (after == before || after != true) return; - $modal.open({ - templateUrl: 'modals/questCompleted.html', - controller: 'InventoryCtrl' - }); + $rootScope.openModal('questCompleted', 'InventoryCtrl'); }); $rootScope.$watch('party.quest.key && !party.quest.active && !questHold && party.quest.members[user._id] == undefined', function(after, before){ if (after == before || after != true) return; - $modal.open({ - templateUrl: 'modals/questInvitation.html' - }); + $rootScope.openModal('questInvitation'); }); $rootScope.$on('responseError', function(ev, error){ diff --git a/public/js/controllers/rootCtrl.js b/public/js/controllers/rootCtrl.js index 35e001a95e..7cdc782ea1 100644 --- a/public/js/controllers/rootCtrl.js +++ b/public/js/controllers/rootCtrl.js @@ -66,11 +66,13 @@ habitrpg.controller("RootCtrl", ['$scope', '$rootScope', '$location', 'User', '$ // Open a modal from a template expression (like ng-click,...) // Otherwise use the proper $modal.open - $rootScope.openModal = function(template, controller, scope){ + $rootScope.openModal = function(template, controller, scope, keyboard, backdrop){ return $modal.open({ templateUrl: 'modals/' + template + '.html', controller: controller, // optional - scope: scope // optional + scope: scope, // optional + keyboard: keyboard, // optional + backdrop: backdrop // optional }); } diff --git a/public/js/services/guideServices.js b/public/js/services/guideServices.js index 1f860e6fa9..c512c72e23 100644 --- a/public/js/services/guideServices.js +++ b/public/js/services/guideServices.js @@ -5,7 +5,7 @@ */ angular.module('guideServices', []). - factory('Guide', ['$rootScope', 'User', '$timeout', '$modal', function($rootScope, User, $timeout, $modal) { + factory('Guide', ['$rootScope', 'User', '$timeout', function($rootScope, User, $timeout) { /** * Init and show the welcome tour. Note we do it listening to a $rootScope broadcasted 'userLoaded' message, @@ -130,26 +130,12 @@ angular.module('guideServices', []). if (!eggs) { eggs['Wolf'] = 1; // This is also set on the server } - $modal.open({ - templateUrl: 'modals/dropsEnabled.html' - }); - }); - - $rootScope.$watch('user.items.pets', function(after, before) { - if (User.user.achievements && User.user.achievements.beastMaster) return; - if (before >= 90) { - User.set({'achievements.beastMaster': true}); - $modal.open({ - templateUrl: 'modals/achievements/beastMaster.html' - }); - } + $rootScope.openModal('dropsEnabled'); }); $rootScope.$watch('user.flags.rebirthEnabled', function(after, before) { if (alreadyShown(before, after)) return; - $modal.open({ - templateUrl: 'modals/rebirthEnabled.html' - }); + $rootScope.openModal('rebirthEnabled'); });