Unverified Commit 7ab5de3e authored by Serge S. Koval's avatar Serge S. Koval Committed by GitHub

Merge pull request #2014 from TitaniumHocker/bootstrap4

Bootstrap4 ui fixes
parents 348c1c6f 2795581c
var AdminFilters = function(element, filtersElement, filterGroups, activeFilters) {
var $root = $(element);
var $container = $('.filters', $root);
var lastCount = 0;
function getCount(name) {
var idx = name.indexOf('_');
if (idx === -1) {
return 0;
}
return parseInt(name.substr(3, idx - 3), 10);
}
function makeName(name) {
var result = 'flt' + lastCount + '_' + name;
lastCount += 1;
return result;
}
function removeFilter() {
$(this).closest('tr').remove();
if($('.filters tr').length == 0) {
$('button', $root).hide();
$('a[class=btn]', $root).hide();
$('.filters tbody').remove();
} else {
$('button', $root).show();
}
return false;
}
// triggered when the filter operation (equals, not equals, etc) is changed
function changeOperation(subfilters, $el, filter, $select) {
// get the filter_group subfilter based on the index of the selected option
var selectedFilter = subfilters[$select.select2('data').element[0].index];
var $inputContainer = $el.find('td').last();
// recreate and style the input field (turn into date range or select2 if necessary)
var $field = createFilterInput($inputContainer, null, selectedFilter);
styleFilterInput(selectedFilter, $field);
$('button', $root).show();
}
// generate HTML for filter input - allows changing filter input type to one with options or tags
function createFilterInput(inputContainer, filterValue, filter) {
if (filter.type == "select2-tags") {
var $field = $('<input type="hidden" class="filter-val form-control" />').attr('name', makeName(filter.arg));
$field.val(filterValue);
} else if (filter.options) {
var $field = $('<select class="filter-val" />').attr('name', makeName(filter.arg));
$(filter.options).each(function() {
// for active filter inputs with options, add "selected" if there is a matching active filter
if (filterValue && (filterValue == this[0])) {
$field.append($('<option/>')
.val(this[0]).text(this[1]).attr('selected', true));
} else {
$field.append($('<option/>')
.val(this[0]).text(this[1]));
}
});
} else {
var $field = $('<input type="text" class="filter-val form-control" />').attr('name', makeName(filter.arg));
$field.val(filterValue);
}
inputContainer.replaceWith($('<td/>').append($field));
return $field;
}
// add styling to input field, accommodates filters that change the input field's HTML
function styleFilterInput(filter, field) {
if (filter.type) {
if ((filter.type == "datepicker") || (filter.type == "daterangepicker")) {
field.attr('data-date-format', "YYYY-MM-DD");
} else if ((filter.type == "datetimepicker") || (filter.type == "datetimerangepicker")) {
field.attr('data-date-format', "YYYY-MM-DD HH:mm:ss");
} else if ((filter.type == "timepicker") || (filter.type == "timerangepicker")) {
field.attr('data-date-format', "HH:mm:ss");
} else if (filter.type == "select2-tags") {
var options = [];
if (filter.options) {
filter.options.forEach(function(option) {
options.push({id:option[0], text:option[1]});
});
// save tag options as json on data attribute
field.attr('data-tags', JSON.stringify(options));
}
}
faForm.applyStyle(field, filter.type);
} else if (filter.options) {
filter.type = "select2";
faForm.applyStyle(field, filter.type);
}
return field;
}
function addFilter(name, subfilters, selectedIndex, filterValue) {
var $el = $('<tr class="form-horizontal" />').appendTo($container);
// Filter list
$el.append(
$('<td/>').append(
$('<a href="#" class="btn btn-secondary remove-filter" />')
.append($('<span class="close-icon">&times;</span>'))
.append('&nbsp;')
.append(name)
.click(removeFilter)
)
);
// Filter operation <select> (equal, not equal, etc)
var $select = $('<select class="filter-op" />');
// if one of the subfilters are selected, use that subfilter to create the input field
var filterSelection = 0;
$.each(subfilters, function( subfilterIndex, subfilter ) {
if (this.index == selectedIndex) {
$select.append($('<option/>').attr('value', subfilter.arg).attr('selected', true).text(subfilter.operation));
filterSelection = subfilterIndex;
} else {
$select.append($('<option/>').attr('value', subfilter.arg).text(subfilter.operation));
}
});
$el.append(
$('<td/>').append($select)
);
// select2 for filter-op (equal, not equal, etc)
$select.select2({width: 'resolve'}).on("change", function(e) {
changeOperation(subfilters, $el, filter, $select);
});
// get filter option from filter_group, only for new filter creation
var filter = subfilters[filterSelection];
var $inputContainer = $('<td/>').appendTo($el);
var $newFilterField = createFilterInput($inputContainer, filterValue, filter).focus();
var $styledFilterField = styleFilterInput(filter, $newFilterField);
return $styledFilterField;
}
// Add Filter Button, new filter
$('a.filter', filtersElement).click(function() {
var name = ($(this).text().trim !== undefined ? $(this).text().trim() : $(this).text().replace(/^\s+|\s+$/g,''));
addFilter(name, filterGroups[name], false, null);
$('button', $root).show();
});
// on page load - add active filters
$.each(activeFilters, function( activeIndex, activeFilter ) {
var idx = activeFilter[0],
name = activeFilter[1],
filterValue = activeFilter[2];
var $activeField = addFilter(name, filterGroups[name], idx, filterValue);
});
// show "Apply Filter" button when filter input is changed
$('.filter-val', $root).on('input change', function() {
$('button', $root).show();
});
$('.remove-filter', $root).click(removeFilter);
$('.filter-val', $root).not('.select2-container').each(function() {
var count = getCount($(this).attr('name'));
if (count > lastCount)
lastCount = count;
});
lastCount += 1;
};
(function($) {
$('[data-role=tooltip]').tooltip({
html: true,
placement: 'bottom'
});
if ($('#filter-groups-data').length == 1) {
var filter = new AdminFilters(
'#filter_form', '.field-filters',
JSON.parse($('#filter-groups-data').text()),
JSON.parse($('#active-filters-data').text())
);
}
})(jQuery);
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -4,21 +4,23 @@
{% block body %}
{% block breadcrums %}
<ul class="breadcrumb">
<li>
<nav area-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item">
<a href="{{ get_dir_url('.index_view', path=None) }}">{{ _gettext('Root') }}</a>
</li>
{% for name, path in breadcrumbs[:-1] %}
<li>
</li>
{% for name, path in breadcrumbs[:-1] %}
<li class="breadcrumb-item">
<a href="{{ get_dir_url('.index_view', path=path) }}">{{ name }}</a>
</li>
{% endfor %}
{% if breadcrumbs %}
<li>
</li>
{% endfor %}
{% if breadcrumbs %}
<li class="breadcrumb-item">
<a href="{{ get_dir_url('.index_view', path=breadcrumbs[-1][1]) }}">{{ breadcrumbs[-1][0] }}</a>
</li>
</li>
{% endif %}
</ul>
</ol>
</nav>
{% endblock %}
{% block file_list_table %}
......@@ -144,27 +146,27 @@
<div class="btn-group">
{%- if admin_view.upload_modal -%}
{{ lib.add_modal_button(url=get_dir_url('.upload', path=dir_path, modal=True),
btn_class="btn btn-default btn-large",
btn_class="btn btn-secondary",
content=_gettext('Upload File')) }}
{% else %}
<a class="btn btn-default btn-large" href="{{ get_dir_url('.upload', path=dir_path) }}">{{ _gettext('Upload File') }}</a>
<a class="btn btn-secondary" href="{{ get_dir_url('.upload', path=dir_path) }}">{{ _gettext('Upload File') }}</a>
{%- endif -%}
</div>
{% endif %}
{% if admin_view.can_mkdir %}
<div class="btn-group">
<div class="mx-1">
{%- if admin_view.mkdir_modal -%}
{{ lib.add_modal_button(url=get_dir_url('.mkdir', path=dir_path, modal=True),
btn_class="btn btn-default btn-large",
btn_class="btn btn-secondary",
content=_gettext('Create Directory')) }}
{% else %}
<a class="btn btn-default btn-large" href="{{ get_dir_url('.mkdir', path=dir_path) }}">{{ _gettext('Create Directory') }}</a>
<a class="btn btn-secondary" href="{{ get_dir_url('.mkdir', path=dir_path) }}">{{ _gettext('Create Directory') }}</a>
{%- endif -%}
</div>
{% endif %}
{% if actions %}
<div class="btn-group">
{{ actionslib.dropdown(actions, 'dropdown-toggle btn btn-default btn-large') }}
<div class="mx-1">
{{ actionslib.dropdown(actions, 'dropdown-toggle btn btn-secondary') }}
</div>
{% endif %}
</div>
......@@ -185,4 +187,5 @@
{{ actionslib.script(_gettext('Please select at least one file.'),
actions,
actions_confirmation) }}
<script src="{{ admin_static.url(filename='admin/js/bs4_modal.js', v='1.0.0') }}"></script>
{% endblock %}
......@@ -4,8 +4,8 @@
{% block body %}
{# content added to modal-content #}
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
{% block header %}<h3>{{ header_text }}</h3>{% endblock %}
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
</div>
<div class="modal-body">
{% block fa_form %}
......@@ -15,5 +15,5 @@
{% endblock %}
{% block tail %}
<script src="{{ admin_static.url(filename='admin/js/bs3_modal.js', v='1.0.0') }}"></script>
<script src="{{ admin_static.url(filename='admin/js/bs4_modal.js', v='1.0.0') }}"></script>
{% endblock %}
......@@ -4,29 +4,29 @@
{% block body %}
{% block navlinks %}
<ul class="nav nav-tabs">
<li>
<a href="{{ return_url }}">{{ _gettext('List') }}</a>
<li class="nav-item">
<a class="nav-link" href="{{ return_url }}">{{ _gettext('List') }}</a>
</li>
{%- if admin_view.can_create -%}
<li>
<a href="{{ get_url('.create_view', url=return_url) }}">{{ _gettext('Create') }}</a>
<li class="nav-item">
<a class="nav-link" href="{{ get_url('.create_view', url=return_url) }}">{{ _gettext('Create') }}</a>
</li>
{%- endif -%}
{%- if admin_view.can_edit -%}
<li>
<a href="{{ get_url('.edit_view', id=request.args.get('id'), url=return_url) }}">{{ _gettext('Edit') }}</a>
<li class="nav-item">
<a class="nav-link" href="{{ get_url('.edit_view', id=request.args.get('id'), url=return_url) }}">{{ _gettext('Edit') }}</a>
</li>
{%- endif -%}
<li class="active">
<a href="javascript:void(0)">{{ _gettext('Details') }}</a>
<li class="nav-item">
<a class="nav-link active disabled" href="javascript:void(0)">{{ _gettext('Details') }}</a>
</li>
</ul>
{% endblock %}
{% block details_search %}
<div class="input-group fa_filter_container col-lg-6">
<span class="input-group-addon">{{ _gettext('Filter') }}</span>
<input id="fa_filter" type="text" class="form-control">
<div class="form-inline fa_filter_container col-lg-6">
<label for="fa_filter">{{ _gettext('Filter') }}</label>
<input id="fa_filter" type="text" class="ml-3 form-control">
</div>
{% endblock %}
......
......@@ -54,7 +54,7 @@
<div class="clearfix"></div>
{% endmacro %}
{% macro search_form(input_class="col-md-4") %}
{% macro search_form(input_class="col-auto") %}
<form method="GET" action="{{ return_url }}" class="form-inline my-2 my-lg-0" role="search">
{% for flt_name, flt_value in filter_args.items() %}
<input type="hidden" name="{{ flt_name }}" value="{{ flt_value }}">
......@@ -69,30 +69,35 @@
<input type="hidden" name="desc" value="{{ sort_desc }}">
{% endif %}
{% if search %}
<div class="input-group">
<input class="form-control mr-sm-2 {{ input_class }}" size="30" type="text" name="search" value="{{ search }}"
<div class="form-inline input-group">
<input class="form-control {{ input_class }}" size="30" type="text" name="search" value="{{ search }}"
placeholder="{{ _gettext('%(placeholder)s', placeholder=search_placeholder) }}">
<a href="{{ clear_search_url }}" class="input-group-addon clear"><span
class="fa fa-times glyphicon glyphicon-remove"></span></a>
<button class="btn btn-secondary my-2 my-sm-0" type="submit">Search</button>
<div class="input-group-append">
<span class="input-group-text">
<a href="{{ clear_search_url }}" class="align-middle">
<span class="fa fa-times glyphicon glyphicon-remove"></span>
</a>
</span>
</div>
<button class="btn btn-secondary my-2 my-sm-0 ml-2" type="submit">{{ _gettext('Search') }}</button>
</div>
{% else %}
<div class="form-group">
<input class="form-control mr-sm-2 {{ input_class }}" size="30" type="text" name="search" value=""
<div class="form-inline">
<input class="form-control {{ input_class }}" size="30" type="text" name="search" value=""
placeholder="{{ _gettext('%(placeholder)s', placeholder=search_placeholder) }}">
<button class="btn btn-secondary my-2 my-sm-0" type="submit">Search</button>
<button class="btn btn-secondary my-2 my-sm-0 ml-2" type="submit">{{ _gettext('Search') }}</button>
</div>
{% endif %}
</form>
{% endmacro %}
{% macro page_size_form(generator, btn_class='dropdown-toggle') %}
{% macro page_size_form(generator, btn_class='nav-link dropdown-toggle') %}
<a class="{{ btn_class }}" data-toggle="dropdown" href="javascript:void(0)">
{{ page_size }} {{ _gettext('items') }}<b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><a href="{{ generator(20) }}">20 {{ _gettext('items') }}</a></li>
<li><a href="{{ generator(50) }}">50 {{ _gettext('items') }}</a></li>
<li><a href="{{ generator(100) }}">100 {{ _gettext('items') }}</a></li>
</ul>
<div class="dropdown-menu">
<a class="dropdown-item{% if page_size == 20 %} active{% endif %}" href="{{ generator(20) }}">20 {{ _gettext('items') }}</a>
<a class="dropdown-item{% if page_size == 50 %} active{% endif %}" href="{{ generator(50) }}">50 {{ _gettext('items') }}</a>
<a class="dropdown-item{% if page_size == 100 %} active{% endif %}" href="{{ generator(100) }}">100 {{ _gettext('items') }}</a>
</div>
{% endmacro %}
......@@ -52,7 +52,7 @@
{% endif %}
{% if search_supported %}
<li class="nav-item">
<li class="nav-item col-auto">
{{ model_layout.search_form() }}
</li>
{% endif %}
......@@ -187,7 +187,7 @@
{% endif %}
<script src="{{ admin_static.url(filename='admin/js/bs4_modal.js', v='1.0.0') }}"></script>
<script src="{{ admin_static.url(filename='admin/js/filters.js', v='1.0.0') }}"></script>
<script src="{{ admin_static.url(filename='admin/js/bs4_filters.js', v='1.0.0') }}"></script>
{{ lib.form_js() }}
{{ actionlib.script(_gettext('Please select at least one record.'),
......
......@@ -11,7 +11,7 @@
<div class="console">
<div class="console-container">
</div>
<div class="console-line">
<div class="console-line mb-4">
<form action="#">
<input type="text"></input>
</form>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment