1 // ==========================================================================
  2 // Project:   SproutCore - JavaScript Application Framework
  3 // Copyright: ©2006-2011 Strobe Inc. and contributors.
  4 //            Portions ©2008-2011 Apple Inc. All rights reserved.
  5 // License:   Licensed under MIT license (see license.js)
  6 // ==========================================================================
  7 
  8 /**
  9   @class SC.Page
 10 
 11   A Page object is used to store a set of views that can be lazily configured
 12   as needed.  The page object works by overloading the get() method.  The
 13   first time you try to get the page
 14   
 15   @extends SC.Object
 16 */
 17 SC.Page = SC.Object.extend(
 18 /** @scope SC.Page.prototype */ {
 19   
 20   /**
 21     When you create a page, you can set it's "owner" property to an
 22     object outside the page definition. This allows views in the page
 23     to use the owner object as a target, (as well as other objects
 24     accessible through the owner object). E.g.
 25     
 26         myButton: SC.ButtonView.design({
 27           title: 'Click me',
 28           target: SC.outlet('page.owner'),
 29           action: 'buttonClicked'
 30         })
 31     
 32     Usually, you'll set 'owner' to the object defined in core.js.
 33   */
 34   owner: null,
 35   
 36   get: function(key) {
 37     var value = this[key] ;
 38     if (value && value.isClass) {
 39       this[key] = value = value.create({ page: this }) ;
 40       return value ;
 41     } else return sc_super();
 42   },
 43 
 44   /**
 45     Returns the named property unless the property is a view that has not yet
 46     been configured.  In that case it will return undefined.  You can use this
 47     method to safely get a view without waking it up.
 48   */
 49   getIfConfigured: function(key) {
 50     var ret = this[key] ;
 51     return (ret && ret.isViewClass) ? null : this.get(key);
 52   },
 53 
 54   /**
 55     Applies a localization to every view builder defined on the page.  You must call this before you construct a view to apply the localization.
 56   */
 57   loc: function(locs) {
 58     var view, key;
 59     for(key in locs) {
 60       if (!locs.hasOwnProperty(key)) continue ;
 61       view = this[key] ;
 62       if (!view || !view.isViewClass) continue ;
 63       view.loc(locs[key]);
 64     }
 65     return this ;
 66   }
 67 
 68   //needsDesigner: YES,
 69   
 70   //inDesignMode: YES
 71     
 72 }) ;
 73 
 74 // ..........................................................
 75 // SUPPORT FOR LOADING PAGE DESIGNS
 76 // 
 77 
 78 /** Calling design() on a page is the same as calling create() */
 79 SC.Page.design = SC.Page.create ;
 80 
 81 /** Calling localization returns passed attrs. */
 82 SC.Page.localization = function(attrs) { return attrs; };
 83 
 84 
 85