Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/main/javascript/controller/cat-base-list-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ function CatBaseListController($scope, $state, $controller, $log, catBreadcrumbs
return this.getUrlForId('new');
};

this.remove = function(id) {
this.remove = function (id, message) {
message = message || 'Successfully deleted entry.';
config.listData.endpoint.remove(id)
.then(function() {
.then(function () {
$globalMessages.addMessage('success', message, true);
catListDataLoadingService.load(config.listData.endpoint, config.listData.searchRequest).then(
function (data) {
_.assign($scope.listData, data);
Expand Down
22 changes: 19 additions & 3 deletions src/main/javascript/directives/cat-confirm-click.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,34 @@
/**
* @ngdoc directive
* @name cat.directives.confirmClick:catConfirmClick
*
* @param cat-i18n-params cat-i18n-params need to be parsed as JSON or it will not work
*/
angular.module('cat.directives.confirmClick', [])
.directive('catConfirmClick', function CatConfirmClickDirective() {
.directive('catConfirmClick', function CatConfirmClickDirective(catI18nService) {
return {
restrict: 'A',
link: function CatConfirmClickLink(scope, element, attr) {
var msg = attr.catConfirmClick || 'Are you sure?';
var clickAction = attr.catOnConfirm;
var params = undefined;
if (!!attr.catI18nParams) {
params = JSON.parse(attr.catI18nParams);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think what you want to do is parse it as an angular expression
see https://docs.angularjs.org/api/ng/service/$parse

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I will fix this, when I have the time.

}
element.bind('click', function (event) {
if (window.confirm(msg)) {
scope.$eval(clickAction);
function dialog(dialogMessage) {
if (window.confirm(dialogMessage)) {
scope.$eval(clickAction);
}
}

catI18nService.translate(msg, params).then(
function (message) {
dialog(message);
}, function (reason) {
dialog(msg);
}
);
});
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/template/cat-base-detail.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div class="panel-heading">
<div class="pull-right edit-buttons" ng-if="!editDetail && !!editTemplate">
<div class="btn-group">
<button type="button" class="btn btn-xs btn-default" cat-confirm-click cat-on-confirm="remove()"
<button type="button" class="btn btn-xs btn-default" cat-confirm-click="{{catConfirmDeleteMessage}}" cat-on-confirm="remove()"
cat-element-visible="cat.base.delete" cat-element-data="config">
<span class="glyphicon glyphicon-trash"></span>
<span cat-i18n="cc.catalysts.general.delete">Delete</span>
Expand Down