UpviseJS Application Structure Guide
An UpviseJS Application consist of just one Javascript file containing:
- Configuration information about the application and its database tables
- function calls to implement each screen and the associated business logic.
This application is deployed to a given Upvise account and available to all users in this account.
User can access the application either when they login on their web account at
htttps://www.upvise.com/uws or on their phone using th Upvise native App for iOs, Android, Windows Phone or Blackberry.
Application fundamentals
Each UpviseJS app contains at minimum:- an Application ID string, which uniquely identifies you app in your account, set in the Config.appid property.
- a Title, set in the Config.title property, used to display your application in the application list in the left side view on mobile and on the top bar on the web
- a version number, set in the Config.version property. Used to perform automatic application updates on mobile.
- a main() function which is called when the user taps on the application title from the Upvise native / HTML5 app.
Config.appid= "myapp"; Config.version = "1"; Config.title= "My App"; function main() { // some code goes here }
Versioning & Deployment
- When an application is first deployed to an account on the cloud, it is visible to all users in their application list.
- As soon as the user uses the mobile app, it is downloaded and locally cached on the user device. All database tables are locally created or their schema upgraded.
- When the user taps on the application name, the main() function call of the application is called by the embedded javascript engine part of the native app.
- When the developer updates and redeploys the application, the application version number must be incremented
- The next time the user uses the native Upvise app, a sync request occurs and finds that the locally stored version of the app is not the same as the one available on the server
- The new application is downloaded, stored locally and the local database tables are upgraded if required based on the new database schema found in the application code.
- If a user does not have an internet connection, no sync occurs and the user uses the old, locally stored application until a connection resumes and the upgrade process occurs.
String interpolation
UpviseJS uses a lot of function callback expressed as javascript string function calls in its API, for example List.addItem("Go to Page2", "page1()"); It is often needed to pass dynamic parameter values in this callback function, for example to display the details of a record from a list view. the function callback string needs to be a valid javascript function call, so the parameters of this function has to be properly formatted or escaped. If a primary string id is passed, it need to be quoted using simple quote.
var id = 'yhinitmvkr4566'; List.addItem("John Smith", "viewContact(" + esc(id) + ")");
UpviseJS framework makes it even better and support natively string interpolation using the {} brackets inside any string literals. At runtime, during application installation it is converted to the corresponding esc() calls. The same rule applies to the where clause of Query.select() or Query.update()
var id = 'yhinitmvkr4566'; List.addItem("John Smith", "viewContact({id})"); var monthStart = Date.month(); var contacts = Query.select("contacts.contacts", "id;name", "date<{monthStart}");