Skip to content
This repository has been archived by the owner on Feb 28, 2022. It is now read-only.

Commit

Permalink
Fix Various Issues With The fileorganizer Dialog (#18)
Browse files Browse the repository at this point in the history
* Initialize label for media selector correctly

* Replace 'Emby' with 'Jellyfin' in error message

* Display a default error message if none is provided by the server

This replaces the existing behavior of displaying "Error: null"

* Open the fileorganizer dialog only after it has been fully initialized

* Add more detail to unhanded server errors
  • Loading branch information
mark-monteiro authored and anthonylavado committed Dec 14, 2019
1 parent 8b193ff commit b15d168
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions Emby.AutoOrganize/Configuration/fileorganizer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
define(['dialogHelper', 'loading', 'emby-checkbox', 'emby-input', 'emby-button', 'emby-select', 'paper-icon-button-light', 'formDialogStyle'], function (dialogHelper, loading) {
define(['dialogHelper', 'loading', 'emby-checkbox', 'emby-input', 'emby-button', 'emby-select', 'paper-icon-button-light', 'formDialogStyle'], function (dialogHelper, loading) {
'use strict';

ApiClient.getFileOrganizationResults = function (options) {
Expand Down Expand Up @@ -104,10 +104,13 @@
loading.hide();

require(['alert'], function (alert) {
alert({
title: 'Error',
text: 'Error: ' + e.headers.get("X-Application-Error-Code")
});
// Get message from server or display a default message
var message =
e.headers.get("X-Application-Error-Code") ||
"Server returned status code " + e.status + " (" + e.statusText + ") but did not provide a more specific error message.";

// Show the error using an alert dialog
alert({ title: 'Error', text: 'Error: ' + message });
});
}

Expand Down Expand Up @@ -284,7 +287,7 @@
require(['alert'], function (alert) {
alert({
title: 'Error',
text: 'No TV libraries are configured in Emby library setup.'
text: 'No TV libraries are configured in Jellyfin library setup.'
});
});
return;
Expand Down Expand Up @@ -319,7 +322,9 @@
}

function selectedMediaTypeChanged(dlg, item) {

var mediaType = dlg.querySelector('#selectMediaType').value;
var mediaSelector = dlg.querySelector('#selectMedias');

switch (mediaType) {
case "":
Expand All @@ -328,8 +333,8 @@
dlg.querySelector('#divEpisodeChoice').classList.add('hide');
break;
case "Movie":
dlg.querySelector('#selectMedias').setAttribute('label', 'Movie');
dlg.querySelector('[for="selectMedias"]').innerHTML = 'Movie';
mediaSelector.setAttribute('label', 'Movie');
if (mediaSelector && mediaSelector.setLabel) mediaSelector.setLabel('Movie');

dlg.querySelector('#divPermitChoice').classList.remove('hide');
dlg.querySelector('#divGlobalChoice').classList.remove('hide');
Expand All @@ -342,8 +347,8 @@

break;
case "Episode":
dlg.querySelector('#selectMedias').setAttribute('label', 'Series');
dlg.querySelector('[for="selectMedias"]').innerHTML = 'Series';
mediaSelector.setAttribute('label', 'Series');
if (mediaSelector && mediaSelector.setLabel) mediaSelector.setLabel('Series');

dlg.querySelector('#divPermitChoice').classList.remove('hide');
dlg.querySelector('#divGlobalChoice').classList.remove('hide');
Expand Down Expand Up @@ -390,8 +395,7 @@

dlg.querySelector('.formDialogHeaderTitle').innerHTML = 'Organize';

dialogHelper.open(dlg);

// Add event listeners to dialog
dlg.addEventListener('close', function () {

if (dlg.submitted) {
Expand Down Expand Up @@ -433,7 +437,10 @@

// Init media type
selectedMediaTypeChanged(dlg, item);
}

// Show dialog
dialogHelper.open(dlg);
};

xhr.send();
});
Expand Down

0 comments on commit b15d168

Please sign in to comment.