[REM] Removed datarecord. Form save works now
bzr revid: fme@openerp.com-20110405151440-jmqja372y3rwxygw
This commit is contained in:
parent
ed1625a04c
commit
c8f4cee551
|
@ -66,14 +66,12 @@ openerp.base.DataSet = openerp.base.Controller.extend( /** @lends openerp.base.
|
|||
offset: offset,
|
||||
limit: limit
|
||||
}, function (records) {
|
||||
var r = [];
|
||||
self.offset = offset;
|
||||
self.count = records.length; // TODO: get real count
|
||||
for (var i=0; i < records.length; i++ ) {
|
||||
self.ids.push(records[i].id);
|
||||
r.push(new openerp.base.DataRecord(self.session, self.model, fields, records[i]));
|
||||
}
|
||||
callback(r);
|
||||
callback(records);
|
||||
});
|
||||
},
|
||||
fetch_ids: function (ids, fields, callback) {
|
||||
|
@ -82,20 +80,16 @@ openerp.base.DataSet = openerp.base.Controller.extend( /** @lends openerp.base.
|
|||
model: this.model,
|
||||
ids: ids,
|
||||
fields: fields
|
||||
}, function (records) {
|
||||
var r = [];
|
||||
for (var i=0; i < records.length; i++ ) {
|
||||
r.push(new openerp.base.DataRecord(self.session, self.model, fields, records[i]));
|
||||
}
|
||||
callback(r);
|
||||
});
|
||||
}, callback);
|
||||
},
|
||||
fetch_index: function (fields, callback) {
|
||||
if (_.isEmpty(this.ids)) {
|
||||
callback([]);
|
||||
} else {
|
||||
fields = fields || false;
|
||||
this.fetch_ids([this.ids[this.index]], fields, callback);
|
||||
this.fetch_ids([this.ids[this.index]], fields, function(records) {
|
||||
callback(records[0]);
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -122,29 +116,6 @@ openerp.base.DataSet = openerp.base.Controller.extend( /** @lends openerp.base.
|
|||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
openerp.base.DataRecord = openerp.base.Controller.extend({
|
||||
init: function(session, model, fields, values) {
|
||||
this._super(session, null);
|
||||
this.model = model;
|
||||
this.id = values.id || null;
|
||||
this.fields = fields;
|
||||
this.values = values;
|
||||
},
|
||||
on_change: function() {
|
||||
},
|
||||
on_reload: function() {
|
||||
},
|
||||
save: function(callback) {
|
||||
console.log("datarecord", this.values)
|
||||
this.rpc('/base/datarecord/save', {
|
||||
model: this.model,
|
||||
id: this.id,
|
||||
data: this.values
|
||||
}, callback);
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
|
|
|
@ -25,7 +25,7 @@ openerp.base.FormView = openerp.base.Controller.extend( /** @lends openerp.base
|
|||
this.widgets = {};
|
||||
this.widgets_counter = 0;
|
||||
this.fields = {};
|
||||
this.datarecord = null;
|
||||
this.datarecord = {};
|
||||
this.ready = false;
|
||||
},
|
||||
start: function() {
|
||||
|
@ -57,13 +57,15 @@ openerp.base.FormView = openerp.base.Controller.extend( /** @lends openerp.base
|
|||
}
|
||||
},
|
||||
on_record_loaded: function(record) {
|
||||
if (record.length) {
|
||||
this.datarecord = record[0];
|
||||
if (record) {
|
||||
this.datarecord = record;
|
||||
for (var f in this.fields) {
|
||||
this.fields[f].set_value(this.datarecord.values[f]);
|
||||
this.fields[f].set_value(this.datarecord[f]);
|
||||
}
|
||||
this.on_form_changed();
|
||||
this.ready = true;
|
||||
} else {
|
||||
this.log("No record received");
|
||||
}
|
||||
this.do_update_pager();
|
||||
},
|
||||
|
@ -86,18 +88,24 @@ openerp.base.FormView = openerp.base.Controller.extend( /** @lends openerp.base
|
|||
return false;
|
||||
}
|
||||
var invalid = false;
|
||||
var values = {};
|
||||
for (var f in this.fields) {
|
||||
f = this.fields[f];
|
||||
if (f.invalid) {
|
||||
invalid = true;
|
||||
} else if (f.touched) {
|
||||
this.datarecord.values[f.name] = f.get_value();
|
||||
values[f.name] = f.get_value();
|
||||
}
|
||||
}
|
||||
if (invalid) {
|
||||
this.on_invalid();
|
||||
} else {
|
||||
this.datarecord.save(this.on_saved);
|
||||
this.log("About to save", values)
|
||||
this.rpc('/base/datarecord/save', {
|
||||
model: this.model,
|
||||
id: this.datarecord.id,
|
||||
data: values
|
||||
}, this.on_saved);
|
||||
}
|
||||
},
|
||||
do_save_edit: function() {
|
||||
|
@ -144,8 +152,9 @@ openerp.base.FormView = openerp.base.Controller.extend( /** @lends openerp.base
|
|||
console.info("Form invalid");
|
||||
},
|
||||
on_saved: function(r) {
|
||||
console.log("Responsed from save", r)
|
||||
debugger;
|
||||
if (!r.result) {
|
||||
this.log("Record was not saved");
|
||||
}
|
||||
// Check response for exceptions, display error
|
||||
},
|
||||
do_search: function (domains, contexts, groupbys) {
|
||||
|
@ -384,7 +393,6 @@ openerp.base.form.Field = openerp.base.form.Widget.extend({
|
|||
if (node.attrs.nolabel != '1' && this.colspan > 1) {
|
||||
this.colspan--;
|
||||
}
|
||||
// this.datarecord = this.view.datarecord ??
|
||||
this.field = view.fields_view.fields[node.attrs.name];
|
||||
this.string = node.attrs.string || this.field.string;
|
||||
this.help = node.attrs.help || this.field.help;
|
||||
|
|
|
@ -72,14 +72,9 @@ openerp.base.ListView = openerp.base.Controller.extend({
|
|||
this.view_manager.sidebar.load_multi_actions();
|
||||
},
|
||||
do_fill_table: function(records) {
|
||||
this.log("do_fill_table");
|
||||
|
||||
this.$table
|
||||
.clearGridData()
|
||||
.addRowData('id', _.map(records, function (record) {
|
||||
return record.values;
|
||||
}));
|
||||
|
||||
.addRowData('id', records);
|
||||
},
|
||||
do_show: function () {
|
||||
// TODO: re-trigger search
|
||||
|
|
|
@ -202,26 +202,6 @@ $(document).ready(function () {
|
|||
});
|
||||
dataset.fetch();
|
||||
});
|
||||
asyncTest("Data records", function () {
|
||||
var dataset = new openerp.base.DataSet({
|
||||
rpc: function (url, _params, on_success) {
|
||||
equal('/base/dataset/find', url);
|
||||
_.delay(on_success, 0, [
|
||||
{id: 1, sequence: 3, name: "dummy", age: 42},
|
||||
{id: 5, sequence: 7, name: "whee", age: 55}
|
||||
]);
|
||||
}
|
||||
});
|
||||
dataset.on_fetch.add(function (records) {
|
||||
equal(records.length, 2, "I loaded two virtual records");
|
||||
var d1 = records[0],
|
||||
d2 = records[1];
|
||||
ok(d1 instanceof openerp.base.DataRecord);
|
||||
ok(d2 instanceof openerp.base.DataRecord);
|
||||
start();
|
||||
});
|
||||
dataset.fetch();
|
||||
});
|
||||
|
||||
var dataset;
|
||||
module("set", {
|
||||
|
|
Loading…
Reference in New Issue