Dataset/JS/AngularCosmoAdmin/admin-panel.js (76 lines of code) (raw):

/************************************************** * Admin Panel Controller * * Control the admin sidebar * **************************************************/ angular.module('cosmo').controller('adminPanelCtrl', ['$scope', 'Users', 'REST', '$location', '$timeout', '$http', '$sce', function($scope, Users, REST, $location, $timeout, $http, $sce){ $scope.admin = {}; $scope.admin.username = Users.username; $scope.admin.roleNum = Users.roleNum; $scope.isUserAdmin = Users.admin; // Check if the user is on the admin or password reset page if($location.path() === '/admin') { $scope.admin.sidebar = 'core/html/login.html'; $scope.admin.showAdminPanel = true; $scope.admin.active = true; } else if($location.path().indexOf('/reset') === 0) { $scope.admin.sidebar = 'core/html/password-reset.html'; $scope.admin.showAdminPanel = true; $scope.admin.active = true; } else $scope.admin.sidebar = 'core/html/sidebar.html'; // Get latest official message from Cosmo (for version, updates, and blog posts) $http.get('http://www.cosmocms.org/message.php?dontcache='+ new Date().getTime()) .success(officialMessagePromise); // Update official message from Cosmo function officialMessagePromise(data){ if(data){ data = angular.fromJson(data); $scope.admin.messageID = data.id; var dontShowCookie = document.cookie.substr(document.cookie.indexOf('dontShowMessage=')+16, 5); if($scope.admin.messageID !== dontShowCookie){ $scope.admin.message = $sce.trustAsHtml(data.message); $scope.admin.displayMessage = true; } } } // Set a cookie so you don't see this message any more $scope.removeMessage = function(){ var expdate = new Date(); expdate.setDate(expdate.getDate() + 90); // 90 days in the future document.cookie = "dontShowMessage=" + $scope.admin.messageID + ";expires=" + expdate.toGMTString(); $scope.admin.displayMessage = false; }; // Get user's info if(Users.id) REST.users.get({userID: Users.id}, usersInfoPromise); // Update user's info in the template function usersInfoPromise(data){ Users.name = data.name; Users.bio = data.bio; Users.photo = data.photo; Users.role = data.role; Users.twitter = data.twitter; Users.facebook = data.facebook; Users.username = data.username; Users.email = data.email; if(data.photo) $scope.admin.photo = data.photo; else $scope.admin.photo = 'core/img/image.svg'; } // Go to the new page $scope.navigate = function(){ $location.path('new'); }; // Watch for calls to open the file menu $scope.$on('editFiles', function(event, data) { $scope.admin.files = angular.fromJson(data); $scope.admin.sidebar = 'core/html/files.html'; $scope.admin.showAdminPanel = true; $scope.admin.active = true; $timeout(function() { $scope.$apply(); }); }); // todo: Depreciate. Remove from admin-panel.html and use loginRegistrationCtrl instead $scope.logout = function(){ // Delete cookies document.cookie = 'username=null;expires=Thu, 01 Jan 1970 00:00:01 GMT;'; document.cookie = 'usersID=null;expires=Thu, 01 Jan 1970 00:00:01 GMT;'; document.cookie = 'token=null;expires=Thu, 01 Jan 1970 00:00:01 GMT;'; Users.id = ''; Users.username = ''; $http.defaults.headers.common['username'] = ''; $http.defaults.headers.common['token'] = ''; $location.path('/'); $timeout(function(){ location.reload(); }, 1000); }; }]);