2016-08-20 11:34:30 -07:00
|
|
|
|
define(['jQuery', 'fnchecked', 'emby-checkbox'], function ($) {
|
2016-10-22 22:11:46 -07:00
|
|
|
|
'use strict';
|
2014-10-29 15:01:02 -07:00
|
|
|
|
|
2014-12-22 20:58:14 -07:00
|
|
|
|
function loadMediaFolders(page, mediaFolders) {
|
2014-10-29 19:06:05 -07:00
|
|
|
|
|
|
|
|
|
var html = '';
|
|
|
|
|
|
2016-08-20 11:34:30 -07:00
|
|
|
|
html += '<h3 class="checkboxListLabel">' + Globalize.translate('HeaderLibraries') + '</h3>';
|
2014-10-29 19:06:05 -07:00
|
|
|
|
|
2016-08-20 11:34:30 -07:00
|
|
|
|
html += '<div class="checkboxList paperList" style="padding:.5em 1em;">';
|
2014-10-29 19:06:05 -07:00
|
|
|
|
|
|
|
|
|
for (var i = 0, length = mediaFolders.length; i < length; i++) {
|
|
|
|
|
|
|
|
|
|
var folder = mediaFolders[i];
|
|
|
|
|
|
2014-12-22 20:58:14 -07:00
|
|
|
|
var checkedAttribute = ' checked="checked"';
|
2014-10-29 19:06:05 -07:00
|
|
|
|
|
2016-08-20 11:34:30 -07:00
|
|
|
|
html += '<label><input type="checkbox" is="emby-checkbox" class="chkFolder" data-id="' + folder.Id + '"' + checkedAttribute + '/><span>' + folder.Name + '</span></label>';
|
2014-10-29 19:06:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-04-09 12:04:14 -07:00
|
|
|
|
html += '</div>';
|
2014-10-29 19:06:05 -07:00
|
|
|
|
|
2015-01-19 22:19:13 -07:00
|
|
|
|
$('.folderAccess', page).html(html).trigger('create');
|
|
|
|
|
|
2016-04-09 12:04:14 -07:00
|
|
|
|
$('#chkEnableAllFolders', page).checked(true).trigger('change');
|
2014-10-29 19:06:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-22 20:58:14 -07:00
|
|
|
|
function loadChannels(page, channels) {
|
2014-10-29 19:06:05 -07:00
|
|
|
|
|
|
|
|
|
var html = '';
|
|
|
|
|
|
2016-08-20 11:34:30 -07:00
|
|
|
|
html += '<h3 class="checkboxListLabel">' + Globalize.translate('HeaderChannels') + '</h3>';
|
2014-10-29 19:06:05 -07:00
|
|
|
|
|
2016-08-20 11:34:30 -07:00
|
|
|
|
html += '<div class="checkboxList paperList" style="padding:.5em 1em;">';
|
2014-10-29 19:06:05 -07:00
|
|
|
|
|
|
|
|
|
for (var i = 0, length = channels.length; i < length; i++) {
|
|
|
|
|
|
|
|
|
|
var folder = channels[i];
|
|
|
|
|
|
2014-12-22 20:58:14 -07:00
|
|
|
|
var checkedAttribute = ' checked="checked"';
|
2014-10-29 19:06:05 -07:00
|
|
|
|
|
2016-08-20 11:34:30 -07:00
|
|
|
|
html += '<label><input type="checkbox" is="emby-checkbox" class="chkChannel" data-id="' + folder.Id + '"' + checkedAttribute + '/><span>' + folder.Name + '</span></label>';
|
2014-10-29 19:06:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-04-09 12:04:14 -07:00
|
|
|
|
html += '</div>';
|
2014-10-29 19:06:05 -07:00
|
|
|
|
|
|
|
|
|
$('.channelAccess', page).show().html(html).trigger('create');
|
|
|
|
|
|
|
|
|
|
if (channels.length) {
|
|
|
|
|
$('.channelAccessContainer', page).show();
|
|
|
|
|
} else {
|
|
|
|
|
$('.channelAccessContainer', page).hide();
|
|
|
|
|
}
|
2015-01-19 13:53:02 -07:00
|
|
|
|
|
2016-04-09 12:04:14 -07:00
|
|
|
|
$('#chkEnableAllChannels', page).checked(true).trigger('change');
|
2014-10-29 19:06:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-22 20:58:14 -07:00
|
|
|
|
function loadUser(page) {
|
2014-10-29 15:01:02 -07:00
|
|
|
|
|
2014-12-22 20:58:14 -07:00
|
|
|
|
$('#txtUserName', page).val('');
|
2014-10-29 19:06:05 -07:00
|
|
|
|
|
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
|
|
|
|
|
|
var promise4 = ApiClient.getJSON(ApiClient.getUrl("Library/MediaFolders", { IsHidden: false }));
|
|
|
|
|
|
|
|
|
|
var promise5 = ApiClient.getJSON(ApiClient.getUrl("Channels"));
|
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
Promise.all([promise4, promise5]).then(function (responses) {
|
2014-10-29 19:06:05 -07:00
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
loadMediaFolders(page, responses[0].Items);
|
|
|
|
|
loadChannels(page, responses[1].Items);
|
2014-10-29 19:06:05 -07:00
|
|
|
|
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
});
|
2014-10-29 15:01:02 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-29 19:06:05 -07:00
|
|
|
|
function saveUser(page) {
|
|
|
|
|
|
|
|
|
|
var name = $('#txtUserName', page).val();
|
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
ApiClient.createUser(name).then(function (user) {
|
2014-10-29 19:06:05 -07:00
|
|
|
|
|
2015-01-19 22:19:13 -07:00
|
|
|
|
user.Policy.EnableAllFolders = $('#chkEnableAllFolders', page).checked();
|
|
|
|
|
user.Policy.EnabledFolders = user.Policy.EnableAllFolders ?
|
|
|
|
|
[] :
|
2016-04-09 12:04:14 -07:00
|
|
|
|
$('.chkFolder', page).get().filter(function (i) {
|
|
|
|
|
return i.checked;
|
|
|
|
|
}).map(function (i) {
|
|
|
|
|
return i.getAttribute('data-id');
|
|
|
|
|
});
|
2014-10-29 19:06:05 -07:00
|
|
|
|
|
2015-01-19 13:53:02 -07:00
|
|
|
|
user.Policy.EnableAllChannels = $('#chkEnableAllChannels', page).checked();
|
|
|
|
|
user.Policy.EnabledChannels = user.Policy.EnableAllChannels ?
|
|
|
|
|
[] :
|
2016-04-09 12:04:14 -07:00
|
|
|
|
$('.chkChannel', page).get().filter(function (i) {
|
|
|
|
|
return i.checked;
|
|
|
|
|
}).map(function (i) {
|
|
|
|
|
return i.getAttribute('data-id');
|
|
|
|
|
});
|
2015-01-13 21:20:30 -07:00
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
ApiClient.updateUserPolicy(user.Id, user.Policy).then(function () {
|
2016-07-15 12:53:49 -07:00
|
|
|
|
Dashboard.navigate("useredit.html?userId=" + user.Id);
|
2014-10-29 19:06:05 -07:00
|
|
|
|
});
|
2015-10-13 12:22:45 -07:00
|
|
|
|
|
2016-01-27 23:42:43 -07:00
|
|
|
|
}, function (response) {
|
|
|
|
|
|
|
|
|
|
if (response.status == 400) {
|
|
|
|
|
|
|
|
|
|
Dashboard.alert({
|
|
|
|
|
message: page.querySelector('.labelNewUserNameHelp').innerHTML
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
} else {
|
2016-02-24 23:38:12 -07:00
|
|
|
|
require(['toast'], function (toast) {
|
|
|
|
|
toast(Globalize.translate('DefaultErrorMessage'));
|
|
|
|
|
});
|
2016-01-27 23:42:43 -07:00
|
|
|
|
}
|
2015-10-13 12:22:45 -07:00
|
|
|
|
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
2014-10-29 15:01:02 -07:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-17 18:27:48 -07:00
|
|
|
|
function onSubmit() {
|
2016-01-27 23:42:43 -07:00
|
|
|
|
var page = $(this).parents('.page')[0];
|
2014-10-29 15:01:02 -07:00
|
|
|
|
|
2015-05-17 18:27:48 -07:00
|
|
|
|
Dashboard.showLoadingMsg();
|
2014-10-29 15:01:02 -07:00
|
|
|
|
|
2015-05-17 18:27:48 -07:00
|
|
|
|
saveUser(page);
|
2014-10-29 15:01:02 -07:00
|
|
|
|
|
2015-05-17 18:27:48 -07:00
|
|
|
|
// Disable default form submission
|
|
|
|
|
return false;
|
2014-10-29 15:01:02 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function loadData(page) {
|
|
|
|
|
|
2014-12-22 20:58:14 -07:00
|
|
|
|
loadUser(page);
|
2014-10-29 15:01:02 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-09-01 07:01:59 -07:00
|
|
|
|
$(document).on('pageinit', "#newUserPage", function () {
|
2015-01-19 13:53:02 -07:00
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
|
|
|
|
|
$('#chkEnableAllChannels', page).on('change', function () {
|
|
|
|
|
|
|
|
|
|
if (this.checked) {
|
|
|
|
|
$('.channelAccessListContainer', page).hide();
|
|
|
|
|
} else {
|
|
|
|
|
$('.channelAccessListContainer', page).show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
2015-01-19 22:19:13 -07:00
|
|
|
|
$('#chkEnableAllFolders', page).on('change', function () {
|
|
|
|
|
|
|
|
|
|
if (this.checked) {
|
|
|
|
|
$('.folderAccessListContainer', page).hide();
|
|
|
|
|
} else {
|
|
|
|
|
$('.folderAccessListContainer', page).show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
2015-05-17 18:27:48 -07:00
|
|
|
|
$('.newUserProfileForm').off('submit', onSubmit).on('submit', onSubmit);
|
|
|
|
|
|
2015-09-24 10:08:10 -07:00
|
|
|
|
}).on('pageshow', "#newUserPage", function () {
|
2014-10-29 15:01:02 -07:00
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
|
|
|
|
|
loadData(page);
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
2016-03-18 21:26:17 -07:00
|
|
|
|
});
|