-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
269 lines (216 loc) · 6.75 KB
/
utils.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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
/*
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
/*
* Utility Javascript methods for DSpace
*/
// Popup window - here so it can be referred to by several methods
var popupWindow;
// =========================================================
// Methods for e-person popup window
// =========================================================
// Add to list of e-people on this page -- invoked by eperson popup window
function addEPerson(id, email, name)
{
var newplace = window.document.epersongroup.eperson_id.options.length;
if (newplace > 0 && window.document.epersongroup.eperson_id.options[0].value == "")
{
newplace = 0;
}
// First we check to see if e-person is already there
for (var i = 0; i < window.document.epersongroup.eperson_id.options.length; i++)
{
if (window.document.epersongroup.eperson_id.options[i].value == id)
{
newplace = -1;
}
}
if (newplace > -1)
{
window.document.epersongroup.eperson_id.options[newplace] = new Option(name + " (" + email + ")", id);
}
}
// Add to list of groups on this page -- invoked by eperson popup window
function addGroup(id, name)
{
var newplace = window.document.epersongroup.group_ids.options.length;
if (newplace > 0 && window.document.epersongroup.group_ids.options[0].value == "")
{
newplace = 0;
}
// First we check to see if group is already there
for (var i = 0; i < window.document.epersongroup.group_ids.options.length; i++)
{
// is it in the list already
if (window.document.epersongroup.group_ids.options[i].value == id)
{
newplace = -1;
}
// are we trying to add the new group to the new group on an Edit Group page (recursive)
if (window.document.epersongroup.group_id)
{
if (window.document.epersongroup.group_id.value == id)
{
newplace = -1;
}
}
}
if (newplace > -1)
{
window.document.epersongroup.group_ids.options[newplace] = new Option(name + " (" + id + ")", id);
}
}
// This needs to be invoked in the 'onClick' javascript event for buttons
// on pages with a dspace:selecteperson element in them
function finishEPerson()
{
selectAll(window.document.epersongroup.eperson_id);
if (popupWindow != null)
{
popupWindow.close();
}
}
// This needs to be invoked in the 'onClick' javascript event for buttons
// on pages with a dspace:selecteperson element in them
function finishGroups()
{
selectAll(window.document.epersongroup.group_ids);
if (popupWindow != null)
{
popupWindow.close();
}
}
// =========================================================
// Miscellaneous utility methods
// =========================================================
// Open a popup window (or bring to front if already open)
function popup_window(winURL, winName)
{
var props = 'scrollBars=yes,resizable=yes,toolbar=no,menubar=no,location=no,directories=no,width=640,height=480';
popupWindow = window.open(winURL, winName, props);
popupWindow.focus();
}
// Select all options in a <SELECT> list
function selectAll(sourceList)
{
for(var i = 0; i < sourceList.options.length; i++)
{
if ((sourceList.options[i] != null) && (sourceList.options[i].value != ""))
sourceList.options[i].selected = true;
}
return true;
}
// Deletes the selected options from supplied <SELECT> list
function removeSelected(sourceList)
{
var maxCnt = sourceList.options.length;
for(var i = maxCnt - 1; i >= 0; i--)
{
if ((sourceList.options[i] != null) && (sourceList.options[i].selected == true))
{
sourceList.options[i] = null;
}
}
}
// Disables accidentally submitting a form when the "Enter" key is pressed.
// Just add "onkeydown='return disableEnterKey(event);'" to form.
function disableEnterKey(e)
{
var key;
if(window.event)
key = window.event.keyCode; //Internet Explorer
else
key = e.which; //Firefox & Netscape
if(key == 13) //if "Enter" pressed, then disable!
return false;
else
return true;
}
//******************************************************
// Functions used by controlled vocabulary add-on
// There might be overlaping with existing functions
//******************************************************
function expandCollapse(node, contextPath) {
node = node.parentNode;
var childNode = (node.getElementsByTagName("ul"))[0];
if(!childNode) return false;
var image = node.getElementsByTagName("img")[0];
if(childNode.style.display != "block") {
childNode.style.display = "block";
image.src = contextPath + "/image/controlledvocabulary/m.gif";
image.alt = "Collapse search term category";
} else {
childNode.style.display = "none";
image.src = contextPath + "/image/controlledvocabulary/p.gif";
image.alt = "Expand search term category";
}
return false;
}
function getAnchorText(ahref) {
if(isMicrosoft()) return ahref.childNodes.item(0).nodeValue;
else return ahref.text;
}
function getTextValue(node) {
if(node.nodeName == "A") {
return getAnchorText(node);
} else {
return "";
}
}
function getParentTextNode(node) {
var parentNode = node.parentNode.parentNode.parentNode;
var children = parentNode.childNodes;
var textNode;
for(var i=0; i< children.length; i++) {
var child = children.item(i);
if(child.className == "value") {
return child;
}
}
return null;
}
function ec(node, contextPath) {
expandCollapse(node, contextPath);
return false;
}
function i(node) {
return sendBackToParentWindow(node);
}
function getChildrenByTagName(rootNode, tagName) {
var children = rootNode.childNodes;
var result = new Array(0);
if(children == null) return result;
for(var i=0; i<children.length; i++) {
if(children[i].tagName == tagName) {
var elementArray = new Array(1);
elementArray[0] = children[i];
result = result.concat(elementArray);
}
}
return result;
}
function popUp(URL) {
var page;
page = window.open(URL, 'controlledvocabulary', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=650,height=450');
}
function isNetscape(v) {
return isBrowser("Netscape", v);
}
function isMicrosoft(v) {
return isBrowser("Microsoft", v);
}
function isMicrosoft() {
return isBrowser("Microsoft", 0);
}
function isBrowser(b,v) {
browserOk = false;
versionOk = false;
browserOk = (navigator.appName.indexOf(b) != -1);
if (v == 0) versionOk = true;
else versionOk = (v <= parseInt(navigator.appVersion));
return browserOk && versionOk;
}