ildar-shaymukhametov_grandnode-refactorings/Grand.Web/Areas/Admin/Views/CustomerReminder/_ConditionCustomerRegister.cshtml
@model CustomerReminderModel.ConditionModel

    @if (String.IsNullOrEmpty(Model.Id))
    {
        <div class="note note-info">
            @T("Admin.Customers.CustomerReminder.Condition.SaveBeforeEdit")
        </div>
    }
    @if (!String.IsNullOrEmpty(Model.Id))
    {

        <div class="panel panel-default">
            <div class="panel-body">
                <div id="customerregister-grid"></div>
            </div>
        </div>

        <script>
        $(document).ready(function () {
        $("#customerregister-grid").kendoGrid({
            dataSource: {
                transport: {
                    read: {
                        url: "@Html.Raw(Url.Action("ConditionCustomerRegister", "CustomerReminder", new { customerReminderId = Model.CustomerReminderId, conditionId = Model.Id }))",
                        type: "POST",
                        dataType: "json",
                        data: addAntiForgeryToken
                    },
                    create: {
                        url: "@Html.Raw(Url.Action("ConditionCustomerRegisterInsert", "CustomerReminder", new { customerReminderId = Model.CustomerReminderId, conditionId = Model.Id }))",
                        type: "POST",
                        dataType: "json",
                        data: addAntiForgeryToken
                    },
                    update: {
                        url: "@Html.Raw(Url.Action("ConditionCustomerRegisterUpdate", "CustomerReminder", new { customerReminderId = Model.CustomerReminderId, conditionId = Model.Id }))",
                        type: "POST",
                        dataType: "json",
                        data: addAntiForgeryToken
                    },
                    destroy: {
                        url: "@Html.Raw(Url.Action("ConditionDeletePosition", "CustomerReminder", new { customerReminderId = Model.CustomerReminderId, conditionId = Model.Id }))",
                        type: "POST",
                        dataType: "json",
                        data: addAntiForgeryToken
                    }
                },
                schema: {
                    data: "Data",
                    total: "Total",
                    errors: "Errors",
                    model: {
                        id: "Id",
                        fields: {
                            CustomerRegisterName: { editable: true, type: "string" },
                            CustomerRegisterValue: { editable: true, type: "string" },
                            Id: { editable: false, type: "string" }
                        }
                    }
                },
                requestEnd: function (e) {
                    if (e.type == "create" || e.type == "update") {
                        this.read();
                    }
                },
                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
            },
            toolbar: [{ name: "create", text: "@T("Admin.Common.AddNewRecord")" }],
            editable: {
                confirmation: false,
                mode: "inline",
            },
            scrollable: false,
            columns: [{
                    field: "CustomerRegisterName",
                    title: "@T("Admin.Customers.CustomerReminder.Condition.Fields.CustomerRegisterName")",
                    width: 200,
                    editor: crDropDownEditor,
                    template: "#:CustomerRegisterName#"
                }, {
                    field: "CustomerRegisterValue",
                    title: "@T("Admin.Customers.CustomerReminder.Condition.Fields.CustomerRegisterValue")",
                    width: 200,
                },
                {
                command: [
                    {
                        name: "edit",
                        text: {
                            edit: "@T("Admin.Common.Edit")",
                            update: "@T("Admin.Common.Update")",
                            cancel: "@T("Admin.Common.Cancel")"
                        }
                },{
                    name: "destroy",
                    text: "@T("Admin.Common.Delete")"
                }],
                width: 200
            }]
        });
    });


    function crDropDownEditor(container, options) {
        $('<input required data-text-field="Name" data-value-field="Id" data-bind="value:CustomerRegisterName"/>')
            .appendTo(container)
            .kendoDropDownList({
                autoBind: false,
                dataSource:
                {
                    transport: {
                        read: "@Html.Raw(Url.Action("CustomerRegisterFields", "CustomerReminder"))"
                    }
                },
                optionLabel: " -- Select -- "
            });
        }
        </script>
    }
