Subversion Repositories SmartDukaan

Rev

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

Rev 34023 Rev 34070
Line 76... Line 76...
76
                        #end
76
                        #end
77
                    </select>
77
                    </select>
78
                </div>
78
                </div>
79
                <div class="form-group">
79
                <div class="form-group">
80
                    <label for="super_catalog_name">Super catalog name</label>
80
                    <label for="super_catalog_name">Super catalog name</label>
81
                    <select id="super_catalog_name" class="form-control selectOrCreate">
81
                    <select id="super_catalog_name" class="form-control selectOrCreate"></select>
82
                    #foreach($row in $allSuperCatalogs)
-
 
83
                        <option value="$row.getId()">$row.getSuperCatalogName()</option>
-
 
84
                    #end
-
 
85
                    </select>
-
 
86
                </div>
82
                </div>
87
                <table class="table" id="catalogMappingTable">
83
                <table class="table" id="catalogMappingTable">
88
                    <thead>
84
                    <thead>
89
                        <tr>
85
                        <tr>
90
                            <th>Catalog</th>
86
                            <th>Catalog</th>
91
                            <th>Variant</th>
87
                            <th>Variant</th>
92
                            <th><button class="btn btn-primary addNew"><i class="fa fa-plus"></i></button></th>
88
                            <th><button class="btn btn-primary addNew"><i class="fa fa-plus"></i></button></th>
93
                        </tr>
89
                        </tr>
94
                    </thead>
90
                    </thead>
95
                    <tbody id="catalogMapping">
91
                    <tbody id="catalogMapping"></tbody>
96
                        <tr>
-
 
97
                            <td>
-
 
98
                                <div class="form-group">
-
 
99
                                    <select id="catalog_id" class="form-control">
-
 
100
                                        <option value="" readonly selected>-- Select Catalog --</option>
-
 
101
                                        #foreach($row in $catalogs)
-
 
102
                                            <option value="$row.getId()">$row.getDescription()</option>
-
 
103
                                        #end
-
 
104
                                    </select>
-
 
105
                                </div>
-
 
106
                            </td>
-
 
107
                            <td>
-
 
108
                                <div class="form-group">
-
 
109
                                    <input id="variant_name" class="form-control" placeholder="Variant name">
-
 
110
                                    <input id="mapping_id" type="hidden" value="0">
-
 
111
                                </div>
-
 
112
                            </td>
-
 
113
                            <td>
-
 
114
                                <button class="btn btn-primary removeExisting"><i class="fa fa-minus"></i></button>
-
 
115
                            </td>
-
 
116
                        </tr>
-
 
117
                    </tbody>
-
 
118
                </table>
92
                </table>
119
            </div>
93
            </div>
120
            <div class="modal-footer">
94
            <div class="modal-footer">
121
                <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
95
                <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
122
                <button type="button" class="btn btn-primary save_super_model">Save</button>
96
                <button type="button" class="btn btn-primary save_super_model">Save</button>
123
            </div>
97
            </div>
124
        </div>
98
        </div>
125
    </div>
99
    </div>
126
</div>
100
</div>
127
 
101
 
128
<script type="text/javascript">
102
<script>
129
 
-
 
130
    $(document).ready(function (){
103
    $('.map-catalog').click(function () {
131
 
-
 
132
        const freshTr = `<tr>
-
 
133
                            <td>
-
 
134
                                <div class="form-group">
-
 
135
                                    <select id="catalog_id" class="form-control">
-
 
136
                                        <option value="" readonly selected>-- Select Catalog --</option>
-
 
137
                                        #foreach($row in $catalogs)
-
 
138
                                            <option value="$row.getId()">$row.getDescription()</option>
-
 
139
                                        #end
-
 
140
                                    </select>
-
 
141
                                </div>
-
 
142
                            </td>
-
 
143
                            <td>
-
 
144
                                <div class="form-group">
-
 
145
                                    <input id="variant_name" class="form-control" placeholder="Variant name">
-
 
146
                                    <input id="mapping_id" type="hidden" value="0">
-
 
147
                                </div>
-
 
148
                            </td>
-
 
149
                            <td>
-
 
150
                                <button class="btn btn-primary removeExisting"><i class="fa fa-minus"></i></button>
-
 
151
                            </td>
-
 
152
                        </tr>`;
-
 
153
 
-
 
154
        $('#catalog_id, #brand_id').multiselect({
-
 
155
            includeSelectAllOption: false,
-
 
156
            multiple:false,
-
 
157
            maxHeight: 200,
-
 
158
            buttonWidth: '100%',
-
 
159
            numberDisplayed: 1,
-
 
160
            nonSelectedText: '-- Select One --',
-
 
161
            nSelectedText: ' - Selected',
-
 
162
            enableFiltering: true,
-
 
163
            enableCaseInsensitiveFiltering : true
-
 
164
        });
-
 
165
 
-
 
166
        $('#manageSuperCatalogModal').on('hidden.bs.modal', function () {
104
        $('#manageSuperCatalogModal').on('show.bs.modal', function () {
167
            $('#mapping_id').val(0);
-
 
168
            $('#variant_name').val('');
105
            console.log("shown bs model")
169
            $('#brand_id').val('').trigger('change');
-
 
170
            $('#catalog_id').val('').trigger('change');
-
 
171
            $('#super_catalog_name').val('').trigger('change');
-
 
172
        });
-
 
173
 
-
 
174
        $('#manageSuperCatalogModal').on('click', '.addNew',function () {
-
 
175
            $('#catalogMapping').append(freshTr);
106
            $('tbody#catalogMapping').empty();
176
            const lastTr = $('#catalogMapping tr:last');
-
 
177
            lastTr.find('#catalog_id').multiselect({
-
 
178
                includeSelectAllOption: false,
-
 
179
                multiple:false,
-
 
180
                maxHeight: 200,
-
 
181
                buttonWidth: '100%',
-
 
182
                numberDisplayed: 1,
-
 
183
                nonSelectedText: '-- Select One --',
-
 
184
                nSelectedText: ' - Selected',
-
 
185
                enableFiltering: true,
-
 
186
                enableCaseInsensitiveFiltering : true
-
 
187
            });
-
 
188
        });
107
        });
189
 
-
 
190
        $('#manageSuperCatalogModal').on('click', '.removeExisting',function () {
-
 
191
            if (confirm("Are you sure you want to remove this")) {
-
 
192
                const tr = $(this).closest('tr');
-
 
193
                const mappingId = tr.data('mapping-id');
-
 
194
                if (mappingId > 0) {
-
 
195
                    doDeleteAjaxRequestHandler(context + "/super-catalog/mapping/" + mappingId, function (response) {
-
 
196
                        if (response == "true") {
-
 
197
                            tr.remove();
-
 
198
                        } else {
-
 
199
                            alert("Something went wrong while deleting the variant");
-
 
200
                        }
-
 
201
                    })
-
 
202
                } else {
-
 
203
                    tr.remove();
-
 
204
                }
-
 
205
            }
-
 
206
        });
-
 
207
 
-
 
208
        $('.selectOrCreate').select2({
-
 
209
            placeholder: "Select or add new",
-
 
210
            tags: true,
-
 
211
            createTag: function(params) {
-
 
212
                return {
-
 
213
                    id: params.term,
-
 
214
                    text: params.term,
-
 
215
                    newOption: true
-
 
216
                };
-
 
217
            },
-
 
218
            templateResult: function(data) {
-
 
219
                return data.newOption ? $('<span class="new-option">Add: ' + data.text + '</span>') : data.text;
-
 
220
            },
-
 
221
        });
-
 
222
 
-
 
223
        $('#super-catalog').on('click', '.view-super-catalog', function (ev) {
-
 
224
            ev.preventDefault();
-
 
225
            let superCatalogId = $(this).parent().parent('tr').data('id'),
-
 
226
                brand = $(this).parent().parent('tr').data('brand_name');
-
 
227
 
-
 
228
            doGetAjaxRequestHandler(context + "/super-catalog/"+superCatalogId,(response) => {
-
 
229
                $('#manageSuperCatalogModalBody').empty();
-
 
230
                $('#manageSuperCatalogModalBody').html(response);
-
 
231
                $('#manageSuperCatalogModal').modal('show');
-
 
232
                $('#catalog_id, #brand_id').multiselect({
-
 
233
                    includeSelectAllOption: false,
-
 
234
                    multiple:false,
-
 
235
                    maxHeight: 200,
-
 
236
                    buttonWidth: '100%',
-
 
237
                    numberDisplayed: 1,
-
 
238
                    nonSelectedText: '-- Select One --',
-
 
239
                    nSelectedText: ' - Selected',
-
 
240
                    allSelectedText: 'All Selected',
-
 
241
                    enableFiltering: true,
-
 
242
                    enableCaseInsensitiveFiltering : true
-
 
243
                });
-
 
244
            });
-
 
245
        });
-
 
246
 
-
 
247
        $('#super-catalog').DataTable();
-
 
248
 
-
 
249
    });
108
    })
250
 
-
 
251
</script>
109
</script>
252
110