forked from jaystack/jaydata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
handlebars_examples.html
263 lines (228 loc) · 15.4 KB
/
handlebars_examples.html
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript" src="http://code.jquery.com/jquery.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.0.rc.1/handlebars.js"></script>
<script type="text/javascript" src="Scripts/jquery.validate.js"></script>
<script type="text/javascript" src="Scripts/knockout-2.1.0.js"></script>
<!--************************************************************************************-->
<script type="text/javascript" src="TypeSystem/initializeJayDataClient.js"></script>
<script type="text/javascript" src="TypeSystem/initializeJayData.js"></script>
<script type="text/javascript" src="TypeSystem/utils.js"></script>
<script type="text/javascript" src="TypeSystem/PreHtml5Compatible.js"></script>
<script type="text/javascript" src="JayService/Scripts/datajs-1.0.3-patched.js"></script>
<script type="text/javascript" src="TypeSystem/JayLint.js"></script>
<script type="text/javascript" src="TypeSystem/TypeSystem.js"></script>
<script type="text/javascript" src="TypeSystem/Trace/Trace.js"></script>
<script type="text/javascript" src="TypeSystem/Trace/Logger.js"></script>
<script type="text/javascript" src="TypeSystem/Types/Geography.js"></script>
<script type="text/javascript" src="TypeSystem/Types/Guid.js"></script>
<script type="text/javascript" src="TypeSystem/Types/EdmTypes.js"></script>
<!--*******************************Expressions****************************************-->
<script type="text/javascript" src="Types/Expressions/ASTParser.js"></script>
<script type="text/javascript" src="Types/Expressions/ExpressionNode2.js"></script>
<script type="text/javascript" src="Types/Expressions/ArrayLiteralExpression.js" ></script>
<script type="text/javascript" src="Types/Expressions/CallExpression.js" ></script>
<script type="text/javascript" src="Types/Expressions/CodeParser.js"></script>
<script type="text/javascript" src="Types/Expressions/ConstantExpression.js" ></script>
<script type="text/javascript" src="Types/Expressions/FunctionExpression.js" ></script>
<script type="text/javascript" src="Types/Expressions/ObjectFieldExpression.js" ></script>
<script type="text/javascript" src="Types/Expressions/ObjectLiteralExpression.js" ></script>
<script type="text/javascript" src="Types/Expressions/PagingExpression.js" ></script>
<script type="text/javascript" src="Types/Expressions/ParameterExpression.js"> </script>
<script type="text/javascript" src="Types/Expressions/PropertyExpression.js" ></script>
<script type="text/javascript" src="Types/Expressions/SimpleBinaryExpression.js" ></script>
<script type="text/javascript" src="Types/Expressions/ThisExpression.js" ></script>
<script type="text/javascript" src="Types/Expressions/Visitors/ExpressionVisitor.js"></script>
<script type="text/javascript" src="Types/Expressions/Visitors/ParameterProcessor.js"></script>
<script type="text/javascript" src="Types/Expressions/Visitors/GlobalContextProcessor.js"></script>
<script type="text/javascript" src="Types/Expressions/Visitors/LocalContextProcessor.js"></script>
<script type="text/javascript" src="Types/Expressions/Visitors/LambdaParameterProcessor.js"></script>
<script type="text/javascript" src="Types/Expressions/Visitors/ParameterResolverVisitor.js"></script>
<script type="text/javascript" src="Types/Expressions/Visitors/LogicalSchemaBinderVisitor.js"></script>
<script type="text/javascript" src="Types/Expressions/Visitors/ExpTreeVisitor.js"></script>
<script type="text/javascript" src="Types/Expressions/Visitors/SetExecutableVisitor.js"></script>
<script type="text/javascript" src="Types/Expressions/Visitors/ExecutorVisitor.js"></script>
<script type="text/javascript" src="Types/Expressions/ExpressionBuilder.js"></script>
<script type="text/javascript" src="Types/Expressions/EntityExpressions/AssociationInfoExpression.js"></script>
<script type="text/javascript" src="Types/Expressions/EntityExpressions/CodeExpression.js"></script>
<script type="text/javascript" src="Types/Expressions/EntityExpressions/CodeToEntityConverter.js"></script>
<script type="text/javascript" src="Types/Expressions/EntityExpressions/ComplexTypeExpression.js"></script>
<script type="text/javascript" src="Types/Expressions/EntityExpressions/EntityContextExpression.js"></script>
<script type="text/javascript" src="Types/Expressions/EntityExpressions/EntityExpression.js"></script>
<script type="text/javascript" src="Types/Expressions/EntityExpressions/EntityExpressionVisitor.js"></script>
<script type="text/javascript" src="Types/Expressions/EntityExpressions/EntityFieldExpression.js"></script>
<script type="text/javascript" src="Types/Expressions/EntityExpressions/EntityFieldOperationExpression.js"></script>
<script type="text/javascript" src="Types/Expressions/EntityExpressions/EntitySetExpression.js"></script>
<script type="text/javascript" src="Types/Expressions/EntityExpressions/ServiceOperationExpression.js"></script>
<script type="text/javascript" src="Types/Expressions/EntityExpressions/FrameOperationExpression.js"></script>
<script type="text/javascript" src="Types/Expressions/EntityExpressions/FilterExpression.js"></script>
<script type="text/javascript" src="Types/Expressions/EntityExpressions/IncludeExpression.js"></script>
<script type="text/javascript" src="Types/Expressions/EntityExpressions/MemberInfoExpression.js"></script>
<script type="text/javascript" src="Types/Expressions/EntityExpressions/OrderExpression.js"></script>
<script type="text/javascript" src="Types/Expressions/EntityExpressions/ParametricQueryExpression.js"></script>
<script type="text/javascript" src="Types/Expressions/EntityExpressions/ProjectionExpression.js"></script>
<script type="text/javascript" src="Types/Expressions/EntityExpressions/QueryExpressionCreator.js"></script>
<script type="text/javascript" src="Types/Expressions/EntityExpressions/QueryParameterExpression.js"></script>
<script type="text/javascript" src="Types/Expressions/EntityExpressions/RepresentationExpression.js"></script>
<!--******************************* Validation ****************************************-->
<script type="text/javascript" src="Types/Validation/EntityValidationBase.js"></script>
<script type="text/javascript" src="Types/Validation/EntityValidation.js"></script>
<!--******************************* Notification ****************************************-->
<script type="text/javascript" src="Types/Notifications/ChangeDistributorBase.js"></script>
<script type="text/javascript" src="Types/Notifications/ChangeCollectorBase.js"></script>
<script type="text/javascript" src="Types/Notifications/ChangeDistributor.js"></script>
<script type="text/javascript" src="Types/Notifications/ChangeCollector.js"></script>
<!--******************************* Types ****************************************-->
<script type="text/javascript" src="Types/Access.js"></script>
<script type="text/javascript" src="Types/Promise.js"></script>
<script type="text/javascript" src="Types/Entity.js"></script>
<script type="text/javascript" src="Types/ItemStore.js"></script>
<script type="text/javascript" src="Types/EntityContext.js"></script>
<script type="text/javascript" src="Types/QueryProvider.js"></script>
<script type="text/javascript" src="Types/ModelBinder.js"></script>
<script type="text/javascript" src="Types/QueryBuilder.js"></script>
<script type="text/javascript" src="Types/Query.js"></script>
<script type="text/javascript" src="Types/Queryable.js"></script>
<script type="text/javascript" src="Types/EntitySet.js"></script>
<script type="text/javascript" src="Types/AuthEntityContext.js"></script>
<script type="text/javascript" src="Types/EntityState.js"></script>
<script type="text/javascript" src="Types/EntityStateManager.js"></script>
<script type="text/javascript" src="Types/Exception.js"></script>
<script type="text/javascript" src="Types/StorageProviderLoader.js"></script>
<script type="text/javascript" src="Types/StorageProviderBase.js"></script>
<script type="text/javascript" src="Types/EntityWrapper.js"></script>
<!--******************************* Ajax*********************************************-->
<script type="text/javascript" src="Types/Ajax/jQueryAjaxWrapper.js"></script>
<script type="text/javascript" src="Types/Ajax/WinJSAjaxWrapper.js"></script>
<script type="text/javascript" src="Types/Ajax/ExtJSAjaxWrapper.js"></script>
<script type="text/javascript" src="Types/Ajax/AjaxStub.js"></script>
<!--******************************* DbClient ****************************************-->
<script type="text/javascript" src="Types/DbClient/DbCommand.js"></script>
<script type="text/javascript" src="Types/DbClient/DbConnection.js"></script>
<script type="text/javascript" src="Types/DbClient/OpenDatabaseClient/OpenDbCommand.js"></script>
<script type="text/javascript" src="Types/DbClient/OpenDatabaseClient/OpenDbConnection.js"></script>
<script type="text/javascript" src="Types/DbClient/JayStorageClient/JayStorageCommand.js"></script>
<script type="text/javascript" src="Types/DbClient/JayStorageClient/JayStorageConnection.js"></script>
<script type="text/javascript" src="Types/DbClient/SqLiteNJClient/SqLiteNjCommand.js"></script>
<script type="text/javascript" src="Types/DbClient/SqLiteNJClient/SqLiteNjConnection.js"></script>
<script type="text/javascript" src="Types/StorageProviders/modelBinderConfigCompiler.js"></script>
<!--******************************* StorageProvider - sqLite ****************************************-->
<script type="text/javascript" src="Types/StorageProviders/SqLite/SqLiteStorageProvider.js"></script>
<script type="text/javascript" src="Types/StorageProviders/SqLite/SqLiteCompiler.js"></script>
<script type="text/javascript" src="Types/StorageProviders/SqLite/SqlPagingCompiler.js"></script>
<script type="text/javascript" src="Types/StorageProviders/SqLite/SqlOrderCompiler.js"></script>
<script type="text/javascript" src="Types/StorageProviders/SqLite/SqlProjectionCompiler.js"></script>
<script type="text/javascript" src="Types/StorageProviders/SqLite/ExpressionMonitor.js"></script>
<script type="text/javascript" src="Types/StorageProviders/SqLite/SqlFilterCompiler.js"></script>
<script type="text/javascript" src="Types/StorageProviders/SqLite/ModelBinder/sqLite_ModelBinderCompiler.js"></script>
<!--******************************* StorageProvider - oData ****************************************-->
<script type="text/javascript" src="Types/StorageProviders/oData/oDataProvider.js"></script>
<script type="text/javascript" src="Types/StorageProviders/oData/oDataCompiler.js"></script>
<script type="text/javascript" src="Types/StorageProviders/oData/oDataWhereCompiler.js"></script>
<script type="text/javascript" src="Types/StorageProviders/oData/oDataOrderCompiler.js"></script>
<script type="text/javascript" src="Types/StorageProviders/oData/oDataPagingCompiler.js"></script>
<script type="text/javascript" src="Types/StorageProviders/oData/oDataProjectionCompiler.js"></script>
<!--******************************* StorageProvider - IndexDb ****************************************-->
<script type="text/javascript" src="Types/StorageProviders/IndexedDB/IndexedDBStorageProvider.js"></script>
<!--******************************* StorageProvider - inMemory ****************************************-->
<script type="text/javascript" src="Types/StorageProviders/InMemory/InMemoryProvider.js"></script>
<script type="text/javascript" src="Types/StorageProviders/InMemory/InMemoryCompiler.js"></script>
<script type="text/javascript" src="Types/StorageProviders/InMemory/InMemoryFunctionCompiler.js"></script>
<script src="JaySvcUtil/JaySvcUtil.js"></script>
<script src="Types/JayStorm.js"></script>
<script src="JayDataModules/deferred.js"></script>
<script src="JayDataModules/handlebars.js"></script>
<script>
var apiKey = { appId: '133e0907-f70b-4f11-92b3-dfebc9bdd6db',
applicationKey: 'XXX',
serviceName: 'mydatabase',
license: 'business',
isDefault: true
};
function FlowerShowApplication() {
function displayCart() {
$data("Cart").renderTo("#cart", "CartArrayTemplate");
}
function listCategories() {
$data("Category")
.renderItemsTo("#categories")
.then(function (categories) {
listProducts(categories[0]);
});
}
function listProducts(category) {
$data("Flower")
.query("it.Category_ID == catId", { catId: category.id })
.then($data.renderItemsTo("#products"));
}
function addFlowerToCart(flower) {
$data("Cart")
.read(this.id)
.then(
function (cartItem) {
//this gets called if we already have this flower in the cart
//only increment amount
cartItem.Amount += 1;
return cartItem.save();
},
function () {
//this gets called if we dont have this flower in the cart
return $data("Cart").save({ FlowerID: flower.id, Name: flower.Name, Amount: 1 });
})
.then(displayCart);
}
function removeCartItem(cartItem) {
cartItem.remove().then(displayCart);
}
$data("Category").addCommand("select", listProducts);
$data("Flower").addCommand("addToCart", addFlowerToCart);
$data("Cart").addCommand("remove", removeCartItem);
this.start = function () {
listCategories();
displayCart();
}
}
$data.define("Cart", {
//we will use the flower id as primary key
FlowerID: { type: String, key: true },
Name: String,
Amount: Number
}).storeToken = "local";
$data.initService(apiKey).then(function () {
new FlowerShowApplication().start();
});
</script>
</head>
<body>
<script id="Category" type="text/x-handlebars">
<li><a href="#" {{entityCommand 'select'}}>{{Name}}</a></li>
</script>
<script id="Flower" type="text/x-handlebars">
<li>
{{Name}}<br />
<img src="{{ImageUrl}}" style="width:250px;height:150px"><br />
Price: {{Price }},
<a href="#" {{entityCommand 'addToCart'}}>Add to cart</a>
</li>
</script>
<script id="Cart" type="text/x-handlebars">
<li>{{Name}}, {{Amount}}, <a href="#" {{entityCommand 'remove'}}>X</a></li>
</script>
<script id="CartArrayTemplate" type="text/x-handlebars">
<ul>
{{#each .}} {{renderEntity}} {{/each }}
</ul>
<div>
Total: {{length}} items.
</div>
</script>
<ul id="categories" style="width:150px;float:left">
</ul>
<ul id="products" style="width:300px;float:left">
</ul>
<ul id="cart" style="width:300px;float:left">
</ul>
</body>
</html>