1 // ==========================================================================
  2 // Project:   Showcase
  3 // Copyright: ©2012 7x7 Software, Inc.
  4 // License:   Licensed under MIT license
  5 // ==========================================================================
  6 /*global Showcase */
  7 
  8 
  9 /**
 10   The source objects.
 11 */
 12 Showcase.sources = SC.Object.create(SC.CollectionContent, SC.TreeItemContent, {
 13 
 14   treeItemIsExpanded: true,
 15 
 16   treeItemIsGrouped: true,
 17 
 18   treeItemChildren: [
 19 
 20     SC.Object.create(SC.TreeItemContent, {
 21       treeItemIsExpanded: true,
 22       group: true,
 23       name: "Demos",
 24       subpath: 'demos',
 25       treeItemChildren: [
 26         SC.Object.create({
 27           appPath: 'http://demos.sproutcore.com/images_demo',
 28           name: "Automatic Image Scaling",
 29           view: 'Showcase.mainPage.demoView'
 30         }),
 31         SC.Object.create({
 32           appPath: 'http://demos.sproutcore.com/child_view_layout_demo',
 33           name: "Child View Layouts",
 34           view: 'Showcase.mainPage.demoView'
 35         }),
 36         SC.Object.create({
 37           appPath: 'http://demos.sproutcore.com/big_data_demo',
 38           name: "Displaying Big Data",
 39           view: 'Showcase.mainPage.demoView'
 40         }),
 41         SC.Object.create({
 42           appPath: 'http://demos.sproutcore.com/flot_demo',
 43           name: "Flot (or other) Integration",
 44           view: 'Showcase.mainPage.demoView'
 45         }),
 46         SC.Object.create({
 47           appPath: 'http://demos.sproutcore.com/lively_view_demo',
 48           name: "Transition Plugins",
 49           view: 'Showcase.mainPage.demoView'
 50         }),
 51         SC.Object.create({
 52           appPath: 'http://demos.sproutcore.com/color_demo',
 53           name: "Working with Color",
 54           view: 'Showcase.mainPage.demoView'
 55         })
 56       ]
 57     }),
 58 
 59     SC.Object.create(SC.TreeItemContent, {
 60       treeItemIsExpanded: true,
 61       group: true,
 62       name: "Views & Controls",
 63       subpath: 'ui',
 64       treeItemChildren: [
 65         SC.Object.create({
 66           name: "SC.ButtonView",
 67           view: 'Showcase.viewsPage.buttonViews'
 68         }),
 69         SC.Object.create({
 70           name: "SC.CheckboxView",
 71           view: 'Showcase.viewsPage.checkboxViews'
 72         }),
 73         SC.Object.create({
 74           name: "SC.ContainerView",
 75           view: 'Showcase.viewsPage.containerViews'
 76         }),
 77         SC.Object.create({
 78           name: "SC.DateFieldView",
 79           view: 'Showcase.viewsPage.dateFieldViews'
 80         }),
 81         SC.Object.create({
 82           name: "SC.DisclosureView",
 83           view: 'Showcase.viewsPage.disclosureViews'
 84         }),
 85         SC.Object.create({
 86           name: "SC.GridView",
 87           view: 'Showcase.viewsPage.gridViews'
 88         }),
 89         SC.Object.create({
 90           name: "SC.ImageButtonView",
 91           view: 'Showcase.viewsPage.imageButtonViews'
 92         }),
 93         SC.Object.create({
 94           name: "SC.ImageView",
 95           view: 'Showcase.viewsPage.imageViews'
 96         }),
 97         SC.Object.create({
 98           name: "SC.LabelView",
 99           view: 'Showcase.viewsPage.labelViews'
100         }),
101         SC.Object.create({
102           name: "SC.ListView",
103           view: 'Showcase.viewsPage.listViews'
104         }),
105         SC.Object.create({
106           name: "SC.PopUpButtonView",
107           view: 'Showcase.viewsPage.popupButtonViews'
108         }),
109         SC.Object.create({
110           name: "SC.ProgressView",
111           view: 'Showcase.viewsPage.progressViews'
112         }),
113         SC.Object.create({
114           name: "SC.RadioView",
115           view: 'Showcase.viewsPage.radioViews'
116         }),
117         SC.Object.create({
118           name: "SC.ScrollView",
119           view: 'Showcase.viewsPage.scrollViews'
120         }),
121         SC.Object.create({
122           name: "SC.SegmentedView",
123           view: 'Showcase.viewsPage.segmentedViews'
124         }),
125         SC.Object.create({
126           name: "SC.SelectView",
127           view: 'Showcase.viewsPage.selectViews'
128         }),
129         SC.Object.create({
130           name: "SC.SliderView",
131           view: 'Showcase.viewsPage.sliderViews'
132         }),
133         SC.Object.create({
134           name: "SC.SourceListView",
135           view: 'Showcase.viewsPage.sourceListViews'
136         }),
137         SC.Object.create({
138           name: "SC.SplitView",
139           view: 'Showcase.viewsPage.splitViews'
140         }),
141         SC.Object.create({
142           name: "SC.StackedView",
143           view: 'Showcase.viewsPage.stackedViews'
144         }),
145         SC.Object.create({
146           name: "SC.StaticContentView",
147           view: 'Showcase.viewsPage.staticContentViews'
148         }),
149         SC.Object.create({
150           name: "SC.TabView",
151           view: 'Showcase.viewsPage.tabViews'
152         }),
153         SC.Object.create({
154           name: "SC.TextFieldView",
155           view: 'Showcase.viewsPage.textFieldViews'
156         }),
157         SC.Object.create({
158           name: "SC.ToolbarView",
159           view: 'Showcase.viewsPage.toolbarViews'
160         }),
161         SC.Object.create({
162           name: "SC.WebView",
163           view: 'Showcase.viewsPage.webViews'
164         }),
165         SC.Object.create({
166           name: "SC.WellView",
167           view: 'Showcase.viewsPage.wellViews'
168         }),
169         SC.Object.create({
170           name: "SC.WorkspaceView",
171           view: 'Showcase.viewsPage.workspaceViews'
172         })
173       ]
174     })
175 
176     // SC.Object.create({
177     //   treeItemIsExpanded: true,
178     //   group: true,
179     //   name: "Recipes",
180     //   treeItemChildren: []
181     // }),
182 
183     // SC.Object.create({
184     //   treeItemIsExpanded: true,
185     //   group: true,
186     //   name: "Labs",
187     //   treeItemChildren: []
188     // })
189 
190   ]
191 });
192 
193 
194 /**
195   The mediating controller for the source list object and the delegate for
196   the source list.
197 */
198 Showcase.sourceTreeController = SC.TreeController.create({
199 
200   /** Display top level items as groups. */
201   treeItemIsGrouped: YES,
202 
203   /** Don't allow multiple selection. */
204   allowsMultipleSelection: NO,
205 
206   /** Don't allow empty selection. */
207   allowsEmptySelection: YES,
208 
209   /** Update the URL to match the selection. */
210   selectionDidChange: function() {
211     var content = this.get('content'),
212       selection = this.get('selection');
213 
214     if (selection && selection.firstObject()) {
215       var object = selection.firstObject(),
216         section;
217 
218       // Determine which group the selection belongs to.
219       content.get('treeItemChildren').forEach(function(group) {
220         if (group.get('treeItemChildren').indexOf(object) >= 0) {
221           section = group;
222         }
223       });
224 
225       // Set the location to be a combination of the section and the item.  We
226       // use the name in the URL rather than having to add extra properties to
227       // our source objects.
228       // Use informLocation to avoid triggering a route call, since the
229       // selection change already does what we want.
230       SC.routes.informLocation('location', section.get('subpath') + '/' + object.get('name'));
231     } else {
232       // Clear the last location
233       SC.routes.informLocation('location', null);
234     }
235   }.observes('selection')
236 
237 });
238