]> jfr.im git - irc/quakenet/qwebirc.git/commitdiff
Add kick support to menu, only visible when opped.
authorChris Porter <redacted>
Wed, 3 Jun 2009 23:45:18 +0000 (00:45 +0100)
committerChris Porter <redacted>
Wed, 3 Jun 2009 23:45:18 +0000 (00:45 +0100)
js/ui/frontends/qui.js
js/ui/menuitems.js

index 31f8b2e1e56af3617c04fe51226a79a91255557f..f89fda4888e99c317667027af924fd766d243f18 100644 (file)
@@ -424,14 +424,18 @@ qwebirc.ui.QUI.Window = new Class({
     e.addClass("menu");
     
     qwebirc.ui.MENU_ITEMS.forEach(function(x) {
-      var e2 = new Element("a");
-      e.appendChild(e2);
-      
-      e2.href = "#";
-      e2.set("text", "- " + x[0]);
-      
-      e2.addEvent("focus", function() { this.blur() }.bind(e2));
-      e2.addEvent("click", function(ev) { new Event(ev.stop()); this.menuClick(x[1]); }.bind(this));
+      var text = x[0], fn = x[1], visible_fn = x[2];
+
+      if(visible_fn == qwebirc.ui.menuitems.fns.always || visible_fn.apply(this)) {
+        var e2 = new Element("a");
+        e.appendChild(e2);
+
+        e2.href = "#";
+        e2.set("text", "- " + text);
+
+        e2.addEvent("focus", function() { this.blur() }.bind(e2));
+        e2.addEvent("click", function(ev) { new Event(ev.stop()); this.menuClick(fn); }.bind(this));
+      }
     }.bind(this));
     return e;
   },
index c5c05230a1b13d458222b3e8d52b283ca7dabd9b..3f9ee89c52fee57ac38e8da894034302a3979e21 100644 (file)
@@ -1,13 +1,43 @@
+qwebirc.ui.menuitems = {fns: {}};
+
+qwebirc.ui.menuitems.fns.always = function() {
+  return true;
+};
+
+qwebirc.ui.menuitems.fns.is_opped = function() {
+  var channel = this.name; /* window name */
+  var myNick = this.client.nickname;
+  
+  var entry = this.client.tracker.getNickOnChannel(myNick, channel);
+  if(!$defined(entry))
+    return false; /* shouldn't happen */
+   
+  /* TODO: improve (halfops) */
+  return entry.prefixes.indexOf("@") != -1;
+};
+
+/*
+  [text, command_fn, visible_predicate]
+  
+  - text is the text shown to the user in the menu
+  - command_fn is executed when they click
+    (this will be the current window)
+  - visible_predicate will be executed to determine whether or not to show the item
+    (this will be the current window)
+*/
 qwebirc.ui.MENU_ITEMS = [
   ["whois", function(nick) {
     this.client.exec("/WHOIS " + nick);
-  }],
+  }, qwebirc.ui.menuitems.fns.always],
   ["query", function(nick) {
     this.client.exec("/QUERY " + nick);
-  }],
+  }, qwebirc.ui.menuitems.fns.always],
   ["slap", function(nick) {
     this.client.exec("/ME slaps " + nick + " around a bit with a large fishbot");
-  }]
+  }, qwebirc.ui.menuitems.fns.always],
+  ["kick", function(nick) { /* TODO: disappear when we're deopped */
+    this.client.exec("/KICK " + nick + " wibble");
+  }, qwebirc.ui.menuitems.fns.is_opped]
 ];
 
 qwebirc.ui.UI_COMMANDS = [