Newer
Older
$(document).ready(function()
{
$('#modalConfirmDelete').modal('open');
// open filter modal if corresponding anchor is in url (originating from hotkeys.js)
if(window.location.href.endsWith('#modalFilter'))
{
$('#modalFilter').modal('open');
}
if($("#transaction-name").length)
{
document.getElementById('transaction-name').focus();
}
if($("#transaction-description").length)
{
$("#transaction-description").characterCounter();
}
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
{
if(typeof pickerEndDate !== "undefined")
{
pickerEndDate.destroy();
pickerEndDate = createDatePickerEnd(this.date, pickerEndDate.date);
}

Robert Goldmann
committed
}
});

Robert Goldmann
committed
// picker end date
if(typeof endDate !== "undefined")
{
var pickerEndDate = createDatePickerEnd(pickerStartDate.date, endDate);
}

Robert Goldmann
committed
}

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',
// select corresponding radio button
var endDate = document.getElementById("repeating-end-date");
endDate.checked = true;
}
}

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

Robert Goldmann
committed
if($(transactionRepeatingModifierID).length)
$(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)
$(transactionRepeatingEndAfterXTimesInputID).on('change keydown paste input', function()
{

Robert Goldmann
committed
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
});
}
// 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)
{
if(e.target.nodeName === 'TEXTAREA' || e.target.id === 'search')
{
return true;
}
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
});
// scroll to highlighted transaction
var highlightedSmall = document.getElementById("highlighted-small");
var highlightedLarge = document.getElementById("highlighted-large");
if(highlightedSmall !== undefined && highlightedSmall != null && !isHidden(highlightedSmall))
{
$('html, body').animate({
scrollTop: $(highlightedSmall).offset().top
}, 500);
}
else if(highlightedLarge !== undefined && highlightedLarge != null && !isHidden(highlightedLarge))
{
$('html, body').animate({
scrollTop: $(highlightedLarge).offset().top
}, 500);
}
});
function isHidden(el)
{
var style = window.getComputedStyle(el);
return (style.display === 'none' || style.display === 'none !important')
}

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);
{
document.getElementById(hiddenID).value = "";
}
return false;
removeTooltip(ID);
{
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());
// description
var description = document.getElementById('transaction-description').value;
if(description.length > 250)
{
return false;
}
// 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($(transactionRepeatingModifierID).length)
if(!validateNumber($(transactionRepeatingModifierID).val(), transactionRepeatingModifierID.substr(1), "hidden-" + transactionRepeatingModifierID.substr(1), numberValidationMessage))
// 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))
{
}
endInput.value = $(transactionRepeatingEndAfterXTimesInputID).val();
}
{
endInput.value = $("#transaction-repeating-end-date-input").val();
}