This repository has been archived by the owner on Nov 12, 2018. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 48
Checkbox actions up bindings down #6
Open
c0urg3tt3
wants to merge
3
commits into
ember-cli:master
Choose a base branch
from
c0urg3tt3:checkbox-actions-up-bindings-down
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import Ember from 'ember'; | ||
|
||
export default Ember.Component.extend({ | ||
tagName: 'input', | ||
classNames: ['todo-checkbox'], | ||
attributeBindings: [ | ||
'type', | ||
'checked', | ||
'indeterminate', | ||
'disabled', | ||
'tabindex', | ||
'name', | ||
'autofocus', | ||
'required', | ||
'form' | ||
], | ||
|
||
type: 'checkbox', | ||
checked: false, | ||
disabled: false, | ||
indeterminate: false, | ||
|
||
didInsertElement() { | ||
this._super(); | ||
this.get('element').indeterminate = !!this.get('indeterminate'); | ||
}, | ||
|
||
change() { | ||
var checked = this.$().prop('checked'); | ||
// this.set('checked', checked); | ||
this.sendAction('action', checked); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
{{#if isEditing}} | ||
{{edit-todo class='edit' value=todo.title | ||
focus-out='save' | ||
insert-newline='save'}} | ||
{{edit-todo class='edit' | ||
value=title | ||
focus-out='titleChange' | ||
insert-newline='titleChange'}} | ||
{{else}} | ||
{{input type='checkbox' checked=todo.isCompleted class='toggle'}} | ||
<label {{action 'editTodo' on='doubleClick'}}>{{todo.title}}</label> | ||
{{todo-checkbox class="toggle" | ||
checked=isCompleted | ||
action='isCompletedChange'}} | ||
<label {{action 'editTodo' on='doubleClick'}}>{{title}}</label> | ||
<button {{action 'removeTodo'}} class='destroy'></button> | ||
{{/if}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
{{#each todos as |todo|}} | ||
{{todo-item todo=todo}} | ||
{{todo-item todo=todo | ||
actionPatchTodo='patchTodo' | ||
actionDeleteTodo='deleteTodo'}} | ||
{{/each}} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import Ember from 'ember'; | ||
|
||
var isEmpty = Ember.isEmpty; | ||
var filterBy = Ember.computed.filterBy; | ||
var computed = Ember.computed; | ||
var filterBy = computed.filterBy; | ||
|
||
export default Ember.Component.extend({ | ||
filtered: computed('[email protected]', 'filter', function() { | ||
|
@@ -22,19 +22,26 @@ export default Ember.Component.extend({ | |
return active === 1 ? 'item' : 'items'; | ||
}).readOnly(), | ||
|
||
allAreDone: computed('[email protected]', function (key, value) { | ||
if (arguments.length === 2) { | ||
// TODO: use action instead of a 2 way CP. | ||
var todos = this.get('active'); | ||
todos.setEach('isCompleted', value); | ||
todos.invoke('save'); | ||
return value; | ||
} else { | ||
return !isEmpty(this) && this.get('length') === this.get('completed.length'); | ||
} | ||
allAreDone: computed('[email protected]', function() { | ||
return isEmpty(this.get('active')); | ||
}), | ||
|
||
actions: { | ||
allAreDoneChange(checked) { | ||
var todos = this.get('todos').filterBy('isCompleted', !checked); | ||
todos.setEach('isCompleted', checked); | ||
todos.invoke('save'); | ||
}, | ||
|
||
patchTodo(todo, propertyName, propertyValue) { | ||
todo.set(propertyName, propertyValue); | ||
todo.save(); | ||
}, | ||
|
||
deleteTodo(todo) { | ||
todo.destroyRecord(); | ||
}, | ||
|
||
createTodo() { | ||
// Get the todo title set by the "New Todo" text field | ||
var title = this.get('newTitle'); | ||
|
@@ -61,8 +68,7 @@ export default Ember.Component.extend({ | |
var completed = this.get('completed'); | ||
|
||
completed.toArray(). // clone the array, so it is not bound while we iterate over and delete. | ||
invoke('deleteRecord'). | ||
invoke('save'); | ||
invoke('destroyRecord'); | ||
} | ||
}, | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { | ||
moduleForComponent, | ||
test | ||
} from 'ember-qunit'; | ||
|
||
moduleForComponent('todo-checkbox', { | ||
// specify the other units that are required for this test | ||
// needs: ['component:foo', 'helper:bar'] | ||
}); | ||
|
||
test('it renders', function(assert) { | ||
assert.expect(2); | ||
|
||
// creates the component instance | ||
var component = this.subject(); | ||
assert.equal(component._state, 'preRender'); | ||
|
||
// renders the component to the page | ||
this.render(); | ||
assert.equal(component._state, 'inDOM'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to call the super.