Skip to content

Commit

Permalink
improvement: moved persistent filters to right bottom of filter boxes…
Browse files Browse the repository at this point in the history
… (LMS+ #620)
  • Loading branch information
chilek committed Sep 7, 2018
1 parent 1072d33 commit 75bc7cb
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 71 deletions.
44 changes: 21 additions & 23 deletions img/lms-ui-persistent-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,21 @@

$(function() {
$('.lms-ui-filter-modify-button').click(function () {
var form = $(this).closest('form.lms-ui-persistent-filter');
var selectelem = form.find('.scombobox')
var div = $(this).closest('div.lms-ui-persistent-filter');
var selectelem = div.find('.scombobox')
var selection = selectelem.scombobox('val');
if (selection == -1 || selection.length < 5) {
return false;
}

var module = location.href.replace(/^.+?m=([a-zA-Z0-9_-]+)(?:&.+|$)/, '$1');
var url = '?m=' + module + '&persistent-filter=' + selection + '&action=update&api=1';

$('html,body').css('cursor', 'wait');
$('.lms-ui-filter-modify-button,.lms-ui-filter-delete-button').addClass('lms-ui-button-disabled');
$.ajax(form.attr('action'), {

$.ajax(url, {
method: "POST",
data: {
'persistent-filter': 1,
api: 1,
action: 'modify',
name: selection
},
success: function (data) {
data.unshift({
text: lmsMessages.filterNone,
Expand All @@ -57,22 +56,21 @@ $(function() {
});

$('.lms-ui-filter-delete-button').click(function () {
var form = $(this).closest('form.lms-ui-persistent-filter');
var selectelem = form.find('.scombobox')
var div = $(this).closest('div.lms-ui-persistent-filter');
var selectelem = div.find('.scombobox')
var selection = selectelem.scombobox('val');
if (selection == -1 || selection.length < 5) {
return false;
}

var module = location.href.replace(/^.+?m=([a-zA-Z0-9_-]+)(?:&.+|$)/, '$1');
var url = '?m=' + module + '&persistent-filter=' + selection + '&action=delete&api=1';

$('html,body').css('cursor', 'wait');
$('.lms-ui-filter-modify-button,.lms-ui-filter-delete-button').addClass('lms-ui-button-disabled');
$.ajax(form.attr('action'), {

$.ajax(url, {
method: "POST",
data: {
'persistent-filter': 1,
api: 1,
action: 'delete',
name: selection
},
success: function (data) {
data.unshift({
text: lmsMessages.filterNone,
Expand All @@ -90,8 +88,8 @@ $(function() {

if ($('.lms-ui-persistent-filter .scombobox').length) {
$('.lms-ui-persistent-filter .scombobox').scombobox('change', function () {
var form = $(this).closest('form.lms-ui-persistent-filter');
var selectelem = form.find('.scombobox')
var div = $(this).closest('div.lms-ui-persistent-filter');
var selectelem = div.find('.scombobox')
var selection = selectelem.scombobox('val');
if (selection != -1 && selection.length < 5) {
$('.lms-ui-filter-modify-button,.lms-ui-filter-delete-button').addClass('lms-ui-button-disabled');
Expand All @@ -105,9 +103,9 @@ $(function() {
}
});
if (!newname) {
form.find('[name="name"]').val(selection);
form.attr('action', form.attr('action').replace('&api=1', ''));
form.submit();
var module = location.href.replace(/^.+?m=([a-zA-Z0-9_-]+)(?:&.+|$)/, '$1');
var url = '?m=' + module + '&persistent-filter=' + selection;
location.href = url;
}
}, 'lms-ui');
}
Expand Down
17 changes: 9 additions & 8 deletions img/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -1984,22 +1984,23 @@ table.dataTable thead tr:last-child th {
border-radius: unset;
}
div.lms-ui-persistent-filter {
display: inline-flex;
justify-content: flex-start;
display: flex;
justify-content: flex-end;
align-items: center;
vertical-align: middle;
padding: 5px;
background-color: #CEBD9B;
border: 1px solid #AE9D7B;
border-radius: 3px;
margin-bottom: 10px;
float: right;
}
div.lms-ui-persistent-filter > * {
margin: 2px;
}
div.lms-ui-persistent-filter .lms-ui-filter-name {
display: none;
}
div.lms-ui-persistent-filter .lms-ui-button {
padding-left: 0;
width: 22px;
height: 22px;
background-position: 2px 2px;
}
div.lms-ui-persistent-filter .lms-ui-button.lms-ui-filter-modify-button {
background-image: url(add.gif);
}
Expand Down
15 changes: 7 additions & 8 deletions img/style.less
Original file line number Diff line number Diff line change
Expand Up @@ -1725,22 +1725,21 @@ table.dataTable {
}

div.lms-ui-persistent-filter {
display: inline-flex;
justify-content: flex-start;
display: flex;
justify-content: flex-end;
align-items: center;
vertical-align: middle;
padding: 5px;
background-color: @dark;
border: 1px solid @superdark;
border-radius: 3px;
margin-bottom: 10px;
float: right;
& > * {
margin: 2px;
}
.lms-ui-filter-name {
display: none;
}
.lms-ui-button {
padding-left: 0;
width: 22px;
height: 22px;
background-position: 2px 2px;
&.lms-ui-filter-modify-button {
background-image: url(add.gif);
}
Expand Down
16 changes: 8 additions & 8 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,9 @@
$SMARTY->assign('persistent_filters', $SESSION->getAllPersistentFilters());

// persister filter apply
if (isset($_GET['persistent-filter']) && isset($_POST['name']) && $_POST['action'] == 'apply') {
$filter = $SESSION->getPersistentFilter($_POST['name']);
$filter['persistent_filter'] = $_POST['name'];
if (isset($_GET['persistent-filter'])) {
$filter = $SESSION->getPersistentFilter($_GET['persistent-filter']);
$filter['persistent_filter'] = $_GET['persistent-filter'];
$SESSION->saveFilter($filter);
} else
$filter = $SESSION->getFilter();
Expand All @@ -325,17 +325,17 @@
$SMARTY->assign('persistent_filter', $filter['persistent_filter']);
} else {
// persistent filter ajax management
if (isset($_GET['persistent-filter']) && isset($_POST['name']))
switch ($_POST['action']) {
case 'modify':
$SESSION->savePersistentFilter($_POST['name'], $SESSION->getFilter());
if (isset($_GET['persistent-filter']) && isset($_GET['action']))
switch ($_GET['action']) {
case 'update':
$SESSION->savePersistentFilter($_GET['persistent-filter'], $SESSION->getFilter());
$persistent_filters = $SESSION->getAllPersistentFilters();
$SESSION->close();
header('Content-type: application/json');
die(json_encode($persistent_filters));
break;
case 'delete':
$SESSION->removePersistentFilter($_POST['name']);
$SESSION->removePersistentFilter($_GET['persistent-filter']);
$persistent_filters = $SESSION->getAllPersistentFilters();
$SESSION->close();
header('Content-type: application/json');
Expand Down
17 changes: 8 additions & 9 deletions lib/SmartyPlugins/function.persistent_filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,21 @@ function smarty_function_persistent_filter($params, $template) {
$filters .= '<option value="' . $filter['value'] . '"' . ($filter['value'] == $persistent_filter ? ' selected' : '')
. '>' . $filter['text'] . '</option >';

return '<form method="post" class="lms-ui-persistent-filter" action="?m=' . $layout['module'] . '&persistent-filter=1&api=1">
<input type="hidden" name="action" value="apply">
<input type="hidden" name="name" value="">
return '
<div class="lms-ui-persistent-filter">
' . trans("Persistent filter:") . '
<input class="lms-ui-filter-action" type="hidden" value="apply">
<input class="lms-ui-filter-name" type="hidden" value="">
<button class="lms-ui-button lms-ui-button-icon lms-ui-filter-modify-button'
. (empty($persistent_filter) ? ' lms-ui-button-disabled' : '') . '">
' . trans("<!filter>Update") . '
. (empty($persistent_filter) ? ' lms-ui-button-disabled' : '') . '" title="'
. trans("<!filter>Update") . '">
</button>
<select class="lms-ui-filter-selection lms-ui-combobox">
<select class="lms-ui-filter-selection lms-ui-combobox" title="' . trans("<!filter>Select filter") . '">
<option value="-1">' . trans("<!filter>- none -") . '</option>
' . $filters . '
</select>
<button class="lms-ui-button lms-ui-button-icon lms-ui-filter-delete-button'
. (empty($persistent_filter) == -1 ? ' lms-ui-button-disabled' : '') . '">
' . trans("<!filter>Delete") . '
. (empty($persistent_filter) == -1 ? ' lms-ui-button-disabled' : '') . '" title="'
. trans("<!filter>Delete") . '">
</button>
</div>
</form>';
Expand Down
5 changes: 2 additions & 3 deletions lib/locale/pl/strings.php
Original file line number Diff line number Diff line change
Expand Up @@ -4107,10 +4107,9 @@

$_LANG['Clear filter'] = 'Wyczyść filtr';

$_LANG['Persistent filter:'] = 'Filtr trwały:';
$_LANG['<!filter>- none -'] = '- brak -';
$_LANG['<!filter>Update'] = 'Aktualizuj';
$_LANG['<!filter>Delete'] = 'Usuń';
$_LANG['<!filter>- none -'] = '- żaden - ';
$_LANG['<!filter>- new -'] = '- nowy -';
$_LANG['<!filter>Select filter'] = 'Wybierz filtr';

?>
4 changes: 1 addition & 3 deletions templates/default/customer/customerlist.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
<!--// $Id$ //-->
<H1>{$layout.pagetitle}</H1>

{persistent_filter}

<FORM method="get" action="?m={$layout.module}" name="choosefilter">
<p style="display: none;">
<INPUT type="submit" class="hiddenbtn">
Expand Down Expand Up @@ -48,7 +46,6 @@ <H1>{$layout.pagetitle}</H1>
{block name="customerlist-list-filters"}
<TR>
<TD colspan="{$number_of_table_columns}" class="nobr">
{clear_filter}
<span class="bold">{trans("Filter:")}</span> {trans("Customers:")}
<SELECT SIZE="1" NAME="s" ONCHANGE="document.choosefilter.submit();">
<OPTION VALUE="0"{if $filter.state == 0} SELECTED{/if}>{trans("- all customers -")}</OPTION>
Expand Down Expand Up @@ -131,6 +128,7 @@ <H1>{$layout.pagetitle}</H1>
<option value="-3" {if $filter.assignments eq '-3'} selected {/if}>{trans('active, with invoice')}</option>
<option value="-4" {if $filter.assignments eq '-4'} selected {/if}>{trans('suspended')}</option>
</select>
{persistent_filter}
</TD>
</TR>
{/block}
Expand Down
2 changes: 0 additions & 2 deletions templates/default/event/eventlist.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ <H1>{trans("Overdue events")}</H1>

<H1>{$layout.pagetitle}</H1>

{persistent_filter}

<TABLE class="lmsbox">
<COLGROUP>
<COL style="width: 1%;">
Expand Down
2 changes: 1 addition & 1 deletion templates/default/event/eventlistfilter.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<FORM method="POST" action="?m=eventlist" name="filter">
<INPUT type="submit" class="hiddenbtn">
<INPUT type="HIDDEN" name="m" value="eventlist">
{clear_filter}
<span class="bold">{trans("Filter:")} </span>
{trans("Type:")}
<SELECT name="type[]" onchange="document.filter.submit();" class="lms-ui-multiselect lms-ui-multiselect-filter" multiple data-default-value="{trans("- all -")}">
Expand Down Expand Up @@ -58,6 +57,7 @@
<OPTION value="0"{if $filter.closed == "0"} selected{/if}>{trans("opened<!plural:event>")}</OPTION>
<OPTION value="1"{if $filter.closed == "1"} selected{/if}>{trans("closed<!plural:event>")}</OPTION>
</SELECT>
{persistent_filter}
</FORM>
</TD>
</TR>
Expand Down
4 changes: 1 addition & 3 deletions templates/default/node/nodelist.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
<!--// $Id$ //-->
<H1>{$layout.pagetitle}</H1>

{persistent_filter}

{$lastonline_limit = ConfigHelper::getConfig('phpui.lastonline_limit')}
<FORM method="get" action="?m={$layout.module}" name="choosefilter">
<p style="display: none;">
Expand Down Expand Up @@ -45,7 +43,6 @@ <H1>{$layout.pagetitle}</H1>
</TR>
<TR>
<TD colspan="5">
{clear_filter}
<SPAN class="bold">{trans("Filter:")}</SPAN>&nbsp;
<SPAN class="nobr">{trans("Status:")}
<SELECT SIZE="1" NAME="s" ONCHANGE="document.choosefilter.submit();">
Expand Down Expand Up @@ -108,6 +105,7 @@ <H1>{$layout.pagetitle}</H1>
{else}
<input type="hidden" name="p" value="-1">
{/if}
{persistent_filter}
</TD>
</TR>
{if $pagination->getTotal() != 0}
Expand Down
2 changes: 1 addition & 1 deletion templates/default/rt/rtfilter.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<INPUT type="submit" class="hiddenbtn">
<INPUT type="HIDDEN" name="m" value="rtqueueview">
<INPUT type="HIDDEN" name="page" value="1">
{clear_filter}
<span class="bold">{trans("Filter:")}</span>
<label class="nobr">
{trans("Queue:")}
Expand Down Expand Up @@ -116,6 +115,7 @@
<option value="{$smarty.const.RT_RIGHT_INDICATOR}" {if $filter.rights == $smarty.const.RT_RIGHT_INDICATOR} selected{/if}>{trans("yes")}</option>
</SELECT>
</label>
{persistent_filter}
</FORM>
</TD>
</TR>
Expand Down
2 changes: 0 additions & 2 deletions templates/default/rt/rtqueueview.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
<!-- $Id$ -->
<H1>{$layout.pagetitle}</H1>

{persistent_filter}

<TABLE class="lmsbox lms-ui-background-cycle">
<COLGROUP>
<COL style="width: 1%;">
Expand Down

0 comments on commit 75bc7cb

Please sign in to comment.