The changed value of a multiline/text control was not saved in the
configuration database due to unable to identify the change properly. Thanks Dave for reporting. This also includes a support to use a 'text' type of preference, and show help string next to the control.pull/3/head
parent
a28df1e0a2
commit
7bce6dd903
|
@ -49,22 +49,34 @@ define(
|
|||
* We will use only one collection object to keep track of all the
|
||||
* preferences.
|
||||
*/
|
||||
var preferences = this.preferences = new (Backbone.Collection.extend({
|
||||
model: PreferenceModel,
|
||||
url: "{{ url_for('preferences.preferences') }}",
|
||||
updateAll: function() {
|
||||
// We will send only the modified data to the server.
|
||||
this.each(function(m) {
|
||||
if (m.hasChanged()) {
|
||||
m.save({
|
||||
fail: function() {
|
||||
}
|
||||
});
|
||||
var changed = {},
|
||||
preferences = this.preferences = new (Backbone.Collection.extend({
|
||||
model: PreferenceModel,
|
||||
url: "{{ url_for('preferences.preferences') }}",
|
||||
updateAll: function() {
|
||||
// We will send only the modified data to the server.
|
||||
for (var key in changed) {
|
||||
this.get(key).save();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}))(null);
|
||||
|
||||
preferences.on('reset', function() {
|
||||
// Reset the changed variables
|
||||
changed = {};
|
||||
});
|
||||
|
||||
preferences.on('change', function(m) {
|
||||
var id = m.get('id');
|
||||
if (!(id in changed)) {
|
||||
// Keep track of the original value
|
||||
changed[id] = m._previousAttributes.value;
|
||||
} else if (_.isEqual(m.get('value'), changed[id])) {
|
||||
// Remove unchanged models.
|
||||
delete changed[id];
|
||||
}
|
||||
}))(null);
|
||||
});
|
||||
|
||||
/*
|
||||
* Function: renderPreferencePanel
|
||||
|
@ -96,7 +108,9 @@ define(
|
|||
_.each(prefs, function(p) {
|
||||
|
||||
var m = preferences.get(p.id),
|
||||
f = new Backform.Field(_.extend({}, p, {id: 'value', name: 'value'})),
|
||||
f = new Backform.Field(
|
||||
_.extend({}, p, {id: 'value', name: 'value'})
|
||||
),
|
||||
cntr = new (f.get("control")) ({
|
||||
field: f,
|
||||
model: m
|
||||
|
@ -171,6 +185,8 @@ define(
|
|||
*/
|
||||
getControlMappedForType = function(p) {
|
||||
switch(p.type) {
|
||||
case 'text':
|
||||
return 'input';
|
||||
case 'boolean':
|
||||
p.options = {
|
||||
onText: '{{ _('True') }}',
|
||||
|
@ -283,6 +299,9 @@ define(
|
|||
if (!p.control) {
|
||||
p.control = getControlMappedForType(p);
|
||||
}
|
||||
if (p.help_str) {
|
||||
p.helpMessage = p.help_str;
|
||||
}
|
||||
});
|
||||
}
|
||||
d.sortable = false;
|
||||
|
|
|
@ -368,7 +368,7 @@ class Preferences(object):
|
|||
assert _type is not None, "Type for a preference can not be none!"
|
||||
assert _type in (
|
||||
'boolean', 'integer', 'numeric', 'date', 'datetime',
|
||||
'options', 'multiline', 'switch', 'node'
|
||||
'options', 'multiline', 'switch', 'node', 'text'
|
||||
), "Type can not be found in the defined list!"
|
||||
|
||||
(cat['preferences'])[name] = res = _Preference(
|
||||
|
@ -523,6 +523,7 @@ Did you forget to register it?"""
|
|||
try:
|
||||
pref.set(value)
|
||||
except Exception as e:
|
||||
current_app.logger.exeception(e)
|
||||
return False, str(e)
|
||||
|
||||
return True, None
|
||||
|
|
Loading…
Reference in New Issue