Subversion Repositories SmartDukaan

Rev

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

Rev 34900 Rev 34947
Line 1... Line 1...
1
$(document).on('click', '.affiliate-product', function () {
1
$(document).on('click', '.affiliate-product', function () {
2
    doGetAjaxRequestHandler(`${context}/affiliate/getAffiliateProductList`, function (response) {
2
    doGetAjaxRequestHandler(`${context}/affiliate/getAffiliateProductList`, function (response) {
3
        $('#main-content').html(response);
3
        $('#main-content').html(response);
4
    });
4
    });
5
});
5
});
-
 
6
 
-
 
7
$(document).on('click', '.affiliate-kyc', function () {
-
 
8
    doGetAjaxRequestHandler(`${context}/affiliate/getPendingKyc`, function (response) {
-
 
9
        $('#main-content').html(response);
-
 
10
    });
-
 
11
});
-
 
12
 
6
$(document).on('click', '.saveAffiliateProduct', function () {
13
$(document).on('click', '.saveAffiliateProduct', function () {
7
    if (!$('#catalog_id').val()) {
14
    if (!$('#catalog_id').val()) {
8
        alert('Please select a catalog');
15
        alert('Please select a catalog');
9
        return;
16
        return;
10
    }
17
    }
11
    const formData = {
18
    const formData = {
12
        catalogId: $('#catalog_id').val(),
19
        catalogId: $('#catalog_id').val(),
13
        status: $('#status').val(),
20
        status: $('#status').val(),
14
        expiryDate: $('#expiry_date').val(),
21
        expiryDate: $('#expiry_date').val(),
-
 
22
        commission: $('#commission').val(),
15
        giftId: $('#gift_ids').val()?.toString(),
23
        giftId: $('#gift_ids').val()?.toString(),
-
 
24
        featured: $('#featured').is(':checked')
16
    };
25
    };
17
    doAjaxRequestWithJsonHandler(
26
    doAjaxRequestWithJsonHandler(
18
        `${context}/affiliate/create-affiliate-product`,
27
        `${context}/affiliate/create-affiliate-product`,
19
        "POST",
28
        "POST",
20
        JSON.stringify(formData),
29
        JSON.stringify(formData),
Line 45... Line 54...
45
            if (!response) {
54
            if (!response) {
46
                console.error('Empty response received');
55
                console.error('Empty response received');
47
                return;
56
                return;
48
            }
57
            }
49
 
58
 
50
            // Set catalog ID
-
 
51
            if (response.catalogId) {
59
            if (response.catalogId) {
52
                $('#edit_catalog_id').val(response.catalogId).multiselect('refresh');
60
                $('#edit_catalog_id').val(response.catalogId).multiselect('refresh');
53
            }
61
            }
54
            const giftIds = response.giftId ? response.giftId.split(',') : [];
62
            const giftIds = response.giftId ? response.giftId.split(',') : [];
55
            $('#edit_gift_ids').val(giftIds).multiselect('refresh');
63
            $('#edit_gift_ids').val(giftIds).multiselect('refresh');
56
            if (response.status) {
64
            if (response.status) {
57
                $('#edit_status').val(response.status);
65
                $('#edit_status').val(response.status);
58
            }
66
            }
-
 
67
            if (response.commission) {
-
 
68
                $('#edit_commission').val(response.commission);
-
 
69
            }
-
 
70
            if (response.featured !== undefined) {
-
 
71
                $('#edit_featured').prop('checked', response.featured);
-
 
72
            }
59
            if (response.expiryDate && Array.isArray(response.expiryDate)) {
73
            if (response.expiryDate && Array.isArray(response.expiryDate)) {
60
                const [year, month, day, hour, minute] = response.expiryDate;
74
                const [year, month, day, hour, minute] = response.expiryDate;
61
                const dateString = `${year}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')}T${String(hour).padStart(2, '0')}:${String(minute).padStart(2, '0')}`;
75
                const dateString = `${year}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')}T${String(hour).padStart(2, '0')}:${String(minute).padStart(2, '0')}`;
62
                $('#edit_expiry_date').val(dateString);
76
                $('#edit_expiry_date').val(dateString);
63
            }
77
            }
64
 
78
 
65
            console.log('About to show modal'); // Debug log
79
            console.log('About to show modal'); // Debug log
66
 
80
 
67
            // Show modal
-
 
68
            $('#editAffiliateProductModal').data('product-id', productId);
81
            $('#editAffiliateProductModal').data('product-id', productId);
69
            $('#editAffiliateProductModal').modal('show');
82
            $('#editAffiliateProductModal').modal('show');
70
 
83
 
71
            console.log('Modal show command executed'); // Debug log
84
            console.log('Modal show command executed'); // Debug log
72
 
85
 
73
        } catch (error) {
86
        } catch (error) {
74
            console.error('Error processing response:', error);
87
            console.error('Error processing response:', error);
75
        }
88
        }
76
    }, function (error) {
89
    }, function (error) {
77
        // Error callback
-
 
78
        console.error('AJAX request failed:', error);
90
        console.error('AJAX request failed:', error);
79
    });
91
    });
80
});
92
});
81
 
93
 
82
 
94
 
Line 84... Line 96...
84
    const productId = $('#editAffiliateProductModal').data('product-id');
96
    const productId = $('#editAffiliateProductModal').data('product-id');
85
 
97
 
86
    const formData = {
98
    const formData = {
87
        id: productId,
99
        id: productId,
88
        catalogId: $('#edit_catalog_id').val(),
100
        catalogId: $('#edit_catalog_id').val(),
89
        giftId: $('#edit_gift_ids').val().join(','), // Convert array to CSV
101
        giftId: $('#edit_gift_ids').val().join(','),
90
        status: $('#edit_status').val(),
102
        status: $('#edit_status').val(),
91
        expiryDate: $('#edit_expiry_date').val()
103
        expiryDate: $('#edit_expiry_date').val(),
-
 
104
        commission: $('#edit_commission').val(),
-
 
105
        featured: $('#edit_featured').is(':checked')
92
    };
106
    };
93
 
107
 
94
    doAjaxRequestWithJsonHandler(
108
    doAjaxRequestWithJsonHandler(
95
        `${context}/affiliate/edit-affiliate-product`,
109
        `${context}/affiliate/edit-affiliate-product`,
96
        "POST",
110
        "POST",
Line 114... Line 128...
114
 
128
 
115
$('#editAffiliateProductModal').on('hidden.bs.modal', function () {
129
$('#editAffiliateProductModal').on('hidden.bs.modal', function () {
116
    $(this).find('form')[0].reset();
130
    $(this).find('form')[0].reset();
117
    $(this).removeData('product-id');
131
    $(this).removeData('product-id');
118
    $('#edit_catalog_id, #edit_gift_ids').val('').multiselect('refresh');
132
    $('#edit_catalog_id, #edit_gift_ids').val('').multiselect('refresh');
-
 
133
    $('#edit_featured').prop('checked', false);
119
});
134
});
120
 
135
 
121
$(document).on('click', '.delete-affiliate-product', function () {
136
$(document).on('click', '.delete-affiliate-product', function () {
122
    const id = $(this).data('productid');
137
    const id = $(this).data('productid');
123
    console.log("this is the id" + id);
138
    console.log("this is the id" + id);
Line 234... Line 249...
234
            }
249
            }
235
        );
250
        );
236
    }
251
    }
237
});
252
});
238
 
253
 
-
 
254
$(document).on('click', '.approve-btn', function () {
-
 
255
    let approveModal = {
-
 
256
        id: $(this).data('kyc-id'),
-
 
257
        status: "APPROVED"
-
 
258
    };
-
 
259
    doPostAjaxRequestWithJsonHandler(
-
 
260
        `${context}/affiliate/approveRejectKyc`,
-
 
261
        JSON.stringify(approveModal),
-
 
262
        function (response) {
-
 
263
            alert("KYC Approved successfully");
-
 
264
 
-
 
265
        }
-
 
266
    );
-
 
267
});
-
 
268
 
-
 
269
$(document).on('click', '#confirmReject', function () {
-
 
270
    let rejectModal = {
-
 
271
        id: $('#rejectionModal').data('kyc-id'),
-
 
272
        status: "REJECTED",
-
 
273
        reason: $('#rejectionReason').val()
-
 
274
    };
-
 
275
    doPostAjaxRequestWithJsonHandler(
-
 
276
        `${context}/affiliate/approveRejectKyc`,
-
 
277
        JSON.stringify(rejectModal),
-
 
278
        function (response) {
-
 
279
            alert("KYC REJECTED successfully");
-
 
280
            $('#rejectionModal').modal('hide');
-
 
281
        }
-
 
282
    );
-
 
283
});
-
 
284
 
-
 
285
$(document).on('click', '.reject-btn', function () {
-
 
286
    let kycId = $(this).data('kyc-id');
-
 
287
    $('#rejectionModal').data('kyc-id', kycId);
-
 
288
});
-
 
289
 
-
 
290
$(document).on("click", ".view-btn", function () {
-
 
291
    var docId = $(this).attr("data-doc-id");
-
 
292
    if (!docId) {
-
 
293
        alert("Document not available");
-
 
294
        return;
-
 
295
    }
-
 
296
    var url = context + "/document/" + docId;
-
 
297
    var isPdf = /\.pdf($|\?)/i.test(url);
-
 
298
    var $body = $("#kycDocBody").empty();
-
 
299
    if (isPdf) {
-
 
300
        $body.html('<iframe src="' + url + '" width="100%" height="600" frameborder="0"></iframe>');
-
 
301
    } else {
-
 
302
        $body.html('<img src="' + url + '" alt="KYC Document" class="img-fluid rounded">');
-
 
303
    }
-
 
304
    $("#kycDocModal").modal("show");
-
 
305
});
-
 
306