Files
jube-fork/Jube.App/wwwroot/kendo/examples/grid/kinvey.html
2022-11-04 13:24:24 +02:00

141 lines
4.5 KiB
HTML
Executable File

<!DOCTYPE html>
<html>
<head>
<title>Binding to Kinvey Backend Services</title>
<meta charset="utf-8">
<link href="../content/shared/styles/examples-offline.css" rel="stylesheet">
<link href="../../styles/kendo.common.min.css" rel="stylesheet">
<link href="../../styles/kendo.rtl.min.css" rel="stylesheet">
<link href="../../styles/kendo.default.min.css" rel="stylesheet">
<link href="../../styles/kendo.default.mobile.min.css" rel="stylesheet">
<script src="../../js/jquery.min.js"></script>
<script src="../../js/jszip.min.js"></script>
<script src="../../js/kendo.all.min.js"></script>
<script src="../content/shared/js/console.js"></script>
<script>
</script>
</head>
<body>
<a class="offline-button" href="../index.html">Back</a>
<div id="example">
<!--[if gte IE 11]>-->
<div id="grid"></div>
<!-- Kinvey JS SDK (HTML, PhoneGap, etc.) -->
<script src="../content/shared/js/kinvey-html5-sdk.min.js"></script>
<!-- Kinvey Kendo UI Data Source -->
<script src="../content/shared/js/kendo.data.kinvey.min.js"></script>
<script>
Kinvey.init({
appKey: 'kid_SJyRpx96G',
appSecret: 'a88466f87e434ca4a1a0194e33d3168d'
});
function createGrid() {
var collectionName = "products";
var dataSourceOptions = {
type: "kinvey",
transport: {
typeName: collectionName
},
schema: {
model: {
id: "_id",
fields: {
UnitPrice: {
type: "number"
},
UnitsInStock: {
type: "number"
},
Discontinued: {
type: "boolean"
}
}
}
},
pageSize: 20,
serverSorting: true,
serverPaging: true,
error: function (err) {
alert(JSON.stringify(err));
}
};
var dataSource = new kendo.data.DataSource(dataSourceOptions);
$("#grid").kendoGrid({
dataSource: dataSource,
height: 430,
sortable: true,
pageable: true,
columns: [
{
field: "ProductName",
title: "Product Name"
}, {
field: "UnitPrice",
title: "Unit Price",
width: 220
}, {
field: "UnitsInStock",
title: "Units In Stock",
width: 220
}, {
field: "Discontinued",
title: "Discontinued",
width: 220
}
]
});
}
$(document).ready(function () {
// Get the locally stored activeUser
var activeUser = Kinvey.User.getActiveUser();
var userPromise;
if (activeUser === null) {
userPromise = Kinvey.User.signup();
} else {
userPromise = activeUser.me();
}
userPromise
// skipped if no error
.catch(function (userError) {
if (userError.name === 'InvalidCredentialsError') {
// clear the activeUser using logout and then initiate login and return login response
return Kinvey.User.logout()
.then(function () {
return Kinvey.User.signup();
});
}
else {
// if the error is different from InvalidCredentialsError, forward it down the chain
return Promise.reject(userError);
}
})
.then(function () {
createGrid();
})
.catch(function (error) {
alert(error.message);
});
});
</script>
<!--[if gte IE 11]>-->
</div>
</body>
</html>