GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 37b02e...ebbbe1 )
by James
08:59
created

public/js/ff/transactions/single/create.js (3 issues)

1
/*
2
 * create.js
3
 * Copyright (c) 2017 [email protected]
4
 *
5
 * This file is part of Firefly III.
6
 *
7
 * Firefly III is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation, either version 3 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * Firefly III is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
19
 */
20
21
/** global: currencyInfo, overruleCurrency,useAccountCurrency, accountInfo, what,Modernizr, title, breadcrumbs, middleCrumbName, button, piggiesLength, txt, middleCrumbUrl,exchangeRateInstructions, convertForeignToNative, convertSourceToDestination, selectsForeignCurrency, accountInfo */
22
23
$(document).ready(function () {
24
    "use strict";
25
26
    // hide ALL exchange things and AMOUNT fields
27
    $('#exchange_rate_instruction_holder').hide();
28
    $('#native_amount_holder').hide();
29
    $('#amount_holder').hide();
30
    $('#source_amount_holder').hide();
31
    $('#destination_amount_holder').hide();
32
33
    // respond to switch buttons (first time always triggers)
34
    updateButtons();
35
    updateForm();
36
    updateLayout();
37
    updateDescription();
38
39
40
    // when user changes source account or destination, native currency may be different.
41
    $('select[name="source_account_id"]').on('change', function() {
42
        selectsDifferentSource();
43
        // do something for transfers:
44
        validateCurrencyForTransfer();
45
    });
46
    $('select[name="destination_account_id"]').on('change', function() {
47
        selectsDifferentDestination();
48
        // do something for transfers:
49
        validateCurrencyForTransfer();
50
    });
51
52
    //$('select[name="source_account_id"]').on('change', updateNativeCurrency);
53
    //$('select[name="destination_account_id"]').on('change', updateNativeCurrency);
54
55
    // convert foreign currency to native currency (when input changes, exchange rate)
56
    $('#ffInput_amount').on('change', convertForeignToNative);
57
58
    // convert source currency to destination currency (slightly different routine for transfers)
59
    $('#ffInput_source_amount').on('change', convertSourceToDestination);
60
61
    // when user selects different currency,
62
    $('.currency-option').on('click', selectsForeignCurrency);
63
    $('#ffInput_description').focus();
64
});
65
66
/**
67
 * The user selects a different source account. Applies to withdrawals
68
 * and transfers.
69
 */
70
function selectsDifferentSource() {
71
    if (what === "deposit") {
72
        console.log('User is making a deposit. Don\'t bother with source.');
0 ignored issues
show
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
73
        $('input[name="source_account_currency"]').val("0");
74
        return;
75
    }
76
    // store original currency ID of the selected account in a separate var:
77
    var sourceId = $('select[name="source_account_id"]').val();
78
    var sourceCurrency = accountInfo[sourceId].preferredCurrency;
79
    $('input[name="source_account_currency"]').val(sourceCurrency);
80
    console.log('selectsDifferenctSource(): Set source account currency to ' + sourceCurrency);
81
82
    // change input thing:
83
    $('.currency-option[data-id="' + sourceCurrency + '"]').click();
84
    $('[data-toggle="dropdown"]').parent().removeClass('open');
85
    $('select[name="source_account_id"]').focus();
86
}
87
88
/**
89
 * The user selects a different source account. Applies to withdrawals
90
 * and transfers.
91
 */
92
function selectsDifferentDestination() {
93
    if (what === "withdrawal") {
94
        console.log('User is making a withdrawal. Don\'t bother with destination.');
0 ignored issues
show
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
95
        $('input[name="destination_account_currency"]').val("0");
96
        return;
97
    }
98
    // store original currency ID of the selected account in a separate var:
99
    var destinationId = $('select[name="destination_account_id"]').val();
100
    var destinationCurrency = accountInfo[destinationId].preferredCurrency;
101
    $('input[name="destination_account_currency"]').val(destinationCurrency);
102
    console.log('selectsDifferentDestination(): Set destinationId account currency to ' + destinationCurrency);
103
104
    // change input thing:
105
    $('.currency-option[data-id="' + destinationCurrency + '"]').click();
106
    $('[data-toggle="dropdown"]').parent().removeClass('open');
107
    $('select[name="destination_account_id"]').focus();
108
}
109
110
111
/**
112
 * This function generates a small helper text to explain the user
113
 * that they have selected a foreign currency.
114
 * @returns {XML|string|void}
115
 */
116
function getExchangeInstructions() {
117
    var foreignCurrencyId = parseInt($('input[name="amount_currency_id_amount"]').val());
118
    var selectedAccountId = getAccountId();
119
    var nativeCurrencyId = parseInt(accountInfo[selectedAccountId].preferredCurrency);
120
121
    var text = exchangeRateInstructions.replace('@name', accountInfo[selectedAccountId].name);
122
    text = text.replace(/@native_currency/g, currencyInfo[nativeCurrencyId].name);
123
    text = text.replace(/@foreign_currency/g, currencyInfo[foreignCurrencyId].name);
124
    return text;
125
}
126
127
/**
128
 *
129
 */
130
function updateDescription() {
131
    $.getJSON('json/transaction-journals/' + what).done(function (data) {
132
        $('input[name="description"]').typeahead('destroy').typeahead({source: data, autoSelect: false});
133
    });
134
    $('#ffInput_description').focus();
135
}
136
137
/**
138
 *
139
 */
140
function updateLayout() {
141
    "use strict";
142
    $('#subTitle').text(title[what]);
143
    $('.breadcrumb .active').text(breadcrumbs[what]);
144
    $('.breadcrumb li:nth-child(2)').html('<a href="' + middleCrumbUrl[what] + '">' + middleCrumbName[what] + '</a>');
145
    $('#transaction-btn').text(button[what]);
146
}
147
148
/**
149
 *
150
 */
151
function updateForm() {
152
    "use strict";
153
154
    $('input[name="what"]').val(what);
155
156
    var destName = $('#ffInput_destination_account_name');
157
    var srcName = $('#ffInput_source_account_name');
158
159
    switch (what) {
160
161
        case 'withdrawal':
162
            // show source_id and dest_name
163
            document.getElementById('source_account_id_holder').style.display = 'block';
164
            document.getElementById('destination_account_name_holder').style.display = 'block';
165
166
            // hide others:
167
            document.getElementById('source_account_name_holder').style.display = 'none';
168
            document.getElementById('destination_account_id_holder').style.display = 'none';
169
            document.getElementById('budget_id_holder').style.display = 'block';
170
171
            // hide piggy bank:
172
            document.getElementById('piggy_bank_id_holder').style.display = 'none';
173
174
            // copy destination account name to source account name:
175
            if (destName.val().length > 0) {
176
                srcName.val(destName.val());
177
            }
178
179
            // exchange / foreign currencies:
180
            // hide explanation, hide source and destination amounts, show normal amount
181
            document.getElementById('exchange_rate_instruction_holder').style.display = 'none';
182
            document.getElementById('source_amount_holder').style.display = 'none';
183
            document.getElementById('destination_amount_holder').style.display = 'none';
184
            document.getElementById('amount_holder').style.display = 'block';
185
            break;
186
        case 'deposit':
187
            // show source_name and dest_id:
188
            document.getElementById('source_account_name_holder').style.display = 'block';
189
            document.getElementById('destination_account_id_holder').style.display = 'block';
190
191
            // hide others:
192
            document.getElementById('source_account_id_holder').style.display = 'none';
193
            document.getElementById('destination_account_name_holder').style.display = 'none';
194
195
            // hide budget
196
            document.getElementById('budget_id_holder').style.display = 'none';
197
198
            // hide piggy bank
199
            document.getElementById('piggy_bank_id_holder').style.display = 'none';
200
201
            // copy name
202
            if (srcName.val().length > 0) {
203
                destName.val(srcName.val());
204
            }
205
206
            // exchange / foreign currencies:
207
            // hide explanation, hide source and destination amounts, show amount
208
            document.getElementById('exchange_rate_instruction_holder').style.display = 'none';
209
            document.getElementById('source_amount_holder').style.display = 'none';
210
            document.getElementById('destination_amount_holder').style.display = 'none';
211
            document.getElementById('amount_holder').style.display = 'block';
212
            break;
213
        case 'transfer':
214
            // show source_id and dest_id:
215
            document.getElementById('source_account_id_holder').style.display = 'block';
216
            document.getElementById('destination_account_id_holder').style.display = 'block';
217
218
            // hide others:
219
            document.getElementById('source_account_name_holder').style.display = 'none';
220
            document.getElementById('destination_account_name_holder').style.display = 'none';
221
222
            // hide budget
223
            document.getElementById('budget_id_holder').style.display = 'none';
224
225
            // optional piggies
226
            var showPiggies = 'block';
227
            if (piggiesLength === 0) {
228
                showPiggies = 'none';
229
            }
230
            document.getElementById('piggy_bank_id_holder').style.display = showPiggies;
231
            break;
232
        default:
233
            break;
234
    }
235
    // get instructions all the time.
236
    //updateNativeCurrency(useAccountCurrency);
237
    console.log('End of update form');
0 ignored issues
show
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
238
    selectsDifferentSource();
239
    selectsDifferentDestination();
240
    selectsForeignCurrency();
241
242
    // do something for transfers:
243
    validateCurrencyForTransfer();
244
}
245
246
/**
247
 *
248
 */
249
function updateButtons() {
250
    "use strict";
251
    $('.switch').each(function (i, v) {
252
        var button = $(v);
253
254
        // remove click event:
255
        button.unbind('click');
256
        // new click event:
257
        button.bind('click', clickButton);
258
259
        if (button.data('what') === what) {
260
            button.removeClass('btn-default').addClass('btn-info').html('<i class="fa fa-fw fa-check"></i> ' + txt[button.data('what')]);
261
        } else {
262
            button.removeClass('btn-info').addClass('btn-default').text(txt[button.data('what')]);
263
        }
264
    });
265
}
266
267
/**
268
 *
269
 * @param e
270
 * @returns {boolean}
271
 */
272
function clickButton(e) {
273
    "use strict";
274
    var button = $(e.target);
275
    var newWhat = button.data('what');
276
    if (newWhat !== what) {
277
        what = newWhat;
278
        updateButtons();
279
        updateForm();
280
        updateLayout();
281
        updateDescription();
282
    }
283
    return false;
284
}
285
286
/**
287
 * Get accountID based on some meta info.
288
 */
289
function getAccountId() {
290
    if (what === "withdrawal") {
291
        return $('select[name="source_account_id"]').val();
292
    }
293
    if (what === "deposit" || what === "transfer") {
294
        return $('select[name="destination_account_id"]').val();
295
    }
296
    return undefined;
297
}
298