diff options
author | Igor Scheller <igor.scheller@igorshp.de> | 2017-12-27 13:36:38 +0100 |
---|---|---|
committer | Igor Scheller <igor.scheller@igorshp.de> | 2017-12-27 13:43:46 +0100 |
commit | 6ceec76e7d27798aeaf968afe2b800bffb9b30f1 (patch) | |
tree | 3aba4999aa50189203eb7a16e08a2dffc2b68550 | |
parent | 02b775684d643850e4a4ea3d9ac7028b6af3b469 (diff) |
feature request: filter angel types based on account settings, closes #362
-rw-r--r-- | includes/model/UserAngelTypes_model.php | 17 | ||||
-rw-r--r-- | includes/pages/user_shifts.php | 49 | ||||
-rw-r--r-- | locale/de_DE.UTF-8/LC_MESSAGES/default.mo | bin | 43684 -> 43711 bytes | |||
-rw-r--r-- | locale/de_DE.UTF-8/LC_MESSAGES/default.po | 8 | ||||
-rw-r--r-- | public/js/forms.js | 37 |
5 files changed, 80 insertions, 31 deletions
diff --git a/includes/model/UserAngelTypes_model.php b/includes/model/UserAngelTypes_model.php index 7b22e347..71901b97 100644 --- a/includes/model/UserAngelTypes_model.php +++ b/includes/model/UserAngelTypes_model.php @@ -226,3 +226,20 @@ function UserAngelType_by_User_and_AngelType($user, $angeltype) ] ); } + +/** + * Get an UserAngelTypes by user + * + * @param array $user + * @return array[]|null + */ +function UserAngelTypes_by_User($user) +{ + return DB::select(' + SELECT * + FROM `UserAngelTypes` + WHERE `user_id`=? + ', + [$user['UID']] + ); +} diff --git a/includes/pages/user_shifts.php b/includes/pages/user_shifts.php index 2c30c86a..d822054e 100644 --- a/includes/pages/user_shifts.php +++ b/includes/pages/user_shifts.php @@ -186,6 +186,7 @@ function view_user_shifts() $session->set('ShiftsFilter', $shiftsFilter); } + /** @var ShiftsFilter $shiftsFilter */ $shiftsFilter = $session->get('ShiftsFilter'); update_ShiftsFilter($shiftsFilter, in_array('user_shifts_admin', $privileges), $days); @@ -214,6 +215,11 @@ function view_user_shifts() info(render_user_arrived_hint()); } + $ownTypes = []; + foreach (UserAngelTypes_by_User($user) as $type) { + $ownTypes[] = (int)$type['angeltype_id']; + } + return page([ div('col-md-12', [ msg(), @@ -238,7 +244,13 @@ function view_user_shifts() $types, $shiftsFilter->getTypes(), 'types', - _('Angeltypes') . '<sup>1</sup>' + _('Angeltypes') . '<sup>1</sup>', + [ + button( + 'javascript: checkOwnTypes(\'selection_types\', ' . json_encode($ownTypes) . ')', + _('Own') + ), + ] ), 'filled_select' => make_select($filled, $shiftsFilter->getFilled(), 'filled', _('Occupancy')), 'task_notice' => @@ -269,12 +281,12 @@ function view_user_shifts() /** * Returns a hint for the user how the ical feature works. */ -function ical_hint() { +function ical_hint() +{ global $user; return heading( - _('iCal export'), 2) - . '<p>' . sprintf( + _('iCal export'), 2) . '<p>' . sprintf( _('Export of shown shifts. <a href="%s">iCal format</a> or <a href="%s">JSON format</a> available (please keep secret, otherwise <a href="%s">reset the api key</a>).'), page_link_to('ical', ['key' => $user['api_key']]), page_link_to('shifts_json_export', ['key' => $user['api_key']]), @@ -291,15 +303,23 @@ function get_ids_from_array($array) return $array['id']; } -function make_select($items, $selected, $name, $title = null) +/** + * @param array $items + * @param array $selected + * @param string $name + * @param string $title + * @param array $additionalButtons + * @return string + */ +function make_select($items, $selected, $name, $title = null, $additionalButtons = []) { - $html_items = []; + $htmlItems = []; if (isset($title)) { - $html_items[] = '<h4>' . $title . '</h4>' . "\n"; + $htmlItems[] = '<h4>' . $title . '</h4>' . "\n"; } foreach ($items as $i) { - $html_items[] = '<div class="checkbox">' + $htmlItems[] = '<div class="checkbox">' . '<label><input type="checkbox" name="' . $name . '[]" value="' . $i['id'] . '" ' . (in_array($i['id'], $selected) ? ' checked="checked"' : '') . ' > ' . $i['name'] . '</label>' @@ -307,11 +327,14 @@ function make_select($items, $selected, $name, $title = null) . '</div><br />'; } $html = '<div id="selection_' . $name . '" class="selection ' . $name . '">' . "\n"; - $html .= implode("\n", $html_items); - $html .= buttons([ - button('javascript: checkAll(\'selection_' . $name . '\', true)', _('All'), ''), - button('javascript: checkAll(\'selection_' . $name . '\', false)', _('None'), '') - ]); + $html .= implode("\n", $htmlItems); + + $buttons = []; + $buttons[] = button('javascript: checkAll(\'selection_' . $name . '\', true)', _('All')); + $buttons[] = button('javascript: checkAll(\'selection_' . $name . '\', false)', _('None')); + $buttons = array_merge($buttons, $additionalButtons); + $html .= buttons($buttons); + $html .= '</div>' . "\n"; return $html; } diff --git a/locale/de_DE.UTF-8/LC_MESSAGES/default.mo b/locale/de_DE.UTF-8/LC_MESSAGES/default.mo Binary files differindex a58c3a05..b7f8e941 100644 --- a/locale/de_DE.UTF-8/LC_MESSAGES/default.mo +++ b/locale/de_DE.UTF-8/LC_MESSAGES/default.mo diff --git a/locale/de_DE.UTF-8/LC_MESSAGES/default.po b/locale/de_DE.UTF-8/LC_MESSAGES/default.po index a093149f..4d6a5807 100644 --- a/locale/de_DE.UTF-8/LC_MESSAGES/default.po +++ b/locale/de_DE.UTF-8/LC_MESSAGES/default.po @@ -1,8 +1,8 @@ msgid "" msgstr "" "Project-Id-Version: Engelsystem 2.0\n" -"POT-Creation-Date: 2017-12-27 12:17+0100\n" -"PO-Revision-Date: 2017-12-27 12:17+0100\n" +"POT-Creation-Date: 2017-12-27 13:38+0100\n" +"PO-Revision-Date: 2017-12-27 13:38+0100\n" "Last-Translator: msquare <msquare@notrademark.de>\n" "Language-Team: \n" "Language: de_DE\n" @@ -1867,6 +1867,10 @@ msgstr "belegt" msgid "free" msgstr "frei" +#: /Users/msquare/workspace/projects/engelsystem/includes/pages/user_shifts.php:251 +msgid "Own" +msgstr "Eigene" + #: /Users/msquare/workspace/projects/engelsystem/includes/pages/user_shifts.php:243 msgid "Occupancy" msgstr "Belegung" diff --git a/public/js/forms.js b/public/js/forms.js index c7f4a095..1efd80bb 100644 --- a/public/js/forms.js +++ b/public/js/forms.js @@ -1,20 +1,25 @@ /** - * Runs through the DOM under the element with the given id, finds all - * checkboxes and sets them to the wanted state. + * Sets all checkboxes to the wanted state * - * @param String - * id Id of the element containing all the checkboxes - * @param Boolean - * checked True if the checkboxes should be checked + * @param {string} id Id of the element containing all the checkboxes + * @param {bool} checked True if the checkboxes should be checked */ function checkAll(id, checked) { - var obj = document.getElementById(id); - var boxes = obj.getElementsByTagName("input"); - for (var i = 0; i < boxes.length; i++) { - if (boxes[i].type === "checkbox" && !boxes[i].disabled) { - boxes[i].checked = checked; - } - } + $("#" + id + " input[type='checkbox']").each(function () { + this.checked = checked; + }); +} + +/** + * Sets the checkboxes according to the given type + * + * @param {string} id The elements ID + * @param {list} shifts_list A list of numbers + */ +function checkOwnTypes(id, shifts_list) { + $('#' + id + ' input[type=checkbox]').each(function () { + this.checked = $.inArray(parseInt(this.value), shifts_list); + }); } /** @@ -82,8 +87,8 @@ $(function () { $("input[type='submit']").prop("readonly", true).addClass("disabled"); return true; }); - - $(".dropdown-menu").css("max-height", function() { - return ($(window).height() - 50) + "px"; + + $(".dropdown-menu").css("max-height", function () { + return ($(window).height() - 50) + "px"; }).css("overflow-y", "scroll"); }); |