/* * create.js * Copyright (c) 2017 thegrumpydictator@gmail.com * * This file is part of Firefly III. * * Firefly III is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Firefly III 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 Firefly III. If not, see . */ /** global: Modernizr, currencies */ $(document).ready(function () { "use strict"; if (!Modernizr.inputtypes.date) { $('input[type="date"]').datepicker( { dateFormat: 'yy-mm-dd' } ); } initializeButtons(); initializeAutoComplete(); respondToFirstDateChange(); respondToRepetitionEnd(); $('.switch-button').on('click', switchTransactionType); $('#ffInput_repetition_end').on('change', respondToRepetitionEnd); $('#ffInput_first_date').on('change', respondToFirstDateChange); $('#calendar-link').on('click', showRepCalendar); }); /** * */ function showRepCalendar() { // pre-append URL with repetition info: var newEventsUri = eventsUri + '?type=' + $('#ffInput_repetition_type').val(); newEventsUri += '&skip=' + $('#ffInput_skip').val(); newEventsUri += '&ends=' + $('#ffInput_repetition_end').val(); newEventsUri += '&endDate=' + $('#ffInput_repeat_until').val(); newEventsUri += '&reps=' + $('#ffInput_repetitions').val(); $('#recurring_calendar').fullCalendar( { defaultDate: '2018-06-13', editable: false, height: 400, width: 200, contentHeight: 300, aspectRatio: 1.25, eventLimit: true, // allow "more" link when too many events events: newEventsUri }); $('#calendarModal').modal('show'); return false; } function respondToRepetitionEnd() { var obj = $('#ffInput_repetition_end'); var value = obj.val(); switch (value) { case 'forever': $('#repeat_until_holder').hide(); $('#repetitions_holder').hide(); break; case 'until_date': $('#repeat_until_holder').show(); $('#repetitions_holder').hide(); break; case 'times': $('#repeat_until_holder').hide(); $('#repetitions_holder').show(); break; } } function respondToFirstDateChange() { var obj = $('#ffInput_first_date'); var select = $('#ffInput_repetition_type'); var date = obj.val(); select.prop('disabled', true); $.getJSON(suggestUri, {date: date}).fail(function () { console.error('Could not load repetition suggestions'); alert('Could not load repetition suggestions'); }).done(parseRepetitionSuggestions); } function parseRepetitionSuggestions(data) { var select = $('#ffInput_repetition_type'); select.empty(); for (var k in data) { if (data.hasOwnProperty(k)) { select.append($('