github.com/justinjmoses/evergreen@v0.0.0-20170530173719-1d50e381ff0d/public/static/js/hosts_admin.js (about) 1 mciModule.controller('AdminOptionsCtrl', ['$scope', '$filter', 'mciHostsRestService', 'notificationService', function($scope, $filter, hostsRestService, notifier) { 2 $scope.modalTitle = 'Modify Hosts'; 3 $scope.validHostStatuses = ["running", "decommissioned", "quarantined"]; 4 $scope.newStatus = $scope.validHostStatuses[0]; 5 6 $scope.updateStatus = function() { 7 var selectedHosts = $scope.selectedHosts(); 8 var hostIds = []; 9 for (var i = 0; i < selectedHosts.length; ++i) { 10 hostIds.push(selectedHosts[i].id); 11 } 12 hostsRestService.updateStatus( 13 hostIds, 14 'updateStatus', 15 { status: $scope.newStatus }, 16 { 17 success: function(data, status) { 18 window.location.reload(); 19 }, 20 error: function(jqXHR, status, errorThrown) { 21 notifier.pushNotification('Error updating host status: ' + jqXHR, 'errorModal'); 22 } 23 } 24 ); 25 }; 26 27 $scope.setHostStatus = function(status) { 28 $scope.newStatus = status; 29 }; 30 31 $scope.openAdminModal = function(opt) { 32 $scope.adminOption = opt; 33 $scope.modalOpen = true; 34 35 var modal = $('#admin-modal').modal('show'); 36 37 if (opt === "statusChange") { 38 modal.on('shown.bs.modal', function() { 39 $scope.modalOpen = true; 40 }); 41 42 modal.on('hide.bs.modal', function() { 43 $scope.modalOpen = false; 44 }); 45 } 46 47 $(document).keyup(function(ev) { 48 if ($scope.modalOpen && ev.keyCode === 13) { 49 if ($scope.adminOption === 'statusChange') { 50 $scope.updateStatus(); 51 $('#admin-modal').modal('hide'); 52 } 53 } 54 }); 55 }; 56 }]); 57 58 59 mciModule.directive('adminUpdateStatus', function() { 60 return { 61 restrict: 'E', 62 templateUrl: '/static/partials/hosts_status_update.html' 63 }; 64 }); 65