2016-08-06 23:15:03 -07:00
|
|
|
|
define(['dialogHelper', 'jQuery', 'emby-input', 'emby-button', 'emby-collapse', 'paper-checkbox', 'paper-icon-button-light', 'formDialogStyle'], function (dialogHelper, $) {
|
2016-02-08 21:46:25 -07:00
|
|
|
|
|
|
|
|
|
function renderLibrarySharingList(context, result) {
|
|
|
|
|
|
|
|
|
|
var folderHtml = '';
|
|
|
|
|
|
2016-02-18 22:03:00 -07:00
|
|
|
|
folderHtml += '<div class="paperCheckboxList">';
|
2016-02-08 21:46:25 -07:00
|
|
|
|
|
|
|
|
|
folderHtml += result.Items.map(function (i) {
|
|
|
|
|
|
|
|
|
|
var currentHtml = '';
|
|
|
|
|
|
|
|
|
|
var isChecked = true;
|
|
|
|
|
var checkedHtml = isChecked ? ' checked="checked"' : '';
|
|
|
|
|
|
2016-02-18 22:03:00 -07:00
|
|
|
|
currentHtml += '<paper-checkbox class="chkShareFolder" data-folderid="' + i.Id + '" type="checkbox"' + checkedHtml + '>' + i.Name + '</paper-checkbox>';
|
2016-02-08 21:46:25 -07:00
|
|
|
|
|
|
|
|
|
return currentHtml;
|
|
|
|
|
|
|
|
|
|
}).join('');
|
|
|
|
|
|
|
|
|
|
folderHtml += '</div>';
|
|
|
|
|
|
2016-02-18 22:03:00 -07:00
|
|
|
|
context.querySelector('.librarySharingList').innerHTML = folderHtml;
|
2016-02-08 21:46:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function inviteUser(dlg) {
|
|
|
|
|
|
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
|
|
|
|
|
|
ApiClient.getJSON(ApiClient.getUrl("Channels", {})).then(function (channelsResult) {
|
|
|
|
|
|
2016-02-18 22:03:00 -07:00
|
|
|
|
var shareExcludes = $(".chkShareFolder", dlg).get().filter(function (i) {
|
|
|
|
|
|
|
|
|
|
return i.checked;
|
|
|
|
|
|
|
|
|
|
}).map(function (i) {
|
2016-02-08 21:46:25 -07:00
|
|
|
|
|
|
|
|
|
return i.getAttribute('data-folderid');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Add/Update connect info
|
|
|
|
|
ApiClient.ajax({
|
|
|
|
|
|
|
|
|
|
type: "POST",
|
|
|
|
|
url: ApiClient.getUrl('Connect/Invite'),
|
|
|
|
|
dataType: 'json',
|
|
|
|
|
data: {
|
|
|
|
|
|
2016-02-23 11:59:13 -07:00
|
|
|
|
ConnectUsername: dlg.querySelector('#txtConnectUsername').value,
|
2016-02-08 21:46:25 -07:00
|
|
|
|
EnabledLibraries: shareExcludes.join(','),
|
|
|
|
|
SendingUserId: Dashboard.getCurrentUserId(),
|
|
|
|
|
EnableLiveTv: false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}).then(function (result) {
|
|
|
|
|
|
|
|
|
|
dlg.submitted = true;
|
2016-03-23 12:03:17 -07:00
|
|
|
|
dialogHelper.close(dlg);
|
2016-02-08 21:46:25 -07:00
|
|
|
|
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
|
|
|
|
|
showNewUserInviteMessage(dlg, result);
|
|
|
|
|
|
2016-04-10 14:11:06 -07:00
|
|
|
|
}, function (response) {
|
|
|
|
|
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
|
|
|
|
|
if (!response.status) {
|
|
|
|
|
// General error
|
|
|
|
|
require(['alert'], function (alert) {
|
|
|
|
|
alert({
|
|
|
|
|
text: Globalize.translate('DefaultErrorMessage')
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
} else if (response.status == 404) {
|
|
|
|
|
// User doesn't exist
|
|
|
|
|
require(['alert'], function (alert) {
|
|
|
|
|
alert({
|
|
|
|
|
text: Globalize.translate('GuestUserNotFound')
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
// status 400 = account not activated
|
|
|
|
|
|
|
|
|
|
// General error
|
|
|
|
|
showAccountErrorMessage();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showAccountErrorMessage() {
|
|
|
|
|
|
|
|
|
|
var html = Globalize.translate('ErrorAddingGuestAccount1', '<a href="https://emby.media/connect" target="_blank">https://emby.media/connect</a>');
|
|
|
|
|
html += '<br/><br/>' + Globalize.translate('ErrorAddingGuestAccount2', 'apps@emby.media');
|
|
|
|
|
|
|
|
|
|
var text = Globalize.translate('ErrorAddingGuestAccount1', 'https://emby.media/connect');
|
|
|
|
|
text += '\n\n' + Globalize.translate('ErrorAddingGuestAccount2', 'apps@emby.media');
|
|
|
|
|
|
|
|
|
|
require(['alert'], function (alert) {
|
|
|
|
|
alert({
|
|
|
|
|
text: text,
|
|
|
|
|
html: html
|
2016-02-08 21:46:25 -07:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showNewUserInviteMessage(page, result) {
|
|
|
|
|
|
|
|
|
|
if (!result.IsNewUserInvitation && !result.IsPending) {
|
|
|
|
|
|
|
|
|
|
// It was immediately approved
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var message = result.IsNewUserInvitation ?
|
|
|
|
|
Globalize.translate('MessageInvitationSentToNewUser', result.GuestDisplayName) :
|
|
|
|
|
Globalize.translate('MessageInvitationSentToUser', result.GuestDisplayName);
|
|
|
|
|
|
2016-04-10 14:11:06 -07:00
|
|
|
|
require(['alert'], function (alert) {
|
|
|
|
|
alert({
|
|
|
|
|
text: message,
|
|
|
|
|
title: Globalize.translate('HeaderInvitationSent')
|
|
|
|
|
});
|
2016-02-08 21:46:25 -07:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
show: function () {
|
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
|
|
|
|
|
|
var xhr = new XMLHttpRequest();
|
|
|
|
|
xhr.open('GET', 'components/guestinviter/guestinviter.template.html', true);
|
|
|
|
|
|
|
|
|
|
xhr.onload = function (e) {
|
|
|
|
|
|
|
|
|
|
var template = this.response;
|
2016-03-23 12:03:17 -07:00
|
|
|
|
var dlg = dialogHelper.createDialog({
|
2016-02-08 21:46:25 -07:00
|
|
|
|
removeOnClose: true,
|
|
|
|
|
size: 'small'
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
dlg.classList.add('ui-body-a');
|
|
|
|
|
dlg.classList.add('background-theme-a');
|
|
|
|
|
|
|
|
|
|
dlg.classList.add('formDialog');
|
|
|
|
|
|
|
|
|
|
var html = '';
|
|
|
|
|
|
2016-03-05 12:07:58 -07:00
|
|
|
|
html += Globalize.translateDocument(template);
|
2016-02-08 21:46:25 -07:00
|
|
|
|
|
|
|
|
|
dlg.innerHTML = html;
|
|
|
|
|
|
2016-03-23 12:03:17 -07:00
|
|
|
|
dialogHelper.open(dlg);
|
2016-02-08 21:46:25 -07:00
|
|
|
|
|
2016-03-22 10:46:57 -07:00
|
|
|
|
dlg.addEventListener('close', function () {
|
2016-02-08 21:46:25 -07:00
|
|
|
|
|
|
|
|
|
if (dlg.submitted) {
|
|
|
|
|
resolve();
|
|
|
|
|
} else {
|
|
|
|
|
reject();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
dlg.querySelector('.btnCancel').addEventListener('click', function (e) {
|
|
|
|
|
|
2016-03-23 12:03:17 -07:00
|
|
|
|
dialogHelper.close(dlg);
|
2016-02-08 21:46:25 -07:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
dlg.querySelector('form').addEventListener('submit', function (e) {
|
|
|
|
|
|
|
|
|
|
inviteUser(dlg);
|
|
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ApiClient.getJSON(ApiClient.getUrl("Library/MediaFolders", { IsHidden: false })).then(function (result) {
|
|
|
|
|
|
|
|
|
|
renderLibrarySharingList(dlg, result);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
xhr.send();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
});
|