Merge "Common table functions are now run on modal.show"
This commit is contained in:
commit
2d0315030e
@ -221,7 +221,7 @@ var Horizon = function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$("form :checkbox").on("click", function (evt) {
|
$("div.table_wrapper, div.modal_wrapper").on("click", ':checkbox', function (evt) {
|
||||||
var $form = $(this).closest("form");
|
var $form = $(this).closest("form");
|
||||||
var any_checked = $form.find("tbody :checkbox").is(":checked");
|
var any_checked = $form.find("tbody :checkbox").is(":checked");
|
||||||
|
|
||||||
|
@ -23,13 +23,13 @@ horizon.modals.create = function (title, body, confirm, cancel) {
|
|||||||
}
|
}
|
||||||
var template = horizon.templates.compiled_templates["#modal_template"],
|
var template = horizon.templates.compiled_templates["#modal_template"],
|
||||||
params = {title: title, body: body, confirm: confirm, cancel: cancel},
|
params = {title: title, body: body, confirm: confirm, cancel: cancel},
|
||||||
modal = $(template.render(params)).appendTo("body");
|
modal = $(template.render(params)).appendTo("div.modal_wrapper");
|
||||||
return modal;
|
return modal;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
horizon.modals.success = function (data, textStatus, jqXHR) {
|
horizon.modals.success = function (data, textStatus, jqXHR) {
|
||||||
$('body').append(data);
|
$('div.modal_wrapper').append(data);
|
||||||
$('.modal span.help-block').hide();
|
$('.modal span.help-block').hide();
|
||||||
$('.modal:last').modal();
|
$('.modal:last').modal();
|
||||||
|
|
||||||
@ -91,8 +91,8 @@ horizon.addInitFunction(function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Focus the first usable form field in the modal for accessibility.
|
// Focus the first usable form field in the modal for accessibility.
|
||||||
$(document).on('shown', '.modal', function(evt) {
|
$('div.modal_wrapper').on('shown', '.modal', function(evt) {
|
||||||
$(this).find("input, select, textarea").filter(":visible:first").focus();
|
$(this).find(":text, select, textarea").filter(":visible:first").focus();
|
||||||
});
|
});
|
||||||
|
|
||||||
$('.ajax-modal').live('click', function (evt) {
|
$('.ajax-modal').live('click', function (evt) {
|
||||||
@ -108,7 +108,7 @@ horizon.addInitFunction(function() {
|
|||||||
var template = horizon.templates.compiled_templates["#spinner-modal"];
|
var template = horizon.templates.compiled_templates["#spinner-modal"];
|
||||||
horizon.modals.spinner = $(template.render());
|
horizon.modals.spinner = $(template.render());
|
||||||
|
|
||||||
horizon.modals.spinner.appendTo("body");
|
horizon.modals.spinner.appendTo("div.modal_wrapper");
|
||||||
horizon.modals.spinner.modal({backdrop: 'static'});
|
horizon.modals.spinner.modal({backdrop: 'static'});
|
||||||
horizon.modals.spinner.spin(horizon.modals.spinner_options);
|
horizon.modals.spinner.spin(horizon.modals.spinner_options);
|
||||||
},
|
},
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
horizon.datatables.init_sorting = function () {
|
horizon.datatables.set_table_sorting = function (parent) {
|
||||||
// Function to initialize the tablesorter plugin strictly on sortable columns.
|
// Function to initialize the tablesorter plugin strictly on sortable columns.
|
||||||
$("table.table").each(function () {
|
$(parent).find("table.table").each(function () {
|
||||||
var $this = $(this),
|
var $this = $(this),
|
||||||
options = {};
|
options = {};
|
||||||
$this.find("thead th").each(function (i, val) {
|
$this.find("thead th").each(function (i, val) {
|
||||||
if (!$(this).hasClass('sortable')) {
|
// Disable if not sortable or has <= 1 item
|
||||||
|
if (!$(this).hasClass('sortable') ||
|
||||||
|
$this.find('tbody tr').not('.empty').length <= 1) {
|
||||||
options[i] = {sorter: false};
|
options[i] = {sorter: false};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -14,7 +16,23 @@ horizon.datatables.init_sorting = function () {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
horizon.datatables.add_table_checkboxes = function(parent) {
|
||||||
|
$(parent).find('table thead .multi_select_column').each(function(index, thead) {
|
||||||
|
if (!$(thead).find(':checkbox').length &&
|
||||||
|
$(thead).parents('table').find('tbody :checkbox').length) {
|
||||||
|
$(thead).append('<input type="checkbox">');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
horizon.addInitFunction(function() {
|
horizon.addInitFunction(function() {
|
||||||
|
$('div.table_wrapper, div.modal_wrapper').on('click', 'table thead .multi_select_column :checkbox', function(evt) {
|
||||||
|
var $this = $(this),
|
||||||
|
$table = $this.closest('table'),
|
||||||
|
is_checked = $this.prop('checked'),
|
||||||
|
checkboxes = $table.find('tbody :checkbox');
|
||||||
|
checkboxes.prop('checked', is_checked);
|
||||||
|
});
|
||||||
$('.table_search input').quicksearch('tbody tr', {
|
$('.table_search input').quicksearch('tbody tr', {
|
||||||
'delay': 300,
|
'delay': 300,
|
||||||
'loader': 'span.loading',
|
'loader': 'span.loading',
|
||||||
@ -33,25 +51,14 @@ horizon.addInitFunction(function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$('table.sortable').each(function(index, table) {
|
horizon.datatables.add_table_checkboxes($('body'));
|
||||||
var $table = $(table);
|
horizon.datatables.set_table_sorting($('body'));
|
||||||
// Only trigger if we have actual data rows in the table.
|
|
||||||
// Calling on an empty table throws a javascript error.
|
|
||||||
if ($table.find('tbody tr').length) {
|
|
||||||
$table.tablesorter();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Add a select all checkbox at table header
|
// Also apply on tables in modal views
|
||||||
$('table thead .multi_select_column').append('<input type="checkbox">');
|
$('div.modal_wrapper').on('shown', '.modal', function(evt) {
|
||||||
$('table thead .multi_select_column :checkbox').click(function(evt) {
|
horizon.datatables.add_table_checkboxes(this);
|
||||||
var $this = $(this),
|
horizon.datatables.set_table_sorting(this);
|
||||||
$table = $this.closest('table'),
|
|
||||||
is_checked = $this.prop('checked'),
|
|
||||||
checkboxes = $table.find('tbody :checkbox');
|
|
||||||
checkboxes.prop('checked', is_checked);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
horizon.datatables.update();
|
horizon.datatables.update();
|
||||||
horizon.datatables.init_sorting();
|
|
||||||
});
|
});
|
||||||
|
@ -27,5 +27,6 @@
|
|||||||
{% block js %}
|
{% block js %}
|
||||||
{% include "_scripts.html" %}
|
{% include "_scripts.html" %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
<div class="modal_wrapper" />
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
Reference in New Issue
Block a user