PageSourceSearch

https://easyfinance.ru/js/operation.js

js easyfinance.ru collected 2026-10-03 20:34:48 UTC 25,802 bytes, 599 lines download raw bytes

1// {* $Id: operation.js 137 2009-08-10 16:00:50Z ukko $ *}
2/*var catlast ;
3 var datelast ;*/
4
5/**
6 * Функция очищает форму ввода операции
7 */
8function clearForm() {
9    $('#op_type,#op_category,#op_target').val(0);
10    $('#op_amount,#op_AccountForTransfer,#op_comment,#op_tags,#op_date').val('');
11    $('span#op_amount_target, span#op_amount_done, span#op_forecast_done, span#op_percent_done').text();
12    $('#op_close').removeAttr('checked');
13    $('form').attr('action', '/operation/add/');
14    $('#op_type').change();
15}
16
17function loadImport(account) {
18    $.ajax({
19        type: "GET",
20        url: '/my/operation/mimport',
21        data: {account_id: account},
22        success: function (data) {
23            if (haveToMoveImportContainer())
24                $(getImportContainerBeforeSelector()).before($('#m_operation_import').empty().remove());
25
26            $('#m_operation_import').html(data);
27            actionRemoveTemplate();
28
29            if (profileState.isProfileRollbacked())
30                return false;
31
32            $('#selected_import_template [default="default"], #account_for_import [default="default"]').attr("selected", "selected");
33
34            $('#account_for_import_div,' +
35                    '#import_warning,' +
36                    '#m_import_operation_wizard_area_2,' +
37                    '#m-operation-import-end').hide();
38
39            $('#m_import_operation_simple_area').show();
40
41            clearInputFile(['#custom_im_import_operation_shownput_upload', '#w_file_input']);
42
43            $('#m_operation_import_form').slideToggle('800', function () {
44                $(window).scrollTop($(window).scrollTop() + 1).resize();
45            });
46            selectTemleteInit();
47
48            new ImportWidget().initButtons();
49        },
50        complete: function (data) {
51            $('#m_import_operation_show').show();
52            s_frm = $('#m_operation_first_form');
53            var financialDocumentFormats = new Array('master', 'xlsxlsx');
54
55            $("#selected_import_template").die('change').live('change', function() {
56
57                if ($.inArray($(this).val(), financialDocumentFormats) != -1) {
58                    $('#account_for_import_div').hide();
59                } else {
60                    $("#account_for_import_div").show();
61                }
62                if ($('#selected_import_template option:selected').attr('system') != "1") {
63                    $("#import_warning").show();
64                    $.ajax({
65                        type: 'get',
66                        url: '/my/params_from_template_ajax?id=' + $(this).val(),
67                        success: function (data) {
68                            if (data != 'false') {
69                                var params = JSON.parse(data);
70
71                                $('#s_category').val(params['categoryId']).change();
72                                $('.account_for_import').val(params['accountId']).change();
73
74                                if (!params['isSetCategory'])
75                                    $('#s_category').show();
76                                else
77                                    $('#s_category').hide();
78                            }
79                            else
80                                $('#s_category option[value="false"],' +
81                                        '#account_for_import [value="false"]').attr("selected", "selected");
82                        }
83                    });
84                }
85            });
86
87            var pupupId;
88
89            s_options = {
90                url: s_frm.attr('action'),
91                iframe: true,
92                timeout: 100000,
93                dataType: 'html',
94                type: 'post',
95                error: function (data, status) {
96//                    $.jGrowl("Ошибка: таймаут превышен.", {
97//                        theme: 'red',
98//                        open: function () {
99//                            closeJGrowlNotices(pupupId);
100//                        }
101//                    });
102                },
103                success: function (data) {
104                    $("#b_import_start").removeAttr('disabled');
105                    closeJGrowlNotices(pupupId);
106                    if (data) {
107                        delete s_json_data;
108                        if (data.length < 100) {
109                            try {
110                                $("#m_import_results").show();
111                                $.jGrowl(JSON.parse(data)['errors'], {
112                                    theme: 'red',
113                                    open: function () {
114                                        closeJGrowlNotices(pupupId);
115                                    }
116                                });
117                            }
118                            catch (err) {
119                                utils.notifyUser(data)
120                            }
121                        }
122                        else {
123                            $("#m_import_results").html('');
124                            $("#m_import_results").hide();
125
126                            $('#m_import_operation_simple_area').hide();
127                            if ($.inArray($('#selected_import_template').val(), financialDocumentFormats) != -1 || $('#is-edit-template').val() == 1) {
128                                if (checkValidateTextJson(data)) {
129                                    data = $.parseJSON(data).errors;
130                                }
131                                $('#m_import_operation_wizard_area_2').html(data);
132                                $('#m_import_operation_wizard_area_2').show();
133                            }
134                            else {
135                                $("#m_import_operation_wizard_area_end").html(data);
136                                $("#m_import_operation_wizard_area_end").show();
137                                ImportReport.showImportingLoader();
138                                ImportReport.checkIsDoneImporting($('#import-session-id').val());
139                            }
140
141                            easyFinance.models.category.load();
142                            easyFinance.models.accounts.load();
143
144
145                            $('.custom-sel').sb({useTie: true});
146                            $('#selectOper').customUfd("destroy").customUfd(getImportParsingFormUfdConfig('account'));
147                            $('#bankSelect').customUfd('destroy').customUfd(getImportParsingFormUfdConfig('bank'));
148                            $('#m_w_operation_table_form #s_category').customUfd('destroy').customUfd(getImportParsingFormUfdConfig('category'));
149                        }
150
151                        $(window).scrollTop($(window).scrollTop() - 1);
152                        $(window).scrollTop($(window).scrollTop() + 1);
153
154                        new ImportWidget().initButtons();
155                    }
156                }
157            };
158
159            $('#m_operation_first_form').bind('submit', function () {
160                if (s_frm.find('input[type="file"]').val() == '' && $('#is-edit-template').val() != 1) {
161                    utils.notifyUser('Не выбран файл');
162                    return false;
163                }
164                $("#m_import_results").html('');
165                $("#b_import_start").attr('disabled', 'disabled');
166
167                s_frm.ajaxSubmit(s_options);
168                pupupId = showActionBeginingNotice('Идет импорт операций', 'green');
169                return false;
170            });
171        }
172    });
173}
174
175(function ($) {
176    window.tool_t;
177
178    function tShow() {
179        clearTimeout(window.tool_t);
180    }
181
182    function tHide() {
183        window.tool_t = setTimeout(function () {
184            $("#m_custom_tooltip").hide();
185        }, 1000);
186    }
187
188    var methods = {
189        init: function (option) {
190            m_tooltip_html = '<div id="m_custom_tooltip" class="m-custom-tooltip" style="display: none; width: 382px; height: auto;"><div class="m_t_parent"><div class="m_t_top"></div><div class="m_t_mid">' +
191                    '<div class="m_t_midTop"><div class="m_t_content" id="m_t_content_id"></div></div>' +
192                    '</div><div class="m_t_bot"></div></div></div>';
193            $('body').append(m_tooltip_html);
194        },
195        show: function (option) {
196            position = this.offset();
197            $("#m_custom_tooltip").css('left', position.left - 334);
198            $("#m_custom_tooltip").css('top', position.top + 35);
199
200            if (option == '')
201                $("#m_custom_tooltip").show('slow');
202            else {
203                this.bind(option, function () {
204                    position = $('#m_basket_icon').offset();
205                    $("#m_custom_tooltip").css('left', position.left - 334);
206                    $("#m_custom_tooltip").css('top', position.top + 35);
207                    $("#m_custom_tooltip").show('slow');
208                });
209            }
210        },
211        setHide: function (option, calback) {
212            if (option == 'button_close') {
213                $('<a class="m_t_closeBtn" id="m_t_close_btn" href="#" onclick="return false;"></a>').prependTo(".m_t_midTop");
214                $('#m_t_close_btn').bind('click', function () {
215                    $("#m_custom_tooltip").hide();
216                    if (calback !== 'null')
217                        calback($("#m_custom_tooltip"));
218                });
219            }
220            if (option == 'mouseover') {
221                $("#m_custom_tooltip").mouseover(function () {
222                    tShow();
223                });
224                $("#m_custom_tooltip").mouseout(function () {
225                    tHide();
226                });
227                this.mouseover(function () {
228                    tShow();
229                });
230                this.mouseout(function () {
231                    tHide();
232                });
233                $("#m_t_close_btn").remove();
234            }
235        },
236        hide: function () {
237            $("#m_custom_tooltip").hide();
238        },
239        update: function (content) {
240            content_div = $("#m_custom_tooltip").find("#m_t_content_id");
241            content_div.html(content);
242        }
243    };
244
245    $.fn.mTooltip = function (method) {
246        // Method calling logic
247        if (methods[method]) {
248            return methods[ method ].apply(this, Array.prototype.slice.call(arguments, 1));
249        } else if (typeof method === 'object' || !method) {
250            return methods.init.apply(this, arguments);
251        } else {
252            $.error('Method ' + method + ' does not exist on mTooltip');
253        }
254    };
255})(jQuery);
256
257$(function () {
258
259    var _defaultTransfer = null;
260    var _defaultExchange = null;
261    // обрабатываем хэш - по какому счёту выводить операции
262    var account = easyFinance.widgets.operationsJournal.getAccountFromUrl();
263
264    $('#op_transfer').focus(function () {
265        _restoreDefaultTransfer('onFocus');
266    });
267
268    $('#op_transfer').blur(function () {
269        _restoreDefaultTransfer('blur');
270    });
271
272    function _restoreDefaultTransfer(focus) {
273        if (focus == "onFocus") {
274            if ($('#op_transfer').hasClass("greyTransfer")) {
275                _defaultTransfer = $('#op_transfer').val();
276                _defaultExchange = $('#op_conversion').val();
277                $('#op_transfer').val('');
278            }
279        }
280        if (focus == "blur") {
281            if (trim($('#op_transfer').val()) == '') {
282                convert = easyFinance.widgets.operationEdit.getRealConversionRate();
283                val = roundToSignificantFigures(parseFloat($('#op_amount').val()) * convert, easyFinance.models.operation.SIGNS_AFTER_COMMA_AMOUNT);
284                $('#op_transfer').val(val);
285                $('#op_conversion').val(_defaultExchange);
286                $('#op_transfer').addClass("greyTransfer");
287            }
288        }
289    }
290
291    $('#m_basket_icon').bind('click', function () {
292        window.location = "/bucket";
293    });
294
295    function regularTooltip(elem) {
296        elem.mTooltip();
297        message_text = '<div style="text-align: justify; color: #363535;"><p style="text-align: justify; margin-bottom: 12px;">Функция &nbsp; &nbsp; "Корзина" &nbsp; &nbsp; будет &nbsp; &nbsp; доступна &nbsp; Вам &nbsp; в &nbsp; течение <b><span style="color: red;">' + basket.subscribed_left + '</span></b> дней/дня.</p><p style="margin-bottom: 4px;">По истечении этого срока:</p><p style="margin-bottom: 4px;">- Ваши удаленные операции нельзя будет восстановить</p>' +
298                '<p style="margin-bottom: 12px;">- Все счета удаленные более 30 дней назад нельзя будет восстановить</p><p>Оплатите "Корзину" заранее для обеспечения сохранности ваших данных.</p></div>';
299        /*$('#m_basket_icon').mTooltip('setHide', 'mouseover', 'null');
300         $('#m_basket_icon').mTooltip('update', message_text);
301         $('#m_basket_icon').mTooltip('show', 'mouseover');*/
302    }
303
304    function disabledTooltip(elem) {
305        elem.mTooltip();
306        message_text = '<div style="text-align: justify; color: #363535;"><p style="text-align: justify; margin-bottom: 12px;">На данный момент услуга "Корзина" отключена.</p>' +
307                '<p style="margin-bottom: 4px;">- Ваши удаленные операции нельзя будет восстановить;</p><p style="margin-bottom: 12px;">- Все счета удаленные более 30 дней назад нельзя будет восстановить.</p>' +
308                '<p>Оплатите "Корзину" для ее активации (300 рублей) чтобы воспользоваться вышеописанными функциями.</p></div>';
309        /*$('#m_basket_icon').mTooltip('setHide', 'mouseover', 'null');
310         $('#m_basket_icon').mTooltip('update', message_text);
311         $('#m_basket_icon').mTooltip('show', 'mouseover');*/
312    }
313
314    function disabledTooltipFirst(elem) {
315        elem.mTooltip();
316        message_text = '<div style="text-align: justify; color: #363535;"><p style="text-align: justify; margin-bottom: 12px;">На данный момент услуга "Корзина" отключена.</p>' +
317                '<p style="margin-bottom: 4px;">- Ваши удаленные операции нельзя будет восстановить;</p><p style="margin-bottom: 12px;">- Все счета удаленные более 30 дней назад нельзя будет восстановить.</p>' +
318                '<p>
318Оплатите "Корзину" для ее активации (300 рублей) чтобы воспользоваться вышеописанными функциями.</p></div>';
319        /*$('#m_basket_icon').mTooltip('setHide', 'button_close', disabledTooltip);
320         $('#m_basket_icon').mTooltip('update', message_text);
321         $('#m_basket_icon').mTooltip('show', '');*/
322    }
323
324    function firstTooltip(elem) {
325        elem.mTooltip();
326        message_text = '<div style="text-align: justify; color: #363535;"><p style="color: red; margin-bottom: 15px;"><b>Новая функция "Корзина"</b></p><p style="margin-bottom: 4px;">Позволяет хранить и восстанавливать удаленные в течение 30 дней счета и операции.</p>' +
327                '<p style="margin-bottom: 4px;">Данная &nbsp; услуга &nbsp; доступна &nbsp; Вам &nbsp; бесплатно &nbsp; в течение </br> <b><span style="color: red;">' + basket.subscribed_left + '</span></b> дней/дня.</p><p style="margin-bottom: 4px;">По истечении этого срока:</p>' +
328                '<p style="margin-bottom: 4px;">Ваши удаленные операции нельзя будет восстановить.</p><p style="margin-bottom: 15px;">Все счета удаленные более 30 дней назад нельзя будет восстановить.</p>' +
329                '<p>Оплатите "Корзину" заранее для обеспечения сохранности ваших данных.</p></div>';
330
331        /*$('#m_basket_icon').mTooltip('setHide', 'button_close', regularTooltip);
332         $('#m_basket_icon').mTooltip('update', message_text);
333         $('#m_basket_icon').mTooltip('show', '');*/
334    }
335
336    var ajax_flag = 0;
337    $('body').ajaxStop(function () {
338        try {
339            var basket = easyFinance.models.user.getTooltipMessage().basket;
340            disabledTooltipFirst($('#m_basket_icon'));
341            if (ajax_flag == 0) {
342                if (basket.enabled) {
343                    if (basket.display_first == 1)
344                        firstTooltip($('#m_basket_icon'));
345                    else
346                        regularTooltip($('#m_basket_icon'));
347                } else {
348                    if (basket.display_first_end == 1) {
349                        disabledTooltipFirst($('#m_basket_icon'));
350                    } else {
351                        disabledTooltip($('#m_basket_icon'));
352                    }
353                }
354                ajax_flag = 1;
355            }
356        } catch (e) {
357        }
358    });
359
360    $('#payForSubscribe').die('click').live('click', function () {
361        var basket = easyFinance.models.user.getTooltipMessage().basket;
362        var urlSubscribe;
363        if (basket.enabled)
364            urlSubscribe = "/my/services/getServicePopup";
365        else
366            urlSubscribe = "/my/services/getbuyBasket";
367        $.ajax({
368            type: 'POST',
369            dataType: 'html',
370            url: urlSubscribe,
371            success: function (data) {
372                $('#donate-dark, #donate-win-copy').remove();
373                $('<div />').attr('id', 'donate-dark').css({
374                    width: $('body').width(),
375                    height: $('body').height(),
376                    opacity: .25
377                }).appendTo($('body'));
378                $('body').append(data);
379                widthBody = parseInt($('body').css('width').replace('px', ''));
380                widthPopup = parseInt($('#donate-win-copy').css('width').replace('px', ''));
381                left = (widthBody - widthPopup) / 2;
382                $('#donate-win-copy').css('left', left + "px");
383            },
384            complete: function () {
385                $('#m_custom_tooltip').mTooltip('hide');
386            }
387        });
388
389        return false;
390    });
391
392
393    $('#m_import_operation_show').bind('click', function () {
394        if ($(this).hasClass('import-open-flag')) {
395            $('#m_operation_import_form').slideToggle('800', function () {
396                $(window).scrollTop($(window).scrollTop() + 1).resize();
397                $('#m_operation_import').empty();
398            });
399            $(this).removeClass('import-open-flag');
400        }
401        else {
402            loadImport(window.location.hash.replace(/#account=/, ''));
403            $(this).addClass('import-open-flag');
404        }
405    });
406
407    // загружаем журнал транзакций
408    // по умолчанию показываются операции по всем счетам
409
410    if (account != '') {
411        // #870. //easyFinance.widgets.operationEdit.showForm();
412        easyFinance.widgets.operationEdit.setAccount(account);
413    }
414    //easyFinance.widgets.operationReminders.init("#operationEdit_reminders", easyFinance.models.user, "operation")
415
416    easyFinance.widgets.operationsJournal.setAccount(account);
417    //easyFinance.widgets.operationsJournal.loadJournal();
418
419    if (window.location.hash != '' && window.location.hash.indexOf('#tag=') > -1) {
420        var tagFromUrl = decodeURIComponent(window.location.hash.replace('#tag=', ''));
421        easyFinance.widgets.operationsJournal.setTags(tagFromUrl);
422    }
423
424    var choosedView = "switchOper";
425    $('#switchOper').addClass('active');
426
427    var type_filtr = '';
428    var account_filtr = '';
429    var cat_filtr = '';
430    var grid_search_field = '';
431
432    $('#extended_reports_link').die('click').live('click', function () {
433        //$('#switchReports').trigger('click');
434    });
435
436    $('.switcher').die('click').live('click', function () {
437        choosedView = $(this).attr('id');
438        $(this).addClass('active');
439        switchView(choosedView);
440        return false;
441    });
442
443    function switchView(choosedView)
444    {
445        clearTimeout(window.calendarTypesFilterTimer);
446        clearTimeout(window.calendarControlsFilterTimer);
447
448        if (typeof default_category_id_rep != 'undefined')
449            easyFinance.widgets.operationsJournal.setCategoryId(default_category_id_rep);
450        if (typeof default_type_rep != 'undefined')
451            easyFinance.widgets.operationsJournal.setType(default_type_rep);
452
453        if (type_filtr == '' && $('#type_filtr option:selected').val() != '-1')
454            type_filtr = $('#type_filtr option:selected').val();
455        if ($('#type_filtr option:selected').val() == '-1')
456            type_filtr = '';
457
458        var accountVal = $('#account_filtr option:selected').val() || '';
459        if (account_filtr == '' && accountVal != '-1')
460            account_filtr = accountVal;
461        if (accountVal == '-1')
462            account_filtr = '';
463
464        var categoryVal = $('#cat_filtr option:selected').val() || '';
465        if (cat_filtr == '' && categoryVal != '-1')
466            cat_filtr = categoryVal;
467        if (categoryVal == '-1')
468            cat_filtr = '';
469
470        if (grid_search_field == '' && $('#grid_search_field').val() != '')
471            grid_search_field = $('#grid_search_field').val();
472        if ($('#grid_search_field').val() == '-1')
473            grid_search_field = '';
474
475        $('.switcher').removeClass('active');
476        $('#page_content').removeClass('contentReports');
477
478        $('.accountIdSelect').hide();
479        if (choosedView == 'switchOper') {
480            url = '/my/operation_table';
481            $('.b-importexport-inside').show();
482        }
483        if (choosedView == 'switchRep') {
484            url = '/my/report_ajax';
485            $('.b-importexport-inside').hide();
486        }
487        if (choosedView == 'switchExtRep') {
488            url = '/my/extended_reports';
489            $('.b-importexport-inside').hide();
490            $('.accountIdSelect').show();
491        }
492        if (choosedView == 'switchReports') {
493            url = '/my/extended_reports';
494            $('#reports-notice').show();
495            $('#ideas-notice').show();
496            $('.b-importexport').hide();
497            window.location.hash = '#reports';
498
499            $('#reports-header').show();
500            $('#operations-journal-header').hide();
501
502            $('.accountIdSelect').show();
503            $('#switchReports').hide();
504            $('#switchOperations').show();
505            $('#toOldReports').show();
506            $('.switcher').removeClass('active');
507            $('#switchExtRep').addClass('active');
508
509            selectHMTab('hm_tab_reports', false);
510        }
511        if (choosedView == 'switchOperations') {
512            showNewCalendar();
513
514            url = '/my/operation_table';
515            $('#reports-notice').hide();
516            $('#ideas-notice').hide();
517            $('.b-importexport').show();
518
519            $('#reports-header').hide();
520            $('#operations-journal-header').show();
521
522            $('#switchOperations').hide();
523            $('#toOldReports').hide();
524            $('#switchReports').show();
525            if (window.location.hash.indexOf("#reports") != -1) {
526                window.location.hash = '';
527            }
528
529            selectHMTab('hm_tab_operations', 'sub_tab_operations');
530        }
531
532        if ($('#dataGrid').length > 0) {
533            DataTables.grid.fnDestroy();
534            $('#dataGrid').remove();
535            $('#dataGrid').remove();
536            $(DataTables).remove();
537        }
538
539        var tourWidget = easyFinance.widgets.tour;
540        tourWidget && tourWidget.setLockState(true);
541
542        $.ajax({
543            type: "POST",
544            url: url,
545            data: {
546                type_filtr: type_filtr,
547                account_filtr: account_filtr,
548                cat_filtr: cat_filtr,
549                grid_search_field: grid_search_field
550            },
551            success: function (data) {
552                $('.switchArea').html(data);
553                $('.b-calendar_view-types .selected')
554                        .eq(0).siblings().removeClass('selected');
555
556                if (DataTables)
557                    DataTables.preloader(false);
558
559                if (choosedView !== 'switchReports')
560                    return;
561
562                tourWidget && tourWidget.setLockState(false);
563                tourWidget && tourWidget.loadAndStartStaticTours();
564            }
565        });
566    }
567
568    showReportsByHash();
569
570    function showReportsByHash() {
571        if (window.location.hash.indexOf("#reports") != -1) {
572            if ($('#chartContainerDiv').length < 1) {
573                switchView('switchReports');
574            }
575        }
576    }
577
578    if (!isHjsUsed()) {
579        $('.hm_tab_reports').die('click').live('click', function() {
580            if (typeof(switchView) == 'function') {
581                switchView('switchReports');
582            }
583        });
584    }
585
586    if (window.location.hash == '#import') {
587        $('#m_import_operation_show').trigger('click');
588    }
589
590});
591
592function checkValidateTextJson(data){
593    try {
594        var json = $.parseJSON(data);
595        return json;
596    } catch (e) {
597        return false;
598    }
599}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.