Implement time parsing/formatting for channel settings
This commit is contained in:
parent
8305c235eb
commit
74cb1b3efc
4 changed files with 54 additions and 20 deletions
30
www/js/ui.js
30
www/js/ui.js
|
|
@ -636,6 +636,36 @@ $(".cs-textbox").keyup(function () {
|
|||
}, 1000);
|
||||
});
|
||||
|
||||
$(".cs-textbox-timeinput").keyup(function (event) {
|
||||
var box = $(this);
|
||||
var key = box.attr("id").replace("cs-", "");
|
||||
var value = box.val();
|
||||
var lastkey = Date.now();
|
||||
box.data("lastkey", lastkey);
|
||||
|
||||
setTimeout(function () {
|
||||
if (box.data("lastkey") !== lastkey || box.val() !== value) {
|
||||
return;
|
||||
}
|
||||
|
||||
$("#cs-textbox-timeinput-validation-error-" + key).remove();
|
||||
$(event.target).parent().removeClass("has-error");
|
||||
var data = {};
|
||||
try {
|
||||
data[key] = parseTimeout(value);
|
||||
} catch (error) {
|
||||
var msg = "Invalid timespan value '" + value + "'. Please use the format " +
|
||||
"HH:MM:SS or enter a single number for the number of seconds.";
|
||||
var validationError = $("<p/>").addClass("text-danger").text(msg)
|
||||
.attr("id", "cs-textbox-timeinput-validation-error-" + key);
|
||||
validationError.insertAfter(event.target);
|
||||
$(event.target).parent().addClass("has-error");
|
||||
return;
|
||||
}
|
||||
socket.emit("setOptions", data);
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
$("#cs-chanlog-refresh").click(function () {
|
||||
socket.emit("readChanLog");
|
||||
});
|
||||
|
|
|
|||
|
|
@ -759,18 +759,23 @@ function applyOpts() {
|
|||
}
|
||||
}
|
||||
|
||||
function showPollMenu() {
|
||||
function parseTimeout(t) {
|
||||
var m;
|
||||
if (m = t.match(/^(\d+):(\d+)$/)) {
|
||||
return parseInt(m[1], 10) * 60 + parseInt(m[2], 10);
|
||||
} else if (m = t.match(/^(\d+)$/)) {
|
||||
return parseInt(m[1], 10);
|
||||
} else {
|
||||
throw new Error("Invalid timeout value '" + t + "'");
|
||||
}
|
||||
function parseTimeout(t) {
|
||||
var m;
|
||||
if (m = t.match(/^(\d+):(\d+):(\d+)$/)) {
|
||||
// HH:MM:SS
|
||||
return parseInt(m[1], 10) * 3600 + parseInt(m[2], 10) * 60 + parseInt(m[3], 10);
|
||||
} else if (m = t.match(/^(\d+):(\d+)$/)) {
|
||||
// MM:SS
|
||||
return parseInt(m[1], 10) * 60 + parseInt(m[2], 10);
|
||||
} else if (m = t.match(/^(\d+)$/)) {
|
||||
// Seconds
|
||||
return parseInt(m[1], 10);
|
||||
} else {
|
||||
throw new Error("Invalid timeout value '" + t + "'");
|
||||
}
|
||||
}
|
||||
|
||||
function showPollMenu() {
|
||||
$("#pollwrap .poll-menu").remove();
|
||||
var menu = $("<div/>").addClass("well poll-menu")
|
||||
.prependTo($("#pollwrap"));
|
||||
|
|
@ -930,8 +935,8 @@ function handleModPermissions() {
|
|||
$("#cs-torbanned").prop("checked", CHANNEL.opts.torbanned);
|
||||
$("#cs-allow_ascii_control").prop("checked", CHANNEL.opts.allow_ascii_control);
|
||||
$("#cs-playlist_max_per_user").val(CHANNEL.opts.playlist_max_per_user || 0);
|
||||
$("#cs-new_user_chat_delay").val(CHANNEL.opts.new_user_chat_delay || 0);
|
||||
$("#cs-new_user_chat_link_delay").val(CHANNEL.opts.new_user_chat_link_delay || 0);
|
||||
$("#cs-new_user_chat_delay").val(formatTime(CHANNEL.opts.new_user_chat_delay || 0));
|
||||
$("#cs-new_user_chat_link_delay").val(formatTime(CHANNEL.opts.new_user_chat_link_delay || 0));
|
||||
(function() {
|
||||
if(typeof CHANNEL.opts.maxlength != "number") {
|
||||
$("#cs-maxlength").val("");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue