Extjs 131015110929 Phpapp01
Extjs 131015110929 Phpapp01
[email protected]
Module 1(Day1): JavaScript
The lessons covered in this module include:
DHTML
Introduction to JavaScript
Elements of JavaScript Program
JavaScript Statements
Functions
Objects
Defining Objects
Arrays
Events
Time Outs
Integrating JavaScript with Java
Creating Windows
Summary
Examples and Exercises
2
Module 2 (Day2): ExtJs
Introduction of ExtJs
Getting Started
Fundamental Classes
Event Handling
Component Model
Examples
Module 3 (Day3): ExtJs cont
Getting Started with Sencha Architect
Create and Configure Components
Create/Configure Data Stores
Templates & DataView
Creating & Extending Classes
Examples
Module 4 (Day4): ExtJs cont
Internationalization
Drag & Drop
Hands-on Experience w/ Common Components
TabPanel
GridPanel
TreePanel
FormPanelBuilding a Theme
Application Best Practices
Objectives
At the end of this module you will be able to:
1. Write JavaScript code using all the basic elements
of JavaScript Programs
2. Create Windows & Dialog Boxes
3. Use the JavaScripts in-built objects in a web page
4. Write code that does Event Handling in HTML
pages
5. Manipulate HTML Forms through JavaScript
dynamically
6. Integrate Java and JavaScript through Applets
6
DHTML
DHTML stands for Dynamic Hyper Text Markup
Language which
helps to add Dynamic content to static HTML
pages.
7
Introduction to JavaScript
JavaScript is:
1. An easy to use object scripting language
2. Designed for creating live online applications
3. Code is included as part of a HTML document
4. Scripts are run by the Web browser
8
Introduction to JavaScript: JavaScript Versus Java
9
Introduction to JavaScript: Using the SCRIPT Tag
<HTML>
<HEAD>
<TITLE>Simple JavaScript Example
</TITLE>
</HEAD>
<BODY>
HTML Text goes here.
<SCRIPT LANGUAGE="JavaScript">
document.write("Here is my output.")
</SCRIPT>
</BODY>
</HTML>
10
Elements of JavaScript Program
Elements of JavaScript Program can be divided
into five categories, as
follows:
1. Variables
2. Expressions
3. Control Structures
4. Functions
5. Objects and Arrays
11
Elements of JavaScript Program:
Variables
Data Types
Type Casting
12
JavaScript Statements: while
Statement
A while statement executes its statements as
long as a specified condition evaluates to true.
A while statement looks as follows:
while (condition) {
statements
}
18
Functions
Functions are one of the fundamental building blocks
in JavaScript. A function is a JavaScript procedure: a set
of statements that performs a specific task. To use a
function, you must first define it, then your script can
call it. A function definition looks as follows:
function gcd(m,n)
{
return n > 0 ? gcd(n,m%n) : m ;
}
19
Objects
An object is a self-contained unit of code
having the following characteristics:
Properties
Methods
Identity
20
Objects: The Window Object
At the top of the browser hierarchy is the
window object, which represents a browser
window
21
Objects: The Document Object
Represents characteristics of the current HTML page.
Some of its properties are:
title - lastModified
fgColor - bgColor
22
Objects: The Form Object
Represents an HTML Form.
23
Objects: Frame Objects
Each Frame in a frame set is represented as a
frame object
24
Objects: The Math Object
The Math object cant be created, since it
exists automatically in all Java Script Programs
Its properties represent mathematical
constants
Its methods are mathematical functions
25
Objects: The String Object
Any String variable in JavaScript is a String
object. It has a property
Length and
Many Methods
26
Objects: The Date Object
Is built-in JavaScript object
27
Defining Objects
The object definition is a simple function that
accepts parameters to
initialize a new object and assigns those to the
corresponding
properties.
29
Defining Objects: Looping through Objects Properties
31
Arrays
JavaScript doesnt support array variables
32
Events
Are things that happen to the browser
33
Events: Event Handlers
Embedded in HTML tags as part of anchor and
links or any of the form element tags.
34
Events
Some (but not all) elements on the web page
respond to user interactivity (keystrokes, mouse
clicks) by creating events
Different kinds of elements produce different events
Browsers are not all alike in what events are produced
We will concentrate on events from HTML form
elements and commonly recognized events
You can put handlers on HTML form elements
If the event isnt generated, the handler does nothing
A handler should be very short
Most handlers call a function to do their work
35
A simple event handler
<form method="post" action="">
<input type="button"
name="myButton"
value="Click me"
onclick="alert('You clicked the button!');">
</form>
The button is enclosed in a form
method tells how to send the form data; action tells where to send it
The tag is input with attribute type="button"
The name can be used by other JavaScript code
The value is what appears on the button
onclick is the name of the event being handled
The value of the onclick element is the JavaScript code to execute
alert pops up an alert box with the given text
36
Capitalization
JavaScript is case sensitive
HTML is not case sensitive
onclick="alert('You clicked the button!');"
The red underlined parts are HTML
The quoted string is JavaScript
You will frequently see onclick capitalized as onClick
The Java naming convention is easier to read
This is fine in HTML, but an error if it occurs in JavaScript
38
Example: Simple rollover
The following code will make the text Hello
red when the mouse moves over it, and
blue when the mouse moves away
<h1 onMouseOver="style.color='red';"
onMouseOut="style.color='blue';">Hello </h1>
Image rollovers are just as easy:
<img src="../Images/duke.gif"
width="55" height="68"
onMouseOver="src='../Images/duke_wave.gif';"
onMouseOut="src='../Images/duke.gif';">
39
Events and event handlers I
The following tables are taken from:
http://developer.netscape.com/docs/manuals/js/client/
jsguide/index.htm
43
Events and event handlers V
Event Applies to Occurs when Handler
Move Windows User or script onMove
moves a window
44
Events and event handlers VI
Event Applies to Occurs when Handler
Focus Windows and all User gives onFocus
form elements element input
focus
Blur Windows and all User moves onBlur
form elements focus to some
other element
Reset Forms User clicks a onReset
Reset button
45
JavaScript and HTML Forms
Object Model for the Browser Window
Compound object structure is created when a web
page loads into a browser
Hierarchy
Window is an object, the HTML document is an
object and its elements are objects
These objects have primitives associated with
them
JavaScript and HTML Forms
window [closed, location]
history [length]
58
Summary
In this module you have learnt to:
Write JavaScript code using all the basic elements
of JavaScript Programs
Create Windows & Dialog Boxes
Use the JavaScripts in-built objects in a web page
Write code that does Event Handling in HTML
pages
Manipulate HTML Forms through JavaScript
dynamically
Integrate Java and JavaScript through Applets
59
Introduction to ExtJS Framework
Introduction to ExtJS
ExtJS is a java-script framework (client-side) that
enables developers to develop Rich Internet
Applications (RIA) (static websites or data-
driven applications) with a large number of
options.
ExtJS has a huge collection of controls (ranging
from textboxes to highly sophisticated UI
Controls) along with a brilliant demo +
examples.
Points to Remember
29/08/2017 123
Hello World with ExtJS
Eureka!!!, there we go
29/08/2017 124
A close look at our code & output
Our code Output
29/08/2017 128
Looking at an Asynchronous Ext!
Ext.onReady(function(){ As denoted at the
// rest of code follows beginning of this lesson,
}); Ext is asynchronous (by
default).
What is Ext.onReady() ?
The code within the
Is is an event. onReady
function would execute
is the first event that
only after the onReady
fires when the DOM is
event.
constructed by the
browser. Understanding the async
nature makes a long step
in programming with Ext.
29/08/2017 129
When Ext.onReady() fires?
ASP.Net Life
Client browser Web Server
Cycle
1 2 3
On after
Browser
generation,
generates the Parsed contents
Ext.onReady()
page
fires
6 5 4 130
Explaining the sequence
1 to 2: The client browser makes a request to a
web page at the web-server.
2 to 3: Web server acknowledges the request,
loads the page & executes it. Execution
includes all server side application logic (making
DB calls / file IO etc) in .net compliant language.
@ stage 3: This shows the life cycle of any web-
form from PreInit event to Unload event.
29/08/2017 131
Explaining the sequence
@ stage 4: Once all server-side events are fired
and execution is completed, web server
constructs the output form with all required CSS,
js files and sends the contents to the browser.
@ stage 5: Browser receives the contents sent by
server, parses & generates the page, and finally
renders to the user.
Once all the HTML elements are generated, the
DOM is said to be ready. All the js files linked
with the page, are cached in the local machine.
29/08/2017 132
Explaining the sequence
@ stage 6: Once all the js files are completely
cached locally & the DOM is ready, the
Ext.onReady() event fires.
It is at this stage, the ExtJS code is loaded from
the js files and the UI is rendered / front end
execution begins.
ExtJS codes are loaded & executed in the
order in which the js files are linked in the
aspx page.
29/08/2017 133
onReady & Async nature
Like any Ext application, in our Hello world
example, the message box code executes only
after Ext.onReady() event.
Thereby care must be taken as to know &
understand, when the components are
rendered and when & how they are available
for accessibility.
Failing to do this, would throw Ext.getCmp()
is null or not an object script error message.
29/08/2017 134
What else extjs can do?
Ajax support
Dom traversing
Dom manipulation
Event Handling
Selectors
OOP emulation
Animation
Main extjs classes
Component
Panel
Observable
Store
Component
All widgets extends component class
Provide base widget functions like
enable()/disable()
show()/hide()
addClass()/removeClass()
update(data/html) update content area
getEl() return element
getId()
getXType()
render(target)
focus()
XType alternate way to define
component
Lazy component creation
var panel1 = {
xtype : 'panel',
title : 'Plain Panel',
html : 'Panel with an xtype specified'
}
var myPanel = new Ext.Panel({
renderTo : document.body,
height : 50,
width : 150,
title : 'Panel',
frame : true
Components are managed by
Ext.ComponentMgr
get(componentId)
registerType(xtype, object) (shorthand Ext.reg())
Containers
handle the basic behavior of containing
items, namely adding, inserting and
removing items
Main functions
add()
remove()/removeAll()
insert()
find()/findBy()/findById()/findByType
doLayout()
get(index or
id)/getComponent(component or index or
id)
Main prop
Items - MixedCollection of children
components
Panels
Main panel functions/prop/conf prop
load()
panel.load({
url: 'your-url.php',
params: {param1: 'foo', param2: 'bar'}, // or a URL encoded string
callback: yourFunction,
scope: yourObject, // optional scope for the callback
discardUrl: false,
nocache: false,
text: 'Loading...',
timeout: 30,
scripts: false
});
body prop
html conf prop
autoLoad conf prop
Ex:
Ext.apply(this, config);
// with defaults
var defConfig = {test: abc};
Ext.apply(this, config, defConfig);
Ext.applyIf
Ext.applyIf works similarly to Ext.apply except
if properties already exist they wont be
overwritten.
Ex:
var point = point || {};
var default = {x: 0, y: 0};
Ext.applyIf(point, default);
Ext.extend
Ext.extend is used to extend or inherit from classes
which already exist.
Generic Pattern:
var SubClass = function() {
SubClass.superclass.constructor.call(this);
};
Ext.extend(SubClass, BaseClass, {
newMethod : function() {},
overriddenMethod : function() {}
};
SubClass extends BaseClass and overrides
overridenMethod and adds newMethod.
superclass.constructor
The superclass.constructor property points to
our base (or super) class constructor.
We use the JavaScript call method to run the
constructor in the scope of this.
this will always be our first argument of call.
Other arguments will be passed to our base
constructor:
Ex:
BaseClass.superclass.constructor.call(this, config);
Extending an Ext Class
Extending and Customizing Ext classes is easy
Goal: Create a extension of BasicDialog
New class DefaultDialog which extends from
BasicDialog
Provide a set of defaults for dialogs
modal, width, height, shadow, draggable, etc
No need to add/override methods to BasicDialog
Extending an Ext class
var DefaultDialog = function(config) {
var config = config || {}; // default config to blank object
var defConfig = {title: 'Default', // provide a default config
height: 130,
width: 250,
shadow: true,
modal: true,
draggable:true,
fixedcenter:true,
collapsible: false,
closable: true,
resizable:false};
Ext.applyIf(config, defConfig); // apply defConfig IF config does not have property
var el = Ext.DomHelper.append(document.body, {tag: 'div'}); // create el
DefaultDialog.superclass.constructor.call(this, el, config); // run superclass
};
Ext.extend(DefaultDialog, Ext.BasicDialog); // DefaultDialog extends Ext.BasicDialog
DefaultDialog example
We can now re-use the DefaultDialog class
By passing configuration options we can override the defaults
By omitting the configuration, we assume the defaults
dlg = new DefaultDialog({title: 'First Dialog', width: 300});
dlg.show();
dlg2 = new DefaultDialog();
dlg2.show();
ExtJS Events
Events
Events describe when a certain action
happens. This could be a user action, a
response to an Ajax call, etc.
Events also provide us with some information
about what occurred via arguments
Events
The DOM model describes numerous events which
may occur to an HTMLElement.
Such as:
mousedown
mouseover
click
select
blur
focus
change
http://www.w3.org/TR/DOM-Level-2-Events/events.html
Event Registration
Please avoid DOM level 0 event registration by
NOT placing your event handlers in-line
<a href= onclick=return myFunction()>link</a>
Event handling like this has been deprecated
for some time and using it in dynamic
applications may cause memory leaks!
Event-handling
ExtJS normalizes event-handling differences
across the browsers.
To add an event handler to an event we use
the following syntax.
Ext.fly(myElement).on(click, myFunction, scope);
Main Website
http://www.sencha.com/
Learning EXT JS
http://www.sencha.com/learn/Ext_Getting_Started
EXT JS Download
http://www.sencha.com/products/extjs/download/
EXT JS Samples
http://dev.sencha.com/deploy/dev/examples/
Girish Srivastava
[email protected]
171 29-08-2017