1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

update fetch

This commit is contained in:
Luke Pulverenti 2015-11-27 23:53:56 -05:00
parent dd09b038d5
commit ee899a7332
21 changed files with 209 additions and 260 deletions

View file

@ -1276,7 +1276,7 @@ $(document).on('pageshow', "#dashboardPage", DashboardPage.onPageShow).on('pageb
function dismissWelcome(page, userId) {
ApiClient.getDisplayPreferences('dashboard', userId, 'dashboard').done(function (result) {
ApiClient.getDisplayPreferences('dashboard', userId, 'dashboard').then(function (result) {
result.CustomPrefs[welcomeTourKey] = welcomeDismissValue;
ApiClient.updateDisplayPreferences('dashboard', result, userId, 'dashboard');
@ -1289,7 +1289,7 @@ $(document).on('pageshow', "#dashboardPage", DashboardPage.onPageShow).on('pageb
var userId = Dashboard.getCurrentUserId();
apiClient.getDisplayPreferences('dashboard', userId, 'dashboard').done(function (result) {
apiClient.getDisplayPreferences('dashboard', userId, 'dashboard').then(function (result) {
if (result.CustomPrefs[welcomeTourKey] == welcomeDismissValue) {
$('.welcomeMessage', page).hide();

View file

@ -90,87 +90,6 @@ if (!Array.prototype.filter) {
};
}
var WebNotifications = {
show: function (data) {
if (window.Notification) {
var level = Notification.permissionLevel ? Notification.permissionLevel() : Notification.permission;
if (level === "granted") {
var notif = new Notification(data.title, data);
if (notif.show) {
notif.show();
}
if (data.timeout) {
setTimeout(function () {
if (notif.close) {
notif.close();
}
else if (notif.cancel) {
notif.cancel();
}
}, data.timeout);
}
return notif;
} else if (level === "default") {
Notification.requestPermission(function () {
return WebNotifications.show(data);
});
}
}
else if (window.webkitNotifications) {
if (!webkitNotifications.checkPermission()) {
var notif = webkitNotifications.createNotification(data.icon, data.title, data.body);
notif.show();
if (data.timeout) {
setTimeout(function () {
if (notif.close) {
notif.close();
}
else if (notif.cancel) {
notif.cancel();
}
}, data.timeout);
}
return notif;
} else {
webkitNotifications.requestPermission(function () {
return WebNotifications.show(data);
});
}
}
},
requestPermission: function () {
if (window.webkitNotifications) {
if (!webkitNotifications.checkPermission()) {
} else {
webkitNotifications.requestPermission(function () {
});
}
}
else if (window.Notification) {
var level = Notification.permissionLevel ? Notification.permissionLevel() : Notification.permission;
if (level === "default") {
Notification.requestPermission(function () {
});
}
}
}
};
/*
* Javascript Humane Dates
* Copyright (c) 2008 Dean Landolt (deanlandolt.com)
@ -229,30 +148,6 @@ function humane_date(date_str) {
return date_str;
}
function humane_elapsed(firstDateStr, secondDateStr) {
var dt1 = new Date(firstDateStr);
var dt2 = new Date(secondDateStr);
var seconds = (dt2.getTime() - dt1.getTime()) / 1000;
var numdays = Math.floor((seconds % 31536000) / 86400);
var numhours = Math.floor(((seconds % 31536000) % 86400) / 3600);
var numminutes = Math.floor((((seconds % 31536000) % 86400) % 3600) / 60);
var numseconds = Math.round((((seconds % 31536000) % 86400) % 3600) % 60);
var elapsedStr = '';
elapsedStr += numdays == 1 ? numdays + ' day ' : '';
elapsedStr += numdays > 1 ? numdays + ' days ' : '';
elapsedStr += numhours == 1 ? numhours + ' hour ' : '';
elapsedStr += numhours > 1 ? numhours + ' hours ' : '';
elapsedStr += numminutes == 1 ? numminutes + ' minute ' : '';
elapsedStr += numminutes > 1 ? numminutes + ' minutes ' : '';
elapsedStr += elapsedStr.length > 0 ? 'and ' : '';
elapsedStr += numseconds == 1 ? numseconds + ' second' : '';
elapsedStr += numseconds == 0 || numseconds > 1 ? numseconds + ' seconds' : '';
return elapsedStr;
}
function getWindowUrl(win) {
return (win || window).location.href;
}
@ -359,25 +254,6 @@ function parseISO8601Date(s, options) {
return new Date(ms);
}
//convert Ticks to human hr:min:sec format
function ticks_to_human(str) {
var in_seconds = (str / 10000000);
var hours = Math.floor(in_seconds / 3600);
var minutes = Math.floor((in_seconds - (hours * 3600)) / 60);
var seconds = '0' + Math.round(in_seconds - (hours * 3600) - (minutes * 60));
var time = '';
if (hours > 0) time += hours + ":";
if (minutes < 10 && hours == 0) time += minutes;
else time += ('0' + minutes).substr(-2);
time += ":" + seconds.substr(-2);
return time;
};
// This only exists because the polymer elements get distorted when using regular jquery show/hide
$.fn.visible = function (visible) {

View file

@ -133,7 +133,7 @@
function dismissWelcome(page, userId) {
getDisplayPreferences('home', userId).done(function (result) {
getDisplayPreferences('home', userId).then(function (result) {
result.CustomPrefs[homePageTourKey] = homePageDismissValue;
ApiClient.updateDisplayPreferences('home', result, userId, AppSettings.displayPreferencesKey());
@ -201,11 +201,11 @@
Dashboard.showLoadingMsg();
getDisplayPreferences('home', userId).done(function (result) {
getDisplayPreferences('home', userId).then(function (result) {
Dashboard.getCurrentUser().then(function (user) {
loadSections(tabContent, user, result).done(function () {
loadSections(tabContent, user, result).then(function () {
if (!AppInfo.isNativeApp) {
showWelcomeIfNeeded(page, result);
@ -307,9 +307,7 @@
function getDisplayPreferences(key, userId) {
return ApiClient.getDisplayPreferences(key, userId, AppSettings.displayPreferencesKey()).done(function (result) {
});
return ApiClient.getDisplayPreferences(key, userId, AppSettings.displayPreferencesKey());
}
window.HomePage = {

View file

@ -271,7 +271,7 @@
function fadeOutLeft(elem, iterations) {
var keyframes = [{ opacity: '1', transform: 'none', offset: 0 },
{ opacity: '0', transform: 'translate3d(-100%, 0, 0)', offset: 1 }];
var timing = { duration: 400, iterations: iterations };
var timing = { duration: 300, iterations: iterations };
return elem.animate(keyframes, timing);
}
if (!LibraryBrowser.navigateOnLibraryTabSelect()) {
@ -279,6 +279,7 @@
var animateTab = !$.browser.safari;
animateTab = false;
var selected = pages.selected;
if (selected != null && animateTab) {
var newValue = this.selected;

View file

@ -948,37 +948,34 @@
Events.on(apiClient, 'websocketmessage', onWebSocketMessage);
}
Dashboard.ready(function () {
if (window.ApiClient) {
initializeApiClient(window.ApiClient);
}
if (window.ApiClient) {
initializeApiClient(window.ApiClient);
}
Events.on(ConnectionManager, 'apiclientcreated', function (e, apiClient) {
initializeApiClient(apiClient);
Events.on(ConnectionManager, 'apiclientcreated', function (e, apiClient) {
initializeApiClient(apiClient);
});
Events.on(ConnectionManager, 'localusersignedin', function () {
requiresLibraryMenuRefresh = true;
requiresViewMenuRefresh = true;
requiresDrawerRefresh = true;
});
Events.on(ConnectionManager, 'localusersignedout', function () {
requiresLibraryMenuRefresh = true;
requiresViewMenuRefresh = true;
requiresDrawerRefresh = true;
});
Events.on(MediaController, 'playerchange', function () {
updateCastIcon();
});
var mainDrawerPanel = document.querySelector('.mainDrawerPanel');
mainDrawerPanel.addEventListener('iron-select', onMainDrawerSelect);
});
Events.on(ConnectionManager, 'localusersignedin', function () {
requiresLibraryMenuRefresh = true;
requiresViewMenuRefresh = true;
requiresDrawerRefresh = true;
});
Events.on(ConnectionManager, 'localusersignedout', function () {
requiresLibraryMenuRefresh = true;
requiresViewMenuRefresh = true;
requiresDrawerRefresh = true;
});
Events.on(MediaController, 'playerchange', function () {
updateCastIcon();
});
var mainDrawerPanel = document.querySelector('.mainDrawerPanel');
mainDrawerPanel.addEventListener('iron-select', onMainDrawerSelect);
})(window, document, jQuery, window.devicePixelRatio);
(function () {

View file

@ -121,7 +121,7 @@
Dashboard.hideLoadingMsg();
setTimeout(function () {
Dashboard.showError(Globalize.translate('MessageInvalidUser'));
Dashboard.alert(Globalize.translate('MessageInvalidUser'));
}, 300);
});

View file

@ -220,7 +220,7 @@
ApiClient.getUser(userId).done(function (user) {
ApiClient.getDisplayPreferences('home', user.Id, AppSettings.displayPreferencesKey()).done(function (displayPreferences) {
ApiClient.getDisplayPreferences('home', user.Id, AppSettings.displayPreferencesKey()).then(function (displayPreferences) {
saveUser(page, user, displayPreferences);
@ -285,7 +285,7 @@
ApiClient.getUser(userId).done(function (user) {
ApiClient.getDisplayPreferences('home', user.Id, AppSettings.displayPreferencesKey()).done(function (result) {
ApiClient.getDisplayPreferences('home', user.Id, AppSettings.displayPreferencesKey()).then(function (result) {
loadForm(page, user, result);

View file

@ -72,15 +72,15 @@
switch (evt.target.error.code) {
case evt.target.error.NOT_FOUND_ERR:
Dashboard.showError(Globalize.translate('FileNotFound'));
Dashboard.alert(Globalize.translate('FileNotFound'));
break;
case evt.target.error.NOT_READABLE_ERR:
Dashboard.showError(Globalize.translate('FileReadError'));
Dashboard.alert(Globalize.translate('FileReadError'));
break;
case evt.target.error.ABORT_ERR:
break; // noop
default:
Dashboard.showError(Globalize.translate('FileReadError'));
Dashboard.alert(Globalize.translate('FileReadError'));
};
}
@ -92,7 +92,7 @@
function onFileReaderAbort(evt) {
Dashboard.hideLoadingMsg();
Dashboard.showError(Globalize.translate('FileReadCancelled'));
Dashboard.alert(Globalize.translate('FileReadCancelled'));
}
function setFiles(page, files) {
@ -317,7 +317,7 @@
if ($('#txtNewPassword', page).val() != $('#txtNewPasswordConfirm', page).val()) {
Dashboard.showError(Globalize.translate('PasswordMatchError'));
Dashboard.alert(Globalize.translate('PasswordMatchError'));
} else {
Dashboard.showLoadingMsg();

View file

@ -92,6 +92,30 @@
divScheduledTasks.innerHTML = html;
}
function humane_elapsed(firstDateStr, secondDateStr) {
var dt1 = new Date(firstDateStr);
var dt2 = new Date(secondDateStr);
var seconds = (dt2.getTime() - dt1.getTime()) / 1000;
var numdays = Math.floor((seconds % 31536000) / 86400);
var numhours = Math.floor(((seconds % 31536000) % 86400) / 3600);
var numminutes = Math.floor((((seconds % 31536000) % 86400) % 3600) / 60);
var numseconds = Math.round((((seconds % 31536000) % 86400) % 3600) % 60);
var elapsedStr = '';
elapsedStr += numdays == 1 ? numdays + ' day ' : '';
elapsedStr += numdays > 1 ? numdays + ' days ' : '';
elapsedStr += numhours == 1 ? numhours + ' hour ' : '';
elapsedStr += numhours > 1 ? numhours + ' hours ' : '';
elapsedStr += numminutes == 1 ? numminutes + ' minute ' : '';
elapsedStr += numminutes > 1 ? numminutes + ' minutes ' : '';
elapsedStr += elapsedStr.length > 0 ? 'and ' : '';
elapsedStr += numseconds == 1 ? numseconds + ' second' : '';
elapsedStr += numseconds == 0 || numseconds > 1 ? numseconds + ' seconds' : '';
return elapsedStr;
}
function getTaskProgressHtml(task) {
var html = '';

View file

@ -16,50 +16,18 @@
$.support.cors = true;
function onOneDocumentClick() {
document.removeEventListener('click', onOneDocumentClick);
WebNotifications.requestPermission();
if (window.Notification) {
Notification.requestPermission();
}
}
document.addEventListener('click', onOneDocumentClick);
})();
var Dashboard = {
jQueryMobileInit: function () {
// Page
//$.mobile.page.prototype.options.theme = "a";
//$.mobile.page.prototype.options.headerTheme = "a";
//$.mobile.page.prototype.options.contentTheme = "a";
//$.mobile.page.prototype.options.footerTheme = "a";
//$.mobile.button.prototype.options.theme = "c";
//$.mobile.listview.prototype.options.dividerTheme = "b";
//$.mobile.popup.prototype.options.theme = "c";
//$.mobile.popup.prototype.options.transition = "none";
if ($.browser.mobile) {
$.mobile.defaultPageTransition = "none";
} else {
$.mobile.defaultPageTransition = "none";
}
//$.mobile.collapsible.prototype.options.contentTheme = "a";
// Make panels a little larger than the defaults
//$.event.special.swipe.verticalDistanceThreshold = 40;
//$.mobile.page.prototype.options.domCache = true;
$.mobile.hideUrlBar = false;
$.mobile.autoInitializePage = false;
$.mobile.changePage.defaults.showLoadMsg = false;
// These are not needed. Nulling them out can help reduce dom querying when pages are loaded
$.mobile.nojs = null;
$.mobile.degradeInputsWithin = null;
$.mobile.filterHtml = Dashboard.filterHtml;
},
filterHtml: function (html) {
@ -282,11 +250,6 @@ var Dashboard = {
}
},
showError: function (message) {
Dashboard.alert(message);
},
updateSystemInfo: function (info) {
Dashboard.lastSystemInfo = info;
@ -578,11 +541,9 @@ var Dashboard = {
Dashboard.hideLoadingMsg();
Dashboard.alert("Settings saved.");
Dashboard.alert(Globalize.translate('MessageSettingsSaved'));
},
defaultErrorMessage: Globalize.translate('DefaultErrorMessage'),
processServerConfigurationUpdateResult: function (result) {
Dashboard.hideLoadingMsg();
@ -1364,7 +1325,7 @@ var Dashboard = {
var newItems = data.ItemsAdded;
if (!newItems.length || AppInfo.isNativeApp) {
if (!newItems.length || AppInfo.isNativeApp || !window.Notification) {
return;
}
@ -1389,7 +1350,8 @@ var Dashboard = {
var notification = {
title: "New " + item.Type,
body: item.Name,
timeout: 5000
timeout: 5000,
vibrate: true
};
var imageTags = item.ImageTags || {};
@ -1403,6 +1365,26 @@ var Dashboard = {
});
}
if (Notification.permission === "granted") {
var notif = new Notification(notification.title, notification);
if (notif.show) {
notif.show();
}
if (notification.timeout) {
setTimeout(function () {
if (notif.close) {
notif.close();
}
else if (notif.cancel) {
notif.cancel();
}
}, notification.timeout);
}
}
WebNotifications.show(notification);
}
});
@ -1727,17 +1709,6 @@ var Dashboard = {
exit: function () {
Dashboard.logout();
},
loadDragula: function (callback) {
require(['dragula'], function (dragula) {
Dashboard.importCss('bower_components/dragula.js/dist/dragula.min.css');
callback(dragula);
});
}
};
@ -2215,6 +2186,8 @@ var AppInfo = {};
deps.push('bower_components/fetch/fetch');
}
deps.push('scripts/mediacontroller');
require(deps, function () {
loadImageCache();
@ -2247,8 +2220,12 @@ var AppInfo = {};
require(['cordova/android/logging']);
}
deps.push('scripts/librarybrowser');
deps.push('scripts/globalize');
deps.push('appstorage');
deps.push('scripts/mediaplayer');
deps.push('scripts/appsettings');
deps.push('apiclient/connectionmanager');
require(deps, function () {
@ -2382,6 +2359,11 @@ var AppInfo = {};
deps.push('scripts/librarylist');
deps.push('scripts/notifications');
deps.push('scripts/alphapicker');
deps.push('thirdparty/jquery.unveil-custom.js');
deps.push('scripts/playlistmanager');
deps.push('scripts/sync');
deps.push('scripts/backdrops');
deps.push('scripts/librarymenu');
require(deps, function () {
@ -2605,4 +2587,4 @@ window.addEventListener("beforeunload", function () {
}
});
Dashboard.jQueryMobileInit();
$.mobile.filterHtml = Dashboard.filterHtml;

View file

@ -85,7 +85,7 @@
if (result.Success) {
Dashboard.alert(Globalize.translate('MessageKeysLinked'));
} else {
Dashboard.showError(result.ErrorMessage);
Dashboard.alert(result.ErrorMessage);
}
Logger.log(result);
@ -109,7 +109,7 @@
if (result.Success) {
Dashboard.alert(Globalize.translate('MessageKeyEmailedTo').replace("{0}", email));
} else {
Dashboard.showError(result.ErrorMessage);
Dashboard.alert(result.ErrorMessage);
}
Logger.log(result);

View file

@ -109,7 +109,7 @@
}).fail(function() {
Dashboard.showError(Globalize.translate('DefaultErrorMessage'));
Dashboard.alert(Globalize.translate('DefaultErrorMessage'));
Dashboard.hideLoadingMsg();
});
}