Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
23914 govind 1
<script type="text/javascript">
30601 amit.gupta 2
    $('input[name="extendSchemeById"]').daterangepicker($.extend(getSingleDatePicker(), {
30017 amit.gupta 3
        "drops": "up",
30601 amit.gupta 4
    }));
30680 amit.gupta 5
    $('input[name="expireSchemeById"]').daterangepicker($.extend(getSingleDatePicker(moment("$scheme.getEndDateTime()")), {
30601 amit.gupta 6
        "drops": "up",
7
    }));
30017 amit.gupta 8
 
36421 amit 9
    $(document).off('click.addScheme').on('click.addScheme', ".add-scheme", function () {
10
        $("#newItemToSchemeModal").modal({backdrop: true, show: true});
23914 govind 11
    });
36421 amit 12
    $(document).off('hidden.bs.modal.addScheme').on('hidden.bs.modal.addScheme', '#newItemToSchemeModal', function () {
30017 amit.gupta 13
        $("#addSchemeForm").trigger("reset");
14
    });
36421 amit 15
 
16
    // Edit scheme item date window
17
    $(document).on('click', '.edit-item-dates', function () {
18
        var row = $(this).closest('tr');
19
        row.find('.date-display').hide();
20
        row.find('.date-edit').show();
21
        row.find('.edit-item-dates').hide();
22
        row.find('.save-item-dates, .cancel-item-dates').show();
23
 
24
        // Initialize daterangepicker on the inline inputs
25
        var startInput = row.find('.edit-start-date');
26
        var endInput = row.find('.edit-end-date');
27
        if (!startInput.data('daterangepicker')) {
28
            var startVal = startInput.val() ? moment(startInput.val(), 'DD/MM/YYYY') : moment("$scheme.getStartDateTime()");
29
            var endVal = endInput.val() ? moment(endInput.val(), 'DD/MM/YYYY') : moment("$scheme.getEndDateTime()");
30
            startInput.daterangepicker($.extend(getSingleDatePicker(startVal), {"drops": "down"}));
31
            endInput.daterangepicker($.extend(getSingleDatePicker(endVal), {"drops": "down"}));
32
        }
33
    });
34
 
35
    $(document).on('click', '.cancel-item-dates', function () {
36
        var row = $(this).closest('tr');
37
        row.find('.date-display').show();
38
        row.find('.date-edit').hide();
39
        row.find('.edit-item-dates').show();
40
        row.find('.save-item-dates, .cancel-item-dates').hide();
41
    });
42
 
43
    // Convert DD/MM/YYYY to ISO LocalDateTime format for the server
44
    function toIsoDateTime(ddmmyyyy, endOfDay) {
45
        var parts = ddmmyyyy.split('/');
46
        if (parts.length !== 3) return ddmmyyyy;
47
        var isoDate = parts[2] + '-' + parts[1] + '-' + parts[0];
48
        return isoDate + (endOfDay ? 'T23:59:59' : 'T00:00:00');
49
    }
50
 
51
    $(document).on('click', '.save-item-dates', function () {
52
        var row = $(this).closest('tr');
53
        var itemId = row.data('schemeitemid');
54
        var startDate = row.find('.edit-start-date').val();
55
        var endDate = row.find('.edit-end-date').val();
56
        if (!startDate || !endDate) {
57
            alert('Both start date and end date are required');
58
            return;
59
        }
60
        var isoStart = toIsoDateTime(startDate, false);
61
        var isoEnd = toIsoDateTime(endDate, true);
62
        doPutAjaxRequestHandler('/scheme/item/window?schemeItemId=' + itemId
63
            + '&startDate=' + encodeURIComponent(isoStart)
64
            + '&endDate=' + encodeURIComponent(isoEnd),
65
            function (response) {
66
                loadSchemeDetails($scheme.getId(), "scheme-details-container");
67
            });
68
    });
69
 
70
    // Modal: category -> brand -> model cascade
71
    $('#newItemToSchemeModal').on('shown.bs.modal', function () {
72
        $('input[name="addItemStartDate"]').daterangepicker($.extend(getSingleDatePicker(moment("$scheme.getStartDateTime()")), {
73
            "drops": "down",
74
        }));
75
        $('input[name="addItemEndDate"]').daterangepicker($.extend(getSingleDatePicker(moment("$scheme.getEndDateTime()")), {
76
            "drops": "down",
77
        }));
78
 
79
        // Load brands for default category
80
        var catId = $('#modal-category-list').val();
81
        if (catId) loadModalBrands(catId);
82
    });
83
 
84
    $('#modal-category-list').on('change', function () {
85
        var catId = $(this).val();
86
        if (catId) loadModalBrands(catId);
87
    });
88
 
89
    function loadModalBrands(categoryId) {
90
        doGetAjaxRequestHandler(context + '/getBrandsByCategory?categoryId=' + categoryId, function (response) {
91
            $('#modal-brand-list').html(response);
92
            // Re-id the select so it doesn't clash with create-scheme page
93
            $('#modal-brand-list select').attr('id', 'modal-tag-listing-brands');
94
            $('#modal-tag-listing-brands').multiselect({
95
                includeSelectAllOption: true,
96
                multiple: true,
97
                maxHeight: 200,
98
                buttonWidth: '180px',
99
                numberDisplayed: 1,
100
                nonSelectedText: 'Brands',
101
                nSelectedText: ' - Brands Selected',
102
                allSelectedText: 'All Brands',
103
                enableFiltering: true,
104
                enableCaseInsensitiveFiltering: true
105
            });
106
            $('#modal-tag-listing-brands').on('change', function () {
107
                var brands = $(this).val();
108
                if (brands) loadModalModels(categoryId, brands);
109
            });
110
        });
111
    }
112
 
113
    function loadModalModels(categoryId, brands) {
114
        var brandsString = brands.join(',');
115
        doGetAjaxRequestHandler(context + '/getCatalogDescriptionByBrands?categoryId=' + categoryId + '&brands=' + brandsString, function (response) {
116
            $('#modal-models-list').html(response);
117
            $('#modal-models-list select').addClass('modalCatalogItems');
118
            $('.modalCatalogItems').multiselect({
119
                includeSelectAllOption: true,
120
                maxHeight: 200,
121
                buttonWidth: '220px',
122
                numberDisplayed: 1,
123
                nonSelectedText: 'Models',
124
                nSelectedText: ' - Models Selected',
125
                allSelectedText: 'All Models',
126
                enableFiltering: true,
127
                enableCaseInsensitiveFiltering: true
128
            });
129
        });
130
    }
30017 amit.gupta 131
</script>
22860 ashik.ali 132
<h3 style="padding-left:3%;padding-top:2%;font-weight:bold;">Scheme Id : $scheme.getId()</h3>
36452 amit 133
<h5 style="padding-left:3%;font-weight:normal;">Reference : #if($scheme.getReference())$scheme.getReference()#else-#end</h5>
23914 govind 134
 
22860 ashik.ali 135
<div class="row" style="padding-left:3%;">
30122 amit.gupta 136
    <div class="col-lg-12">
30017 amit.gupta 137
        <table>
138
            <tr>
139
                <td>
140
                    #if($scheme.getActiveTimestamp())
141
                        <span>Activated On : $scheme.getFormattedActiveTimestamp()</span>
142
                        <p></p>
143
                    #end
144
                    #if($scheme.getExpireTimestamp())
145
                        <span>Expired On : $scheme.getFormattedExpireTimestamp()</span>
146
                        <p></p>
147
                    #end
148
                </td>
149
                #if($isAdmin && $fullAccess)
150
                    <td>
151
                        <button class="btn btn-sm btn-primary add-scheme" data="$scheme.getId()"
36421 amit 152
                                style="width:100%;background-color:#007aff;color:white;padding-right: 10px">Add Item
30017 amit.gupta 153
                        </button>
154
                    </td>
155
                #end
156
            <tr>
157
        </table>
158
        <table class="table table-striped table-advance table-hover">
159
            <tbody>
160
            <tr>
30122 amit.gupta 161
                <th>Model ID</th>
162
                <th>Model Name</th>
36421 amit 163
                <th>Start Date</th>
164
                <th>End Date</th>
165
                <th>Updated By</th>
166
                <th>Updated On</th>
30017 amit.gupta 167
                #if($isAdmin && $fullAccess)
30122 amit.gupta 168
                    <th>Action</th>
30017 amit.gupta 169
                #end
170
            </tr>
36421 amit 171
                #if($schemeItems && $schemeItems.size()>0)
172
                    #foreach( $item in $schemeItems)
173
                    <tr data-schemeitemid="$item.getId()" data-catalogid="$item.getCatalogId()">
174
                        <td>$item.getCatalogId()</td>
175
                        <td>#if($scheme.getCatalogStringMap().containsKey($item.getCatalogId()))$scheme.getCatalogStringMap().get($item.getCatalogId())#else-#end</td>
176
                        <td>
177
                            <span class="date-display">#if($item.getStartDate())$dateFormatter.format($item.getStartDate())#else-#end</span>
178
                            <input type="text" class="form-control date-edit edit-start-date" style="display:none; width:160px" value="#if($item.getStartDate())$dateFormatter.format($item.getStartDate())#end">
179
                        </td>
180
                        <td>
181
                            <span class="date-display">#if($item.getEndDate())$dateFormatter.format($item.getEndDate())#else-#end</span>
182
                            <input type="text" class="form-control date-edit edit-end-date" style="display:none; width:160px" value="#if($item.getEndDate())$dateFormatter.format($item.getEndDate())#end">
183
                        </td>
184
                        <td>#if($item.getUpdatedBy())$item.getUpdatedBy()#else-#end</td>
185
                        <td>#if($item.getUpdatedOn())$dateTimeFormatter.format($item.getUpdatedOn())#else-#end</td>
186
                        #if($isAdmin && $fullAccess)
187
                        <td>
188
                            <button class="btn btn-xs btn-info edit-item-dates">Edit</button>
189
                            <button class="btn btn-xs btn-success save-item-dates" style="display:none">Save</button>
190
                            <button class="btn btn-xs btn-default cancel-item-dates" style="display:none">Cancel</button>
191
                            <button class="btn btn-xs btn-danger delete-schemes" data-schemeid="$scheme.getId()"
192
                                    data-catalogid="$item.getCatalogId()">Delete</button>
193
                        </td>
194
                        #end
195
                    </tr>
196
                    #end
197
                #elseif($scheme.getCatalogStringMap().size()>0)
30122 amit.gupta 198
                    #foreach( $catalogIdDescriptionEntry in $scheme.getCatalogStringMap().entrySet())
199
                    <tr data-catalogid="$catalogIdDescriptionEntry.getKey()">
200
                        <td>$catalogIdDescriptionEntry.getKey()</td>
30144 amit.gupta 201
                        <td>$catalogIdDescriptionEntry.getValue()</td>
36421 amit 202
                        <td colspan="4">-</td>
30017 amit.gupta 203
                        #if($isAdmin && $fullAccess)
204
                        <td>
205
                            <button class="btn btn-primary delete-schemes" data-schemeid="$scheme.getId()"
30122 amit.gupta 206
                                    data-catalogid="$catalogIdDescriptionEntry.getKey()">Delete
30017 amit.gupta 207
                            </button>
208
                        #end
209
                    </tr>
210
                    #end
211
                #else
212
                <tr>
213
                    <td colspan="12" style="text-align:center;">NO ITEM FOUND FOR SCHEME</td>
214
                </tr>
215
                #end
216
            </tbody>
217
        </table>
218
        <p></p>
29899 tejbeer 219
        #if($isAdmin && $fullAccess)
30017 amit.gupta 220
            <span>Created By : $scheme.getCreatedBy()</span>
221
            <p></p>
222
            #if((!$scheme.getActiveTimestamp()) && (!$scheme.getExpireTimestamp()))
223
                <div class="btn-group" style="width:40%">
224
                    <button class="btn active-scheme" data="$scheme.getId()"
225
                            style="width:100%;background-color:#e98c8f;color:white;">Active
226
                    </button>
227
                </div>
228
            #else
229
                #if(($scheme.getActiveTimestamp()) && (!$scheme.getExpireTimestamp()))
230
                    <table>
231
                        <td>
232
                            <div class="scheme-extend">
233
                                <div class="row">
234
                                    <div class="col-lg-12">
235
                                        <div class="input-group" style="width:80%">
236
                                            <input type="hidden" value="$scheme.getId()" id="schemeId">
30601 amit.gupta 237
                                            <input placeholder="Extend Date Time" id="extendSchemeById" type="text"
238
                                                   class="form-control" name="extendSchemeById">
239
                                            <span class="input-group-btn"> <button
240
                                                    class="btn btn-primary extendSchemeById"
241
                                                    id="extendScheme-button"
242
                                                    type="button">Extend</button></span>
30017 amit.gupta 243
                                        </div>
244
                                    </div>
245
                                </div>
246
                            </div>
247
                        </td>
248
                        <td>
249
                            <div class="input-group" style="width:80%">
250
                                <input type="hidden" value="$scheme.getId()" id="schemeId">
30601 amit.gupta 251
                                <input placeholder="Expire Time" type="text"
252
                                       class="form-control expireTime" id="exprireScheme" name="expireSchemeById">
30017 amit.gupta 253
                                <span class="input-group-btn">
25069 amit.gupta 254
								<button class="btn btn-primary expire-scheme" data="$scheme.getId()">Expire</button>
25068 amit.gupta 255
							</span>
30017 amit.gupta 256
                            </div>
257
                        </td>
258
                    </table>
259
                    <br><br>
260
                #end
261
            #end
262
        #end
263
    </div>
36421 amit 264
    <div id="newItemToSchemeModal" class="modal fade" role="dialog" tabindex="-1">
265
        <div class="modal-dialog modal-lg">
30017 amit.gupta 266
            <div class="modal-content">
267
                <div class="modal-header">
268
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
36421 amit 269
                    <h4 class="modal-title"><b>Add Item To Scheme (ID: $scheme.getId())</b></h4>
30017 amit.gupta 270
                </div>
271
                <div class="modal-body">
272
                    <form id="addSchemeForm">
36421 amit 273
                        <input type="hidden" value="$scheme.getId()" id="schemeids">
274
                        <div class="row">
275
                            <div class="col-lg-4">
276
                                <div class="form-group">
277
                                    <label><b>Category</b> <span style="color:red">*</span></label>
278
                                    <select class="form-control input-sm" id="modal-category-list">
279
                                        #foreach($category in $categories)
280
                                            <option value="$category.getId()">$category.getLabel()</option>
281
                                        #end
282
                                    </select>
283
                                </div>
30017 amit.gupta 284
                            </div>
285
                            <div class="col-lg-4">
36421 amit 286
                                <div class="form-group">
287
                                    <label><b>Brands</b> <span style="color:red">*</span></label>
288
                                    <div id="modal-brand-list"></div>
289
                                </div>
30017 amit.gupta 290
                            </div>
36421 amit 291
                            <div class="col-lg-4">
292
                                <div class="form-group">
293
                                    <label><b>Models</b> <span style="color:red">*</span></label>
294
                                    <div id="modal-models-list">
295
                                        <select class="form-control modalCatalogItems" multiple="multiple"></select>
296
                                    </div>
297
                                </div>
298
                            </div>
30017 amit.gupta 299
                        </div>
36421 amit 300
                        <div class="row">
301
                            <div class="col-lg-6">
302
                                <div class="form-group">
303
                                    <label><b>Start Date</b> <small>(optional, defaults to scheme start: $dateFormatter.format($scheme.getStartDateTime()))</small></label>
304
                                    <input type="text" class="form-control" id="addItemStartDate" name="addItemStartDate" placeholder="dd/mm/yyyy"/>
305
                                </div>
306
                            </div>
307
                            <div class="col-lg-6">
308
                                <div class="form-group">
309
                                    <label><b>End Date</b> <small>(optional, defaults to scheme end: $dateFormatter.format($scheme.getEndDateTime()))</small></label>
310
                                    <input type="text" class="form-control" id="addItemEndDate" name="addItemEndDate" placeholder="dd/mm/yyyy"/>
311
                                </div>
312
                            </div>
313
                        </div>
314
                        <div class="alert alert-info" style="margin-top:5px; padding:8px;">
315
                            Item dates must be within scheme window: <b>$dateFormatter.format($scheme.getStartDateTime())</b> to <b>$dateFormatter.format($scheme.getEndDateTime())</b>.
316
                            Non-overlapping windows are enforced per model within this scheme.
317
                        </div>
30017 amit.gupta 318
                    </form>
319
                </div>
320
                <div class="modal-footer">
321
                    <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
36421 amit 322
                    <button type="button" class="btn btn-primary add-item">Add Item</button>
30017 amit.gupta 323
                </div>
324
            </div>
325
        </div>
326
    </div>
22860 ashik.ali 327
</div>