The function controls how the webapp behaves; ie what happens when a user clicks a button.
The webapp function is constucted using Javascript code.
This quick start guide will provide you with the Javascript basics that you need when creating a webapp.
Javascript (js) is the programming language for the web, every commonly used web-browser comes with Javascript built in and ready to use.
Some common uses for Javascript in a webapp include;
Use | Description |
---|---|
Managing user interactions | This is where you create code that "listens" to user actions and then responds by invoking your code - when a user clicks a button, or inputs some text. We use jQuery to help with this, more on jQuery later in this guide. |
Managing data | Organisational webapps are all about managing data and saving it on the cloud, in this case entityOS.cloud. Javascript is used to manage the sending and receiving data from a webservice. |
The look | Javascript code is used to dynamically updating elements based on user interactions or data. ie if status = Completed set backgroup-color to green , or if a user clicks on tab show that tab page. |
Key concepts / best practice;
Item | Description |
---|---|
Store JavaScript in code files | Separate your code (function) from the HTML (form), by placing it in files ending with .js |
Using functions | Create functions to better organise your code and also make it easier to reuse the same code.
Example function declaration;
Example function execution;
|
Be expressive | Create variables that express what they represent - ie var totalCount; not var a; |
Debugging | Use the console! Webbrowers have a built-in developer console that anyone can access and use to inspect the form (HTML/CSS) and function (Javascript). More about this in the Quick Start guide. |
When building a webapp you will find you use some common techniques repeatedly, such as;
Item | Description | ||||||
---|---|---|---|---|---|---|---|
Using jQuery Selectors |
jQuery is a set of functions that makes it easier to dynamically manipulate a webpages elements, by first selecting the element or elements and then using jQuery functions to change or add elements. You can use either jQuery or $ as shorthand.
Common selectors when developing a webapp;
|
||||||
Use objects to store data |
Objects are used to store data that represent objects in the real-world - ie in an organisational webapp this can be a customer's contact details ie business name, phone number, webaddress etc.
Example object using entityOS notation;
Example of accessing an object;
|
||||||
Use objects to store code |
Store your code, acting as what is called a "namespace" in an object. This allows you to better organise and reference your code in a meaning full way.
Example of using an object to hold code;
Example of executing code held in object;
|
||||||
Working with data; using "variables" |
Data that is inputted by the user or retrieved from entityOS.cloud typically needs to be held within the browser for later use. To do that we use an object (as per above).
Example of setting data;
Example of getting data;
|
||||||
Common techniques |
A common task of code is to loop through data a compare it to other data or user inputted values. In the following examples we use the lodash framework (more on it in the next section).
var businessContacts = entityOS.search( { object: 'contact_business' }); _.each(businessContacts, function(businessContact) { if (businessContact.status == 'Active') { businessContact.include = true } }); |
||||||
The rules of Javascript |
Javascript as a language has a number of rules that must be followed - similar to the rules of the English language.
|
Similar to how there are frameworks (like bootstrap) to make it easier to work with CSS, there are similar frameworks that add to the functionality of Javascript - like jQuery, lodash & bootstrap (again). All these frameworks provide additional functions that you will commonly use when creating a webapp.
In addition to these general Javascript frameworks, there is a framework that makes it easier to work with entityOS.cloud - more on that later!
Some common frameworks used in webapps include;
Congratulations!
You have now completed the quick tutorials on form & function and how they are constructed for an organisational webapp.
There's more to learn, but we'll tackle that as we work through building an example app in the quick start guide.