AppML case model
This case study demonstrates how to build a complete <AppML> Internet application with capabilities for listing, editing, and searching information against several tables in a database.
Application Model
In this chapter, we will build a complete application model for the Customers table in the database.
<AppML> Filters
To allow filtering of <AppML> data, simply add a <filters> element to the model:
Example:
<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>
For a complete explanation, see the <AppML> reference manual.
<AppML> Updates
To allow updates to <AppML> data, simply add an <update> element to the model:
Example:
<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>
And add a <maintable> and <keyfield> elements to the <database> element:
Example:
<keyfield>CustomerID</keyfield>
For a complete understanding, see the <AppML> reference manual.
<AppML> Security
You can easily add security to your <AppML> model by adding a security attribute to the <AppML> tag.
Example:
In the above example, only the user logged in as the user group "admin" Members only have access to models.
To set security for the <update> element, simply add a security attribute to the <update> element:
Example:
<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>
Complete Customers Model
In this chapter, we will set up an application model for each table in the database.
Create a new folder named Models. In the Models folder, create a model for each application.
Model: Customers.xml
<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>
##Model ViewCreate a model view, save it as Demo_Model.html, and try it out:
视图: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>
Run Instance»Click the "Run Instance" button to view the online instance
Now merge everything togetherThen, with a little JavaScript coding, create a test page for all models:
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>