supervisor editing solved #78

parent 62dcf558
/* global angular */
angular.module('dashboardConfig', []).constant('config', {
backend: 'https://' + window.location.host,
backend: 'http://' + window.location.host,
});
......@@ -14,11 +14,14 @@ dashboardControllers.controller('AdminSupervisorsCtrl', function AdminSupervisor
surname: '',
address: '',
country: '',
postalCode: '',
email: '',
phone: '',
gender: 'F',
lang: 'es',
office: ''
office: '',
password: '',
password_confirm: ''
};
// List of supervisors
......@@ -53,11 +56,14 @@ dashboardControllers.controller('AdminSupervisorsCtrl', function AdminSupervisor
surname: '',
address: '',
country: '',
postalCode: '',
email: '',
phone: '',
gender: 'F',
lang: 'es',
office: ''
office: '',
password: '',
password_confirm: ''
};
// Hide the form
......@@ -78,11 +84,14 @@ dashboardControllers.controller('AdminSupervisorsCtrl', function AdminSupervisor
name: supervisor.name,
surname: supervisor.surname,
address: supervisor.address,
postalCode: supervisor.address,
country: supervisor.country,
email: supervisor.email,
actualEmail: supervisor.email,
phone: supervisor.phone,
gender: supervisor.gender,
password: supervisor.password,
password_confirm: supervisor.password_confirm,
lang: supervisor.lang,
office: supervisor.office
};
......@@ -94,7 +103,7 @@ dashboardControllers.controller('AdminSupervisorsCtrl', function AdminSupervisor
// Checking new email
// If no change, it is deleted from supervisor object
if(supervisor.email == supervisor.actualEmail){
if (supervisor.email == supervisor.actualEmail){
delete supervisor.email;
delete supervisor.actualEmail;
}
......@@ -103,6 +112,14 @@ dashboardControllers.controller('AdminSupervisorsCtrl', function AdminSupervisor
var supid = supervisor.id;
delete supervisor.id;
if (supervisor.password != supervisor.password_confirm)
return;
if (supervisor.password.length == 0) {
delete supervisor.password;
delete supervisor.password_confirm;
}
$http
.put(config.backend + '/sup/' + supid, supervisor)
.success(function(data, status, headers, config) {
......@@ -122,6 +139,9 @@ dashboardControllers.controller('AdminSupervisorsCtrl', function AdminSupervisor
$scope.supervisors[i].gender = data.gender;
$scope.supervisors[i].lang = data.lang;
$scope.supervisors[i].office = data.office;
$scope.supervisors[i].postalCode = data.postalCode;
$scope.supervisors[i].password = '';
$scope.supervisors[i].password_confirm = '';
}
}
......@@ -142,7 +162,13 @@ dashboardControllers.controller('AdminSupervisorsCtrl', function AdminSupervisor
var supervisor = $scope.formdatasupervisor;
// Add password
supervisor.password = supervisor.name + supervisor.email;
if (supervisor.password != supervisor.password_confirm)
return;
if (supervisor.password.length == 0) {
delete supervisor.password;
delete supervisor.password_confirm;
}
$http
.post(config.backend+'/sup', supervisor)
......
......@@ -14,7 +14,11 @@
<input type="text" class="form-control" id="supervisor_address" placeholder="{{ 'address' | translate }}" ng-model="formdatasupervisor.address" />
</div>
<div class="form-group">
<div class="form-group">
<input type="text" class="form-control" id="supervisor_postal_code" placeholder="{{ 'postal_code' | translate }}" required ng-model="formdata.postal_code" ng-change="formdata.postal_code = formdata.postal_code.toUpperCase()"/>
</div>
<div class="form-group">
<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>
......@@ -39,7 +43,7 @@
</div>
<fieldset>
<legend translate>office</legend>
<label translate>office</label>
<div class="form-group">
<select class="form-control" name="supervisor_office" id="supervisor_office" ng-model="formdatasupervisor.office" required>
<option ng-repeat="of in offices | orderBy: 'name'" value="{{ of.id }}">
......@@ -50,7 +54,7 @@
</fieldset>
<fieldset>
<legend translate>language</legend>
<label translate>language</label>
<div class="form-group">
<select class="form-control" name="supervisor_language" id="supervisor_language" ng-model="formdatasupervisor.lang">
<option value="es" selected>Español</option>
......@@ -59,6 +63,17 @@
</div>
</fieldset>
<fieldset>
<label translate>password</label>
<span class="color_red text_sm pull-right" ng-show="formdata.password != formdata.password_confirm" translate>password_match</span>
<div class="form-group">
<input type="password" class="form-control" id="supervisor_password1" placeholder="{{ 'password_type' | translate }}" required ng-model="formdatasupervisor.password" />
</div>
<div class="form-group">
<input type="password" class="form-control" id="supervisor_password2" placeholder="{{ 'password_confirm' | translate }}" required ng-model="formdatasupervisor.password_confirm" />
</div>
</fieldset>
<div class="form-group">
<button type="button" class="btn btn-default" ng-click="resetForm()">{{'cancel'|translate}}</button>
<button type="submit" class="btn btn-primary" translate>add</button>
......
<h3 translate>update_supervisor</h3>
<form name="UpdateSupervisorForm" role="form" ng-submit="save_supervisor()">
<fieldset>
<div class="form-group">
......@@ -14,7 +14,11 @@
<input type="text" class="form-control" id="supervisor_address" placeholder="{{ 'address' | translate }}" ng-model="formdatasupervisor.address" />
</div>
<div class="form-group">
<div class="form-group">
<input type="text" class="form-control" id="supervisor_postal_code" placeholder="{{ 'postal_code' | translate }}" required ng-model="formdata.postalCode" ng-change="formdata.postalCode = formdata.postalCode.toUpperCase()"/>
</div>
<div class="form-group">
<input type="text" class="form-control" id="supervisor_country" placeholder="{{ 'country' | translate }}" ng-model="formdatasupervisor.country" />
</div>
......@@ -34,7 +38,7 @@
</div>
<fieldset>
<legend translate>office</legend>
<label translate>office</label>
<div class="form-group">
<select class="form-control" name="supervisor_office" id="supervisor_office" ng-model="formdatasupervisor.office">
<option ng-repeat="of in offices | orderBy: 'name'" value="{{ of.id }}">
......@@ -45,7 +49,7 @@
</fieldset>
<fieldset>
<legend translate>language</legend>
<label translate>language</label>
<div class="form-group">
<select class="form-control" name="supervisor_language" id="supervisor_language" ng-model="formdatasupervisor.lang">
<option value="es">Español</option>
......@@ -54,9 +58,20 @@
</div>
</fieldset>
<fieldset>
<label translate>password</label>
<span class="color_red text_sm pull-right" ng-show="formdata.password != formdata.password_confirm" translate>password_match</span>
<div class="form-group">
<input type="password" class="form-control" id="supervisor_password1" placeholder="{{ 'password_type' | translate }}" ng-model="formdatasupervisor.password" />
</div>
<div class="form-group">
<input type="password" class="form-control" id="supervisor_password2" placeholder="{{ 'password_confirm' | translate }}" ng-model="formdatasupervisor.password_confirm" />
</div>
</fieldset>
<div class="form-group">
<button type="button" class="btn btn-default" ng-click="resetForm()">{{'cancel'|translate}}</button>
<button type="submit" class="btn btn-primary" translate>save</button>
</div>
</fieldset>
</form>
\ No newline at end of file
</form>
......@@ -106,7 +106,7 @@
</div>
</div>
</div>
<fieldset>
</fieldset>
<fieldset>
<div class="form-group">
......
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