diff --git a/static/plugin_dbui/src/appform.js b/static/plugin_dbui/src/appform.js index 9367f50c04a33269205665dad7e5167de0762bac..a6501a043040d96f19f5c84e27cb30612f60d63c 100644 --- a/static/plugin_dbui/src/appform.js +++ b/static/plugin_dbui/src/appform.js @@ -284,45 +284,73 @@ App.form.FormPanel = Ext.extend(Ext.form.FormPanel, { /** * Private method to update the selected record with the value of the form - * This method have designed to handle foreign keys. + * This method have been designed to handle foreign keys, date object, .... * @param {Object} record */ updateRecord: function (record) { - var combo, - fields, - i, - item, - rec, - values; - - // Get all values from the form - values = this.getForm().getFieldValues(); - for (item in values) { - if (values.hasOwnProperty(item)) { - record.set(item, values[item]); + var combo, + field, + fields = [], + i, + items, + rec, + value; + + // get the list of dirty fields + items = this.findByType('field'); + for (i = 0; i < items.length; i += 1) { + field = items[i]; + if (field.getXType() !== 'compositefield') { + fields.push(field); } } - - // handle field embedded in composite fields - fields = this.findByType('compositefield'); - for (i = 0; i < fields.length; i += 1) { - fields[i].items.eachKey(function(key, field) { - if (field.isDirty()) { - record.set(field.getName(), field.getValue()); - } + + // include dirty fields embedded in composite fields + items = this.findByType('compositefield'); + for (i = 0; i < items.length; i += 1) { + items[i].items.eachKey(function(key, subfield) { + fields.push(subfield); }); } - - // For foreign key, the record contains the valueField - // as well as the displayField. Previous action update the valueField - // but note the display field. The next line append the displayField - fields = this.findByType('xcombobox'); + + // update the record + // take care of special treatment required by date and combobox for (i = 0; i < fields.length; i += 1) { - combo = fields[i]; - rec = combo.findRecord(combo.valueField, combo.getValue()); - record.set(combo.displayField, rec.get(combo.displayField)); + + field = fields[i]; + value = field.getValue(); + + switch (field.getXType()) { + + // We convert the date object according to a string defined + // by the Ext.form.DateField property format. + // NOTE: by default in the json encoding, the date object + // is converted as string using iso format YYYY-MM-DDTHH:MM:SS. + // However, the string expected by the database depends on + // the date type: date, datetime or time. The format of the + // Ext.form.DateField, used by the interface, is defined in the + // property format. + + case 'datefield': + value = value.format(field.format); + break; + + // For foreign key, the record contains the valueField + // as well as the displayField. The default action update + // the valueField but note the display field. + // The next lines append the displayField + + case 'xcombobox': + combo = field; + rec = combo.findRecord(combo.valueField, combo.getValue()); + record.set(combo.displayField, rec.get(combo.displayField)); + break; + } + + record.set(field.getName(), value); } + } });