Some javascript cleanup in settings

This commit is contained in:
JonnyWong16 2016-05-12 20:58:33 -07:00
parent 955b69a9bf
commit b0eb98c667
3 changed files with 263 additions and 336 deletions

View file

@ -122,7 +122,6 @@
}); });
function loadHistoryTable(media_type, selected_user_id) { function loadHistoryTable(media_type, selected_user_id) {
console.log(selected_user_id)
history_table_options.ajax = { history_table_options.ajax = {
url: 'get_history', url: 'get_history',
type: 'post', type: 'post',
@ -150,7 +149,6 @@
$('#history-user').on('change', function () { $('#history-user').on('change', function () {
selected_user_id = $(this).val() || null; selected_user_id = $(this).val() || null;
console.log(selected_user_id)
history_table.draw(); history_table.draw();
}); });
} }

View file

@ -1,12 +1,13 @@
function initConfigCheckbox(elem) { function initConfigCheckbox(elem) {
var config = $(elem).parent().next(); var config = $(elem).closest('div').next();
config.css('overflow', 'hidden');
if ($(elem).is(":checked")) { if ($(elem).is(":checked")) {
config.show(); config.show();
} else { } else {
config.hide(); config.hide();
} }
$(elem).click(function () { $(elem).click(function () {
var config = $(this).parent().next(); var config = $(this).closest('div').next();
if ($(this).is(":checked")) { if ($(this).is(":checked")) {
config.slideDown(); config.slideDown();
} else { } else {
@ -42,7 +43,6 @@ function showMsg(msg,loader,timeout,ms,error) {
} }
$(feedback).html(message); $(feedback).html(message);
feedback.fadeIn(); feedback.fadeIn();
if (timeout) { if (timeout) {
setTimeout(function () { setTimeout(function () {
message.fadeOut(function () { message.fadeOut(function () {
@ -64,7 +64,6 @@ function doAjaxCall(url, elem, reload, form, callback) {
} else { } else {
feedback.removeAttr("style"); feedback.removeAttr("style");
} }
feedback.fadeIn(); feedback.fadeIn();
// Get Form data // Get Form data
var formID = "#" + url; var formID = "#" + url;
@ -88,10 +87,10 @@ function doAjaxCall(url, elem, reload, form, callback) {
// Get Success & Error message from inline data, else use standard message // Get Success & Error message from inline data, else use standard message
var succesMsg = $("<div class='msg'><i class='fa fa-check'></i> " + dataSucces + "</div>"); var succesMsg = $("<div class='msg'><i class='fa fa-check'></i> " + dataSucces + "</div>");
var errorMsg = $("<div class='msg'><i class='fa fa-exclamation-triangle'></i> " + dataError + "</div>"); var errorMsg = $("<div class='msg'><i class='fa fa-exclamation-triangle'></i> " + dataError + "</div>");
// Check if checkbox is selected // Check if checkbox is selected
if (form) { if (form) {
if ( $('td#select input[type=checkbox]').length > 0 && !$('td#select input[type=checkbox]').is(':checked') || $('#importLastFM #username:visible').length > 0 && $("#importLastFM #username" ).val().length === 0 ) { if ($('td#select input[type=checkbox]').length > 0 && !$('td#select input[type=checkbox]').is(':checked') ||
$('#importLastFM #username:visible').length > 0 && $("#importLastFM #username").val().length === 0) {
feedback.addClass('error') feedback.addClass('error')
$(feedback).prepend(errorMsg); $(feedback).prepend(errorMsg);
setTimeout(function () { setTimeout(function () {
@ -106,7 +105,6 @@ function doAjaxCall(url, elem, reload, form, callback) {
return false; return false;
} }
} }
// Ajax Call // Ajax Call
$.ajax({ $.ajax({
url: url, url: url,
@ -139,7 +137,7 @@ function doAjaxCall(url, elem, reload, form, callback) {
}); });
if (reload == true) refreshSubmenu(); if (reload == true) refreshSubmenu();
if (reload == "table") { if (reload == "table") {
console.log('refresh'); refreshTable(); refreshTable();
} }
if (reload == "tabs") refreshTab(); if (reload == "tabs") refreshTab();
if (reload == "page") location.reload(); if (reload == "page") location.reload();
@ -149,7 +147,8 @@ function doAjaxCall(url, elem, reload, form, callback) {
} }
if (form) { if (form) {
// Change the option to 'choose...' // Change the option to 'choose...'
$(formID + " select").children('option[disabled=disabled]').attr('selected','selected'); $(formID + " select").children('option[disabled=disabled]').attr(
'selected', 'selected');
} }
}) })
}, 2000); }, 2000);
@ -175,7 +174,6 @@ function resetFilters(text){
} }
function getPlatformImagePath(platformName) { function getPlatformImagePath(platformName) {
if (platformName.indexOf("Roku") > -1) { if (platformName.indexOf("Roku") > -1) {
return 'images/platforms/roku.png'; return 'images/platforms/roku.png';
} else if (platformName.indexOf("Apple TV") > -1) { } else if (platformName.indexOf("Apple TV") > -1) {
@ -242,10 +240,9 @@ function isPrivateIP(ip_address) {
// get IPv4 mapped address (xxx.xxx.xxx.xxx) from IPv6 addresss (::ffff:xxx.xxx.xxx.xxx) // get IPv4 mapped address (xxx.xxx.xxx.xxx) from IPv6 addresss (::ffff:xxx.xxx.xxx.xxx)
var parts = ip_address.split(":"); var parts = ip_address.split(":");
var parts = parts[parts.length - 1].split('.'); var parts = parts[parts.length - 1].split('.');
if ((parts[0] === '127' && parts[1] === '0' && parts[2] === '0' && parts[3] === '1') || if ((parts[0] === '127' && parts[1] === '0' && parts[2] === '0' && parts[3] === '1') || (parts[0] === '10') ||
(parts[0] === '10') || (parts[0] === '172' && (parseInt(parts[1], 10) >= 16 && parseInt(parts[1], 10) <= 31)) || (parts[0] ===
(parts[0] === '172' && (parseInt(parts[1], 10) >= 16 && parseInt(parts[1], 10) <= 31)) || '192' && parts[1] === '168')) {
(parts[0] === '192' && parts[1] === '168')) {
return true; return true;
} }
return false; return false;
@ -256,16 +253,18 @@ function isPrivateIP(ip_address) {
function humanTime(seconds) { function humanTime(seconds) {
if (seconds >= 86400) { if (seconds >= 86400) {
text = '<h3>' + Math.floor(moment.duration(seconds, 'seconds').asDays()) + '</h3><p> days</p>' + text = '<h3>' + Math.floor(moment.duration(seconds, 'seconds').asDays()) + '</h3><p> days</p>' + '<h3>' +
'<h3>' + Math.floor(moment.duration((seconds % 86400), 'seconds').asHours()) + '</h3><p> hrs</p>' + Math.floor(moment.duration((seconds % 86400), 'seconds').asHours()) + '</h3><p> hrs</p>' + '<h3>' +
'<h3>' + Math.floor(moment.duration(((seconds % 86400) % 3600), 'seconds').asMinutes()) + '</h3><p> mins</p>'; Math.floor(moment.duration(((seconds % 86400) % 3600), 'seconds').asMinutes()) + '</h3><p> mins</p>';
return text; return text;
} else if (seconds >= 3600) { } else if (seconds >= 3600) {
text = '<h3>' + Math.floor(moment.duration((seconds % 86400), 'seconds').asHours()) + '</h3><p> hrs</p>' + text = '<h3>' + Math.floor(moment.duration((seconds % 86400), 'seconds').asHours()) + '</h3><p> hrs</p>' +
'<h3>' + Math.floor(moment.duration(((seconds % 86400) % 3600), 'seconds').asMinutes()) + '</h3><p> mins</p>'; '<h3>' + Math.floor(moment.duration(((seconds % 86400) % 3600), 'seconds').asMinutes()) +
'</h3><p> mins</p>';
return text; return text;
} else if (seconds >= 60) { } else if (seconds >= 60) {
text = '<h3>' + Math.floor(moment.duration(((seconds % 86400) % 3600), 'seconds').asMinutes()) + '</h3><p> mins</p>'; text = '<h3>' + Math.floor(moment.duration(((seconds % 86400) % 3600), 'seconds').asMinutes()) +
'</h3><p> mins</p>';
return text; return text;
} else { } else {
text = '<h3>0</h3><p> mins</p>'; text = '<h3>0</h3><p> mins</p>';
@ -275,13 +274,13 @@ function humanTime(seconds) {
function humanTimeClean(seconds) { function humanTimeClean(seconds) {
if (seconds >= 86400) { if (seconds >= 86400) {
text = Math.floor(moment.duration(seconds, 'seconds').asDays()) + ' days ' + text = Math.floor(moment.duration(seconds, 'seconds').asDays()) + ' days ' + Math.floor(moment.duration((
Math.floor(moment.duration((seconds % 86400), 'seconds').asHours()) + ' hrs ' + seconds % 86400), 'seconds').asHours()) + ' hrs ' + Math.floor(moment.duration(
Math.floor(moment.duration(((seconds % 86400) % 3600), 'seconds').asMinutes()) + ' mins'; ((seconds % 86400) % 3600), 'seconds').asMinutes()) + ' mins';
return text; return text;
} else if (seconds >= 3600) { } else if (seconds >= 3600) {
text = Math.floor(moment.duration((seconds % 86400), 'seconds').asHours()) + ' hrs ' + text = Math.floor(moment.duration((seconds % 86400), 'seconds').asHours()) + ' hrs ' + Math.floor(moment.duration(
Math.floor(moment.duration(((seconds % 86400) % 3600), 'seconds').asMinutes()) + ' mins'; ((seconds % 86400) % 3600), 'seconds').asMinutes()) + ' mins';
return text; return text;
} else if (seconds >= 60) { } else if (seconds >= 60) {
text = Math.floor(moment.duration(((seconds % 86400) % 3600), 'seconds').asMinutes()) + ' mins'; text = Math.floor(moment.duration(((seconds % 86400) % 3600), 'seconds').asMinutes()) + ' mins';
@ -291,17 +290,16 @@ function humanTimeClean(seconds) {
return text; return text;
} }
} }
String.prototype.toProperCase = function () { String.prototype.toProperCase = function () {
return this.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();}); return this.replace(/\w\S*/g, function (txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
});
}; };
function millisecondsToMinutes(ms, roundToMinute) { function millisecondsToMinutes(ms, roundToMinute) {
if (ms > 0) { if (ms > 0) {
seconds = ms / 1000; seconds = ms / 1000;
minutes = seconds / 60; minutes = seconds / 60;
if (roundToMinute) { if (roundToMinute) {
output = Math.round(minutes, 0) output = Math.round(minutes, 0)
} else { } else {
@ -321,7 +319,6 @@ function millisecondsToMinutes(ms, roundToMinute) {
} }
} }
} }
// Our countdown plugin takes a callback, a duration, and an optional message // Our countdown plugin takes a callback, a duration, and an optional message
$.fn.countdown = function (callback, duration, message) { $.fn.countdown = function (callback, duration, message) {
// If no message is provided, we use an empty string // If no message is provided, we use an empty string
@ -343,7 +340,6 @@ $.fn.countdown = function (callback, duration, message) {
} }
// Run interval every 1000ms (1 second) // Run interval every 1000ms (1 second)
}, 1000); }, 1000);
}; };
function setCookie(cname, cvalue, exdays) { function setCookie(cname, cvalue, exdays) {
@ -363,39 +359,37 @@ function getCookie(cname) {
} }
return ""; return "";
} }
var Accordion = function (el, multiple) { var Accordion = function (el, multiple) {
this.el = el || {}; this.el = el || {};
this.multiple = multiple || false; this.multiple = multiple || false;
// Variables privadas // Variables privadas
var links = this.el.find('.link'); var links = this.el.find('.link');
// Evento // Evento
links.on('click', {el: this.el, multiple: this.multiple}, this.dropdown) links.on('click', {
el: this.el,
multiple: this.multiple
}, this.dropdown)
} }
Accordion.prototype.dropdown = function (e) { Accordion.prototype.dropdown = function (e) {
var $el = e.data.el; var $el = e.data.el;
$this = $(this), $this = $(this),
$next = $this.next(); $next = $this.next();
$next.slideToggle(); $next.slideToggle();
$this.parent().toggleClass('open'); $this.parent().toggleClass('open');
if (!e.data.multiple) { if (!e.data.multiple) {
$el.find('.submenu').not($next).slideUp().parent().removeClass('open'); $el.find('.submenu').not($next).slideUp().parent().removeClass('open');
}; };
} }
function clearSearchButton(tableName, table) { function clearSearchButton(tableName, table) {
$('#' + tableName + '_filter').find('input[type=search]') $('#' + tableName + '_filter').find('input[type=search]').wrap(
.wrap('<div class="input-group" role="group" aria-label="Search"></div>') '<div class="input-group" role="group" aria-label="Search"></div>').after(
.after('<span class="input-group-btn"><button class="btn btn-form" data-toggle="button" aria-pressed="false" autocomplete="off" id="clear-search-' + tableName + '"><i class="fa fa-remove"></i></button></span>') '<span class="input-group-btn"><button class="btn btn-form" data-toggle="button" aria-pressed="false" autocomplete="off" id="clear-search-' +
tableName + '"><i class="fa fa-remove"></i></button></span>')
$('#clear-search-' + tableName).click(function () { $('#clear-search-' + tableName).click(function () {
table.search('').draw(); table.search('').draw();
}); });
} }
// Taken from https://github.com/Hellowlol/HTPC-Manager // Taken from https://github.com/Hellowlol/HTPC-Manager
window.onerror = function (message, file, line) { window.onerror = function (message, file, line) {
var e = { var e = {
@ -404,7 +398,5 @@ window.onerror = function (message, file, line) {
'file': file, 'file': file,
'line': line 'line': line
}; };
$.post("log_js_errors", e, function (data) { });
$.post("log_js_errors", e, function (data) {
});
}; };

View file

@ -2071,13 +2071,13 @@ $(document).ready(function() {
$('#restart-modal').modal('show'); $('#restart-modal').modal('show');
} }
$("#http_hashed_password").val($("#http_hash_password").is(":checked") ? 1 : 0) $("#http_hashed_password").val($("#http_hash_password").is(":checked") ? 1 : 0)
getSchedulerTable();
} }
var configForm = $("#configUpdate"); var configForm = $("#configUpdate");
function saveSettings() { function saveSettings() {
if (configForm.parsley().validate()) { if (configForm.parsley().validate()) {
doAjaxCall('configUpdate', $(this), 'tabs', true, getSchedulerTable); doAjaxCall('configUpdate', $(this), 'tabs', true, postSaveChecks);
postSaveChecks();
return false; return false;
} else { } else {
showMsg('<i class="fa fa-exclamation-circle"></i> Please verify your settings.', false, true, 5000, true) showMsg('<i class="fa fa-exclamation-circle"></i> Please verify your settings.', false, true, 5000, true)
@ -2092,6 +2092,12 @@ $(document).ready(function() {
} }
}); });
initConfigCheckbox('#api_enabled');
initConfigCheckbox('#enable_https');
initConfigCheckbox('#https_create_cert');
initConfigCheckbox('#check_github');
initConfigCheckbox('#notify_upload_posters');
$("#menu_link_shutdown").click(function() { $("#menu_link_shutdown").click(function() {
$("#confirm-message").text("Are you sure you want to shutdown PlexPy?"); $("#confirm-message").text("Are you sure you want to shutdown PlexPy?");
$('#confirm-modal').modal(); $('#confirm-modal').modal();
@ -2120,6 +2126,18 @@ $(document).ready(function() {
window.location.href = "restart"; window.location.href = "restart";
}); });
function getSchedulerTable() {
$.ajax({
url: 'get_scheduler_table',
cache: false,
async: true,
complete: function(xhr, status) {
$("#plexpy-scheduler-table").html(xhr.responseText);
}
});
}
getSchedulerTable();
$("#backup_database").click(function () { $("#backup_database").click(function () {
$("#confirm-message").text("Are you sure you want to create a backup of the PlexPy database?"); $("#confirm-message").text("Are you sure you want to create a backup of the PlexPy database?");
$('#confirm-modal').modal(); $('#confirm-modal').modal();
@ -2180,19 +2198,6 @@ $(document).ready(function() {
}); });
}); });
if ($("#api_enabled").is(":checked")) {
$("#apioptions").show();
} else {
$("#apioptions").hide();
}
$("#api_enabled").click(function(){
if ($("#api_enabled").is(":checked")) {
$("#apioptions").slideDown();
} else {
$("#apioptions").slideUp();
}
});
$('#api_key').click(function(){ $('#api_key').select() }); $('#api_key').click(function(){ $('#api_key').select() });
$("#generate_api").click(function() { $("#generate_api").click(function() {
@ -2206,62 +2211,6 @@ $(document).ready(function() {
}); });
}); });
if ($("#enable_https").is(":checked")) {
$("#https_options").show();
} else {
$("#https_options").hide();
}
$("#enable_https").click(function(){
if ($("#enable_https").is(":checked")) {
$("#https_options").slideDown();
} else {
$("#https_options").slideUp();
}
});
if ($("#https_create_cert").is(":checked")) {
$("#https_options_self-signed").show();
} else {
$("#https_options_self-signed").hide();
}
$("#https_create_cert").click(function(){
if ($("#https_create_cert").is(":checked")) {
$("#https_options_self-signed").slideDown();
} else {
$("#https_options_self-signed").slideUp();
}
});
if ($("#check_github").is(":checked")) {
$("#git_update_options").show();
} else {
$("#git_update_options").hide();
}
$("#check_github").click(function(){
if ($("#check_github").is(":checked")) {
$("#git_update_options").slideDown();
} else {
$("#git_update_options").slideUp();
}
});
if ($("#notify_upload_posters").is(":checked")) {
$("#imgur_upload_options").show();
} else {
$("#imgur_upload_options").hide();
}
$("#notify_upload_posters").click(function(){
if ($("#notify_upload_posters").is(":checked")) {
$("#imgur_upload_options").slideDown();
} else {
$("#imgur_upload_options").slideUp();
}
});
$( ".http-settings" ).change(function() { $( ".http-settings" ).change(function() {
httpChanged = true; httpChanged = true;
}); });
@ -2342,8 +2291,8 @@ $(document).ready(function() {
$("#pms-token-status").html('<i class="fa fa-refresh fa-spin"></i> Fetching token...'); $("#pms-token-status").html('<i class="fa fa-refresh fa-spin"></i> Fetching token...');
if (($("#pms_username").val() !== '') || ($("#pms_password").val() !== '')) { if (($("#pms_username").val() !== '') || ($("#pms_password").val() !== '')) {
$.ajax({ $.ajax({
type: "post", type: 'POST',
url: "https://plex.tv/users/sign_in.xml", url: 'https://plex.tv/users/sign_in.xml',
dataType: 'xml', dataType: 'xml',
async: true, async: true,
headers: {'Content-Type': 'application/xml; charset=utf-8', headers: {'Content-Type': 'application/xml; charset=utf-8',
@ -2595,18 +2544,6 @@ $(document).ready(function() {
$(this).on('focus keyup input', function() { resizeTextarea(this); }).removeAttr('data-autoresize'); $(this).on('focus keyup input', function() { resizeTextarea(this); }).removeAttr('data-autoresize');
}); });
function getSchedulerTable() {
$.ajax({
url: 'get_scheduler_table',
cache: false,
async: true,
complete: function(xhr, status) {
$("#plexpy-scheduler-table").html(xhr.responseText);
}
});
}
getSchedulerTable();
$("#notify_recently_added_grandparent").change(function () { $("#notify_recently_added_grandparent").change(function () {
var c = this.checked ? '#eb8600' : '#737373'; var c = this.checked ? '#eb8600' : '#737373';
$('#notify_recently_added_grandparent_note').css('color', c); $('#notify_recently_added_grandparent_note').css('color', c);