1 // ==========================================================================
  2 // Project:   SproutCore - JavaScript Application Framework
  3 // Copyright: ©2008-2011 Apple Inc. All rights reserved.
  4 // License:   Licensed under MIT license (see license.js)
  5 // ==========================================================================
  6 /**
  7   Handles propagation of a property isEditing to all child views.
  8 */
  9 SC.FormsEditMode = {
 10   
 11   /**
 12     Walks like a duck.
 13   */
 14   hasEditMode: YES,
 15   
 16   /**
 17     Whether we are in edit mode.
 18   */
 19   isEditing: NO,
 20   
 21   /**
 22     Handles changes to edit state. Alerts children.
 23   */
 24   editModeDidChange: function(){
 25     this._propagateEditMode();    
 26   }.observes("isEditing"),
 27   
 28   /**
 29     Ensures that edit mode is passed to all children.
 30   */
 31   _scfem_childViewsDidChange: function() {
 32     this._propagateEditMode();
 33   }.observes("childViews"),
 34   
 35   /**
 36     Propagates edit mode.
 37   */
 38   _propagateEditMode: function() {
 39     var isEditing = this.get("isEditing");
 40     var cv = this.get("childViews");
 41     if (!cv) { return; }
 42 
 43     var idx, len = cv.length, v;
 44     for (idx = 0; idx < len; idx++) {
 45       v = cv[idx];
 46 
 47       if (SC.typeOf(v) === SC.T_STRING || v.isClass) {
 48         return;
 49       }
 50       if (v.get("hasEditMode")) {
 51         v.set("isEditing", isEditing);
 52       }
 53     }
 54   }
 55   
 56 };
 57