Changeset 9132

Show
Ignore:
Timestamp:
06/20/08 18:01:03 (4 months ago)
Author:
matthias
Message:

* Introduce global.controller -> this is the only chance to use controller methods without the this. prefix, and still access controller instance fields.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/aida/demo-app/app/controllers/say_controller.js

    r9131 r9132  
    4242    
    4343   this.index_action = function() { 
     44      render({layout:null}); 
    4445      /* 
    4546      res.writeln("---" + getShortName()) 
  • sandbox/aida/demo-app/main.js

    r9128 r9132  
    1616 
    1717importModule("aida.controller"); 
    18 importFromModule("aida.routing", "RouteSet"); 
    1918 
    2019// main method called to start application 
  • sandbox/aida/modules/aida/controller.js

    r9130 r9132  
    4747   req.route = req.route || routeSet.recognizeRequest(req);    
    4848   if (!req.route) return; // FIXME 404 
    49    var controller = getControllerInstance(req.route.controllerName, req, res, session); 
     49   global.controller = getControllerInstance(req.route.controllerName, req, res, session); 
    5050    
    5151   Object.extend(req.data, req.route.params); 
  • sandbox/aida/modules/aida/controller/layout.js

    r9130 r9132  
    2323      );    
    2424   } 
     25    
     26    
     27   /** 
     28    * Set a layout for this controller, and override all prvious layout settings. 
     29    * 
     30    * @param {String} layout     Name of template file, without extension. 
     31    * @param {Function} layout   Functions which returns a template file name. 
     32    */ 
     33   this.setLayout = function(layout) { 
     34      this.layoutChain = [new Layout(this, layout)]; 
     35   }    
    2536 
    2637   this.renderLayout = function() { 
    27       helma.skin.render("app/views/layouts/" + getLayoutName() + ".skin", { "yield" : this.content }); 
     38      var name = getLayoutName.apply(this); 
     39      if (name === null) { 
     40         res.write(this.content); 
     41         return; 
     42      } 
     43      helma.skin.render("app/views/layouts/" + name + ".skin", { "yield" : this.content }); 
    2844   } 
    2945 
     
    3753   function Layout(controller, layout, param) { 
    3854      this.controller = controller; 
    39       this.name = (typeof layout === "string") ? layout : layout.apply(controller)
     55      this.name = (Object.isFunction(layout)) ? layout.apply(controller) : layout
    4056      this.param = param || {}; 
    4157      if (this.param.only && !Object.isArray(this.param.only)) this.param.only = [this.param.only]; 
  • sandbox/aida/modules/aida/controller/templates.js

    r9130 r9132  
    9292   res.calledRender = true; 
    9393   var action = options.action || req.route.action; 
    94    var context = this.prepareContext(options.context); 
     94   var context = controller.prepareContext(options.context); 
     95   if (options.layout !== undefined) controller.setLayout(options.layout); 
    9596    
    96    if (typeof options === "string" && options != "") { 
     97   delete options.layout; 
     98    
     99   if (typeof options === "string" && options !== "") { 
    97100      res.writeln(options); 
    98101   } else if (options && options.inline) { 
     
    145148      { 
    146149         request : req.data, 
    147          controller : this
     150         controller : controller
    148151         flash : req.flash, 
    149152         headers : req.headers,