-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.js
118 lines (102 loc) · 4.3 KB
/
main.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
(function ($, _) {
// config
// var endpoint = 'https://services.arcgis.com/fLeGjb7u4uXqeF9q/arcgis/rest/services/PermitAppStatusEclipse/FeatureServer/0/query'
var endpoint = 'https://services.arcgis.com/fLeGjb7u4uXqeF9q/arcgis/rest/services/AGO_Lyr_Permit_App_Status_Eclipse/FeatureServer/0/query'
// var FAILED_OR_INCOMPLETE_TEXT = "\
// PLAN REVIEW COMPLETED; IF 'APPROVED' A BILLING STATEMENT HAS BEEN \
// ISSUED BY THE DEPARTMENT TO THE PRIMARY APPLICANT. IF 'INCOMPLETE' OR \
// 'FAILED' A REQUEST FOR ADDITIONAL INFORMATION LETTER HAS BEEN ISSUED \
// BY THE DEPARTMENT TO THE PRIMARY APPLICANT; PLEASE CONTACT THE \
// PRIMARY APPLICANT AS LISTED ON THE APPLICATION FOR PERMIT.\
// ";
var FAILED_OR_INCOMPLETE_TEXT = "\
PLAN REVIEW COMPLETED; A REQUEST FOR ADDITIONAL INFORMATION HAS \
BEEN ISSUED BY THE DEPARTMENT TO THE PRIMARY APPLICANT.\
",
DATE_FORMAT = 'dddd, MMMM Do YYYY',
INVALID_DATE_TEXT = 'Review Not Yet Completed',
NO_COMPDTTM = 'PLAN REVIEW NOT YET COMPLETED; PLEASE ALLOW UNTIL THE SCHEDULED DUE DATE FOR A COMPLETED REVIEW'
var params = qs(window.location.search.substr(1))
// Use mustache.js style brackets in templates
_.templateSettings = { interpolate: /\{\{(.+?)\}\}/g }
var templates = {
result: _.template($('#tmpl-result').html()),
error: _.template($('#tmpl-error').html()),
loading: $('#tmpl-loading').html()
}
var resultContainer = $('#result')
if (params.id) {
resultContainer.html(templates.loading)
var requestParams = {
where: "APPLICATIONNUMBER = '" + params.id + "'",
outFields: '*',
f: 'pjson',
}
$.getJSON(endpoint, requestParams, function (response) {
var features = response.features
if (!features || features.length < 1) {
// If there's no feature, indicate such
resultContainer.html(templates.error({ applicationnumber: params.id }))
} else {
// Otherwise display the first feature (which should be the only
// feature)
// Rename/manipulate API response to fit our HTML template
var attrs = response.features[0].attributes
// handle comments
var status = attrs.STATUS,
comments = attrs.COMMENTS
// if failed, or incomplete and there's a review date
if (status === 'FAILED' || (status === 'INCOMPLETE' && attrs.LATESTREVIEWCOMPLETEDDATE)) {
comments = FAILED_OR_INCOMPLETE_TEXT
}
//if status is incomplete and there is no COMPDTTM
if (status === 'INCOMPLETE' && (!attrs.LATESTREVIEWCOMPLETEDDATE || attrs.LATESTREVIEWCOMPLETEDDATE === '')) {
comments = NO_COMPDTTM
}
console.log('testing')
function formatDate(input) {
var dateFormatted
// make sure date isn't just whitespace
if (!/\S/.test(input)) {
input = null;
}
// if we have a valid string
if (input) {
// format it with moment
dateFormatted = moment(input).utc().format(DATE_FORMAT)
}
// otherwise return invalid date text
else {
dateFormatted = INVALID_DATE_TEXT
}
return dateFormatted
}
var templateData = {
applicationnumber: attrs.APPLICATIONNUMBER,
comments: comments,
status: status,
address: attrs.ADDRESS,
applicationdate: formatDate(attrs.APPLICATIONDATE),
latestreviewduedate: formatDate(attrs.LATESTREVIEWDUEDATE),
applicationdescription: attrs.APPLICATIONDESCRIPTION,
latestreviewcompleteddate: formatDate(attrs.LATESTREVIEWCOMPLETEDDATE),
}
// Render template
resultContainer.html(templates.result(templateData))
}
}).fail(function () {
resultContainer.html(templates.error({ applicationnumber: params.id }))
})
}
// decode a uri into a kv representation :: str -> obj
// https://github.com/yoshuawuyts/sheet-router/blob/master/qs.js
function qs(uri) {
var obj = {}
var reg = new RegExp('([^?=&]+)(=([^&]*))?', 'g')
uri.replace(/^.*\?/, '').replace(reg, map)
return obj
function map(a0, a1, a2, a3) {
obj[window.decodeURIComponent(a1)] = window.decodeURIComponent(a3)
}
}
})(window.jQuery, window._)