6157 |
02 Mar 21 |
nicklas |
var VarSearch = function() |
6157 |
02 Mar 21 |
nicklas |
2 |
{ |
6157 |
02 Mar 21 |
nicklas |
var varsearch = {}; |
6157 |
02 Mar 21 |
nicklas |
var HOME = null; |
6157 |
02 Mar 21 |
nicklas |
5 |
|
7307 |
28 Aug 23 |
nicklas |
varsearch.VERSION = '1.10-dev'; |
6160 |
04 Mar 21 |
nicklas |
7 |
|
6160 |
04 Mar 21 |
nicklas |
varsearch.checkIsAdmin = function(message, callback, servletDir) |
6160 |
04 Mar 21 |
nicklas |
9 |
{ |
6160 |
04 Mar 21 |
nicklas |
var url = (servletDir || '../') + 'Session.servlet?ID='+App.getSessionId(); |
6160 |
04 Mar 21 |
nicklas |
url += '&cmd=CheckIsAdmin'; |
6160 |
04 Mar 21 |
nicklas |
if (message) url += '&message='+encodeURIComponent(message); |
6160 |
04 Mar 21 |
nicklas |
if (!callback) callback = function() {}; |
6160 |
04 Mar 21 |
nicklas |
Wizard.asyncJsonRequest(url, callback); |
6160 |
04 Mar 21 |
nicklas |
15 |
} |
6160 |
04 Mar 21 |
nicklas |
16 |
|
6157 |
02 Mar 21 |
nicklas |
varsearch.initElements = function(element, autoInit) |
6157 |
02 Mar 21 |
nicklas |
18 |
{ |
6170 |
17 Mar 21 |
nicklas |
if (autoInit == 'varsearch-options') |
6170 |
17 Mar 21 |
nicklas |
20 |
{ |
6170 |
17 Mar 21 |
nicklas |
Events.addEventHandler(element, 'click', varsearch.showOptions); |
6170 |
17 Mar 21 |
nicklas |
22 |
} |
6170 |
17 Mar 21 |
nicklas |
else if (autoInit == 'varsearch-hit') |
6170 |
17 Mar 21 |
nicklas |
24 |
{ |
6170 |
17 Mar 21 |
nicklas |
Events.addEventHandler(element, 'click', varsearch.showHitDetails); |
6170 |
17 Mar 21 |
nicklas |
26 |
} |
6522 |
20 Dec 21 |
nicklas |
else if (autoInit == 'varsearch-rba-hits') |
6522 |
20 Dec 21 |
nicklas |
28 |
{ |
6522 |
20 Dec 21 |
nicklas |
Events.addEventHandler(element, 'click', varsearch.showRbaHits); |
6522 |
20 Dec 21 |
nicklas |
30 |
} |
6189 |
29 Mar 21 |
nicklas |
else if (autoInit == 'varsearch-hide-col') |
6189 |
29 Mar 21 |
nicklas |
32 |
{ |
6190 |
29 Mar 21 |
nicklas |
var draggable = element.parentNode; |
6189 |
29 Mar 21 |
nicklas |
Events.addEventHandler(element, 'click', varsearch.hideColumn); |
6190 |
29 Mar 21 |
nicklas |
Events.addEventHandler(draggable, 'dragstart', varsearch.beginColumnDrag); |
6190 |
29 Mar 21 |
nicklas |
Events.addEventHandler(draggable, 'dragover', varsearch.checkColumnDropTarget); |
6190 |
29 Mar 21 |
nicklas |
Events.addEventHandler(draggable, 'dragleave', varsearch.leaveColumnDropTarget); |
6190 |
29 Mar 21 |
nicklas |
Events.addEventHandler(draggable, 'drop', varsearch.columnDropped); |
6190 |
29 Mar 21 |
nicklas |
Events.addEventHandler(draggable, 'dragend', varsearch.endColumnDrag); |
6189 |
29 Mar 21 |
nicklas |
40 |
} |
6157 |
02 Mar 21 |
nicklas |
41 |
} |
6157 |
02 Mar 21 |
nicklas |
42 |
|
6157 |
02 Mar 21 |
nicklas |
varsearch.showOptions = function(event) |
6157 |
02 Mar 21 |
nicklas |
44 |
{ |
6157 |
02 Mar 21 |
nicklas |
var url = varsearch.getHome()+'options.jsp?ID='+App.getSessionId(); |
6157 |
02 Mar 21 |
nicklas |
url += '&indexId='+Data.get(event.currentTarget, 'index-id'); |
6157 |
02 Mar 21 |
nicklas |
Dialogs.openPopup(url, 'VarSearchOptions', 600, 400); |
6157 |
02 Mar 21 |
nicklas |
48 |
} |
6189 |
29 Mar 21 |
nicklas |
49 |
|
6190 |
29 Mar 21 |
nicklas |
varsearch.setVisibleColumns = function(indexId, columns) |
6190 |
29 Mar 21 |
nicklas |
51 |
{ |
6190 |
29 Mar 21 |
nicklas |
var url = varsearch.getHome()+'Session.servlet?ID='+App.getSessionId(); |
6190 |
29 Mar 21 |
nicklas |
url += '&cmd=SetVisibleColumns'; |
6190 |
29 Mar 21 |
nicklas |
url += '&indexId='+encodeURIComponent(indexId); |
6190 |
29 Mar 21 |
nicklas |
url += '&visibleColumns='+encodeURIComponent(columns); |
6190 |
29 Mar 21 |
nicklas |
Wizard.asyncJsonRequest(url, varsearch.reloadPage, 'POST'); |
6190 |
29 Mar 21 |
nicklas |
57 |
} |
6190 |
29 Mar 21 |
nicklas |
58 |
|
6189 |
29 Mar 21 |
nicklas |
varsearch.hideColumn = function(event) |
6189 |
29 Mar 21 |
nicklas |
60 |
{ |
6190 |
29 Mar 21 |
nicklas |
var element = event.currentTarget.parentNode; |
6190 |
29 Mar 21 |
nicklas |
var colToHide = Data.get(element, 'col'); |
6190 |
29 Mar 21 |
nicklas |
var indexId = Data.get(element, 'index-id'); |
6189 |
29 Mar 21 |
nicklas |
// Find all other columns for the same index |
6278 |
04 Jun 21 |
nicklas |
var visible = varsearch.getVisibleColumns(indexId, colToHide); |
6190 |
29 Mar 21 |
nicklas |
varsearch.setVisibleColumns(indexId, visible.join(',')); |
6190 |
29 Mar 21 |
nicklas |
67 |
} |
6190 |
29 Mar 21 |
nicklas |
68 |
|
6190 |
29 Mar 21 |
nicklas |
69 |
/** |
6190 |
29 Mar 21 |
nicklas |
Get all visible column for the given index. |
6190 |
29 Mar 21 |
nicklas |
71 |
*/ |
6190 |
29 Mar 21 |
nicklas |
varsearch.getVisibleColumns = function(indexId, except) |
6190 |
29 Mar 21 |
nicklas |
73 |
{ |
6189 |
29 Mar 21 |
nicklas |
var visible = []; |
6189 |
29 Mar 21 |
nicklas |
var cols = document.getElementsByClassName('hide-col'); |
6189 |
29 Mar 21 |
nicklas |
for (var i = 0; i < cols.length; i++) |
6189 |
29 Mar 21 |
nicklas |
77 |
{ |
6190 |
29 Mar 21 |
nicklas |
var col = cols[i].parentNode; |
6190 |
29 Mar 21 |
nicklas |
if (Data.get(col, 'index-id') == indexId) |
6189 |
29 Mar 21 |
nicklas |
80 |
{ |
6190 |
29 Mar 21 |
nicklas |
if (except && Data.get(col, 'col') == except) continue; |
6190 |
29 Mar 21 |
nicklas |
visible[visible.length] = Data.get(col, 'col'); |
6189 |
29 Mar 21 |
nicklas |
83 |
} |
6189 |
29 Mar 21 |
nicklas |
84 |
} |
6190 |
29 Mar 21 |
nicklas |
return visible; |
6190 |
29 Mar 21 |
nicklas |
86 |
} |
6190 |
29 Mar 21 |
nicklas |
87 |
|
6190 |
29 Mar 21 |
nicklas |
88 |
/** |
6190 |
29 Mar 21 |
nicklas |
Start dragging a table column. Store table-id, column-id |
6190 |
29 Mar 21 |
nicklas |
and column-index on the table element. |
6190 |
29 Mar 21 |
nicklas |
91 |
*/ |
6190 |
29 Mar 21 |
nicklas |
varsearch.beginColumnDrag = function(event) |
6190 |
29 Mar 21 |
nicklas |
93 |
{ |
6190 |
29 Mar 21 |
nicklas |
var dragSrc = {}; |
6190 |
29 Mar 21 |
nicklas |
dragSrc.indexId = Data.get(event.currentTarget, 'index-id'); |
6190 |
29 Mar 21 |
nicklas |
dragSrc.col = Data.get(event.currentTarget, 'col'); |
6190 |
29 Mar 21 |
nicklas |
dragSrc.colNo = Data.int(event.currentTarget, 'col-no'); |
6189 |
29 Mar 21 |
nicklas |
98 |
|
6190 |
29 Mar 21 |
nicklas |
// Store the drag data on the <div> grid element |
6190 |
29 Mar 21 |
nicklas |
Doc.element('varsearch-header.'+dragSrc.indexId).dragSrc = dragSrc; |
6190 |
29 Mar 21 |
nicklas |
event.dataTransfer.effectAllowed = 'move'; |
6190 |
29 Mar 21 |
nicklas |
// In FF, we also need to call setData() or the drag event will not start |
6190 |
29 Mar 21 |
nicklas |
// but this results in an exception in IE!!! |
6190 |
29 Mar 21 |
nicklas |
try |
6190 |
29 Mar 21 |
nicklas |
105 |
{ |
6190 |
29 Mar 21 |
nicklas |
event.dataTransfer.setData('application/json', JSON.stringify(dragSrc)); |
6190 |
29 Mar 21 |
nicklas |
107 |
} |
6190 |
29 Mar 21 |
nicklas |
catch (e) |
6190 |
29 Mar 21 |
nicklas |
109 |
{} |
6189 |
29 Mar 21 |
nicklas |
110 |
} |
6157 |
02 Mar 21 |
nicklas |
111 |
|
6190 |
29 Mar 21 |
nicklas |
112 |
/** |
6190 |
29 Mar 21 |
nicklas |
Checks if dropping is allowed at this target. |
6190 |
29 Mar 21 |
nicklas |
We only allow dragging within the same table, |
6190 |
29 Mar 21 |
nicklas |
and the target column must be different from the |
6190 |
29 Mar 21 |
nicklas |
source column. |
6190 |
29 Mar 21 |
nicklas |
117 |
*/ |
6190 |
29 Mar 21 |
nicklas |
varsearch.checkColumnDropTarget = function(event) |
6190 |
29 Mar 21 |
nicklas |
119 |
{ |
6190 |
29 Mar 21 |
nicklas |
var indexId = Data.get(event.currentTarget, 'index-id'); |
6190 |
29 Mar 21 |
nicklas |
var dragSrc = Doc.element('varsearch-header.'+indexId).dragSrc; |
6190 |
29 Mar 21 |
nicklas |
122 |
|
6190 |
29 Mar 21 |
nicklas |
var dropLocation = varsearch.checkTheDropTarget(dragSrc, event.currentTarget); |
6190 |
29 Mar 21 |
nicklas |
if (dropLocation) |
6190 |
29 Mar 21 |
nicklas |
125 |
{ |
6190 |
29 Mar 21 |
nicklas |
// Enable drop target! |
6190 |
29 Mar 21 |
nicklas |
event.preventDefault(); |
6190 |
29 Mar 21 |
nicklas |
event.dataTransfer.dropEffect = 'move'; |
6190 |
29 Mar 21 |
nicklas |
// Left or right depending on the order or columns |
6190 |
29 Mar 21 |
nicklas |
Doc.addClass(event.currentTarget, dropLocation < 0 ? 'table-drop-left' : 'table-drop-right'); |
6190 |
29 Mar 21 |
nicklas |
131 |
} |
6190 |
29 Mar 21 |
nicklas |
132 |
} |
6190 |
29 Mar 21 |
nicklas |
133 |
|
6190 |
29 Mar 21 |
nicklas |
134 |
/** |
6190 |
29 Mar 21 |
nicklas |
Remove drop indicator classes when leaving. |
6190 |
29 Mar 21 |
nicklas |
136 |
*/ |
6190 |
29 Mar 21 |
nicklas |
varsearch.leaveColumnDropTarget = function(event) |
6190 |
29 Mar 21 |
nicklas |
138 |
{ |
6190 |
29 Mar 21 |
nicklas |
Doc.removeClass(event.currentTarget, 'table-drop-right'); |
6190 |
29 Mar 21 |
nicklas |
Doc.removeClass(event.currentTarget, 'table-drop-left'); |
6190 |
29 Mar 21 |
nicklas |
141 |
} |
6190 |
29 Mar 21 |
nicklas |
142 |
|
6190 |
29 Mar 21 |
nicklas |
143 |
/** |
6190 |
29 Mar 21 |
nicklas |
Another column was dropped here! |
6190 |
29 Mar 21 |
nicklas |
145 |
*/ |
6190 |
29 Mar 21 |
nicklas |
varsearch.columnDropped = function(event) |
6190 |
29 Mar 21 |
nicklas |
147 |
{ |
6190 |
29 Mar 21 |
nicklas |
App.debug('columnDropped'); |
6190 |
29 Mar 21 |
nicklas |
Doc.removeClass(event.currentTarget, 'table-drop-right'); |
6190 |
29 Mar 21 |
nicklas |
Doc.removeClass(event.currentTarget, 'table-drop-left'); |
6190 |
29 Mar 21 |
nicklas |
151 |
|
6190 |
29 Mar 21 |
nicklas |
// Check that we can drop here |
6190 |
29 Mar 21 |
nicklas |
var indexId = Data.get(event.currentTarget, 'index-id'); |
6190 |
29 Mar 21 |
nicklas |
var dragSrc = Doc.element('varsearch-header.'+indexId).dragSrc; |
6190 |
29 Mar 21 |
nicklas |
if (!varsearch.checkTheDropTarget(dragSrc, event.currentTarget)) return; |
6190 |
29 Mar 21 |
nicklas |
156 |
|
6190 |
29 Mar 21 |
nicklas |
// Get the existing columns as an array |
6190 |
29 Mar 21 |
nicklas |
var colArray = varsearch.getVisibleColumns(indexId); |
6190 |
29 Mar 21 |
nicklas |
159 |
|
6190 |
29 Mar 21 |
nicklas |
var indexSrc = colArray.indexOf(dragSrc.col); |
6190 |
29 Mar 21 |
nicklas |
var indexDest = colArray.indexOf(Data.get(event.currentTarget, 'col')); |
6190 |
29 Mar 21 |
nicklas |
// Remove the dragged column from the array |
6190 |
29 Mar 21 |
nicklas |
if (indexSrc >= 0) colArray.splice(indexSrc, 1); |
6190 |
29 Mar 21 |
nicklas |
// Insert the dragged column before or after the column it was dropped on |
6190 |
29 Mar 21 |
nicklas |
if (indexDest >= 0) colArray.splice(indexDest, 0, dragSrc.col); |
6190 |
29 Mar 21 |
nicklas |
166 |
|
6190 |
29 Mar 21 |
nicklas |
// Update and submit the table |
6190 |
29 Mar 21 |
nicklas |
varsearch.setVisibleColumns(indexId, colArray.join(',')); |
6190 |
29 Mar 21 |
nicklas |
169 |
} |
6190 |
29 Mar 21 |
nicklas |
170 |
|
6190 |
29 Mar 21 |
nicklas |
171 |
|
6190 |
29 Mar 21 |
nicklas |
172 |
/** |
6190 |
29 Mar 21 |
nicklas |
Checks if dropping is allowed at this target. |
6190 |
29 Mar 21 |
nicklas |
We only allow dragging within the same table, |
6190 |
29 Mar 21 |
nicklas |
and the target column must be different from the |
6190 |
29 Mar 21 |
nicklas |
source column. |
6190 |
29 Mar 21 |
nicklas |
returns: 0 = no drop, -1 drop to left, +1 drop to right |
6190 |
29 Mar 21 |
nicklas |
178 |
*/ |
6190 |
29 Mar 21 |
nicklas |
varsearch.checkTheDropTarget = function(dragSrc, dragTarget) |
6190 |
29 Mar 21 |
nicklas |
180 |
{ |
6190 |
29 Mar 21 |
nicklas |
if (!dragSrc) return false; |
6190 |
29 Mar 21 |
nicklas |
var indexId = Data.get(dragTarget, 'index-id'); |
6190 |
29 Mar 21 |
nicklas |
var colNo = Data.int(dragTarget, 'col-no'); |
6190 |
29 Mar 21 |
nicklas |
return indexId == dragSrc.indexId ? colNo - dragSrc.colNo : 0; |
6190 |
29 Mar 21 |
nicklas |
185 |
} |
6190 |
29 Mar 21 |
nicklas |
186 |
|
6190 |
29 Mar 21 |
nicklas |
187 |
|
6170 |
17 Mar 21 |
nicklas |
varsearch.showHitDetails = function(event) |
6170 |
17 Mar 21 |
nicklas |
189 |
{ |
6170 |
17 Mar 21 |
nicklas |
var url = varsearch.getHome()+'hit-details.jsp?ID='+App.getSessionId(); |
6170 |
17 Mar 21 |
nicklas |
url += '&rbaId='+Data.get(event.currentTarget, 'rba'); |
6170 |
17 Mar 21 |
nicklas |
url += '&fileId='+Data.get(event.currentTarget, 'file'); |
6170 |
17 Mar 21 |
nicklas |
url += '&lineNo='+Data.get(event.currentTarget, 'line'); |
6551 |
26 Jan 22 |
nicklas |
url += '&snpId='+Data.get(event.currentTarget, 'snp'); |
6173 |
18 Mar 21 |
nicklas |
url += '&idx='+encodeURIComponent(Data.get(event.currentTarget, 'idx')); |
6170 |
17 Mar 21 |
nicklas |
Dialogs.openPopup(url, 'VarSearchHit', 600, 400); |
6170 |
17 Mar 21 |
nicklas |
197 |
} |
6170 |
17 Mar 21 |
nicklas |
198 |
|
6522 |
20 Dec 21 |
nicklas |
varsearch.showRbaHits = function(event) |
6522 |
20 Dec 21 |
nicklas |
200 |
{ |
6522 |
20 Dec 21 |
nicklas |
var url = varsearch.getHome()+'rba-hits.jsp?ID='+App.getSessionId(); |
6522 |
20 Dec 21 |
nicklas |
url += '&rbaId='+Data.get(event.currentTarget, 'rba'); |
6526 |
20 Dec 21 |
nicklas |
url += '&fileId='+Data.get(event.currentTarget, 'file'); |
6522 |
20 Dec 21 |
nicklas |
url += '&idx='+encodeURIComponent(Data.get(event.currentTarget, 'idx')); |
6522 |
20 Dec 21 |
nicklas |
Dialogs.openPopup(url, 'VarSearchRbaHits', 900, 600); |
6522 |
20 Dec 21 |
nicklas |
206 |
} |
6522 |
20 Dec 21 |
nicklas |
207 |
|
6189 |
29 Mar 21 |
nicklas |
varsearch.reloadPage = function() |
6189 |
29 Mar 21 |
nicklas |
209 |
{ |
6189 |
29 Mar 21 |
nicklas |
window.location.reload(); |
6189 |
29 Mar 21 |
nicklas |
211 |
} |
6189 |
29 Mar 21 |
nicklas |
212 |
|
6157 |
02 Mar 21 |
nicklas |
// Find the <script> tag for 'varsearch.js' and extract the path to it |
6157 |
02 Mar 21 |
nicklas |
varsearch.getHome = function() |
6157 |
02 Mar 21 |
nicklas |
215 |
{ |
6157 |
02 Mar 21 |
nicklas |
if (HOME != null) return HOME; |
6157 |
02 Mar 21 |
nicklas |
217 |
|
6157 |
02 Mar 21 |
nicklas |
var scripts = document.getElementsByTagName('script'); |
6157 |
02 Mar 21 |
nicklas |
for (var i = scripts.length - 1; i >= 0; i--) |
6157 |
02 Mar 21 |
nicklas |
220 |
{ |
6157 |
02 Mar 21 |
nicklas |
var src = scripts[i].src; |
6157 |
02 Mar 21 |
nicklas |
var end = src.indexOf('varsearch.js'); |
6157 |
02 Mar 21 |
nicklas |
if (end > 0) |
6157 |
02 Mar 21 |
nicklas |
224 |
{ |
6157 |
02 Mar 21 |
nicklas |
var start = src.indexOf(App.getRoot()); |
6157 |
02 Mar 21 |
nicklas |
HOME = src.substring(start, end); |
6157 |
02 Mar 21 |
nicklas |
227 |
} |
6157 |
02 Mar 21 |
nicklas |
228 |
} |
6157 |
02 Mar 21 |
nicklas |
// Fallback that should never happen! |
6157 |
02 Mar 21 |
nicklas |
if (HOME == null) HOME = App.getRoot() + 'extensions/varsearch.jar/'; |
6157 |
02 Mar 21 |
nicklas |
return HOME; |
6157 |
02 Mar 21 |
nicklas |
232 |
} |
6163 |
05 Mar 21 |
nicklas |
233 |
|
6163 |
05 Mar 21 |
nicklas |
234 |
/** |
6163 |
05 Mar 21 |
nicklas |
Add thousand separators to the count |
6163 |
05 Mar 21 |
nicklas |
236 |
*/ |
6163 |
05 Mar 21 |
nicklas |
varsearch.niceCount = function(count) |
6163 |
05 Mar 21 |
nicklas |
238 |
{ |
6544 |
19 Jan 22 |
nicklas |
if (!count && count != 0) return '-'; |
6253 |
25 May 21 |
nicklas |
return count.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1 '); //   == NARROW NO-BREAK SPACE |
6163 |
05 Mar 21 |
nicklas |
241 |
} |
6157 |
02 Mar 21 |
nicklas |
242 |
|
6157 |
02 Mar 21 |
nicklas |
return varsearch; |
6157 |
02 Mar 21 |
nicklas |
244 |
}(); |
6157 |
02 Mar 21 |
nicklas |
245 |
|
6157 |
02 Mar 21 |
nicklas |
Doc.addElementInitializer(VarSearch.initElements); |
6157 |
02 Mar 21 |
nicklas |
247 |
|
6160 |
04 Mar 21 |
nicklas |
var Wizard = function() |
6160 |
04 Mar 21 |
nicklas |
249 |
{ |
6160 |
04 Mar 21 |
nicklas |
var wizard = {}; |
6160 |
04 Mar 21 |
nicklas |
var internal = {}; |
6533 |
21 Dec 21 |
nicklas |
var debug = 0; |
6160 |
04 Mar 21 |
nicklas |
253 |
|
6160 |
04 Mar 21 |
nicklas |
var numLiveAsyncRequests = 0; |
6160 |
04 Mar 21 |
nicklas |
var hasFatalError = false; |
6160 |
04 Mar 21 |
nicklas |
256 |
|
6160 |
04 Mar 21 |
nicklas |
257 |
|
6160 |
04 Mar 21 |
nicklas |
258 |
/** |
6160 |
04 Mar 21 |
nicklas |
Submit an ansynchronous request for JSON data. 'GET' method |
6160 |
04 Mar 21 |
nicklas |
is used if 'method' parameter is not set. |
6160 |
04 Mar 21 |
nicklas |
The 'callback' should be a method accepting a single |
6160 |
04 Mar 21 |
nicklas |
JSON parameter object. If the 'status' of the response |
6160 |
04 Mar 21 |
nicklas |
is not 'ok' this method will call setFatalError and |
6160 |
04 Mar 21 |
nicklas |
without calling the callback method. |
6160 |
04 Mar 21 |
nicklas |
265 |
|
6160 |
04 Mar 21 |
nicklas |
The 'errorCallback' is an optional function parameter that should |
6160 |
04 Mar 21 |
nicklas |
take two parameters. The first is an Error object and the second is |
6160 |
04 Mar 21 |
nicklas |
the JSON response. The seconds parameter only has a value if the error |
6160 |
04 Mar 21 |
nicklas |
happens after parsing the response and is null otherwise. |
6160 |
04 Mar 21 |
nicklas |
270 |
*/ |
6160 |
04 Mar 21 |
nicklas |
wizard.asyncJsonRequest = function(url, callback, method, postdata, errorCallback) |
6160 |
04 Mar 21 |
nicklas |
272 |
{ |
6160 |
04 Mar 21 |
nicklas |
if (debug) |
6160 |
04 Mar 21 |
nicklas |
274 |
{ |
6160 |
04 Mar 21 |
nicklas |
App.debug((method || 'GET') + ': ' + url); |
6160 |
04 Mar 21 |
nicklas |
if (postdata) App.debug(postdata); |
6160 |
04 Mar 21 |
nicklas |
277 |
} |
6160 |
04 Mar 21 |
nicklas |
var request = Ajax.getXmlHttpRequest(); |
6160 |
04 Mar 21 |
nicklas |
request.jsonCallback = callback; |
6160 |
04 Mar 21 |
nicklas |
request.errorCallback = errorCallback; |
6160 |
04 Mar 21 |
nicklas |
request.open(method || 'GET', url, true); |
6160 |
04 Mar 21 |
nicklas |
// Firefox only adds request header with needed "boundary" info, if request header is not set explicitly |
6160 |
04 Mar 21 |
nicklas |
if (postdata && !(postdata instanceof FormData)) |
6160 |
04 Mar 21 |
nicklas |
284 |
{ |
6160 |
04 Mar 21 |
nicklas |
request.setRequestHeader("Content-Type", "application/json; charset=UTF-8"); |
6160 |
04 Mar 21 |
nicklas |
286 |
} |
6160 |
04 Mar 21 |
nicklas |
Ajax.setReadyStateHandler(request, internal.asyncCallbackWrapper, internal.asyncCallbackWrapper); |
6160 |
04 Mar 21 |
nicklas |
numLiveAsyncRequests++; |
6160 |
04 Mar 21 |
nicklas |
request.send(postdata || null); |
6160 |
04 Mar 21 |
nicklas |
290 |
} |
6160 |
04 Mar 21 |
nicklas |
291 |
|
6160 |
04 Mar 21 |
nicklas |
292 |
/** |
6160 |
04 Mar 21 |
nicklas |
Callback wrapper for ansynchronous requests. |
6160 |
04 Mar 21 |
nicklas |
294 |
*/ |
6160 |
04 Mar 21 |
nicklas |
internal.asyncCallbackWrapper = function(request) |
6160 |
04 Mar 21 |
nicklas |
296 |
{ |
6160 |
04 Mar 21 |
nicklas |
numLiveAsyncRequests--; |
6160 |
04 Mar 21 |
nicklas |
if (debug) App.debug(request.responseText); |
6160 |
04 Mar 21 |
nicklas |
if (!hasFatalError) Wizard.hideWizardStatus(); |
6160 |
04 Mar 21 |
nicklas |
300 |
|
6160 |
04 Mar 21 |
nicklas |
var response = null; |
6160 |
04 Mar 21 |
nicklas |
var messages = null; |
6160 |
04 Mar 21 |
nicklas |
try |
6160 |
04 Mar 21 |
nicklas |
304 |
{ |
6160 |
04 Mar 21 |
nicklas |
if (request.status != 200) |
6160 |
04 Mar 21 |
nicklas |
306 |
{ |
6160 |
04 Mar 21 |
nicklas |
throw new Error(request.responseText); |
6160 |
04 Mar 21 |
nicklas |
308 |
} |
6160 |
04 Mar 21 |
nicklas |
else |
6160 |
04 Mar 21 |
nicklas |
310 |
{ |
6160 |
04 Mar 21 |
nicklas |
if (request.getResponseHeader('Content-Type').indexOf('json') != -1) |
6160 |
04 Mar 21 |
nicklas |
312 |
{ |
6160 |
04 Mar 21 |
nicklas |
response = JSON.parse(request.responseText); |
6160 |
04 Mar 21 |
nicklas |
messages = response.messages; |
6160 |
04 Mar 21 |
nicklas |
if (response.status != 'ok') |
6160 |
04 Mar 21 |
nicklas |
316 |
{ |
6160 |
04 Mar 21 |
nicklas |
throw new Error(response.message || response.stacktrace); |
6160 |
04 Mar 21 |
nicklas |
318 |
} |
6160 |
04 Mar 21 |
nicklas |
319 |
} |
6160 |
04 Mar 21 |
nicklas |
else |
6160 |
04 Mar 21 |
nicklas |
321 |
{ |
6160 |
04 Mar 21 |
nicklas |
response = request.responseText; |
6160 |
04 Mar 21 |
nicklas |
323 |
} |
6160 |
04 Mar 21 |
nicklas |
if (request.jsonCallback && request.jsonCallback.call) |
6160 |
04 Mar 21 |
nicklas |
325 |
{ |
6160 |
04 Mar 21 |
nicklas |
request.jsonCallback.call(null, response); |
6160 |
04 Mar 21 |
nicklas |
327 |
} |
6160 |
04 Mar 21 |
nicklas |
328 |
} |
6160 |
04 Mar 21 |
nicklas |
329 |
} |
6160 |
04 Mar 21 |
nicklas |
catch (err) |
6160 |
04 Mar 21 |
nicklas |
331 |
{ |
6160 |
04 Mar 21 |
nicklas |
if (request.errorCallback && request.errorCallback.call) |
6160 |
04 Mar 21 |
nicklas |
333 |
{ |
6160 |
04 Mar 21 |
nicklas |
request.errorCallback.call(null, err, response); |
6160 |
04 Mar 21 |
nicklas |
335 |
} |
6160 |
04 Mar 21 |
nicklas |
else |
6160 |
04 Mar 21 |
nicklas |
337 |
{ |
6160 |
04 Mar 21 |
nicklas |
Wizard.setFatalError(err, messages); |
6160 |
04 Mar 21 |
nicklas |
339 |
} |
6160 |
04 Mar 21 |
nicklas |
340 |
} |
6160 |
04 Mar 21 |
nicklas |
341 |
} |
6160 |
04 Mar 21 |
nicklas |
342 |
|
6160 |
04 Mar 21 |
nicklas |
343 |
|
6160 |
04 Mar 21 |
nicklas |
344 |
/** |
6160 |
04 Mar 21 |
nicklas |
A fatal error has occurred and the wizard will not be able to continue. |
6160 |
04 Mar 21 |
nicklas |
This method will display the error message, disable all form input fields |
6160 |
04 Mar 21 |
nicklas |
and buttons (except the 'Restart' button). |
6160 |
04 Mar 21 |
nicklas |
348 |
*/ |
6160 |
04 Mar 21 |
nicklas |
wizard.setFatalError = function(err, messages) |
6160 |
04 Mar 21 |
nicklas |
350 |
{ |
6160 |
04 Mar 21 |
nicklas |
hasFatalError = true; |
6160 |
04 Mar 21 |
nicklas |
var msg = err; |
6160 |
04 Mar 21 |
nicklas |
if (err.toString) |
6160 |
04 Mar 21 |
nicklas |
354 |
{ |
6160 |
04 Mar 21 |
nicklas |
App.debug(err.toString()); |
6160 |
04 Mar 21 |
nicklas |
msg = Strings.encodeTags(err.toString()); |
6160 |
04 Mar 21 |
nicklas |
if (err.stack && !messages) |
6160 |
04 Mar 21 |
nicklas |
358 |
{ |
6160 |
04 Mar 21 |
nicklas |
App.debug(err.stack); |
6160 |
04 Mar 21 |
nicklas |
msg += '<br><pre>'+Strings.encodeTags(err.stack)+'</pre>'; |
6160 |
04 Mar 21 |
nicklas |
361 |
} |
6160 |
04 Mar 21 |
nicklas |
362 |
} |
6160 |
04 Mar 21 |
nicklas |
else |
6160 |
04 Mar 21 |
nicklas |
364 |
{ |
6160 |
04 Mar 21 |
nicklas |
App.debug(msg); |
6160 |
04 Mar 21 |
nicklas |
366 |
} |
6160 |
04 Mar 21 |
nicklas |
367 |
|
6160 |
04 Mar 21 |
nicklas |
if (messages) |
6160 |
04 Mar 21 |
nicklas |
369 |
{ |
6160 |
04 Mar 21 |
nicklas |
msg = '<div class="messagecontainer error">'+msg+'</div>'+internal.generateMessageList(messages).html; |
6160 |
04 Mar 21 |
nicklas |
wizard.setWizardStatus('success', msg); |
6160 |
04 Mar 21 |
nicklas |
372 |
} |
6160 |
04 Mar 21 |
nicklas |
else |
6160 |
04 Mar 21 |
nicklas |
374 |
{ |
6160 |
04 Mar 21 |
nicklas |
wizard.setWizardStatus('messagecontainer error', msg || 'Unexpected failure!'); |
6160 |
04 Mar 21 |
nicklas |
376 |
} |
6160 |
04 Mar 21 |
nicklas |
377 |
|
6160 |
04 Mar 21 |
nicklas |
Doc.addClass('wizard', 'disabled'); |
6160 |
04 Mar 21 |
nicklas |
internal.disableAllFormElements('wizard', true); |
6160 |
04 Mar 21 |
nicklas |
Doc.show('gorestart'); |
6160 |
04 Mar 21 |
nicklas |
381 |
} |
6160 |
04 Mar 21 |
nicklas |
382 |
|
6160 |
04 Mar 21 |
nicklas |
383 |
/** |
6160 |
04 Mar 21 |
nicklas |
Display a global wizard-status message. This may for example be |
6160 |
04 Mar 21 |
nicklas |
an error message, a work-in-progress indicator, etc. |
6160 |
04 Mar 21 |
nicklas |
386 |
*/ |
6160 |
04 Mar 21 |
nicklas |
wizard.setWizardStatus = function(className, msg) |
6160 |
04 Mar 21 |
nicklas |
388 |
{ |
6160 |
04 Mar 21 |
nicklas |
var status = Doc.element('wizard-status'); |
6160 |
04 Mar 21 |
nicklas |
status.className = className; |
6160 |
04 Mar 21 |
nicklas |
status.innerHTML = msg; |
6160 |
04 Mar 21 |
nicklas |
Doc.show(status); |
6160 |
04 Mar 21 |
nicklas |
393 |
} |
6160 |
04 Mar 21 |
nicklas |
394 |
|
6160 |
04 Mar 21 |
nicklas |
395 |
|
6160 |
04 Mar 21 |
nicklas |
396 |
/** |
6160 |
04 Mar 21 |
nicklas |
Hide the current global wizard-status message. |
6160 |
04 Mar 21 |
nicklas |
398 |
*/ |
6160 |
04 Mar 21 |
nicklas |
wizard.hideWizardStatus = function() |
6160 |
04 Mar 21 |
nicklas |
400 |
{ |
6160 |
04 Mar 21 |
nicklas |
Doc.hide('wizard-status'); |
6160 |
04 Mar 21 |
nicklas |
Doc.hide('wizard-progress'); |
6160 |
04 Mar 21 |
nicklas |
403 |
} |
6160 |
04 Mar 21 |
nicklas |
404 |
|
6161 |
04 Mar 21 |
nicklas |
405 |
/** |
6161 |
04 Mar 21 |
nicklas |
Display a 'loading' global wizard-status message. |
6161 |
04 Mar 21 |
nicklas |
The 'progress' parameter is optional. If given, |
6161 |
04 Mar 21 |
nicklas |
it should be the name of a progress reporter. |
6161 |
04 Mar 21 |
nicklas |
This activates the display of a progress bar which |
6161 |
04 Mar 21 |
nicklas |
Relax will update at regular intervals in the background. |
6161 |
04 Mar 21 |
nicklas |
See SessionServlet (cmd=GetProgress) for more information. |
6161 |
04 Mar 21 |
nicklas |
412 |
*/ |
6161 |
04 Mar 21 |
nicklas |
wizard.showLoadingAnimation = function(msg, progress) |
6161 |
04 Mar 21 |
nicklas |
414 |
{ |
6161 |
04 Mar 21 |
nicklas |
wizard.setWizardStatus('loading', msg || 'Working, please wait...'); |
6161 |
04 Mar 21 |
nicklas |
if (progress) |
6161 |
04 Mar 21 |
nicklas |
417 |
{ |
6161 |
04 Mar 21 |
nicklas |
var progressBar = Doc.element('wizard-progress'); |
6161 |
04 Mar 21 |
nicklas |
progressBar.classList.add('progress-bar'); |
6161 |
04 Mar 21 |
nicklas |
420 |
|
6161 |
04 Mar 21 |
nicklas |
// Get/create child elements |
6161 |
04 Mar 21 |
nicklas |
var done = Doc.element('wizard-progress-done'); |
6161 |
04 Mar 21 |
nicklas |
if (!done) |
6161 |
04 Mar 21 |
nicklas |
424 |
{ |
6161 |
04 Mar 21 |
nicklas |
done = document.createElement('span'); |
6161 |
04 Mar 21 |
nicklas |
done.id = 'wizard-progress-done'; |
6161 |
04 Mar 21 |
nicklas |
done.className = 'progress-bar-done bg-filled-100 topborder bottomborder leftborder'; |
6161 |
04 Mar 21 |
nicklas |
progressBar.appendChild(done); |
6161 |
04 Mar 21 |
nicklas |
429 |
} |
6161 |
04 Mar 21 |
nicklas |
var remain = Doc.element('wizard-progress-remain'); |
6161 |
04 Mar 21 |
nicklas |
if (!remain) |
6161 |
04 Mar 21 |
nicklas |
432 |
{ |
6161 |
04 Mar 21 |
nicklas |
remain = document.createElement('span'); |
6161 |
04 Mar 21 |
nicklas |
remain.id = 'wizard-progress-remain'; |
6161 |
04 Mar 21 |
nicklas |
remain.className = 'progress-bar-remain topborder bottomborder rightborder'; |
6161 |
04 Mar 21 |
nicklas |
progressBar.appendChild(remain); |
6161 |
04 Mar 21 |
nicklas |
437 |
} |
6161 |
04 Mar 21 |
nicklas |
438 |
|
6161 |
04 Mar 21 |
nicklas |
progressBar.setAttribute('value', '0%'); |
6161 |
04 Mar 21 |
nicklas |
done.style.width = '0%'; |
6161 |
04 Mar 21 |
nicklas |
remain.style.width = '100%'; |
6161 |
04 Mar 21 |
nicklas |
Doc.show(progressBar); |
6161 |
04 Mar 21 |
nicklas |
443 |
|
6161 |
04 Mar 21 |
nicklas |
// Initial request for updating the progress bar |
6161 |
04 Mar 21 |
nicklas |
progressTimer = setTimeout(internal.requestProgressUpdate, 1500, progress); |
6161 |
04 Mar 21 |
nicklas |
446 |
} |
6161 |
04 Mar 21 |
nicklas |
447 |
} |
6161 |
04 Mar 21 |
nicklas |
448 |
|
6161 |
04 Mar 21 |
nicklas |
449 |
/** |
6161 |
04 Mar 21 |
nicklas |
Make a request for the progress information. The 'progress' |
6161 |
04 Mar 21 |
nicklas |
parameter is the name of a progress bar. |
6161 |
04 Mar 21 |
nicklas |
452 |
*/ |
6161 |
04 Mar 21 |
nicklas |
internal.requestProgressUpdate = function(progress) |
6161 |
04 Mar 21 |
nicklas |
454 |
{ |
6161 |
04 Mar 21 |
nicklas |
if (hasFatalError) return; |
6161 |
04 Mar 21 |
nicklas |
var url = '../Session.servlet?ID='+App.getSessionId(); |
6161 |
04 Mar 21 |
nicklas |
url += '&cmd=GetProgress'; |
6161 |
04 Mar 21 |
nicklas |
url += '&name='+encodeURIComponent(progress); |
6161 |
04 Mar 21 |
nicklas |
459 |
|
6161 |
04 Mar 21 |
nicklas |
var request = Ajax.getXmlHttpRequest(); |
6161 |
04 Mar 21 |
nicklas |
request.open("GET", url, true); |
6161 |
04 Mar 21 |
nicklas |
Ajax.setReadyStateHandler(request, internal.onProgressReport, internal.onProgressReport); |
6161 |
04 Mar 21 |
nicklas |
request.send(null); |
6161 |
04 Mar 21 |
nicklas |
464 |
} |
6161 |
04 Mar 21 |
nicklas |
465 |
|
6161 |
04 Mar 21 |
nicklas |
466 |
/** |
6161 |
04 Mar 21 |
nicklas |
Callback when receiving a progress update. |
6161 |
04 Mar 21 |
nicklas |
468 |
*/ |
6161 |
04 Mar 21 |
nicklas |
internal.onProgressReport = function(request) |
6161 |
04 Mar 21 |
nicklas |
470 |
{ |
6161 |
04 Mar 21 |
nicklas |
if (hasFatalError) return; |
6161 |
04 Mar 21 |
nicklas |
if (debug) App.debug(Strings.encodeTags(request.responseText)); |
6161 |
04 Mar 21 |
nicklas |
var response; |
6161 |
04 Mar 21 |
nicklas |
var error = false; |
6161 |
04 Mar 21 |
nicklas |
try |
6161 |
04 Mar 21 |
nicklas |
476 |
{ |
6161 |
04 Mar 21 |
nicklas |
response = JSON.parse(request.responseText); |
6161 |
04 Mar 21 |
nicklas |
if (response.status != 'ok') |
6161 |
04 Mar 21 |
nicklas |
479 |
{ |
6161 |
04 Mar 21 |
nicklas |
error = response.message || response.stacktrace || 'Unexpected error'; |
6161 |
04 Mar 21 |
nicklas |
481 |
} |
6161 |
04 Mar 21 |
nicklas |
482 |
} |
6161 |
04 Mar 21 |
nicklas |
catch (ex) |
6161 |
04 Mar 21 |
nicklas |
484 |
{ |
6161 |
04 Mar 21 |
nicklas |
error = ex; |
6161 |
04 Mar 21 |
nicklas |
486 |
} |
6161 |
04 Mar 21 |
nicklas |
487 |
|
6161 |
04 Mar 21 |
nicklas |
if (error) |
6161 |
04 Mar 21 |
nicklas |
489 |
{ |
6161 |
04 Mar 21 |
nicklas |
return; |
6161 |
04 Mar 21 |
nicklas |
491 |
} |
6161 |
04 Mar 21 |
nicklas |
492 |
|
6161 |
04 Mar 21 |
nicklas |
var progress = response.progress; |
6161 |
04 Mar 21 |
nicklas |
var progressBar = Doc.element('wizard-progress'); |
6161 |
04 Mar 21 |
nicklas |
495 |
|
6161 |
04 Mar 21 |
nicklas |
if (!progress) |
6161 |
04 Mar 21 |
nicklas |
497 |
{ |
6161 |
04 Mar 21 |
nicklas |
// Give up if no progress information |
6161 |
04 Mar 21 |
nicklas |
Doc.hide(progressBar); |
6161 |
04 Mar 21 |
nicklas |
return; |
6161 |
04 Mar 21 |
nicklas |
501 |
} |
6161 |
04 Mar 21 |
nicklas |
502 |
|
6161 |
04 Mar 21 |
nicklas |
var done = Doc.element('wizard-progress-done'); |
6161 |
04 Mar 21 |
nicklas |
var remain = Doc.element('wizard-progress-remain'); |
6161 |
04 Mar 21 |
nicklas |
505 |
|
6161 |
04 Mar 21 |
nicklas |
progressBar.setAttribute('value', progress.percent+'%'); |
6161 |
04 Mar 21 |
nicklas |
done.style.width = progress.percent+'%'; |
6161 |
04 Mar 21 |
nicklas |
remain.style.width = (100-progress.percent)+'%'; |
6161 |
04 Mar 21 |
nicklas |
509 |
|
6161 |
04 Mar 21 |
nicklas |
if (progress.message) |
6161 |
04 Mar 21 |
nicklas |
511 |
{ |
6161 |
04 Mar 21 |
nicklas |
Doc.element('wizard-status').innerHTML = Strings.encodeTags(progress.message); |
6161 |
04 Mar 21 |
nicklas |
513 |
} |
6161 |
04 Mar 21 |
nicklas |
514 |
|
6161 |
04 Mar 21 |
nicklas |
if (progress.percent < 100) |
6161 |
04 Mar 21 |
nicklas |
516 |
{ |
6161 |
04 Mar 21 |
nicklas |
// Continue to request updates until we 100% has been reached |
6161 |
04 Mar 21 |
nicklas |
progressTimer = setTimeout(internal.requestProgressUpdate, 1500, progress.name); |
6161 |
04 Mar 21 |
nicklas |
519 |
} |
6161 |
04 Mar 21 |
nicklas |
else |
6161 |
04 Mar 21 |
nicklas |
521 |
{ |
6161 |
04 Mar 21 |
nicklas |
progressTimer = null; |
6161 |
04 Mar 21 |
nicklas |
Doc.hide(progressBar); |
6161 |
04 Mar 21 |
nicklas |
524 |
} |
6161 |
04 Mar 21 |
nicklas |
525 |
} |
6161 |
04 Mar 21 |
nicklas |
526 |
|
6160 |
04 Mar 21 |
nicklas |
// Disable all form elements inside the given container |
6160 |
04 Mar 21 |
nicklas |
internal.disableAllFormElements = function(container, hideButtons) |
6160 |
04 Mar 21 |
nicklas |
529 |
{ |
6160 |
04 Mar 21 |
nicklas |
container = Doc.element(container); |
6160 |
04 Mar 21 |
nicklas |
if (!container) return; |
6160 |
04 Mar 21 |
nicklas |
var input = container.getElementsByTagName('input'); |
6160 |
04 Mar 21 |
nicklas |
for (var i = 0; i < input.length; i++) |
6160 |
04 Mar 21 |
nicklas |
534 |
{ |
6160 |
04 Mar 21 |
nicklas |
input[i].disabled = true; |
6160 |
04 Mar 21 |
nicklas |
536 |
} |
6160 |
04 Mar 21 |
nicklas |
var select = container.getElementsByTagName('select'); |
6160 |
04 Mar 21 |
nicklas |
for (var i = 0; i < select.length; i++) |
6160 |
04 Mar 21 |
nicklas |
539 |
{ |
6160 |
04 Mar 21 |
nicklas |
select[i].disabled = true; |
6160 |
04 Mar 21 |
nicklas |
541 |
} |
6160 |
04 Mar 21 |
nicklas |
var text = container.getElementsByTagName('textarea'); |
6160 |
04 Mar 21 |
nicklas |
for (var i = 0; i < text.length; i++) |
6160 |
04 Mar 21 |
nicklas |
544 |
{ |
6160 |
04 Mar 21 |
nicklas |
text[i].disabled = true; |
6160 |
04 Mar 21 |
nicklas |
546 |
} |
6160 |
04 Mar 21 |
nicklas |
if (hideButtons) |
6160 |
04 Mar 21 |
nicklas |
548 |
{ |
6160 |
04 Mar 21 |
nicklas |
internal.hideButtons(container); |
6160 |
04 Mar 21 |
nicklas |
550 |
} |
6160 |
04 Mar 21 |
nicklas |
551 |
} |
6160 |
04 Mar 21 |
nicklas |
552 |
|
6160 |
04 Mar 21 |
nicklas |
// Hide all 'basicbuttons':s in the given container |
6160 |
04 Mar 21 |
nicklas |
internal.hideButtons = function(container) |
6160 |
04 Mar 21 |
nicklas |
555 |
{ |
6160 |
04 Mar 21 |
nicklas |
container = Doc.element(container); |
6160 |
04 Mar 21 |
nicklas |
var buttons = container.getElementsByClassName('basicbutton'); |
6160 |
04 Mar 21 |
nicklas |
for (var i = 0; i < buttons.length; i++) |
6160 |
04 Mar 21 |
nicklas |
559 |
{ |
6160 |
04 Mar 21 |
nicklas |
Doc.hide(buttons[i]); |
6160 |
04 Mar 21 |
nicklas |
561 |
} |
6160 |
04 Mar 21 |
nicklas |
562 |
} |
6160 |
04 Mar 21 |
nicklas |
563 |
|
6160 |
04 Mar 21 |
nicklas |
564 |
|
6160 |
04 Mar 21 |
nicklas |
565 |
/** |
6160 |
04 Mar 21 |
nicklas |
Initialize the wizard: |
6160 |
04 Mar 21 |
nicklas |
* Display version number |
6160 |
04 Mar 21 |
nicklas |
568 |
*/ |
6160 |
04 Mar 21 |
nicklas |
internal.initWizard = function() |
6160 |
04 Mar 21 |
nicklas |
570 |
{ |
6160 |
04 Mar 21 |
nicklas |
var path = document.getElementsByClassName('path'); |
6160 |
04 Mar 21 |
nicklas |
if (path && path.length) |
6160 |
04 Mar 21 |
nicklas |
573 |
{ |
6160 |
04 Mar 21 |
nicklas |
var varsearchVersion = document.createElement('span'); |
6160 |
04 Mar 21 |
nicklas |
varsearchVersion.id = 'varsearch-version'; |
6160 |
04 Mar 21 |
nicklas |
varsearchVersion.innerHTML = '[Variant Search '+VarSearch.VERSION+']'; |
6160 |
04 Mar 21 |
nicklas |
path[0].appendChild(varsearchVersion); |
6160 |
04 Mar 21 |
nicklas |
578 |
} |
6160 |
04 Mar 21 |
nicklas |
579 |
} |
6160 |
04 Mar 21 |
nicklas |
580 |
|
6160 |
04 Mar 21 |
nicklas |
Doc.addFinalizer(internal.initWizard); |
6160 |
04 Mar 21 |
nicklas |
return wizard; |
6160 |
04 Mar 21 |
nicklas |
583 |
}(); |
6160 |
04 Mar 21 |
nicklas |
584 |
|
6161 |
04 Mar 21 |
nicklas |
585 |
/** |
6161 |
04 Mar 21 |
nicklas |
Holds one or more filter criterias. Use the 'add*' methods |
6161 |
04 Mar 21 |
nicklas |
to add criterias to the filter, and the 'check(item)' method |
6161 |
04 Mar 21 |
nicklas |
to evaluate all criterias against a single item. |
6161 |
04 Mar 21 |
nicklas |
589 |
*/ |
6161 |
04 Mar 21 |
nicklas |
var Filter = function() |
6161 |
04 Mar 21 |
nicklas |
591 |
{ |
6161 |
04 Mar 21 |
nicklas |
this.criterias = []; |
6161 |
04 Mar 21 |
nicklas |
593 |
} |
6160 |
04 Mar 21 |
nicklas |
594 |
|
6161 |
04 Mar 21 |
nicklas |
595 |
/** |
6161 |
04 Mar 21 |
nicklas |
Adds a text criteria comparing the given item property to |
6161 |
04 Mar 21 |
nicklas |
a static value (f2). |
6161 |
04 Mar 21 |
nicklas |
598 |
*/ |
6161 |
04 Mar 21 |
nicklas |
Filter.prototype.addTextCriteria = function(itemProp, f2) |
6161 |
04 Mar 21 |
nicklas |
600 |
{ |
6161 |
04 Mar 21 |
nicklas |
if (f2 != '') |
6161 |
04 Mar 21 |
nicklas |
602 |
{ |
6161 |
04 Mar 21 |
nicklas |
var cmp; |
6161 |
04 Mar 21 |
nicklas |
if (f2 == '=') |
6161 |
04 Mar 21 |
nicklas |
605 |
{ |
6161 |
04 Mar 21 |
nicklas |
cmp = Comparator.eq; |
6161 |
04 Mar 21 |
nicklas |
f2 = null; |
6161 |
04 Mar 21 |
nicklas |
608 |
} |
6161 |
04 Mar 21 |
nicklas |
else if (f2 == '<>') |
6161 |
04 Mar 21 |
nicklas |
610 |
{ |
6161 |
04 Mar 21 |
nicklas |
cmp = Comparator.neq; |
6161 |
04 Mar 21 |
nicklas |
f2 = null; |
6161 |
04 Mar 21 |
nicklas |
613 |
} |
6161 |
04 Mar 21 |
nicklas |
else |
6161 |
04 Mar 21 |
nicklas |
615 |
{ |
6161 |
04 Mar 21 |
nicklas |
cmp = Comparator.eq; |
6161 |
04 Mar 21 |
nicklas |
617 |
} |
6161 |
04 Mar 21 |
nicklas |
this.criterias[this.criterias.length] = function(item) { return cmp(itemProp(item), f2) }; |
6161 |
04 Mar 21 |
nicklas |
619 |
} |
6161 |
04 Mar 21 |
nicklas |
620 |
} |
6161 |
04 Mar 21 |
nicklas |
621 |
|
6161 |
04 Mar 21 |
nicklas |
622 |
/** |
6161 |
04 Mar 21 |
nicklas |
Adds a text criteria checking if the given item property to |
6161 |
04 Mar 21 |
nicklas |
contains a static value (f2). |
6161 |
04 Mar 21 |
nicklas |
625 |
*/ |
6161 |
04 Mar 21 |
nicklas |
Filter.prototype.addContainsCriteria = function(itemProp, f2) |
6161 |
04 Mar 21 |
nicklas |
627 |
{ |
6161 |
04 Mar 21 |
nicklas |
if (f2 != '') |
6161 |
04 Mar 21 |
nicklas |
629 |
{ |
6161 |
04 Mar 21 |
nicklas |
var cmp; |
6161 |
04 Mar 21 |
nicklas |
if (f2 == '=') |
6161 |
04 Mar 21 |
nicklas |
632 |
{ |
6161 |
04 Mar 21 |
nicklas |
cmp = Comparator.eq; |
6161 |
04 Mar 21 |
nicklas |
f2 = null; |
6161 |
04 Mar 21 |
nicklas |
635 |
} |
6161 |
04 Mar 21 |
nicklas |
else if (f2 == '<>') |
6161 |
04 Mar 21 |
nicklas |
637 |
{ |
6161 |
04 Mar 21 |
nicklas |
cmp = Comparator.neq; |
6161 |
04 Mar 21 |
nicklas |
f2 = null; |
6161 |
04 Mar 21 |
nicklas |
640 |
} |
6161 |
04 Mar 21 |
nicklas |
else |
6161 |
04 Mar 21 |
nicklas |
642 |
{ |
6161 |
04 Mar 21 |
nicklas |
cmp = Comparator.contains; |
6161 |
04 Mar 21 |
nicklas |
644 |
} |
6161 |
04 Mar 21 |
nicklas |
this.criterias[this.criterias.length] = function(item) { return cmp(itemProp(item), f2) }; |
6161 |
04 Mar 21 |
nicklas |
646 |
} |
6161 |
04 Mar 21 |
nicklas |
647 |
} |
6161 |
04 Mar 21 |
nicklas |
648 |
|
6161 |
04 Mar 21 |
nicklas |
649 |
/** |
6161 |
04 Mar 21 |
nicklas |
Evaluate all criterias. Return true if all pass, false otherwise. |
6161 |
04 Mar 21 |
nicklas |
651 |
*/ |
6161 |
04 Mar 21 |
nicklas |
Filter.prototype.check = function(item) |
6161 |
04 Mar 21 |
nicklas |
653 |
{ |
6161 |
04 Mar 21 |
nicklas |
for (var i = 0; i < this.criterias.length; i++) |
6161 |
04 Mar 21 |
nicklas |
655 |
{ |
6161 |
04 Mar 21 |
nicklas |
if (!this.criterias[i](item)) return false; |
6161 |
04 Mar 21 |
nicklas |
657 |
} |
6161 |
04 Mar 21 |
nicklas |
return true; |
6161 |
04 Mar 21 |
nicklas |
659 |
} |
6161 |
04 Mar 21 |
nicklas |
660 |
|
6161 |
04 Mar 21 |
nicklas |
661 |
|
6161 |
04 Mar 21 |
nicklas |
var Comparator = function() |
6161 |
04 Mar 21 |
nicklas |
663 |
{ |
6161 |
04 Mar 21 |
nicklas |
var cmp = {}; |
6161 |
04 Mar 21 |
nicklas |
665 |
|
6161 |
04 Mar 21 |
nicklas |
666 |
/** |
6161 |
04 Mar 21 |
nicklas |
Return a comparator based on the symbol |
6161 |
04 Mar 21 |
nicklas |
which can be either '>' or '<' to return |
6161 |
04 Mar 21 |
nicklas |
Comparator.gt or Comparator.lt. Otherwise |
6161 |
04 Mar 21 |
nicklas |
the given default or Comparator.eq is returned. |
6161 |
04 Mar 21 |
nicklas |
671 |
*/ |
6161 |
04 Mar 21 |
nicklas |
cmp.get = function(symbol, defaultCmp) |
6161 |
04 Mar 21 |
nicklas |
673 |
{ |
6161 |
04 Mar 21 |
nicklas |
var c; |
6161 |
04 Mar 21 |
nicklas |
if (symbol == '<') |
6161 |
04 Mar 21 |
nicklas |
676 |
{ |
6161 |
04 Mar 21 |
nicklas |
c = cmp.lt; |
6161 |
04 Mar 21 |
nicklas |
678 |
} |
6161 |
04 Mar 21 |
nicklas |
else if (symbol == '>') |
6161 |
04 Mar 21 |
nicklas |
680 |
{ |
6161 |
04 Mar 21 |
nicklas |
c = cmp.gt; |
6161 |
04 Mar 21 |
nicklas |
682 |
} |
6161 |
04 Mar 21 |
nicklas |
else |
6161 |
04 Mar 21 |
nicklas |
684 |
{ |
6161 |
04 Mar 21 |
nicklas |
c = defaultCmp || cmp.eq; |
6161 |
04 Mar 21 |
nicklas |
686 |
} |
6161 |
04 Mar 21 |
nicklas |
return c; |
6161 |
04 Mar 21 |
nicklas |
688 |
} |
6161 |
04 Mar 21 |
nicklas |
689 |
|
6161 |
04 Mar 21 |
nicklas |
// Compare if two values are equal |
6161 |
04 Mar 21 |
nicklas |
cmp.eq = function(v1, v2) |
6161 |
04 Mar 21 |
nicklas |
692 |
{ |
6161 |
04 Mar 21 |
nicklas |
return v1 == v2; |
6161 |
04 Mar 21 |
nicklas |
694 |
} |
6161 |
04 Mar 21 |
nicklas |
695 |
|
6161 |
04 Mar 21 |
nicklas |
// Compare if two values are different |
6161 |
04 Mar 21 |
nicklas |
cmp.neq = function(v1, v2) |
6161 |
04 Mar 21 |
nicklas |
698 |
{ |
6161 |
04 Mar 21 |
nicklas |
return v1 != v2; |
6161 |
04 Mar 21 |
nicklas |
700 |
} |
6161 |
04 Mar 21 |
nicklas |
701 |
|
6161 |
04 Mar 21 |
nicklas |
// Check if v2 is contained in v1 |
6161 |
04 Mar 21 |
nicklas |
cmp.contains = function(v1, v2) |
6161 |
04 Mar 21 |
nicklas |
704 |
{ |
6161 |
04 Mar 21 |
nicklas |
return v1 != null && v2 != null && v1.indexOf(v2) >= 0; |
6161 |
04 Mar 21 |
nicklas |
706 |
} |
6161 |
04 Mar 21 |
nicklas |
707 |
|
6161 |
04 Mar 21 |
nicklas |
// Compare if two values are appoximately equals (difference is not more than 0.05) |
6161 |
04 Mar 21 |
nicklas |
cmp.approx = function(v1, v2) |
6161 |
04 Mar 21 |
nicklas |
710 |
{ |
6161 |
04 Mar 21 |
nicklas |
return Math.abs(v2 - v1) < 0.05; |
6161 |
04 Mar 21 |
nicklas |
712 |
} |
6161 |
04 Mar 21 |
nicklas |
713 |
|
6161 |
04 Mar 21 |
nicklas |
// Compare if v1 starts with the same string as v2 |
6161 |
04 Mar 21 |
nicklas |
cmp.startsWith = function(v1, v2) |
6161 |
04 Mar 21 |
nicklas |
716 |
{ |
6161 |
04 Mar 21 |
nicklas |
return v1 != null && v1.indexOf(v2) == 0; |
6161 |
04 Mar 21 |
nicklas |
718 |
} |
6161 |
04 Mar 21 |
nicklas |
719 |
|
6161 |
04 Mar 21 |
nicklas |
// Compare if v1 is greater than or equal to v2 |
6161 |
04 Mar 21 |
nicklas |
cmp.gt = function(v1, v2) |
6161 |
04 Mar 21 |
nicklas |
722 |
{ |
6161 |
04 Mar 21 |
nicklas |
return v1 != null && v2 != null && v1 >= v2; |
6161 |
04 Mar 21 |
nicklas |
724 |
} |
6161 |
04 Mar 21 |
nicklas |
725 |
|
6161 |
04 Mar 21 |
nicklas |
// Compare if v1 is less than or equal to v2 |
6161 |
04 Mar 21 |
nicklas |
cmp.lt = function(v1, v2) |
6161 |
04 Mar 21 |
nicklas |
728 |
{ |
6161 |
04 Mar 21 |
nicklas |
return v1 != null && v2 != null && v1 <= v2; |
6161 |
04 Mar 21 |
nicklas |
730 |
} |
6161 |
04 Mar 21 |
nicklas |
731 |
|
6161 |
04 Mar 21 |
nicklas |
return cmp; |
6161 |
04 Mar 21 |
nicklas |
733 |
}(); |
6161 |
04 Mar 21 |
nicklas |
734 |
|
6161 |
04 Mar 21 |
nicklas |
735 |
|