2327 |
08 Apr 14 |
nicklas |
var Install = function() |
2327 |
08 Apr 14 |
nicklas |
2 |
{ |
2327 |
08 Apr 14 |
nicklas |
var install = {}; |
2593 |
19 Aug 14 |
nicklas |
var debug = 0; |
4361 |
16 Feb 17 |
nicklas |
var checks; |
2327 |
08 Apr 14 |
nicklas |
6 |
|
2327 |
08 Apr 14 |
nicklas |
install.initPage = function() |
2327 |
08 Apr 14 |
nicklas |
8 |
{ |
2618 |
01 Sep 14 |
nicklas |
if (!App.getActiveProjectId()) return; |
4361 |
16 Feb 17 |
nicklas |
Events.addEventHandler('typeFilter', 'change', install.filterOnChange); |
4361 |
16 Feb 17 |
nicklas |
Events.addEventHandler('nameFilter', 'change', install.filterOnChange); |
4361 |
16 Feb 17 |
nicklas |
Events.addEventHandler('messageFilter', 'change', install.filterOnChange); |
4361 |
16 Feb 17 |
nicklas |
13 |
|
2327 |
08 Apr 14 |
nicklas |
Buttons.addClickHandler('btnFixItems', install.fixInstallation); |
2327 |
08 Apr 14 |
nicklas |
Buttons.addClickHandler('btnCreateMissingItems', install.fixInstallation); |
6713 |
28 Apr 22 |
nicklas |
Buttons.addClickHandler('btnReggieUpdated', install.fixInstallation); |
2327 |
08 Apr 14 |
nicklas |
17 |
|
2618 |
01 Sep 14 |
nicklas |
install.checkInstallation('Validate', 'Checking installation...'); |
2327 |
08 Apr 14 |
nicklas |
19 |
} |
2327 |
08 Apr 14 |
nicklas |
20 |
|
2327 |
08 Apr 14 |
nicklas |
install.fixInstallation = function() |
2327 |
08 Apr 14 |
nicklas |
22 |
{ |
2618 |
01 Sep 14 |
nicklas |
install.checkInstallation('Install', 'Fixing installation...'); |
2327 |
08 Apr 14 |
nicklas |
24 |
} |
2327 |
08 Apr 14 |
nicklas |
25 |
|
2327 |
08 Apr 14 |
nicklas |
26 |
|
2618 |
01 Sep 14 |
nicklas |
install.checkInstallation = function(cmd, workText) |
2327 |
08 Apr 14 |
nicklas |
28 |
{ |
4361 |
16 Feb 17 |
nicklas |
Doc.hide('item-list'); |
4361 |
16 Feb 17 |
nicklas |
Doc.hide('itemTable'); |
2618 |
01 Sep 14 |
nicklas |
Doc.hide('createMissingItems'); |
2618 |
01 Sep 14 |
nicklas |
Doc.hide('fixIncompleteItems'); |
6713 |
28 Apr 22 |
nicklas |
Doc.hide('registerUpdated'); |
2618 |
01 Sep 14 |
nicklas |
34 |
|
2327 |
08 Apr 14 |
nicklas |
var url = '../Install.servlet?ID=' + App.getSessionId(); |
2327 |
08 Apr 14 |
nicklas |
url += '&cmd='+cmd; |
2618 |
01 Sep 14 |
nicklas |
Doc.addClass('workInProgress', 'working'); |
2618 |
01 Sep 14 |
nicklas |
Wizard.showLoadingAnimation(workText); |
2618 |
01 Sep 14 |
nicklas |
Wizard.asyncJsonRequest(url, install.onChecked); |
2327 |
08 Apr 14 |
nicklas |
40 |
} |
2327 |
08 Apr 14 |
nicklas |
41 |
|
2618 |
01 Sep 14 |
nicklas |
install.onChecked = function(response) |
2327 |
08 Apr 14 |
nicklas |
43 |
{ |
2618 |
01 Sep 14 |
nicklas |
Doc.removeClass('workInProgress', 'working'); |
2327 |
08 Apr 14 |
nicklas |
45 |
|
4361 |
16 Feb 17 |
nicklas |
checks = response.checks; |
2327 |
08 Apr 14 |
nicklas |
47 |
|
2327 |
08 Apr 14 |
nicklas |
var numMissing = 0; |
2327 |
08 Apr 14 |
nicklas |
var numWarnings = 0; |
2327 |
08 Apr 14 |
nicklas |
var numErrors = 0; |
2327 |
08 Apr 14 |
nicklas |
var numIncomplete = 0; |
4361 |
16 Feb 17 |
nicklas |
52 |
|
2327 |
08 Apr 14 |
nicklas |
var index = 0; |
2327 |
08 Apr 14 |
nicklas |
var topLines = []; // Top lines are for items with error/warning/special message |
2327 |
08 Apr 14 |
nicklas |
var bottomLines = []; // Bottom lines are for all 'OK' items |
2327 |
08 Apr 14 |
nicklas |
var allOk = true; |
2327 |
08 Apr 14 |
nicklas |
var clickableItems = []; |
4361 |
16 Feb 17 |
nicklas |
var typeFilter = Doc.element('typeFilter'); |
4361 |
16 Feb 17 |
nicklas |
typeFilter.length = 0; |
4361 |
16 Feb 17 |
nicklas |
typeFilter[0] = new Option(); |
4361 |
16 Feb 17 |
nicklas |
var types = []; |
2327 |
08 Apr 14 |
nicklas |
62 |
|
4361 |
16 Feb 17 |
nicklas |
for (var checkNo = 0; checkNo < checks.length; checkNo++) |
2327 |
08 Apr 14 |
nicklas |
64 |
{ |
4361 |
16 Feb 17 |
nicklas |
var check = checks[checkNo]; |
4361 |
16 Feb 17 |
nicklas |
66 |
|
2327 |
08 Apr 14 |
nicklas |
var icon = 'ok.png'; |
2327 |
08 Apr 14 |
nicklas |
check.ok = true; |
6864 |
04 Nov 22 |
nicklas |
check.fixable = false; |
2327 |
08 Apr 14 |
nicklas |
if (check.status == 'missing') |
2327 |
08 Apr 14 |
nicklas |
71 |
{ |
2327 |
08 Apr 14 |
nicklas |
numMissing++; |
2327 |
08 Apr 14 |
nicklas |
icon = 'error.png'; |
2327 |
08 Apr 14 |
nicklas |
check.ok = false; |
6864 |
04 Nov 22 |
nicklas |
check.fixable = true; |
2327 |
08 Apr 14 |
nicklas |
76 |
} |
2327 |
08 Apr 14 |
nicklas |
if (check.status == 'incomplete') |
2327 |
08 Apr 14 |
nicklas |
78 |
{ |
2327 |
08 Apr 14 |
nicklas |
numIncomplete++; |
2327 |
08 Apr 14 |
nicklas |
icon = 'warning.png'; |
2327 |
08 Apr 14 |
nicklas |
check.ok = false; |
6864 |
04 Nov 22 |
nicklas |
check.fixable = true; |
2327 |
08 Apr 14 |
nicklas |
83 |
} |
2327 |
08 Apr 14 |
nicklas |
if (check.status == 'error') |
2327 |
08 Apr 14 |
nicklas |
85 |
{ |
2327 |
08 Apr 14 |
nicklas |
numErrors++; |
2327 |
08 Apr 14 |
nicklas |
icon = 'error.png'; |
2327 |
08 Apr 14 |
nicklas |
check.ok = false; |
2327 |
08 Apr 14 |
nicklas |
89 |
} |
2327 |
08 Apr 14 |
nicklas |
if (check.status == 'warning') |
2327 |
08 Apr 14 |
nicklas |
91 |
{ |
2327 |
08 Apr 14 |
nicklas |
numWarnings++; |
2327 |
08 Apr 14 |
nicklas |
icon = 'warning.png'; |
2327 |
08 Apr 14 |
nicklas |
check.ok = false; |
2327 |
08 Apr 14 |
nicklas |
95 |
} |
2327 |
08 Apr 14 |
nicklas |
allOk &= check.ok; |
2327 |
08 Apr 14 |
nicklas |
97 |
|
4361 |
16 Feb 17 |
nicklas |
if (!types[check.itemType]) |
2327 |
08 Apr 14 |
nicklas |
99 |
{ |
4361 |
16 Feb 17 |
nicklas |
typeFilter[typeFilter.length] = new Option(check.itemType); |
4361 |
16 Feb 17 |
nicklas |
types[check.itemType] = 1; |
2327 |
08 Apr 14 |
nicklas |
102 |
} |
2327 |
08 Apr 14 |
nicklas |
103 |
|
4361 |
16 Feb 17 |
nicklas |
var line = '<tr id="check'+checkNo+'"class="highlight '+check.itemType+' ' + (check.ok ? 'check-ok' : 'check-not-ok') + '">'; |
4361 |
16 Feb 17 |
nicklas |
line += '<td class="indexCol"><span id="index.'+checkNo+'">'+(checkNo+1)+'</span></td>'; |
4361 |
16 Feb 17 |
nicklas |
106 |
|
4361 |
16 Feb 17 |
nicklas |
line += '<td class="dottedleft">'+Strings.encodeTags(check.itemType)+'</td>'; |
4361 |
16 Feb 17 |
nicklas |
var name = Strings.encodeTags(check.name); |
2327 |
08 Apr 14 |
nicklas |
if (check.mainType) name += ' <span class="itemsubtype">[' + check.mainType + ']</span>'; |
2327 |
08 Apr 14 |
nicklas |
if (check.id) |
2327 |
08 Apr 14 |
nicklas |
111 |
{ |
2327 |
08 Apr 14 |
nicklas |
clickableItems[clickableItems.length] = check.itemType+check.id; |
4361 |
16 Feb 17 |
nicklas |
line += '<td><div class="link" id="'+check.itemType+check.id+'" data-item-type="'+check.itemType+'" data-item-id="'+check.id+'"'; |
2327 |
08 Apr 14 |
nicklas |
line += ' title="View this item (use CTRL, ALT or SHIFT to edit)">'+name+'</div></td>'; |
2327 |
08 Apr 14 |
nicklas |
115 |
} |
2327 |
08 Apr 14 |
nicklas |
else |
2327 |
08 Apr 14 |
nicklas |
117 |
{ |
2327 |
08 Apr 14 |
nicklas |
line += '<td class="itemTypeCol"><i>' + name + '</i></td>'; |
2327 |
08 Apr 14 |
nicklas |
119 |
} |
6864 |
04 Nov 22 |
nicklas |
line += '<td class="iconCol">'; |
6864 |
04 Nov 22 |
nicklas |
if (check.fixable) line += '<img src="../../../images/fixit.png">'; |
6864 |
04 Nov 22 |
nicklas |
line += '<img src="../images/'+icon+'">'; |
6864 |
04 Nov 22 |
nicklas |
line += '</td>'; |
4361 |
16 Feb 17 |
nicklas |
line += '<td>'; |
2327 |
08 Apr 14 |
nicklas |
if (check.messages.length > 1) |
2327 |
08 Apr 14 |
nicklas |
126 |
{ |
2327 |
08 Apr 14 |
nicklas |
for (var m = 0; m < check.messages.length; m++) |
2327 |
08 Apr 14 |
nicklas |
128 |
{ |
2327 |
08 Apr 14 |
nicklas |
line += '• '+check.messages[m] + '<br>'; |
2327 |
08 Apr 14 |
nicklas |
130 |
} |
2327 |
08 Apr 14 |
nicklas |
131 |
} |
2327 |
08 Apr 14 |
nicklas |
else |
2327 |
08 Apr 14 |
nicklas |
133 |
{ |
2327 |
08 Apr 14 |
nicklas |
line += check.messages; |
2327 |
08 Apr 14 |
nicklas |
135 |
} |
5962 |
03 Jun 20 |
nicklas |
if (check.stderr) |
5962 |
03 Jun 20 |
nicklas |
137 |
{ |
5962 |
03 Jun 20 |
nicklas |
line += '<div class="stacktrace">'+Strings.encodeTags(check.stderr)+'</div>'; |
5962 |
03 Jun 20 |
nicklas |
139 |
} |
2327 |
08 Apr 14 |
nicklas |
line += '</td></tr>'; |
2327 |
08 Apr 14 |
nicklas |
141 |
|
2327 |
08 Apr 14 |
nicklas |
if (!check.ok || check.messages != 'Ok') |
2327 |
08 Apr 14 |
nicklas |
143 |
{ |
2327 |
08 Apr 14 |
nicklas |
topLines[topLines.length] = line; |
2327 |
08 Apr 14 |
nicklas |
145 |
} |
2327 |
08 Apr 14 |
nicklas |
else |
2327 |
08 Apr 14 |
nicklas |
147 |
{ |
2327 |
08 Apr 14 |
nicklas |
bottomLines[bottomLines.length] = line; |
2327 |
08 Apr 14 |
nicklas |
149 |
} |
2327 |
08 Apr 14 |
nicklas |
index++; |
2327 |
08 Apr 14 |
nicklas |
151 |
} |
2327 |
08 Apr 14 |
nicklas |
152 |
|
4361 |
16 Feb 17 |
nicklas |
if (topLines.length + bottomLines.length > 0) |
2327 |
08 Apr 14 |
nicklas |
154 |
{ |
4361 |
16 Feb 17 |
nicklas |
Doc.element('item-list').innerHTML = topLines.join('') + bottomLines.join(''); |
4361 |
16 Feb 17 |
nicklas |
Doc.show('item-list'); |
2327 |
08 Apr 14 |
nicklas |
157 |
} |
4361 |
16 Feb 17 |
nicklas |
Doc.show('itemTable', 'table'); |
2618 |
01 Sep 14 |
nicklas |
159 |
|
2327 |
08 Apr 14 |
nicklas |
// Add click handler to items |
2327 |
08 Apr 14 |
nicklas |
for (var i = 0; i < clickableItems.length; i++) |
2327 |
08 Apr 14 |
nicklas |
162 |
{ |
2327 |
08 Apr 14 |
nicklas |
Events.addEventHandler(clickableItems[i], 'click', Items.itemOnClick); |
2327 |
08 Apr 14 |
nicklas |
164 |
} |
2327 |
08 Apr 14 |
nicklas |
165 |
|
2327 |
08 Apr 14 |
nicklas |
if (numErrors > 0) |
2327 |
08 Apr 14 |
nicklas |
167 |
{ |
4361 |
16 Feb 17 |
nicklas |
Wizard.setWizardStatus('messagecontainer error', numErrors+' errors was detected. You need to fix those manually.'); |
2327 |
08 Apr 14 |
nicklas |
169 |
} |
2618 |
01 Sep 14 |
nicklas |
else if (numMissing > 0) |
2618 |
01 Sep 14 |
nicklas |
171 |
{ |
2618 |
01 Sep 14 |
nicklas |
Doc.show('createMissingItems'); |
2618 |
01 Sep 14 |
nicklas |
173 |
} |
2618 |
01 Sep 14 |
nicklas |
else if (numIncomplete > 0) |
2618 |
01 Sep 14 |
nicklas |
175 |
{ |
2618 |
01 Sep 14 |
nicklas |
Doc.show('fixIncompleteItems'); |
2618 |
01 Sep 14 |
nicklas |
177 |
} |
6713 |
28 Apr 22 |
nicklas |
else |
2327 |
08 Apr 14 |
nicklas |
179 |
{ |
6713 |
28 Apr 22 |
nicklas |
if (numWarnings > 0) |
6713 |
28 Apr 22 |
nicklas |
181 |
{ |
6713 |
28 Apr 22 |
nicklas |
Wizard.setWizardStatus('all-checks-passed with-warnings', numWarnings+' warnings was detected. Reggie may still work. If not, you need to fix it manually.'); |
6713 |
28 Apr 22 |
nicklas |
183 |
} |
6713 |
28 Apr 22 |
nicklas |
else |
6713 |
28 Apr 22 |
nicklas |
185 |
{ |
6713 |
28 Apr 22 |
nicklas |
Wizard.setWizardStatus('all-checks-passed', 'All checks passed'); |
6713 |
28 Apr 22 |
nicklas |
187 |
} |
6713 |
28 Apr 22 |
nicklas |
if (response.installedVersion != Reggie.VERSION) |
6713 |
28 Apr 22 |
nicklas |
189 |
{ |
6713 |
28 Apr 22 |
nicklas |
Doc.show('registerUpdated'); |
6713 |
28 Apr 22 |
nicklas |
191 |
} |
2327 |
08 Apr 14 |
nicklas |
192 |
} |
2327 |
08 Apr 14 |
nicklas |
193 |
} |
2327 |
08 Apr 14 |
nicklas |
194 |
|
4361 |
16 Feb 17 |
nicklas |
install.filterOnChange = function() |
2327 |
08 Apr 14 |
nicklas |
196 |
{ |
4361 |
16 Feb 17 |
nicklas |
197 |
|
4361 |
16 Feb 17 |
nicklas |
var filter = new Filter(); |
4361 |
16 Feb 17 |
nicklas |
filter.addTextCriteria(ItemProperty.ItemType, Doc.element('typeFilter').value); |
4361 |
16 Feb 17 |
nicklas |
filter.addContainsCriteria(ItemProperty.Name, Doc.element('nameFilter').value); |
4361 |
16 Feb 17 |
nicklas |
filter.addContainsCriteria(ItemProperty.Messages, Doc.element('messageFilter').value); |
4361 |
16 Feb 17 |
nicklas |
202 |
|
4361 |
16 Feb 17 |
nicklas |
var numMatch = 0; |
4361 |
16 Feb 17 |
nicklas |
for (var checkNo = 0; checkNo < checks.length; checkNo++) |
4361 |
16 Feb 17 |
nicklas |
205 |
{ |
4361 |
16 Feb 17 |
nicklas |
var check = checks[checkNo]; |
4361 |
16 Feb 17 |
nicklas |
207 |
|
4361 |
16 Feb 17 |
nicklas |
check.include = filter.check(check); |
4361 |
16 Feb 17 |
nicklas |
if (check.include) |
4361 |
16 Feb 17 |
nicklas |
210 |
{ |
4361 |
16 Feb 17 |
nicklas |
numMatch++; |
4361 |
16 Feb 17 |
nicklas |
Doc.show('check'+checkNo); |
4361 |
16 Feb 17 |
nicklas |
213 |
} |
4361 |
16 Feb 17 |
nicklas |
else |
4361 |
16 Feb 17 |
nicklas |
215 |
{ |
4361 |
16 Feb 17 |
nicklas |
Doc.hide('check'+checkNo); |
4361 |
16 Feb 17 |
nicklas |
217 |
} |
4361 |
16 Feb 17 |
nicklas |
218 |
} |
4361 |
16 Feb 17 |
nicklas |
219 |
|
4361 |
16 Feb 17 |
nicklas |
Doc.showHide('item-list', numMatch > 0); |
4361 |
16 Feb 17 |
nicklas |
Doc.showHide('no-matching-items', numMatch==0); |
2327 |
08 Apr 14 |
nicklas |
222 |
} |
2327 |
08 Apr 14 |
nicklas |
223 |
|
2327 |
08 Apr 14 |
nicklas |
224 |
|
2327 |
08 Apr 14 |
nicklas |
return install; |
2327 |
08 Apr 14 |
nicklas |
226 |
}(); |
2327 |
08 Apr 14 |
nicklas |
227 |
|
2327 |
08 Apr 14 |
nicklas |
Doc.onLoad(Install.initPage); |
4361 |
16 Feb 17 |
nicklas |
229 |
|
4361 |
16 Feb 17 |
nicklas |
var ItemProperty = function() |
4361 |
16 Feb 17 |
nicklas |
231 |
{ |
4361 |
16 Feb 17 |
nicklas |
var p = {}; |
4361 |
16 Feb 17 |
nicklas |
233 |
|
4361 |
16 Feb 17 |
nicklas |
p.Name = function(item) |
4361 |
16 Feb 17 |
nicklas |
235 |
{ |
4361 |
16 Feb 17 |
nicklas |
return item.name; |
4361 |
16 Feb 17 |
nicklas |
237 |
} |
4361 |
16 Feb 17 |
nicklas |
238 |
|
4361 |
16 Feb 17 |
nicklas |
p.ItemType = function(item) |
4361 |
16 Feb 17 |
nicklas |
240 |
{ |
4361 |
16 Feb 17 |
nicklas |
return item.itemType; |
4361 |
16 Feb 17 |
nicklas |
242 |
} |
4361 |
16 Feb 17 |
nicklas |
243 |
|
4361 |
16 Feb 17 |
nicklas |
p.Messages = function(item) |
4361 |
16 Feb 17 |
nicklas |
245 |
{ |
4361 |
16 Feb 17 |
nicklas |
return item.messages.join(''); |
4361 |
16 Feb 17 |
nicklas |
247 |
} |
4361 |
16 Feb 17 |
nicklas |
248 |
|
4361 |
16 Feb 17 |
nicklas |
return p; |
4361 |
16 Feb 17 |
nicklas |
250 |
}(); |
4361 |
16 Feb 17 |
nicklas |
251 |
|
4361 |
16 Feb 17 |
nicklas |
252 |
/** |
4361 |
16 Feb 17 |
nicklas |
Holds one or more filter criterias. Use the 'add*' methods |
4361 |
16 Feb 17 |
nicklas |
to add criterias to the filter, and the 'check(item)' method |
4361 |
16 Feb 17 |
nicklas |
to evaluate all criterias against a single item. |
4361 |
16 Feb 17 |
nicklas |
256 |
*/ |
4361 |
16 Feb 17 |
nicklas |
var Filter = function() |
4361 |
16 Feb 17 |
nicklas |
258 |
{ |
4361 |
16 Feb 17 |
nicklas |
this.criterias = []; |
4361 |
16 Feb 17 |
nicklas |
260 |
} |
4361 |
16 Feb 17 |
nicklas |
261 |
|
4361 |
16 Feb 17 |
nicklas |
262 |
/** |
4361 |
16 Feb 17 |
nicklas |
Adds a text criteria comparing the given item property to |
4361 |
16 Feb 17 |
nicklas |
a static value (f2). |
4361 |
16 Feb 17 |
nicklas |
265 |
*/ |
4361 |
16 Feb 17 |
nicklas |
Filter.prototype.addTextCriteria = function(itemProp, f2) |
4361 |
16 Feb 17 |
nicklas |
267 |
{ |
4361 |
16 Feb 17 |
nicklas |
if (f2 != '') |
4361 |
16 Feb 17 |
nicklas |
269 |
{ |
4361 |
16 Feb 17 |
nicklas |
var cmp; |
4361 |
16 Feb 17 |
nicklas |
if (f2 == '=') |
4361 |
16 Feb 17 |
nicklas |
272 |
{ |
4361 |
16 Feb 17 |
nicklas |
cmp = Comparator.eq; |
4361 |
16 Feb 17 |
nicklas |
f2 = null; |
4361 |
16 Feb 17 |
nicklas |
275 |
} |
4361 |
16 Feb 17 |
nicklas |
else if (f2 == '<>') |
4361 |
16 Feb 17 |
nicklas |
277 |
{ |
4361 |
16 Feb 17 |
nicklas |
cmp = Comparator.neq; |
4361 |
16 Feb 17 |
nicklas |
f2 = null; |
4361 |
16 Feb 17 |
nicklas |
280 |
} |
4361 |
16 Feb 17 |
nicklas |
else |
4361 |
16 Feb 17 |
nicklas |
282 |
{ |
4361 |
16 Feb 17 |
nicklas |
cmp = Comparator.eq; |
4361 |
16 Feb 17 |
nicklas |
284 |
} |
4361 |
16 Feb 17 |
nicklas |
this.criterias[this.criterias.length] = function(item) { return cmp(itemProp(item), f2) }; |
4361 |
16 Feb 17 |
nicklas |
286 |
} |
4361 |
16 Feb 17 |
nicklas |
287 |
} |
4361 |
16 Feb 17 |
nicklas |
288 |
|
4361 |
16 Feb 17 |
nicklas |
289 |
/** |
4361 |
16 Feb 17 |
nicklas |
Adds a text criteria checking if the given item property to |
4361 |
16 Feb 17 |
nicklas |
contains a static value (f2). |
4361 |
16 Feb 17 |
nicklas |
292 |
*/ |
4361 |
16 Feb 17 |
nicklas |
Filter.prototype.addContainsCriteria = function(itemProp, f2) |
4361 |
16 Feb 17 |
nicklas |
294 |
{ |
4361 |
16 Feb 17 |
nicklas |
if (f2 != '') |
4361 |
16 Feb 17 |
nicklas |
296 |
{ |
4361 |
16 Feb 17 |
nicklas |
var cmp; |
4361 |
16 Feb 17 |
nicklas |
if (f2 == '=') |
4361 |
16 Feb 17 |
nicklas |
299 |
{ |
4361 |
16 Feb 17 |
nicklas |
cmp = Comparator.eq; |
4361 |
16 Feb 17 |
nicklas |
f2 = null; |
4361 |
16 Feb 17 |
nicklas |
302 |
} |
4361 |
16 Feb 17 |
nicklas |
else if (f2 == '<>') |
4361 |
16 Feb 17 |
nicklas |
304 |
{ |
4361 |
16 Feb 17 |
nicklas |
cmp = Comparator.neq; |
4361 |
16 Feb 17 |
nicklas |
f2 = null; |
4361 |
16 Feb 17 |
nicklas |
307 |
} |
4361 |
16 Feb 17 |
nicklas |
else |
4361 |
16 Feb 17 |
nicklas |
309 |
{ |
4361 |
16 Feb 17 |
nicklas |
cmp = Comparator.contains; |
4361 |
16 Feb 17 |
nicklas |
311 |
} |
4361 |
16 Feb 17 |
nicklas |
this.criterias[this.criterias.length] = function(item) { return cmp(itemProp(item), f2) }; |
4361 |
16 Feb 17 |
nicklas |
313 |
} |
4361 |
16 Feb 17 |
nicklas |
314 |
} |
4361 |
16 Feb 17 |
nicklas |
315 |
|
4361 |
16 Feb 17 |
nicklas |
316 |
/** |
4361 |
16 Feb 17 |
nicklas |
Evaluate all criterias. Return true if all pass, false otherwise. |
4361 |
16 Feb 17 |
nicklas |
318 |
*/ |
4361 |
16 Feb 17 |
nicklas |
Filter.prototype.check = function(item) |
4361 |
16 Feb 17 |
nicklas |
320 |
{ |
4361 |
16 Feb 17 |
nicklas |
for (var i = 0; i < this.criterias.length; i++) |
4361 |
16 Feb 17 |
nicklas |
322 |
{ |
4361 |
16 Feb 17 |
nicklas |
if (!this.criterias[i](item)) return false; |
4361 |
16 Feb 17 |
nicklas |
324 |
} |
4361 |
16 Feb 17 |
nicklas |
return true; |
4361 |
16 Feb 17 |
nicklas |
326 |
} |
4361 |
16 Feb 17 |
nicklas |
327 |
|
4361 |
16 Feb 17 |
nicklas |
328 |
|
4361 |
16 Feb 17 |
nicklas |
var Comparator = function() |
4361 |
16 Feb 17 |
nicklas |
330 |
{ |
4361 |
16 Feb 17 |
nicklas |
var cmp = {}; |
4361 |
16 Feb 17 |
nicklas |
332 |
|
4361 |
16 Feb 17 |
nicklas |
333 |
/** |
4361 |
16 Feb 17 |
nicklas |
Return a comparator based on the symbol |
4361 |
16 Feb 17 |
nicklas |
which can be either '>' or '<' to return |
4361 |
16 Feb 17 |
nicklas |
Comparator.gt or Comparator.lt. Otherwise |
4361 |
16 Feb 17 |
nicklas |
the given default or Comparator.eq is returned. |
4361 |
16 Feb 17 |
nicklas |
338 |
*/ |
4361 |
16 Feb 17 |
nicklas |
cmp.get = function(symbol, defaultCmp) |
4361 |
16 Feb 17 |
nicklas |
340 |
{ |
4361 |
16 Feb 17 |
nicklas |
var c; |
4361 |
16 Feb 17 |
nicklas |
if (symbol == '<') |
4361 |
16 Feb 17 |
nicklas |
343 |
{ |
4361 |
16 Feb 17 |
nicklas |
c = cmp.lt; |
4361 |
16 Feb 17 |
nicklas |
345 |
} |
4361 |
16 Feb 17 |
nicklas |
else if (symbol == '>') |
4361 |
16 Feb 17 |
nicklas |
347 |
{ |
4361 |
16 Feb 17 |
nicklas |
c = cmp.gt; |
4361 |
16 Feb 17 |
nicklas |
349 |
} |
4361 |
16 Feb 17 |
nicklas |
else |
4361 |
16 Feb 17 |
nicklas |
351 |
{ |
4361 |
16 Feb 17 |
nicklas |
c = defaultCmp || cmp.eq; |
4361 |
16 Feb 17 |
nicklas |
353 |
} |
4361 |
16 Feb 17 |
nicklas |
return c; |
4361 |
16 Feb 17 |
nicklas |
355 |
} |
4361 |
16 Feb 17 |
nicklas |
356 |
|
4361 |
16 Feb 17 |
nicklas |
// Compare if two values are equal |
4361 |
16 Feb 17 |
nicklas |
cmp.eq = function(v1, v2) |
4361 |
16 Feb 17 |
nicklas |
359 |
{ |
4361 |
16 Feb 17 |
nicklas |
return v1 == v2; |
4361 |
16 Feb 17 |
nicklas |
361 |
} |
4361 |
16 Feb 17 |
nicklas |
362 |
|
4361 |
16 Feb 17 |
nicklas |
// Compare if two values are different |
4361 |
16 Feb 17 |
nicklas |
cmp.neq = function(v1, v2) |
4361 |
16 Feb 17 |
nicklas |
365 |
{ |
4361 |
16 Feb 17 |
nicklas |
return v1 != v2; |
4361 |
16 Feb 17 |
nicklas |
367 |
} |
4361 |
16 Feb 17 |
nicklas |
368 |
|
4361 |
16 Feb 17 |
nicklas |
// Check if v2 is contained in v1 |
4361 |
16 Feb 17 |
nicklas |
cmp.contains = function(v1, v2) |
4361 |
16 Feb 17 |
nicklas |
371 |
{ |
4361 |
16 Feb 17 |
nicklas |
return v1 != null && v2 != null && v1.indexOf(v2) >= 0; |
4361 |
16 Feb 17 |
nicklas |
373 |
} |
4361 |
16 Feb 17 |
nicklas |
374 |
|
4361 |
16 Feb 17 |
nicklas |
// Compare if two values are appoximately equals (difference is not more than 0.05) |
4361 |
16 Feb 17 |
nicklas |
cmp.approx = function(v1, v2) |
4361 |
16 Feb 17 |
nicklas |
377 |
{ |
4361 |
16 Feb 17 |
nicklas |
return Math.abs(v2 - v1) < 0.05; |
4361 |
16 Feb 17 |
nicklas |
379 |
} |
4361 |
16 Feb 17 |
nicklas |
380 |
|
4361 |
16 Feb 17 |
nicklas |
// Compare if v1 starts with the same string as v2 |
4361 |
16 Feb 17 |
nicklas |
cmp.startsWith = function(v1, v2) |
4361 |
16 Feb 17 |
nicklas |
383 |
{ |
4361 |
16 Feb 17 |
nicklas |
return v1 != null && v1.indexOf(v2) == 0; |
4361 |
16 Feb 17 |
nicklas |
385 |
} |
4361 |
16 Feb 17 |
nicklas |
386 |
|
4361 |
16 Feb 17 |
nicklas |
// Compare if v1 is greater than or equal to v2 |
4361 |
16 Feb 17 |
nicklas |
cmp.gt = function(v1, v2) |
4361 |
16 Feb 17 |
nicklas |
389 |
{ |
4361 |
16 Feb 17 |
nicklas |
return v1 != null && v2 != null && v1 >= v2; |
4361 |
16 Feb 17 |
nicklas |
391 |
} |
4361 |
16 Feb 17 |
nicklas |
392 |
|
4361 |
16 Feb 17 |
nicklas |
// Compare if v1 is less than or equal to v2 |
4361 |
16 Feb 17 |
nicklas |
cmp.lt = function(v1, v2) |
4361 |
16 Feb 17 |
nicklas |
395 |
{ |
4361 |
16 Feb 17 |
nicklas |
return v1 != null && v2 != null && v1 <= v2; |
4361 |
16 Feb 17 |
nicklas |
397 |
} |
4361 |
16 Feb 17 |
nicklas |
398 |
|
4361 |
16 Feb 17 |
nicklas |
return cmp; |
4361 |
16 Feb 17 |
nicklas |
400 |
}(); |
4361 |
16 Feb 17 |
nicklas |
401 |
|
4361 |
16 Feb 17 |
nicklas |
402 |
|
4361 |
16 Feb 17 |
nicklas |
403 |
|