Subversion Repositories SmartDukaan

Rev

Rev 34881 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
34881 aman 1
$(document).on('click', '.affiliate-product', function () {
2
    doGetAjaxRequestHandler(`${context}/affiliate/getAffiliateProductList`, function (response) {
3
        $('#main-content').html(response);
4
    });
5
});
6
$(document).on('click', '.saveAffiliateProduct', function () {
7
    if (!$('#catalog_id').val()) {
8
        alert('Please select a catalog');
9
        return;
10
    }
11
    const formData = {
12
        catalogId: $('#catalog_id').val(),
13
        status: $('#status').val(),
14
        expiryDate: $('#expiry_date').val(),
15
        giftId: $('#gift_ids').val()?.toString(),
16
    };
17
    doAjaxRequestWithJsonHandler(
18
        `${context}/affiliate/create-affiliate-product`,
19
        "POST",
20
        JSON.stringify(formData),
21
        function (response) {
22
            if (response.responseStatus === "SUCCESS") {
23
                alert('Affiliate product created successfully!');
24
                $('#addAffiliateProductModal').modal('hide');
34900 aman 25
                $('.affiliate-product').click();
34881 aman 26
            } else {
27
                alert('Error: ' + response.message);
28
            }
29
 
30
        }
31
    );
32
});
33
 
34
$(document).on('click', '.map-catalog', function () {
35
    $('#addAffiliateProductModal').modal('show');
36
});
37
 
38
$(document).on('click', '.edit-affiliate-product', function () {
39
    const productId = $(this).data('productid');
40
 
41
    doGetAjaxRequestHandler(`${context}/affiliate/updateAffiliateProductList/${productId}`, function (response) {
42
        console.log('Response received:', response);
43
 
44
        try {
45
            if (!response) {
46
                console.error('Empty response received');
47
                return;
48
            }
49
 
50
            // Set catalog ID
51
            if (response.catalogId) {
52
                $('#edit_catalog_id').val(response.catalogId).multiselect('refresh');
53
            }
54
            const giftIds = response.giftId ? response.giftId.split(',') : [];
55
            $('#edit_gift_ids').val(giftIds).multiselect('refresh');
56
            if (response.status) {
57
                $('#edit_status').val(response.status);
58
            }
59
            if (response.expiryDate && Array.isArray(response.expiryDate)) {
60
                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')}`;
62
                $('#edit_expiry_date').val(dateString);
63
            }
64
 
65
            console.log('About to show modal'); // Debug log
66
 
67
            // Show modal
68
            $('#editAffiliateProductModal').data('product-id', productId);
69
            $('#editAffiliateProductModal').modal('show');
70
 
71
            console.log('Modal show command executed'); // Debug log
72
 
73
        } catch (error) {
74
            console.error('Error processing response:', error);
75
        }
76
    }, function (error) {
77
        // Error callback
78
        console.error('AJAX request failed:', error);
79
    });
80
});
81
 
82
 
83
$(document).on('click', '.updateAffiliateProduct', function () {
84
    const productId = $('#editAffiliateProductModal').data('product-id');
85
 
86
    const formData = {
87
        id: productId,
88
        catalogId: $('#edit_catalog_id').val(),
89
        giftId: $('#edit_gift_ids').val().join(','), // Convert array to CSV
90
        status: $('#edit_status').val(),
91
        expiryDate: $('#edit_expiry_date').val()
92
    };
93
 
94
    doAjaxRequestWithJsonHandler(
95
        `${context}/affiliate/edit-affiliate-product`,
96
        "POST",
97
        JSON.stringify(formData),
98
        function (response) {
99
            if (response) {
100
                alert('Updated successfully!');
101
                $('#editAffiliateProductModal').modal('hide');
34900 aman 102
                $('.affiliate-product').click();
34881 aman 103
            } else {
104
                alert('Error: ' + response.message);
105
            }
106
        }
107
    );
108
});
109
// Reset CREATE modal when closed
110
$('#addAffiliateProductModal').on('hidden.bs.modal', function () {
111
    $(this).find('form')[0].reset();
112
    $('#catalog_id, #gift_ids').val('').multiselect('refresh');
113
});
114
 
115
$('#editAffiliateProductModal').on('hidden.bs.modal', function () {
116
    $(this).find('form')[0].reset();
117
    $(this).removeData('product-id');
118
    $('#edit_catalog_id, #edit_gift_ids').val('').multiselect('refresh');
119
});
120
 
121
$(document).on('click', '.delete-affiliate-product', function () {
122
    const id = $(this).data('productid');
123
    console.log("this is the id" + id);
124
    if (confirm('Are you sure you want to delete this product?')) {
125
        doDeleteAjaxRequestHandler(
126
            `${context}/affiliate/delete-affiliate-product/${id}`,
127
            function () {
128
                alert('Product deleted successfully!');
129
 
130
            }
131
        );
132
    }
133
});
134
 
135
 
136
$(document).on('click', '.affiliate-gift', function () {
137
    doGetAjaxRequestHandler(`${context}/affiliate/getAffiliateGiftList`, function (response) {
138
        $('#main-content').html(response);
139
    });
140
});
141
 
142
$(document).on('click', '.saveAffiliateGift', function () {
143
    const formData = {
144
        name: $('#gift_name').val(),
145
        status: $('#gift_Status').val() || "ACTIVE",
146
        qty: $('#gift_qty').val(),
147
    };
148
    console.log("we are getting the request body", formData);
149
    doAjaxRequestWithJsonHandler(
150
        `${context}/affiliate/create-affiliate-gift`,
151
        "POST",
152
        JSON.stringify(formData),
153
        function (response) {
154
            if (response.responseStatus === "SUCCESS") {
155
                alert('Affiliate product created successfully!');
156
                $('#addAffiliateGiftModal').modal('hide');
34900 aman 157
                $('.affiliate-gift').click();
34881 aman 158
            } else {
159
                alert('Error: ' + response.message);
160
            }
161
 
162
        }
163
    );
164
});
165
 
166
 
167
$(document).on('click', '.edit-affiliate-gift', function () {
168
    const giftId = $(this).data('giftid');
169
 
170
    doGetAjaxRequestHandler(`${context}/affiliate/updateAffiliateGift/${giftId}`, function (response) {
171
        console.log('Response received:', response);
172
 
173
        try {
174
            if (!response) {
175
                console.error('Empty response received');
176
                return;
177
            }
178
            if (response.name) {
179
                $('#edit_gift_name').val(response.name);
180
            }
181
            $('#edit_gift_qty').val(response.qty);
182
            if (response.status) {
183
                $('#edit_gift_Status').val(response.status);
184
            }
185
            console.log('About to show modal'); // Debug log
186
            $('#editAffiliateGiftModal').data('gift-id', giftId);
187
            $('#editAffiliateGiftModal').modal('show');
188
            console.log('Modal show command executed'); // Debug log
189
        } catch (error) {
190
            console.error('Error processing response:', error);
191
        }
192
    }, function (error) {
193
        console.error('AJAX request failed:', error);
194
    });
195
});
196
 
197
$(document).on('click', '.updateAffiliateGift', function () {
198
    const giftId = $('#editAffiliateGiftModal').data('gift-id');
199
 
200
    const formData = {
201
        id: giftId,
202
        name: $('#edit_gift_name').val(),
203
        qty: $('#edit_gift_qty').val(),
204
        status: $('#edit_gift_Status').val(),
205
 
206
    };
207
 
208
    doAjaxRequestWithJsonHandler(
209
        `${context}/affiliate/edit-affiliate-gift`,
210
        "POST",
211
        JSON.stringify(formData),
212
        function (response) {
213
            if (response) {
214
                alert('Updated successfully!');
215
                $('#editAffiliateGiftModal').modal('hide');
34900 aman 216
                $('.affiliate-gift').click();
34881 aman 217
            } else {
218
                alert('Error: ' + response.message);
219
            }
220
        }
221
    );
222
});
223
 
224
 
225
$(document).on('click', '.delete-affiliate-gift', function () {
226
    const id = $(this).data('giftid');
227
    console.log("this is the id" + id);
228
    if (confirm('Are you sure you want to delete this gift?')) {
229
        doDeleteAjaxRequestHandler(
230
            `${context}/affiliate/delete-affiliate-gift/${id}`,
231
            function () {
232
                alert('Gift deleted successfully!');
233
 
234
            }
235
        );
236
    }
237
});
238