Subversion Repositories SmartDukaan

Rev

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