Preserve pre-typed query parameters
This commit is contained in:
parent
d9dbfc8408
commit
a0f38a2d17
|
@ -1,7 +1,6 @@
|
||||||
import RestModel from 'discourse/models/rest';
|
import RestModel from 'discourse/models/rest';
|
||||||
|
|
||||||
let Query;
|
const Query = RestModel.extend({
|
||||||
Query = RestModel.extend({
|
|
||||||
dirty: false,
|
dirty: false,
|
||||||
params: {},
|
params: {},
|
||||||
results: null,
|
results: null,
|
||||||
|
@ -18,6 +17,8 @@ Query = RestModel.extend({
|
||||||
this.resetParams();
|
this.resetParams();
|
||||||
}.on('init').observes('param_names'),
|
}.on('init').observes('param_names'),
|
||||||
|
|
||||||
|
// the server uses 'qopts' and the client uses 'options' due to ActiveRecord
|
||||||
|
// freaking out if a serialized value is named 'options'
|
||||||
options: Em.computed.alias('qopts'),
|
options: Em.computed.alias('qopts'),
|
||||||
|
|
||||||
markDirty: function() {
|
markDirty: function() {
|
||||||
|
@ -29,14 +30,14 @@ Query = RestModel.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
resetParams() {
|
resetParams() {
|
||||||
let newParams = {};
|
const newParams = {};
|
||||||
let defaults = this.get('options.defaults');
|
const oldParams = this.get('params');
|
||||||
if (!defaults) {
|
const defaults = this.get('options.defaults') || {};
|
||||||
defaults = {};
|
|
||||||
}
|
|
||||||
(this.get('param_names') || []).forEach(function(name) {
|
(this.get('param_names') || []).forEach(function(name) {
|
||||||
if (defaults[name]) {
|
if (defaults[name]) {
|
||||||
newParams[name] = defaults[name];
|
newParams[name] = defaults[name];
|
||||||
|
} else if (oldParams[name]) {
|
||||||
|
newParams[name] = oldParams[name];
|
||||||
} else {
|
} else {
|
||||||
newParams[name] = '';
|
newParams[name] = '';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue