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   Used for contentIndexDisclosureState().  Indicates open branch node.
 10 
 11   @type Number
 12   @constant
 13 */
 14 SC.BRANCH_OPEN = 0x0011;
 15 
 16 /**
 17   Used for contentIndexDisclosureState().  Indicates closed branch node.
 18 
 19   @type Number
 20   @constant
 21 */
 22 SC.BRANCH_CLOSED = 0x0012;
 23 
 24 /**
 25   Used for contentIndexDisclosureState().  Indicates leaf node.
 26 
 27   @type Number
 28   @constant
 29 */
 30 SC.LEAF_NODE = 0x0020;
 31 
 32 /**
 33   @namespace
 34 
 35   This mixin provides standard methods used by a CollectionView to provide
 36   additional meta-data about content in a collection view such as selection
 37   or enabled state.
 38 
 39   You can apply this mixin to a class that you set as a delegate or to the
 40   object you set as content.
 41 
 42   @since SproutCore 1.0
 43 */
 44 SC.CollectionContent = {
 45 
 46   /**
 47     Used to detect the mixin by SC.CollectionView
 48 
 49     @type Boolean
 50   */
 51   isCollectionContent: YES,
 52 
 53   /**
 54     Return YES if the content index should be selected.  Default behavior
 55     looks at the selection property on the view.
 56 
 57     @param {SC.CollectionView} collection the collection view
 58     @param {SC.Array} content the content object
 59     @param {Number} idx the content index
 60     @returns {Boolean} YES, NO, or SC.MIXED_STATE
 61   */
 62   contentIndexIsSelected: function(collection, content, idx) {
 63     var sel = collection.get('selection');
 64     return sel ? sel.contains(content, idx) : NO ;
 65   },
 66 
 67   /**
 68     Returns YES if the content index should be enabled.  Default looks at the
 69     isEnabled state of the collection view.
 70 
 71     @param {SC.CollectionView} collection the collection view
 72     @param {SC.Array} content the content object
 73     @param {Number} idx the content index
 74     @returns {Boolean} YES, NO, or SC.MIXED_STATE
 75   */
 76   contentIndexIsEnabled: function(collection, content, idx) {
 77     return collection.get('isEnabled');
 78   },
 79 
 80   // ..........................................................
 81   // GROUPING
 82   //
 83 
 84   /**
 85     Optionally return an index set containing the indexes that may be group
 86     views.  For each group view, the delegate will actually be asked to
 87     confirm the view is a group using the contentIndexIsGroup() method.
 88 
 89     If grouping is not enabled, return null.
 90 
 91     @param {SC.CollectionView} collection the calling view
 92     @param {SC.Array} content the content object
 93     @return {SC.IndexSet}
 94   */
 95   contentGroupIndexes: function(collection, content) {
 96     return null;
 97   },
 98 
 99   /**
100     Returns YES if the item at the specified content index should be rendered
101     using the groupExampleView instead of the regular exampleView.  Note that
102     a group view is different from a branch/leaf view.  Group views often
103     appear with different layout and a different look and feel.
104 
105     Default always returns NO.
106 
107     @param {SC.CollectionView} collection the collection view
108     @param {SC.Array} content the content object
109     @param {Number} idx the content index
110     @returns {Boolean} YES, NO, or SC.MIXED_STATE
111   */
112   contentIndexIsGroup: function(collection, content, idx) {
113     return NO ;
114   },
115 
116   // ..........................................................
117   // OUTLINE VIEWS
118   //
119 
120   /**
121     Returns the outline level for the item at the specified index.  Can be
122     used to display hierarchical lists.
123 
124     Default always returns -1 (no outline).
125 
126     @param {SC.CollectionView} collection the collection view
127     @param {SC.Array} content the content object
128     @param {Number} idx the content index
129     @returns {Boolean} YES, NO, or SC.MIXED_STATE
130   */
131   contentIndexOutlineLevel: function(collection, content, idx) {
132     return -1;
133   },
134 
135   /**
136     Returns a constant indicating the disclosure state of the item.  Must be
137     one of SC.BRANCH_OPEN, SC.BRANCH_CLOSED, SC.LEAF_NODE.  If you return one
138     of the BRANCH options then the item may be rendered with a disclosure
139     triangle open or closed.  If you return SC.LEAF_NODe then the item will
140     be rendered as a leaf node.
141 
142     Default returns SC.LEAF_NODE.
143 
144     @param {SC.CollectionView} collection the collection view
145     @param {SC.Array} content the content object
146     @param {Number} idx the content index
147     @returns {Boolean} YES, NO, or SC.MIXED_STATE
148   */
149   contentIndexDisclosureState: function(collection, content, idx) {
150     return SC.LEAF_NODE;
151   },
152 
153   /**
154     Called to expand a content index item if it is currently in a closed
155     disclosure state.  The default implementation does nothing.
156 
157     @param {SC.CollectionView} collection the collection view
158     @param {SC.Array} content the content object
159     @param {Number} idx the content index
160     @returns {void}
161   */
162   contentIndexExpand: function(collection, content, idx) {
163     SC.Logger.log('contentIndexExpand(%@, %@, %@)'.fmt(collection, content, idx));
164   },
165 
166   /**
167     Called to collapse a content index item if it is currently in an open
168     disclosure state.  The default implementation does nothing.
169 
170     @param {SC.CollectionView} collection the collection view
171     @param {SC.Array} content the content object
172     @param {Number} idx the content index
173     @returns {void}
174   */
175   contentIndexCollapse: function(collection, content, idx) {
176     SC.Logger.log('contentIndexCollapse(%@, %@, %@)'.fmt(collection, content, idx));
177   }
178 
179 };
180