Commit ad8a026c authored by Pascal Hartig's avatar Pascal Hartig

Ember: jshint style

parent 55065f19
/*global Ember*/
window.Todos = Ember.Application.create();
/*global Todos Ember*/
'use strict';
Todos.TodoController = Ember.ObjectController.extend({
isEditing: false,
editTodo: function() {
editTodo: function () {
this.set('isEditing', true);
},
removeTodo: function() {
removeTodo: function () {
var todo = this.get('model');
todo.deleteRecord();
......
/*global Todos Ember*/
'use strict';
Todos.TodosController = Ember.ArrayController.extend({
createTodo: function() {
createTodo: function () {
// Get the todo title set by the "New Todo" text field
var title = this.get('newTitle');
if (!title.trim()) { return; }
......@@ -17,38 +20,38 @@ Todos.TodosController = Ember.ArrayController.extend({
this.get('store').commit();
},
clearCompleted: function() {
clearCompleted: function () {
var completed = this.filterProperty('isCompleted', true);
completed.invoke('deleteRecord');
this.get('store').commit();
},
remaining: function() {
return this.filterProperty( 'isCompleted', false ).get( 'length' );
}.property( '@each.isCompleted' ),
remaining: function () {
return this.filterProperty('isCompleted', false).get('length');
}.property('@each.isCompleted'),
remainingFormatted: function() {
remainingFormatted: function () {
var remaining = this.get('remaining');
var plural = remaining === 1 ? 'item' : 'items';
return '<strong>%@</strong> %@ left'.fmt(remaining, plural);
}.property('remaining'),
completed: function() {
completed: function () {
return this.filterProperty('isCompleted', true).get('length');
}.property('@each.isCompleted'),
hasCompleted: function() {
hasCompleted: function () {
return this.get('completed') > 0;
}.property('completed'),
allAreDone: function( key, value ) {
if ( value !== undefined ) {
this.setEach( 'isCompleted', value );
allAreDone: function (key, value) {
if (value !== undefined) {
this.setEach('isCompleted', value);
return value;
} else {
return !!this.get( 'length' ) &&
this.everyProperty( 'isCompleted', true );
return !!this.get('length') &&
this.everyProperty('isCompleted', true);
}
}.property( '@each.isCompleted' )
}.property('@each.isCompleted')
});
/*global Todos DS*/
'use strict';
Todos.Store = DS.Store.extend({
revision: 11,
adapter: 'Todos.LSAdapter'
......
/*global Todos DS Ember*/
'use strict';
Todos.Todo = DS.Model.extend({
title: DS.attr('string'),
isCompleted: DS.attr('boolean'),
todoDidChange: function() {
Ember.run.once(this, function() {
todoDidChange: function () {
Ember.run.once(this, function () {
this.get('store').commit();
});
}.observes('isCompleted', 'title')
......
Todos.Router.map(function() {
this.resource('todos', { path: '/' }, function() {
/*global Todos Ember*/
'use strict';
Todos.Router.map(function () {
this.resource('todos', { path: '/' }, function () {
this.route('active');
this.route('completed');
});
});
Todos.TodosRoute = Ember.Route.extend({
model: function() {
model: function () {
return Todos.Todo.find();
}
});
Todos.TodosIndexRoute = Ember.Route.extend({
setupController: function() {
setupController: function () {
var todos = Todos.Todo.find();
this.controllerFor('todos').set('filteredTodos', todos);
}
});
Todos.TodosActiveRoute = Ember.Route.extend({
setupController: function() {
var todos = Todos.Todo.filter(function(todo) {
setupController: function () {
var todos = Todos.Todo.filter(function (todo) {
if (!todo.get('isCompleted')) { return true; }
});
......@@ -29,8 +32,8 @@ Todos.TodosActiveRoute = Ember.Route.extend({
});
Todos.TodosCompletedRoute = Ember.Route.extend({
setupController: function() {
var todos = Todos.Todo.filter(function(todo) {
setupController: function () {
var todos = Todos.Todo.filter(function (todo) {
if (todo.get('isCompleted')) { return true; }
});
......
/*global Todos Ember*/
'use strict';
Todos.EditTodoView = Ember.TextField.extend({
classNames: ['edit'],
valueBinding: 'todo.title',
change: function() {
change: function () {
var value = this.get('value');
if (Ember.isEmpty(value)) {
......@@ -11,15 +14,15 @@ Todos.EditTodoView = Ember.TextField.extend({
}
},
focusOut: function() {
focusOut: function () {
this.set('controller.isEditing', false);
},
insertNewline: function() {
insertNewline: function () {
this.set('controller.isEditing', false);
},
didInsertElement: function() {
didInsertElement: function () {
this.$().focus();
}
});
/*global Todos Ember*/
'use strict';
Todos.TodoView = Ember.View.extend({
tagName: 'li',
classNameBindings: ['todo.isCompleted:completed', 'isEditing:editing'],
doubleClick: function(event) {
doubleClick: function () {
this.set('isEditing', true);
}
});
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