diff --git a/lib/channel-new.js b/lib/channel-new.js index 70be6b3b..04dcc757 100644 --- a/lib/channel-new.js +++ b/lib/channel-new.js @@ -1404,7 +1404,6 @@ Channel.prototype.handleQueue = function (user, data) { maxlength: this.hasPermission(user, "exceedmaxlength") ? 0 : this.opts.maxlength }, function (err, media) { if (err) { - console.log(err); user.socket.emit("queueFail", { msg: err, link: link @@ -2539,20 +2538,42 @@ Channel.prototype.handleSetRank = function (user, data) { var updateDB = function () { self.getRank(name, function (err, oldrank) { - if (self.dead || err) { + if (self.dead) { + return; + } + + if (err) { + user.socket.emit("channelRankFail", { + msg: "Updating user rank failed: " + err + }); return; } if (oldrank >= user.rank) { + user.socket.emit("channelRankFail", { + msg: "Updating user rank failed: " + name + " has equal or higher " + + "rank than you" + }); return; } db.channels.setRank(self.name, name, rank, function (err, res) { - if (self.dead || err) { + if (self.dead) { + return; + } + + if (err) { + user.socket.emit("channelRankFail", { + msg: "Updating user rank failed: " + err + }); return; } self.logger.log("*** " + user.name + " set " + name + "'s rank to " + rank); + self.sendAll("setUserRank", { + name: name, + rank: rank + }); }); }); }; @@ -2565,11 +2586,6 @@ Channel.prototype.handleSetRank = function (user, data) { if (receiver.loggedIn) { updateDB(); } - - self.sendAll("setUserRank", { - name: name, - rank: rank - }); } else if (self.registered) { updateDB(); } diff --git a/templates/channel.jade b/templates/channel.jade index 69057bdc..e124673f 100644 --- a/templates/channel.jade +++ b/templates/channel.jade @@ -167,7 +167,7 @@ html(lang="en") li: a(href="#cs-motdeditor", data-toggle="tab", tabindex="-1") Edit MOTD li: a(href="#cs-csseditor", data-toggle="tab", tabindex="-1") Edit CSS li: a(href="#cs-jseditor", data-toggle="tab", tabindex="-1") Edit Javascript - li: a(href="#cs-chanranks", data-toggle="tab", tabindex="-1", onclick="javascript:socket.emit('requestChannelRanks')") Edit user ranks + li: a(href="#cs-chanranks", data-toggle="tab", tabindex="-1", onclick="javascript:socket.emit('requestChannelRanks')") Edit moderators li: a(href="#cs-banlist", data-toggle="tab", tabindex="-1", onclick="javascript:socket.emit('requestBanlist')") Ban list .modal-body .tab-content diff --git a/templates/channeloptions.jade b/templates/channeloptions.jade index 4af9187d..14e518b1 100644 --- a/templates/channeloptions.jade +++ b/templates/channeloptions.jade @@ -92,6 +92,12 @@ mixin recentjoins mixin chanranks #cs-chanranks.tab-pane + form.form-inline(action="javascript:void(0)", role="form") + .input-group + input#cs-chanranks-name.form-control(type="text", placeholder="Name") + span.input-group-btn + button#cs-chanranks-mod.btn.btn-success +Mod + button#cs-chanranks-adm.btn.btn-info +Admin table.table.table-striped thead tr diff --git a/www/assets/js/callbacks.js b/www/assets/js/callbacks.js index b6b4eef0..32a7aa7a 100644 --- a/www/assets/js/callbacks.js +++ b/www/assets/js/callbacks.js @@ -505,7 +505,7 @@ Callbacks = { }); entries.forEach(function (entry) { - var tr = $(""); + var tr = $("").addClass("cs-chanrank-tr-" + entry.name); var name = $("").text(entry.name).appendTo(tr); name.addClass(getNameColor(entry.rank)); var rankwrap = $(""); @@ -523,6 +523,7 @@ Callbacks = { rankedit.hide(); rank.hide(); editbox = $("").addClass("form-control") + .attr("type", "text") .attr("placeholder", entry.rank) .appendTo(rankwrap) .focus(); @@ -553,6 +554,10 @@ Callbacks = { }); }, + channelRankFail: function (data) { + makeAlert("Error", data.msg, "alert-danger").prependTo($("#cs-chanranks")); + }, + setChannelRank: function(data) { var ents = $("#channelranks").data("entries"); if(typeof ents === "undefined" || ents === null) @@ -752,6 +757,11 @@ Callbacks = { }, setUserRank: function (data) { + var tr = $(".cs-chanrank-tr-" + data.name); + var tds = tr.find("td"); + $(tds[0]).removeClass().addClass(getNameColor(data.rank)); + $(tds[1]).find("span").text(data.rank); + var user = findUserlistItem(data.name); if (user === null) { return; @@ -764,8 +774,9 @@ Callbacks = { } formatUserlistItem(user); addUserDropdown(user); - if(USEROPTS.sort_rank) + if (USEROPTS.sort_rank) { sortUserlist(); + } }, setUserIcon: function (data) { diff --git a/www/assets/js/ui.js b/www/assets/js/ui.js index 3a063ed2..15682fe1 100644 --- a/www/assets/js/ui.js +++ b/www/assets/js/ui.js @@ -490,3 +490,22 @@ if (location.protocol === "https:") { makeAlert(title, text, "alert-warning") .appendTo($("#announcements")); } + +/* channel ranks stuff */ +$("#cs-chanranks-mod").click(function () { + var name = $("#cs-chanranks-name").val(); + var rank = 2; + socket.emit("setChannelRank", { + user: name, + rank: rank + }); +}); + +$("#cs-chanranks-adm").click(function () { + var name = $("#cs-chanranks-name").val(); + var rank = 3; + socket.emit("setChannelRank", { + user: name, + rank: rank + }); +});