@{
ViewBag.Title = "Edit Aspect";
Layout = "~/Areas/Administrator/Views/Shared/_Layout.cshtml";
}
@if( false ){
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/jquery-ui.js"></script>

<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.8/jquery.validate.min.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/mvc/3.0/jquery.validate.unobtrusive.min.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/mvc/3.0/jquery.unobtrusive-ajax.min.js"></script>


<script type="text/javascript" src="https://github.com/jquery/jquery-tmpl/raw/master/jquery.tmpl.min.js"></script>
<script type="text/javascript" src="http://cloud.github.com/downloads/SteveSanderson/knockout/knockout-1.2.0.js"></script>
<script type="text/javascript" src="https://github.com/SteveSanderson/knockout.mapping/raw/master/build/output/knockout.mapping-latest.debug.js"></script>
}
@{ Html.BeginForm("Edit","Aspects", FormMethod.Post, new { @id = "__frmAspect"}); }
@( Html.ValidationSummary(false) )
@( Html.AntiForgeryToken() )
@( Html.EditorFor(model => model) )
<h2>Properties</h2>
<hr />
<br class="space" />
<div class="clearfix right">
<button type="submit">Submit</button>
</div>
@{ Html.EndForm(); }

<script type="text/javascript">

// Construct knockout view models for persisting the aspect
var viewModel = {
// a GUID that the user will never be able to edit. This
// is assigned, maintained, and persisted by the server.
Id
: ko.observable(),
Name
: ko.observable(),
Description
: ko.observable(),
Archetype
: ko.observable(),
Classification
: ko.observable(),
Properties
: ko.observableArray([]),

Save: function () {
alert('we reached the save function.');

// we will try to send the model to the server.
ko.utils.postJson(
$("#__frmAspect").attr('action'),
{ model: ko.toJS(this) }
);
}
};

// ----------------------------------------------------------------------- //
// **************************** MODEL BINDING **************************** //
// ----------------------------------------------------------------------- //

// apply the knockout binding to the viewModel
ko.applyBindings(viewModel, $("#__frmAspect")[0]);

// attach the jquery unobtrusive validator
$.validator.unobtrusive.parse("#__frmAspect");

// bind the submit handler to unobtrusive validation.
$("#__frmAspect").validate({
submitHandler: function () {
viewModel.Save();
}
});
</script>