Skip to content

Commit

Permalink
Merge pull request #509 from zarianec/develop
Browse files Browse the repository at this point in the history
Fixed SweetAlert confirmation popup
  • Loading branch information
twhiston committed Apr 3, 2018
2 parents 8b41b19 + 8ba64af commit 123a4ea
Show file tree
Hide file tree
Showing 5 changed files with 214 additions and 125 deletions.
33 changes: 23 additions & 10 deletions web/public/js/controllers/projects/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ define(function () {
$scope.alert_chat = Project.alert_chat;

$scope.save = function (name, alert, alert_chat) {
$http.put(Project.getURL(), { name: name, alert: alert, alert_chat: alert_chat}).then(function () {
$http.put(Project.getURL(), {name: name, alert: alert, alert_chat: alert_chat}).then(function () {
swal('Saved', 'Project settings saved.', 'success');
}).catch(function () {
swal('Error', 'Project settings were not saved', 'error');
Expand All @@ -16,15 +16,28 @@ define(function () {
swal({
title: 'Delete Project?',
text: 'All data related to this project will be deleted.',
type: 'warning',
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: 'Yes, DELETE'
}, function () {
$http.delete(Project.getURL()).then(function () {
$state.go('dashboard');
}).catch(function () {
swal('error', 'could not delete project!', 'error');
icon: 'warning',
buttons: {
cancel: true,
confirm: {
text: 'Yes, DELETE',
closeModal: false,
className: 'bg-danger',
},
},
}).then(function (value) {
if (!value) {
return;
}

$http.delete(Project.getURL())
.then(function () {
swal.stopLoading();
swal.close();

$state.go('dashboard');
}).catch(function () {
swal('Error', 'Could not delete project!', 'error');
});
});
}
Expand Down
76 changes: 47 additions & 29 deletions web/public/js/controllers/projects/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,46 @@ define(function () {
}

$scope.remove = function (environment) {
$http.delete(Project.getURL() + '/environment/' + environment.id).then(function () {
$scope.reload();
}).catch(function (response) {
var d = response.data;
if (!(d && d.inUse)) {
swal('error', 'could not delete environment..', 'error');
return;
}

swal({
title: 'Environment in use',
text: d.error,
type: 'error',
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: 'Mark as removed'
}, function () {
$http.delete(Project.getURL() + '/environment/' + environment.id + '?setRemoved=1').then(function () {
$scope.reload();
}).catch(function () {
$http.delete(Project.getURL() + '/environment/' + environment.id)
.then(function () {
$scope.reload();
})
.catch(function (response) {
var d = response.data;
if (!(d && d.inUse)) {
swal('error', 'could not delete environment..', 'error');
return;
}

swal({
title: 'Environment in use',
text: d.error,
icon: 'error',
buttons: {
cancel: true,
confirm: {
text: 'Mark as removed',
closeModel: false,
className: 'bg-danger',
}
}
}).then(function (value) {
if (!value) {
return;
}

$http.delete(Project.getURL() + '/environment/' + environment.id + '?setRemoved=1')
.then(function () {
swal.stopLoading();
swal.close();

$scope.reload();
})
.catch(function () {
swal('Error', 'Could not delete environment..', 'error');
});
});
});
});
}

$scope.add = function () {
Expand All @@ -44,12 +60,13 @@ define(function () {
scope: scope
}).result.then(function (env) {
$http.post(Project.getURL() + '/environment', env.environment)
.then(function () {
$scope.reload();
}).catch(function (response) {
.then(function () {
$scope.reload();
}).catch(function (response) {
swal('Error', 'Environment not added: ' + response.status, 'error');
});
}, function () {});
}, function () {
});
}

$scope.editEnvironment = function (env) {
Expand All @@ -65,12 +82,13 @@ define(function () {
}

$http.put(Project.getURL() + '/environment/' + env.id, opts.environment)
.then(function () {
$scope.reload();
}).catch(function (response) {
.then(function () {
$scope.reload();
}).catch(function (response) {
swal('Error', 'Environment not updated: ' + response.status, 'error');
});
}, function () {});
}, function () {
});
}

$scope.reload();
Expand Down
90 changes: 56 additions & 34 deletions web/public/js/controllers/projects/inventory.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,47 @@ define(function () {
}

$scope.remove = function (inventory) {
$http.delete(Project.getURL() + '/inventory/' + inventory.id).then(function () {
$scope.reload();
}).catch(function (response) {
var d = response.data;
if (!(d && d.inUse)) {
swal('error', 'could not delete inventory..', 'error');
return;
}

swal({
title: 'Inventory in use',
text: d.error,
type: 'error',
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: 'Mark as removed'
}, function () {
$http.delete(Project.getURL() + '/inventory/' + inventory.id + '?setRemoved=1').then(function () {
$scope.reload();
}).catch(function () {
$http.delete(Project.getURL() + '/inventory/' + inventory.id)
.then(function () {
$scope.reload();
})
.catch(function (response) {
var d = response.data;
if (!(d && d.inUse)) {
swal('error', 'could not delete inventory..', 'error');
return;
}

swal({
title: 'Inventory in use',
text: d.error,
icon: 'error',
buttons: {
cancel: true,
confirm: {
text: 'Mark as removed',
closeModel: false,
className: 'bg-danger',
}
}
}).then(function (value) {
if (!value) {
return;
}

$http
.delete(Project.getURL() + '/inventory/' + inventory.id + '?setRemoved=1')
.then(function () {
swal.stopLoading();
swal.close();

$scope.reload();
})
.catch(function () {
swal('Error', 'Could not delete inventory..', 'error');
});
});
});
});
}

$scope.add = function () {
Expand All @@ -43,12 +60,13 @@ define(function () {
scope: scope
}).result.then(function (inventory) {
$http.post(Project.getURL() + '/inventory', inventory.inventory)
.then(function () {
$scope.reload();
}).catch(function (response) {
.then(function () {
$scope.reload();
}).catch(function (response) {
swal('Error', 'Inventory not added: ' + response.status, 'error');
});
}, function () {});
}, function () {
});
});
}

Expand All @@ -68,12 +86,13 @@ define(function () {
}

$http.put(Project.getURL() + '/inventory/' + inventory.id, opts.inventory)
.then(function () {
$scope.reload();
}).catch(function (response) {
.then(function () {
$scope.reload();
}).catch(function (response) {
swal('Error', 'Inventory not updated: ' + response.status, 'error');
});
}, function () {});
}, function () {
});
});
}

Expand All @@ -87,16 +106,19 @@ define(function () {
}).result.then(function (v) {
inventory.inventory = v;
$http.put(Project.getURL() + '/inventory/' + inventory.id, inventory)
.then(function () {
$scope.reload();
}).catch(function (response) {
.then(function () {
$scope.reload();
}).catch(function (response) {
swal('Error', 'Inventory not updated: ' + response.status, 'error');
});
}, function () {});
}, function () {
});
}

$scope.getKeys = function (cb) {
if (typeof cb != 'function') cb = function () {}
if (typeof cb != 'function') {
cb = function () {};
}

$http.get(Project.getURL() + '/keys?type=ssh').then(function (keys) {
cb(keys.data);
Expand Down
70 changes: 44 additions & 26 deletions web/public/js/controllers/projects/keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,47 @@ define(function () {
}

$scope.remove = function (key) {
$http.delete(Project.getURL() + '/keys/' + key.id).then(function () {
$scope.reload();
}).catch(function (response) {
var d = response.data;
$http.delete(Project.getURL() + '/keys/' + key.id)
.then(function () {
$scope.reload();
})
.catch(function (response) {
var d = response.data;

if (!(d && d.inUse)) {
swal('error', 'could not delete key..', 'error');
return;
}
if (!(d && d.inUse)) {
swal('error', 'could not delete key..', 'error');
return;
}

swal({
title: 'Key in use',
text: d.error,
type: 'error',
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: 'Mark as removed'
}, function () {
$http.delete(Project.getURL() + '/keys/' + key.id + '?setRemoved=1').then(function () {
$scope.reload();
}).catch(function () {
swal('error', 'could not remove key..', 'error');
swal({
title: 'Key in use',
text: d.error,
icon: 'error',
buttons: {
cancel: true,
confirm: {
text: 'Mark as removed',
closeModel: false,
className: 'bg-danger',
}
}
}).then(function (value) {
if (!value) {
return;
}

$http.delete(Project.getURL() + '/keys/' + key.id + '?setRemoved=1')
.then(function () {
swal.stopLoading();
swal.close();

$scope.reload();
})
.catch(function () {
swal('Error', 'Could not remove key..', 'error');
});
});
});
});
}

$scope.add = function () {
Expand All @@ -43,7 +59,8 @@ define(function () {
}).catch(function (response) {
swal('error', 'could not add key:' + response.status, 'error');
});
}, function () {});
}, function () {
});
}

$scope.update = function (key) {
Expand All @@ -61,12 +78,13 @@ define(function () {
}

$http.put(Project.getURL() + '/keys/' + key.id, opts.key)
.then(function () {
$scope.reload();
}).catch(function (response) {
.then(function () {
$scope.reload();
}).catch(function (response) {
swal('Error', 'could not update key:' + response.status, 'error');
});
}, function () {});
}, function () {
});
}

$scope.reload();
Expand Down
Loading

0 comments on commit 123a4ea

Please sign in to comment.