<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<IEnumerable<r14.Models.MountainInfo>>" %>
<%@ Import Namespace="r14.Helpers" %>
<%@ Import Namespace="r14.Models" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Szczyty</title>
    <link rel="Stylesheet" href="../../Content/site.css" />

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js" 
        type="text/javascript"></script> 
    <script type="text/javascript">
        $(function () {

           $("#summits tr:nth-child(even)").css("background-color", "silver");

           $("#summits form[action$='/DeleteItem']").live("submit", function () {
                var itemText = $("input[name='item']", this).val();
                return confirm("Czy na pewno chcesz usunąć '" + itemText + "'?");
            });
            $("<label><input id='heights' type='checkbox'/>Pokaż wysokości</label>")
                .insertBefore("#summits")
                .children("input").click(function () {
                    $("#summits td:nth-child(2)").toggle(this.checked);
                });
            $("#summits td:nth-child(2)").hide();

            $("#summits a").live("click", function () {
                $.get($(this).attr("href"), function (response) {
                    $("#summits").replaceWith($("#summits", response));

                    // Ponowne zastosowanie paskowania
                    $("#summits tr:even").addClass("alternate");

                    // Odzwierciedlenie stanu pola wyboru "Pokaż wysokości"
                    $("#summits td:nth-child(2)").toggle($("#heights")[0].checked);
                });
                return false;
            }); 
 

        }); 
    </script> 

</head>
<body>
<div>
<h2>Siedem szczytów</h2> 
<div id="summits"> 
    <table> 
        <thead><tr> 
            <td>Element</td> <td>Wysokość (m)</td> <td>Akcje</td> 
        </tr></thead> 
        <% foreach(var mountain in Model) { %>
            <tr> 
                <td><%: mountain.Name %></td> 
                <td><%: mountain.HeightInMeters %></td> 
                <td> 
                    <% using(Html.BeginForm("DeleteItem", "Home")) { %> 
                        <%: Html.Hidden("item", mountain.Name) %> 
                        <input type="submit" value="Usuń" /> 
                    <% } %> 
                </td> 
            </tr> 
        <% } %> 
    </table> 
    Strona: 
    <%: Html.PageLinks((PagingInfo)ViewData["pagingInfo"],  
                       i => Url.Action("Summits", new { page = i })) %> 
</div>

<p><i>Strona wygenerowana o godzinie <%: DateTime.Now.ToLongTimeString() %></i></p>
</div>
</body>
</html>
