FIX: In Ember 2.0 you can't bind Query Parametrs like this

This commit is contained in:
Robin Ward 2016-11-02 16:22:52 -04:00
parent 2d126cff8f
commit 95c8d66fe0
3 changed files with 19 additions and 33 deletions

View File

@ -1,38 +1,14 @@
import { default as computed } from 'ember-addons/ember-computed-decorators';
let lastSearch; let lastSearch;
let lastOverridden;
export default Ember.Controller.extend({ export default Ember.Controller.extend({
_q: null,
searching: false, searching: false,
siteTexts: null, siteTexts: null,
preferred: false, preferred: false,
_overridden: null,
queryParams: ['q', 'overridden'], queryParams: ['q', 'overridden'],
@computed q: null,
overridden: { overridden: null,
set(value) {
if (!value || value === "false") { value = false; }
this._overridden = value;
return value;
},
get() {
return this._overridden;
}
},
@computed
q: {
set(value) {
if (Ember.isEmpty(value)) { value = null; }
this._q = value;
return value;
},
get() {
return this._q;
}
},
_performSearch() { _performSearch() {
this.store.find('site-text', this.getProperties('q', 'overridden')).then(results => { this.store.find('site-text', this.getProperties('q', 'overridden')).then(results => {
@ -46,11 +22,14 @@ export default Ember.Controller.extend({
}, },
search(overridden) { search(overridden) {
this.set('overridden', overridden);
const q = this.get('q'); const q = this.get('q');
if (q !== lastSearch || overridden) { if (q !== lastSearch || overridden !== lastOverridden) {
this.set('searching', true); this.set('searching', true);
Ember.run.debounce(this, this._performSearch, 400); Ember.run.debounce(this, this._performSearch, 400);
lastSearch = q; lastSearch = q;
lastOverridden = overridden;
} }
} }
} }

View File

@ -3,16 +3,23 @@ import { on } from "ember-addons/ember-computed-decorators";
export default Ember.Component.extend({ export default Ember.Component.extend({
tagName: 'label', tagName: 'label',
@on('didInsertElement') didInsertElement() {
_watchChanges() { this._super();
const checked = this.get('checked');
if (checked && checked !== "false") {
this.$('input').prop('checked', true);
}
// In Ember 13.3 we can use action on the checkbox `{{input}}` but not in 1.11 // In Ember 13.3 we can use action on the checkbox `{{input}}` but not in 1.11
this.$('input').on('click.d-checkbox', () => { this.$('input').on('click.d-checkbox', () => {
Ember.run.scheduleOnce('afterRender', () => this.sendAction('change', true)); Ember.run.scheduleOnce('afterRender', () => this.sendAction('change', this.$('input').prop('checked')));
}); });
}, },
@on('willDestroyElement') @on('willDestroyElement')
_stopWatching() { willDestroyElement() {
this._super();
this.$('input').off('click.d-checkbox'); this.$('input').off('click.d-checkbox');
} }
}); });

View File

@ -1,2 +1,2 @@
{{input type="checkbox" checked=checked}} <input type='checkbox'>
{{i18n label}} {{i18n label}}