Sencha Touch – History Support ”; Previous Next Sencha Touch comes with full history support and deep linking facilities. It has the simplest back button functionality, which helps the user navigate between the screens, without even refreshing the page or application. It also provides routes functionality, which helps the user navigate to any URL. Based on the URL provided in the browser window, it calls specific functions to perform a specific task. Look at the following example for back button functionality. This example shows the nested list which is nothing but a list inside a list, so when you click any of the list items, it opens another list and a back button appears on top of the screen. For complete code base, you can check Nested List under view component section. Routing Simplest example of routes Ext.define(”MyApp.controller.Main”, { extend: ”Ext.app.Controller”, config: { routes: { login: ”showLogin”, ”user/:id”: ”userId” } }, showLogin: function() { Ext.Msg.alert(”This is the login page”); }, userId: function(id) { Ext.Msg.alert(”This is the login page specific to the used Id provided”); } }); In the above example if browser URL is https://myApp.com/#login then the function showLogin will be called. We can provide parameters in the URL and based on the specific parameter the function can get called. For example If the URL is https://myApp.com/#user/3 then the another function userId will be called and the specific ID can be used inside the functions. Advance routing Sometime we have advance parameters which includes comma, blank space and special characters etc. for this if we use the above way of writing routes then it will not work. To solve this problem Sencha touch provides conditional routing where we can specify condition of what type of data the parameter should accept. Ext.define(”MyApp.controller.Main”, { extend: ”Ext.app.Controller”, config: { routes: { login/:id: { action: showLogin, conditions: {”:id: “[0-9a-zA-Z.]+” } } }, showLogin: function() { Ext.Msg.alert(”This is the login page with specific id which matches criteria”); } } }); So as in the above example we have given regex in the condition which clearly states what type of data should be allowed as URL parameter. Sharing same URL across different device profiles As Sencha touch provides device profile so the same application code can be used across multiple devices there may be possibilities that different profiles may have different functionality for the same URL. To resolve this issue Sencha touch gives us freedom to write routing in the main controller and the called function to be written in the all the profile with their profile specific ones. Ext.define(”MyApp.controller.Main”, { extend: ”Ext.app.Controller”, config: { routes: { login: ”showLogin” } }, }); // For phone profile Ext.define(”MyApp.controller.phone.Main, { extend: ”MyApp.controller.Main, showLogin: function() { Ext.Msg.alert(”This is the login page for mobile phone profile”); } }); // For tablet profile Ext.define(”MyApp.controller.tablet.Main, { extend: ”MyApp.controller.Main,showLogin: function() { Ext.Msg.alert(”This is the login page for tablet profile”); } }); As example shows we have one main controller which has showLogin function and we have two different profiles(Phone/ Tablet). Both the profile has showLogin function with different code specific to the profile. This way we can share same URL across multiple profile devices with their specific functionalities. Print Page Previous Next Advertisements ”;
Category: sencha Touch
Sencha Touch – MVC ”; Previous Next MVC stands for Model View Controller. It is an architectural pattern which separates the application into logical components making it more manageable. The following diagram shows how MVC architecture works − Controller − Controller controls whole application it notify view if model is changed and performs actions based on user inputs. View − It contains the interface part of the application which is visual to user. It notify controller to change model on user input. Model − It contains the objects which binds the store data to view. It is representation of the real world object which basically deals with database. It also notify controller for any change in view. Print Page Previous Next Advertisements ”;
Sencha Touch – Device Profile ”; Previous Next In today”s world of technologies, we have multiple devices such as mobile, tablet, desktop, and laptop with different screen sizes. Hence, there is a need to develop applications, which are accessible from all the devices with good look and feel. However, to develop different code for different devices is very time consuming and costly. Sencha Touch helps us in this regard, by offering a device profile feature. Based on the active profile, the different dependencies will be run and applicable. We can declare device profile while writing an application code. We can have multiple devices as − Ext.application({ name: ”MyApp”, profiles: [”Phone”, ”Tablet”] }); Once it is done, the profiles will be loaded as − MyApp.profiles.Phone.js MyApp.profiles.Tablet.js Writing a simple phone profile Ext.define(”Mail.profile.Phone”, { extend: ”Ext.app.Profile”, config: { name: ”Phone”, views: [”phoneView”] }, isActive: function() { return Ext.os.is(”Phone”); } }); Writing a simple tablet profile Ext.define(”Mail.profile.Tablet”, { extend: ”Ext.app.Profile”, config: { name: ”Tablet”, views: [”tableView”] }, isActive: function() { return Ext.os.is(”Tablet”); } }); As we can see in profile, we have isActive function which determines if the particular device is active. If the device is active, the corresponding dependencies will be loaded and instantiated. As mentioned in the above example, if we are using phone device then phone profile”s isActive function will return true and the dependencies related to the phone device will be loaded; here phoneView will be loaded. If the device is a tablet then phone profile”s isActive function will return false and tablet profile”s isActive function will return true and dependency tabletView will be loaded. Launch Process One more point to be noticed here is when we have profiles in the application, then the loading and instantiation of application code will be in the following order − Controllers are instantiated first and each controller”s init function will be loaded. Profile”s launch function will be called. Application”s launch function will be called. Both profile and application”s launch functions are optional, so if we do not define any one of them they will not get called. Take a look at the following code to check where and how the different launch and init functions can be defined. Controller”s init function Ext.define(”MyApp.controller.Main”, { extend: ”Ext.app.Controller”, init : function (){ Ext.Msg.alert(”Controller”s init method”); }, config: { refs: { tab: ”#divId } } }); Profile”s launch function Ext.define(”Mail.profile.Tablet”, { extend: ”Ext.app.Profile”, config: { name: ”Tablet”, views: [”tableView”] }, isActive: function() { return Ext.os.is(”Tablet”); } launch : function() { Ext.Msg.alert(”profile”s launch function”); } }); Application”s launch function Ext.application({ name: ”Sencha”, launch: function() { Ext.Msg.alert(Application”s launch function); } }); Print Page Previous Next Advertisements ”;
Sencha Touch – Core Concepts
Sencha Touch – Core Concept ”; Previous Next Sencha Touch has various core concepts such as class system, ajax, controllers, etc. Following table lists the link for core concepts of Sencha Touch. Sr.No. Concept & Description Link 1 Class System 2 Components 3 Controllers 4 BlackBerry support 5 Use of Ajax Print Page Previous Next Advertisements ”;
Sencha Touch – Naming Convention ”; Previous Next Naming convention is a set of rules to be followed for identifiers. It makes the code easily readable and understandable for other programmers as well. Naming convention in Sencha Touch follows the standard JavaScript convention, which is not mandatory but a good practice to follow. It should follow camel case syntax for naming the class, method, variable, and properties. If the name is combined with two words, the second word will start with an uppercase letter always. For example, doLayout(), StudentForm, firstName, etc. Sr.No. Name & Convention 1 Class Name It should start with an uppercase letter, followed by camel case. For example, StudentClass 2 Method Name It should start with a lowercase letter, followed by camel case. For example, studentMethod() 3 Variable Name It should start with a lowercase letter, followed by camel case. For example, studentName 4 Constant Name It should be in uppercase only. For example, COUNT, MAX_VALUE 5 Property Name It should start with a lowercase letter, followed by camel case. For example, enableColumnResize = true Print Page Previous Next Advertisements ”;
Sencha Touch – Builds ”; Previous Next Today”s demand for a web application is to develop a fast application with less development efforts. Sencha Touch helps in doing so with ease as it provide a number of build libraries to choose from, based on the development or production code along with the facility to create a custom build. Sencha Touch build libraries loads the classes dynamically. Dynamic loading stands for the classes that gets loaded when required and only those classes will be included which are required in the application. This makes the application run faster as the number of files to be loaded reduces, simultaneously decreasing the time to load. Sencha Touch 2.x provides the following five build libraries. Sr.No. Builds & Usage 1 sencha-touchdebug.js This build is used while developing the application locally. It is a nonminified version with all the comments and debug logs for easy debugging while development. 2 senchatouch.js This file is used for production purpose. It is the minified version when we have a custom build. 3 sencha-touchall.js This file is used for production purpose. It is the minified version when we do not have a custom build. 4 sencha-touchall-debug.js This file is used for debugging in production. It is not minified and has all the comments and debug logs. 5 sencha-touchall-compat.js This build is used to migrate the version 1.x to version 2.x. It gives a warning wherever version 1.x code is not compatible and needs code modification. With the above mentioned builds, Sencha Touch provides a facility to create custom builds. Advantages of Having a Custom Build Custom build does not load all the touch files. It loads only those files, which we are using in the application, which makes the application faster and easily maintainable. Sencha CMD is used to create a custom build. To create a custom build in Sencha CMD, go to the directory where the app file resides and type one of the following commands to create a build. Sr.No. Command & Usage 1 sencha app build native Builds the app and prepares a file called packager.temp.json that you can use to package an application–the packager.temp.json is the same as packager.json, but contains additional paths. 2 sencha app build -run native Builds and automatically packages the application, and launches the appropriate simulator. 3 sencha app build package Builds the app with packaging support, but does not configure a packager JSON file. This is useful for projects that manually maintain multiple packager.json files. Once the build is successful, it will generate all-classes.js file which we need to include in our index.html to make it production ready. Following code shows the changes to be done for production ready code. Index.html before building application <!DOCTYPE html> <html> <head> <link href = “https://cdn.sencha.com/touch/sencha-touch-2.4.2/resources/css/sencha-touch.css” rel = “stylesheet” /> <script type = “text/javascript” src = “https://cdn.sencha.com/touch/sencha-touch-2.4.2/sencha-touch-debug.js”></script> <script type = “text/javascript” src = “app.js”> </script> </head> <body> </body> </html> Index.html after building the application <!DOCTYPE html> <html> <head> <link href = “https://cdn.sencha.com/touch/sencha-touch-2.4.2/resources/css/sencha-touch.css” rel = “stylesheet” /> <script type = “text/javascript” src = “https://cdn.sencha.com/touch/sencha-touch-2.4.2/sencha-touch.js”></script> <script type = “text/javascript” src = “app.js”> </script> <script type = “text/javascript” src = “app-classes.js”> </script> </head> <body> </body> </html> Print Page Previous Next Advertisements ”;
Sencha Touch – Environment
Sencha Touch – Environment ”; Previous Next Local Environment Setup This section guides you on how to download and set up Sencha Touch on your machine. Please follow the steps to set up the environment. Downloading library files Download a commercial version of Sencha Touch library files from the following link https://www.sencha.com. You will get the trial version from the site on your registered mail id, which will be a zipped folder named sencha-touch-2.4.2-commercial. Unzip the folder and you will find various JavaScript and CSS files to include in your application. Include mostly the following files − Javascript Files − JS file which you can find under folder sencha-touch-2.4.2commercialtouch-2.4.2 are − Sr.No File & Description 1 sencha-touch.js This is the core file which contains all functionalities to run the application. 2 sencha-touch-all.js This file contains all the code minified with no comments in the file. 3 sencha-touch-debug.js This is the unminified version of sencha-touch-all.js for debugging purpose. 4 sencha-touch-all-debug.js This file is also unminified and is used for development purpose as it contains all the comments and console logs to check any errors/issues. You can add these files to your projects JS folder or you can provide a direct path where the files reside in your system. CSS Files − There are number of theme based files which you can find under folder I:sencha touchsencha-touch-2.4.2-commercialtouch-2.4.2resourcescsssencha-touch.css These library files will be added in Sencha Touch application as follows − <html> <head> <script type = “text/javascript” src = “../sencha-touch-2.4.2-commercial/touch-2.4.2/sencha-touch-all.js”></script> <link href = “../sencha-touch-2.4.2-commercial/touch-2.4.2/resources/css/sencha-touch.css” rel = “stylesheet” /> <script type =”text/javascript” src = “app.js” > </script> </head> </html> You can keep Sencha Touch application code in app.js file. CDN Setup CDN is content delivery network with which you do not need to download the Sencha Touch library files, instead you can directly add CDN link for ExtJS to your program as follows − <html> <head> <script type = “text/javascript” src = “https://cdn.sencha.com/touch/sencha-touch-2.4.2/sencha-touch-all.js”></script> <link href = “https://cdn.sencha.com/touch/sencha-touch-2.4.2/resources/css/sencha-touch.css” rel=”stylesheet” /> <script type = “text/javascript” src = “app.js” > </script> </head> </html> Popular Editors As it is a JavaScript framework used for developing web applications, the project will have HTML, JS files, and to write your Ext JS programs, you will need a text editor. There are multiple IDEs available in the market. But for now, you can consider one of the following − Notepad − On Windows machine, you can use any simple text editor such as Notepad (Recommended for this tutorial), Notepad++. Brackets − Another popular IDE which can be downloaded from http://brackets.io/. Sublime − Another popular IDE which can be downloaded from https://www.sublimetext.com/3/. Print Page Previous Next Advertisements ”;
Sencha Touch – Quick Guide
Sencha Touch – Quick Guide ”; Previous Next Sencha Touch – Overview Sencha Touch is a popular framework of Sencha for creating a user interface for mobile applications. It helps the developer create a mobile app using simple HTML, CSS, JS which supports many mobile devices such as android, IOS, BlackBerry, and Windows. It is based on MVC architecture. The latest version of Sencha Touch is 2.4. History of Sencha Touch After releasing Sencha”s other product, ExtJs, which was for web application, there was a need to develop a framework which works on mobile devices too. The first version of Sencha Touch was 0.9 beta version, which supported Android and IOS devices. Later, the first main release of Sencha Touch version 1.0 was in November 2010, which was the first stable version and supported Blackberry devices too. The latest release of Sencha Touch is version 2.4 released in June 2015, which supports many devices such as Windows, Tizen along with Android, IOS, BlackBerry OS 10, Google Chrome for Android and mobile Safari, etc. Features of Sencha Touch Following are the most prominent features of Sencha Touch − Customizable and more than 50 build in UI widgets with a collection of rich UI such as lists, carousels, forms, menus, and toolbars, built specifically for mobile platforms. Code compatibility of new versions with the older one. A flexible layout manager that helps organize the display of data and content across multiple mobile devices with different OS. The framework includes a robust data package that can consume data from any backend data source. Adaptive layouts, animations, and smooth scrolling for a better mobile web application experience for the use. Out-of-the-box, native-looking themes for every major platform enables to make web and hybrid applications match the look and feel of the target platforms. Sencha Touch ─ Benefits Sencha Touch is the leading standard for business-grade web application development. It offers the tools necessary to build robust applications for most of the mobile devices providing a single platform for developing applications. Following are some of the benefits − Provides a responsive touch feature, hence the user can easily navigate while using the mobile app. Provides compatibility with all the latest versions of IOS, Android and Blackberry, and Windows. Provides fastest possible speed desirable for any mobile application. Provides a cost-effective solution with its cross-platform compatibility. Based on the native APIs and basic web development languages such as HTML, CSS, JS which makes it easier for a developer to understand Sencha Touch. Sencha Touch ─ Limitations Sencha Touch API doesn”t have the following capability − The app does not have access to the device’s camera, contacts, and accelerometer. It does not provide the push notification facility. For this, we have to use websockets or long polling. According to general public license policy, it is free for open source applications however paid for commercial applications. It is not good for hardcore graphics and animation apps such as for gaming apps. Sencha Touch ─ Tools Sencha SDK This is Sencha development kit used to create a skeleton of the project. We use the command “sencha -sdk path/to/touch generate app appName” to create an app with the name given in the command. When the app is created, you can see the following files in the app − app − This folder contains model, view, controller and store files for the app. app.js − This is the main JS file for your application. From this file, the Sencha code flow starts. app.json − This is the configuration file for the app, all the configuration details presents here. index.html − This is the main html file where we include the app.js and other Sencha related files. package.json − This file has all the dependency and other information related to the app. resources − This folder includes all the CSS files and images required for the application. Sencha CMD Sencha CMD is a command line tool, which provides the features of Sencha Touch code minification, scaffolding, build generation, and other useful features for production purpose. We use command “Sencha app build package” in the command prompt to build the application for this. Go to the app directory in the command prompt and type the above command. Once the build is successful, we will see the minified version of the application basically used for production purpose. This can be downloaded from https://www.sencha.com/products/extjs/cmd-download/ Sencha Inspector Sencha Inspector is a debugging tool to debug any issue in Sencha code during development. Sencha Touch – Environment Setup We have set up Sencha Touch Programming environment online, so that you can compile and execute all the available examples online. It gives you confidence in what you are reading and enables you to verify the programs with different options. Feel free to modify any example and execute it online. <!DOCTYPE html> <html> <head> <link href=”http://cdn.sencha.com/touch/sencha-touch-2.4.2/resources/css/sencha-touch.css” rel=”stylesheet” /> <script type=”text/javascript” src=”http://cdn.sencha.com/touch/sencha-touch-2.4.2/sencha-touch-all.js”></script> <script type=”text/javascript”> Ext.application({ name: ”Sencha”, launch: function() { Ext.create(“Ext.tab.Panel”, { fullscreen: true, items: [{ title: ”Home”, iconCls: ”home”, html: ”Welcome” }] }); } }); </script> </head> <body> </body> </html> Local Environment Setup This section guides you on how to download and set up sench Touch on your machine. Please follow the steps to set up the environment. Downloading library files Download a commercial version of Sencha Touch library files from sencha https://www.sencha.com. You will get the trial version from the site on your registered mail id which will be a zipped folder named sencha-touch-2.4.2-commercial. Unzip the folder and you will find various JavaScript and CSS files which you will include in our application. We will mostly include following files:
Sencha Touch – Home
Sencha Touch Tutorial PDF Version Quick Guide Resources Job Search Discussion Sencha Touch is a mobile application framework to develop user interface for mobile apps using HTML5, CSS3, and JavaScript. It assists the developers in creating mobile apps with ease that supports Android, iOS, Windows, Tizen, Microsoft Surface Pro and RT, and BlackBerry devices. Audience This tutorial has been prepared for beginners to help them understand the concepts of Sencha Touch to build a mobile application. Prerequisites For this tutorial, the reader should have prior knowledge of HTML, CSS, and JavaScript coding. It would be helpful if the reader is aware of the concepts of object-oriented programming and also has a general idea on creating web applications. Print Page Previous Next Advertisements ”;
Sencha Touch – First App
Sencha Touch – First Program ”; Previous Next In this chapter, we will list down the steps to write the first Hello World program in Ext JS. Step 1 Create an index.htm page in an editor of our choice. Include the required library files in the head section of html page as follows. index.htm Live Demo <!DOCTYPE html> <html> <head> <link href = “https://cdn.sencha.com/touch/sencha-touch-2.4.2/resources/css/sencha-touch.css” rel = “stylesheet” /> <script type = “text/javascript” src = “https://cdn.sencha.com/touch/sencha-touch-2.4.2/sencha-touch-all.js”> </script> <script type = “text/javascript”> Ext.application( { name: ”Sencha”, launch: function() { Ext.create(“Ext.tab.Panel”, { fullscreen: true, items: [{ title: ”Home”, iconCls: ”home”, html: ”Welcome to sencha touch” }] }); } }); </script> </head> <body> </body> </html> Explanation Ext.application() method is the starting point of Sencha Touch application. It creates a global variable called ”Sencha” declared with the name property – all the Application”s classes such as its Models, Views and Controllers will reside under this single namespace, which reduces the chances of colliding global variables and file names. launch() method is called once the page is ready and all the JavaScript files are loaded. Ext.create() method is used to create an object in Sencha Touch. Here, we are creating an object of simple panel class Ext.tab.Panel. Ext.tab.Panel is the predefined class in Sencha Touch for creating a panel. Every Sencha Touch class has different properties to perform some basic functionalities. Ext.Panel class has various properties such as − fullscreen property is to make use of a complete screen, hence the panel will take fullscreen space. items property is the container for various items. iconCls is the class used for displaying different icons. title property is to provide the title to the panel. html property is the html content to be shown in the panel. Step 2 Open the index.htm file in a standard browser and you will get the following output. Print Page Previous Next Advertisements ”;