2020-06-10 21:33:08 +09:00
|
|
|
import loading from 'loading';
|
|
|
|
import libraryMenu from 'libraryMenu';
|
|
|
|
import globalize from 'globalize';
|
|
|
|
import dialogHelper from 'dialogHelper';
|
|
|
|
import 'emby-button';
|
|
|
|
import 'emby-checkbox';
|
|
|
|
import 'emby-select';
|
|
|
|
import 'formDialogStyle';
|
2020-06-11 03:02:38 +09:00
|
|
|
import 'listViewStyle';
|
2020-06-10 21:33:08 +09:00
|
|
|
|
|
|
|
let repositories = [];
|
|
|
|
|
|
|
|
function reloadList(page) {
|
|
|
|
loading.show();
|
2020-06-11 03:02:38 +09:00
|
|
|
ApiClient.getJSON(ApiClient.getUrl('Repositories')).then(list => {
|
|
|
|
repositories = list;
|
2020-06-10 21:33:08 +09:00
|
|
|
populateList({
|
|
|
|
listElement: page.querySelector('#repositories'),
|
|
|
|
noneElement: page.querySelector('#none'),
|
2020-06-11 03:02:38 +09:00
|
|
|
repositories: repositories
|
2020-06-10 21:33:08 +09:00
|
|
|
});
|
|
|
|
}).catch(error => {
|
2020-06-11 19:34:06 +09:00
|
|
|
console.error('error loading repositories');
|
2020-06-10 21:33:08 +09:00
|
|
|
page.querySelector('#none').classList.remove('hide');
|
|
|
|
loading.hide();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-06-16 21:13:07 +09:00
|
|
|
function saveList(page) {
|
2020-06-10 21:33:08 +09:00
|
|
|
loading.show();
|
|
|
|
ApiClient.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
url: ApiClient.getUrl('Repositories'),
|
|
|
|
data: JSON.stringify(repositories),
|
|
|
|
contentType: 'application/json'
|
2020-06-16 21:13:07 +09:00
|
|
|
}).then(response => {
|
|
|
|
reloadList(page);
|
2020-06-10 21:33:08 +09:00
|
|
|
}).catch(error => {
|
2020-06-11 19:34:06 +09:00
|
|
|
console.error('error saving repositories');
|
2020-06-10 21:33:08 +09:00
|
|
|
loading.hide();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function populateList(options) {
|
2020-10-07 21:12:14 +09:00
|
|
|
let html = '';
|
2020-06-10 21:33:08 +09:00
|
|
|
|
|
|
|
html += '<div class="paperList">';
|
2020-10-07 21:12:14 +09:00
|
|
|
for (let i = 0; i < options.repositories.length; i++) {
|
2020-06-10 21:33:08 +09:00
|
|
|
html += getRepositoryHtml(options.repositories[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
html += '</div>';
|
|
|
|
if (!options.repositories.length) {
|
|
|
|
options.noneElement.classList.remove('hide');
|
|
|
|
}
|
|
|
|
|
|
|
|
options.listElement.innerHTML = html;
|
|
|
|
loading.hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
function getRepositoryHtml(repository) {
|
2020-10-07 21:12:14 +09:00
|
|
|
let html = '';
|
2020-06-10 21:33:08 +09:00
|
|
|
|
2020-06-11 03:02:38 +09:00
|
|
|
html += '<div class="listItem listItem-border">';
|
2020-06-11 19:34:06 +09:00
|
|
|
html += `<a is="emby-linkbutton" style="margin:0;padding:0" class="clearLink listItemIconContainer" href="${repository.Url}">`;
|
|
|
|
html += '<span class="material-icons listItemIcon open_in_new"></span>';
|
|
|
|
html += '</a>';
|
2020-06-10 21:33:08 +09:00
|
|
|
html += '<div class="listItemBody two-line">';
|
2020-06-17 02:15:05 +09:00
|
|
|
html += `<h3 class="listItemBodyText">${repository.Name}</h3>`;
|
2020-06-10 21:33:08 +09:00
|
|
|
html += `<div class="listItemBodyText secondary">${repository.Url}</div>`;
|
2020-06-11 03:02:38 +09:00
|
|
|
html += '</div>';
|
2020-08-13 21:23:51 +09:00
|
|
|
html += `<button type="button" is="paper-icon-button-light" id="${repository.Url}" class="btnDelete" title="${globalize.translate('Delete')}"><span class="material-icons delete"></span></button>`;
|
2020-06-11 03:02:38 +09:00
|
|
|
html += '</div>';
|
2020-06-10 21:33:08 +09:00
|
|
|
|
|
|
|
return html;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getTabs() {
|
|
|
|
return [{
|
|
|
|
href: 'installedplugins.html',
|
|
|
|
name: globalize.translate('TabMyPlugins')
|
|
|
|
}, {
|
|
|
|
href: 'availableplugins.html',
|
|
|
|
name: globalize.translate('TabCatalog')
|
|
|
|
}, {
|
|
|
|
href: 'repositories.html',
|
|
|
|
name: globalize.translate('TabRepositories')
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function(view, params) {
|
|
|
|
view.addEventListener('viewshow', function () {
|
|
|
|
libraryMenu.setTabs('plugins', 2, getTabs);
|
|
|
|
reloadList(this);
|
2020-06-11 03:02:38 +09:00
|
|
|
|
2020-10-07 21:12:14 +09:00
|
|
|
const save = this;
|
2020-06-11 03:02:38 +09:00
|
|
|
$('#repositories', view).on('click', '.btnDelete', function() {
|
2020-10-07 21:12:14 +09:00
|
|
|
const button = this;
|
2020-06-11 19:34:06 +09:00
|
|
|
repositories = repositories.filter(function (r) {
|
|
|
|
return r.Url !== button.id;
|
|
|
|
});
|
|
|
|
|
2020-06-16 21:13:07 +09:00
|
|
|
saveList(save);
|
2020-06-11 03:02:38 +09:00
|
|
|
});
|
2020-06-10 21:33:08 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
view.querySelector('.btnNewRepository').addEventListener('click', () => {
|
2020-07-16 22:19:09 +02:00
|
|
|
const dialog = dialogHelper.createDialog({
|
2020-06-10 21:33:08 +09:00
|
|
|
scrollY: false,
|
|
|
|
size: 'large',
|
|
|
|
modal: false,
|
|
|
|
removeOnClose: true
|
|
|
|
});
|
|
|
|
|
|
|
|
let html = '';
|
|
|
|
|
|
|
|
html += '<div class="formDialogHeader">';
|
|
|
|
html += '<button type="button" is="paper-icon-button-light" class="btnCancel autoSize" tabindex="-1"><span class="material-icons arrow_back"></span></button>';
|
|
|
|
html += `<h3 class="formDialogHeaderTitle">${globalize.translate('HeaderNewRepository')}</h3>`;
|
|
|
|
html += '</div>';
|
2020-06-11 03:02:38 +09:00
|
|
|
html += '<form class="newPluginForm" style="margin:4em">';
|
2020-06-10 21:33:08 +09:00
|
|
|
html += '<div class="inputContainer">';
|
2020-06-16 21:13:07 +09:00
|
|
|
html += `<input is="emby-input" id="txtRepositoryName" label="${globalize.translate('LabelRepositoryName')}" type="text" required />`;
|
2020-06-10 21:33:08 +09:00
|
|
|
html += `<div class="fieldDescription">${globalize.translate('LabelRepositoryNameHelp')}</div>`;
|
|
|
|
html += '</div>';
|
|
|
|
html += '<div class="inputContainer">';
|
2020-06-16 21:13:07 +09:00
|
|
|
html += `<input is="emby-input" id="txtRepositoryUrl" label="${globalize.translate('LabelRepositoryUrl')}" type="url" required />`;
|
2020-06-10 21:33:08 +09:00
|
|
|
html += `<div class="fieldDescription">${globalize.translate('LabelRepositoryUrlHelp')}</div>`;
|
|
|
|
html += '</div>';
|
2020-08-09 23:10:58 +09:00
|
|
|
html += `<button is="emby-button" type="submit" class="raised button-submit block"><span>${globalize.translate('Save')}</span></button>`;
|
2020-06-10 21:33:08 +09:00
|
|
|
html += '</div>';
|
|
|
|
html += '</form>';
|
|
|
|
|
|
|
|
dialog.innerHTML = html;
|
|
|
|
dialog.querySelector('.btnCancel').addEventListener('click', () => {
|
|
|
|
dialogHelper.close(dialog);
|
|
|
|
});
|
|
|
|
|
2020-06-11 03:02:38 +09:00
|
|
|
dialog.querySelector('.newPluginForm').addEventListener('submit', () => {
|
2020-06-10 21:33:08 +09:00
|
|
|
repositories.push({
|
|
|
|
Name: dialog.querySelector('#txtRepositoryName').value,
|
|
|
|
Url: dialog.querySelector('#txtRepositoryUrl').value,
|
|
|
|
Enabled: true
|
|
|
|
});
|
|
|
|
|
2020-06-16 21:13:07 +09:00
|
|
|
saveList(view);
|
2020-06-10 21:33:08 +09:00
|
|
|
dialogHelper.close(dialog);
|
2020-06-11 19:34:06 +09:00
|
|
|
return false;
|
2020-06-10 21:33:08 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
dialogHelper.open(dialog);
|
|
|
|
});
|
|
|
|
}
|