This case study demonstrates how to build a complete < AppML > Internet application with the ability to enumerate, edit, and search for information against several tables in the database. In this chapter, we will build a complete application model for the Customers table in the database. To allow filtering of < AppML > data, simply add a < filters > element to the model: For a comprehensive understanding, see < AppML > 参考手册 . To allow < AppML > data to be updated, simply add a < update > element to the model: And add a < maintable > and < keyfield > element to the < database > element: For a comprehensive understanding, see < AppML > 参考手册 . You can easily add security to the < AppML > model by adding a security attribute to the < AppML > tag. In the above example, the model can be accessed only if the user logs in to become a member of the user group “admin”. To set security for the < update > element, simply add a security attribute to the < update > element: In this chapter, we will set up an application model for each table in the database. Create a new folder called Models. In the Models folder, create a model for each application. Create a model view, save it as Demo_Model.html, and give it a try: Then, with a small amount of JavaScript coding, create a test page for all models: 4.8.1. Application model ¶
4.8.2. < AppML > filter ¶
Example: ¶
<filters>
<query>
<field label="Customer">CustomerName</field>
<field>City</field>
<field>Country</field>
</query>
<order>
<field label="Customer">CustomerName</field>
<field>City</field>
<field>Country</field>
</order>
</filters>
4.8.3. < AppML > Update ¶
Example: ¶
<update>
<item><name>LastName</name></item>
<item><name>FirstName</name></item>
<item><name>BirthDate</name></item>
<item><name>Photo</name></item>
<item><name>Notes</name></item>
</update>
Example: ¶
<maintable>Customers</maintable>
<keyfield>CustomerID</keyfield>
4.8.4. < AppML > Security ¶
Example: ¶
<appml **security="admin"**>
Example: ¶
<update **security="admin"**>
<item><name>LastName</name></item>
<item><name>FirstName</name></item>
<item><name>BirthDate</name></item>
<item><name>Photo</name></item>
<item><name>Notes</name></item>
</update>
4.8.5. Complete Customers model ¶
模型:Customers.xml ¶
<appml security="">
<datasource>
<database>
<connection>Demo</connection>
<maintable>Customers</maintable>
<keyfield>CustomerID</keyfield>
<sql>SELECT \* FROM Customers</sql>
<orderby>CustomerName,City,Country</orderby>
</database>
</datasource>
<filters>
<query>
<field label="Customer">CustomerName</field>
<field>City</field>
<field>Country</field>
</query>
<order>
<field label="Customer">CustomerName</field>
<field>City</field>
<field>Country</field>
</order>
</filters>
<update security="admin">
<item><name>CustomerName</name></item>
<item><name>ContactName</name></item>
<item><name>Address</name></item>
<item><name>PostalCode</name></item>
<item><name>City</name></item>
<item><name>Country</name></item>
</update>
</appml>
4.8.6. Model view ¶
视图:Demo_Model.htm ¶
<h1>Customers</h1>
<div id="List01"></div>
<script src="appml.js"></script>
<script>
customers=new AppML("appml.htmlx","Models/Customers");
customers.run("List01");
</script>
4.8.7. Now put it all together. ¶
Demo_Model_Views.htm ¶
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="appml.css" />
</head>
<body>
<h1>Demo Applications</h1>
<button onclick='myOpen("Customers")'>Customers</button>
<button onclick='myOpen("Products")'>Products</button>
<button onclick='myOpen("Suppliers")'>Suppliers</button>
<button onclick='myOpen("Shippers")'>Shippers</button>
<button onclick='myOpen("Categories")'>Categories</button>
<button onclick='myOpen("Employees")'>Employees</button>
<button onclick='myOpen("Orders")'>Orders</button>
<button onclick='myOpen("OrderDetails")'>OrderDetails</button>
<br><br>
<div id="Place01"></div>
<script src="appml.js"></script>
<script>
function myOpen(pname)
{
var app_obj
app_obj=new AppML("appml.php","Models/" + pname);
app_obj.run("Place01");
}
</script>
</body>
</html>