1
0
Fork 0

Merge branch 'devel' of https://github.com/triAGENS/ArangoDB into devel

This commit is contained in:
beckmann73 2013-02-28 13:33:32 +01:00
commit 991d93d8bb
6 changed files with 72 additions and 143 deletions

View File

@ -1,138 +1,55 @@
(function($) {
$.fn.pagination = function(o) {
var prevText = o.prevText ? o.prevText : '<<';
var nextText = o.nextText ? o.nextText : '>>';
var moreText = o.moreText ? o.moreText :'...';
var isDisplayFirst = o.isDisplayFirst || true;
var isDisplayLast = o.isDisplayLast || true;
var current = o.current ? o.current : 1;
var count = o.count ? o.count : 0;
var link = o.link ? o.link : '#?page={p}';
var displayCount = o.displayCount ? o.displayCount : 7;
var me = $(this);
console.log(current);
me.initPagination = function () {
// 创建 ul
var ul = $('<ul>');
// 获取 页码数组
var disp = me.computeDisplayPageNumber();
for(var i=0;i<disp.length;i++){
// 创建 li
var li = $('<li>');
// 创建 a
var a = $("<a>");
// 计算超链接中的页码
var p=0;
if(disp[i]==moreText){
if(i==2){
p=disp[i+1]-1;
}else if(i==displayCount|| i==displayCount+1){
p=disp[i-1]+1;
}
}else if(disp[i]==prevText){
p = current-1;
}else if(disp[i]==nextText){
p = current+1;
}else{
p = disp[i];
}
// 超链接
var pLink = link.replace('{p}',p);
// 设置a的超链接和显示文本
a.attr("href",pLink).text(disp[i]);
// 为li添加a
li.append(a);
// 如果是当前页,设置样式
if(current ==disp[i]){
li.addClass('active');
}
// 向 ul 添加这个li
ul.append(li);
}
// 添加ul
me.append(ul);
};
me.computeDisplayPageNumber = function(){
var disp = new Array();
var j = 0;
// 如果当前页不是第一页,则添加 prevText
if(current>1){
disp[j] = prevText;
j++;
}
// 添加具体页码的逻辑
if(count <= 1){
// 如果总页数小于等于1不添加任何页码
return disp;
}else if(count <= displayCount){
// 如果总页数小于显示页数则添加页码——1至count
for(var i=1;i<=count;i++){
disp[j] = i;
j++;
}
}else if(displayCount - current >=2){
// (当前页在前端)如果显示页数 - 当前页 大于等于2则添加页码——1至displayCount后面再添加一个moreText后面再添加一个末页页码
for(var i=1;i<displayCount;i++){
disp[j] = i;
j++;
}
disp[j] = moreText;
j++;
if(isDisplayLast){
disp[j] = count;
j++;
}
}else if(count - current <= (displayCount-1)/2){
// (当前页在后端)如果总页数 - 当前页 小于等于(displayCount-1)/2则先添加一个首页页码再添加一个moreText再添加页码——count-(displayCount-2)至count
if(isDisplayFirst){
disp[j] = 1;
j++;
}
disp[j] = moreText;
j++;
for(var i=1;i<displayCount;i++){
disp[j] = count - (displayCount -i-1);
j++;
}
}else{
// (当前页在中间)其他的情况则先添加一个首页页码再添加一个moreText再添加当前页左边(displayCount-1)/2-1个页码再添加当前页码再添加一个moreText再添加末页页码
if(isDisplayFirst){
disp[j] = 1;
j++;
}
disp[j] = moreText;
j++;
var alignLeftCount = (displayCount-1)/2-1;
for(var i=0;i<alignLeftCount;i++){
disp[j] = current-alignLeftCount+i;
j++;
}
disp[j] = current;
j++;
var alignRightCount = alignLeftCount;
for(var i=0;i<alignRightCount;i++){
disp[j] = current+i+1;
j++;
}
disp[j] = moreText;
j++;
if(isDisplayLast){
disp[j] = count;
j++;
}
}
// 如果当前页不是最后一页,则添加 nextText
if(current != count){
disp[j] = nextText;
j++;
}
return disp;
};
me.initPagination();
};
})(jQuery);
/**
* * bootstrap-pagination.js by takumakei (http://github.com/takumakei)
* * Copyright 2012 takumakei.
* * http://www.apache.org/licenses/LICENSE-2.0.txt
* */
(function ($) {
'use strict';
function defaultClick(i) {}
function stopPropagation(event) { event.stopPropagation(); }
$.fn.pagination = function (config) {
var options = $.extend({
prev: '«',
next: '»',
left: 3,
right: 3,
page: 1,
lastPage: 1,
click: defaultClick
}, config || {}),
lr = options.left + options.right,
begin = Math.max(1, options.page - options.left),
end = begin + lr;
if (options.lastPage < end) {
begin = Math.max(1, options.lastPage - lr);
end = options.lastPage;
}
function newLI(label, page) {
var enable = (1 <= page && page <= options.lastPage),
a = $('<a/>').append(label),
li = $('<li/>').append(a);
if (enable) {
a.click(function () { options.click(page); });
} else {
li.addClass('disabled');
}
a.click(stopPropagation);
if (page === options.page) { li.addClass('active'); }
return li;
}
function newUL() {
var ul = $('<ul/>'), i;
ul.append(newLI(options.prev, options.page - 1));
for (i = begin; i <= end; i += 1) { ul.append(newLI(i, i)); }
return ul.append(newLI(options.next, options.page + 1));
}
return this.each(function (i) {
var self = $(this), ul = self.children('ul');
if (ul.length) {
ul.replaceWith(newUL());
} else {
self.append(newUL());
}
});
};
}(jQuery));

View File

@ -64,7 +64,6 @@
<p>Theres no way back…</p>
</div>
<div class="modal-footer">
<!-- <button class="arangoBtn" data-dismiss="modal" aria-hidden="true">Close</button> -->
<button id="confirmDeleteBtn" class="btn btn-danger" style="float:right">Delete</button>
</div>
</div>
@ -91,7 +90,6 @@
</table>
</div>
<div class="modal-footer">
<!-- <button class="arangoBtn" data-dismiss="modal" aria-hidden="true">Close</button> -->
<button id="confirmCreateEdge" class="btn btn-success" style="float:right">Create</button>
</div>
</div>

View File

@ -1,6 +1,6 @@
<div class="thumbnails2">
<div id="transparentHeader">
<h4>Logs</h4>
</div>
<div id="logContent">

View File

@ -61,6 +61,6 @@
</div>
<div class="modal-footer">
<button id="save-new-collection" class="arangoBtnSuccess">Create Collection</button>
<button id="save-new-collection" class="btn btn-success">Create Collection</button>
</div>
</div>

View File

@ -12,7 +12,7 @@
<div id="editorLabel">Input</div>
<div id="aqlEditor"></div>
<button id="submitQueryButton" class="arangoBtnSuccess">Submit</button>
<button id="submitQueryButton" class="btn btn-success">Submit</button>
</div>

View File

@ -245,6 +245,20 @@ var documentsView = Backbone.View.extend({
},
renderPagination: function (totalPages) {
var currentPage = JSON.parse(this.pageid);
var self = this;
var target = $('#testdiv'),
options = {
left: 1,
right: 1,
page: currentPage,
lastPage: totalPages,
click: function(i) {
options.page = i;
window.location.hash = '#collection/' + self.colid + '/documents/' + options.page;
}
};
target.pagination(options);
return;
$('#testdiv').pagination({
link: '#collection/' + this.colid + '/documents/{p}',
count: totalPages,