72920506 by Adam Heath

Split files.

1 parent bbb7f7fb
{
"directory": "src/lib/bower"
}
......@@ -11,7 +11,7 @@ module.exports = function(grunt) {
browserOptions: {
},
model: [
'src/scripts/solr-search/model/**/*.js',
'src/scripts/solr/model/**/*.js',
],
};
/*
......
define(function(require) {
'use strict';
var Backbone = require('backbone');
var Ordering = Backbone.Model.extend({
defaults: {
value: null,
items: new Backbone.Collection(),
},
initialize: function(data, options) {
if (this.get('value') === null) {
var firstItem = this.get('items').at(0);
if (firstItem) {
this.set('value', firstItem.get('value'));
}
}
},
parse: function(data) {
var result = _.clone(data);
if (result.items && !(result.items instanceof Backbone.Collection)) {
result.items = new Backbone.Collection(result.items, {parse: true});
}
return result;
},
});
return Ordering;
});
define(function(require) {
'use strict';
var Backbone = require('backbone');
function stepFalse(e) {
e.preventDefault();
return false;
}
var Pagination = Backbone.Model.extend({
defaults: {
currentPage: 1,
hasNext: false,
hasNextJumpPage: false,
hasPrevious: false,
hasPreviousJumpPage: false,
nextJumpPage: undefined,
nextPage: undefined,
pages: [],
pageJump: 5,
pageSize: 10,
previousJumpPage: undefined,
previousPage: undefined,
totalCount: 0,
totalPages: 0,
},
initialize: function(data, options) {
var buildPages = function buildPages() {
var currentPage = parseInt(this.get('currentPage'));
var pageSize = parseInt(this.get('pageSize'));
var totalCount = parseInt(this.get('totalCount'));
if (!currentPage || !pageSize || !totalCount) {
return;
}
var pages = [];
var totalPages = Math.floor((totalCount + pageSize - 1) / pageSize);
function addPage(self, i) {
pages.push({
current: i === currentPage,
jump: function() {
self.set('currentPage', i);
return true;
},
number: i,
});
}
var startAt = currentPage - 4, endAt = currentPage + 5;
if (startAt < 1) {
endAt += (1 - startAt);
}
if (endAt > totalPages) {
startAt -= endAt - totalPages - 1;
endAt = totalPages + 1;
}
if (startAt < 1) {
startAt = 1;
}
if (endAt - startAt < 9) {
/* global console:false */
console.log('foo');
}
for (var i = startAt; i < endAt; i++) {
if (i > 0 && i <= totalPages) {
addPage(this, i);
}
}
var hasPrevious = currentPage > 1;
var hasNext = currentPage < totalPages;
var pageJump = this.get('pageJump');
var nextJumpPage, previousJumpPage, hasNextJump, hasPreviousJump;
if (pageJump) {
nextJumpPage = currentPage + pageJump;
previousJumpPage = currentPage - pageJump;
hasNextJump = nextJumpPage < totalPages;
hasPreviousJump = previousJumpPage > 0;
} else {
hasNextJump = false;
hasPreviousJump = false;
}
this.set({
hasNext: hasNext,
hasNextJump: hasNextJump,
hasPrevious: hasPrevious,
hasPreviousJump: hasPreviousJump,
nextJumpPage: hasNextJump ? nextJumpPage : undefined,
nextPage: hasNext ? currentPage + 1 : undefined,
pages: pages,
previousJumpPage: hasNextJump ? previousJumpPage : undefined,
previousPage: hasPrevious ? currentPage - 1 : undefined,
totalPages: totalPages,
});
};
this.on('change:pageSize change:currentPage change:totalCount', buildPages, this);
var installActions = _.bind(function installActions(eventName, nextName, hasNextName, previousName, hasPreviousName, pageCount) {
this.on(eventName, function() {
var hasNext = this.get(hasNextName);
var hasPrevious = this.get(hasPreviousName);
var next, previous;
if (hasNext) {
next = _.bind(function(e) {
e.preventDefault();
this.set('currentPage', this.get('currentPage') + pageCount);
return false;
}, this);
} else {
next = stepFalse;
}
if (hasPrevious) {
previous = _.bind(function(e) {
e.preventDefault();
this.set('currentPage', this.get('currentPage') - pageCount);
return false;
}, this);
} else {
previous = stepFalse;
}
this.set(nextName, next);
this.set(previousName, previous);
}, this);
this[nextName] = _.bind(function() {
return this.get(nextName)();
}, this);
this[previousName] = _.bind(function() {
return this.get(previousName)();
}, this);
}, this);
this.on('change:pageJump', function() {
var pageJump = this.get('pageJump');
installActions('change:hasNextJump change:hasPreviousJump', 'nextJump', 'hasNextJump', 'previousJump', 'hasPreviousJump', pageJump);
}, this);
installActions('change:hasNext change:hasPrevious', 'next', 'hasNext', 'previous', 'hasPrevious', 1);
buildPages.apply(this);
this.trigger('change:pageJump');
return Pagination.__super__.initialize.apply(this, arguments);
}
});
return Pagination;
});
define(function(require) {
'use strict';
var Backbone = require('backbone');
var QueryTextField = Backbone.Model.extend({
defaults: {
formName: null,
name: null,
queries: [],
fields: null,
multi: false
},
});
return QueryTextField;
});