3837 |
12 Apr 16 |
nicklas |
var StrayFiles = function() |
3837 |
12 Apr 16 |
nicklas |
2 |
{ |
3837 |
12 Apr 16 |
nicklas |
var sf = {}; |
3837 |
12 Apr 16 |
nicklas |
var debug = 0; |
3837 |
12 Apr 16 |
nicklas |
5 |
|
3838 |
13 Apr 16 |
nicklas |
var strayFolders; |
3837 |
12 Apr 16 |
nicklas |
7 |
|
3837 |
12 Apr 16 |
nicklas |
// Page initialization |
3837 |
12 Apr 16 |
nicklas |
sf.initPage = function() |
3837 |
12 Apr 16 |
nicklas |
10 |
{ |
3837 |
12 Apr 16 |
nicklas |
// Step 1 |
3838 |
13 Apr 16 |
nicklas |
Events.addEventHandler('pathFilter', 'change', sf.filterOnChange); |
3838 |
13 Apr 16 |
nicklas |
Events.addEventHandler('serverFilter', 'change', sf.filterOnChange); |
3838 |
13 Apr 16 |
nicklas |
Events.addEventHandler('dateFilter', 'change', sf.filterOnChange); |
3839 |
13 Apr 16 |
nicklas |
Events.addEventHandler('ownerFilter', 'change', sf.filterOnChange); |
3837 |
12 Apr 16 |
nicklas |
16 |
|
3838 |
13 Apr 16 |
nicklas |
Buttons.addClickHandler('check_uncheck', sf.selectAll); |
3838 |
13 Apr 16 |
nicklas |
18 |
|
3838 |
13 Apr 16 |
nicklas |
Buttons.addClickHandler('btnDeleteStrayFolders', sf.deleteStrayFolders); |
3838 |
13 Apr 16 |
nicklas |
20 |
|
3837 |
12 Apr 16 |
nicklas |
// Navigation |
3837 |
12 Apr 16 |
nicklas |
Buttons.addClickHandler('gocancel', Wizard.cancelWizard); |
3837 |
12 Apr 16 |
nicklas |
Buttons.addClickHandler('gorestart', Wizard.restartWizard); |
3837 |
12 Apr 16 |
nicklas |
Buttons.addClickHandler('gonext', Wizard.goNextOnClick); |
3837 |
12 Apr 16 |
nicklas |
Buttons.addClickHandler('goregister', Wizard.goRegister); |
3837 |
12 Apr 16 |
nicklas |
26 |
|
3837 |
12 Apr 16 |
nicklas |
// Final registration |
3837 |
12 Apr 16 |
nicklas |
Events.addEventHandler('wizard', 'wizard-submit', sf.submit); |
3837 |
12 Apr 16 |
nicklas |
29 |
|
3912 |
02 May 16 |
nicklas |
Wizard.showLoadingAnimation('Searching for stray folders...', 'stray-files-progress'); |
3837 |
12 Apr 16 |
nicklas |
var url = '../Admin.servlet?ID='+App.getSessionId(); |
3843 |
13 Apr 16 |
nicklas |
url += '&cmd=FindStrayFolders'; |
3837 |
12 Apr 16 |
nicklas |
Wizard.asyncJsonRequest(url, sf.initializeStep1); |
3837 |
12 Apr 16 |
nicklas |
34 |
} |
3837 |
12 Apr 16 |
nicklas |
35 |
|
3837 |
12 Apr 16 |
nicklas |
// --- Step 1 ----------------------------------- |
3837 |
12 Apr 16 |
nicklas |
sf.initializeStep1 = function(response) |
3837 |
12 Apr 16 |
nicklas |
38 |
{ |
3838 |
13 Apr 16 |
nicklas |
var frm = document.forms['reggie']; |
3837 |
12 Apr 16 |
nicklas |
var fileServers = response.fileServers; |
3837 |
12 Apr 16 |
nicklas |
var serverById = []; |
3837 |
12 Apr 16 |
nicklas |
for (var serverNo = 0; serverNo < fileServers.length; serverNo++) |
3837 |
12 Apr 16 |
nicklas |
43 |
{ |
3837 |
12 Apr 16 |
nicklas |
var fs = fileServers[serverNo]; |
3837 |
12 Apr 16 |
nicklas |
serverById['id-'+fs.id] = fs; |
3837 |
12 Apr 16 |
nicklas |
fs.encodedName = Strings.encodeTags(fs.name); |
3838 |
13 Apr 16 |
nicklas |
frm.serverFilter[frm.serverFilter.length] = new Option(fs.name, fs.id); |
3837 |
12 Apr 16 |
nicklas |
48 |
} |
3837 |
12 Apr 16 |
nicklas |
49 |
|
3838 |
13 Apr 16 |
nicklas |
strayFolders = response.strayFolders; |
3837 |
12 Apr 16 |
nicklas |
var html = ''; |
3837 |
12 Apr 16 |
nicklas |
for (var strayNo = 0; strayNo < strayFolders.length; strayNo++) |
3837 |
12 Apr 16 |
nicklas |
53 |
{ |
3837 |
12 Apr 16 |
nicklas |
var folder = strayFolders[strayNo]; |
3838 |
13 Apr 16 |
nicklas |
folder.include = true; |
3843 |
13 Apr 16 |
nicklas |
folder.index = strayNo; |
3837 |
12 Apr 16 |
nicklas |
var server = serverById['id-'+folder.fileServer]; |
3837 |
12 Apr 16 |
nicklas |
58 |
|
3838 |
13 Apr 16 |
nicklas |
html += '<tr class="highlight" id="stray.'+strayNo+'">'; |
3838 |
13 Apr 16 |
nicklas |
html += '<td><span id="index.'+strayNo+'">'+(strayNo+1)+'</span> <input type="checkbox" name="check.'+strayNo+'" value="'+strayNo+'"></td>' |
3837 |
12 Apr 16 |
nicklas |
html += '<td>'; |
3837 |
12 Apr 16 |
nicklas |
html += '<span class="link file-link" data-server="'+server.id+'" data-folder="'+Strings.encodeTags(folder.path)+'" title="View files in this folder"><img src="../images/remote_folder.png"></span>'; |
3837 |
12 Apr 16 |
nicklas |
html += Strings.encodeTags(folder.path); |
3837 |
12 Apr 16 |
nicklas |
html += '</td>'; |
3838 |
13 Apr 16 |
nicklas |
html += '<td>'+server.encodedName+'</td>'; |
3838 |
13 Apr 16 |
nicklas |
html += '<td>' + Reggie.reformatDate(folder.lastModified) + '</td>'; |
3839 |
13 Apr 16 |
nicklas |
html += '<td>' + Strings.encodeTags(folder.owner) + '</td>'; |
3837 |
12 Apr 16 |
nicklas |
html += '</tr>'; |
3837 |
12 Apr 16 |
nicklas |
69 |
} |
3837 |
12 Apr 16 |
nicklas |
70 |
|
3837 |
12 Apr 16 |
nicklas |
Doc.element('strayFilesSection').innerHTML = html; |
3838 |
13 Apr 16 |
nicklas |
Doc.element('num-stray').innerHTML = Reggie.formatCount(strayFolders.length); |
3838 |
13 Apr 16 |
nicklas |
Doc.element('num-stray').title = strayFolders.length; |
3838 |
13 Apr 16 |
nicklas |
Doc.element('num-total').innerHTML = Reggie.formatCount(response.totalFolders); |
3838 |
13 Apr 16 |
nicklas |
Doc.element('num-total').title = response.totalFolders; |
3837 |
12 Apr 16 |
nicklas |
76 |
|
3837 |
12 Apr 16 |
nicklas |
// Add click handler to file links |
3837 |
12 Apr 16 |
nicklas |
var clickableItems = document.getElementsByClassName('file-link'); |
3837 |
12 Apr 16 |
nicklas |
for (var i = 0; i < clickableItems.length; i++) |
3837 |
12 Apr 16 |
nicklas |
80 |
{ |
3837 |
12 Apr 16 |
nicklas |
Events.addEventHandler(clickableItems[i], 'click', sf.fileLinkOnClick); |
3837 |
12 Apr 16 |
nicklas |
82 |
} |
3837 |
12 Apr 16 |
nicklas |
83 |
|
3843 |
13 Apr 16 |
nicklas |
Doc.showHide('strayFilesSection', strayFolders.length > 0); |
3843 |
13 Apr 16 |
nicklas |
Doc.showHide('no-stray-files', strayFolders.length==0); |
3837 |
12 Apr 16 |
nicklas |
Doc.show('step-1'); |
3837 |
12 Apr 16 |
nicklas |
87 |
} |
3837 |
12 Apr 16 |
nicklas |
88 |
|
3838 |
13 Apr 16 |
nicklas |
sf.filterOnChange = function() |
3838 |
13 Apr 16 |
nicklas |
90 |
{ |
3838 |
13 Apr 16 |
nicklas |
var frm = document.forms['reggie']; |
3838 |
13 Apr 16 |
nicklas |
92 |
|
3838 |
13 Apr 16 |
nicklas |
var filter = new Filter(); |
3838 |
13 Apr 16 |
nicklas |
94 |
|
3838 |
13 Apr 16 |
nicklas |
filter.addTextCriteria(ItemProperty.Path, frm.pathFilter.value); |
3838 |
13 Apr 16 |
nicklas |
filter.addNumericCriteria(ItemProperty.ServerId, frm.serverFilter.value); |
3838 |
13 Apr 16 |
nicklas |
filter.addDateCriteria(ItemProperty.LastModified, frm.dateFilter.value); |
3839 |
13 Apr 16 |
nicklas |
filter.addTextCriteria(ItemProperty.Owner, frm.ownerFilter.value); |
3838 |
13 Apr 16 |
nicklas |
99 |
|
3838 |
13 Apr 16 |
nicklas |
var numMatching = 0; |
3838 |
13 Apr 16 |
nicklas |
for (var strayNo = 0; strayNo < strayFolders.length; strayNo++) |
3838 |
13 Apr 16 |
nicklas |
102 |
{ |
3838 |
13 Apr 16 |
nicklas |
var folder = strayFolders[strayNo]; |
3838 |
13 Apr 16 |
nicklas |
104 |
|
3838 |
13 Apr 16 |
nicklas |
folder.include = filter.check(folder); |
3838 |
13 Apr 16 |
nicklas |
if (folder.include) |
3838 |
13 Apr 16 |
nicklas |
107 |
{ |
3838 |
13 Apr 16 |
nicklas |
numMatching++; |
3838 |
13 Apr 16 |
nicklas |
Doc.element('index.'+strayNo).innerHTML = numMatching; |
3838 |
13 Apr 16 |
nicklas |
Doc.show('stray.'+strayNo); |
3838 |
13 Apr 16 |
nicklas |
111 |
} |
3838 |
13 Apr 16 |
nicklas |
else |
3838 |
13 Apr 16 |
nicklas |
113 |
{ |
3838 |
13 Apr 16 |
nicklas |
Doc.hide('stray.'+strayNo); |
3838 |
13 Apr 16 |
nicklas |
115 |
} |
3838 |
13 Apr 16 |
nicklas |
116 |
} |
3838 |
13 Apr 16 |
nicklas |
117 |
|
3838 |
13 Apr 16 |
nicklas |
Doc.showHide('strayFilesSection', numMatching > 0); |
3838 |
13 Apr 16 |
nicklas |
Doc.showHide('no-stray-files', numMatching==0); |
3838 |
13 Apr 16 |
nicklas |
120 |
} |
3837 |
12 Apr 16 |
nicklas |
121 |
|
3838 |
13 Apr 16 |
nicklas |
122 |
|
3837 |
12 Apr 16 |
nicklas |
sf.fileLinkOnClick = function(event) |
3837 |
12 Apr 16 |
nicklas |
124 |
{ |
3837 |
12 Apr 16 |
nicklas |
var folder = Data.get(event.currentTarget, 'folder'); |
3837 |
12 Apr 16 |
nicklas |
var server = Data.get(event.currentTarget, 'server'); |
3837 |
12 Apr 16 |
nicklas |
var url = '../analysis/view_remote_files.jsp?ID=' + App.getSessionId(); |
3837 |
12 Apr 16 |
nicklas |
url += '&fileserver='+server; |
3837 |
12 Apr 16 |
nicklas |
url += '&path='+encodeURIComponent(folder); |
3837 |
12 Apr 16 |
nicklas |
Dialogs.openPopup(url, 'ViewStrayFiles', 750, 500); |
3837 |
12 Apr 16 |
nicklas |
131 |
} |
3837 |
12 Apr 16 |
nicklas |
132 |
|
3838 |
13 Apr 16 |
nicklas |
133 |
|
3838 |
13 Apr 16 |
nicklas |
sf.selectAll = function() |
3838 |
13 Apr 16 |
nicklas |
135 |
{ |
3838 |
13 Apr 16 |
nicklas |
var frm = document.forms['reggie']; |
3838 |
13 Apr 16 |
nicklas |
var firstChecked = null; |
3838 |
13 Apr 16 |
nicklas |
for (var strayNo = 0; strayNo < strayFolders.length; strayNo++) |
3838 |
13 Apr 16 |
nicklas |
139 |
{ |
3838 |
13 Apr 16 |
nicklas |
var sf = strayFolders[strayNo]; |
3838 |
13 Apr 16 |
nicklas |
var checkbox = frm['check.'+strayNo]; |
3838 |
13 Apr 16 |
nicklas |
if (sf.include && checkbox) |
3838 |
13 Apr 16 |
nicklas |
143 |
{ |
3838 |
13 Apr 16 |
nicklas |
if (firstChecked == null) |
3838 |
13 Apr 16 |
nicklas |
145 |
{ |
3838 |
13 Apr 16 |
nicklas |
firstChecked = checkbox.checked; |
3838 |
13 Apr 16 |
nicklas |
147 |
} |
3838 |
13 Apr 16 |
nicklas |
checkbox.checked = !firstChecked; |
3838 |
13 Apr 16 |
nicklas |
149 |
} |
3838 |
13 Apr 16 |
nicklas |
150 |
} |
3838 |
13 Apr 16 |
nicklas |
151 |
} |
3838 |
13 Apr 16 |
nicklas |
152 |
|
3838 |
13 Apr 16 |
nicklas |
sf.checkSelected = function(filter, noneSelectedMsg) |
3838 |
13 Apr 16 |
nicklas |
154 |
{ |
3838 |
13 Apr 16 |
nicklas |
var frm = document.forms['reggie']; |
3838 |
13 Apr 16 |
nicklas |
var selected = []; |
3838 |
13 Apr 16 |
nicklas |
157 |
|
3838 |
13 Apr 16 |
nicklas |
for (var strayNo = 0; strayNo < strayFolders.length; strayNo++) |
3838 |
13 Apr 16 |
nicklas |
159 |
{ |
3838 |
13 Apr 16 |
nicklas |
var folder = strayFolders[strayNo]; |
3838 |
13 Apr 16 |
nicklas |
if (folder.include && frm['check.'+strayNo] && frm['check.'+strayNo].checked) |
3838 |
13 Apr 16 |
nicklas |
162 |
{ |
3838 |
13 Apr 16 |
nicklas |
if (!filter || filter.check(folder)) |
3838 |
13 Apr 16 |
nicklas |
selected[selected.length] = folder; |
3838 |
13 Apr 16 |
nicklas |
165 |
} |
3838 |
13 Apr 16 |
nicklas |
166 |
} |
3838 |
13 Apr 16 |
nicklas |
167 |
|
3838 |
13 Apr 16 |
nicklas |
if (selected.length == 0 && noneSelectedMsg) |
3838 |
13 Apr 16 |
nicklas |
169 |
{ |
3838 |
13 Apr 16 |
nicklas |
Forms.showNotification('check_uncheck', noneSelectedMsg, null, 'pointer-below'); |
3838 |
13 Apr 16 |
nicklas |
171 |
} |
3838 |
13 Apr 16 |
nicklas |
172 |
|
3838 |
13 Apr 16 |
nicklas |
return selected; |
3838 |
13 Apr 16 |
nicklas |
174 |
} |
3838 |
13 Apr 16 |
nicklas |
175 |
|
6824 |
30 Aug 22 |
nicklas |
sf.deleteStrayFolders = function() |
3838 |
13 Apr 16 |
nicklas |
177 |
{ |
3838 |
13 Apr 16 |
nicklas |
var selected = sf.checkSelected(null, 'Select at least one folder'); |
3838 |
13 Apr 16 |
nicklas |
if (selected.length == 0) return; |
3843 |
13 Apr 16 |
nicklas |
180 |
|
3843 |
13 Apr 16 |
nicklas |
if (!confirm('Delete ' + selected.length + ' folders? This action can\'t be undone.')) |
3843 |
13 Apr 16 |
nicklas |
182 |
{ |
3843 |
13 Apr 16 |
nicklas |
return; |
3843 |
13 Apr 16 |
nicklas |
184 |
} |
3843 |
13 Apr 16 |
nicklas |
185 |
|
3843 |
13 Apr 16 |
nicklas |
var index = []; |
3843 |
13 Apr 16 |
nicklas |
for (var i = 0; i < selected.length; i++) |
3843 |
13 Apr 16 |
nicklas |
188 |
{ |
3843 |
13 Apr 16 |
nicklas |
index[i] = selected[i].index; |
3843 |
13 Apr 16 |
nicklas |
190 |
} |
3843 |
13 Apr 16 |
nicklas |
191 |
|
3838 |
13 Apr 16 |
nicklas |
var submitInfo = {}; |
3838 |
13 Apr 16 |
nicklas |
submitInfo.cmd = 'DeleteStrayFolders'; |
3838 |
13 Apr 16 |
nicklas |
submitInfo.message = 'Deleting ' + selected.length + ' stray folders'; |
3843 |
13 Apr 16 |
nicklas |
submitInfo.folders = index; |
3838 |
13 Apr 16 |
nicklas |
Wizard.goRegister(submitInfo); |
3838 |
13 Apr 16 |
nicklas |
197 |
} |
3838 |
13 Apr 16 |
nicklas |
198 |
|
3838 |
13 Apr 16 |
nicklas |
199 |
|
3843 |
13 Apr 16 |
nicklas |
sf.submit = function(event) |
3837 |
12 Apr 16 |
nicklas |
201 |
{ |
3843 |
13 Apr 16 |
nicklas |
var submitInfo = event.detail; |
3843 |
13 Apr 16 |
nicklas |
var url = '../Admin.servlet?ID='+App.getSessionId(); |
3843 |
13 Apr 16 |
nicklas |
url += '&cmd='+submitInfo.cmd; |
3843 |
13 Apr 16 |
nicklas |
Wizard.showLoadingAnimation(submitInfo.message || 'Registering YellowLabel specimen...'); |
3843 |
13 Apr 16 |
nicklas |
Wizard.asyncJsonRequest(url, sf.submissionResults, 'POST', JSON.stringify(submitInfo)); |
3837 |
12 Apr 16 |
nicklas |
207 |
} |
3843 |
13 Apr 16 |
nicklas |
208 |
|
3843 |
13 Apr 16 |
nicklas |
sf.submissionResults = function(response) |
3843 |
13 Apr 16 |
nicklas |
210 |
{ |
3843 |
13 Apr 16 |
nicklas |
Wizard.showFinalMessage(response.messages); |
3843 |
13 Apr 16 |
nicklas |
Doc.show('gorestart'); |
3843 |
13 Apr 16 |
nicklas |
213 |
} |
3837 |
12 Apr 16 |
nicklas |
214 |
|
3837 |
12 Apr 16 |
nicklas |
return sf; |
3837 |
12 Apr 16 |
nicklas |
216 |
}(); |
3837 |
12 Apr 16 |
nicklas |
217 |
|
3837 |
12 Apr 16 |
nicklas |
Doc.onLoad(StrayFiles.initPage); |
3837 |
12 Apr 16 |
nicklas |
219 |
|
3838 |
13 Apr 16 |
nicklas |
220 |
/** |
3838 |
13 Apr 16 |
nicklas |
Holds one or more filter criterias. Use the 'add*' methods |
3838 |
13 Apr 16 |
nicklas |
to add criterias to the filter, and the 'check(item)' method |
3838 |
13 Apr 16 |
nicklas |
to evaluate all criterias against a single item. |
3838 |
13 Apr 16 |
nicklas |
224 |
*/ |
3838 |
13 Apr 16 |
nicklas |
var Filter = function() |
3838 |
13 Apr 16 |
nicklas |
226 |
{ |
3838 |
13 Apr 16 |
nicklas |
this.criterias = []; |
3838 |
13 Apr 16 |
nicklas |
228 |
} |
3838 |
13 Apr 16 |
nicklas |
229 |
|
3838 |
13 Apr 16 |
nicklas |
230 |
/** |
3838 |
13 Apr 16 |
nicklas |
Adds a text criteria comparing the given item property to |
3838 |
13 Apr 16 |
nicklas |
a static value (f2). |
3838 |
13 Apr 16 |
nicklas |
233 |
*/ |
3838 |
13 Apr 16 |
nicklas |
Filter.prototype.addTextCriteria = function(itemProp, f2) |
3838 |
13 Apr 16 |
nicklas |
235 |
{ |
3838 |
13 Apr 16 |
nicklas |
if (f2 != '') |
3838 |
13 Apr 16 |
nicklas |
237 |
{ |
3838 |
13 Apr 16 |
nicklas |
this.criterias[this.criterias.length] = function(item) { return Comparator.contains(itemProp(item), f2) }; |
3838 |
13 Apr 16 |
nicklas |
239 |
} |
3838 |
13 Apr 16 |
nicklas |
240 |
} |
3838 |
13 Apr 16 |
nicklas |
241 |
|
3838 |
13 Apr 16 |
nicklas |
242 |
/** |
3838 |
13 Apr 16 |
nicklas |
Adds a numeric criteria comparing the given item property to |
3838 |
13 Apr 16 |
nicklas |
a static value (f2). The 'f2' value may start with either '<' or '>' |
3838 |
13 Apr 16 |
nicklas |
to compare with less than/greater than operators, otherwise |
3838 |
13 Apr 16 |
nicklas |
it will use the 'approximately equals' operator. |
3838 |
13 Apr 16 |
nicklas |
247 |
*/ |
3838 |
13 Apr 16 |
nicklas |
Filter.prototype.addNumericCriteria = function(itemProp, f2, factor) |
3838 |
13 Apr 16 |
nicklas |
249 |
{ |
3838 |
13 Apr 16 |
nicklas |
if (f2 != '') |
3838 |
13 Apr 16 |
nicklas |
251 |
{ |
3838 |
13 Apr 16 |
nicklas |
var firstChar = f2.charAt(0); |
3838 |
13 Apr 16 |
nicklas |
if (!firstChar.match(/[\d\-]/)) f2 = f2.substring(1); |
3838 |
13 Apr 16 |
nicklas |
254 |
|
3838 |
13 Apr 16 |
nicklas |
var cmp = Comparator.get(firstChar, Comparator.approx); |
3838 |
13 Apr 16 |
nicklas |
var limit = parseFloat(f2); |
3838 |
13 Apr 16 |
nicklas |
if (factor) limit *= factor; |
3838 |
13 Apr 16 |
nicklas |
258 |
|
3838 |
13 Apr 16 |
nicklas |
this.criterias[this.criterias.length] = function(item) { return cmp(itemProp(item), limit) }; |
3838 |
13 Apr 16 |
nicklas |
260 |
} |
3838 |
13 Apr 16 |
nicklas |
261 |
} |
3838 |
13 Apr 16 |
nicklas |
262 |
|
3838 |
13 Apr 16 |
nicklas |
263 |
/** |
3838 |
13 Apr 16 |
nicklas |
Adds a temporal criteria for comparing dates. The 'f2' value |
3838 |
13 Apr 16 |
nicklas |
may start with either '<' or '>' to compare with earlier/later |
3838 |
13 Apr 16 |
nicklas |
than operators. In all cases, the 'f2' value is stripped from '-' |
3838 |
13 Apr 16 |
nicklas |
characters. |
3838 |
13 Apr 16 |
nicklas |
268 |
*/ |
3838 |
13 Apr 16 |
nicklas |
Filter.prototype.addDateCriteria = function(itemProp, f2) |
3838 |
13 Apr 16 |
nicklas |
270 |
{ |
3838 |
13 Apr 16 |
nicklas |
if (f2 != '') |
3838 |
13 Apr 16 |
nicklas |
272 |
{ |
3838 |
13 Apr 16 |
nicklas |
var firstChar = f2.charAt(0); |
3838 |
13 Apr 16 |
nicklas |
if (firstChar == '<' || firstChar == '>') f2 = f2.substring(1); |
3838 |
13 Apr 16 |
nicklas |
f2 = f2.replace(/\-/g, ''); |
3838 |
13 Apr 16 |
nicklas |
var cmp = Comparator.get(firstChar, Comparator.startsWith); |
3838 |
13 Apr 16 |
nicklas |
this.criterias[this.criterias.length] = function(item) { return cmp(itemProp(item), f2) }; |
3838 |
13 Apr 16 |
nicklas |
278 |
} |
3838 |
13 Apr 16 |
nicklas |
279 |
|
3838 |
13 Apr 16 |
nicklas |
280 |
} |
3838 |
13 Apr 16 |
nicklas |
281 |
|
3838 |
13 Apr 16 |
nicklas |
282 |
/** |
3838 |
13 Apr 16 |
nicklas |
Evaluate all criterias. Return true if all pass, false otherwise. |
3838 |
13 Apr 16 |
nicklas |
284 |
*/ |
3838 |
13 Apr 16 |
nicklas |
Filter.prototype.check = function(item) |
3838 |
13 Apr 16 |
nicklas |
286 |
{ |
3838 |
13 Apr 16 |
nicklas |
for (var i = 0; i < this.criterias.length; i++) |
3838 |
13 Apr 16 |
nicklas |
288 |
{ |
3838 |
13 Apr 16 |
nicklas |
if (!this.criterias[i](item)) return false; |
3838 |
13 Apr 16 |
nicklas |
290 |
} |
3838 |
13 Apr 16 |
nicklas |
return true; |
3838 |
13 Apr 16 |
nicklas |
292 |
} |
3838 |
13 Apr 16 |
nicklas |
293 |
|
3838 |
13 Apr 16 |
nicklas |
294 |
/** |
3838 |
13 Apr 16 |
nicklas |
Functions for extracting various properties from |
3838 |
13 Apr 16 |
nicklas |
folder items. Each method accepts a single folder as a parameter |
3838 |
13 Apr 16 |
nicklas |
and return a value from the folder item. The methods |
3838 |
13 Apr 16 |
nicklas |
are used as parameters to Filter.add*Criteria() methods. |
3838 |
13 Apr 16 |
nicklas |
299 |
*/ |
3838 |
13 Apr 16 |
nicklas |
var ItemProperty = function() |
3838 |
13 Apr 16 |
nicklas |
301 |
{ |
3838 |
13 Apr 16 |
nicklas |
var p = {}; |
3838 |
13 Apr 16 |
nicklas |
303 |
|
3838 |
13 Apr 16 |
nicklas |
p.Path = function(item) |
3838 |
13 Apr 16 |
nicklas |
305 |
{ |
3838 |
13 Apr 16 |
nicklas |
return item.path; |
3838 |
13 Apr 16 |
nicklas |
307 |
} |
3838 |
13 Apr 16 |
nicklas |
308 |
|
3838 |
13 Apr 16 |
nicklas |
p.ServerId = function(item) |
3838 |
13 Apr 16 |
nicklas |
310 |
{ |
3838 |
13 Apr 16 |
nicklas |
return item.fileServer; |
3838 |
13 Apr 16 |
nicklas |
312 |
} |
3838 |
13 Apr 16 |
nicklas |
313 |
|
3838 |
13 Apr 16 |
nicklas |
p.LastModified = function(item) |
3838 |
13 Apr 16 |
nicklas |
315 |
{ |
3838 |
13 Apr 16 |
nicklas |
return item.lastModified; |
3838 |
13 Apr 16 |
nicklas |
317 |
} |
3838 |
13 Apr 16 |
nicklas |
318 |
|
3839 |
13 Apr 16 |
nicklas |
p.Owner = function(item) |
3839 |
13 Apr 16 |
nicklas |
320 |
{ |
3839 |
13 Apr 16 |
nicklas |
return item.owner; |
3839 |
13 Apr 16 |
nicklas |
322 |
} |
3839 |
13 Apr 16 |
nicklas |
323 |
|
3838 |
13 Apr 16 |
nicklas |
return p; |
3838 |
13 Apr 16 |
nicklas |
325 |
}(); |
3838 |
13 Apr 16 |
nicklas |
326 |
|
3838 |
13 Apr 16 |
nicklas |
327 |
/** |
3838 |
13 Apr 16 |
nicklas |
Comparator functions for comparing two values. |
3838 |
13 Apr 16 |
nicklas |
329 |
*/ |
3838 |
13 Apr 16 |
nicklas |
var Comparator = function() |
3838 |
13 Apr 16 |
nicklas |
331 |
{ |
3838 |
13 Apr 16 |
nicklas |
var cmp = {}; |
3838 |
13 Apr 16 |
nicklas |
333 |
|
3838 |
13 Apr 16 |
nicklas |
334 |
/** |
3838 |
13 Apr 16 |
nicklas |
Return a comparator based on the symbol |
3838 |
13 Apr 16 |
nicklas |
which can be either '>' or '<' to return |
3838 |
13 Apr 16 |
nicklas |
Comparator.gt or Comparator.lt. Otherwise |
3838 |
13 Apr 16 |
nicklas |
the given default or Comparator.eq is returned. |
3838 |
13 Apr 16 |
nicklas |
339 |
*/ |
3838 |
13 Apr 16 |
nicklas |
cmp.get = function(symbol, defaultCmp) |
3838 |
13 Apr 16 |
nicklas |
341 |
{ |
3838 |
13 Apr 16 |
nicklas |
var c; |
3838 |
13 Apr 16 |
nicklas |
if (symbol == '<') |
3838 |
13 Apr 16 |
nicklas |
344 |
{ |
3838 |
13 Apr 16 |
nicklas |
c = cmp.lt; |
3838 |
13 Apr 16 |
nicklas |
346 |
} |
3838 |
13 Apr 16 |
nicklas |
else if (symbol == '>') |
3838 |
13 Apr 16 |
nicklas |
348 |
{ |
3838 |
13 Apr 16 |
nicklas |
c = cmp.gt; |
3838 |
13 Apr 16 |
nicklas |
350 |
} |
3838 |
13 Apr 16 |
nicklas |
else |
3838 |
13 Apr 16 |
nicklas |
352 |
{ |
3838 |
13 Apr 16 |
nicklas |
c = defaultCmp || cmp.eq; |
3838 |
13 Apr 16 |
nicklas |
354 |
} |
3838 |
13 Apr 16 |
nicklas |
return c; |
3838 |
13 Apr 16 |
nicklas |
356 |
} |
3838 |
13 Apr 16 |
nicklas |
357 |
|
3838 |
13 Apr 16 |
nicklas |
// Compare if two values are equal |
3838 |
13 Apr 16 |
nicklas |
cmp.eq = function(v1, v2) |
3838 |
13 Apr 16 |
nicklas |
360 |
{ |
3838 |
13 Apr 16 |
nicklas |
return v1 == v2; |
3838 |
13 Apr 16 |
nicklas |
362 |
} |
3838 |
13 Apr 16 |
nicklas |
363 |
|
3838 |
13 Apr 16 |
nicklas |
cmp.contains = function(v1, v2) |
3838 |
13 Apr 16 |
nicklas |
365 |
{ |
3838 |
13 Apr 16 |
nicklas |
return v1 != null && v2 != null && v1.indexOf(v2) >= 0; |
3838 |
13 Apr 16 |
nicklas |
367 |
} |
3838 |
13 Apr 16 |
nicklas |
368 |
|
3838 |
13 Apr 16 |
nicklas |
// Compare if two values are appoximately equals (difference is not more than 0.05) |
3838 |
13 Apr 16 |
nicklas |
cmp.approx = function(v1, v2) |
3838 |
13 Apr 16 |
nicklas |
371 |
{ |
3838 |
13 Apr 16 |
nicklas |
return Math.abs(v2 - v1) < 0.05; |
3838 |
13 Apr 16 |
nicklas |
373 |
} |
3838 |
13 Apr 16 |
nicklas |
374 |
|
3838 |
13 Apr 16 |
nicklas |
// Compare if v1 starts with the same string as v2 |
3838 |
13 Apr 16 |
nicklas |
cmp.startsWith = function(v1, v2) |
3838 |
13 Apr 16 |
nicklas |
377 |
{ |
3838 |
13 Apr 16 |
nicklas |
return v1 != null && v1.indexOf(v2) == 0; |
3838 |
13 Apr 16 |
nicklas |
379 |
} |
3838 |
13 Apr 16 |
nicklas |
380 |
|
3838 |
13 Apr 16 |
nicklas |
// Compare if v1 is greater than or equal to v2 |
3838 |
13 Apr 16 |
nicklas |
cmp.gt = function(v1, v2) |
3838 |
13 Apr 16 |
nicklas |
383 |
{ |
3838 |
13 Apr 16 |
nicklas |
return v1 != null && v2 != null && v1 >= v2; |
3838 |
13 Apr 16 |
nicklas |
385 |
} |
3838 |
13 Apr 16 |
nicklas |
386 |
|
3838 |
13 Apr 16 |
nicklas |
// Compare if v1 is less than or equal to v2 |
3838 |
13 Apr 16 |
nicklas |
cmp.lt = function(v1, v2) |
3838 |
13 Apr 16 |
nicklas |
389 |
{ |
3838 |
13 Apr 16 |
nicklas |
return v1 != null && v2 != null && v1 <= v2; |
3838 |
13 Apr 16 |
nicklas |
391 |
} |
3838 |
13 Apr 16 |
nicklas |
392 |
|
3838 |
13 Apr 16 |
nicklas |
return cmp; |
3838 |
13 Apr 16 |
nicklas |
394 |
}(); |