THE INDIA LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

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 bootstrap in this example:

Example

<!DOCTYPE html>
<html lang="en-US">

<title>Customers</title>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">

<body>

<div class="container">
<h1>Customers</h1>
<table class="table table-striped table-bordered">
  <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 »
Note {{ ... }} 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="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<script src="https://www.noidatut.com/appml/2.0.3/appml.js"></script>
<script src="https://www.noidatut.com/appml/2.0.3/appml_sql.js"></script>
<body>

<div class="container" appml-data="customers.js">
<h1>Customers</h1>
<table class="table table-striped table-bordered">
  <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://www.noidatut.com/appml/2.0.3/appml.js">

Add a local WebSQL database:

<script src="https://www.noidatut.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"

Note 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.

Note 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 appml-data="local?model=proto_customers_single">
<h1>Customers</h1>
<table class="table table-striped table-bordered">
  <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 appml-data="local?model=proto_customers_all">
<h1>Customers</h1>
<table class="table table-striped table-bordered">
  <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="btn-group" role="toolbar" style="margin-bottom:10px;">

  <button id='appmlbtn_first' type="button" class="btn btn-default">
  <span class="glyphicon glyphicon-fast-backward"></span></button>

  <button id='appmlbtn_previous' type="button" class="btn btn-default">
  <span class="glyphicon glyphicon-backward"></span></button>

  <button id='appmlbtn_text' type="button" class="btn btn-default disabled"></button>

  <button id='appmlbtn_next' type="button" class="btn btn-default">
  <span class="glyphicon glyphicon-forward"></span></button>
 
  <button id='appmlbtn_last' type="button" class="btn btn-default">
  <span class="glyphicon glyphicon-fast-forward"></span></button>

  <button id='appmlbtn_query' type="button" class="btn btn-primary">
  <span class="glyphicon glyphicon-search"></span> 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 appml-data="local?model=proto_customers_all">
<h1>Customers</h1>
<div appml-include-html="inc_listcommands.htm"></div>

<table class="table table-striped table-bordered">
  <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 »