fix: loading of the config pages.
This commit is contained in:
parent
aa6fed146d
commit
9ca1712b5d
2 changed files with 50 additions and 42 deletions
|
@ -3,7 +3,7 @@ var COLLECTIONS = [
|
||||||
{
|
{
|
||||||
Id: 'My New Smartcollection',
|
Id: 'My New Smartcollection',
|
||||||
Name: 'My New Smartcollection',
|
Name: 'My New Smartcollection',
|
||||||
Program: '(is-favourite)',
|
Program: 'nil',
|
||||||
SortProgram: '(begin *items*)',
|
SortProgram: '(begin *items*)',
|
||||||
CollectionId: '00000000000000000000000000000000',
|
CollectionId: '00000000000000000000000000000000',
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
|
@ -73,17 +73,29 @@ ApiClient.setSmartCollection = function (c) {
|
||||||
data: JSON.stringify(c),
|
data: JSON.stringify(c),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
function initial_load(selectedId) {
|
||||||
|
Dashboard.showLoadingMsg();
|
||||||
|
ApiClient.getSmartCollections().then(function (collections) {
|
||||||
|
COLLECTIONS = [COLLECTIONS[0]].concat(collections);
|
||||||
|
const selection = document.querySelector('#SmartcollectionSelection');
|
||||||
|
fillCollectionSelect(COLLECTIONS);
|
||||||
|
if (selectedId === null) {
|
||||||
|
selection.selectedIndex = 0;
|
||||||
|
} else {
|
||||||
|
selection.selectedIndex = COLLECTIONS.map(x => x.Id).indexOf(selectedId);
|
||||||
|
}
|
||||||
|
fillForm(COLLECTIONS[selection.selectedIndex]);
|
||||||
|
Dashboard.hideLoadingMsg();
|
||||||
|
});
|
||||||
|
}
|
||||||
document.querySelector('#SmartCollectionConfigPage')
|
document.querySelector('#SmartCollectionConfigPage')
|
||||||
.addEventListener('viewshow', function() {
|
.addEventListener('viewshow', function() {
|
||||||
Dashboard.showLoadingMsg();
|
initial_load(null);
|
||||||
ApiClient.getSmartCollections().then(function (collections) {
|
});
|
||||||
COLLECTIONS = [COLLECTIONS[0]].concat(collections);
|
|
||||||
const selection = document.querySelector('#SmartcollectionSelection');
|
document.querySelector('#SmartCollectionConfigPage')
|
||||||
fillCollectionSelect(COLLECTIONS);
|
.addEventListener('pageshow', function() {
|
||||||
fillForm(COLLECTIONS[selection.selectedIndex]);
|
initial_load(null);
|
||||||
Dashboard.hideLoadingMsg();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
document.querySelector('#SmartcollectionSelection')
|
document.querySelector('#SmartcollectionSelection')
|
||||||
|
@ -96,16 +108,9 @@ document.querySelector('#SmartCollectionConfigForm')
|
||||||
.addEventListener('submit', function (e) {
|
.addEventListener('submit', function (e) {
|
||||||
Dashboard.showLoadingMsg();
|
Dashboard.showLoadingMsg();
|
||||||
const selection = document.querySelector('#SmartcollectionSelection');
|
const selection = document.querySelector('#SmartcollectionSelection');
|
||||||
const selectedid = COLLECTIONS[selection.selectedIndex].Id;
|
const selectedId = COLLECTIONS[selection.selectedIndex].Id;
|
||||||
ApiClient.setSmartCollection(jsonFromForm(COLLECTIONS[selection.selectedIndex].CollectionId)).then(function () {
|
ApiClient.setSmartCollection(jsonFromForm(COLLECTIONS[selection.selectedIndex].CollectionId)).then(function () {
|
||||||
ApiClient.getSmartCollections().then(function (collections) {
|
initial_load(selectedId);
|
||||||
COLLECTIONS = [COLLECTIONS[0]].concat(collections);
|
|
||||||
fillCollectionSelect(COLLECTIONS);
|
|
||||||
const idx = COLLECTIONS.map(x => x.Id).indexOf(selectedid);
|
|
||||||
selection.selectedIndex = idx;
|
|
||||||
fillForm(COLLECTIONS[selection.selectedIndex]);
|
|
||||||
Dashboard.hideLoadingMsg();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
});
|
});
|
||||||
|
|
|
@ -97,19 +97,32 @@ ApiClient.setSmartPlaylist = function (p) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function initial_load(selectedId) {
|
||||||
|
Dashboard.showLoadingMsg();
|
||||||
|
ApiClient.getSmartPlaylists().then(function (playlists) {
|
||||||
|
PLAYLISTS = [PLAYLISTS[0]].concat(playlists);
|
||||||
|
ApiClient.getUsers().then(function (users) {
|
||||||
|
USERS = users;
|
||||||
|
const selection = document.querySelector('#SmartplaylistSelection');
|
||||||
|
fillPlaylistSelect(PLAYLISTS);
|
||||||
|
if (selectedId === null) {
|
||||||
|
selection.selectedIndex = 0;
|
||||||
|
} else {
|
||||||
|
selection.selectedIndex = PLAYLISTS.map(x => x.Id).indexOf(selectedId);
|
||||||
|
}
|
||||||
|
fillForm(PLAYLISTS[selection.selectedIndex], USERS);
|
||||||
|
Dashboard.hideLoadingMsg();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
document.querySelector('#SmartPlaylistConfigPage')
|
document.querySelector('#SmartPlaylistConfigPage')
|
||||||
.addEventListener('viewshow', function() {
|
.addEventListener('viewshow', function() {
|
||||||
Dashboard.showLoadingMsg();
|
initial_load(null);
|
||||||
ApiClient.getSmartPlaylists().then(function (playlists) {
|
});
|
||||||
PLAYLISTS = [PLAYLISTS[0]].concat(playlists);
|
document.querySelector('#SmartPlaylistConfigPage')
|
||||||
ApiClient.getUsers().then(function (users) {
|
.addEventListener('pageshow', function() {
|
||||||
USERS = users;
|
initial_load(null);
|
||||||
const selection = document.querySelector('#SmartplaylistSelection');
|
|
||||||
fillPlaylistSelect(PLAYLISTS);
|
|
||||||
fillForm(PLAYLISTS[selection.selectedIndex], USERS);
|
|
||||||
Dashboard.hideLoadingMsg();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
document.querySelector('#SmartplaylistSelection')
|
document.querySelector('#SmartplaylistSelection')
|
||||||
|
@ -122,19 +135,9 @@ document.querySelector('#SmartPlaylistConfigForm')
|
||||||
.addEventListener('submit', function (e) {
|
.addEventListener('submit', function (e) {
|
||||||
Dashboard.showLoadingMsg();
|
Dashboard.showLoadingMsg();
|
||||||
const selection = document.querySelector('#SmartplaylistSelection');
|
const selection = document.querySelector('#SmartplaylistSelection');
|
||||||
const selectedid = PLAYLISTS[selection.selectedIndex].Id;
|
const selectedId = PLAYLISTS[selection.selectedIndex].Id;
|
||||||
ApiClient.setSmartPlaylist(jsonFromForm()).then(function () {
|
ApiClient.setSmartPlaylist(jsonFromForm()).then(function () {
|
||||||
ApiClient.getSmartPlaylists().then(function (playlists) {
|
initial_load(selectedId);
|
||||||
PLAYLISTS = [PLAYLISTS[0]].concat(playlists);
|
|
||||||
ApiClient.getUsers().then(function (users) {
|
|
||||||
USERS = users;
|
|
||||||
fillPlaylistSelect(PLAYLISTS);
|
|
||||||
const idx = PLAYLISTS.map(x => x.Id).indexOf(selectedid);
|
|
||||||
selection.selectedIndex = idx;
|
|
||||||
fillForm(PLAYLISTS[selection.selectedIndex], USERS);
|
|
||||||
Dashboard.hideLoadingMsg();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue