<commit_before>﻿@using NinjaHive.WebApp.Controllers
@using NinjaHive.WebApp.Extensions
@using NinjaHive.WebApp.Helpers
@model NinjaHive.WebApp.Models.GameItemViewModel

<div class="row">
    <div class="page-header">
        <h2>
            Game Item <small>Edit</small>
        </h2>
    </div>

    <div class="col-md-offset-10">
        <button id="deleteItem" type="button" class="btn btn-danger">Delete</button>
    </div>

    @{ Html.BeginForm<ItemsController>(c => c.Edit(null), new { @class = "form-horizontal", role = "form" }); }
    @Html.AntiForgeryToken()

    @Html.Partial(Partials.EditGameItem, Model)

    <div class="form-group">
        <div class="col-md-12">
            <input type="submit" class="btn btn-primary" value="Save changes" />
        </div>
    </div>

    @{ Html.EndForm(); }
</div>

@section Scripts {
    <script>
        $(function() {
            $("#deleteItem").click(function() {
                var result = true; //TODO: model dialog box: are you sure?

                if (result) {
                    @{
                        var deleteUrl = UrlProvider<ItemsController>.GetUrl(c => c.Delete(Model.GameItem.Id));
                        var redirectUrl = UrlProvider<ItemsController>.GetUrl(c => c.Index());
                    }
                    $.post("@deleteUrl", function() {
                        window.location.href = "@redirectUrl";
                    });
                }
            });
        });
    </script>
}<commit_msg>Added modal for item deletion and fixed anti-forgery token issues, closes issue #11<commit_after>﻿@using NinjaHive.WebApp.Controllers
@using NinjaHive.WebApp.Extensions
@using NinjaHive.WebApp.Helpers
@model NinjaHive.WebApp.Models.GameItemViewModel


<div class="row">
    <div class="page-header">
        <h2>
            Game Item <small>Edit</small>
        </h2>
    </div>

    <div class="col-md-offset-10">
        <button id="deleteItem" type="button" class="btn btn-danger">Delete</button>
    </div>

    @{ Html.BeginForm<ItemsController>(c => c.Edit(null), new { @class = "form-horizontal", role = "form", name="itemEditForm" }); }
    @Html.AntiForgeryToken()

    @Html.Partial(Partials.EditGameItem, Model)

    <div class="form-group">
        <div class="col-md-12">
            <input type="submit" class="btn btn-primary" value="Save changes" />
        </div>
    </div>

    @{ Html.EndForm(); }
</div>
@Scripts.Render("~/bundles/ninjahive")

@section Scripts {
    <script>
        $(function() {
            $("#deleteItem").click(function () {
                
                ninjaHive.modal.questionDialog("Are You Sure?", "Are you sure that you want to delete this item? This action cannot be undone and all associated information with this item will be lost.")
                    .on("submit", function (evt) {
                        @{
                            var deleteUrl = UrlProvider<ItemsController>.GetUrl(c => c.Delete(Model.GameItem.Id));
                            var redirectUrl = UrlProvider<ItemsController>.GetUrl(c => c.Index());
                        }

                        var itemForm = document.forms['itemEditForm'];
                        $.ajax({
                            url: "@deleteUrl",
                            type: 'POST',
                            data: {
                                __RequestVerificationToken: itemForm['__RequestVerificationToken'].value,
                                id: itemForm['GameItem.Id'].value
                            },
                            success: function(data, status, ajax)
                            {
                                ninjaHive.modal.alertDialog("SUCCESS!","Redirecting...");
                                window.location.href = "@redirectUrl";
                            },
                            error: function(ajax, status, error)
                            {
                                ninjaHive.modal.alertDialog("An Error Has Occurred", "There was an error processing your request. Please try again later.");
                                console.log("RequestError:" + error);
                            }
                        });
                    });
            });
        });
    </script>
}
{'fraction_non_alphanumeric': 0.1345343940102948, 'fraction_numerical': 0.003275620028076743, 'mean_word_length': 1.5940533980582525, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2964971', 'n_tokens_mistral': 1183, 'n_tokens_neox': 1127, 'n_words': 231}