-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtrello-search.js
163 lines (141 loc) · 5.1 KB
/
trello-search.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
$(document).ready(function() {
window.onload = function WindowLoad() {
query = window.location.search.substring(1).split("&");
// Parses the URL to extract the keyword value if a URL parameter is present.
if (query[0] !== '') {
params = new String();
for (p = 0; p < query.length; p++) {
params[query[p].split("=")[0]] = query[p].split("=")[1]
}
keyword = params.q
loadresults(keyword)
}
}
// Allow users to use 'enter' key on search box.
$('#keyword').keypress(function(enter){
if(enter.keyCode==13)
$('#input').click();
});
function loadresults(keyword) {
$('#topresults').html('<tr><td colspan="5"><center><img width=500 src="https://catalog.archives.gov/images/loader.gif"/></center></td></tr>');
$('#table').show();
var url = 'https://trello.com/b/koF9BuSn/fielded-digitization-tracking-board.json'
$.getJSON(url, function(t) {
var top_results = ''
var load_results = ''
count = 0;
for (n = 0; n < t.cards.length; n++) {
var title = t.cards[n].name;
var pub = '';
var naid = '';
var record_group = '';
var digi_by = '';
var list = t.cards[n].idList;
var status = '';
// Available on Partner Website
if (list == '5a27058566eaed7756e33deb') {
var status = 'style="background-color: #B28DFF"'
};
// Awaiting Processing at NARA
if (list == '5a27058566eaed7756e33dec') {
var status = 'style="background-color: #FFF5BA"'
};
// Being Processed at NARA
if (list == '5a27058566eaed7756e33ded') {
var status = 'style="background-color: #AFCBFF"'
};
// Available in National Archives Catalog
if (list == '5a27058566eaed7756e33dee') {
var status = 'style="background-color: #AFF8DB"'
};
for (u = 0; u < t.cards[n].customFieldItems.length; u++) {
var code = t.cards[n].customFieldItems[u].idCustomField
if (code == '5a986700d6afbd6de1c1fa91') {
var pub = t.cards[n].customFieldItems[u].value.text
};
if (code == '5a986700d6afbd6de1c1fa8f') {
var naid = t.cards[n].customFieldItems[u].value.number
};
if (code == '5a986700d6afbd6de1c1fa8d') {
var record_group = t.cards[n].customFieldItems[u].value.number
};
if (code == '5a986700d6afbd6de1c1fa93') {
if (t.cards[n].customFieldItems[u].idValue == '5a986700d6afbd6de1c1fa94') {
var digi_by = 'Partner'
};
if (t.cards[n].customFieldItems[u].idValue == '5a986700d6afbd6de1c1fa95') {
var digi_by = 'NARA'
}
};
}
avail = '';
for (r = 0; r < t.cards[n].attachments.length; r++) {
avail = avail + '<a href="' + t.cards[n].attachments[r].url + '">' + t.cards[n].attachments[r].name.replace('Ancestry@nara', 'Ancestry@NARA') + '</a><br/>'
if (t.cards[n].attachments[r].name.toLowerCase().includes('ancestry@nara')) {
avail = avail + '<a href="' + t.cards[n].attachments[r].url.replace('search.ancestryinstitution', 'search.ancestry') + '">' + 'Ancestry$' + '</a><br/>'
}
if (t.cards[n].attachments[r].name.toLowerCase().includes('ancestry$')) {
avail = avail + '<a href="' + t.cards[n].attachments[r].url.replace('search.ancestry.', 'search.ancestryinstitution.') + '">' + 'Ancestry@NARA' + '</a><br/>'
}
}
var last_activity = new Date(t.cards[n].dateLastActivity)
last_activity = last_activity.toString()
//
// var urlRegex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
// description = description.replace(urlRegex, function(url) {
// return '<a href="' + url + '">' + url + '</a>';
// });
if (naid != '') {
var catalog_url = 'https://catalog.archives.gov/id/' + naid
var title_url = '<a href="' + catalog_url + '">' + title + '</a>'
}
else {
var title_url = title
}
new_result = '<tr title="Last updated: ' + last_activity + '" scope="row"> <td ' + status + '> </td> <td>' + pub + '</td> <td>' + title_url + '</td> <td>' + avail + '</td> <td>' + record_group + '</td> </tr>'
if (count <= 9) {
if ((keyword != '') && (keyword != '*')) {
if (new_result.toLowerCase().includes(keyword.toLowerCase())) {
top_results = top_results + new_result;
count = count + 1
}
}
else {
top_results = top_results + new_result;
count = count + 1
}
}
else {
if ((keyword != '') && (keyword != '*')) {
if (new_result.toLowerCase().includes(keyword.toLowerCase())) {
load_results = load_results + new_result;
count = count + 1
}
}
else {
load_results = load_results + new_result;
count = count + 1
}
}
}
$('#resultcount').html('There are <u>' + count + '</u> <span style="color:#993333">results</span> for this search.');
$('#topresults').html(top_results)
$('#loadresults').html(load_results)
if (count > 10) {
$('#load').show();
}
});
}
$("#input").click(function(event){
var url = window.location.pathname;
keyword = $('#keyword').val();
if (keyword !== '') { keyword = '?q=' + keyword };
newUrl=url.replace(keyword,"");
newUrl+=keyword;
window.location.href = newUrl;
});
$("#load").click(function(event){
$('#load').hide();
$('#loadresults').show();
});
})