Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Repeater multiple view config #845

Merged
merged 1 commit into from
Nov 14, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 49 additions & 22 deletions dev/dev.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,21 @@
});
})();
require(['jquery', '../data', 'fuelux/all'], function($, data){
//REPEATER
var delays = ['300', '600', '900', '1200'];
var $myRepeater = $('#myRepeater');
// simulate network latency
var loadDelays = ['300', '600', '900', '1200'];

// list view setup
var list = function(options, callback){

// build dataSource based with options
var resp = {
count: data.repeater.listData.length,
items: [],
page: options.pageIndex
};
var i, l;

// get start and end limits for JSON
var i, l;
resp.pages = Math.ceil(resp.count/(options.pageSize || 50));

i = options.pageIndex * (options.pageSize || 50);
Expand All @@ -59,12 +62,12 @@
resp.start = i + 1;
resp.end = l;

// setup columns for list view
resp.columns = [
{
label: 'Common Name',
property: 'commonName',
sortable: true,
className: 'rover'
sortable: true
},
{
label: 'Latin Name',
Expand All @@ -74,8 +77,7 @@
{
label: 'Appearance',
property: 'appearance',
sortable: true,
className: 'blub'
sortable: true
},
{
label: 'Sound',
Expand All @@ -84,66 +86,88 @@
}
];

// add sample items to datasource
for(i; i<l; i++){
// from data.js
resp.items.push(data.repeater.listData[i]);
}

//if(options.search){
//resp.items = [];
//}

// call and simulate latency
setTimeout(function(){
callback(resp);
}, delays[Math.floor(Math.random() * 4)]);
}, loadDelays[Math.floor(Math.random() * 4)]);
};


// thumbnail view setup
var thumbnail = function(options, callback){
var categories = ['abstract', 'animals', 'business', 'cats', 'city', 'food', 'nature', 'technics', 'transport'];
var sampleImageCategories = ['abstract', 'animals', 'business', 'cats', 'city', 'food', 'nature', 'technics', 'transport'];
var numItems = 200;

// build dataSource based with options
var resp = {
count: numItems,
items: [],
pages: (Math.ceil(numItems/(options.pageSize || 30))),
page: options.pageIndex
};
var i, l;

// get start and end limits for JSON
var i, l;
i = options.pageIndex * (options.pageSize || 30);
l = i + (options.pageSize || 30);
resp.start = i + 1;
resp.end = l;

// add sample items to datasource
for(i; i<l; i++){
resp.items.push({
name: ('Thumbnail ' + (i + 1)),
src: 'http://lorempixel.com/65/75/' + categories[Math.floor(Math.random() * 9)] + '/?_=' + i
src: 'http://lorempixel.com/65/65/' + sampleImageCategories[Math.floor(Math.random() * 9)] + '/?_=' + i
});
}

//if(options.search){
//resp.items = [];
//}

// call and simulate latency
setTimeout(function(){
callback(resp);
}, delays[Math.floor(Math.random() * 4)]);
}, loadDelays[Math.floor(Math.random() * 4)]);
};

$myRepeater.repeater({
// initialize repater
$('#myRepeater').repeater({
dataSource: function(options, callback){
if(options.view==='list'){
//you can check view name here, and call separate functions...
if(options.view==='list.view1'){
list(options, callback);
}else if(options.view==='thumbnail'){
thumbnail(options, callback);
}
},
list_highlightSortedColumn: true,
list_selectable: 'multi',
list_noItemsHTML: 'no items found',
list_infiniteScroll: true,
thumbnail_noItemsHTML: 'no items found',
thumbnail_infiniteScroll: { hybrid: true },
thumbnail_selectable: true
views: {
//you can go with just the view name
'view1': {
list_selectable: true
},
//this syntax is also supported (makes it possible to do 'list' and 'thumbnail' this way)
'list.view2': {
//...or you can do this! :)
dataSource: function(options, callback){
list(options, callback);
},
list_infiniteScroll: true,
list_highlightSortedColumn: true
}
}
});
});
</script>
Expand Down Expand Up @@ -184,11 +208,14 @@
</div>
<div class="btn-group repeater-views" data-toggle="buttons">
<label class="btn btn-default active">
<input name="repeaterViews" type="radio" value="list"><span class="glyphicon glyphicon-list"></span>
<input name="repeaterViews" type="radio" value="list.view1"><span class="glyphicon glyphicon-list"></span>
</label>
<label class="btn btn-default">
<input name="repeaterViews" type="radio" value="thumbnail"><span class="glyphicon glyphicon-th"></span>
<input name="repeaterViews" type="radio" value="list.view2"><span class="glyphicon glyphicon-list"></span>
</label>
<!--<label class="btn btn-default">-->
<!--<input name="repeaterViews" type="radio" value="thumbnail"><span class="glyphicon glyphicon-th"></span>-->
<!--</label>-->
</div>
</div>
</div>
Expand Down
34 changes: 17 additions & 17 deletions js/repeater-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

$.fn.repeater.Constructor.prototype.list_highlightColumn = function(index, force){
var tbody = this.$canvas.find('.repeater-list tbody');
if(this.options.list_highlightSortedColumn || force){
if(this.viewOptions.list_highlightSortedColumn || force){
tbody.find('td.sorted').removeClass('sorted');
tbody.find('tr').each(function(){
var col = $(this).find('td:nth-child(' + (index + 1) + ')');
Expand Down Expand Up @@ -70,7 +70,7 @@
};

$.fn.repeater.Constructor.prototype.list_setSelectedItems = function(items, force){
var selectable = this.options.list_selectable;
var selectable = this.viewOptions.list_selectable;
var self = this;
var data, i, $item, l;

Expand Down Expand Up @@ -145,9 +145,9 @@
});

//EXTENSION DEFINITION
$.fn.repeater.views.list = {
$.fn.repeater.viewTypes.list = {
cleared: function(helpers, callback){
if(this.options.list_columnSyncing){
if(this.viewOptions.list_columnSyncing){
this.list_sizeHeadings();
}
callback();
Expand All @@ -167,7 +167,7 @@
callback();
},
selected: function(helpers, callback){
var infScroll = this.options.list_infiniteScroll;
var infScroll = this.viewOptions.list_infiniteScroll;
var opts;

this.list_firstRender = true;
Expand All @@ -181,15 +181,15 @@
callback();
},
resize: function(helpers, callback){
if(this.options.list_columnSyncing){
if(this.viewOptions.list_columnSyncing){
this.list_sizeHeadings();
}
callback();
},
renderer: { //RENDERING REPEATER-LIST, REPEATER-LIST-WRAPPER, AND TABLE
complete: function(helpers, callback){
var $sorted;
if(this.options.list_columnSyncing){
if(this.viewOptions.list_columnSyncing){
this.list_sizeHeadings();
this.list_positionHeadings();
}
Expand All @@ -208,7 +208,7 @@
}else{
$item = $('<div class="repeater-list" data-preserve="shallow"><div class="repeater-list-wrapper" data-infinite="true" data-preserve="shallow"><table aria-readonly="true" class="table" data-container="true" data-preserve="shallow" role="grid"></table></div></div>');
$item.find('.repeater-list-wrapper').on('scroll.fu.repeaterList', function(){
if(self.options.list_columnSyncing){
if(self.viewOptions.list_columnSyncing){
self.list_positionHeadings();
}
});
Expand All @@ -222,7 +222,7 @@
var self = this;
var i, l, newWidth, taken;

if(!this.options.list_columnSizing || this.list_columnsSame){
if(!this.viewOptions.list_columnSizing || this.list_columnsSame){
callback();
}else{
i = 0;
Expand Down Expand Up @@ -327,7 +327,7 @@
$spans.removeClass(chevUp).addClass(chevDown);
self.list_sortDirection = 'desc';
}else{
if(!self.options.list_sortClearing){
if(!self.viewOptions.list_sortClearing){
$spans.removeClass(chevDown).addClass(chevUp);
self.list_sortDirection = 'asc';
}else{
Expand Down Expand Up @@ -382,7 +382,7 @@
if(helpers.data.items.length<1){
obj.skipNested = true;
$empty = $('<tr class="empty"><td colspan="' + this.list_columns.length + '"></td></tr>');
$empty.find('td').append(this.options.list_noItemsHTML);
$empty.find('td').append(this.viewOptions.list_noItemsHTML);
$item.append($empty);
}

Expand All @@ -398,8 +398,8 @@
if(helpers.item!==undefined){
obj.item = helpers.item;
}
if(this.options.list_rowRendered){
this.options.list_rowRendered(obj, function(){
if(this.viewOptions.list_rowRendered){
this.viewOptions.list_rowRendered(obj, function(){
callback();
});
}else{
Expand All @@ -410,7 +410,7 @@
var $item = $('<tr data-container="true"></tr>');
var self = this;

if(this.options.list_selectable){
if(this.viewOptions.list_selectable){
$item.addClass('selectable');
$item.attr('tabindex', 0); // allow items to be tabbed to / focused on
$item.data('item_data', helpers.subset[helpers.index]);
Expand All @@ -421,7 +421,7 @@
$row.find('.repeater-list-check').remove();
self.$element.trigger('deselected.fu.repeaterList', $row);
}else{
if(self.options.list_selectable!=='multi'){
if(self.viewOptions.list_selectable!=='multi'){
self.$canvas.find('.repeater-list-check').remove();
self.$canvas.find('.repeater-list tbody tr.selected').each(function(){
$(this).removeClass('selected');
Expand Down Expand Up @@ -457,8 +457,8 @@
if(helpers.item!==undefined){
obj.item = helpers.item;
}
if(this.options.list_columnRendered){
this.options.list_columnRendered(obj, function(){
if(this.viewOptions.list_columnRendered){
this.viewOptions.list_columnRendered(obj, function(){
callback();
});
}else{
Expand Down
16 changes: 8 additions & 8 deletions js/repeater-thumbnail.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
};

$.fn.repeater.Constructor.prototype.thumbnail_setSelectedItems = function(items, force){
var selectable = this.options.thumbnail_selectable;
var selectable = this.viewOptions.thumbnail_selectable;
var self = this;
var i, $item, l;

Expand Down Expand Up @@ -94,9 +94,9 @@
});

//EXTENSION DEFINITION
$.fn.repeater.views.thumbnail = {
$.fn.repeater.viewTypes.thumbnail = {
selected: function(helpers, callback){
var infScroll = this.options.thumbnail_infiniteScroll;
var infScroll = this.viewOptions.thumbnail_infiniteScroll;
var opts;
if(infScroll){
opts = (typeof infScroll === 'object') ? infScroll : {};
Expand All @@ -118,7 +118,7 @@
if(helpers.data.items.length<1){
obj.skipNested = true;
$empty = $('<div class="empty"></div>');
$empty.append(this.options.thumbnail_noItemsHTML);
$empty.append(this.viewOptions.thumbnail_noItemsHTML);
$item.append($empty);
}else{
$item.find('.empty:first').remove();
Expand All @@ -132,7 +132,7 @@
container: helpers.container,
itemData: helpers.subset[helpers.index]
};
var selectable = this.options.thumbnail_selectable;
var selectable = this.viewOptions.thumbnail_selectable;
var selected = 'selected';
var self = this;
var $item;
Expand All @@ -159,8 +159,8 @@
});
}
}
if(this.options.thumbnail_itemRendered){
this.options.thumbnail_itemRendered(obj, function(){
if(this.viewOptions.thumbnail_itemRendered){
this.viewOptions.thumbnail_itemRendered(obj, function(){
callback();
});
}else{
Expand Down Expand Up @@ -191,7 +191,7 @@
}
return str;
};
callback({ item: template(this.options.thumbnail_template) });
callback({ item: template(this.viewOptions.thumbnail_template) });
},
repeat: 'data.items'
}
Expand Down
Loading