Gazelle/static/functions/sort.js

115 lines
2.9 KiB
JavaScript
Raw Normal View History

2012-10-27 08:00:09 +00:00
var sortableTable;
2013-06-27 08:01:06 +00:00
$(document).ready(function () {
2012-10-30 08:00:18 +00:00
$.tablesorter.addParser({
id: 'relative_time',
is: function (s) {
return false;
},
format: function(str, table, td) {
return td.title;
},
type: 'text'
});
2012-10-27 08:00:09 +00:00
sortableTable = {
container : $('#manage_collage_table'),
form : $('#drag_drop_collage_form'),
serialInput : $('#drag_drop_collage_sort_order'),
check : $('#check_all'),
counter : function () {
var x = 10;
$('input.sort_numbers').each(function () {
this.value = x;
x += 10;
});
this.serializer();
},
color : function () {
var i = 0, css;
$('tr.drag').each(function () {
css = i % 2 === 0 ? ['rowa', 'rowb'] : ['rowb', 'rowa'];
$(this).removeClass(css[0]).addClass(css[1]);
i++;
});
},
serializer : function () {
this.serialInput.val(this.container.sortable('serialize'));
},
save : function () {
sortableTable.form.submit();
},
widthFix : function(e, row) {
row.children('td').each(function () {
$(this).width($(this).width());
});
return row;
},
init : function () {
$('.drag_drop_save').removeClass('hidden');
2012-07-11 08:00:16 +00:00
2012-10-27 08:00:09 +00:00
this.noteToggle();
this.draggable();
this.tableSorter();
if (this.check.length !== 0) {
this.checks();
} else {
$('.save_sortable_collage').click(sortableTable.save);
2012-07-11 08:00:16 +00:00
}
2012-10-27 08:00:09 +00:00
},
draggable : function () {
this.container.sortable({
items: '.drag',
axis: 'y',
containment: '.thin',
forcePlaceholderSize: true,
helper: sortableTable.widthFix,
stop: sortableTable.postSort
});
},
tableSorter : function () {
2013-08-28 23:08:41 +00:00
var obj = { 0: { sorter : false }, 6: { sorter : false } };
2012-10-30 08:00:18 +00:00
if (this.check.length !== 0) {
2013-08-28 23:08:41 +00:00
obj[5] = { sorter : 'relative_time' };
2012-10-30 08:00:18 +00:00
}
2012-10-27 08:00:09 +00:00
this.container.tablesorter({
cssHeader : 'headerSort',
textExtraction: sortableTable.extractor,
2012-10-30 08:00:18 +00:00
headers : obj
2012-10-27 08:00:09 +00:00
}).on('sortEnd', sortableTable.postSort);
},
extractor : function (node) {
return node.textContent || node.innerText;
},
postSort : function () {
sortableTable.color();
sortableTable.counter();
},
noteToggle : function () {
2013-11-05 08:01:12 +00:00
var span = $('<a href="#" class="brackets tooltip" title="Toggle note">Hide</a>').click(function (e) {
2012-10-27 08:00:09 +00:00
e.preventDefault();
$('#drag_drop_textnote > :first-child').toggle();
2012-10-30 08:00:18 +00:00
var $this = $(this);
2013-08-28 23:08:41 +00:00
$this.text($this.text() === 'Hide' ? 'Show' : 'Hide');
2012-10-27 08:00:09 +00:00
});
$('#sorting_head').append(' ', span);
},
checks : function () {
this.check.on('click', 'input', function () {
var s = this.checked ?
'td.center :checkbox:not(:checked)' :
'td.center :checked';
$(s).click();
}).find('span').html('<input type="checkbox" />');
this.container.on('click', 'td > :checkbox', function() {
$(this).parents('tr').toggleClass('row_checked');
}).on('dblclick', 'tr.drag', function () {
$(this).find(':checkbox').click();
});
}
};
sortableTable.init();
2013-06-27 08:01:06 +00:00
});