Skip to content

Commit d13cde6

Browse files
committed
Merge remote branch 'brado23/grid-clean' into grid
2 parents dc4e9fb + 0e2cddb commit d13cde6

File tree

3 files changed

+41
-19
lines changed

3 files changed

+41
-19
lines changed

ui/jquery.ui.dataview.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,26 @@ $.widget( "ui.dataview", {
6161
return Math.ceil( this.totalCount / this.options.paging.limit );
6262
},
6363

64-
refresh: function( callback ) {
65-
if ( callback ) {
66-
this.element.one( "dataviewresponse", callback );
67-
}
64+
// TODO need reasonable signatures/names for callback and error.
65+
refresh: function( callback, error ) {
6866
this._trigger( "request" );
6967

7068
var request = $.extend( {}, this.options, {
7169
page: this.page()
7270
});
71+
7372
var that = this;
7473
this.options.source( request, function( data, totalCount ) {
7574
that.totalCount = parseInt(totalCount, 10);
7675
$.observable( that.result ).replaceAll( data );
7776
that._trigger( "response" );
77+
if (callback) {
78+
callback.apply(that, arguments);
79+
}
80+
}, function () {
81+
if (error) {
82+
error.apply(that, arguments);
83+
}
7884
});
7985
return this;
8086
}

ui/jquery.ui.grid.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,9 @@ $.widget( "ui.grid", {
227227
var that = this;
228228
this._container().children().each(function() {
229229
if ( $( this ).data( "grid-item" ) === item ) {
230-
$( this ).replaceWith( that._newRow(item) );
230+
// Don't replace here. Clients may be storing state relative to the element and
231+
// will be surprised if the element is replaced due to, for instance, a property change.
232+
$( this ).html( that._newRow( item ) );
231233
}
232234
});
233235
this._trigger( "refresh" );

ui/jquery.ui.observable.js

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
*
44
*/
55
(function ( $, undefined ) {
6-
$.observable = function( data, parent ) {
7-
return new observable( data, parent );
6+
$.observable = function ( data ) {
7+
return new observable( data );
88
};
99

1010
var splice = [].splice;
1111

12-
function observable( data, parent ) {
12+
var observable = $.observable.Observable = function ( data ) {
1313
this.data = data;
14-
this.parent = parent;
1514
}
15+
1616
observable.prototype = {
1717
data: null,
1818

@@ -46,36 +46,40 @@
4646
changed = true;
4747
oldValues[ key ] = oldValue;
4848
newValues[ key ] = path[ key ];
49-
this._set( key, path[ key ] );
5049
}
5150
}
5251
if ( changed ) {
53-
this._trigger( "change", {
54-
oldValues: oldValues,
55-
newValues: newValues
56-
});
52+
return this._property( oldValues, newValues );
5753
}
5854
} else if (arguments.length == 1) {
5955
return this._get( path );
6056
} else {
6157
var oldValue = this._get( path );
6258
// TODO should be strict? currently helpers are unaware of data types, don't do parsing, therefore strict comparison wouldn't be good
6359
if ( oldValue != value ) {
64-
this._set( path, value );
6560
var oldValues = {};
6661
oldValues[ path ] = oldValue;
6762
var newValues = {};
6863
newValues[ path ] = value;
69-
this._trigger( "change", {
70-
oldValues: oldValues,
71-
newValues: newValues
72-
});
64+
return this._property( oldValues, newValues );
7365
}
7466

7567
}
7668
return this;
7769
},
7870

71+
_property: function( oldValues, newValues ) {
72+
var that = this;
73+
$.each( newValues, function( path, value ) {
74+
that._set( path, value );
75+
} );
76+
77+
return this._trigger( "change", {
78+
oldValues: oldValues,
79+
newValues: newValues
80+
} );
81+
},
82+
7983
insert: function( index, items) {
8084
// insert( object )
8185
if ( $.type(index) === "object" ) {
@@ -85,6 +89,11 @@
8589
} else if ( !$.isArray( items ) ) {
8690
items = [ items ];
8791
}
92+
93+
return this._insert( index, items );
94+
},
95+
96+
_insert: function( index, items ) {
8897
// insert( index, objects )
8998
splice.apply( this.data, [ index, 0 ].concat( items ) );
9099
return this._trigger( "insert", {
@@ -135,6 +144,11 @@
135144
if ( !numToRemove ) {
136145
numToRemove = 1;
137146
}
147+
148+
return this._remove( index, numToRemove );
149+
},
150+
151+
_remove: function( index, numToRemove ) {
138152
var items = this.data.slice( index, index + numToRemove );
139153
this.data.splice( index, numToRemove );
140154
// TODO update event data, along with support for removing array of objects

0 commit comments

Comments
 (0)