Subversion Repositories SmartDukaan

Rev

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

<div class="form-group">
    <label for="brand_id">Select brand</label>
    <select id="brand_id" class="form-control">
        <option value="">-- Select --</option>
        #foreach($brand in $brands)
            <option value="$brand.getId()" #if($brand.getId() == $superCatalogModel.getBrandId()) selected="selected" #end>$brand.getName()</option>
        #end
    </select>
</div>
<div class="form-group">
    <label for="super_catalog_name">Super catalog name</label>
    <select id="super_catalog_name" class="form-control selectOrCreate">
        <option value="">-- Select --</option>
        #foreach($row in $superCatalogs)
            <option value="$row.getId()" #if($row.getId() == $superCatalogModel.getSuperCatalogId()) selected="selected" #end>$row.getSuperCatalogName()</option>
        #end
    </select>
</div>
<table class="table" id="catalogMappingTable">
    <thead>
    <tr>
        <th width="70%">Catalog</th>
        <th width="20%">Variant</th>
        <th width="10%"><button class="btn btn-primary addNew"><i class="fa fa-plus"></i></button></th>
    </tr>
    </thead>
    <tbody id="catalogMapping">
        #foreach($mapping in $superCatalogMapping)
        <tr data-mapping-id="$mapping.getId()">
            <td>
                <div class="form-group">
                    <select class="form-control catalog_id" id="catalog_id">
                        <option value="">-- Select Catalog --</option>
                        #foreach($row in $catalogs)
                            <option value="$row.getId()" #if($row.getId() == $mapping.getCatalogId()) selected="selected" #end>$row.getBrand() $row.getModelName() $row.getModelNumber()</option>
                        #end
                    </select>
                </div>
            </td>
            <td>
                <div class="form-group">
                    <input id="variant_name" class="form-control variant_name" placeholder="Variant name" #if($mapping.getVariantName()) value="$mapping.getVariantName()" #end>
                    <input type="hidden" id="mapping_id" value="$mapping.getId()">
                </div>
            </td>
            <td>
                <button class="btn btn-danger removeExisting"><i class="fa fa-times"></i></button>
            </td>
        </tr>
        #end
        <tr>
            <td>
                <div class="form-group">
                    <select class="form-control select2 catalog_id" id="catalog_id">
                        <option value="">-- Select Catalog --</option>
                        #foreach($row in $catalogs)
                            <option value="$row.getId()">$row.getBrand() $row.getModelName() $row.getModelNumber()</option>
                        #end
                    </select>
                </div>
            </td>
            <td>
                <div class="form-group">
                    <input id="variant_name" class="form-control variant_name" placeholder="Variant name">
                    <input type="hidden" id="mapping_id" value="0">
                </div>
            </td>
            <td>
                <button class="btn btn-primary removeExisting"><i class="fa fa-minus"></i></button>
            </td>
        </tr>
    </tbody>
</table>

<script>
    $(document).ready(function (){
        $('.selectOrCreate').select2({
            placeholder: "Select or add new",
            tags: true,
            createTag: function(params) {
                return {
                    id: params.term,
                    text: params.term,
                    newOption: true
                };
            },
            templateResult: function(data) {
                return data.newOption ? $('<span class="new-option">Add: ' + data.text + '</span>') : data.text;
            },
        });
    });
</script>