@model ProductVariantModel.ProductVariantAttributeValueListModel

@using Telerik.Web.Mvc.UI;
@using (Html.BeginForm(null, null, FormMethod.Post, new { id = "productvariantattribute-form" }))
{
<div class="section-header">
    <div class="title">
        <img src="@Url.Content("~/Administration/Content/images/ico-catalog.png")" alt="" />
        @string.Format(T("Admin.Catalog.Products.Variants.ProductVariantAttributes.Attributes.Values.EditAttributeDetails").Text, Model.ProductVariantAttributeName, Model.ProductVariantName)
        @Html.ActionLink("(" + T("Admin.Catalog.Products.Variants.ProductVariantAttributes.Attributes.Values.BackToProductVariant") + ")", "Edit", "ProductVariant", new { Id = Model.ProductVariantId }, null)
    </div>
    <div class="options">
    </div>
</div>
<table class="adminContent">
    <tr>
        <td>
            @(Html.Telerik().Grid<ProductVariantModel.ProductVariantAttributeValueModel>()
                            .Name("pvav-grid")
                            .DataKeys(x =>
                            {
                                x.Add(y => y.Id).RouteKey("pvavId");
                                x.Add(y => y.ProductVariantAttributeId).RouteKey("productVariantAttributeId");
                            })
                            .Columns(columns =>
                            {
                                columns.Bound(x => x.Name)
                                    .Width(300);
                                //TODO display localized values here
                                columns.Bound(x => x.PriceAdjustment)
                                    .Width(100)
                                    .Centered();
                                columns.Bound(x => x.WeightAdjustment)
                                    .Width(100)
                                    .Centered();
                                columns.Bound(x => x.IsPreSelected)
                                    .Width(100)
                                    .Template(x => x.IsPreSelected.ToString().ToLower())
                                    .Centered();
                                columns.Bound(x => x.DisplayOrder)
                                    .Width(100)
                                    .Centered();
                                columns.Bound(x => x.Id)
                                    .Width(50)
                                    .Centered()
                                    .ClientTemplate("<input type='submit' id='btnEditValue<#= Id #>' name='btnEditValue<#= Id #>' value='Edit' onclick=\"" + "javascript:OpenWindow('" + @Url.Content("~/Admin/ProductVariant/ProductAttributeValueEditPopup/") + "<#= Id #>?btnId=btnRefresh&formId=productvariantattribute-form', 800, 250, true); return false;\" class='t-button' />")
                                    .Title(T("Admin.Common.Edit").Text);
                                columns.Command(commands =>
                                {
                                    commands.Delete();
                                })
                                .Width(50)
                                .Title(T("Admin.Common.Delete").Text);
                            })
                            .DataBinding(dataBinding =>
                                dataBinding.Ajax()
                                .Select("ProductAttributeValueList", "ProductVariant", new { productVariantAttributeId = Model.ProductVariantAttributeId })
                                .Delete("ProductAttributeValueDelete", "ProductVariant"))
                            .EnableCustomBinding(true))
        </td>
    </tr>
    <tr>
        <td width="100%">
            <input type="submit" id="btnAddNewValue" name="btnAddNewValue" value="@T("Admin.Catalog.Products.Variants.ProductVariantAttributes.Attributes.Values.AddNew")" onclick="javascript:OpenWindow('@(Url.Action("ProductAttributeValueCreatePopup", "ProductVariant", new { productAttributeAttributeId = Model.ProductVariantAttributeId, btnId = "btnRefresh", formId="productvariantattribute-form" }))', 800, 400, true); return false;" class="t-button" />
            <input type="submit" id="btnRefresh" name="btnRefresh" style="display: none" />
            <script type="text/javascript">
                $(document).ready(function () {
                    $('#btnRefresh').click(function () {
                        //refresh grid
                        var optionsGrid = $("#pvav-grid");
                        optionsGrid.data('tGrid').ajaxRequest();

                        //return false to don't reload a page
                        return false;
                    });
                });
            </script>
        </td>
    </tr>
</table>
}