}
};
- var levels = {'fatal': true, 'error': true, 'warning' : true, 'info' : true, 'debug' : false};
-
var methods = {
init : function( options ) {
var $this = $(this);
instance=new Messages (options,$this);
$this.data('Messages',instance);
- for (level in levels) {
+ for (level in options.levels) {
(function (instance,level) {
- $.subscribe("messages:"+level, function (e, msg){ instance.display_message (msg,level)});
+ $.subscribe("/messages/"+level, function (e, msg){ instance.display_message (msg,level)});
}) (instance,level);
}
// this happens very early - even before the document is loaded
// so it won't show right away; no big deal though
- $.publish ("messages:info", 'Subscribed to all 5 message channels');
+ $.publish ("/messages/info", 'Subscribed to all 5 message channels');
});
},
destroy : function( ) {
},
this.initialize = function () {
- this.plugindiv.find("div.messages-buttons>input").each(this.init_button);
+ var init_button=this.init_button;
+ var levels=this.options.levels;
+ this.plugindiv.find("div.messages-buttons>input").each(
+ function (i,input) {init_button (input, levels)});
var arm_button=this.arm_button;
var toggle_handler=this.toggle_handler;
this.plugindiv.find("div.messages-buttons>input").each(
- function (i,input) {arm_button (input,toggle_handler); }
- );
+ function (i,input) {arm_button (input,toggle_handler); });
},
- this.init_button = function (_,input) {
+ this.init_button = function (input,levels) {
/* set initial 'checked' state for that input from global 'levels' above */
var level=input.name;
if (levels[level]) $(input).attr('checked','checked');
counter : 2,
period : 1000,
sample : function () {
- $.publish("messages:fatal","a fatal message (" + messages_test.counter + " runs to go)");
- $.publish("messages:error","an error message");
- $.publish("messages:warning","a warning message");
- $.publish("messages:info","an info message");
- $.publish("messages:debug","a debug message");
+ $.publish("/messages/fatal","a fatal message (" + messages_test.counter + " runs to go)");
+ $.publish("/messages/error","an error message");
+ $.publish("/messages/warning","a warning message");
+ $.publish("/messages/info","an info message");
+ $.publish("/messages/debug","a debug message");
messages_test.counter -= 1;
if (messages_test.counter == 0)
window.clearInterval (messages_test.interval_id);
from unfold.plugin import Plugin
+# lists levels and sets them to enabled or not at startup
+default_levels = {'fatal': True, 'error': True, 'warning' : True, 'info' : True, 'debug' : False}
+
class Messages (Plugin):
- def __init__ (self, **settings):
+ def __init__ (self, levels=None, **settings):
Plugin.__init__ (self, **settings)
+ if levels is None: levels=default_levels
+ # shortcut: 'ALL' turn everything on
+ elif levels=='ALL': levels=dict( [ (k,True) for k in default_levels ] )
+ elif levels=='NONE': levels=dict( [ (k,False) for k in default_levels ] )
+ self.levels=levels
def template_file (self):
return "messages.html"
return True
# the js plugin expects a domid
def json_settings_list (self):
- return [ 'plugin_uuid' ]
+ return [ 'plugin_uuid', 'levels' ]
# and we don't need a spin wheel
def start_with_spin (self):