<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Tutorial2_4.aspx.cs" Inherits="KnockoutApp.Tutorials.Tutorial2_3" %>
<
asp:Content
ID
=
"Content1"
ContentPlaceHolderID
=
"HeadContent"
runat
=
"server"
>
<
style
type
=
"text/css"
>
.deleteLink
{
color: red;
font-weight: bold;
}
</
style
>
</
asp:Content
>
<
asp:Content
ID
=
"Content2"
ContentPlaceHolderID
=
"MainContent"
runat
=
"server"
>
<!-- -->
<
div
id
=
"mvvmRegion"
>
<
h2
>Your seat reservations (<
span
data-bind
=
"text: seats.length"
></
span
>)</
h2
>
<
button
id
=
"addSeatButton"
data-bind
=
"click: addSeat"
>Reserve another seat</
button
>
<
div
style
=
"width: 600px;"
>
<
table
id
=
"reservationTable"
>
<
thead
><
tr
>
<
th
data-field
=
"name"
style
=
"width: 160px;"
>Passenger name</
th
>
<
th
data-field
=
"meal.mealName"
style
=
"width: 160px;"
>Meal</
th
>
<
th
data-field
=
"meal.price"
style
=
"width: 100px;"
>Surcharge</
th
>
<
th
> </
th
>
</
tr
></
thead
>
<
tbody
>
</
tbody
>
</
table
>
</
div
>
<
h3
data-bind
=
"visible: surcharge"
>
Total surcharge: $<
span
data-bind
=
"text: totalSurcharge00"
></
span
>
</
h3
>
</
div
>
<
script
id
=
"reservationTemplate"
type
=
"text/x-kendo-template"
>
<
tr
>
<
td
style
=
"width: 160px;"
><
input
id
=
"nameTextBox"
value
=
"#= name #"
data-bind
=
"value: seats.name"
/></
td
>
<
td
style
=
"width: 160px;"
><
input
id
=
"mealDropDown"
class
=
"mealDropDownClass"
value
=
"#= meal.mealName #"
data-bind
=
"value: seats.meal.mealName"
/></
td
>
<
td
style
=
"width: 100px;"
>#= meal.price #</
td
>
<
td
><
a
href
=
""
class
=
"deleteLink"
>Remove</
a
></
td
>
</
tr
>
</
script
>
<
script
type
=
"text/javascript"
>
// Class to represent a row in the seat reservations grid
function SeatReservation(fname, initialMeal) {
var self = this;
self.name = fname;
self.meal = initialMeal;
}
//
var availableMeals = [
{ mealName: "Standard (sandwich)", price: 0.0 },
{ mealName: "Premium (lobster)", price: 34.95 },
{ mealName: "Ultimate (whole zebra)", price: 290.0 }
];
//
var viewModel = kendo.observable({
// type array populates the drop down
meals: availableMeals,
// array will hold the grid values
seats: [
new SeatReservation("Steve", availableMeals[1]),
new SeatReservation("Bert", availableMeals[0])
],
// Computed data
totalSurcharge: function () {
var total = 0;
for (var i = 0; i <
this.get
("seats").length; i++)
total += this.get("seats")[i].meal.price;
return total + 0.00;
},
totalSurcharge00: function () {
var
total
=
this
.totalSurcharge() + 0.00;
return total.toFixed(2);
},
surcharge: function () {
var
total
=
this
.totalSurcharge() + 0.00;
if (total > 0) return true;
return false;
},
//
maxSeating: function () {
if (this.seats.length <
5
) return true;
return false;
},
// seats.length < 5
// event execute on click of add button
addSeat: function (e) {
// add the items to the array of expenses
this.get("seats").push(new SeatReservation("", self.availableMeals[1]));
return false;
},
removeSeat: function (seat) {
var
seats
=
this
.get("seats");
seats.splice(seats.indexOf(seat), 1);
}
});
// apply the bindings
kendo.bind($("#mvvmRegion"), viewModel);
//
var
reservationDataSource
=
new
kendo.data.DataSource({
data: viewModel.get("seats"),
schema: {
model: {
id: "name",
fields: {
// data type of the field {Number|String|Boolean|Date} default is String
name: { type: "String" },
meal: {
mealName: { type: "String" },
price: { type: "Numeric" }
}
}
}
}
});
//
$("#reservationTable").kendoGrid({
dataSource: reservationDataSource,
rowTemplate: kendo.template($("#reservationTemplate").html()),
dataBound: function (e) {
$(".deleteLink").click(function (e) {
e.preventDefault();
if (confirm("Do you what to delete this?")) {
var grid = $("#reservationTable").data("kendoGrid");
var
dataItem
=
grid
.dataItem($(this).closest("tr"));
viewModel.removeSeat(dataItem);
}
return false;
});
}
});
$(".mealDropDownClass").kendoDropDownList({
dataTextField: "mealName",
dataValueField: "mealName",
dataSource: availableMeals
});
//
</script>
</
asp:Content
>
[{
"status"
:
"Received"
,
"number"
:
"2"
},{
"status"
:
"In Progress"
,
"number"
:
"1"
}]
function
createChart() {
$(
"#chart"
).kendoChart({
theme: $(document).data(
"kendoSkin"
) ||
"default"
,
dataSource: {
transport: {
read: {
dataType:
"json"
},
},
sort: {
field:
"status"
,
dir:
"asc"
},
},
chartArea: {
height: 125,
width: 125
},
legend: {
visible:
false
},
seriesDefaults: {
type:
"pie"
},
series: [{
field:
"number"
,
categoryField:
"status"
,
padding: 10
}],
tooltip: {
visible:
true
,
template:
"#= dataItem.status #: #= dataItem.number #"
}
});
}
Thank you very much for your time.
puyo
$
this
.children().each(
function
(i) {
var
$item = $(
"<li><label>"
+ $(
this
).val() +
" <input type=\""
+ (base.multiple ?
"checkbox"
:
"radio"
) +
"\" "
+ (
this
.selected ?
"checked=\"checked\""
:
""
) +
" /></label></li>"
);
listview.prepend($item);
var
that =
this
;
$item.on(
"click"
,
function
() {
console.log(
"test"
);
that.selected =
true
;
$
this
.ButtonCombobox(
"setSelection"
);
})
});
script>
var viewModel = null;
$(document).ready(function() {
var treeview;
$("#vertical").kendoSplitter({
orientation: "vertical",
panes: [
{ collapsible: true, size: "50%" },
{ collapsible: true, size: "50%" }
]
});
$("#horizontal").kendoSplitter({
panes: [
{ collapsible: true, size: "35%" },
{ collapsible: true, size: "65%" }
]
});
treeview = $("#treeview").kendoTreeView({
template: kendo.template($("#treeview-template").html()),
dragAndDrop: false,
dataSource: [@(Html.Raw(Model.Json))],
select: onSelect
}).data("kendoTreeView");
var productdata = @(Html.Raw(Model.JsonProducts));
viewModel = kendo.observable({
gridSource: productdata
});
$("#grid").kendoGrid({
dataSource: {
data: viewModel.gridSource,
pageSize: 10
},
autoBind:true,
selectable: "multiple, row",
groupable: false,
scrollable: true,
sortable: true,
pageable: false,
drop: droptargetOnDrop,
columns: [
{
field: "id",
width: 50,
title: "Id"
},
{
field: "categoryid",
width: 250,
title: "Category Id"
}, {
field: "productname",
width: 250,
title: "Product Name"
}
]
});
$("#grid").kendoDraggable({
filter: "tr",
hint: function() {
var g = $("#grid").data("kendoGrid");
return g.select().clone();
}
});
$("#treeview").kendoDropTarget({
dragAndDrop: true,
drop: droptargetOnDrop
});
});
function onSelect(e) {
var url = "/home/UpdateListingByCategory";
var selectedCatId = $(e.node.children[0]).find("input").val();
$.ajax({
type: "POST",
url: url,
data: { categoryId: selectedCatId },
success: function(data) {
viewModel.gridSource = JSON.parse(data);
alert(viewModel.gridSource);
},
error: function() {
alert("error");
}
});
}
function droptargetOnDrop(e) {
var ss = e.srcElement.parentElement.children[1];
var url = "/home/update";
var list = new Array();
for (var i=0; i < e.draggable.hint.length; i++) {
var id = e.draggable.hint[i].firstChild.innerHTML;
list.push(id);
}
$.ajax({
type: "POST",
url: url,
data: { categoryId: $(ss).val(), productIds: list.join() },
success: function(data) {
viewModel.gridSource = JSON.parse(data);
},
error: function() {
alert("error");
}
});
kendo.bind($("#grid"), viewModel);
}
</script>