1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
@model Facture.facture
@{ ViewBag.Title = "Facture ";}
@Html.TextBoxFor(m => m.Id, new { data_bind = "value: facture.Id" })
@Html.TextBoxFor(m => m.date, new { data_bind = "value: facture.date" })
@Html.TextBoxFor(m => m.dbl, new { data_bind = "value: facture.dbl" })
@Html.TextBoxFor(m => m.nom, new { data_bind = "value: facture.nom" })
@Html.TextBoxFor(m => m.prenom, new { data_bind = "value: facture.prenom" })
@Html.TextBoxFor(m => m.rue, new { data_bind = "value: facture.rue" })
@Html.TextBoxFor(m => m.cp, new { data_bind = "value: facture.cp" })
@Html.TextBoxFor(m => m.ville, new { data_bind = "value: facture.ville" })
<input type="text" id="Id" data-bind="value: facture.id" value="@Model.Id"/>
<input type="text" data-bind="value: facture.nom" />
<br />
<ul data-bind="foreach: facture.lignes">
@for (int i = 0; i < Model.lignes.Count(); i++) {
<li>
<input name="lignes[@i]" type="text" data-bind="value: code" />
@Html.TextBoxFor(m => m.lignes[i].code, new { data_bind = "value: code" })
@Html.TextBoxFor(m => m.lignes[i].lib, new { data_bind = "value: lib" })
@Html.TextBoxFor(m => m.lignes[i].qte, new { data_bind = "value: qte" })
@Html.TextBoxFor(m => m.lignes[i].pu, new { data_bind = "value: pu" })
@Html.TextBoxFor(m => m.lignes[i].pt, new { data_bind = "value: pt", disabled = "disabled" })
<input name="lignes[0]" type="button" value="Ajouter Ligne" onclick="Insert(this)" />
<input name="lignes[0]" type="button" value="Supprimer Ligne" onclick="Del(this)" />
</li>
}
</ul>
<input type="button" value="Modifier" onclick="Update()" />
<input type="button" value="Annuler" onclick="Cancel()" />
<input type="button" value="Enregistrer" onclick="Save()" />
@section scripts
{
<script>
var vm = {
facture: null
}
var Token = "@AjaxHeader.TokenHeaderValue()";
$(document).ready(function () {
});
function Insert() {
vm.facture.lignes.push({ code: "", lib: "", qte: 0, pu: 0, pt: 0 });
};
function Del() {
vm.facture.lignes.splice(0, 1);
};
function Cancel() {
};
function Update() {
Ajax("Facture", "GET", $("#Id").val(), null,
function (data, textStatus, jqXHR) {
ko.mapping.fromJS(data, vm);
vm.facture.lignes = ko.observableArray(data.lignes);
$('[data-bind*="foreach"] input:not([name*="0"])').parent().remove(); // Supprime les input sauf pour i=0
if (!ko.dataFor($('#Id').get(0))) { ko.applyBindings(vm); };
},
function (jqXHR, textStatus, exception) {
if (jqXHR.status == 404) { alert('Facture Inexistante !!!'); }
else { alert(error(jqXHR, textStatus, exception)) }
},
Token);
}
function Save() {
Ajax("Facture",
($("#Id").val() == 0) ? "POST" : "PUT",
$("#Id").val(),
vm.facture(),
function (data, textStatus, jqXHR) {
document.location.href = '@Url.Action("Factures", "Home")';
},
function (jqXHR, textStatus, exception) { alert(error(jqXHR, textStatus, exception)); },
Token);
}
</script>
<script src="~/Scripts/AppLibs.js"></script>
} |
Partager