I'm struggling almost the whole day now with the following: I have two controllers, where controller A extends $.Controller and B extends controller A. Controller A provides event handlers for some common events on it's element and Controller B provides additional event handlers for events which Controller A shouldn't know anything about. The problem now is that I each controller needs some templates to output dialogs and depending on the controller instance those are not found. I followed the following link when using templates in my controller and therefor always work with relative paths to the template file, which results in an absolute path calculated from jQuery.Controller._calculatePosition.
The problem seems to be that during calculation of the path it seems that only the class name of the "current instance" is used and base classes are not considered. This way the calculated path for an instance of controller B while executing an event handler of the base class controller A is with the names of the instance controller B. But this controller doesn't have, and shouldn't have, the templates for controller A, only controller A should know about it's on templates. This problem rises with every inheritance level added, for example because of controller C inheriting from controller B because some of the event handlers of controller B should be disallowed for the elements behind controller C.
The automatic calculation can only be overridden if I provide a full path to this.view('//app/controller_a/views/some_template.ejs') and is something I always tried to avoid because it's a lot of text to type and it's easy to break the path during refactoring or else.
I tried to write a function on the controllers which provide the common part of the path or save it in a static member or stuff like that but neither seemed to work because instances of controller B always seem to overwrite everything of controller A and I wasn't able to call the controller a instance from controller B instance. What I would need i something like a private variable in C++ classes which are only visible to instances of the class itself and can't be overridden by extending classes. But I couldn't get anything like that working, neither using _super because this way each extending controller first needs to implement addition functions from the base class, .prototype only references the controller instance B and for some reason I'm even unable to use hasOwnProperty to detect if an event handler comes from the base class or not.
You are my last chance before I need to hard code the complete path to my templates in each new controller. Is there any way or best practice with which I can use relative template paths with extending Controllers and the magic of _calculatePosition? Or any possibility that I don't need to type the complete path in each invocation of this.view?
Thanks for any help!
Change topic type
Link this topic
Provide the permalink of a topic that is related to this topic