Subversion Repositories SmartDukaan

Rev

Rev 34859 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
34859 vikas 1
const rightHero = `<table class="table table-bordered" id="rightHero">
2
                        <tr>
3
                            <td>
4
                                <img src="https://placehold.co/300x200" alt="Top Left Image" id="topLeftImage" width="300">
5
                                <input type="file" class="topLeftFile" style="display: none;">
6
                                <input type="hidden" id="topLeftFile">
7
                                <input id="topLeftLink" class="form-control" placeholder="Redirection Link">
8
                            </td>
9
                            <td>
10
                                <img src="https://placehold.co/300x200" alt="Bottom Left Image" id="bottomLeftImage" width="300">
11
                                <input type="file" class="bottomLeftFile" style="display: none;">
12
                                <input type="hidden" id="bottomLeftFile">
13
                                <input id="bottomLeftLink" class="form-control" placeholder="Redirection Link">
14
                            </td>
15
                        </tr>
16
                        <tr>
17
                            <td>
18
                                <img src="https://placehold.co/300x200" alt="Top Right Image" id="topRightImage" width="300">
19
                                <input type="file" class="topRightFile" style="display: none;">
20
                                <input type="hidden" id="topRightFile">
21
                                <input id="topRightLink" class="form-control" placeholder="Redirection Link">
22
                            </td>
23
                            <td>
24
                                <img src="https://placehold.co/300x200" alt="Bottom Right Image" id="bottomRightImage" width="300">
25
                                <input type="file" class="bottomRightFile" style="display: none;">
26
                                <input type="hidden" id="bottomRightFile">
27
                                <input id="bottomRightLink" class="form-control" placeholder="Redirection Link">
28
                            </td>
29
                            <td rowspan="2">
30
                                <img src="https://placehold.co/600x400" alt="Hero Image" id="heroImage" width="300">
31
                                <input type="file" class="heroFile" style="display: none;">
32
                                <input type="hidden" id="heroFile">
33
                                <input id="heroLink" class="form-control" placeholder="Redirection Link">
34
                            </td>
35
                        </tr>
36
                    </table>`,
37
leftHero = `<table class="table table-bordered" id="leftHero">
38
                        <tr>
39
                            <td rowspan="2">
40
                                <img src="https://placehold.co/600x400" alt="Hero Image" id="heroImage" width="300">
41
                                <input type="file" class="heroFile" style="display: none;">
42
                                <input type="hidden" id="heroFile">
43
                                <input id="heroLink" class="form-control" placeholder="Redirection Link">
44
                            </td>
45
                            <td>
46
                                <img src="https://placehold.co/300x200" alt="Top Left Image" id="topLeftImage" width="300">
47
                                <input type="file" class="topLeftFile" style="display: none;">
48
                                <input type="hidden" id="topLeftFile">
49
                                <input id="topLeftLink" class="form-control" placeholder="Redirection Link">
50
                            </td>
51
                            <td>
52
                                <img src="https://placehold.co/300x200" alt="Bottom Left Image" id="bottomLeftImage" width="300">
53
                                <input type="file" class="bottomLeftFile" style="display: none;">
54
                                <input type="hidden" id="bottomLeftFile">
55
                                <input id="bottomLeftLink" class="form-control" placeholder="Redirection Link">
56
                            </td>
57
                        </tr>
58
                        <tr>
59
                            <td>
60
                                <img src="https://placehold.co/300x200" alt="Top Right Image" id="topRightImage" width="300">
61
                                <input type="file" class="topRightFile" style="display: none;">
62
                                <input type="hidden" id="topRightFile">
63
                                <input id="topRightLink" class="form-control" placeholder="Redirection Link">
64
                            </td>
65
                            <td>
66
                                <img src="https://placehold.co/300x200" alt="Bottom Right Image" id="bottomRightImage" width="300">
67
                                <input type="file" class="bottomRightFile" style="display: none;">
68
                                <input type="hidden" id="bottomRightFile">
69
                                <input id="bottomRightLink" class="form-control" placeholder="Redirection Link">
70
                            </td>
71
                        </tr>
72
                    </table>`,
73
centerHero = `<table class="table table-bordered" id="centerHero">
74
                        <tr>
75
                            <td>
76
                                <img src="https://placehold.co/300x200" alt="Top Left Image" id="topLeftImage" width="300">
77
                                <input type="file" class="topLeftFile" style="display: none;">
78
                                <input type="hidden" id="topLeftFile">
79
                                <input id="topLeftLink" class="form-control" placeholder="Redirection Link">
80
                            </td>
81
                            <td rowspan="2">
82
                                <img src="https://placehold.co/600x400" alt="Hero Image" id="heroImage" width="300">
83
                                <input type="file" class="heroFile" style="display: none;">
84
                                <input type="hidden" id="heroFile">
85
                                <input id="heroLink" class="form-control" placeholder="Redirection Link">
86
                            </td>
87
                            <td>
88
                                <img src="https://placehold.co/300x200" alt="Bottom Left Image" id="bottomLeftImage" width="300">
89
                                <input type="file" class="bottomLeftFile" style="display: none;">
90
                                <input type="hidden" id="bottomLeftFile">
91
                                <input id="bottomLeftLink" class="form-control" placeholder="Redirection Link">
92
                            </td>
93
                        </tr>
94
                        <tr>
95
                            <td>
96
                                <img src="https://placehold.co/300x200" alt="Top Right Image" id="topRightImage" width="300">
97
                                <input type="file" class="topRightFile" style="display: none;">
98
                                <input type="hidden" id="topRightFile">
99
                                <input id="topRightLink" class="form-control" placeholder="Redirection Link">
100
                            </td>
101
                            <td>
102
                                <img src="https://placehold.co/300x200" alt="Bottom Right Image" id="bottomRightImage" width="300">
103
                                <input type="file" class="bottomRightFile" style="display: none;">
104
                                <input type="hidden" id="bottomRightFile">
105
                                <input id="bottomRightLink" class="form-control" placeholder="Redirection Link">
106
                            </td>
107
                        </tr>
108
                    </table>`;
34949 vikas 109
doubleHero = `<table class="table table-bordered" id="doubleHero">
110
                <tr>
111
                    <td>
112
                        <img src="https://placehold.co/300x200" alt="Image" id="topLeftImage" width="300">
113
                        <input type="file" class="doubleLeftFile" style="display: none;">
114
                        <input type="hidden" id="doubleLeftFile">
115
                        <input id="doubleLeftLink" class="form-control" placeholder="Redirection Link">
116
                    </td>
117
                    <td>
118
                        <img src="https://placehold.co/300x200" alt="Image" id="bottomLeftImage" width="300">
119
                        <input type="file" class="doubleRightFile" style="display: none;">
120
                        <input type="hidden" id="doubleRightFile">
121
                        <input id="doubleRightLink" class="form-control" placeholder="Redirection Link">
122
                    </td>
123
                </tr>
124
            </table>`;
125
singleHero = `<table class="table table-bordered" id="singleHero">
126
                <tr>
127
                    <td>
128
                        <img src="https://placehold.co/600x300" alt="Image" id="topLeftImage" width="300">
129
                        <input type="file" class="singleFile" style="display: none;">
130
                        <input type="hidden" id="singleFile">
131
                        <input id="singleLink" class="form-control" placeholder="Redirection Link">
132
                    </td>
133
                </tr>
134
            </table>`;
34859 vikas 135
function patchSectionData(sectionData) {
136
    const container = $('.style-container');
137
    container.find('#heroFile').val(sectionData.hero.image.split('/').filter(Boolean).pop());
138
    container.find('#heroLink').val(sectionData.hero.link);
139
    container.find('#heroImage').attr('src',sectionData.hero.image);
140
 
141
    container.find('#topLeftFile').val(sectionData.leftTop.image.split('/').filter(Boolean).pop());
142
    container.find('#topLeftLink').val(sectionData.leftTop.link);
143
    container.find('#topLeftImage').attr('src',sectionData.leftTop.image);
144
 
145
    container.find('#bottomLeftFile').val(sectionData.leftBottom.image.split('/').filter(Boolean).pop());
146
    container.find('#bottomLeftLink').val(sectionData.leftBottom.link);
147
    container.find('#bottomLeftImage').attr('src',sectionData.leftBottom.image);
148
 
149
    container.find('#bottomRightFile').val(sectionData.rightTop.image.split('/').filter(Boolean).pop());
150
    container.find('#bottomRightLink').val(sectionData.rightTop.link);
151
    container.find('#bottomRightImage').attr('src',sectionData.rightTop.image);
152
 
153
    container.find('#topRightFile').val(sectionData.rightBottom.image.split('/').filter(Boolean).pop());
154
    container.find('#topRightLink').val(sectionData.rightBottom.link);
155
    container.find('#topRightImage').attr('src',sectionData.rightBottom.image);
156
}
157
$(document).on('click', ".pages-list", function () {
158
    doGetAjaxRequestHandler(context + "/pages", (response) => {
159
        $('#main-content').html(response);
160
        //$('#pages-list').DataTable();
161
        console.log('loaderDialogObj',loaderDialogObj);
162
    });
163
});
164
 
165
$(document).on('click', '.view-page', function (ev) {
166
    ev.preventDefault();
167
    let pageId = $(this).parent().parent('tr').data('id');
168
    doGetAjaxRequestHandler(context + "/pages/"+pageId,(response) => {
169
        const sectionData = JSON.parse(response.sectionData);
170
        $('#id').val(response.id);
171
        $('#title').val(response.title);
172
        $('#tabTitle').val(response.tabTitle);
173
        $('#visible_on').val(response.visibleOn).trigger('change');
174
        $('#section_order').val(response.sectionOrder);
34949 vikas 175
        $('#group').val(response.sectionGroup).trigger('change');
34859 vikas 176
        $('#style').val(sectionData.style+'Hero').trigger('change');
177
        $('#below').val(response.sectionBelow).trigger('change');
178
        $('#status').prop('checked', response.status);
179
        patchSectionData(sectionData);
180
        $('#managePagesModal').modal('show');
181
    });
182
});
183
 
184
function validateRequiredFields(fields) {
185
    let isValid = true;
186
    fields.each(function () {
187
        if (!$(this).val()) {
188
            isValid = false;
189
            $(this).addClass('is-invalid');
190
        } else {
191
            $(this).removeClass('is-invalid');
192
        }
193
    });
194
    return isValid;
195
}
196
 
197
$(document).on('click', ".save_page", function () {
198
    const selectedStyle = $('#style').val();
199
    const imgURL = $('#imgURL').val();
200
 
201
    if (!selectedStyle) {
202
        alert("Please select a style");
203
        return;
204
    }
205
 
206
    const container = $('.style-container');
207
    const styleEntry = {
208
        style: selectedStyle.replace('Hero', '').toLowerCase(),
209
        hero: {
210
            image: imgURL+container.find('#heroFile').val() || '',
211
            link: container.find('#heroLink').val() || ''
212
        },
213
        leftTop: {
214
            image: imgURL+container.find('#topLeftFile').val() || '',
215
            link: container.find('#topLeftLink').val() || ''
216
        },
217
        leftBottom: {
218
            image: imgURL+container.find('#bottomLeftFile').val() || '',
219
            link: container.find('#bottomLeftLink').val() || ''
220
        },
221
        rightTop: {
222
            image: imgURL+container.find('#topRightFile').val() || '',
223
            link: container.find('#topRightLink').val() || ''
224
        },
225
        rightBottom: {
226
            image: imgURL+container.find('#bottomRightFile').val() || '',
227
            link: container.find('#bottomRightLink').val() || ''
34949 vikas 228
        },
229
        doubleLeft: {
230
            image: imgURL+container.find('#doubleLeftFile').val() || '',
231
            link: container.find('#doubleLeftLink').val() || ''
232
        },
233
        doubleRight: {
234
            image: imgURL+container.find('#doubleRightFile').val() || '',
235
            link: container.find('#doubleRightLink').val() || ''
236
        },
237
        single: {
238
            image: imgURL+container.find('#singleFile').val() || '',
239
            link: container.find('#singleLink').val() || ''
34859 vikas 240
        }
241
    };
242
 
243
 
244
    const params = {
245
        id: $('#id').val() || 0,
246
        title: $('#title').val() || 'Untitled',
247
        visibleOn: $('#visible_on').val() || 'Home',
248
        tabTitle: $('#tabTitle').val() || 'Untitled',
249
        sectionGroup: $('#group').val() || 'Parent',
250
        sectionOrder: $('#section_order').val() ||  0,
251
        sectionData: JSON.stringify(styleEntry),
252
        sectionBelow: $('#below').val(),
253
        status: $('#status').prop('checked'),
254
    };
255
    console.log('params:', params);
256
    doAjaxRequestWithJsonHandler(context + "/pages", "POST", JSON.stringify(params), (response) => {
257
        if (response) {
258
            $('.pages-list').trigger('click');
259
            $('#managePagesModal').modal('hide');
260
            alert("Saved successfully");
261
        } else {
262
            alert("Something went wrong!");
263
        }
264
    });
265
});
266
 
267
$(document).on('click', ".delete-page", function() {
268
    const id = parseInt($(this).closest('td').data('id')) || 0;
269
    console.log("id",id);
270
    if (confirm("Are you sure you want to delete this record")) {
271
        if (id > 0) {
272
            doDeleteAjaxRequestHandler(context + "/pages/" + id, (response) => {
273
                if (response) {
274
                    $(this).parent('td').closest('tr').remove();
275
                    $('.pages-list').trigger('click');
276
                    alert("Deleted successfully");
277
                } else {
278
                    alert("Something went wrong!");
279
                }
280
            });
281
        } else {
282
            $(this).parent('td').closest('tr').remove();
283
        }
284
    }
285
});
286
 
287
$(document).on('change', "#style", function() {
288
    var selectedStyle = $(this).val();
289
    $('.style-container').empty();
34949 vikas 290
    if (selectedStyle === 'leftHero') $('.style-container').append(leftHero);
291
    if (selectedStyle === 'rightHero') $('.style-container').append(rightHero);
292
    if (selectedStyle === 'centerHero') $('.style-container').append(centerHero);
293
    if (selectedStyle === 'doubleHero') $('.style-container').append(doubleHero);
294
    if (selectedStyle === 'singleHero') $('.style-container').append(singleHero);
34859 vikas 295
});
296
 
297
$(document).on('click', '.style-container img', function () {
298
    const container = $(this).closest('td');
299
    const fileInput = container.find('input[type="file"]');
300
    fileInput.click();
301
});
302
 
303
$(document).on('change', '.style-container input[type="file"]', function (event) {
304
    const files = event.target.files;
305
    if (files.length > 0) {
306
        const container = $(this).closest('td');
307
        const img = container.find('img').first();
308
        const hiddenInput = container.find('input[type="hidden"]');
309
 
310
        img.attr('src', URL.createObjectURL(files[0]));
311
        img.on('load', function () {
312
            URL.revokeObjectURL(img.attr('src'));
313
        });
314
 
315
        uploadDocument(files[0], function (id) {
316
            hiddenInput.val(id);
317
        });
318
    }
319
});
320
 
321
$(document).on('change', '#group', function (event) {
322
    if ($(this).val() == '') $('.optional').show();
323
    else $('.optional').hide();
324
});