Newer
Older
$('#modalConfirmDelete').modal('open');
if($(".datepicker").length)
{

Robert Goldmann
committed
var pickerStartDate = M.Datepicker.init(document.getElementById('transaction-datepicker'), {

Robert Goldmann
committed
firstDay: 1,
showClearBtn: false,
setDefaultDate: true,

Robert Goldmann
committed
defaultDate: startDate,
i18n: {
// Strings and translations
months: monthNames,
monthsShort: monthNamesShort,
weekdays: weekDays,
weekdaysShort: weekDaysShort,
weekdaysAbbrev: weekDaysLetters,
// Buttons
done: buttonClose,
// Accessibility labels
labelMonthNext: '>',
labelMonthPrev: '<'
},

Robert Goldmann
committed
// Formats
format: 'dd.mm.yyyy',
formatSubmit: 'dd.mm.yyyy',

Robert Goldmann
committed
{

Robert Goldmann
committed
pickerEndDate.destroy();
pickerEndDate = createDatePickerEnd(this.date, pickerEndDate.date);

Robert Goldmann
committed
}
});

Robert Goldmann
committed
// picker end date

Robert Goldmann
committed
var pickerEndDate = createDatePickerEnd(pickerStartDate.date, endDate);
}

Robert Goldmann
committed

Robert Goldmann
committed
function createDatePickerEnd(minDate, selectedDate)
{
if(selectedDate < minDate)

Robert Goldmann
committed
{

Robert Goldmann
committed
selectedDate = minDate;

Robert Goldmann
committed
}
return M.Datepicker.init(document.getElementById('transaction-repeating-end-date-input'), {
firstDay: 1,
showClearBtn: false,
setDefaultDate: true,

Robert Goldmann
committed
minDate: minDate,

Robert Goldmann
committed
defaultDate: selectedDate,
i18n: {
// Strings and translations
months: monthNames,
monthsShort: monthNamesShort,
weekdays: weekDays,
weekdaysShort: weekDaysShort,
weekdaysAbbrev: weekDaysLetters,
// Buttons
done: buttonClose,
// Accessibility labels
labelMonthNext: '>',
labelMonthPrev: '<'
},
// Formats
format: 'dd.mm.yyyy',
formatSubmit: 'dd.mm.yyyy',
onSelect: function ()
{
// select corresponding radio button
var endDate = document.getElementById("repeating-end-date");
endDate.checked = true;
}
}

Robert Goldmann
committed
if($('#transaction-amount').length)
{

Robert Goldmann
committed
$('#transaction-amount').on('change keydown paste input', function() {
validateAmount($(this).val());
});
}

Robert Goldmann
committed
if($(transactionRepeatingModifierID).length)

Robert Goldmann
committed
$(transactionRepeatingModifierID).on('change keydown paste input', function() {
// substr(1) removes "#" at the beginning

Robert Goldmann
committed
validateNumber($(this).val(), transactionRepeatingModifierID.substr(1), "hidden-" + transactionRepeatingModifierID.substr(1), numberValidationMessage);
});
}

Robert Goldmann
committed
if($(transactionRepeatingEndAfterXTimesInputID).length)

Robert Goldmann
committed
$(transactionRepeatingEndAfterXTimesInputID).on('change keydown paste input', function() {
validateNumber($(this).val(), transactionRepeatingEndAfterXTimesInputID.substr(1), null, numberValidationMessage);
// select corresponding radio button
var endAfterXTimes = document.getElementById("repeating-end-after-x-times");
endAfterXTimes.checked = true;
if($(".chips-autocomplete").length)
{
$('.chips-autocomplete').chips({
autocompleteOptions: {
data: tagAutoComplete,
limit: Infinity,
minLength: 1
},

Robert Goldmann
committed
placeholder: tagsPlaceholder,
data: initialTags
$('#enableRepeating').change(function(){
if($(this).is(":checked"))
{

Robert Goldmann
committed
$('#transaction-repeating-modifier-row').show();
$('#transaction-repeating-end').show();

Robert Goldmann
committed
$('#transaction-repeating-modifier-row').hide();
$('#transaction-repeating-end').hide();
}
});
// fire change listener on page load
$('#enableRepeating').trigger("change");
// prevent form submit on enter (otherwise tag functionality will be hard to use)
$(document).on("keypress", 'form', function (e) {
var code = e.keyCode || e.which;
if((code === 13) && e.target.nodeName!=='TEXTAREA') {
e.preventDefault();
return false;
}
});
$('.buttonIncome').click(function()
$('.buttonIncome').each(function () {
$(this).removeClass("budgetmaster-grey");
$(this).removeClass("budgetmaster-text-isPayment");
$(this).addClass("budgetmaster-green");
});
$('.buttonExpenditure').each(function () {
$(this).removeClass("budgetmaster-red");
$(this).addClass("budgetmaster-grey");
$(this).addClass("budgetmaster-text-isPayment");
});
document.getElementById("input-isPayment").value = 0;
});
$('.buttonExpenditure').click(function()
$('.buttonExpenditure').each(function () {
$(this).removeClass("budgetmaster-grey");
$(this).removeClass("budgetmaster-text-isPayment");
$(this).addClass("budgetmaster-red");
});
$('.buttonIncome').each(function () {
$(this).removeClass("budgetmaster-green");
$(this).addClass("budgetmaster-grey");
$(this).addClass("budgetmaster-text-isPayment");
});
document.getElementById("input-isPayment").value = 1;
});
M.FloatingActionButton.init(document.querySelectorAll('.fixed-action-btn'), {
direction: 'bottom',
hoverEnabled: false
});
});

Robert Goldmann
committed
var transactionRepeatingModifierID = "#transaction-repeating-modifier";
var transactionRepeatingEndAfterXTimesInputID = "#transaction-repeating-end-after-x-times-input";
AMOUNT_REGEX = new RegExp("^-?\\d+(,\\d+)?(\\.\\d+)?$");
NUMBER_REGEX = new RegExp("^\\d+$");
ALLOWED_CHARACTERS = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ",", "."];
function validateAmount(text)
{

Robert Goldmann
committed
var id = "transaction-amount";
if(text.match(AMOUNT_REGEX) == null)
{
addTooltip(id, amountValidationMessage);
document.getElementById("hidden-" + id).value = "";
}
else
{
var amount = parseFloat(text.replace(",", ".")) * 100;
document.getElementById("hidden-" + id).value = amount.toFixed(0);
}
function validateNumber(text, ID, hiddenID, message)
{
if(text.match(NUMBER_REGEX) == null)
{
addTooltip(ID, message);
if (hiddenID != null)
{
document.getElementById(hiddenID).value = "";
}
return false;
removeTooltip(ID);
if (hiddenID != null)
{
document.getElementById(hiddenID).value = parseInt(text);
}
return true;
}
}
function addTooltip(id, message)
{
var element = document.getElementById(id);
removeClass(element, "validate");
removeClass(element, "valid");
addClass(element, "tooltipped");
addClass(element, "invalid");
element.dataset.tooltip=message;
element.dataset.position="bottom";
element.dataset.delay="50";

Robert Goldmann
committed
M.Tooltip.init(element);
}
function removeTooltip(id)
{
var element = document.getElementById(id);
removeClass(element, "validate");
removeClass(element, "invalid");
removeClass(element, "tooltipped");
addClass(element, "valid");

Robert Goldmann
committed
var tooltip = M.Tooltip.getInstance(element);
if(tooltip !== undefined)
{
tooltip.destroy();
}
function validateForm()
{
// amount

Robert Goldmann
committed
validateAmount($('#transaction-amount').val());
// handle tags
if($(".chips-autocomplete").length)
var tags = M.Chips.getInstance(document.querySelector('.chips-autocomplete')).chipsData;
var parent = document.getElementById("hidden-transaction-tags");
for (var i = 0; i < tags.length; i++)
{
var input = document.createElement("input");
input.setAttribute("type", "hidden");
input.setAttribute("name", "tags[" + i + "].name");
input.setAttribute("value", tags[i].tag);
parent.appendChild(input);
}
if($("#enableRepeating").length)
if(document.getElementById("enableRepeating").checked)
if(!validateNumber($(transactionRepeatingModifierID).val(), transactionRepeatingModifierID.substr(1), "hidden-" + transactionRepeatingModifierID.substr(1), numberValidationMessage))
{
return false;
}
// handle repeating end
var endNever = document.getElementById("repeating-end-never");
var endAfterXTimes = document.getElementById("repeating-end-after-x-times");
var endDate = document.getElementById("repeating-end-date");
var endInput = document.getElementById("hidden-transaction-repeating-end-value");
if(endNever.checked)
{
return true;
}
if(endAfterXTimes.checked)
{
if(!validateNumber($(transactionRepeatingEndAfterXTimesInputID).val(), transactionRepeatingEndAfterXTimesInputID.substr(1), null, numberValidationMessage))
{
return false;
}
endInput.value = $(transactionRepeatingEndAfterXTimesInputID).val();
}
if(endDate.checked)
{
endInput.value = $("#transaction-repeating-end-date-input").val();
}
}
{
document.getElementById("hidden-" + transactionRepeatingModifierID.substr(1)).value = -1;
}