@model EForT.Models.PublisherModel

@if (Model.EditPublisher != null)
{
<div class="modal fade text-left" id="editPubModal" tabindex="-1" role="dialog" aria-labelledby="editPublisherModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="editPubModalLabel">Manage Publisher</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <form id="editPubisherForm" asp-action="ManagePublisher" asp-controller="Publisher" method="post">
                <input type="hidden" asp-for="EditPublisher.Id" id="hdnId" />
                <div class="modal-body">
                    <fieldset class="form-group floating-label-form-group">
                        <label for="UserName">User Name: <i class="warning">*</i></label>
                        <select class="form-control" asp-for="EditPublisher.UserId" id="UserId" onchange="getForexForEditPub(this, @Model.EditPublisher.ForexAccount)" required>
                            <option value="" selected disabled>Select</option>
                            @if (Model.ListBasicTraders != null)
                            {
                                if (Model.ListBasicTraders.Count > 0)
                                {
                                    for (int i = 0; i < Model.ListBasicTraders.Count; i++)
                                    {
                                        <option value="@Model.ListBasicTraders[i].LoginId">@Model.ListBasicTraders[i].Login.Username</option>
                                    }
                                }
                            }
                        </select>
                    </fieldset>
                    <fieldset class="form-group floating-label-form-group">
                        <label for="EditPubForexAccount">Forex Account: <i class="warning">*</i></label>
                        <select class="form-control" asp-for="EditPublisher.ForexAccount" id="EditPubForexAccount" required>
                            <option value="" disabled selected>Select</option>
                            @if (Model?.ListAvailableForexAccounts?.Count > 0)
                            {
                                for (int i = 0; i < Model.ListAvailableForexAccounts.Count; i++)
                                {
                                    var login = Model.ListAvailableForexAccounts[i];
                                    <option value="@login.ForexId" selected>@login.ForexId (@login.Server)</option>
                                }
                            }
                        </select>
                    </fieldset>
                    <fieldset class="form-group floating-label-form-group">
                        <label for="ForexAccount">Server: </label>
                        <select class="form-control" asp-for="EditPublisher.ServerId" id="ServerId" onchange="getTerminalsForServerPubEdit(this)">
                            <option value="" selected>Select</option>
                            @if (Model.ListServers.Count > 0)
                            {
                                for (int i = 0; i < Model.ListServers.Count; i++)
                                {
                                    var server = Model.ListServers[i];
                                    <option value="@server.Id">@server.ServerName</option>
                                }
                            }
                        </select>
                    </fieldset>
                    <fieldset class="form-group floating-label-form-group">
                        <label for="ForexAccount">Terminal: </label>
                        <select class="form-control" asp-for="EditPublisher.TerminalId" id="EditPubTerminalForServer">
                            <option value="" selected>Select</option>
                            @if (Model.ListTerminals.Count > 0)
                            {
                                for (int i = 0; i < Model.ListTerminals.Count; i++)
                                {
                                    var terminal = Model.ListTerminals[i];
                                    <option value="@terminal.Id">@terminal.TerminalInstance (Id: @terminal.Id)</option>
                                }
                            }
                        </select>
                    </fieldset>
                    <fieldset class="form-group floating-label-form-group">
                        <label for="ExpertAdvisorId">Expert Advisor: </label>
                        <select class="form-control" asp-for="EditPublisher.ExpertAdvisorId" id="ExpertAdvisorId">
                            <option value="" selected>Select</option>
                            @if (Model.ListExpertAdvisors != null)
                            {
                                if (Model.ListExpertAdvisors.Count > 0)
                                {
                                    for (int i = 0; i < Model.ListExpertAdvisors.Count; i++)
                                    {
                                        <option value="@Model.ListExpertAdvisors[i].Id">@Model.ListExpertAdvisors[i].Name</option>
                                    }
                                }
                            }
                        </select>
                    </fieldset>
                    <fieldset class="form-group">
                        <label for="Report" class="position-relative">Advertise On:</label>

                        <input type="checkbox" asp-for="EditPublisher.ShowOnHome" class="defaultCheckbox" id="ShowOnHome">
                        <label for="ShowOnHome">Home</label>
                        <input type="checkbox" asp-for="EditPublisher.ShowOnLanding" class="defaultCheckbox" id="ShowOnLanding">
                        <label for="ShowOnLanding">Landing</label>
                        <input type="checkbox" asp-for="EditPublisher.ShowOnOther" class="defaultCheckbox" id="ShowOnOther">
                        <label for="ShowOnOther">Other</label>
                    </fieldset>
                </div>
                <div class="modal-footer">
                    <input disabled id="btn-edit-publisher" type="submit" class="btn btn-primary" value="Save Changes">
                    <input type="reset" class="btn btn-secondary" data-dismiss="modal" value="Close">
                </div>
            </form>
        </div>
    </div>
</div>

}
<script>
    $('#editPubisherForm select').change(function () {
        if (parseInt($("#EditPubForexAccount").val()) > 0) {
            $("#btn-edit-publisher").removeAttr("disabled");
        } else {
            $("#btn-edit-publisher").attr("disabled", true);
        }
    });
</script>