-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathaddcontact.js
More file actions
119 lines (103 loc) · 4.05 KB
/
addcontact.js
File metadata and controls
119 lines (103 loc) · 4.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
define(['views/form',
'models/labcontact',
'collections/countries',
'collections/users',
'templates/contact/contactadd.html',
'jquery',
'backbone',
'backbone-validation',
], function(FormView,
Contact, Countries, Users,
template, $_, Backbone) {
return FormView.extend({
template: template,
ui: {
country: 'select[name=COUNTRY]',
pid: 'select[name=PERSONID]',
cn: 'input[name=CARDNAME]',
fn: 'input[name=FAMILYNAME]',
gn: 'input[name=GIVENNAME]',
pn: 'input[name=PHONENUMBER]',
ea: 'input[name=EMAILADDRESS]',
ln: 'input[name=LABNAME]',
ad: 'textarea[name=ADDRESS]',
ci: 'input[name=CITY]',
pc: 'input[name=POSTCODE]',
lb: '.leaveblank',
},
events: {
'change @ui.pid': 'fillUserInfo',
'change @ui.country': 'onCountryChange',
},
onCountryChange: function() {
let country = this.ui.country.val()
if (
app.options.get('facility_courier_countries').indexOf(country) > -1 ||
app.options.get('facility_courier_countries_nde').indexOf(country) > -1
) {
this.ui.lb.html('<br />Academic users from '+country+' can leave this blank to use the facility courier.')
} else {
this.ui.lb.html('')
}
},
fillUserInfo: function() {
var u = this.users.findWhere({ PERSONID: this.ui.pid.val() })
if (u){
this.ui.cn.val(u.get('FULLNAME'))
this.ui.fn.val(u.get('FAMILYNAME'))
this.ui.gn.val(u.get('GIVENNAME'))
this.ui.pn.val(u.get('PHONENUMBER'))
this.ui.ea.val(u.get('EMAILADDRESS'))
this.ui.ln.val(u.get('LABNAME'))
this.ui.ad.val(u.get('ADDRESS'))
this.ui.ci.val(u.get('CITY'))
this.ui.pc.val(u.get('POSTCODE'))
this.ui.country.val(u.get('COUNTRY'))
}
},
initialize: function() {
this.countries = new Countries()
this.countries.state.pageSize = 9999
this.users = new Users()
this.users.state.pageSize = 9999
this.users.queryParams.login = 1
},
createModel: function() {
this.model = new Contact()
},
onRender: function() {
Promise.all([this.countries.fetch(), this.users.fetch()]).then(() => {
this.populateCountries();
this.populateUsers();
this.onCountryChange();
})
this.ui.ad.css('height', '100px')
this.ui.ad.css('width', '50%')
},
populateCountries: function() {
this.ui.country.html(this.countries.opts())
},
populateUsers: function() {
// only want to display the current user
var u = this.users.findWhere({ PERSONID: app.personid.toString() })
var opts = '<option value=""> - </option>'
opts += '<option value="'+u.get('PERSONID')+'">'+u.get('FULLNAME')+'</option>'
this.ui.pid.html(opts)
},
success: function(model, response, options) {
console.log('success from contact add')
if (this.getOption('dialog')) {
app.message({ message: 'New Lab Contact Registered' })
if (app.dialog.currentView) app.dialog.currentView.closeDialog()
} else app.trigger('contact:show', model.get('LABCONTACTID'))
},
failure: function(model, response, options) {
console.log('failure from contact add')
var message = 'Something went wrong registering this lab contact'
if (response && response.responseJSON && response.responseJSON.message) {
message += ': '+response.responseJSON.message
}
app.alert({ message: message })
},
})
})