Skip to content

Commit

Permalink
Working remote source test. Currently relying on a workaround in
Browse files Browse the repository at this point in the history
datasource to refresh grid.
  • Loading branch information
jzaefferer committed Jan 30, 2011
1 parent b95f7bd commit 2629fbe
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 33 deletions.
20 changes: 14 additions & 6 deletions tests/visual/grid/datasource.js
Expand Up @@ -13,18 +13,26 @@
},
_create: function() {
$.ui.datasource.types[ this.options.type ] = this;
// TODO initialzing items[type] should probably be moved into the populate call
$.ui.datastore.main.items[ this.options.type ] = [];
// populate store with static data directly
if ($.isArray(this.options.source)) {
// TODO pass this (as the datasource instance) instead of type?
$.ui.datastore.main.populate( this.options.type );
}
$.ui.datastore.main.populate( this.options.type );
},
create: function( props ) {
this.options.source.push( props );
},
get: function( store ) {
store._populate( this.options.type, this.options.source );
if ($.isArray( this.options.source ) ) {
// TODO pass this (as the datasource instance) instead of type?
store._populate( this.options.type, this.options.source );
} else if ( $.isFunction( this.options.source ) ) {
var that = this;
this.options.source( {}, function(data) {
store._populate( that.options.type, data );
// TODO replace this workaround with proper notifications or async handling
$("table").grid("refresh");
});
}
// TODO typeof source == "string" => $.getJSON(source)?
},
save: function( items ) {
$.each( items, function( itemId, item ) {
Expand Down
5 changes: 2 additions & 3 deletions tests/visual/grid/datastore.js
Expand Up @@ -51,11 +51,10 @@
},
// TODO or rename this
_populate: function( type, items ) {
// TODO just assign items to this.items[type]?
// remove cached dataitems object
delete this.dataitems[ type ];
var local = this.items[ type ];
$.each( items, function( i, item ) {
// TODO changed this to use index for proper array indexing
// was item.guid which is not useful as array index
local[ i ] = item;
});
},
Expand Down
36 changes: 18 additions & 18 deletions tests/visual/grid/fixture.json
@@ -1,26 +1,26 @@
[
{
guid: 1,
firstName: "Scott",
lastName: "González",
country: "USA",
twitter: "scott_gonzalez",
github: "scottgonzalez"
"guid": 1,
"firstName": "Scott",
"lastName": "González",
"country": "USA",
"twitter": "scott_gonzalez",
"github": "scottgonzalez"
},
{
guid: 2,
firstName: "Richard",
lastName: "Worth",
country: "USA",
twitter: "rworth",
github: "rdworth"
"guid": 2,
"firstName": "Richard",
"lastName": "Worth",
"country": "USA",
"twitter": "rworth",
"github": "rdworth"
},
{
guid: 3,
firstName: "Jörn",
lastName: "Zaefferer",
country: "Germany",
twitter: "bassistance",
github: "jzaefferer"
"guid": 3,
"firstName": "Jörn",
"lastName": "Zaefferer",
"country": "Germany",
"twitter": "bassistance",
"github": "jzaefferer"
}
]
8 changes: 2 additions & 6 deletions tests/visual/grid/remote-source.html
Expand Up @@ -8,9 +8,6 @@
<link rel="stylesheet" href="grid.css" />
<script src="../../../jquery-1.4.4.js"></script>
<script src="../../../external/jquery.tmpl.js"></script>
<script src="../../../external/jquery.global.js"></script>
<script src="../../../external/jquery.global.de-DE.js"></script>
<script src="../../../external/jquery.global.ja-JP.js"></script>
<script src="../../../ui/jquery.ui.core.js"></script>
<script src="../../../ui/jquery.ui.widget.js"></script>
<script src="dataitem.js"></script>
Expand All @@ -24,13 +21,12 @@
$.ui.datasource({
type: "developer",
source: function(request, response) {
console.log(this, arguments);
$.getJSON("fixture.json", response);
$.getJSON("fixture.json", request, response);
}
});

$("table").grid({
type: "developers",
type: "developer",
// TODO remove this; move template generation from extractor to grid init or refresh
rowTemplate: $( "#row-tmpl" ).html(),
})
Expand Down

0 comments on commit 2629fbe

Please sign in to comment.