User Interface

User Interface
Monday, April 9, 2018PrintSubscribe
Changing Field Values Via JavaScript Business Rules

Some form of validation is required in every application to help the user insert the correct data. Applications created with Code On Time app generator offer validation in the form of business rules.

Validating the Last Name field of the New Employees form.

Let’s add validation business rules the Employees controller of our sample Northwind app.

Open the Project Designer. In the Solution Explorer, switch to the Controllers tab, right-click on Employees / Business Rules node, and press New Business Rule.

Creating a new business rule on Employees controller.

Specify the following:

Property Value
Type JavaScript
Command Name Insert
Phase Before
if ($row.LastName == 'Smith') {
    $row.LastName = null;

The above script will run when the user presses Save. It will check if the user has specified a Last Name of “Smith” – if so, it will cancel the save operation and clear the field.

Save the new business rule. On the toolbar, press Browse to run the app. Navigate to the Employees page and create a new record.

Creating a new employee with Last Name of "Smith".

Enter values for the employee and press Save. The save operation will not be executed, and the Last Name field will be cleared.

The Last Name field has been cleared.

Our business rule does ensure the user does not enter an incorrect value, but it does not make it clear to the user what is going on. We will want to add some feedback in the form of a message box to help the user understand.

Change the business rule as shown below:

if ($row.LastName == 'Smith') {
    // show message box
    $app.alert('Last Name "Smith" is not allowed.').done(function () {
        // update field value to null
            values: [
                { name: 'LastName', value: null }
        // focus on the field
        $app.input.focus({ fieldName: 'LastName' });

Our updated business rule has a few changes. Notice that the $app.alert function is used to display a message to the user. However, this alert will show a different form and change the current context. Attempting to update the field LastName after an alert is displayed will attempt to update a LastName field inside the alert form – which does not exist. Therefore, a done handler will need to be added to the $app.alert method call in order to execute code after the user closes the alert.

One more point to notice is that the $row variable is only in scope during the execution of the business rule. The asynchronous code in the done handler is executed when $row is out of scope. Therefore, it is necessary to use the $app.input.execute API to update the field values when the user returns to the Employees create form. The execute method accepts an object with the property values that contains a list of key value pairs. The $app.input.focus API is called in order to focus on a field called LastName as well.

Save the business rule and regenerate the project. Create a new employee with the last name of “Smith” and attempt to save. Notice that a message box now notifies the user that the last name is not allowed.

Alert message box is displayed to the user.

Press OK to close the message box. The Last Name field has been cleared and is currently focused.

The last name field is cleared and focused.

There are other ways of displaying a message to the user without interrupting the workflow. Let’s try the following:

if ($row.LastName == 'Smith') {
    $row.LastName = null;
    // focus and show message next to field
    this.result.focus('LastName', 'Last Name "Smith" is not allowed.');

The example above will clear the field, and use the result.focus() method to focus on the field, and display a message next to the input. The result can be seen below.

Focus message displayed next to the LastName field.

Another technique is to use the notification API to display a transient message to the user at the bottom of the screen.

if ($row.LastName == 'Smith') {
    $row.LastName = null;
    $app.touch.notify('Last Name "Smith" is not allowed.');

The result can be seen below:


The notification will disappear after a default of 2 seconds.

Wednesday, March 7, 2018PrintSubscribe
App Factory vs App Factory (Advanced)

When users create a new project in the app generator using release and later, the project type will now be App Factory.

App Factory projects will create an ASP.NET-hosted web site project, deployable to any server running Microsoft Internet Information Services (IIS).

These projects contain both a REST API web server and stream HTML, CSS, and JavaScript to web browsers, to support user interaction through a publicly accessible web site. App Factory projects also function as a REST API server for native Mobile Apps.

Developers can also enable App Factory integration with DotNetNuke and SharePoint.

App Factory project folder directory root contains metadata files required by the app generator, as well as the Visual Studio solution file. An “app” folder contains the generated code required to run the server.

Project structure of App Factory projects.

Note that projects created before release will use the “WebSite” folder name instead.

The app folder contains a set of resources required for the application to function. The App_Code folder contains the application framework. Upon running the application, the code in that folder is automatically compiled and executed.

All styling is stored under ~/css folder. All client-side scripts are stored under ~/js folder. Standard styling and script files are read by the framework, joined together, and streamed to the client (native app or web browser). The “_ignore.txt” file located in the two directories enumerates which non-standard files and directories are included in the output.

App folder of App Factory projects.

App Factory (Advanced)

An additional checkbox is now present on the New Project screen – “Implement application framework as class library (for experienced users only).”

Implement application framework as class library.

When this option is enabled, the application framework code is placed in a separate class library project, named after the project’s namespace.

Folder structure of App Factory (Advanced) projects.

The developer must have an instance of Visual Studio 2010, 2012, 2013, 2015, or 2017 installed on the development computer in order for the application to run. At compile-time, the Microsoft Visual Studio compiler must compile and package the application source code stored in the namespace folder into a *.dll file under the app folder. Only then will hosting software (Microsoft IIS) will be able to run the application.

App Factory (Advanced) projects store standard CSS and JS files under the class library. Upon compilation, these files are saved as embedded resources and read from the class manifest.

Custom CSS files can be placed under a “css” folder under the “app” directory. Custom JS files can be placed under the “js” folder under the “app” directory. The framework will read any files in those directories and not excluded by the “_ignore.txt” file, and stream them with every page request.

Pros of App Factory (Advanced)

  • Application source code is stored in a re-usable class library.
  • Hosting provider or customer is unable to view or edit the application source code.
  • Developer can only modify code during debugging if solution platform is switched to x86.

Cons of App Factory (Advanced)

  • Microsoft Visual Studio is required.
  • Application takes longer to generate and compile.
  • Developer cannot modify code files while application is running.

Old Project Types

A number of project types have been deprecated or disabled:

  1. Web Site Factory – renamed to App Factory.
  2. Web App Factory – renamed to App Factory (Advanced).
  3. Mobile Factory – a variant of Web Site Factory with Classic disabled. Deprecated. Use App Factory with User Interface set to “Touch UI” instead.
  4. DotNetNuke Factory – a variant of Web App Factory designed to work as a DNN module in DNN 7 and below. Deprecated. Use App Factory with DotNetNuke Connector instead.
  5. SharePoint Factory – a variant of Web App Factory designed to work as a SharePoint extension in SP 2010. Deprecated. Use App Factory with SharePoint Add-in instead.
Wednesday, January 24, 2018PrintSubscribe
Cloud On Time App

Cloud On Time app runs cloud applications created with Code On Time products directly on your device with an optional offline mode. Integrated access to device camera and sensors contributes to enhanced user experience.

Employee Registry cloud running hosted in the native Universal Windows Platform app Cloud On Time.

The entire front-end of the cloud application is downloaded and installed on the device for a smooth and responsive user experience.

Installed cloud application front-end is automatically updated whenever the cloud is changed. You can maintain multiple accounts for each installed app with automatic secure sign-in.

If you are installing a cloud application with Offline Sync enabled, then the relevant data is also downloaded on your device. You will work with the local data in offline mode whether your device is online or disconnected. Synchronize data with the cloud when online connection becomes available.

Connect to a compatible application in the Cloud On Time app by specifying the name or URL. If the cloud application can be connected, then its name, icon, and description are displayed in the prompt to install.

Adding Order Management cloud to native Universal Windows Platform app Cloud On Time.

Cloud On Time app will redirect to the application in the cloud and prompt to sign in to authorize access on the device. Enter username and password to confirm your identity.

Logging in to add Order Management cloud to native Universal Windows Platform app Cloud On Time.

If your identity has been confirmed by the application in the cloud, then Cloud On Time app will download a manifest of files required to run the application front-end. Files listed in the manifest are downloaded to the device.

Optionally, the data that you can access in the cloud is download to the device during the last step of installation. This requires the cloud application to be configured for offline mode.

A list of cloud applications installed on the device is displayed on the home screen of Cloud On Time app.

List of clouds displayed in native Universal Windows Platform app Cloud On Time.

List of clouds displayed in native Universal Windows Platform app Cloud On Time.

Tap the application name or select “Launch” in the “more” menu to start the app. Choose “Delete” option to remove the app from the device.

Removing a cloud from native Universal Windows Platform app Cloud On Time.

Cloud On Time app will compare the local manifest of files with the one available in the cloud when the installed application is launched from the home screen. Any missing or changed files are downloaded before the front-end of the selected Cloud is displayed.

If the launched app is working with the local data in offline mode, then the manifest verification is skipped. The manifest will be processed when you initiate data synchronization and successfully commit local changes to the cloud.

If the Cloud On Time app is closed and started again, then the last used front-end is started automatically.

Use “Exit” option in the application front-end to get back to the home screen of Cloud On Time app.

Exiting a cloud in native Universal Windows Platform app Cloud On Time.

The cloud app launched from the home screen will operate under the same identity that was confirmed by the cloud application during installation. If you need to use multiple identities on the same device, then launch the installed application front-end and add an account. Cloud On Time app will redirect you to the cloud to confirm the new identity.

Adding an identity to a cloud in native Universal Windows Platform app Cloud On Time.

Unique files of the front-end specific to the confirmed identity are downloaded and the application is launched on the device. Use the account manager of the installed front-end to switch between identities. Cloud On Time app will use the last selected identity when the application is launched from the home screen.

Log out of all identities of the installed front-end to uninstall the application. It will remain to be listed on the home screen of Cloud On Time app until explicitly deleted. User identity will need to be confirmed to run the front-end of the uninstalled cloud application.

Use Cloud On Time app for instant access to applications deployed in the cloud on your native device. Work with your data offline, online, and on-premises.

Cloud On Time app is perfect for enterprise environment. An administrator can compose a simple text file listing names or URLs of custom enterprise business apps in the cloud. The entire collection of the apps is installed when Cloud On Time app is connected to the text file. Cloud On Time app will automatically check for the revisions of the file and update the contents of its home screen. Administrator can optionally disable ability of users to connect to apps manually or delete from the home screen.