mirror of
https://github.com/ZoneMinder/zoneminder.git
synced 2026-05-19 03:56:18 -04:00
parseRows just needs to recreate the php logic
This commit is contained in:
@@ -98,54 +98,112 @@ function deleteFilter( element, name ) {
|
||||
}
|
||||
|
||||
function parseRows (rows) {
|
||||
for (let i = 0; i < rows.length; i++) { //Traverse terms(rows)
|
||||
let inputs = rows[i].children; //Array of tds
|
||||
if (i == 0) $j(inputs[0]).html(' '); //Remove and from first term
|
||||
if (rows.length -1 > 0 && i > 0 && inputs[0].children.length == 0) { //add and/or to 1+ if doesn't exist
|
||||
$j(inputs[0]).html('<select name="filter[Query][terms][' + i + '][cnj]" id="filter[Query][terms][' + i + '][cnj]"><option value="and">and</option><option value="or">or</option></select>');
|
||||
for (let rowNum = 0; rowNum < rows.length; rowNum++) { //Each row is a term
|
||||
let queryPrefix = 'filter[Query][terms][';
|
||||
let inputTds = rows.eq(rowNum).children();
|
||||
|
||||
if (rowNum == 0) inputTds.eq(0).html(' '); //Remove and from first term
|
||||
if (rowNum > 0) { //add and/or to 1+
|
||||
let cnjVal = inputTds.eq(0).children().val();
|
||||
let conjSelect = $j('<select></select>').attr('name', queryPrefix + rowNum + '][cnj]').attr('id', queryPrefix + rowNum + '][cnj]');
|
||||
$j.each(conjTypes, function (i) {
|
||||
conjSelect.append('<option value="' + i + '" >' + i + '</option>');
|
||||
});
|
||||
inputTds.eq(0).html(conjSelect).children().val(cnjVal);
|
||||
}
|
||||
|
||||
let brackets = rows.length - 2;
|
||||
if (brackets > 0) { //add bracket td to all rows
|
||||
let obr = '<select name="filter[Query][terms][' + i + '][obr]" id="filter[Query][terms][' + i + '][obr]"><option value="0"></option>';
|
||||
let cbr = '<select name="filter[Query][terms][' + i + '][cbr]" id="filter[Query][terms][' + i + '][cbr]"><option value="0"></option>';
|
||||
for (let k = 1; k <= brackets; k++) {//build bracket options
|
||||
obr += '<option value="' + k + '">' + '('.repeat(k) + '</option>';
|
||||
cbr += '<option value="' + k + '">' + ')'.repeat(k) + '</option>';
|
||||
if (brackets > 0) { //add bracket select to all rows
|
||||
let obrSelect = $j('<select></select>').attr('name', queryPrefix + rowNum + '][obr]').attr('id', queryPrefix + rowNum + '][obr]');
|
||||
let cbrSelect = $j('<select></select>').attr('name', queryPrefix + rowNum + '][cbr]').attr('id', queryPrefix + rowNum + '][cbr]');
|
||||
obrSelect.append('<option value="0"</option>');
|
||||
cbrSelect.append('<option value="0"</option>');
|
||||
for (let i = 1; i <= brackets; i++) {//build bracket options
|
||||
obrSelect.append('<option value="' + i + '">' + '('.repeat(i) + '</option>');
|
||||
cbrSelect.append('<option value="' + i + '">' + ')'.repeat(i) + '</option>');
|
||||
}
|
||||
obr += '</select>';
|
||||
cbr += '</select>';
|
||||
let obrVal = $j(inputs[1]).children().val(); //Save currently selected bracket option
|
||||
let cbrVal = $j(inputs[5]).children().val();
|
||||
$j(inputs[1]).html(obr).children().val(obrVal); //Set bracket contents and assign saved value
|
||||
$j(inputs[5]).html(cbr).children().val(cbrVal);
|
||||
let obrVal = inputTds.eq(1).children().val(); //Save currently selected bracket option
|
||||
let cbrVal = inputTds.eq(5).children().val();
|
||||
inputTds.eq(1).html(obrSelect).children().val(obrVal); //Set bracket contents and assign saved value
|
||||
inputTds.eq(5).html(cbrSelect).children().val(cbrVal);
|
||||
} else {
|
||||
$j(inputs[1]).html(' ');
|
||||
$j(inputs[5]).html(' ');
|
||||
inputTds.eq(1).html(' ');
|
||||
inputTds.eq(5).html(' ');
|
||||
}
|
||||
if ($j(inputs[2]).children().val() == "Archived") { //Archived filter is very different. Handles html changes.
|
||||
$j(inputs[3]).html('equal to<input type="hidden" name="filter[Query][terms][' + i + '][op]" value="=">');
|
||||
$j(inputs[4]).html('<select name="filter[Query][terms][' + i + '][val]" id="filter[Query][terms][' + i + '][val]"><option value="0">Unarchived Only</option><option value="1">Archived Only</option></select>');
|
||||
} else if ($j(inputs[3]).children().attr('type') == 'hidden' ) {
|
||||
$j(inputs[3]).html('<select name="filter[Query][terms][' + i + '][op]" id="filter[Query][terms][' + i + '][op]"><option value="=">equal to</option><option value="!=">not equal to</option><option value=">=">greater than or equal to</option><option value=">">greater than</option><option value="<">less than</option><option value="<=">less than or equal to</option><option value="=~">matches</option><option value="!~">does not match</option><option value="=[]">in set</option><option value="![]">not in set</option><option value="IS">is</option><option value="IS NOT">is not</option></select>');
|
||||
$j(inputs[4]).html('<input type="text" name="filter[Query][terms][' + i + '][val]" value="" id="filter[Query][terms][' + i + '][val]">');
|
||||
|
||||
if (rows.length == 1) {
|
||||
inputTds.eq(6).find(':input[value="-"]').prop('disabled', true);
|
||||
} else {
|
||||
inputTds.eq(6).find(':input[value="-"]').prop('disabled', false);
|
||||
}
|
||||
for (let j = 0; j < inputs.length; j++) { //Set all query array values in case any were missed
|
||||
let input = inputs[j].children;
|
||||
if (input.length) { //Ignore placeholders.
|
||||
if (input[0].type == 'button' && rows.length == 1) { //if add/delete button disable when only term
|
||||
$j(input[1]).prop('disabled', true);
|
||||
} else if (input[0].type == 'button') { //Enable if more than one term
|
||||
$j(input[1]).prop('disabled', false);
|
||||
} else { // Set all non-button array values
|
||||
let term = input[0].name.split(/[[\]]{1,2}/);
|
||||
term.length--;
|
||||
term.shift();
|
||||
term[2] = i;
|
||||
input[0].name = 'filter'+stringFilter(term);
|
||||
input[0].id = 'filter'+stringFilter(term);
|
||||
}
|
||||
|
||||
if (inputTds.eq(2).children().val() == "Archived") {
|
||||
inputTds.eq(3).html('equal to<input type="hidden" name="filter[Query][terms][' + rowNum + '][op]" value="=">');
|
||||
let archiveSelect = $j('<select></select>').attr('name', queryPrefix + rowNum + '][val]').attr('id', queryPrefix + rowNum + '][val]');
|
||||
for (let i = 0; i < archiveTypes.length; i++) {
|
||||
archiveSelect.append('<option value="' + i + '">' + archiveTypes[i] + '</option>');
|
||||
}
|
||||
}
|
||||
let archiveVal = inputTds.eq(4).children().val();
|
||||
inputTds.eq(4).html(archiveSelect).children().val(archiveVal);
|
||||
|
||||
} else if (inputTds.eq(2).children().val().indexOf('Weekday') >= 0) {
|
||||
let weekdaySelect = $j('<select></select>').attr('name', queryPrefix + rowNum + '][val]').attr('id', queryPrefix + rowNum + '][val]');
|
||||
for (let i = 0; i < weekdays.length; i++) {
|
||||
weekdaySelect.append('<option value="' + i + '">' + weekdays[i] + '</option>');
|
||||
}
|
||||
let weekdayVal = inputTds.eq(4).children().val();
|
||||
inputTds.eq(4).html(weekdaySelect).children().val(weekdayVal);
|
||||
|
||||
} else if (inputTds.eq(2).children().val() == 'StateId') {
|
||||
let stateSelect = $j('<select></select>').attr('name', queryPrefix + rowNum + '][val]').attr('id', queryPrefix + rowNum + '][val]');
|
||||
for (let key in states) {
|
||||
stateSelect.append('<option value="' + key + '">' + states[key] + '</option>');
|
||||
}
|
||||
let stateVal = inputTds.eq(4).children().val();
|
||||
inputTds.eq(4).html(weekdaySelect).children().val(stateVal)
|
||||
|
||||
|
||||
} else if (inputTds.eq(2).children().val() == 'ServerId') {
|
||||
let serverSelect = $j('<select></select>').attr('name', queryPrefix + rowNum + '][val]').attr('id', queryPrefix + rowNum + '][val]');
|
||||
for (let key in servers) {
|
||||
serverSelect.append('<option value="' + key + '">' + servers[key] + '</option>');
|
||||
}
|
||||
let serverVal = inputTds.eq(4).children().val();
|
||||
inputTds.eq(4).html(weekdaySelect).children().val(serverVal)
|
||||
|
||||
} else if (inputTds.eq(2).children().val() == 'StorageId') {
|
||||
let storageSelect = $j('<select></select>').attr('name', queryPrefix + rowNum + '][val]').attr('id', queryPrefix + rowNum + '][val]');
|
||||
for (let i=0; i < storageareas.length; i++) {
|
||||
storageSelect.append('<option value="' + i + '">' + storageareas[i] + '</option>');
|
||||
}
|
||||
let storageVal = inputTds.eq(4).children().val();
|
||||
inputTds.eq(4).html(storageSelect).children().val(storageVal)
|
||||
|
||||
} else if (inputTds.eq(2).children().val() == 'MonitorName') {
|
||||
let monitorSelect = $j('<select></select>').attr('name', queryPrefix + rowNum + '][val]').attr('id', queryPrefix + rowNum + '][val]');
|
||||
for (let key in monitors) {
|
||||
monitorSelect.append('<option value="' + key + '">' + monitors[key] + '</option>');
|
||||
}
|
||||
let monitorVal = inputTds.eq(4).children().val();
|
||||
inputTds.eq(4).html(monitorSelect).children().val(monitorVal)
|
||||
} else {
|
||||
let opSelect = $j('<select></select>').attr('name', queryPrefix + rowNum + '][op]').attr('id', queryPrefix + rowNum + '][op]');
|
||||
for (let key in opTypes) {
|
||||
opSelect.append('<option value="' + key + '">' + opTypes[key] + '</option>');
|
||||
}
|
||||
let opVal = inputTds.eq(3).children().val();
|
||||
inputTds.eq(3).html(opSelect).children().val(opVal)
|
||||
let textInput = $j('<input></input>').attr('type', 'text').attr('name', queryPrefix + rowNum + '][val]').attr('id', queryPrefix + rowNum + '][val]')
|
||||
let textVal = inputTds.eq(4).children().val();
|
||||
inputTds.eq(4).html(textInput).children().val(textVal);
|
||||
}
|
||||
let attr = inputTds.find("[name$='attr\\]']") // Set attr list id and name
|
||||
let term = attr.attr('name').split(/[[\]]{1,2}/);
|
||||
term.length--;
|
||||
term.shift();
|
||||
term[2] = rowNum;
|
||||
inputTds.eq(2).children().attr('name', 'filter'+stringFilter(term));
|
||||
inputTds.eq(2).children().attr('id', 'filter'+stringFilter(term));
|
||||
}
|
||||
history.replaceState(null, null, '?view=filter&' + $j('#contentForm').serialize());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user