0
$.Controller("Whiteboard", {}, {
    init: function(){
        var pen = new Pen();
    },
    sendRequest: function() {
        // This function should listen draw/erasing events from Pen
    }

});
$.Class("Pen",{},{

    init: function() {
        // Pen setup, click to draw etc..
    }
});

Something like this, I want the Whiteboard listen events from Pen, how can I do this? I need Controller listen on a Class.

user469652
  • 48,855
  • 59
  • 128
  • 165

1 Answers1

0

If this is JMVC 3.2+ you can do something like this:

$('.whiteboard').whiteboard({pen:new Pen()});

$.Controller("Whiteboard", {}, {
    "{pen} draw": function() {
        this.sendRequest();
    }
});

$.Observe('Pen',{},{
    draw: function() {
        $(this).triggerHandler('draw');
    }
});

For JMVC 3.1, you'll have to use $.Model instead of $.Observe and use this.bind in your controller like this:

$.Controller("Whiteboard", {}, {
    init: function() {
        this.bind(this.options.pen,'draw',this.callback('sendRequest'));
    }
});
noah
  • 21,289
  • 17
  • 64
  • 88
  • Hi,Noah, thanks for your answer. One more question is that I do not want to initialise the Pen in the controller. I'd like to init the "tool(Pen, eraser, etc..)" dynamically. – user469652 May 17 '12 at 11:51