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
commit f4df24647c
10 changed files with 43 additions and 11 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -428,8 +428,8 @@ export default
* })
*
*/
.factory('DeleteSchedule', ['GetBasePath','Rest', 'Wait', 'ProcessErrors', 'Prompt', 'Find',
function(GetBasePath, Rest, Wait, ProcessErrors, Prompt, Find) {
.factory('DeleteSchedule', ['GetBasePath','Rest', 'Wait', 'ProcessErrors', 'Prompt', 'Find', '$location',
function(GetBasePath, Rest, Wait, ProcessErrors, Prompt, Find, $location) {
return function(params) {
var scope = params.scope,
@ -455,6 +455,9 @@ export default
.success(function () {
$('#prompt-modal').modal('hide');
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) {
try {

View File

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

View File

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

View File

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

View File

@ -8,12 +8,12 @@ export default
[ '$rootScope','Wait', 'generateList', 'NotificationTemplatesList',
'GetBasePath' , 'SearchInit' , 'PaginateInit', 'Rest' ,
'ProcessErrors', 'Prompt', '$state', 'GetChoices', 'Empty', 'Find',
'ngToast', '$compile', '$filter',
'ngToast', '$compile', '$filter', '$location',
function(
$rootScope,Wait, GenerateList, NotificationTemplatesList,
GetBasePath, SearchInit, PaginateInit, Rest,
ProcessErrors, Prompt, $state, GetChoices, Empty, Find, ngToast,
$compile, $filter) {
$compile, $filter, $location) {
var scope = $rootScope.$new(),
defaultUrl = GetBasePath('notification_templates'),
list = NotificationTemplatesList,
@ -183,6 +183,9 @@ export default
Rest.destroy()
.success(function () {
scope.search(list.iterator);
if (new RegExp('/' + id + '$').test($location.$$url)) {
$state.go('^');
}
})
.error(function (data, status) {
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)
.then(function (data) {
var queryValue, queryType;
if (data.data.results[0].type === "user") {
queryValue = data.data.results[0].username;
queryType = "username";
if (data.data.results.length) {
if (data.data.results[0].type === "user") {
queryValue = data.data.results[0].username;
queryType = "username";
} else {
queryValue = data.data.results[0].name;
queryType = "name";
}
} else {
queryValue = data.data.results[0].name;
queryValue = "";
queryType = "name";
}
// 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
// page the data should be on
var count = data.data.count;
return Math.ceil(count/parseInt(pageSize));
return Math.max(1, Math.ceil(count/parseInt(pageSize)));
});
});
} else {