Index: openacs-4/packages/ajaxhelper/tcl/ajax-dojo-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/ajaxhelper/tcl/ajax-dojo-procs.tcl,v
diff -u -r1.1 -r1.2
--- openacs-4/packages/ajaxhelper/tcl/ajax-dojo-procs.tcl 6 Nov 2006 13:15:29 -0000 1.1
+++ openacs-4/packages/ajaxhelper/tcl/ajax-dojo-procs.tcl 25 Dec 2006 16:39:50 -0000 1.2
@@ -16,12 +16,12 @@
This source_list will be the global ajax_helper_dojo_js_sources variable.
This script is called in the blank-master template.
- @author Hamilton Chua (ham@solutiongrove.com)
+ @author Hamilton Chua (ham@solutiongrove.com)
@creation-date 2006-11-05
} {
set ah_base_url [ah::get_url]
- set script ""
+ set script "\n"
set dojo_script ""
foreach source $source_list {
@@ -44,8 +44,10 @@
"lfx" {
append dojo_script "dojo.require(\"dojo.lfx.*\"); "
}
+ "collections" {
+ append dojo_script "dojo.require(\"dojo.collections.Store\"); "
+ }
"chart" {
- append dojo_script "dojo.require(\"dojo.collections.Store\"); "
append dojo_script "dojo.require(\"dojo.charting.Chart\"); "
}
"widget-chart" {
@@ -59,21 +61,50 @@
return ""
}
+ad_proc -private ah::dojo::requires {
+ -sources
+} {
+ This proc should be called by an ajaxhelper proc that uses dojo with a comma separated list of dojo javascript sources
+ that the ajaxhelper proc needs in order to work.
+
+ @author Hamilton Chua (ham@solutiongrove.com)
+ @creation-date 2006-12-19
+ @param sources Comma separated list of sources
+} {
+ #split up the comma delimited sources into a list
+ set source_list [split $sources ","]
+ #declare the global variable
+ global ajax_helper_dojo_js_sources
+ foreach source $source_list {
+ # do some checks before we add the source to the global
+ # - is it already loaded
+ # - is it a valid source name
+ # - is the source utilities or yahoo,dom,event
+ if { ![ah::dojo::is_js_sources_loaded -js_source $source] && [ah::dojo::is_valid_source -js_source $source] } {
+ # TODO : figure out other dependencies and possible overlaps and try to work them out here
+ lappend ajax_helper_dojo_js_sources $source
+ } else {
+ # TODO : we must return an error/exception, for now just add a notice in the log
+ ns_log Notice "AJAXHELPER dojo: $source is already loaded or not valid"
+ }
+ }
+}
+
ad_proc -private ah::dojo::is_js_sources_loaded {
-js_source
} {
This proc will loops thru source_list and check for the presence of js_source.
- If found, this proc will return 1
+ If found, this proc will return 1
If not found, this proc will return 0
- @author Hamilton Chua (ham@solutiongrove.com)
+ @author Hamilton Chua (ham@solutiongrove.com)
@creation-date 2006-11-05
} {
global ajax_helper_dojo_js_sources
set state 0
if { [info exists ajax_helper_dojo_js_sources] } {
foreach source $ajax_helper_dojo_js_sources {
- if { [string match $source $js_source] } {
+ if { [string match $source $js_source] } {
set state 1
break
}
@@ -87,7 +118,7 @@
} {
Generates the javascript that loads the dojo javascript sources.
- @author Hamilton Chua (ham@solutiongrove.com)
+ @author Hamilton Chua (ham@solutiongrove.com)
@creation-date 2006-11-05
} {
@@ -129,9 +160,13 @@
append dojo_script "dojo.require(\"dojo.lfx.*\"); "
}
}
+ "collections" {
+ if { ![ah::dojo::is_js_sources_loaded -js_source "collections"] } {
+ append dojo_script "dojo.require(\"dojo.collections.Store\"); "
+ }
+ }
"chart" {
if { ![ah::dojo::is_js_sources_loaded -js_source "chart"] } {
- append dojo_script "dojo.require(\"dojo.collections.Store\"); "
append dojo_script "dojo.require(\"dojo.charting.Chart\"); "
}
}
@@ -151,37 +186,88 @@
-argslist:required
} {
Builds a javascript object that holds the arguments that are commonly passed to a dojo function.
-
- @author Hamilton Chua (ham@solutiongrove.com)
+
+ @author Hamilton Chua (ham@solutiongrove.com)
@creation-date 2006-11-05
-} {
+} {
set objargs [list]
foreach args $argslist {
- lappend objargs [split ":" $args]
+ lappend objargs [join $args ":"]
}
- set objargs [split "," $objargs]
+ set objargs [join $objargs ","]
set script "var $varname = {$objargs}; "
return $script
}
ad_proc -public ah::dojo::iobind {
-objargs:required
} {
- Generates the javascript that loads the dojo javascript sources.
+ Generates the javascript for a dojo io bind.
+ Does the same thing as ah::ajaxrequest or ah::ajaxupdate
+ but is more robust as dojo.io.bind is capable of using
+ different transport layers. In fact, it's smart enough to determine
+ which transport layer to use given a certain situation without bothering
+ the developer. More details in the dojo book.
+ http://manual.dojotoolkit.org/WikiHome/DojoDotBook/Book8
- @author Hamilton Chua (ham@solutiongrove.com)
+ @author Hamilton Chua (ham@solutiongrove.com)
@creation-date 2006-11-05
@param objargs A javascript object generated by ah::dojo::args which contain arguments that is passed to dojo.io.bind.
} {
- if { ![ah::dojo::is_js_sources_loaded -js_source "dojo"] } {
- global ajax_helper_dojo_js_sources
- lappend ajax_helper_dojo_js_sources "dojo"
- if { ![ah::dojo::is_js_sources_loaded -js_source "io"] } {
- lappend ajax_helper_dojo_js_sources "io"
- }
- }
+ ah::dojo::requires -sources "dojo,io"
set script "dojo.io.bind($objargs); "
return $script
-}
\ No newline at end of file
+}
+
+ad_proc -public ah::dojo::util_list_to_json {
+ -lists_of_pairs
+} {
+ Converts a properly structured list of lists into JSON format.
+ The list of lists may look something like
+
+ set data [list]
+ lappend data [list [list "x" "1"] [list "y" "10"] ]
+ lappend data [list [list "x" "5"] [list "y" "20"] ]
+
+ each line represents a row composed of lists.
+ Each list in the row holds a pair that will be joined by ":".
+} {
+ set rows [list]
+ foreach row $lists_of_pairs {
+ set pairs [list]
+ foreach pair $row {
+ lappend pairs [join $pair ":"]
+ }
+ lappend rows [join $pairs ","]
+ }
+ return "\{[join $rows "\},\{"]\}"
+}
+
+ad_proc -public ah::dojo::collections_store {
+ -varname:required
+ -lists_of_pairs:required
+} {
+ Creates a dojo collection store
+} {
+ ah::dojo::requires -sources "dojo,collections"
+ set json [ah::dojo::util_list_to_json -lists_of_pairs $lists_of_pairs]
+ set script "var ${varname}_data = \[$json\]; \n"
+ append script "var ${varname} = new dojo.collections.Store(); ${varname}.setData(${varname}_data); \n"
+ return $script
+}
+
+ad_proc -public ah::dojo::chart {
+ -varname:required
+ -node:required
+ -datalist
+ -serieslist
+ -axislist
+ -plotlist
+ -onload:boolean
+} {
+ Creates a chart using the dojo charting engine
+} {
+ ah::dojo::requires -sources "dojo,chart"
+}