Permalink
Browse files

added upsert methods to data store

  • Loading branch information...
1 parent 42e94ff commit a3d1395ba95d1a9a13943a62f9425aa5a68544fa @hofmeister committed Dec 29, 2012
Showing with 20 additions and 4 deletions.
  1. +19 −3 js/data.js
  2. +1 −1 js/widget-ext.js
View
@@ -841,22 +841,38 @@ $wb.data.ListStore = $wb.Class('ListStore',{
update:function(row) {
var i = this.indexOf(row);
if (i < 0)
- return;
+ return false;
$.extend(this._data.rows.get(i),row);
this.trigger('change');
this.trigger('updated',[[row]]);
+ return true;
},
updateAll:function(rows) {
+ var newRows = [];
for(var i = 0; i < rows.length;i++) {
var row = rows[i];
var ix = this.indexOf(row);
- if (ix < 0)
- return;
+ if (ix < 0) {
+ newRows.push(row);
+ continue;
+ }
$.extend(this._data.rows.get(ix),row);
}
this.trigger('change');
this.trigger('updated',[[row]]);
+ return newRows;
+ },
+ upsert:function(row) {
+ if (!this.update(row)) {
+ this.add(row);
+ }
+ },
+ upsertAll:function(rows) {
+ var newRows = this.updateAll(rows);
+ if (newRows.length > 0) {
+ this.addAll(newRows);
+ }
},
getByMethod:function(value,comparator) {
var i = this.getIndexByMethod(value,comparator);
View
@@ -570,7 +570,7 @@ $wb.ui.Table = $wb.Class('Table',
this._paging.bind('change',function(page) {
var rowsPerPage = this.getStore().getRowsPerPage();
this.trigger('page-change',[page,page*rowsPerPage,rowsPerPage]);
- if (!this.getStore().getSource() && this.getPaging()) {
+ if (!this.getStore().getSource()) {
this.repaintRows();
}
}.bind(this));

0 comments on commit a3d1395

Please sign in to comment.