AppML Prototype
In this chapter, we will build a prototype for a web application.
Create an HTML Prototype
First, create a decent HTML prototype, using your favorite CSS.
We have used W3.CSS in this example:
Example
<!DOCTYPE html>
<html lang="en-US">
<title>Customers</title>
<link rel="stylesheet" href="https://w3.p2hp.com/w3css/4/w3.css">
<body>
<div class="w3-container">
<h1>Customers</h1>
<table class="w3-table-all">
<tr>
<th>Customer</th>
<th>City</th>
<th>Country</th>
</tr>
<tr>
<td>{{CustomerName}}</td>
<td>{{City}}</td>
<td>{{Country}}</td>
</tr>
</table>
</div>
</body>
</html>
Try It Yourself »
{{ ... }} Are placeholders for future data.
Add AppML
After you have created an HTML prototype, you can add AppML:
Example
<!DOCTYPE html>
<html lang="en-US">
<title>Customers</title>
<link rel="stylesheet" href="https://w3.p2hp.com/w3css/4/w3.css">
<script src="https://w3.p2hp.com/appml/2.0.3/appml.js"></script>
<script src="https://w3.p2hp.com/appml/2.0.3/appml_sql.js"></script>
<body>
<div class="w3-container" appml-data="customers.js">
<h1>Customers</h1>
<table class="w3-table-all">
<tr>
<th>Customer</th>
<th>City</th>
<th>Country</th>
</tr>
<tr appml-repeat="records">
<td>{{CustomerName}}</td>
<td>{{City}}</td>
<td>{{Country}}</td>
</tr>
</table>
</div>
</body>
</html>
Try It Yourself »
Add AppML:
<script src="https://w3.p2hp.com/appml/2.0.3/appml.js">
Add a local WebSQL database:
<script src="https://w3.p2hp.com/appml/2.0.3/appml_sql.js">
Define a data source:
appml-data="customers.js"
Define the HTML element to be repeated for each record in records:
appml_repeat="records"
To make it simple, start with local data like customers.js before connecting to a database.
Create an AppML Model
To be able to use a database, you will need an AppML database model:
proto_customers.js
{
"rowsperpage" : 10,
"database" : {
"connection"
: "localmysql",
"sql" : "Select * from Customers",
"orderby"
: "CustomerName",
}
If you don't have a local database, you can use the AppML model to create a Web SQL database.
To create a table with a single record, use a model like this: proto_customers_single.js.
Creating a local database does not work in IE or Firefox. Use Chrome or Safari.
Use the model in your application. Change the data source to local?model=proto_customers_single:
Example
<div class="w3-container" appml-data="local?model=proto_customers_single">
<h1>Customers</h1>
<table class="w3-table-all">
<tr>
<th>Customer</th>
<th>City</th>
<th>Country</th>
</tr>
<tr appml-repeat="records">
<td>{{CustomerName}}</td>
<td>{{City}}</td>
<td>{{Country}}</td>
</tr>
</table>
</div>
Try It Yourself »
Create a Local Database with Multiple Records
To create a table with multiple records, use a model like this: proto_customers_all.js.
Change the data source to local?model=proto_customers_all
Example
<div class="w3-container" appml-data="local?model=proto_customers_all">
<h1>Customers</h1>
<table class="w3-table-all">
<tr>
<th>Customer</th>
<th>City</th>
<th>Country</th>
</tr>
<tr appml-repeat="records">
<td>{{CustomerName}}</td>
<td>{{City}}</td>
<td>{{Country}}</td>
</tr>
</table>
</div>
Try It Yourself »
Add a Navigation Template
Suppose you want all your applications to have a common navigation toolbar:
Create an HTML template for it:
inc_listcommands.htm
<div class="w3-bar w3-border w3-section">
<button class="w3-button" id='appmlbtn_first'>❮❮</button>
<button class="w3-button" id='appmlbtn_previous'>❮</button>
<button class="w3-button w3-hover-none" id='appmlbtn_text'></button>
<button class="w3-button" id='appmlbtn_next'>❯</button>
<button class="w3-button" id='appmlbtn_last'>❯❯</button>
<button class="w3-btn ws-green" id='appmlbtn_query'>Filter</button>
</div>
<div id="appmlmessage"></div>
Save the template in a file with a proper name like "inc_listcommands.htm".
Include the template in your prototype with the attribute appml-include-html:
Example
<div class="w3-container" appml-data="local?model=proto_customers_all">
<h1>Customers</h1>
<div appml-include-html="inc_listcommands.htm"></div>
<table class="w3-table-all">
<tr>
<th>Customer</th>
<th>City</th>
<th>Country</th>
</tr>
<tr appml-repeat="records">
<td>{{CustomerName}}</td>
<td>{{City}}</td>
<td>{{Country}}</td>
</tr>
</table>
</div>
Try It Yourself »