Deleting supervisors in admin view working

parent 6baafbf1
...@@ -614,6 +614,18 @@ module.exports = { ...@@ -614,6 +614,18 @@ module.exports = {
} else { } else {
res.badRequest(); res.badRequest();
} }
},
/**
* Deletes a supervisor
* @param {Id} id Id of the supervisor to delete
*/
delete: function (req, res) {
if (!req.params.id)
return res.badRequest("Missing parameter");
Supervisor.destroy({id: req.params.id})
.then(() => {res.ok()})
.catch((err) => {res.serverError("Could not delete supervisor")});
} }
}; };
...@@ -147,16 +147,9 @@ dashboardControllers.controller('AdminSupervisorsCtrl', function AdminSupervisor ...@@ -147,16 +147,9 @@ dashboardControllers.controller('AdminSupervisorsCtrl', function AdminSupervisor
$http $http
.post(config.backend+'/sup', supervisor) .post(config.backend+'/sup', supervisor)
.success(function(data, status, headers, config) { .success(function(data, status, headers, config) {
$translate('supervisor_added').then(function (translation) { ngToast.success({ content: $translate.instant('supervisor_added') });
ngToast.success({ content: translation });
});
// Add to the list of supervisors in view
$scope.supervisors.push(data.user); $scope.supervisors.push(data.user);
// Delete the fields of the form to avoid data binding
// between the new element created and the form fields
$scope.resetForm(); $scope.resetForm();
// Show the add form to new adding
$scope.hidesupervisoradd = false; $scope.hidesupervisoradd = false;
}) })
.error(function(data, status, headers, config) { .error(function(data, status, headers, config) {
...@@ -171,7 +164,7 @@ dashboardControllers.controller('AdminSupervisorsCtrl', function AdminSupervisor ...@@ -171,7 +164,7 @@ dashboardControllers.controller('AdminSupervisorsCtrl', function AdminSupervisor
var deleteSupervisor = $window.confirm('Are you absolutely sure you want to delete?'); var deleteSupervisor = $window.confirm('Are you absolutely sure you want to delete?');
if(deleteSupervisor){ if(deleteSupervisor){
$http $http
.delete(config.backend+'/supervisor/'+ supervisor.id) .delete(config.backend+'/sup/'+ supervisor.id)
.success(function(data, status, headers, config) { .success(function(data, status, headers, config) {
// Eliminar de la vista: Se recorre el array de objetos json para buscarlo // Eliminar de la vista: Se recorre el array de objetos json para buscarlo
......
...@@ -7,7 +7,9 @@ ...@@ -7,7 +7,9 @@
<div class="row"> <div class="row">
<div class="col-xs-3"> <div class="col-xs-3">
<button type="button" class="btn btn-success btn-circle btn-lg" ng-click="resetForm(); hidesupervisoradd = false" title="{{'add'|translate}}"><i class="glyphicon glyphicon-plus"></i></button> <a ng-click="resetForm(); hidesupervisoradd = false" class="btn btn-success btn-sm" role="button">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span> {{ 'add_supervisor' | translate }}
</a>
</div> </div>
<div class="col-xs-6 input-group"> <div class="col-xs-6 input-group">
<input type="text" ng-model="search_sups" id="search_sups" placeholder="{{ 'filter' | translate }}" class="form-control" aria-describedby="basic-addon2"> <input type="text" ng-model="search_sups" id="search_sups" placeholder="{{ 'filter' | translate }}" class="form-control" aria-describedby="basic-addon2">
...@@ -29,7 +31,7 @@ ...@@ -29,7 +31,7 @@
<td class="ops"> <td class="ops">
<a ng-click="update_supervisor(supervisor)" title="{{'edit'|translate}}"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span></a> <a ng-click="update_supervisor(supervisor)" title="{{'edit'|translate}}"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span></a>
<a ng-click="delete_supervisor(supervisor)" title="{{'delete'|translate}}"><span class="color_red glyphicon glyphicon-remove-circle" aria-hidden="true"></span></a> <a ng-click="delete_supervisor(supervisor)" title="{{'delete'|translate}}"><span class="color_red glyphicon glyphicon-remove-circle" aria-hidden="true"></span></a>
</td> </td>
</tr> </tr>
</table> </table>
......
<h3 translate>add_supervisor</h3> <h3 translate>add_supervisor</h3>
<form name="AddSupervisorForm" role="form" ng-submit="add_supervisor()"> <form name="AddSupervisorForm" role="form" ng-submit="add_supervisor()">
<fieldset> <fieldset>
<div class="form-group"> <div class="form-group">
...@@ -15,7 +15,12 @@ ...@@ -15,7 +15,12 @@
</div> </div>
<div class="form-group"> <div class="form-group">
<input type="text" class="form-control" id="supervisor_country" placeholder="{{ 'country' | translate }}" ng-model="formdatasupervisor.country" /> <label translate>country</label>
<select class="form-control" name="supervisor_country" id="supervisor_country" ng-model="formdatasupervisor.country" required>
<option value="ES" selected>España</option>
<option value="UK">United Kingdom</option>
<option value="US">United States</option>
</select>
</div> </div>
<div class="form-group"> <div class="form-group">
...@@ -59,4 +64,4 @@ ...@@ -59,4 +64,4 @@
<button type="submit" class="btn btn-primary" translate>add</button> <button type="submit" class="btn btn-primary" translate>add</button>
</div> </div>
</fieldset> </fieldset>
</form> </form>
\ No newline at end of file
...@@ -132,7 +132,8 @@ module.exports.policies = { ...@@ -132,7 +132,8 @@ module.exports.policies = {
activate: true, activate: true,
upload: ['tokenAuth'], upload: ['tokenAuth'],
subscribe: ['tokenAuth'], subscribe: ['tokenAuth'],
unsubscribe: ['tokenAuth'] unsubscribe: ['tokenAuth'],
delete: ['tokenAuth', 'isAdmin']
}, },
TryController: { TryController: {
......
...@@ -115,6 +115,7 @@ module.exports.routes = { ...@@ -115,6 +115,7 @@ module.exports.routes = {
'POST /sup/upload': 'SupervisorController.upload', 'POST /sup/upload': 'SupervisorController.upload',
'POST /sup/subscribe': 'SupervisorController.subscribe', 'POST /sup/subscribe': 'SupervisorController.subscribe',
'POST /sup/unsubscribe': 'SupervisorController.unsubscribe', 'POST /sup/unsubscribe': 'SupervisorController.unsubscribe',
'DELETE /sup/:id': 'SupervisorController.delete',
'PUT /try/:id': 'TryController.update', 'PUT /try/:id': 'TryController.update',
'POST /try': 'TryController.create', 'POST /try': 'TryController.create',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment