jmaki.namespace("jmaki.listeners");

// force logger to display
jmaki.debug = false;
jmaki.debugGlue=false;

jmaki.subscribe("/jmaki/editor/onSave", "jmaki.listeners.editorListener");

jmaki.listeners.editorListener = function(args) {
    var contentValue = args.value;
    var contentId  = args.id;
    if ( typeof contentValue != 'undefined' ) {
	jmaki.log("Editor content=  " + args.value);
	// send data back to server

       jmaki.doAjax({method: "POST",
                               url: "Service.jsp",
                               content: {message: contentValue },
                               callback: function(_req) {
                                   // handle any errors
			       }
                           });
    } else { 			// call came from a timer
	var editor = jmaki.attributes.get('myeditor');
	if ( editor  ){
	    editor.saveState();
	}
    }
}; 

jmaki.addTimer( {
	action: "call",
	timeout: 30000,
	target: {
	    object:"jmaki.listeners",
            functionName : "editorListener"
        }
});

jmaki.subscribe("/dojo/fisheye*", function(args) {
    jmaki.log("glue.js : fisheye event");
 });


// map topics ending with  /onSave to the handler
jmaki.subscribe("*onSave", function(args) {
    jmaki.log("glue.js : onSave request from: " + args.id + " value=" + args.value);
});

// map topics ending with  /onSave to the handler
jmaki.subscribe("*onSelect", function(args) {
    jmaki.log("glue.js : onSelect request from: " + args.widgetId);
});

// map topics ending with  /onSave to the handler
jmaki.subscribe("*onClick", function(args) {
    jmaki.log("glue.js : onClick request from: " + args.widgetId);
});
