obj._updates = [];
obj.on_cell_changed = function(text,col,row) {
if (row > table._num_rows - 1) return;
if (col > table._num_columns - 1) return;
var decoded_text = html_entity_decode(text);
table.get_row_data(row);
if (decoded_text == table._row_data[col]) return;
if (! table._updates[row]) table._updates[row] = [];
table._updates[row][col] = decoded_text;
if (table._on_cell_change) table._on_cell_change(decoded_text,col,row);
}
obj.process_updates = function(skip_current_check) {
if (! skip_current_check) {
var col = this._grid.getCurrentColumn();
var row = this._grid.getCurrentRow();
var text = this._grid.getCellText(col,row);
this.get_row_data(row);
if ((row < this._num_rows) && this._row_data) {
var compare_text = html_entity_encode(this._row_data[col]);
if (text != compare_text) this.on_cell_changed(text,col,row);
}
}
if (this._updates.length > 0) {
window.status = 'Saving Updates...';
var request = new AW.HTTP.Request;
request.setURL(this._url);
request.setRequestMethod("POST");
request.setAsync(false);
request.setParameter("Command","UpdateRecord");
request.setParameter("Table",this._table_name);
var field_name;
var field;
var key_change_flag;
for (var update_row in this._updates) {
this.get_row_data(update_row);
if (! this._row_data) continue;
key_change_flag = false;
for (field in this._field_names) {
field_name = this._field_names[field];
if (this._updates[update_row][field] != null) {
if (this._key_fields[field]) key_change_flag = true;
request.setParameter(field_name,this._updates[update_row][field]);
}
else request.setParameter(field_name,this._row_data[field]);
}
if (key_change_flag) request.setParameter("Command","AddRecord");
request.request();
if (request._http.status != 200) {
alert('Unable to update table record: ' +
this.parse_value(request.getResponseText(),'message') +
' ('+request._http.status+')');
}
if (key_change_flag) {
request.setParameter("Command","DeleteRecord");
for (field in this._field_names)
if (this._key_fields[field])
request.setParameter(this._field_names[field],
this._row_data[field]);
request.request();
if (request._http.status != 200) {
alert('Unable to delete table record: ' +
this.parse_value(request.getResponseText(),'message') +
' ('+request._http.status+')');
}
request.setParameter("Command","UpdateRecord");
}
for (field in this._field_names) {
field_name = this._field_names[field];
if (this._updates[update_row][field] != null)
this._row_data[field] = this._updates[update_row][field];
}
this.set_row_data();
}
this._updates = [];
window.status = 'Done';
}
}
This topic is archived.