Advance ExtJS concepts. Javascript Object var obj = {}; obj.x = 10; obj.y = 20; var obj = new Object; obj.x = 10; obj.y = 20; function Foo() {this.x =

Slides:



Advertisements
Similar presentations
Java Programming 2 Dr. Priti Srinivas Sajja Introductory concepts of java programming as specified in PGDCA 203:Object Technology, S P University.
Advertisements

Using Eclipse. Getting Started There are three ways to create a Java project: 1:Select File > New > Project, 2 Select the arrow of the button in the upper.
The Web Warrior Guide to Web Design Technologies
C++ Inheritance Gordon College CPS212. Basics OO-programming can be defined as a combination of Abstract Data Types (ADTs) with Inheritance and Dynamic.
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Advanced Object-Oriented Programming Features
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
Chapter 14 Generics and the ArrayList Class Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
C# Programming: From Problem Analysis to Program Design1 Advanced Object-Oriented Programming Features C# Programming: From Problem Analysis to Program.
Chapter 3 - Introduction to Java Applets Outline 3.1Introduction 3.2Thinking About Objects 3.4A Simple Java Applet: Drawing a String 3.5Two More Simple.
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
ExtJS Classes By Aaron Conran. Creating Classes Creating classes in JavaScript is easy as creating a constructor function and using the new keyword when.
1 Using jQuery JavaScript & jQuery the missing manual (Second Edition)
Chapter 6: Graphical User Interface (GUI) and Object-Oriented Design (OOD) J ava P rogramming: Program Design Including Data Structures Program Design.
Presented by…. Group 2 1. Programming language 2Introduction.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Object Based Programming. Summary Slide  Instantiating An Object  Encapsulation  Inheritance  Polymorphism –Overriding Methods –Overloading vs. Overriding.
1 Chapter One A First Program Using C#. 2 Objectives Learn about programming tasks Learn object-oriented programming concepts Learn about the C# programming.
A First Program Using C#
WaveMaker Visual AJAX Studio 4.0 Training Troubleshooting.
“is a”  Define a new class DerivedClass which extends BaseClass class BaseClass { // class contents } class DerivedClass : BaseClass { // class.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
Ajax Runtime Toolkits IBM Emerging Technologies. What is an AJAX Toolkit/Framework? An AJAX Toolkit/Runtime is more than just XMLHTTPRequest Should includes:
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Design patterns. What is a design pattern? Christopher Alexander: «The pattern describes a problem which again and again occurs in the work, as well as.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
1 JavaScript. 2 What’s wrong with JavaScript? A very powerful language, yet –Often hated –Browser inconsistencies –Misunderstood –Developers find it painful.
Virtual techdays INDIA │ Nov 2010 Developing Office Biz Application using WPF on Windows 7 Sarang Datye │ Sr. Consultant, Microsoft Sridhar Poduri.
Tutorial 2 Variables and Objects. Working with Variables and Objects Variables (or identifiers) –Values stored in computer memory locations –Value can.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
1 JavaScript in Context. Server-Side Programming.
Getting a handle on ActionScript A basic primer for non-programmers.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
Object Oriented JavaScript. JavaScript Really only 4 types in JavaScript – number, string, boolean – Object (includes arrays) Remember that an object.
Introduction to Exception Handling and Defensive Programming.
JavaScript Framework for Rich Apps in Every Browser Maura Wilder Joan Wortman
CSD 340 (Blum)1 Starting JavaScript Homage to the Homage to the Square.
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Java Programming: From Problem Analysis to Program Design, 3e Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Java Programming: From Problem Analysis to Program Design, Second Edition1 Lecture 5 Objectives  Learn about basic GUI components.  Explore how the GUI.
CSD 340 (Blum)1 Starting JavaScript Homage to the Homage to the Square.
1 JavaScript in Context. Server-Side Programming.
Introduction to Object-Oriented Programming Lesson 2.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
Rich Internet Applications 2. Core JavaScript. The importance of JavaScript Many choices open to the developer for server-side Can choose server technology.
Changing HTML Attributes each() function Anonymous Functions $(this) keyword.
Understanding JavaScript and Coding Essentials Lesson 8.
Object-Oriented Programming: Inheritance and Polymorphism.
Object Oriented JavaScript. JavaScript Really only 4 types in JavaScript – number, string, boolean – Object (includes arrays) Remember that an object.
POLYMORPHISM Chapter 6. Chapter Polymorphism  Polymorphism concept  Abstract classes and methods  Method overriding  Concrete sub classes and.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Internet Computing Module II. Syllabus Creating & Using classes in Java – Methods and Classes – Inheritance – Super Class – Method Overriding – Packages.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
Customizing Share Document Previews Will Abson Senior Integrations Engineer and Share Extras Project Lead
1 Using jQuery JavaScript & jQuery the missing manual (Second Edition)
Layouts To understand various layouts extjs provides, and overview of some commonly used layouts.
Advance ExtJS concepts. Javascript Object var obj = {}; obj.x = 10; obj.y = 20; var obj = new Object; obj.x = 10; obj.y = 20; function Foo() {this.x =
Java Programming: From Problem Analysis to Program Design,
12 Data abstraction Packages and encapsulation
Using Procedures and Exception Handling
Tutorial 19 - Microwave Oven Application Building Your Own Classes and Objects Outline Test-Driving the Microwave Oven Application Designing.
WEB PROGRAMMING JavaScript.
Java – Inheritance.
Object-Oriented Programming: Inheritance and Polymorphism
Using Templates and Library Items
Constructors, GUI’s(Using Swing) and ActionListner
Presentation transcript:

Advance ExtJS concepts

Javascript Object var obj = {}; obj.x = 10; obj.y = 20; var obj = new Object; obj.x = 10; obj.y = 20; function Foo() {this.x = 10; this.y = 20;} var obj = new Foo In JavaScript, each Object can inherit properties from another object, called it's prototype function Bar() {this.z = 30;} Bar.prototype = new Foo; Bar.prototype.constructor = Bar; var obj = new Bar x10 y20 Foo.prototype constructorFoo Object.protoype constructorObject z30 Bar.prototype x10 y20 constructorBar Foo.prototype constructorFoo Object.protoype constructorObject

function Mammal(name){ this.name=name; this.offspring=[]; } Mammal.prototype.baby=function(){ var newBaby=new Mammal("Baby "+this.name); this.offspring.push(newBaby); return newBaby; } function Cat( name ){ this.name=name; } Cat.prototype = new Mammal(); Cat.prototype.constructor=Cat; Cat.prototype.parent = Mammal.prototype; Cat.prototype.baby=function(){ var theKitten = this.parent.baby.call(this); alert("mew!"); return theKitten; }

Inheritance Summary You cause a class to inherit using ChildClassName.prototype = new ParentClass(); You need to remember to reset the constructor property for the class using ChildClassName.prototype.constructor=ChildClassName You can call ancestor class methods which your child class has overridden using the Function.call() method.

Inheritance: ExtJS Ext provides a utility function called Ext.extend that is the mechanism for implementing class inheritance using the Ext framework. It gives you the ability to modify or extend the base functionality of any JavaScript class without making code changes directly to the class itself. It is the preferred method for extending Ext components. MyClass = Ext.extend(Ext.SomeClass, { someFunction : function(arg1, arg2){ // custom code // call base class MyClass.superclass.someFunction.call(this, arg1, arg2); // custom code } );

How to create custom extjs components Sometimes you will have a component whose config options you want to make reusable. For example, you may have a set of panels with the same width and height, only the title is different. This is called a preconfigured class. Another reason you want to use OO classes is that you want to extend the functionality of another class. Let us say you want to add a function in the above panel and override an existing function.

Constructor Model // MyPanel Extends Ext.Panel MyPanel = Ext.extend(Ext.Panel, { // constructor function constructor: function(config) { Ext.apply(this, { // Put your pre-configured config options here width: 300, height: 300 }); MyPanel.superclass.constructor.apply(this, arguments); } }); var myfirstpanel = new MyPanel({ title: 'My First Panel' });

Factory Pattern function createMyPanel(config) { return new Ext.Panel(Ext.apply({ //Pre-configured config options go here width: 300, height: 300 }, config)); }; var myfirstpanel = createMyPanel({ title: 'My First Panel' });

Extending Functionality // Constructor var MyPanel = function(config) { //Reusable config options here Ext.apply(this, { width: 300, height: 300 }); // And Call the superclass to preserve baseclass functionality MyPanel.superclass.constructor.apply(this, arguments); // Here you can add functionality that requires the object to exist, like event handling. this.on('click', function() {alert("You Clicked " + this.title);}, this); };

Another way to write the constructor above var MyPanel = function(config) { // Call the superclass to preserve baseclass functionality MyPanel.superclass.constructor.call(this, Ext.apply({ //Reusable config options here width: 300, height: 300 }, config)); // After superclass constructor add functionality that requires // the object to exist (like event handling...listeners) this.on('click', function() {alert("You Clicked " + this.title);}, this); };

// MyPanel Extends Ext.Panel Ext.extend(MyPanel, Ext.Panel, { // Here you can add static variables for the class. variables that will have // the same value for all object instances of this class. // New function added myNewFunction: function() { }, // Override an existing function onRender: function() { MyPanel.superclass.onRender.apply(this, arguments); this.myNewFunction(); } }); // register xtype to allow for lazy initialization Ext.reg('mypanelxtype', MyPanel );

initComponent (new) To extend an Ext class we do not need to create a constructor function. We just need to assign the return value of Ext.extend call to a variable in our name space. Ext.extend takes the original class and a config object as arguments and returns our extension. All tasks that were done in a custom constructor function are now done in initComponent function that we almost always override. initComponent is called early from the parent constructor function. However, initComponent of the original class contains useful code that needs to be executed. Registering an xtype for your extension is not mandatory but it is very good practice.

initComponent: function() { //Reusable config options here Ext.apply(this, { width: 300, height: 300 }); // And Call the superclass to preserve baseclass functionality MyPanel.superclass.initComponent.apply(this, arguments); // Here you can add functionality that requires the object to // exist, like event handling. this.on('click',function() {alert("You Clicked " + this.title);},this); }

var MyPanel = Ext.extend(Ext.Panel, { // Here you can add static variables for the class. variables that // will have the same value for all object instances of this class. initComponent: function() { … }, // New function added myNewFunction: function() { }, // Override an existing function onRender: function() { MyPanel.superclass.onRender.apply(this, arguments); this.myNewFunction(); } }); var myfirstpanel = new MyPanel({ title: 'My First Panel' });

Composition or Extension When creating a new class, the decision must be made whether to own an instance of a utility class which is to perform a major role, or to extend that class. It is recommended that you extend the nearest base class to the functionality required.

The Template method Pattern The render method is called (This is done by a Container’s layout manager). This method may not be overridden and is implemented by the Ext base class

The Template Methods for Component onRender afterRender onAdded onRemoved onShow onHide onDisable onEnable onDestroy

Which class to extend Component If the required UI control does not need to contain any other controls, that is, if it just to encapsulate some form of HTML which performs the requirements BoxComponent I needs to have its size and/or position managed by a layout manager Container If the required UI control is to contain other UI elements, but does not need any additional capabilities of Panel – onBeforeAdd – onAdd – onRemove – onLayout Panel If the required UI control must have a header, footer, or toolbars, then Ext.Panel is the appropriate class to extend. – onCollapse – onExpand

When a subclass is not needed Method injection When in one particular situation, one piece of functionality of an existing class needs to be overridden, or added to, an instance-specific implementation. Configuring a Plugin A Plugin is a class which implements an init(Component) method which is attached to a Component through the plugins config option. A Factory method If all that is required is a specific configuration of an existing class. Override a functionality (universally) Adds a list of functions to the prototype of an existing class, overwriting any existing methods with the same name. Usage: Ext.override(MyClass, { newMethod1: function(){ // etc. }, newMethod2: function(foo){ // etc. } });

Events in Ext Event is a message, a function call, generated by one (part of) program, the event source, that notifies another (part of) program, the event listener, that something happened. Events in Ext – DOM Events – JavaScript Events var myPanel = new Ext.Panel({...}); myPanel.on('some_event', function(…) {…}); Event source in ExtJS are extension of Ext.Util.Observable class

Custom Events MyPanel = Ext.extend(Ext.Panel, { initComponent:function() {... MyPanel.superclass.initComponent.apply(this, arguments);... // add custom events this.addEvents('loaded', 'completed'); }, load:function(cfg) {.... // fire loaded event this.fireEvent('loaded', this, cfg); }, complete:function(cfg) {... // fire completed event this.fireEvent('completed', this, cfg); } });

Relay Events Relays selected events from the specified Observable as if the events were fired by this … var content = new MyPanel({...}); var itemx = … … // create the window and add content panel var win = new Ext.Window({... items : [itemx, …, content ] }); // Tell the window to handle the 'loaded' and 'completed' events from the content panel win.relayEvents(content, ['loaded', 'completed']); // here's the handlers for the custom MyPanel events win.on( { 'loaded' : function (panel, obj) {...}, 'completed' : function(panel, obj) {...}, scope : this });

Events: Summary event is a message sent (fired) by an event source to inform listeners that something happened event source is an object that can fire events event listener is a function that is called when event source fires an event to listen to events we use on function to install an event listener to create an event source we extend Observable class, addEvents and fireEvent

Namespaces It is typical to include many libraries, widgets and snippets of code from many different sources. not a safe assumption that you have the entire global namespace at your disposal. When developing your own scripts you should place all of your classes and singletons into namespaces to avoid collisions with other developers code. An abstract container to hold all of your classes and singletons

Namespaces (ExtJS) if (!App) App = {}; if (!App.form) App.form = {}; if (!App.data) App.data = {}; Ext provides the Ext.namespace method which will setup namespaces for you, including checking if the namespace already exists. /* Ext.namespace will create these objects if they don't already exist */ Ext.namespace('App', 'App.form', 'App.data'); /* Now you can define a new class such as SampleForm inside of the App.form package */ App.form.SampleForm = Ext.extend(Ext.form.FormPanel, { initComponent: function() {... App.form.SampleForm.superclass.initComponent.call(this); } }); /* Define MySingleton inside of the App.data package */ App.data.MySingleton = function() { return { x: 4 }; }();

Upgrade of ExtJS (to version 3.x) Look for extended classes and see if they override any base ExtJS Classes methods. Ensure that these are not modified. Ensure you have updated all the Ext-provided CSS with the new CSS from version 3. Ensure you have updated all the Ext-provided images with the new images from version 3. Read the release notes and look for areas in coding using changed functionality. They have done some changes in data stores and ajax. If you have not extended these classes then you should be OK.

Debugging ExtJS Using IE Explorer debugger for 8.x Using MS Visual studio Using Firebug for firefox Using other in-built debuggers with respective browsers

ExtJS Performance Build your own Extjs - this will just use the components you need, and as well css. Reduces file size. Compress using JSmin. Concatenate all your Javascript sources into one file for live running. Serve javascript files gzipped. Avoid memory leaks like using mon instead of on to bind events. Destroy any component added to this on destroy of this.

ExtJS Cross browser ExtJs supports – IE 7.x, 8.x – FF 2.x, 3.x – Webkit based browsers (safari, chrome) Handling of trailing commas in JSON for IE CSS issues related to box model on IE Other CSS issues like float, z-index

ExtJS Coding Standards The unit of indentation is four spaces Avoid lines longer than 80 characters. Place the break after an operator, ideally after a comma. Be generous with comments. All variables should be declared before used. All functions should be declared before they are used. Inner functions should follow the var statement. Names should be formed from the 26 upper and lower case letters (A.. Z, a.. z), the 10 digits (0.. 9), and _ (underbar). Global variables should be in all caps.

Each line should contain at most one statement. Put a ; (semicolon) at the end of every simple statement. A return statement with a value should not use ( ) (parentheses) around the value. Use {} instead of new Object(). Use [] instead of new Array(). Avoid the use of the comma operator except for very disciplined use in the control part of for statements. It is almost always better to use the === and !== operators. The == and != operators do type coercion. The eval function is the most misused feature of JavaScript. Avoid it.