@model SpecificationAttributeModel

<link rel="stylesheet" type="text/css" asp-src="@(Common.WwwRoot)/administration/farbtastic/farbtastic.css" />
<script asp-location="Footer" asp-src="@(Common.WwwRoot)/administration/farbtastic/farbtastic.js"></script>

@{
    if (!String.IsNullOrEmpty(Model.Id))
    {

        <div class="panel panel-default">
            <vc:admin-widget widget-zone="specification_attribute_details_options_top" additional-data="null" />
            <div class="panel-body">
                <div id="specificationattributeoptions-grid"></div>
            </div>
            <div class="panel-footer">
                <a id="btnAddNewOption" href="@(Url.Action("OptionCreatePopup", "SpecificationAttribute", new { specificationAttributeId = Model.Id, area = Constants.AreaAdmin }))" class="k-button"><i class="fa fa-plus"></i>&nbsp;@Loc["Admin.Catalog.Attributes.SpecificationAttributes.Options.AddNew"]</a>
                <input type="submit" id="btnRefresh" style="display: none" />
            </div>
            <vc:admin-widget widget-zone="specification_attribute_details_options_bottom" additional-data="Model" />
        </div>

        <script>
            $(document).ready(function () {
                $('#btnAddNewOption').magnificPopup({
                    type: 'ajax',
                    settings: { cache: false, async: false },
                    midClick: true,
                    callbacks: {
                        parseAjax: function (mfpResponse) {
                            mfpResponse.data = $('<div></div>').html(mfpResponse.data);
                        },
                        ajaxContentAdded: function () {
                            $('.mfp-wrap').removeAttr('tabindex');
                        }
                    }
                });
                $("#specificationattributeoptions-grid").kendoGrid({
                    dataBound: function () {
                        $('.editoption').magnificPopup({
                            type: 'ajax',
                            settings: { cache: false, async: false },
                            midClick: true,
                            callbacks: {
                                parseAjax: function (mfpResponse) {
                                    mfpResponse.data = $('<div></div>').html(mfpResponse.data);
                                },
                                ajaxContentAdded: function () {
                                    $('.mfp-wrap').removeAttr('tabindex');
                                }
                            }
                        });
                    },
                    dataSource: {
                        transport: {
                            read: {
                                url: "@Html.Raw(Url.Action("OptionList", "SpecificationAttribute", new { specificationAttributeId = Model.Id, area = Constants.AreaAdmin }))",
                                type: "POST",
                                dataType: "json",
                                data: addAntiForgeryToken
                            },
                            destroy: {
                                url: "@Html.Raw(Url.Action("OptionDelete", "SpecificationAttribute", new { area = Constants.AreaAdmin }))",
                                type: "POST",
                                dataType: "json",
                                data: addAntiForgeryToken
                            }
                        },
                        schema: {
                            data: "Data",
                            total: "Total",
                            errors: "Errors",
                            model: {
                                id: "Id"
                            }
                        },
                        error: function(e) {
                            display_kendoui_grid_error(e);
                            // Cancel the changes
                            this.cancelChanges();
                        },
                        serverPaging: true,
                        serverFiltering: true,
                        serverSorting: true
                    },
                    pageable: {
                        refresh: true,
                        numeric: false,
                        previousNext: false,
                        info: false
                    },
                    editable: {
                        confirmation: true,
                        mode: "inline"
                    },
                    autoBind: false,
                    scrollable: false,
                    columns: [{
                        field: "Name",
                        title: "@Loc["Admin.Catalog.Attributes.SpecificationAttributes.Options.Fields.Name"]",
                        template: "<a class='k-link editoption' href=\"@Url.Action("OptionEditPopup", "SpecificationAttribute", new { area = Constants.AreaAdmin })/#=Id#\">#=kendo.htmlEncode(Name)#</a>"
                    }, {
                        field: "DisplayOrder",
                        title: "@Loc["Admin.Catalog.Attributes.SpecificationAttributes.Options.Fields.DisplayOrder"]",
                        width: 100
                    }, {
                        field: "NumberOfAssociatedProducts",
                        title: "@Loc["Admin.Catalog.Attributes.SpecificationAttributes.Options.Fields.NumberOfAssociatedProducts"]",
                        width: 150
                    }, {
                        command: {name: "destroy", text: "@Loc["Admin.Common.Delete"]"},
                        title: "@Loc["Admin.Common.Delete"]",
                        width: 100
                    }]
                });
            });
        </script>
        <script>
            $(document).ready(function () {
                $('#btnRefresh').click(function () {
                    //refresh grid
                    var grid = $("#specificationattributeoptions-grid").data('kendoGrid');
                    grid.dataSource.read();

                    //return false to don't reload a page
                    return false;
                });
            });
        </script>
    }
    else
    {
        <div class="note note-info">
            @Loc["Admin.Catalog.Attributes.SpecificationAttributes.Options.SaveBeforeEdit"]
        </div>
    }

}