1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-01 12:24:28 +01:00
fab-manager/app/assets/javascripts/controllers/admin/abuses.js
2019-12-18 11:08:14 +01:00

53 lines
1.7 KiB
JavaScript

/**
* Controller used in abuses management page
*/
Application.Controllers.controller('AbusesController', ['$scope', '$state', 'Abuse', 'abusesPromise', 'dialogs', 'growl', '_t',
function ($scope, $state, Abuse, abusesPromise, dialogs, growl, _t) {
/* PUBLIC SCOPE */
// List of all reported abuses
$scope.abuses = [];
/**
* Callback handling a click on the ✓ button: confirm before delete
*/
$scope.confirmProcess = function (abuseId) {
dialogs.confirm(
{
resolve: {
object () {
return {
title: _t('app.admin.manage_abuses.confirmation_required'),
msg: _t('app.admin.manage_abuses.report_will_be_destroyed')
};
}
}
},
function () { // cancel confirmed
Abuse.remove({ id: abuseId }, function () { // successfully canceled
growl.success(_t('app.admin.manage_abuses.report_removed'));
Abuse.query({}, function (abuses) {
$scope.abuses = abuses.abuses.filter(a => a.signaled_type === 'Project');
});
}
, function () { // error while canceling
growl.error(_t('app.admin.manage_abuses.failed_to_remove'));
});
}
);
};
/* PRIVATE SCOPE */
/**
* Kind of constructor: these actions will be realized first when the controller is loaded
*/
const initialize = function () {
// we display only abuses related to projects
$scope.abuses = abusesPromise.abuses.filter(a => a.signaled_type === 'Project');
};
// !!! MUST BE CALLED AT THE END of the controller
return initialize();
}
]);