new ludo.View(config)
A basic ludoJS view. When rendered on a Web page, a View is made out of two <div> elements, one parent and one child(called body).
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
config |
Object |
Properties
|
Fires:
- ludo.View#rendered Fired when the view has been rendered and resized. Argument: ludo.event:View
- ludo.View#toFront Fired when view has brought to front. Argument: ludo.event:View
- ludo.View#hide Fired when view has been hidden using the hide method. Argument: ludo.event:View
- ludo.View#show Fired when view is displayed using the show method. Argument. ludo.event:View
- ludo.View#beforeshow Fired just before a view is displayed using the show method. Argument: ludo.event:View
- ludo.View#event:resize Fired when a view has been resized.
Examples
<!-- A basic rendered ludoJS view --> <div class="ludo-view"> <div class="ludo-body"></div> </div>
// Example 1: View render to <body> tag new ludo.View({ renderTo:document.body, html : 'Hello' } // Example 2: Creating custom View myApp = {}; myApp.View = new Class({ Extends: ludo.View, type : 'myApp.View', __rendered:function(){ this.html('My custom view'); } } children:[{ type : 'myApp.View' }]
Extends
Methods
-
__children() → {Array|children}
-
Alternative to the "children" config array. By defining children in __children, you will have access to "this" referring to
the View instance. This is a method you override when creating your own Views.Returns:
- Type
- Array | children
-
__construct(config)
-
Constructor for Views.
Parameters:
Name Type Description config
Object -
__rendered()
-
The final life cycle method. When this method is executed, the view (including child views)
are fully rendered. -
addChild(insertAt, pos) → {View}
-
Add a child View. The method will returned the created view.
Parameters:
Name Type Description child.
Object | View A Child object can be a View or a JSON config object for a new View.
insertAt
String pos
String Returns:
child
- Type
- View
-
addChildren(children) → {Array}
-
Add child components
Only param is an array of child objects. A Child object can be a component or a JSON object describing the component.Parameters:
Name Type Description children
Array Returns:
of new children
- Type
- Array
-
addControllerEvents()
-
Add events to controller
- Inherited From:
- Source:
Returns:
void
Example
this.controller.addEvent('eventname', this.methodName.bind(this));
-
getAllChildren()
-
Return Array of child views, recursive.
Returns:
Array of sub components
-
getChild(childName)
-
Get child view by name or id
Parameters:
Name Type Description childName
String id or name of child view
-
getChildren()
-
Return Array of direct child views.
Returns:
Array of Child components
-
getEl() → {HTMLElement}
-
Return reference to the Views DOM div element.
DOM "body" elementReturns:
DOMElement
- Type
- HTMLElement
-
getForm *() → {ludo.form.Manager}
-
Returns
ludo.form.Manager"
for this view.Returns:
- Type
- ludo.form.Manager
Examples
view.getForm().reset(); to reset all form fields
view.getForm().save(); to submit the form
view.getForm().read(1); to send a read request to the server for record with id 1.
-
getHeight() → {Number}
-
Get current height of component
Returns:
- Type
- Number
-
getId()
-
Return id of component
- Inherited From:
- Source:
Returns:
String id
-
getName()
-
Get name of component and form element
- Inherited From:
- Source:
Returns:
String name
-
getNamespace() → {String}
-
Returns component type minus class name, example:
type: calendar.View will return "calendar"- Inherited From:
- Source:
Returns:
namespace
- Type
- String
-
getParent() → {Object}
-
Get reference to parent view
Returns:
view | null
- Type
- Object
-
getTitle()
-
Returns title
Returns:
string
-
getWidth() → {Number}
-
Returns total width of component including padding, borders and margins
Returns:
width
- Type
- Number
-
hasChildren() → {Boolean}
-
Returns true if this component contain any children
Returns:
- Type
- Boolean
-
html(html) → {string}
-
Set HTML
Parameters:
Name Type Description html
Returns:
- Type
- string
Example
var view = new ludo.View({ renderTo:document.body, layout:{ width:500,height:500 } }); view.html('<h1>Heading</h1><p>Paragraph</p>');
-
isHidden() → {Boolean}
-
Is this component hidden?
Returns:
- Type
- Boolean
-
isVisible() → {Boolean}
-
Return true if this component is visible
Returns:
- Type
- Boolean
-
JSON(json, tpl)
-
Parse and insert JSON into the view
The JSON will be sent to the JSON parser(defined in JSONParser) and
This method will be called automatically when you're using a JSON data-sourceParameters:
Name Type Description json
Object tpl
String Optional String template
Returns:
void
-
load()
-
Load content from the server. This method will send an Ajax request to the server
using the data sourceReturns:
void
-
remove()
-
Hide and removes the view view
Returns:
void
-
resize(size)
-
Resize View and it's children.
Parameters:
Name Type Description size
Object Object with optional width and height properties. Example: { width: 200, height: 100 }
Example
view.resize( { width: 200, height:200 } );
-
saveState()
-
Save state for stateful components and views. States are stored in localStorage which
is supported by all major browsers(IE from version 8).- Inherited From:
- Source:
Returns:
void
Examples
myComponent.saveState(); OR
this.fireEvent('state'); which does the same.
-
setTitle(title)
-
Set new title
Parameters:
Name Type Description title
String -
show(skipEvents)
-
Make the view visible
Parameters:
Name Type Description skipEvents
Boolean Returns:
void
-
showChild(key) → {Boolean}
-
Call show() method of a child component
key must be id or name of childParameters:
Name Type Description key
String Returns:
success
- Type
- Boolean
-
svg() → {ludo.svg.Canvas}
-
Creates(if not exists) SVG surface and returns it. The SVG element is appended to the body of
the view.Returns:
canvas
- Type
- ludo.svg.Canvas
Example
var win = new ludo.Window({ id:'myWindow', left:50, top:50, width:410, height:490, title:'Canvas', css:{ 'background-color':'#FFF' } }); // Get reference to canvas var canvas = win.svg(); // Using the svg dollar function to create SVG DOM nodes. var circle = canvas.$('circle', { cx:100,cy:100, r: 50, fill: "#000" }); canvas.append(circle);