Commit 8da22268 authored by Stas SUȘCOV's avatar Stas SUȘCOV

Update todos controller to initalize secondary views upon content attribute setup.

TODO: Refactor this to be part of `ApplicationView` as child views.
parent 43d57107
define('app/controllers/todos', [ define('app/controllers/todos', [
'app/controllers/entries',
'app/views/items',
'app/views/stats', 'app/views/stats',
'app/views/filters', 'app/views/filters',
'app/views/clear_button', 'app/views/clear_button'
], ],
/** /**
* Todos controller * Todos controller
...@@ -11,24 +9,23 @@ define('app/controllers/todos', [ ...@@ -11,24 +9,23 @@ define('app/controllers/todos', [
* Main controller inherits the `Entries` class * Main controller inherits the `Entries` class
* which is an `ArrayProxy` linked with the `Store` model * which is an `ArrayProxy` linked with the `Store` model
* *
* @param Class Entries, the Entries class
* @param Class ItemsView, items view class
* @param Class StatsView, stats view class * @param Class StatsView, stats view class
* @param Class FiltersView, filters view class * @param Class FiltersView, filters view class
* @param Class ClearBtnView, clear button view class * @param Class ClearBtnView, clear button view class
* @returns Class * @returns Class
*/ */
function( Entries, ItemsView, StatsView, FiltersView, ClearBtnView ) { function( StatsView, FiltersView, ClearBtnView ) {
return Entries.extend({ return Ember.Controller.extend({
viewsLoaded: false,
// New todo input // New todo input
InputView: Ember.TextField.extend({ InputView: Ember.TextField.extend({
placeholder: 'What needs to be done?', placeholder: 'What needs to be done?',
elementId: 'new-todo', elementId: 'new-todo',
// Bind this to newly inserted line
insertNewline: function() { insertNewline: function() {
var value = this.get( 'value' ); var value = this.get( 'value' );
if ( value ) { if ( value ) {
this.get( 'controller' ).createNew( value ); this.get( 'content' ).createNew( value );
this.set( 'value', '' ); this.set( 'value', '' );
} }
} }
...@@ -36,33 +33,36 @@ define('app/controllers/todos', [ ...@@ -36,33 +33,36 @@ define('app/controllers/todos', [
// Handle visibility of some elements as items totals change // Handle visibility of some elements as items totals change
visibilityObserver: function() { visibilityObserver: function() {
$( '#main, #footer' ).toggle( !!this.get( 'total' ) ); $( '#main, #footer' ).toggle( !!this.getPath( 'content.total' ) );
}.observes( 'total' ), }.observes( 'content.total' ),
// Checkbox to mark all todos done. // Checkbox to mark all todos done.
MarkAllChkbox: Ember.Checkbox.extend({ MarkAllChkbox: Ember.Checkbox.extend({
elementId: 'toggle-all', elementId: 'toggle-all',
checkedBinding: 'controller.allAreDone' checkedBinding: 'content.allAreDone'
}), }),
// Activates the views and other initializations // Activates secondary views when content was set
init: function() { initViews: function() {
this._super(); var entries = this.get( 'content' );
if ( this.get( 'viewsLoaded' ) || Ember.none( entries ) )
return;
this.set( 'inputView', this.InputView.create({ controller: this }) ); this.set( 'inputView', this.InputView.create({ content: entries }) );
this.set( 'markAllChkbox', this.MarkAllChkbox.create({ controller: this }) ); this.set( 'markAllChkbox', this.MarkAllChkbox.create({ content: entries }) );
this.set( 'itemsView', ItemsView.create({ controller: this }) ); // this.set( 'itemsView', ItemsView.create({ controller: this }) );
this.set( 'statsView', StatsView.create({ controller: this }) ); this.set( 'statsView', StatsView.create({ controller: entries }) );
this.set( 'filtersView', FiltersView.create() ); this.set( 'filtersView', FiltersView.create() );
this.set( 'clearBtnView', ClearBtnView.create({ controller: this }) ); this.set( 'clearBtnView', ClearBtnView.create({ controller: entries }) );
this.get( 'inputView' ).appendTo( 'header' ); this.get( 'inputView' ).appendTo( 'header' );
this.get( 'markAllChkbox' ).appendTo( '#main' ); this.get( 'markAllChkbox' ).appendTo( '#main' );
this.get( 'itemsView' ).appendTo( '#main' ); // this.get( 'itemsView' ).appendTo( '#main' );
this.get( 'statsView' ).appendTo( '#footer' ); this.get( 'statsView' ).appendTo( '#footer' );
this.get( 'filtersView' ).appendTo( '#footer' ); this.get( 'filtersView' ).appendTo( '#footer' );
this.get( 'clearBtnView' ).appendTo( '#footer' ); this.get( 'clearBtnView' ).appendTo( '#footer' );
} }.observes( 'content' )
}); });
} }
); );
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment