2017-05-19 01:50:56 +08:00
|
|
|
function setButtonStates( element ) {
|
|
|
|
var form = element.form;
|
|
|
|
var checked = 0;
|
2018-02-08 22:47:16 +08:00
|
|
|
for ( var i=0; i < form.elements.length; i++ ) {
|
|
|
|
if (
|
2020-09-04 22:02:43 +08:00
|
|
|
form.elements[i].type=="checkbox" &&
|
2018-02-08 22:47:16 +08:00
|
|
|
form.elements[i].name=="markMids[]"
|
|
|
|
) {
|
2018-02-08 22:57:11 +08:00
|
|
|
var tr = $j(form.elements[i]).closest("tr");
|
|
|
|
if ( form.elements[i].checked ) {
|
|
|
|
checked ++;
|
|
|
|
tr.addClass("danger");
|
|
|
|
} else {
|
|
|
|
tr.removeClass("danger");
|
|
|
|
}
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
2017-05-19 01:50:56 +08:00
|
|
|
}
|
2018-02-08 22:47:16 +08:00
|
|
|
if ( checked ) {
|
|
|
|
form.editBtn.disabled = false;
|
|
|
|
form.deleteBtn.disabled = false;
|
2018-04-04 01:36:58 +08:00
|
|
|
form.selectBtn.disabled = false;
|
2018-02-08 22:47:16 +08:00
|
|
|
if ( checked == 1 ) {
|
2019-01-18 23:00:55 +08:00
|
|
|
$j(form.cloneBtn).css('display', 'inline');
|
2018-02-08 22:47:16 +08:00
|
|
|
} else {
|
|
|
|
form.cloneBtn.hide();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
form.cloneBtn.hide();
|
|
|
|
form.editBtn.disabled = true;
|
|
|
|
form.deleteBtn.disabled = true;
|
2018-04-04 01:36:58 +08:00
|
|
|
form.selectBtn.disabled = true;
|
2018-02-08 22:47:16 +08:00
|
|
|
}
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
|
|
|
|
2017-10-27 09:56:10 +08:00
|
|
|
function addMonitor(element) {
|
2020-08-28 20:58:42 +08:00
|
|
|
window.location.assign('?view=monitor');
|
2018-02-09 02:15:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function cloneMonitor(element) {
|
2017-05-19 01:50:56 +08:00
|
|
|
var form = element.form;
|
|
|
|
var monitorId=-1;
|
2018-02-09 02:15:27 +08:00
|
|
|
// get the value of the first checkbox
|
|
|
|
for ( var i = 0; i < form.elements.length; i++ ) {
|
|
|
|
if (
|
2020-09-04 22:02:43 +08:00
|
|
|
form.elements[i].type == "checkbox" &&
|
|
|
|
form.elements[i].name == "markMids[]" &&
|
2018-02-09 02:15:27 +08:00
|
|
|
form.elements[i].checked
|
|
|
|
) {
|
|
|
|
monitorId = form.elements[i].value;
|
|
|
|
break;
|
2017-03-18 15:00:51 +08:00
|
|
|
}
|
2018-02-09 02:15:27 +08:00
|
|
|
} // end foreach element
|
2018-01-13 00:11:25 +08:00
|
|
|
if ( monitorId != -1 ) {
|
2020-08-28 20:58:42 +08:00
|
|
|
window.location.assign('?view=monitor&dupId='+monitorId);
|
2018-01-13 00:11:25 +08:00
|
|
|
}
|
2016-04-15 01:53:10 +08:00
|
|
|
}
|
|
|
|
|
2017-05-19 01:50:56 +08:00
|
|
|
function editMonitor( element ) {
|
|
|
|
var form = element.form;
|
2017-10-24 08:01:43 +08:00
|
|
|
var monitorIds = Array();
|
|
|
|
|
2017-05-19 01:50:56 +08:00
|
|
|
for ( var i = 0; i < form.elements.length; i++ ) {
|
2019-01-18 23:00:55 +08:00
|
|
|
if (
|
2020-09-04 22:02:43 +08:00
|
|
|
form.elements[i].type == "checkbox" &&
|
|
|
|
form.elements[i].name == "markMids[]" &&
|
2018-02-09 02:15:27 +08:00
|
|
|
form.elements[i].checked
|
|
|
|
) {
|
|
|
|
monitorIds.push( form.elements[i].value );
|
|
|
|
//form.elements[i].checked = false;
|
|
|
|
//setButtonStates( form.elements[i] );
|
|
|
|
//$(form.elements[i]).getParent( 'tr' ).removeClass( 'highlight' );
|
|
|
|
//break;
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
2017-10-24 08:01:43 +08:00
|
|
|
} // end foreach checkboxes
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( monitorIds.length == 1 ) {
|
2020-08-28 20:58:42 +08:00
|
|
|
window.location.assign('?view=monitor&mid='+monitorIds[0]);
|
2019-01-19 23:32:40 +08:00
|
|
|
} else if ( monitorIds.length > 1 ) {
|
2020-08-28 20:58:42 +08:00
|
|
|
window.location.assign( '?view=monitors&'+(monitorIds.map(function(mid) {
|
2019-01-19 23:32:40 +08:00
|
|
|
return 'mids[]='+mid;
|
2020-08-28 20:58:42 +08:00
|
|
|
}).join('&')));
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
|
|
|
|
2017-05-19 01:50:56 +08:00
|
|
|
function deleteMonitor( element ) {
|
|
|
|
if ( confirm( 'Warning, deleting a monitor also deletes all events and database entries associated with it.\nAre you sure you wish to delete?' ) ) {
|
|
|
|
var form = element.form;
|
|
|
|
form.elements['action'].value = 'delete';
|
|
|
|
form.submit();
|
|
|
|
}
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
|
|
|
|
2018-04-04 01:36:58 +08:00
|
|
|
function selectMonitor(element) {
|
|
|
|
var form = element.form;
|
|
|
|
var url = thisUrl+'?view=console';
|
|
|
|
for ( var i = 0; i < form.elements.length; i++ ) {
|
|
|
|
if (
|
2020-09-04 22:02:43 +08:00
|
|
|
form.elements[i].type == 'checkbox' &&
|
|
|
|
form.elements[i].name == 'markMids[]' &&
|
2019-12-03 03:18:27 +08:00
|
|
|
form.elements[i].checked
|
2019-01-19 23:32:40 +08:00
|
|
|
) {
|
2019-12-03 03:21:25 +08:00
|
|
|
url += '&MonitorId[]='+form.elements[i].value;
|
2018-04-04 01:36:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
window.location.replace(url);
|
|
|
|
}
|
|
|
|
|
2017-05-19 01:50:56 +08:00
|
|
|
function reloadWindow() {
|
|
|
|
window.location.replace( thisUrl );
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
|
|
|
|
2020-09-19 23:18:59 +08:00
|
|
|
// Manage the the Function modal and its buttons
|
2020-10-20 23:52:18 +08:00
|
|
|
function manageFunctionModal(evt) {
|
|
|
|
evt.preventDefault();
|
2020-09-04 06:24:45 +08:00
|
|
|
|
2020-12-09 04:36:19 +08:00
|
|
|
if ( !canEdit.Events ) {
|
2020-10-20 23:52:18 +08:00
|
|
|
enoperm();
|
|
|
|
return;
|
|
|
|
}
|
2020-09-04 06:24:45 +08:00
|
|
|
|
2020-10-20 23:52:18 +08:00
|
|
|
if ( ! $j('#modalFunction').length ) {
|
|
|
|
// Load the Function modal on page load
|
|
|
|
$j.getJSON(thisUrl + '?request=modal&modal=function')
|
|
|
|
.done(function(data) {
|
|
|
|
insertModalHtml('modalFunction', data.html);
|
|
|
|
// Manage the CANCEL modal buttons
|
|
|
|
$j('.funcCancelBtn').click(function(evt) {
|
|
|
|
evt.preventDefault();
|
|
|
|
$j('#modalFunction').modal('hide');
|
|
|
|
});
|
|
|
|
// Manage the SAVE modal buttons
|
|
|
|
$j('.funcSaveBtn').click(function(evt) {
|
|
|
|
evt.preventDefault();
|
|
|
|
$j('#function_form').submit();
|
|
|
|
});
|
2020-09-19 23:18:59 +08:00
|
|
|
|
2020-10-20 23:52:18 +08:00
|
|
|
manageFunctionModal(evt);
|
|
|
|
})
|
|
|
|
.fail(logAjaxFail);
|
|
|
|
return;
|
|
|
|
}
|
2020-08-27 00:39:48 +08:00
|
|
|
|
2020-10-20 23:52:18 +08:00
|
|
|
var mid = evt.currentTarget.getAttribute('data-mid');
|
|
|
|
monitor = monitors[mid];
|
|
|
|
if ( !monitor ) {
|
|
|
|
console.error("No monitor found for mid " + mid);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var function_form = document.getElementById('function_form');
|
|
|
|
if ( !function_form ) {
|
|
|
|
console.error("Unable to find form with id function_form");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
function_form.elements['newFunction'].value = monitor.Function;
|
|
|
|
function_form.elements['newEnabled'].checked = monitor.Enabled == '1';
|
|
|
|
function_form.elements['mid'].value = mid;
|
|
|
|
document.getElementById('function_monitor_name').innerHTML = monitor.Name;
|
|
|
|
|
|
|
|
$j('#modalFunction').modal('show');
|
|
|
|
} // end function manageFunctionModal
|
2020-09-19 23:18:59 +08:00
|
|
|
|
|
|
|
function initPage() {
|
|
|
|
reloadWindow.periodical(consoleRefreshTimeout);
|
|
|
|
if ( showDonatePopup ) {
|
|
|
|
$j.getJSON(thisUrl + '?request=modal&modal=donate')
|
|
|
|
.done(function(data) {
|
2020-10-15 04:58:39 +08:00
|
|
|
insertModalHtml('donate', data.html);
|
2020-09-19 23:18:59 +08:00
|
|
|
$j('#donate').modal('show');
|
|
|
|
// Manage the Apply button
|
|
|
|
$j('#donateApplyBtn').click(function(evt) {
|
|
|
|
evt.preventDefault();
|
|
|
|
$j('#donateForm').submit();
|
|
|
|
});
|
|
|
|
})
|
2020-09-20 21:41:16 +08:00
|
|
|
.fail(logAjaxFail);
|
2020-09-19 23:18:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Makes table sortable
|
|
|
|
$j( function() {
|
|
|
|
$j( "#consoleTableBody" ).sortable({
|
|
|
|
handle: ".sort",
|
|
|
|
update: applySort,
|
|
|
|
axis: 'Y'} );
|
|
|
|
$j( "#consoleTableBody" ).disableSelection();
|
|
|
|
} );
|
|
|
|
|
|
|
|
// Setup the thumbnail video animation
|
2020-11-26 03:16:11 +08:00
|
|
|
initThumbAnimation();
|
2020-09-19 23:18:59 +08:00
|
|
|
|
2020-10-20 23:52:18 +08:00
|
|
|
$j('.functionLnk').click(manageFunctionModal);
|
|
|
|
} // end function initPage
|
2008-07-14 21:54:50 +08:00
|
|
|
|
2017-01-23 23:12:57 +08:00
|
|
|
function applySort(event, ui) {
|
|
|
|
var monitor_ids = $j(this).sortable('toArray');
|
|
|
|
var ajax = new Request.JSON( {
|
2019-01-19 23:32:40 +08:00
|
|
|
url: 'index.php?request=console',
|
|
|
|
data: {monitor_ids: monitor_ids, action: 'sort'},
|
|
|
|
method: 'post',
|
|
|
|
timeout: AJAX_TIMEOUT
|
|
|
|
} );
|
2017-01-23 23:12:57 +08:00
|
|
|
ajax.send();
|
|
|
|
} // end function applySort(event,ui)
|
|
|
|
|
2020-10-01 21:15:20 +08:00
|
|
|
$j(document).ready(initPage );
|