1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Merge pull request #378 from dkanada/pw

Add optional password field on user creation
This commit is contained in:
dkanada 2019-07-06 05:07:49 -07:00 committed by GitHub
commit bf5f3b3fde
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 90 additions and 50 deletions

View file

@ -1190,15 +1190,13 @@ define(["events", "appStorage"], function(events, appStorage) {
data: JSON.stringify(info), data: JSON.stringify(info),
contentType: "application/json" contentType: "application/json"
}) })
}, ApiClient.prototype.createUser = function(name) { }, ApiClient.prototype.createUser = function(user) {
var url = this.getUrl("Users/New"); var url = this.getUrl("Users/New");
return this.ajax({ return this.ajax({
type: "POST", type: "POST",
url: url, url: url,
data: { data: JSON.stringify(user),
Name: name contentType: "application/json"
},
dataType: "json"
}) })
}, ApiClient.prototype.updateUser = function(user) { }, ApiClient.prototype.updateUser = function(user) {
if (!user) throw new Error("null user"); if (!user) throw new Error("null user");

View file

@ -3,74 +3,113 @@ define(["jQuery", "loading", "fnchecked", "emby-checkbox"], function($, loading)
function loadMediaFolders(page, mediaFolders) { function loadMediaFolders(page, mediaFolders) {
var html = ""; var html = "";
html += '<h3 class="checkboxListLabel">' + Globalize.translate("HeaderLibraries") + "</h3>", html += '<div class="checkboxList paperList" style="padding:.5em 1em;">'; html += '<h3 class="checkboxListLabel">' + Globalize.translate("HeaderLibraries") + "</h3>";
for (var i = 0, length = mediaFolders.length; i < length; i++) { html += '<div class="checkboxList paperList" style="padding:.5em 1em;">';
for (var i = 0; i < mediaFolders.length; i++) {
var folder = mediaFolders[i]; var folder = mediaFolders[i];
html += '<label><input type="checkbox" is="emby-checkbox" class="chkFolder" data-id="' + folder.Id + '" checked="checked"/><span>' + folder.Name + "</span></label>" html += '<label><input type="checkbox" is="emby-checkbox" class="chkFolder" data-id="' + folder.Id + '" checked="checked"/><span>' + folder.Name + "</span></label>";
} }
html += "</div>", $(".folderAccess", page).html(html).trigger("create"), $("#chkEnableAllFolders", page).checked(!0).trigger("change") html += "</div>";
$(".folderAccess", page).html(html).trigger("create");
$("#chkEnableAllFolders", page).checked(true).trigger("change");
} }
function loadChannels(page, channels) { function loadChannels(page, channels) {
var html = ""; var html = "";
html += '<h3 class="checkboxListLabel">' + Globalize.translate("HeaderChannels") + "</h3>", html += '<div class="checkboxList paperList" style="padding:.5em 1em;">'; html += '<h3 class="checkboxListLabel">' + Globalize.translate("HeaderChannels") + "</h3>";
for (var i = 0, length = channels.length; i < length; i++) { html += '<div class="checkboxList paperList" style="padding:.5em 1em;">';
for (var i = 0; i < channels.length; i++) {
var folder = channels[i]; var folder = channels[i];
html += '<label><input type="checkbox" is="emby-checkbox" class="chkChannel" data-id="' + folder.Id + '" checked="checked"/><span>' + folder.Name + "</span></label>" html += '<label><input type="checkbox" is="emby-checkbox" class="chkChannel" data-id="' + folder.Id + '" checked="checked"/><span>' + folder.Name + "</span></label>";
} }
html += "</div>", $(".channelAccess", page).show().html(html).trigger("create"), channels.length ? $(".channelAccessContainer", page).show() : $(".channelAccessContainer", page).hide(), $("#chkEnableAllChannels", page).checked(!0).trigger("change") html += "</div>";
$(".channelAccess", page).show().html(html).trigger("create");
if (channels.length) {
$(".channelAccessContainer", page).show();
} else {
$(".channelAccessContainer", page).hide();
}
$("#chkEnableAllChannels", page).checked(true).trigger("change");
} }
function loadUser(page) { function loadUser(page) {
$("#txtUserName", page).val(""), loading.show(); $("#txtUsername", page).val("");
var promise4 = ApiClient.getJSON(ApiClient.getUrl("Library/MediaFolders", { $("#txtPassword", page).val("");
IsHidden: !1 loading.show();
})), var promiseFolders = ApiClient.getJSON(ApiClient.getUrl("Library/MediaFolders", {
promise5 = ApiClient.getJSON(ApiClient.getUrl("Channels")); IsHidden: false
Promise.all([promise4, promise5]).then(function(responses) { }));
loadMediaFolders(page, responses[0].Items), loadChannels(page, responses[1].Items), loading.hide() var promiseChannels = ApiClient.getJSON(ApiClient.getUrl("Channels"));
Promise.all([promiseFolders, promiseChannels]).then(function(responses) {
loadMediaFolders(page, responses[0].Items);
loadChannels(page, responses[1].Items);
loading.hide();
}) })
} }
function saveUser(page) { function saveUser(page) {
var name = $("#txtUserName", page).val(); var user = {};
ApiClient.createUser(name).then(function(user) { user.Name = $("#txtUsername", page).val();
user.Policy.EnableAllFolders = $("#chkEnableAllFolders", page).checked(), user.Policy.EnabledFolders = user.Policy.EnableAllFolders ? [] : $(".chkFolder", page).get().filter(function(i) { user.Password = $("#txtPassword", page).val();
return i.checked ApiClient.createUser(user).then(function(user) {
}).map(function(i) { user.Policy.EnableAllFolders = $("#chkEnableAllFolders", page).checked();
return i.getAttribute("data-id") user.Policy.EnabledFolders = [];
}), user.Policy.EnableAllChannels = $("#chkEnableAllChannels", page).checked(), user.Policy.EnabledChannels = user.Policy.EnableAllChannels ? [] : $(".chkChannel", page).get().filter(function(i) { if (!user.Policy.EnableAllFolders) {
return i.checked user.Policy.EnabledFolders = $(".chkFolder", page).get().filter(function(i) {
}).map(function(i) { return i.checked
return i.getAttribute("data-id") }).map(function(i) {
}), ApiClient.updateUserPolicy(user.Id, user.Policy).then(function() { return i.getAttribute("data-id");
Dashboard.navigate("useredit.html?userId=" + user.Id) });
}) }
user.Policy.EnableAllChannels = $("#chkEnableAllChannels", page).checked();
user.Policy.EnabledChannels = [];
if (!user.Policy.EnableAllChannels) {
user.Policy.EnabledChannels = $(".chkChannel", page).get().filter(function(i) {
return i.checked
}).map(function(i) {
return i.getAttribute("data-id");
});
}
ApiClient.updateUserPolicy(user.Id, user.Policy).then(function() {
Dashboard.navigate("useredit.html?userId=" + user.Id);
});
}, function(response) { }, function(response) {
400 == response.status ? Dashboard.alert({ require(["toast"], function(toast) {
message: page.querySelector(".labelNewUserNameHelp").innerHTML toast(Globalize.translate("DefaultErrorMessage"));
}) : require(["toast"], function(toast) { });
toast(Globalize.translate("DefaultErrorMessage")) loading.hide();
}), loading.hide() });
})
} }
function onSubmit() { function onSubmit() {
var page = $(this).parents(".page")[0]; var page = $(this).parents(".page")[0];
return loading.show(), saveUser(page), !1 loading.show();
saveUser(page);
return false;
} }
function loadData(page) { function loadData(page) {
loadUser(page) loadUser(page);
} }
$(document).on("pageinit", "#newUserPage", function() { $(document).on("pageinit", "#newUserPage", function() {
var page = this; var page = this;
$("#chkEnableAllChannels", page).on("change", function() { $("#chkEnableAllChannels", page).on("change", function() {
this.checked ? $(".channelAccessListContainer", page).hide() : $(".channelAccessListContainer", page).show() if (this.checked) {
}), $("#chkEnableAllFolders", page).on("change", function() { $(".channelAccessListContainer", page).hide();
this.checked ? $(".folderAccessListContainer", page).hide() : $(".folderAccessListContainer", page).show() } else {
}), $(".newUserProfileForm").off("submit", onSubmit).on("submit", onSubmit) $(".channelAccessListContainer", page).show();
}
});
$("#chkEnableAllFolders", page).on("change", function() {
if (this.checked) {
$(".folderAccessListContainer", page).hide();
} else {
$(".folderAccessListContainer", page).show();
}
});
$(".newUserProfileForm").off("submit", onSubmit).on("submit", onSubmit);
}).on("pageshow", "#newUserPage", function() { }).on("pageshow", "#newUserPage", function() {
loadData(this) loadData(this);
}) });
}); });

View file

@ -1,8 +1,6 @@
<div id="newUserPage" data-role="page" class="page type-interior"> <div id="newUserPage" data-role="page" class="page type-interior">
<div> <div>
<div class="content-primary"> <div class="content-primary">
<form class="newUserProfileForm"> <form class="newUserProfileForm">
<div class="verticalSection"> <div class="verticalSection">
<div class="sectionTitleContainer flex align-items-center"> <div class="sectionTitleContainer flex align-items-center">
@ -11,7 +9,11 @@
</div> </div>
<div class="inputContainer"> <div class="inputContainer">
<input is="emby-input" id="txtUserName" required type="text" label="${LabelName}" /> <input is="emby-input" id="txtUsername" required type="text" label="${LabelName}" />
</div>
<div class="inputContainer">
<input is="emby-input" id="txtPassword" type="password" label="${LabelPassword}" />
</div> </div>
</div> </div>
@ -29,6 +31,7 @@
</div> </div>
</div> </div>
</div> </div>
<div class="channelAccessContainer verticalSection verticalSection-extrabottompadding" style="display:none;"> <div class="channelAccessContainer verticalSection verticalSection-extrabottompadding" style="display:none;">
<h2 class="sectionTitle">${HeaderChannelAccess}</h2> <h2 class="sectionTitle">${HeaderChannelAccess}</h2>
<div class="checkboxContainer checkboxContainer-withDescription"> <div class="checkboxContainer checkboxContainer-withDescription">