Files
firefly-iii/public/js/ff/transactions/create.js

131 lines
3.8 KiB
JavaScript
Raw Normal View History

2016-01-29 18:39:50 +01:00
/*
* create.js
2016-04-01 16:46:11 +02:00
* Copyright (C) 2016 thegrumpydictator@gmail.com
2016-01-29 18:39:50 +01:00
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
2015-06-03 17:32:50 +02:00
/* globals what:true, $, doSwitch, txt, middleCrumbName, title,button, middleCrumbUrl, piggiesLength, breadcrumbs */
2015-02-24 21:10:25 +01:00
$(document).ready(function () {
2015-05-24 20:41:14 +02:00
"use strict";
2015-03-26 22:52:49 +01:00
2016-01-29 18:39:50 +01:00
// respond to switch buttons when
// creating stuff:
2015-06-03 17:32:50 +02:00
if (doSwitch) {
updateButtons();
updateForm();
updateLayout();
}
});
function updateLayout() {
"use strict";
$('#subTitle').text(title[what]);
$('.breadcrumb .active').text(breadcrumbs[what]);
$('.breadcrumb li:nth-child(2)').html('<a href="' + middleCrumbUrl[what] + '">' + middleCrumbName[what] + '</a>');
2015-06-20 21:55:55 +02:00
$('#transaction-btn').text(button[what]);
2015-06-03 17:32:50 +02:00
}
function updateForm() {
"use strict";
$('input[name="what"]').val(what);
switch (what) {
case 'withdrawal':
2016-04-29 17:29:13 +02:00
// show source_id and dest_name:
$('#source_account_id_holder').show();
$('#destination_account_name_holder').show();
// hide others:
$('#source_account_name_holder').hide();
$('#destination_account_id_holder').hide();
// show budget:
2015-06-03 17:32:50 +02:00
$('#budget_id_holder').show();
2016-04-29 17:29:13 +02:00
// hide piggy bank:
$('#piggy_bank_id_holder').hide();
2015-06-03 17:32:50 +02:00
2016-04-29 17:29:13 +02:00
// copy destination account name to
// source account name:
if ($('#ffInput_destination_account_name').val().length > 0) {
$('#ffInput_source_account_name').val($('#ffInput_destination_account_name').val());
2015-06-03 17:32:50 +02:00
}
break;
case 'deposit':
2016-04-29 17:29:13 +02:00
// show source_name and dest_id:
$('#source_account_name_holder').show();
$('#destination_account_id_holder').show();
// hide others:
$('#source_account_id_holder').hide();
$('#destination_account_name_holder').hide();
// hide budget
2015-06-03 17:32:50 +02:00
$('#budget_id_holder').hide();
2016-04-29 17:29:13 +02:00
// hide piggy bank
2015-06-03 17:32:50 +02:00
$('#piggy_bank_id_holder').hide();
2016-04-29 17:29:13 +02:00
if ($('#ffInput_source_account_name').val().length > 0) {
$('#ffInput_destination_account_name').val($('#ffInput_source_account_name').val());
2015-06-03 17:32:50 +02:00
}
break;
case 'transfer':
2016-04-29 17:29:13 +02:00
// show source_id and dest_id:
$('#source_account_id_holder').show();
$('#destination_account_id_holder').show();
// hide others:
$('#source_account_name_holder').hide();
$('#destination_account_name_holder').hide();
// hide budget
2015-06-03 17:32:50 +02:00
$('#budget_id_holder').hide();
if (piggiesLength === 0) {
$('#piggy_bank_id_holder').hide();
} else {
$('#piggy_bank_id_holder').show();
}
break;
}
}
function updateButtons() {
"use strict";
$('.switch').each(function (i, v) {
var button = $(v);
// remove click event:
button.unbind('click');
// new click event:
button.bind('click', clickButton);
if (button.data('what') == what) {
button.removeClass('btn-default').addClass('btn-info').html('<i class="fa fa-fw fa-check"></i> ' + txt[button.data('what')]);
console.log('Now displaying form for ' + what);
} else {
button.removeClass('btn-info').addClass('btn-default').text(txt[button.data('what')]);
}
});
}
function clickButton(e) {
"use strict";
var button = $(e.target);
var newWhat = button.data('what');
if (newWhat != what) {
what = newWhat;
updateButtons();
updateForm();
updateLayout();
}
return false;
}