Subversion Repositories SmartDukaan

Rev

Rev 33886 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 33886 Rev 37031
Line -... Line 1...
-
 
1
var blockTargetRow = null;
-
 
2
var unblockTargetRow = null;
-
 
3
 
1
$(function () {
4
$(function () {
2
 
5
 
3
    $(document).on('click', ".partner-credit-detail", function () {
6
    $(document).on('click', ".partner-credit-detail", function () {
4
 
7
 
5
        loadCreditDetail("main-content");
8
        loadCreditDetail("main-content");
6
    });
9
    });
7
 
10
 
8
 
11
 
-
 
12
    // Switch a partner to a different credit gateway (e.g. SIDBI) and activate it.
9
    $(document).on('click', '.activate-partner-kred', function () {
13
    $(document).on('click', '.switch-credit-gateway', function () {
10
        var row = $(this).closest("tr");
14
        var row = $(this).closest("tr");
11
        var id = $(this).data('id');
15
        var id = $(this).data('id');
12
        let gateway = $(row).find('select').val();
16
        let gateway = $(row).find('select').val();
13
        if(typeof gateway==="undefined"){
17
        if (typeof gateway === "undefined") {
14
            gateway = row.find('.mk_gateway').data("gateway");
18
            gateway = row.find('.mk_gateway').data("gateway");
15
        }
19
        }
16
        console.log(id)
-
 
17
        if (confirm(`Are you sure you want to activate ${gateway}?`)) {
20
        if (confirm(`Are you sure you want to activate ${gateway}?`)) {
18
            doPostAjaxRequestHandler(`${context}/activateKred?id=${id}&gateway=${gateway}`,
21
            doPostAjaxRequestHandler(`${context}/switchCreditGateway?id=${id}&gateway=${gateway}`,
19
                function (response) {
22
                function (response) {
20
                    row.html(response);
23
                    row.html(response);
21
                    alert(`${gateway} successfully activated`);
24
                    alert(`${gateway} successfully activated`);
-
 
25
                });
-
 
26
        }
-
 
27
    });
22
 
28
 
23
 
29
 
-
 
30
    // Block credit -> open modal to capture the mandatory reason.
-
 
31
    $(document).on('click', '.block-credit', function () {
-
 
32
        blockTargetRow = $(this).closest("tr");
-
 
33
        $('#blockCreditId').val($(this).data('id'));
-
 
34
        $('#blockCreditReason').val('');
-
 
35
        $('#blockCreditModal').modal('show');
-
 
36
    });
-
 
37
 
-
 
38
    $(document).on('click', '#confirmBlockCredit', function () {
-
 
39
        var id = $('#blockCreditId').val();
-
 
40
        var reason = $('#blockCreditReason').val().trim();
-
 
41
        if (reason === '') {
-
 
42
            alert('Reason is mandatory to block credit');
24
                });
43
            return;
25
        }
44
        }
-
 
45
        doPostAjaxRequestHandler(`${context}/blockCredit?id=${id}&reason=${encodeURIComponent(reason)}`,
-
 
46
            function (response) {
-
 
47
                if (blockTargetRow) {
-
 
48
                    blockTargetRow.html(response);
-
 
49
                }
-
 
50
                $('#blockCreditModal').modal('hide');
-
 
51
                alert('Credit blocked successfully');
-
 
52
            });
26
    });
53
    });
27
 
54
 
-
 
55
 
-
 
56
    // Unblock credit -> open modal, load the full block/unblock history, then confirm.
28
    $(document).on('click', '.deactivate-partner-kred', function () {
57
    $(document).on('click', '.unblock-credit', function () {
29
        var row = $(this).closest("tr");
58
        unblockTargetRow = $(this).closest("tr");
30
        var id = $(this).data('id');
59
        var id = $(this).data('id');
31
        let gateway = $(row).find('select').val();
60
        var fofoId = $(this).data('fofo-id');
32
        if(typeof gateway==="undefined"){
61
        $('#unblockCreditId').val(id);
-
 
62
        $('#unblockCreditReason').val('');
-
 
63
        $('#creditBlockLogsContainer').html('Loading...');
-
 
64
        doGetAjaxRequestHandler(`${context}/creditBlockLogs?fofoId=${fofoId}`,
33
            gateway="SDDIRECT";
65
            function (response) {
-
 
66
                $('#creditBlockLogsContainer').html(response);
34
        }
67
            });
35
        if (confirm('Are you sure you want to deactivate?')) {
68
        $('#unblockCreditModal').modal('show');
-
 
69
    });
-
 
70
 
36
            doPostAjaxRequestHandler(context + "/deactivateKred?id=" + id,
71
    $(document).on('click', '#confirmUnblockCredit', function () {
37
                function (response) {
72
        var id = $('#unblockCreditId').val();
38
                    row.html(response);
73
        var reason = $('#unblockCreditReason').val().trim();
39
                    alert(`${gateway} successfully deactivated`);
74
        var url = `${context}/unblockCredit?id=${id}`;
40
                });
75
        if (reason !== '') {
-
 
76
            url += `&reason=${encodeURIComponent(reason)}`;
41
        }
77
        }
-
 
78
        doPostAjaxRequestHandler(url,
-
 
79
            function (response) {
-
 
80
                if (unblockTargetRow) {
-
 
81
                    unblockTargetRow.html(response);
-
 
82
                }
-
 
83
                $('#unblockCreditModal').modal('hide');
-
 
84
                alert('Credit unblocked successfully');
-
 
85
            });
42
    });
86
    });
43
 
87
 
44
});
88
});
45
 
89
 
46
function loadCreditDetail(domId) {
90
function loadCreditDetail(domId) {
Line 48... Line 92...
48
        function (response) {
92
        function (response) {
49
            $('#' + domId).html(response);
93
            $('#' + domId).html(response);
50
        });
94
        });
51
 
95
 
52
 
96
 
53
}
-
 
54
97
}
-
 
98