A few UI fixes; improve tab complete algorithm

This commit is contained in:
calzoneman 2014-01-30 23:02:58 -06:00
parent 6f3b10222f
commit 6051dd3939
5 changed files with 77 additions and 42 deletions

View File

@ -83,6 +83,10 @@ function User(socket) {
}
}
});
if (self.global_rank >= 255) {
self.initAdminCallbacks();
}
});
}
@ -407,6 +411,32 @@ User.prototype.initChannelCallbacks = function () {
});
};
User.prototype.initAdminCallbacks = function () {
var self = this;
self.socket.on("borrow-rank", function (rank) {
if (self.inChannel()) {
if (typeof rank !== "number") {
return;
}
if (rank > self.global_rank) {
return;
}
if (rank === 255 && self.global_rank > 255) {
rank = self.global_rank;
}
self.rank = rank;
self.socket.emit("rank", rank);
self.channel.sendAll("setUserRank", {
name: self.name,
rank: rank
});
}
});
};
User.prototype.whenLoggedIn = function (fn) {
if (this.loggedIn) {
fn();

View File

@ -20,7 +20,7 @@ html(lang="en")
section#mainpage
.container
.row
#acp-logview.col-md-12(style="display: none")
#acp-logview.acp-panel.col-md-12(style="display: none")
h3 Log Viewer
.input-group
div.input-group-btn
@ -29,10 +29,10 @@ html(lang="en")
button#acp-httplog-btn.btn.btn-default HTTP log
input#acp-chanlog-name.form-control(type="text", placeholder="Channel name")
pre#acp-log
#acp-announcements.col-md-12(style="display: none")
#acp-announcements.acp-panel.col-md-6.col-md-offset-3(style="display: none")
h3 Announcements
h3 New Announcement
div(style="max-width: 50%")
div
form.form-horizontal(action="javascript:void(0)", role="form")
.form-group
label.control-label.col-sm-2(for="acp-announce-title") Title
@ -45,7 +45,7 @@ html(lang="en")
.form-group
.col-sm-10.col-sm-offset-2
button#acp-announce-submit.btn.btn-primary Announce
#acp-global-bans.col-md-12(style="display: none")
#acp-global-bans.acp-panel.col-md-12(style="display: none")
h3 Global Bans
table.table.table-striped.table-bordered
thead
@ -67,7 +67,7 @@ html(lang="en")
.form-group
.col-sm-9.col-sm-offset-3
button#acp-gban-submit.btn.btn-danger Add ban
#acp-user-lookup.col-md-12(style="display: none")
#acp-user-lookup.acp-panel.col-md-12(style="display: none")
h3 Users
.input-group(style="max-width: 25%")
input#acp-ulookup-name.form-control(type="text")
@ -81,7 +81,7 @@ html(lang="en")
th#acp-users-rank Rank
th#acp-users-email Email
th Actions
#acp-channel-lookup.col-md-12(style="display: none")
#acp-channel-lookup.acp-panel.col-md-12(style="display: none")
h3 Channels
form.form-inline(action="javascript:void(0)", role="form")
.form-group
@ -97,7 +97,7 @@ html(lang="en")
th ID
th Name
th Owner
#acp-loaded-channels.col-md-12(style="display: none")
#acp-loaded-channels.acp-panel.col-md-12(style="display: none")
h3 Loaded Channels
button#acp-lchannels-refresh.btn.btn-default Refresh
table.table.table-bordered.table-striped(style="margin-top: 20px")
@ -109,12 +109,12 @@ html(lang="en")
th Registered
th Public
th Force Unload
#acp-eventlog.col-md-12(style="display: none")
#acp-eventlog.acp-panel.col-md-12(style="display: none")
h3 Event Log
strong Filter event types
select#acp-eventlog-filter.form-control(multiple="multiple", style="max-width: 25%")
pre#acp-eventlog-text(style="margin-top: 20px")
#acp-stats.col-md-12(style="display: none")
#acp-stats.acp-panel.col-md-12(style="display: none")
h3 User Count
canvas#stat_users(width="100%", height="400")
h3 Channel Count

View File

@ -393,7 +393,7 @@ Callbacks = {
CLIENT.rank = r;
handlePermissionChange();
if(SUPERADMIN && $("#setrank").length == 0) {
$("<a/>").attr("href", "/acp.html")
$("<a/>").attr("href", "/acp")
.attr("target", "_blank")
.text("ACP")
.appendTo($("<li/>").appendTo($(".nav")[0]));

View File

@ -23,13 +23,13 @@ $("#togglemotd").click(function () {
var hidden = $("#motd").css("display") === "none";
$("#motd").toggle();
if (hidden) {
$("#togglemotd").find(".icon-plus")
.removeClass("icon-plus")
.addClass("icon-minus");
$("#togglemotd").find(".glyphicon-plus")
.removeClass("glyphicon-plus")
.addClass("glyphicon-minus");
} else {
$("#togglemotd").find(".icon-minus")
.removeClass("icon-minus")
.addClass("icon-plus");
$("#togglemotd").find(".glyphicon-minus")
.removeClass("glyphicon-minus")
.addClass("glyphicon-plus");
}
});
@ -103,6 +103,35 @@ $("#guestname").keydown(function (ev) {
}
});
function chatTabComplete() {
var words = $("#chatline").val().split(" ");
var current = words[words.length - 1].toLowerCase();
var users = $("#userlist").children().map(function (_, elem) {
return elem.children[1].innerHTML;
}).filter(function (_, name) {
return name.toLowerCase().indexOf(current) === 0;
});
// users now contains a list of names that start with current word
if (users.length === 0) {
return;
}
var min = Math.min.apply(Math, users.map(function (_, name) {
return name.length;
}));
current = users[0].substring(0, min);
if (users.length === 1) {
if (words.length === 1) {
current += ":";
}
current += " ";
}
words[words.length - 1] = current;
$("#chatline").val(words.join(" "));
}
$("#chatline").keydown(function(ev) {
// Enter/return
if(ev.keyCode == 13) {
@ -135,31 +164,7 @@ $("#chatline").keydown(function(ev) {
return;
}
else if(ev.keyCode == 9) { // Tab completion
var words = $("#chatline").val().split(" ");
var current = words[words.length - 1].toLowerCase();
var users = $("#userlist").children();
var match = null;
for(var i = 0; i < users.length; i++) {
var name = users[i].children[1].innerHTML.toLowerCase();
// Last word is a unique match for a userlist name
if(name.indexOf(current) == 0 && match == null) {
match = users[i].children[1].innerHTML;
}
// Last word is NOT a unique match- a match has already
// been found. Bail because no unique completion is possible.
else if(name.indexOf(current) == 0) {
match = null;
break;
}
}
if(match != null) {
words[words.length - 1] = match;
if(words.length == 1)
words[0] += ": ";
else
words[words.length - 1] += " ";
$("#chatline").val(words.join(" "));
}
chatTabComplete();
ev.preventDefault();
return false;
}

View File

@ -20,7 +20,7 @@ function addMenuItem(target, text) {
.text(text)
.appendTo(li)
.click(function () {
$(".col-md-12").hide();
$(".acp-panel").hide();
$(target).show();
});
};