-
Notifications
You must be signed in to change notification settings - Fork 0
/
WG-Snagging.js
215 lines (173 loc) · 5.6 KB
/
WG-Snagging.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
// data events for fulcrum app [WG] Snagging
// version 0.5
var BP = ['[GR] Road Site Inspector','[BP] Inspector','Owner','[BP] admin L2'];
var MC = ['[CON-M] Site Inspector'];
var CON = ['[CON] Site Inspector'];
var storage = STORAGE();
// // require portrait image
// ON('add-photo', 'photos', function(event) {
// if (event.value.width > event.value.height) {
// INVALID('Please retake the photo in portrait orientation.');
// }
// });
// // Auto-increment feature: when saving the record, save the value to storage to use next time.
// ON('save-record', function(event) {
// storage.setItem('ref_value', $id);
// if (ISROLE(admin))
// {
// var fieldArray = ['contractor_photos','contractor_remarks']
// fieldArray.forEach(function(dataName)
// {
// SETREADONLY(dataName, true);
// })
// }
// });
ON('new-record', function(event) {
// var idStorage = NUM(storage.getItem('ref_value'))+1
// SETVALUE('id', idStorage)
// if (ISROLE(admin))
// {
// var fieldArray = ['contractor_photos','contractor_remarks']
// fieldArray.forEach(function(dataName)
// {
// SETREADONLY(dataName, true);
// })
// }
if (ISROLE(MC))
{
var fieldArray = ['contractor_photos','contractor_remarks']
fieldArray.forEach(function(dataName)
{
SETREADONLY(dataName, true);
})
SETSTATUSFILTER(['Snag identified','Action required','Re-inspection required','Snag lifted']);
//if (!PROJECTNAME()) {
//INVALID('Please select a project before saving.');
//};
}
});
ON('validate-record', function(event) {
if (ISROLE(CON))
// if contractor
{
var fieldArray = ['id','discipline','remarks','recommended_actions','photos']
fieldArray.forEach(function(dataName)
{
SETREADONLY(dataName, true);
})
SETSTATUSFILTER(['Action required','Works in progress','Re-inspection required']);
//SETHIDDEN('item_description', false)
//SETHIDDEN('phase', true)
// prevent manual location changes
var config = {
// auto_sync_enabled: true,
// auto_location_enabled: true,
// auto_location_minimum_accuracy: 20,
manual_location_enabled: false
// media_gallery_enabled: false,
// media_capture_enabled: true,
// photo_quality: '2048',
// video_quality: '720p',
// drafts_enabled: false,
// edit_locations_enabled: true,
// edit_durations_enabled: true
};
SETFORMATTRIBUTES(config);
var lat = LATITUDE();
var lng = LONGITUDE();
var location = CURRENTLOCATION();
if (!location)
{
// ALERT('No Location Available');
return;
}
var latitude = location.latitude;
var longitude = location.longitude;
var minLatitude = lat - 0.000300;
var maxLatitude = lat + 0.000300;
var minLongitude = lng - 0.000300;
var maxLongitude = lng + 0.000300;
if (!(latitude <= maxLatitude && latitude >= minLatitude && longitude <= maxLongitude && longitude >= minLongitude))
{
INVALID("You are not close enough to the records to make changes.");
SETSTATUSREADONLY(true);
}
}
// admin permissions
if (ISROLE(MC))
{
var fieldArray = ['contractor_photos','contractor_remarks']
fieldArray.forEach(function(dataName)
{
SETREADONLY(dataName, true);
})
SETSTATUSFILTER(['Snag identified','Action required','Re-inspection required','Snag lifted']);
//if (!PROJECTNAME()) {
//INVALID('Please select a project before saving.');
//};
}
});
ON('edit-record', function(event) {
// contractor permissions
if (ISROLE(CON))
{
var fieldArray = ['id','discipline','remarks','recommended_actions','photos']
fieldArray.forEach(function(dataName)
{
SETREADONLY(dataName, true);
})
SETSTATUSFILTER(['Action required','Works in progress','Re-inspection required']);
//SETHIDDEN('item_description', false)
//SETHIDDEN('phase', true)
//if((admin.indexOf($updated_by_role)!== -1) && 'no'.indexOf($3rd_party_damage)!== -1)
//{
// ALERT('Client and Consultant have agreed that this item is not a 3rd party damage. You cannot change the 3rd party damage field anymore.');
// SETREADONLY('3rd_party_damage', true);
//}
// prevent manual location changes
var config = {
// auto_sync_enabled: true,
// auto_location_enabled: true,
// auto_location_minimum_accuracy: 20,
manual_location_enabled: false
// media_gallery_enabled: false,
// media_capture_enabled: true,
// photo_quality: '2048',
// video_quality: '720p',
// drafts_enabled: false,
// edit_locations_enabled: true,
// edit_durations_enabled: true
};
SETFORMATTRIBUTES(config);
var lat = LATITUDE();
var lng = LONGITUDE();
var location = CURRENTLOCATION();
if (!location)
{
// ALERT('No Location Available');
return;
}
var latitude = location.latitude;
var longitude = location.longitude;
var minLatitude = lat - 0.000300;
var maxLatitude = lat + 0.000300;
var minLongitude = lng - 0.000300;
var maxLongitude = lng + 0.000300;
if (!(latitude <= maxLatitude && latitude >= minLatitude && longitude <= maxLongitude && longitude >= minLongitude))
{
INVALID("It looks like you are not close to the tree to make changes.");
SETSTATUSREADONLY(true);
}
}
// admin permissions
if (ISROLE(MC))
{
var fieldArray = ['contractor_photos', 'contractor_remarks']
fieldArray.forEach(function(dataName)
{
SETREADONLY(dataName, true);
})
SETSTATUSFILTER(['Snag identified','Action required','Re-inspection required','Snag lifted']);
}
});
// the end