-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhancement: introduced persistent filter support (LMS+ #620)
- Loading branch information
Showing
2 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* LMS version 1.11-git | ||
* | ||
* (C) Copyright 2001-2018 LMS Developers | ||
* | ||
* Please, see the doc/AUTHORS for more information about authors! | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License Version 2 as | ||
* published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | ||
* USA. | ||
* | ||
* $Id$ | ||
*/ | ||
|
||
$(function() { | ||
$('.lms-ui-filter-selection').change(function () { | ||
if ($(this).val() == -1) { | ||
$(this).next('.lms-ui-filter-name').show(); | ||
} else { | ||
$(this).next('.lms-ui-filter-name').hide(); | ||
} | ||
}); | ||
|
||
$('.lms-ui-filter-modify-button').click(function () { | ||
var form = $(this).closest('form.lms-ui-persistent-filter'); | ||
var selectelem = $(this).siblings('.lms-ui-filter-selection') | ||
var selection = selectelem.val(); | ||
var name = $(this).siblings('.lms-ui-filter-name').val(); | ||
if (!selection.length || (selection == -1 && name.length < 5)) { | ||
return false; | ||
} | ||
$.ajax(form.attr('action'), { | ||
method: "POST", | ||
data: { | ||
'persistent-filter': 1, | ||
api: 1, | ||
action: 'modify', | ||
name: (selection == -1 ? name : selection) | ||
}, | ||
success: function (data) { | ||
selectelem.find('option:nth-child(n+3)').remove(); | ||
$.each(data, function (index, value) { | ||
selectelem.append('<option value="' + value + '">' + value + '</option>'); | ||
}); | ||
selectelem.val(selection == -1 ? name : selection); | ||
} | ||
}); | ||
return false; | ||
}); | ||
|
||
$('.lms-ui-filter-delete-button').click(function () { | ||
var form = $(this).closest('form.lms-ui-persistent-filter'); | ||
var selectelem = $(this).siblings('.lms-ui-filter-selection') | ||
var selection = selectelem.val(); | ||
if (!selection.length || selection == -1) { | ||
return false; | ||
} | ||
$.ajax(form.attr('action'), { | ||
method: "POST", | ||
data: { | ||
'persistent-filter': 1, | ||
api: 1, | ||
action: 'delete', | ||
name: selection | ||
}, | ||
success: function (data) { | ||
selectelem.find('option:nth-child(n+3)').remove(); | ||
$.each(data, function (index, value) { | ||
selectelem.append('<option value="' + value + '">' + value + '</option>'); | ||
}); | ||
} | ||
}); | ||
return false; | ||
}); | ||
|
||
$('.lms-ui-filter-apply-button').click(function () { | ||
var form = $(this).closest('form.lms-ui-persistent-filter'); | ||
var name = $(this).siblings('.lms-ui-filter-selection').val(); | ||
form.find('[name="name"]').val(name); | ||
form.attr('action', form.attr('action').replace('&api=1', '')); | ||
form.submit(); | ||
return false; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
/** | ||
* LMS version 1.11-git | ||
* | ||
* (C) Copyright 2001-2018 LMS Developers | ||
* | ||
* Please, see the doc/AUTHORS for more information about authors! | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License Version 2 as | ||
* published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | ||
* USA. | ||
* | ||
* $Id$ | ||
*/ | ||
|
||
function smarty_function_persistent_filter($params, $template) { | ||
$layout = $template->getTemplateVars('layout'); | ||
$persistent_filters = $template->getTemplateVars('persistent_filters'); | ||
|
||
$filters = ''; | ||
foreach ($persistent_filters as $filter_name => $filter) | ||
$filters .= '<option value="' . $filter_name . '">' . $filter_name . '</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=""> | ||
<div class="lms-ui-persistent-filter"> | ||
' . trans("Persistent filter:") . ' | ||
<button class="lms-ui-button lms-ui-filter-apply-button" > | ||
' . trans("<!filter>Apply") . ' | ||
</button> | ||
<button class="lms-ui-button lms-ui-filter-modify-button" > | ||
' . trans("<!filter>Update") . ' | ||
</button> | ||
<select class="lms-ui-filter-selection"> | ||
<option value="">' . trans("<!filter>- none -") . '</option> | ||
<option value="-1">' . trans("<!filter>- new -") . '</option> | ||
' . $filters . ' | ||
</select> | ||
<input type="text" size="20" class="lms-ui-filter-name" pattern="^.{5,}$"> | ||
<button class="lms-ui-button lms-ui-filter-delete-button" > | ||
' . trans("<!filter>Delete") . ' | ||
</button> | ||
</div> | ||
</form>'; | ||
} |