-
Notifications
You must be signed in to change notification settings - Fork 205
/
PersonsModel.js
executable file
·174 lines (149 loc) · 9.23 KB
/
PersonsModel.js
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
define([
'Backbone',
'Underscore',
'moment',
'Validation',
'constants'
], function (Backbone, _, moment, Validation, CONSTANTS) {
'use strict';
var PersonModel = Backbone.Model.extend({
idAttribute: '_id',
initialize : function () {
this.on('invalid', function (model, errors) {
var msg;
if (errors.length > 0) {
msg = errors.join('\n');
App.render({
type : 'error',
message: msg
});
}
});
},
parse: function (response) {
if (!response.data) {
if (response.createdBy) {
response.createdBy.date = moment(response.createdBy.date).format('DD MMM, YYYY, H:mm:ss');
}
if (response.editedBy && response.editedBy.length !== 24) {
response.editedBy.date = moment(response.editedBy.date).format('DD MMM, YYYY, H:mm:ss');
}
if (response.dateBirth) {
response.dateBirth = moment(response.dateBirth).format('DD MMM, YYYY');
}
if (response.social && response.social.LI) {
response.social.LI = response.social.LI.replace('[]', 'linkedin');
}
if (response.notes) {
_.map(response.notes, function (note) {
note.date = moment(new Date(note.date));
// note.date = moment(note.date).format('DD MMM, YYYY, H:mm:ss');
if (note.history && (note.history.changedField === 'Date of Birth' || note.history.changedField === 'Creation Date')) {
note.history.changedValue = note.history.changedValue ? moment(new Date(note.history.changedValue)).format('DD MMM, YYYY') : '';
note.history.newValue = note.history.newValue ? moment(new Date(note.history.newValue)).format('DD MMM, YYYY') : '';
note.history.prevValue = note.history.prevValue ? moment(new Date(note.history.prevValue)).format('DD MMM, YYYY') : '';
}
if (note.history && note.history.changedField === 'LinkedIn') {
note.history.changedValue = note.history.changedValue ? note.history.changedValue.replace('[]', 'linkedin') : '';
note.history.newValue = note.history.newValue ? note.history.newValue.replace('[]', 'linkedin') : '';
note.history.prevValue = note.history.prevValue ? note.history.prevValue.replace('[]', 'linkedin') : '';
}
return note;
});
/*response.notes.forEach(function (note, index) {
if (!note.name && note.history && (note.history.changedField === 'Creation Date')) {
response.notes.splice(index, 1);
response.notes.unshift(note);
return;
}
});
response.notes.forEach(function (note, index) {
if (note.task && (note.task.workflow.status !== 'Done') && (note.task.workflow.status !== 'Cancelled')) {
response.notes.splice(index, 1);
response.notes.push(note);
return;
}
});*/
}
if (response.attachments) {
_.map(response.attachments, function (attachment) {
attachment.uploadDate = moment(attachment.uploadDate).format('DD MMM, YYYY, H:mm:ss');
return attachment;
});
}
return response;
}
},
validate: function (attrs) {
var errors = [];
Validation.checkNameField(errors, true, attrs['name.first'] || attrs.name.first, 'First name');
Validation.checkNameField(errors, true, attrs['name.last'] || attrs.name.last, 'Last name');
Validation.checkPhoneField(errors, false, attrs['phones.phone'] || attrs.phones.phone, 'Phone');
Validation.checkPhoneField(errors, false, attrs['phones.mobile'] || attrs.phones.mobile, 'Mobile');
Validation.checkPhoneField(errors, false, attrs['phones.fax'] || attrs.phones.fax, 'Fax');
Validation.checkCountryCityStateField(errors, false, attrs['address.country'] || attrs.address.country, 'Country');
Validation.checkCountryCityStateField(errors, false, attrs['address.state'] || attrs.address.state, 'State');
Validation.checkCountryCityStateField(errors, false, attrs['address.city'] || attrs.address.city, 'City');
Validation.checkZipField(errors, false, attrs['address.zip'] || attrs.address.zip, 'Zip');
Validation.checkStreetField(errors, false, attrs['address.street'] || attrs.address.street, 'Street');
Validation.checkCountryCityStateField(errors, false, attrs['shippingAddress.country'] || attrs.address.country, 'Shipping Country');
Validation.checkCountryCityStateField(errors, false, attrs['shippingAddress.state'] || attrs.address.state, 'Shipping State');
Validation.checkCountryCityStateField(errors, false, attrs['shippingAddress.city'] || attrs.address.city, 'Shipping City');
Validation.checkZipField(errors, false, attrs['shippingAddress.zip'] || attrs.address.zip, 'Shipping Zip');
Validation.checkStreetField(errors, false, attrs['shippingAddress.street'] || attrs.address.street, 'Shipping Street');
Validation.checkNameField(errors, false, attrs.jobPosition, 'Job position');
Validation.checkSkypeField(errors, false, attrs.skype, 'Skype');
Validation.checkEmailField(errors, false, attrs.email, 'Email');
Validation.checkFacebookSocial(errors, false, attrs.social.FB, 'Facebook');
Validation.checkLinkedinSocial(errors, false, attrs.social.LI, 'LinkedIn');
if (errors.length > 0) {
return errors;
}
},
defaults: {
id : null,
imageSrc: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAAAAACPAi4CAAAACXBIWXMAAABIAAAASABGyWs+AAAACXZwQWcAAABAAAAAQADq8/hgAAAEaElEQVRYw82X6XLbNhCA+f4PVomk5MRyHDtp63oEgDcl3vfRBQhQIEVKSvsnO+OxRBEfFnthV+n/pyi/NaCryzzL8rJu/wOgzQPXJBgjhDExnXPW/Aqgy30DI0yIwYQQ4Bhe2j0I6BIbI1jL9meC2TdkRu0jgMxCGN5H2HT8IIzjKPAdE9NngEjuAhqfv3rOpe3aIrDAFoB1qtuA3ADlMXKuz9vlLqZokt4CxPAOQXa2bPDCRVSJYB0QIDA4ibp+TVKDbuCvAeh6YpX9DWkcUGJCkAARXW9UfXeL0PmUcF4CZBA4cALv5nqQM+yD4mtATQMOGMi9RzghiKriCuBiAzsB1e8uwUUGtroZIAEsqfqHCI2JjdGZHNDSZzHYb0boQK4JOTVXNQFEoJXDPskEvrYTrJHgIwOdZEBrggXzfkbo+sY7Hp0Fx9bUYbUEAAtgV/waHAcCnOew3arbLy5lVXGSXIrKGQkrKKMLcnHsPjEGAla1PYi+/YCV37e7DRp1qUDjwREK1wjbo56hezRoPLxt9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xMC0xMi0yMVQxNDozMDo0NCswMTowMGxOe/8AAAAZdEVYdFNvZnR3YXJlAEFkb2JlIEltYWdlUmVhZHlxyWU8AAAAAElFTkSuQmCC',
type : 'Person',
name : {
first: '',
last : ''
},
email : '',
address: {
street1: '',
street2: '',
city : '',
zip : '',
country: '',
state : ''
},
shippingAddress: {
street1: '',
street2: '',
city : '',
zip : '',
country: '',
state : ''
},
website : '',
jobPosition: '',
skype : '',
phones : {
phone : '',
mobile: '',
fax : ''
},
salesPurchases: {
isCustomer: true
},
department : null,
dateBirth : null,
attachments: [],
notes : []
},
urlRoot: function () {
return CONSTANTS.URLS.PERSONS;
}
});
return PersonModel;
});