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
 10 
 11   The controller base class provides some common functions you will need
 12   for controllers in your applications, especially related to maintaining
 13   an editing context.
 14 
 15   In general you will not use this class, but you can use a subclass such
 16   as ObjectController, TreeController, or ArrayController.
 17 
 18   ## EDITING CONTEXTS
 19 
 20   One major function of a controller is to mediate between changes in the
 21   UI and changes in the model.  In particular, you usually do not want
 22   changes you make in the UI to be applied to a model object directly.
 23   Instead, you often will want to collect changes to an object and then
 24   apply them only when the user is ready to commit their changes.
 25 
 26   The editing contact support in the controller class will help you
 27   provide this capability.
 28 
 29   @extends SC.Object
 30   @since SproutCore 1.0
 31 */
 32 SC.Controller = SC.Object.extend(
 33 /** @scope SC.Controller.prototype */ {
 34 
 35   /**
 36     Makes a controller editable or not editable.  The SC.Controller class
 37     itself does not do anything with this property but subclasses will
 38     respect it when modifying content.
 39 
 40     @type Boolean
 41   */
 42   isEditable: YES,
 43 
 44   /**
 45    * Set this to YES if you are setting the controller content to a recordArray
 46    * or other content that needs to be cleaned up (with `.destroy()`) when
 47    * new content is set.
 48    */
 49   destroyContentOnReplace: NO,
 50 
 51   contentObjectDidChanged: function() {
 52     var oldContent, newContent;
 53 
 54     if (!this.get('destroyContentOnReplace')) return;
 55 
 56     oldContent = this._oldContent;
 57     newContent = this.get('content');
 58     if (oldContent && newContent !== oldContent && oldContent.destroy) {
 59       oldContent.destroy();
 60     }
 61     this._oldContent = newContent;
 62   }.observes('content')
 63 
 64 });
 65