2016-03-18 14:12:44 -07:00
|
|
|
|
define(['paperdialoghelper', 'jQuery', 'paper-input', 'paper-button', 'emby-collapsible', 'paper-checkbox'], function (paperDialogHelper, $) {
|
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;
|
|
|
|
|
paperDialogHelper.close(dlg);
|
|
|
|
|
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
|
|
|
|
|
showNewUserInviteMessage(dlg, result);
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
Dashboard.alert({
|
|
|
|
|
message: message,
|
|
|
|
|
title: Globalize.translate('HeaderInvitationSent')
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
var dlg = paperDialogHelper.createDialog({
|
|
|
|
|
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;
|
|
|
|
|
document.body.appendChild(dlg);
|
|
|
|
|
|
|
|
|
|
paperDialogHelper.open(dlg);
|
|
|
|
|
|
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) {
|
|
|
|
|
|
|
|
|
|
paperDialogHelper.close(dlg);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
});
|