Merge pull request #2194 from anoek/1742

Behave better when deleting items you are currently editing
This commit is contained in:
Akita Noek
2016-06-08 14:53:25 -04:00
10 changed files with 43 additions and 11 deletions

View File

@@ -103,6 +103,9 @@ export function CredentialsList($scope, $rootScope, $location, $log,
Rest.destroy() Rest.destroy()
.success(function () { .success(function () {
$scope.search(list.iterator); $scope.search(list.iterator);
if (new RegExp('/' + id + '$').test($location.$$url)) {
$state.go('^');
}
}) })
.error(function (data, status) { .error(function (data, status) {
ProcessErrors($scope, data, status, null, { hdr: 'Error!', ProcessErrors($scope, data, status, null, { hdr: 'Error!',

View File

@@ -247,6 +247,9 @@ export function ProjectsList ($scope, $rootScope, $location, $log, $stateParams,
Rest.destroy() Rest.destroy()
.success(function () { .success(function () {
$scope.search(list.iterator); $scope.search(list.iterator);
if (new RegExp('/' + id + '$').test($location.$$url)) {
$state.go('^');
}
}) })
.error(function (data, status) { .error(function (data, status) {
ProcessErrors($scope, data, status, null, { hdr: 'Error!', ProcessErrors($scope, data, status, null, { hdr: 'Error!',

View File

@@ -98,6 +98,9 @@ export function TeamsList($scope, $rootScope, $location, $log, $stateParams,
Wait('stop'); Wait('stop');
$('#prompt-modal').modal('hide'); $('#prompt-modal').modal('hide');
$scope.search(list.iterator); $scope.search(list.iterator);
if (new RegExp('/' + id + '$').test($location.$$url)) {
$state.go('^');
}
}) })
.error(function (data, status) { .error(function (data, status) {
Wait('stop'); Wait('stop');

View File

@@ -112,6 +112,9 @@ export function UsersList($scope, $rootScope, $location, $log, $stateParams,
Rest.destroy() Rest.destroy()
.success(function () { .success(function () {
$scope.search(list.iterator); $scope.search(list.iterator);
if (new RegExp('/' + id + '$').test($location.$$url)) {
$state.go('^');
}
}) })
.error(function (data, status) { .error(function (data, status) {
ProcessErrors($scope, data, status, null, { hdr: 'Error!', ProcessErrors($scope, data, status, null, { hdr: 'Error!',

View File

@@ -428,8 +428,8 @@ export default
* }) * })
* *
*/ */
.factory('DeleteSchedule', ['GetBasePath','Rest', 'Wait', 'ProcessErrors', 'Prompt', 'Find', .factory('DeleteSchedule', ['GetBasePath','Rest', 'Wait', 'ProcessErrors', 'Prompt', 'Find', '$location',
function(GetBasePath, Rest, Wait, ProcessErrors, Prompt, Find) { function(GetBasePath, Rest, Wait, ProcessErrors, Prompt, Find, $location) {
return function(params) { return function(params) {
var scope = params.scope, var scope = params.scope,
@@ -455,6 +455,9 @@ export default
.success(function () { .success(function () {
$('#prompt-modal').modal('hide'); $('#prompt-modal').modal('hide');
scope.$emit(callback, id); scope.$emit(callback, id);
if (new RegExp('/' + id + '$').test($location.$$url)) {
$location.url($location.url().replace(/[/][0-9]+$/, "")); // go to list view
}
}) })
.error(function (data, status) { .error(function (data, status) {
try { try {

View File

@@ -323,6 +323,9 @@ function InventoriesList($scope, $rootScope, $location, $log,
Rest.destroy() Rest.destroy()
.success(function () { .success(function () {
$scope.search(list.iterator); $scope.search(list.iterator);
if (new RegExp('/' + id + '$').test($location.$$url)) {
$state.go('^');
}
}) })
.error(function (data, status) { .error(function (data, status) {
ProcessErrors( $scope, data, status, null, { hdr: 'Error!', ProcessErrors( $scope, data, status, null, { hdr: 'Error!',

View File

@@ -7,11 +7,11 @@
export default export default
[ '$rootScope','Wait', 'generateList', 'inventoryScriptsListObject', [ '$rootScope','Wait', 'generateList', 'inventoryScriptsListObject',
'GetBasePath' , 'SearchInit' , 'PaginateInit', 'GetBasePath' , 'SearchInit' , 'PaginateInit',
'Rest' , 'ProcessErrors', 'Prompt', '$state', 'Rest' , 'ProcessErrors', 'Prompt', '$state', '$location',
function( function(
$rootScope,Wait, GenerateList, inventoryScriptsListObject, $rootScope,Wait, GenerateList, inventoryScriptsListObject,
GetBasePath, SearchInit, PaginateInit, GetBasePath, SearchInit, PaginateInit,
Rest, ProcessErrors, Prompt, $state Rest, ProcessErrors, Prompt, $state, $location
) { ) {
var scope = $rootScope.$new(), var scope = $rootScope.$new(),
defaultUrl = GetBasePath('inventory_scripts'), defaultUrl = GetBasePath('inventory_scripts'),
@@ -59,6 +59,9 @@ export default
Rest.destroy() Rest.destroy()
.success(function () { .success(function () {
scope.search(list.iterator); scope.search(list.iterator);
if (new RegExp('/' + id + '$').test($location.$$url)) {
$state.go('^');
}
}) })
.error(function (data, status) { .error(function (data, status) {
ProcessErrors(scope, data, status, null, { hdr: 'Error!', ProcessErrors(scope, data, status, null, { hdr: 'Error!',

View File

@@ -78,6 +78,9 @@ export default
Rest.destroy() Rest.destroy()
.success(function () { .success(function () {
$scope.search(list.iterator); $scope.search(list.iterator);
if (new RegExp('/' + id + '$').test($location.$$url)) {
$state.go('^');
}
}) })
.error(function (data) { .error(function (data) {
Wait('stop'); Wait('stop');

View File

@@ -8,12 +8,12 @@ export default
[ '$rootScope','Wait', 'generateList', 'NotificationTemplatesList', [ '$rootScope','Wait', 'generateList', 'NotificationTemplatesList',
'GetBasePath' , 'SearchInit' , 'PaginateInit', 'Rest' , 'GetBasePath' , 'SearchInit' , 'PaginateInit', 'Rest' ,
'ProcessErrors', 'Prompt', '$state', 'GetChoices', 'Empty', 'Find', 'ProcessErrors', 'Prompt', '$state', 'GetChoices', 'Empty', 'Find',
'ngToast', '$compile', '$filter', 'ngToast', '$compile', '$filter', '$location',
function( function(
$rootScope,Wait, GenerateList, NotificationTemplatesList, $rootScope,Wait, GenerateList, NotificationTemplatesList,
GetBasePath, SearchInit, PaginateInit, Rest, GetBasePath, SearchInit, PaginateInit, Rest,
ProcessErrors, Prompt, $state, GetChoices, Empty, Find, ngToast, ProcessErrors, Prompt, $state, GetChoices, Empty, Find, ngToast,
$compile, $filter) { $compile, $filter, $location) {
var scope = $rootScope.$new(), var scope = $rootScope.$new(),
defaultUrl = GetBasePath('notification_templates'), defaultUrl = GetBasePath('notification_templates'),
list = NotificationTemplatesList, list = NotificationTemplatesList,
@@ -183,6 +183,9 @@ export default
Rest.destroy() Rest.destroy()
.success(function () { .success(function () {
scope.search(list.iterator); scope.search(list.iterator);
if (new RegExp('/' + id + '$').test($location.$$url)) {
$state.go('^');
}
}) })
.error(function (data, status) { .error(function (data, status) {
ProcessErrors(scope, data, status, null, { hdr: 'Error!', ProcessErrors(scope, data, status, null, { hdr: 'Error!',

View File

@@ -12,11 +12,16 @@ export default ['$http', '$q', function($http, $q) {
return $http.get(url + "?id=" + id) return $http.get(url + "?id=" + id)
.then(function (data) { .then(function (data) {
var queryValue, queryType; var queryValue, queryType;
if (data.data.results[0].type === "user") { if (data.data.results.length) {
queryValue = data.data.results[0].username; if (data.data.results[0].type === "user") {
queryType = "username"; queryValue = data.data.results[0].username;
queryType = "username";
} else {
queryValue = data.data.results[0].name;
queryType = "name";
}
} else { } else {
queryValue = data.data.results[0].name; queryValue = "";
queryType = "name"; queryType = "name";
} }
// get how many results are less than or equal to // get how many results are less than or equal to
@@ -26,7 +31,7 @@ export default ['$http', '$q', function($http, $q) {
// divide by the page size to get what // divide by the page size to get what
// page the data should be on // page the data should be on
var count = data.data.count; var count = data.data.count;
return Math.ceil(count/parseInt(pageSize)); return Math.max(1, Math.ceil(count/parseInt(pageSize)));
}); });
}); });
} else { } else {