Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Active input widget is now even more abstract

  • Loading branch information...
commit 2c408d895e99abe69692befdcc7289aee26b8899 1 parent 791ff3b
@jonnymind jonnymind authored
View
17 frameworks/nest/nest.fal
@@ -251,6 +251,9 @@ object Nest
/*# For now, use the max authlevel by default. */
auth_level = AuthLevel.ADMIN
+ /*# Script that should be executed at the end of the page. */
+ closingScript = ""
+
/*# Function called back after routing and before routed page execution.
This is the ideal place to put code that must be always executed.
@@ -1348,6 +1351,9 @@ object Nest
// render the slices requiring rendering.
self._renderSlices()
+ // render the closeScripts
+ self._renderClosingScript()
+
// finalize services
self._finalizeServices()
@@ -1408,6 +1414,17 @@ object Nest
end
end
+ function _renderClosingScript()
+ if self.closingScript
+ self.logi( "Rendering closing script -- generating" )
+ self._contentSlices += "<script language=\"javascript\">\n(function(){\n" +
+ self.closingScript +
+ "\n}());\n</script>"
+ else
+ self.logi( "Rendering closing script -- skipping" )
+ end
+ end
+
function _packSlices()
self.logi( "Packing data slices" )
View
95 frameworks/nest/nest/widgets/ActiveInput.fal
@@ -0,0 +1,95 @@
+/*
+ FALCON - The Falcon Programming Language
+
+ Nest - Falcon web applcation engine
+
+ FILE: ActiveInput.fal
+
+ AJAX widgeting subsystem -- Text input Widget exciting msg and AJAX
+ -------------------------------------------------------------------
+ Author: Giancarlo Niccolai
+ Begin: Mon, 26 Sep 2011 11:55:58 +0200
+
+ -------------------------------------------------------------------
+ (C) Copyright 2011: the FALCON developers (see list in AUTHORS file)
+
+ See LICENSE file for licensing details.
+*/
+
+import InputText from nest.widgets.InputText as InputText
+
+/*# Class dispatching local messages and/or AJAX messages on text change.
+
+ Might be a text (default) or a textarea (if its tag is changed into
+ textarea) field that can send a 'change' message to local listeners
+ and to ajax listeners.
+*/
+class ActiveInput( id, prompt ) from InputText( id, prompt )
+
+ //# Timeout before starting to check updates
+ typeTimeout = 0
+
+ //# if true (default), sends a local message on change.
+ checkLocal = true
+
+ //# if true (default is false), sends an ajax message on change.
+ checkAjax = false
+
+ //# code used to prevent generating local messages.
+ localFilter = nil
+
+ //# code used to prevent generating ajax messages.
+ ajaxFilter = nil
+
+ init
+ self.props += [
+ "onchange" => "this.onActiveChange();",
+ "onkeyup" => "this.onActiveChange();"
+ ]
+ end
+
+ function onRender()
+
+ // create the onChange callback with preliminary check (if not changed, do nothing).
+ checkFunc = "function() { if(this.oldValue == this.value) {return;}\n"
+
+ if self.checkLocal
+ if self.localFilter
+ checkFunc += "if( " + self.localFilter + ") { return; }\n"
+ end
+
+ // This is the message for the listener widgets.
+ checkFunc += self.makeMessage( 'change', 'this.value' ) + "\n"
+ end
+
+ if self.checkAjax
+ if self.ajaxFilter
+ checkFunc += "if( " + self.ajaxFilter + ") { return; }\n"
+ end
+
+ // This is the message for the listener widgets.
+ checkFunc += self.ajaxMsg( 'change', ['value'] ) + "\n"
+ end
+
+ checkFunc += "this.oldValue = this.value; }\n"
+
+ self.jsMethods = [
+ "activeCheck" => checkFunc
+ ]
+
+ if self.typeTimeout
+ self.jsMethods[ "onActiveChange" ] = "
+ function() {
+ if( this.timeoutVar ) { clearTimeout( this.timeoutVar ); }
+ this.timeoutVar = setTimeout('document.getElementById(\"' +this.id + '\").activeCheck()', " +
+ self.typeTimeout + ");}"
+ else
+ self.jsMethods[ "onActiveChange" ] = "
+ function() { this.activeCheck(); }"
+ end
+
+ self.onCreate = "document.getElementById(\""+ self.getFullID() +"\").activeCheck()"
+ end
+end
+
+/* end of ActiveInput.fal */
View
39 frameworks/nest/nest/widgets/ActiveTextArea.fal
@@ -0,0 +1,39 @@
+/*
+ FALCON - The Falcon Programming Language
+
+ Nest - Falcon web applcation engine
+
+ FILE: ActiveTextArea.fal
+
+ AJAX widgeting subsystem -- Textarea Widget exciting msg and AJAX
+ -------------------------------------------------------------------
+ Author: Giancarlo Niccolai
+ Begin: Mon, 26 Sep 2011 11:55:58 +0200
+
+ -------------------------------------------------------------------
+ (C) Copyright 2011: the FALCON developers (see list in AUTHORS file)
+
+ See LICENSE file for licensing details.
+*/
+
+import ActiveInput from nest.widgets.ActiveInput as ActiveInput
+
+/*# Class dispatching local messages and/or AJAX messages on text change.
+
+ Might be a text (default) or a textarea (if its tag is changed into
+ textarea) field that can send a 'change' message to local listeners
+ and to ajax listeners.
+*/
+class ActiveTextArea( id, prompt, rows, cols ) from ActiveInput( id, prompt )
+ tag = "textarea"
+ isSelfClosing = false
+
+ init
+ if rows and cols
+ self.props["rows"] = rows
+ self.props["cols"] = cols
+ end
+ end
+end
+
+/* end of ActiveInput.fal */
View
2  frameworks/nest/nest/widgets/InputText.fal
@@ -3,7 +3,7 @@
Nest - Falcon web applcation engine
- FILE: text.fal
+ FILE: InputText.fal
AJAX widgeting subsystem -- input field.
-------------------------------------------------------------------
View
59 frameworks/nest/nest/widgets/NameWithAvail.fal
@@ -18,6 +18,7 @@
import from nest.widgets.widget in widget
import InputText from nest.widgets.InputText as InputText
+import ActiveInput from nest.widgets.ActiveInput as ActiveInput
import Image from nest.widgets.Image as Image
@@ -123,9 +124,10 @@ class AvailWidget( id, name_wid ) from widget.Widget( id )
self.addChild( self.img_wid )
self.addChild( self.status_wid )
end
-
end
+
+
/*# Class checking for a name to be available.
*/
class NameWithAvail( id, prompt ) from InputText( id, prompt )
@@ -133,20 +135,17 @@ class NameWithAvail( id, prompt ) from InputText( id, prompt )
isAJAXHost = true
initInfos = [id, prompt]
- //# Minimum size for a name
minSize = 6
-
- //# Timeout before starting to check for the name.
- typeTimeout = 250
- name_wid = InputText( "name", prompt )
+ name_wid = ActiveInput( "name", prompt )
avail_wid = AvailWidget( "avail", self.name_wid )
name_checked = widget.Widget( "name_checked" )
-
init
self.name_checked.tag = "input"
self.name_checked.props = ["type" => "hidden"]
+ self.name_wid.typeTimeout = 250
+ self.name_wid.checkAjax = true
self.addChild( self.name_wid )
self.addChild( self.avail_wid )
@@ -172,7 +171,7 @@ class NameWithAvail( id, prompt ) from InputText( id, prompt )
iwid = self.avail_wid.img_wid
if self.checkAvail( name )
return [
- swid.msgInvoke( "setAvailable", ["avail"=>true, "again"=>"test"] ),
+ swid.msgInvoke( "setAvailable", ["avail"=>true] ),
iwid.msgInvoke( "setAvailable", ["avail"=>true] ),
self.name_checked.msgSetProperty( "value", "checked" ) ]
else
@@ -186,48 +185,8 @@ class NameWithAvail( id, prompt ) from InputText( id, prompt )
function onRender()
// force the input widget to be posted with OUR name in forms.
- self.name_wid.props = [
- "name" => self.getFullID(),
- "onchange" => "this.onChange();",
- "onkeyup" => "this.onChange();"
- ]
-
- // The prefix function posts the data value to the listeners and prevents calling ajax if name is too short.
- changeMsg = self.name_wid.makeMessage( 'value', 'this.value' )
- ajaxMsg = self.name_wid.ajaxMsg( 'change', ['value'] )
- checkFunc = @'
- function() {
- if(this.oldValue == this.value) {return;}
- $(changeMsg)
- if(this.value.length < $(self.minSize) ) {return;}
- this.oldValue = this.value;
- $(ajaxMsg)
- }'
-
- self.name_wid.jsMethods = [
- "onChange" => "
- function() {
- if( this.timeoutVar ) { clearTimeout( this.timeoutVar ); }
- this.timeoutVar = setTimeout('document.getElementById(\"' +this.id + '\").checkName()', " +
- self.typeTimeout + ");}",
-
- "checkName" => checkFunc
- ]
-
-
-
-
- // add the same request for onchange and onkeyup in our name widget.
- /*
- checkValueReq = widget.AJAXRequest( ["value"], nil, prefixFunc )
- self.name_wid.ajaxReqs = [
- //"onfocus"=> checkValueReq,
- "onchange"=> checkValueReq,
- "onkeyup"=> checkValueReq
- ]
- */
-
- self.name_wid.onCreate = "document.getElementById(\""+ self.name_wid.getFullID() +"\").checkName()"
+ self.name_wid.props["name"] = self.getFullID();
+ self.name_wid.ajaxFilter = @"this.value.length < $(self.minSize)"
end
/*# Overridable Method checking for availability of a name.
View
33 frameworks/nest/nest/widgets/Text.fal
@@ -0,0 +1,33 @@
+/*
+ FALCON - The Falcon Programming Language
+
+ Nest - Falcon web applcation engine
+
+ FILE: Text.fal
+
+ AJAX widgeting subsystem -- Simple text/label widget (span).
+ -------------------------------------------------------------------
+ Author: Giancarlo Niccolai
+ Begin: Mon, 26 Sep 2011 11:55:58 +0200
+
+ -------------------------------------------------------------------
+ (C) Copyright 2011: the FALCON developers (see list in AUTHORS file)
+
+ See LICENSE file for licensing details.
+*/
+
+import from nest.widgets.widget in widget
+
+class Text( id, deftext ) from widget.Widget( id )
+ tag = "span"
+ defText = deftext ? deftext : ""
+
+ init
+ if self.props == nil: self.props = [=>]
+ end
+
+ function renderContent()
+ return self.defText
+ end
+end
+
View
2  frameworks/nest/nest/widgets/widget.fal
@@ -197,7 +197,7 @@ class Widget( id )
if self.onCreate
rend += "element.onCreate = function(){" + self.onCreate +";}\n"
- rend += "element.onCreate();"
+ Nest.closingScript += "document.getElementById('" + self.getFullID() + "').onCreate();\n"
end
if rend
View
14 tests/frameworks/nest/widgets/nest/pages/home.ftd
@@ -33,8 +33,22 @@
<hr>
<p>Nest AJAX enabled widget test.</p>
<?= Nest.widget( "HashMaker" )("hm").render() ?>
+
<hr>
+<p>Basic widgets with local page messaging: Type some text and see the count change.</p>
+<?
+ wid = Nest.widget( "ActiveTextArea" )("enter_text", "Enter text", 3, 30)
+
+ widtext = Nest.widget("Text")("counter","0")
+ widtext.jsListeners = [
+ wid => " function( source, msg, value ) { this.innerHTML = value.length; }"
+ ]
+?>
+<p><?= wid.render() ?></p>
+<p>Lenght of the text: <span style="color:red"><?=widtext.render() ?></span></p>
+
+<hr>
<p>Advanced widgets with local page messaging</p>
<?= Nest.widget( "RichPassword" )("my_password", "Enter password", "Repeat password").render() ?>
<hr>
View
3  tests/frameworks/nest/widgets/nest/widgets/TheNameIsAvail.fal
@@ -2,6 +2,7 @@
import from nest.widgets.NameWithAvail in na
class TheNameIsAvail() from na.NameWithAvail( "the_name", "Enter a name" )
+
minSize = 4
takenNames = [
@@ -13,7 +14,7 @@ class TheNameIsAvail() from na.NameWithAvail( "the_name", "Enter a name" )
"gian",
"stan"
]
-
+
function checkAvail( name )
return name notin self.takenNames
end
Please sign in to comment.
Something went wrong with that request. Please try again.