Deleting supervisors in admin view working

parent 6baafbf1
......@@ -614,6 +614,18 @@ module.exports = {
} else {
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
$http
.post(config.backend+'/sup', supervisor)
.success(function(data, status, headers, config) {
$translate('supervisor_added').then(function (translation) {
ngToast.success({ content: translation });
});
// Add to the list of supervisors in view
ngToast.success({ content: $translate.instant('supervisor_added') });
$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();
// Show the add form to new adding
$scope.hidesupervisoradd = false;
})
.error(function(data, status, headers, config) {
......@@ -171,7 +164,7 @@ dashboardControllers.controller('AdminSupervisorsCtrl', function AdminSupervisor
var deleteSupervisor = $window.confirm('Are you absolutely sure you want to delete?');
if(deleteSupervisor){
$http
.delete(config.backend+'/supervisor/'+ supervisor.id)
.delete(config.backend+'/sup/'+ supervisor.id)
.success(function(data, status, headers, config) {
// Eliminar de la vista: Se recorre el array de objetos json para buscarlo
......
......@@ -7,7 +7,9 @@
<div class="row">
<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 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">
......@@ -29,7 +31,7 @@
<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="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>
</tr>
</table>
......
<h3 translate>add_supervisor</h3>
<form name="AddSupervisorForm" role="form" ng-submit="add_supervisor()">
<fieldset>
<div class="form-group">
......@@ -15,7 +15,12 @@
</div>
<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 class="form-group">
......@@ -59,4 +64,4 @@
<button type="submit" class="btn btn-primary" translate>add</button>
</div>
</fieldset>
</form>
\ No newline at end of file
</form>
......@@ -132,7 +132,8 @@ module.exports.policies = {
activate: true,
upload: ['tokenAuth'],
subscribe: ['tokenAuth'],
unsubscribe: ['tokenAuth']
unsubscribe: ['tokenAuth'],
delete: ['tokenAuth', 'isAdmin']
},
TryController: {
......
......@@ -115,6 +115,7 @@ module.exports.routes = {
'POST /sup/upload': 'SupervisorController.upload',
'POST /sup/subscribe': 'SupervisorController.subscribe',
'POST /sup/unsubscribe': 'SupervisorController.unsubscribe',
'DELETE /sup/:id': 'SupervisorController.delete',
'PUT /try/:id': 'TryController.update',
'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