Skip to content

Commit 0759949

Browse files
committed
Added new model AddressInformation associated with Operator, modified Operator client sidem #38
1 parent 6b644ed commit 0759949

14 files changed

+290
-87
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* AddressInformationController
3+
*
4+
* @description :: Server-side logic for managing contactinformations
5+
* @help :: See http://links.sailsjs.org/docs/controllers
6+
*/
7+
8+
module.exports = {
9+
10+
};

api/models/AddressInformation.js

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* ContactInformation.js
3+
*
4+
* @description :: Contact Information according to the MIABIS format
5+
*/
6+
7+
module.exports = {
8+
9+
tableName: 'address_information',
10+
11+
attributes: {
12+
// MIABIS-07C
13+
office: {
14+
type: 'string',
15+
required: true
16+
},
17+
phone: {
18+
type: 'string',
19+
required: true
20+
},
21+
// MIABIS-07E
22+
address: {
23+
type: 'text',
24+
required: true
25+
},
26+
// MIABIS-07F
27+
zip: {
28+
type: 'string',
29+
required: true
30+
},
31+
// MIABIS-07G
32+
city: {
33+
type: 'string',
34+
alpha: true,
35+
required: true
36+
},
37+
// MIABIS-07H
38+
country: {
39+
type: 'string',
40+
alpha: true,
41+
required: true,
42+
minLength: 2,
43+
maxLength: 2
44+
},
45+
createdAt: {
46+
type: 'datetime',
47+
columnName: 'created_at'
48+
},
49+
updatedAt: {
50+
type: 'datetime',
51+
columnName: 'updated_at'
52+
}
53+
54+
}
55+
};

api/models/Biobank.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = {
1616
acronym: {
1717
columnName: 'acronym',
1818
type: 'string',
19-
required: true,
19+
required: true
2020
},
2121
// MIABIS-03
2222
name: {
@@ -65,4 +65,3 @@ module.exports = {
6565

6666
}
6767
};
68-

api/models/Operator.js

+5-12
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,6 @@ var Operator = {
4141
columnName: 'email'
4242
},
4343

44-
laboratory: {
45-
type: 'string',
46-
required: true,
47-
columnName: 'laboratory'
48-
},
49-
50-
phone: {
51-
type: 'string',
52-
required: true,
53-
columnName: 'phone'
54-
},
55-
5644
login: {
5745
type: 'string',
5846
required: true,
@@ -64,6 +52,11 @@ var Operator = {
6452
via: 'user'
6553
},
6654

55+
addressInformation: {
56+
columnName: 'address_information',
57+
model: 'addressInformation'
58+
},
59+
6760
createdAt: {
6861
type:'datetime',
6962
columnName: 'created_at'

assets/js/application/Router.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -527,8 +527,8 @@
527527
var that = this;
528528
var operator = new Operator.Model();
529529
if (id) {
530-
operator.set('id', id);
531530
operator.fetch({
531+
data:$.param({id: id, populate:['addressInformation']}),
532532
success: function(operator) {
533533
that.loadView(new Operator.Views.Edit({model: operator}));
534534
},
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* @author Massimiliano Izzo
3+
* @description This file contains the Backbone classes for handling AddressInformation
4+
* models, collections and views according to the MIABIS standard
5+
*/
6+
(function(xtens, AddressInformation) {
7+
// dependencies
8+
var i18n = xtens.module("i18n").en;
9+
10+
// XTENS router alias
11+
var router = xtens.router;
12+
13+
AddressInformation.Model = Backbone.Model.extend({
14+
urlRoot: '/addressInformation'
15+
});
16+
17+
AddressInformation.List = Backbone.Collection.extend({
18+
url: '/addressInformation',
19+
model: AddressInformation.Model
20+
});
21+
22+
AddressInformation.Views.Edit = Backbone.View.extend({
23+
24+
initialize: function(options) {
25+
this.template = JST["views/templates/addressinformation-edit.ejs"];
26+
},
27+
28+
bindings: {
29+
'#office': 'office',
30+
'#phone': 'phone',
31+
'#address':'address',
32+
'#zip': 'zip',
33+
'#city': 'city',
34+
'#country': 'country'
35+
},
36+
37+
render: function() {
38+
this.$el.html(this.template({__: i18n}));
39+
this.stickit();
40+
return this;
41+
}
42+
43+
});
44+
45+
AddressInformation.Views.List = Backbone.View.extend({
46+
//TODO
47+
});
48+
49+
} (xtens, xtens.module("addressinformation")));

assets/js/modules/Operator.js

+34-27
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
var i18n = xtens.module('i18n').en;
66
var router = xtens.router;
77
var Group = xtens.module('group');
8+
var AddressInformation = xtens.module("addressinformation");
89
var GroupsOperator =xtens.module('groupsOperator');
910
var sexOptions = xtens.module('xtensconstants').SexOptions;
1011
var ModalDialog = xtens.module('xtensbootstrap').Views.ModalDialog;
@@ -33,6 +34,9 @@
3334

3435
Operator.Views.Edit = Backbone.View.extend({
3536

37+
tagName: 'div',
38+
className: 'operator',
39+
3640
events: {
3741
'click button.delete': 'deleteOperator',
3842
'submit .edit-operator-form': 'saveOperator'
@@ -42,6 +46,11 @@
4246
$('#main').html(this.el);
4347
this.template = JST['views/templates/operator-edit.ejs'];
4448
this.render();
49+
50+
this.personalAddressView = new AddressInformation.Views.Edit({
51+
model: new AddressInformation.Model(this.model.get("addressInformation"))
52+
});
53+
this.$("#address-information-cnt").append(this.personalAddressView.render().el);
4554
},
4655

4756
bindings: {
@@ -108,14 +117,6 @@
108117
observe: 'email'
109118
},
110119

111-
'#laboratory': {
112-
observe: 'laboratory'
113-
},
114-
115-
'#phone': {
116-
observe: 'phone'
117-
},
118-
119120
'#login': 'login'
120121

121122

@@ -132,34 +133,40 @@
132133

133134
saveOperator: function(ev) {
134135
var that = this;
136+
var addressInformation = _.clone(this.personalAddressView.model.attributes);
135137
if(!that.model.get('id')){
136138
that.model.set('password',$('#password').val());
137139
}
138-
that.model.save(null, {
139-
success: function(operator) {
140-
if (that.modal) {
141-
that.modal.hide();
142-
}
143-
var modal = new ModalDialog({
144-
title: i18n('ok'),
145-
body: i18n('operator-correctly-stored-on-server')
146-
});
147-
that.$modal.append(modal.render().el);
148-
$('.modal-header').addClass('alert-success');
149-
modal.show();
150-
151-
setTimeout(function(){ modal.hide(); }, 1200);
152-
that.$('.operator-modal').on('hidden.bs.modal', function (e) {
153-
modal.remove();
154-
xtens.router.navigate('operators', {trigger: true});
155-
});
140+
this.personalAddressView.model.save(null,{
141+
success: function(addressInformation) {
142+
that.model.save({addressInformation:addressInformation.id}, {
143+
success: function(operator) {
144+
if (that.modal) {
145+
that.modal.hide();
146+
}
147+
var modal = new ModalDialog({
148+
title: i18n('ok'),
149+
body: i18n('operator-correctly-stored-on-server')
150+
});
151+
that.$modal.append(modal.render().el);
152+
$('.modal-header').addClass('alert-success');
153+
modal.show();
156154

155+
setTimeout(function(){ modal.hide(); }, 1200);
156+
that.$('.operator-modal').on('hidden.bs.modal', function (e) {
157+
modal.remove();
158+
xtens.router.navigate('operators', {trigger: true});
159+
});
160+
},
161+
error: function(model, res) {
162+
xtens.error(res);
163+
}
164+
});
157165
},
158166
error: function(model, res) {
159167
xtens.error(res);
160168
}
161169
});
162-
163170
return false;
164171
},
165172

assets/js/modules/i18n.js

+3
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@
120120
"update-data": "Update Data",
121121
"subject": "Subject",
122122
"sample": "Sample",
123+
/* views/templates/addressinformation-edit.ejs */
124+
"office": "Office",
125+
"address-information": "Address Information",
123126
/* views/templates/operator-edit.ejs */
124127
"operator-manager": "Operator Manager",
125128
"confirm-password": "Confirm Password",

assets/styles/pages/xtens-operator.less

+23-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
#operator {
22
width: 100%;
3-
}
4-
#operator .edit-operator-form{
5-
63
}
74
#operator .col-md-6{
85
border-radius: 5px;
@@ -28,6 +25,28 @@ font-size: 16px;
2825
#edit{
2926
font-family: "Times New Roman", Times, serif;
3027
font-size: 16px;
28+
}
3129

32-
30+
.operator {
31+
width: 100%;
32+
}
33+
.operator h2,h3 {
34+
margin-top: 15px;
35+
margin-bottom: 15px;
36+
}
37+
.operator .operator-label {
38+
.make-sm-column(1);
39+
.make-xs-column(2);
40+
}
41+
.operator .operator-halfinput-div {
42+
.make-sm-column(5);
43+
.make-xs-column(10);
44+
}
45+
.operator .operator-thirdinput-div {
46+
.make-sm-column(3);
47+
.make-xs-column(10);
48+
}
49+
.operator .operator-input-div {
50+
.make-sm-column(11);
51+
.make-xs-column(10);
3352
}

0 commit comments

Comments
 (0)