Index: openacs-4/packages/ajaxhelper/tcl/ajax-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/ajaxhelper/tcl/ajax-procs.tcl,v
diff -u -r1.8 -r1.9
--- openacs-4/packages/ajaxhelper/tcl/ajax-procs.tcl 14 Jun 2007 11:40:42 -0000 1.8
+++ openacs-4/packages/ajaxhelper/tcl/ajax-procs.tcl 8 Sep 2007 14:21:22 -0000 1.9
@@ -10,182 +10,68 @@
# ********* Loading Sources **********
-ad_proc -private ah::load_js_sources {
- -source_list
+ad_proc -private ah::requires {
+ -sources
} {
- Accepts a tcl list of sources to load.
- This source_list will be the global ajax_helper_js_sources variable.
- This script is called in the blank-master template and
- should preferrably NOT BE USED to load your
- javascript sources. Use ah::js_sources instead.
+ This proc should be called by an ajaxhelper proc with a comma separated list of javascript sources
+ that the ajaxhelper proc needs in order to work.
@author Hamilton Chua (ham@solutiongrove.com)
- @creation-date 2006-11-05
- @param source_list The list of javascript source names to load
+ @creation-date 2006-12-19
+ @param sources Comma separated list of sources
} {
- set ah_base_url [ah::get_url]
- set script ""
+ #split up the comma delimited sources into a list
+ set source_list [split $sources ","]
+
+ set ah_base_url [ah::get_url]
+ set script ""
set minsuffix ""
if { [parameter::get_from_package_key -package_key "ajaxhelper" -parameter "UseMinifiedJs"] == 1 } {
set minsuffix "-min"
}
- # TODO : 12/19/06
- # Prior to just loading, we also have to think about dependencies
- # we might need to sort the source_list first and check for dependencies.
- # For example, we need to load prototype first before scriptaculous.
-
- foreach source $source_list {
+ foreach source $source_list {
switch $source {
"rounder" {
- append script " \n"
+ template::head::add_javascript -src "${ah_base_url}curvycorners/rounded_corners_lite.inc.js"
}
"overlibmws" {
- append script " \n"
+ template::head::add_javascript -src "${ah_base_url}overlibmws/overlibmws${minsuffix}.js"
}
"overlibmws_bubble" {
- append script "\n"
- append script "\n"
+ template::head::add_javascript -order 1 -src "${ah_base_url}overlibmws/overlibmws${minsuffix}.js"
+ template::head::add_javascript -order 2 -script "var OLbubbleImageDir=\"${ah_base_url}overlibmws\";"
+ template::head::add_javascript -order 3 -src "${ah_base_url}overlibmws/overlibmws_bubble${minsuffix}.js"
}
"overlibmws_scroll" {
- append script "\n"
+ template::head::add_javascript -order 1 -src "${ah_base_url}overlibmws/overlibmws${minsuffix}.js"
+ template::head::add_javascript -order 2 -src "${ah_base_url}overlibmws/overlibmws_scroll${minsuffix}.js"
}
"overlibmws_drag" {
- append script "\n"
+ template::head::add_javascript -src -order 1 "${ah_base_url}overlibmws/overlibmws${minsuffix}.js"
+ template::head::add_javascript -src -order 2 "${ah_base_url}overlibmws/overlibmws_draggable${minsuffix}.js"
}
"prototype" {
- append script " \n"
+ template::head::add_javascript -src "${ah_base_url}prototype/prototype${minsuffix}.js"
}
"scriptaculous" {
- append script " \n"
+ template::head::add_javascript -order 1 -src "${ah_base_url}prototype/prototype${minsuffix}.js"
+ template::head::add_javascript -order 2 -src "${ah_base_url}scriptaculous/scriptaculous.js"
}
- "scriptaculous-effects" {
- append script " \n"
- }
- "scriptaculous-dragdrop" {
- append script " \n"
- }
"autosuggest" {
- append script "\n"
- append script " \n"
+ template::head::add_javascript -order 1 -src "${ah_base_url}prototype/prototype${minsuffix}.js"
+ template::head::add_javascript -order 2 -src "${ah_base_url}autosuggest/autosuggest.js"
+ template::head::add_css -href "${ah_base_url}autosuggest/autosuggest.css"
}
}
- }
- return $script
-}
-
-ad_proc -private ah::is_valid_source {
- -js_source
-} {
- This proc will determine if the js_source file is the name is a valid name associated to
- a javascript source. This proc contains hard coded list of javascript sources that
- ajaxhelper supports.
-
- @author Hamilton Chua (ham@solutiongrove.com)
- @creation-date 2006-12-19
- @param js_source The name of the javascript source to check
-} {
-
- set valid_sources [list "prototype" \
- "scriptaculous" \
- "scriptaculous-effects" \
- "scriptaculous-dragdrop" \
- "autosuggest" \
- "rounder" \
- "overlibmws" \
- "overlibmws_bubble" \
- "overlibmws_scroll" \
- "overlibmws_drag" ]
- set found [lsearch -exact $valid_sources $js_source]
- if { $found == -1 } {
- return 0
- } else {
- return 1
}
}
-ad_proc -private ah::is_js_sources_loaded {
- -js_source
-} {
- This proc will loop thru source_list global variable and
- check for the presence of the specified js_source.
- If found, this proc will return 1
- If not found, this proc will return 0
-
- @author Hamilton Chua (ham@solutiongrove.com)
- @creation-date 2006-11-05
- @param js_source The name of the javascript source to check
-} {
- global ajax_helper_js_sources
- set state 0
- if { [info exists ajax_helper_js_sources] } {
- foreach source $ajax_helper_js_sources {
- if { [string match $source $js_source] } {
- set state 1
- break
- }
- }
- }
- return $state
-}
-
-ad_proc -private ah::requires {
- -sources
-} {
- This proc should be called by an ajaxhelper proc with a comma separated list of 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_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 scriptaculous, scriptaculous-effects or scriptaculous-dragdrop
- if { ![ah::is_js_sources_loaded -js_source $source] && [ah::is_valid_source -js_source $source] } {
- if { $source == "scriptaculous" || $source == "scriptaculous-effects" || $source == "scriptaculous-dragdrop" } {
- # source is scriptaculous
- # load only if scriptaculous-effects and scriptaculous-dragdrop are not loaded yet
- if { $source == "scriptaculous" } {
- if { ![ah::is_js_sources_loaded -js_source "scriptaculous-effects"] || ![ah::is_js_sources_loaded -js_source "scriptaculous-dragdrop"]} {
- lappend ajax_helper_js_sources $source
- }
- }
- # source is scriptaculous-effects
- # load only if scriptaculous and scriptaculous-dragdrop are not loaded yet
- if { $source == "scriptaculous-effects" } {
- if { ![ah::is_js_sources_loaded -js_source "scriptaculous"] || ![ah::is_js_sources_loaded -js_source "scriptaculous-dragdrop"]} {
- lappend ajax_helper_js_sources $source
- }
- }
- # source is scriptaculous-dragdrop
- # load only if scriptaculous and scriptaculous-effects are not loaded yet
- if { $source == "scriptaculous-dragdrop" } {
- if { ![ah::is_js_sources_loaded -js_source "scriptaculous"] || ![ah::is_js_sources_loaded -js_source "scriptaculous-effects"]} {
- lappend ajax_helper_js_sources $source
- }
- }
- } else {
- lappend ajax_helper_js_sources $source
- }
- } else {
- # TODO : we must return an error/exception, for now just add a notice in the log
- # Maltes: ACtually you should do nothing, otherwise you cannot call this procedure in helper procedures
- # Which may or may not be called multiple times on a page.
- ns_log Debug "AJAXHELPER : $source is already loaded or not valid"
- }
- }
-}
-
ad_proc -public ah::js_sources {
{-source "default"}
} {
+ DEPRECATED. Use ah::requires instead.
+
Will load any of the following javascript sources
prototype,
scriptaculous,
@@ -210,8 +96,6 @@
"overlibmws_drag" : to load the overlibmws javascript files for draggable dhtml callouts and popups.
"prototype" : to load ONLY the prototype javascript source.
"scriptaculous" : to load all scriptaculous javascript sources.
- "scriptaculous-effects" : to load only the scriptaculous javascript sources needed for effects.
- "scriptaculous-dragdrop" : to load only the scriptaculous javascript sources needed for drag and drop.
@return
@error
@@ -229,17 +113,15 @@
if { $source == "default" } {
if { ![ah::is_js_sources_loaded -js_source "prototype"] } {
# load prototype
- append script " \n"
+ template::head::add_javascript -src "${ah_base_url}prototype/prototype${minsuffix}.js"
# make sure helper procs don't load it again
lappend ajax_helper_js_sources "prototype"
}
- if { ![ah::is_js_sources_loaded -js_source "scriptaculous"] && ![ah::is_js_sources_loaded -js_source "scriptaculous-effects"] && ![ah::is_js_sources_loaded -js_source "scriptaculous-dragdrop"]} {
+ if { ![ah::is_js_sources_loaded -js_source "scriptaculous"] } {
# load scriptaculous
- append script " \n"
+ template::head::add_javascript -src "${ah_base_url}scriptaculous/scriptaculous${minsuffix}.js"
# make sure it doesn't get loaded again
lappend ajax_helper_js_sources "scriptaculous"
- lappend ajax_helper_js_sources "scriptaculous-dragdrop"
- lappend ajax_helper_js_sources "scriptaculous-effects"
}
}
@@ -249,57 +131,47 @@
switch $x {
"rounder" {
if { ![ah::is_js_sources_loaded -js_source "rounder"] } {
- append script " \n"
+ template::head::add_javascript -src "${ah_base_url}curvycorners/rounded_corners_lite.inc.js"
}
}
"overlibmws" {
if { ![ah::is_js_sources_loaded -js_source "overlibmws"] } {
- append script " \n"
- append script "\n"
+ template::head::add_javascript -src "${ah_base_url}overlibmws/overlibmws${minsuffix}.js"
+ template::head::add_javascript -src "${ah_base_url}overlibmws/overlibmws_overtwo${minsuffix}.js"
}
}
"overlibmws_bubble" {
if { ![ah::is_js_sources_loaded -js_source "overlibmws_bubble"] } {
- append script "\n"
- append script "\n"
+ template::head::add_javascript -script "var OLbubbleImageDir=\"${ah_base_url}overlibmws\";"
+ template::head::add_javascript -src "${ah_base_url}overlibmws/overlibmws_bubble${minsuffix}.js"
}
}
"overlibmws_scroll" {
if { ![ah::is_js_sources_loaded -js_source "overlibmws_scroll"] } {
- append script "\n"
+ template::head::add_javascript -src "${ah_base_url}overlibmws/overlibmws_scroll${minsuffix}.js"
}
}
"overlibmws_drag" {
if { ![ah::is_js_sources_loaded -js_source "overlibmws_drag"] } {
- append script "\n"
+ template::head::add_javascript -src "${ah_base_url}overlibmws/overlibmws_draggable${minsuffix}.js"
}
}
"prototype" {
if { ![ah::is_js_sources_loaded -js_source "prototype"] } {
- append script " \n"
+ template::head::add_javascript -src "${ah_base_url}prototype/prototype${minsuffix}.js"
}
}
- "autosuggest" {
- if { ![ah::is_js_sources_loaded -js_source "autosuggest"] } {
- append script "\n"
- append script " \n"
- }
- }
"scriptaculous" {
if { ![ah::is_js_sources_loaded -js_source "scriptaculous"] } {
- append script " \n"
+ template::head::add_javascript -src "${ah_base_url}scriptaculous/scriptaculous${minsuffix}.js"
}
}
- "scriptaculous-effects" {
- if { ![ah::is_js_sources_loaded -js_source "scriptaculous-effects"] } {
- append script " \n"
+ "autosuggest" {
+ if { ![ah::is_js_sources_loaded -js_source "autosuggest"] } {
+ template::head::add_javascript -src "${ah_base_url}autosuggest/autosuggest.js"
+ template::head::add_css -href "${ah_base_url}autosuggest/autosuggest.css"
}
}
- "scriptaculous-dragdrop" {
- if { ![ah::is_js_sources_loaded -js_source "scriptaculous-dragdrop"] } {
- append script " \n"
- }
- }
}
}
@@ -308,6 +180,30 @@
# ********* UTILS ************
+ad_proc -public ah::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 -private ah::get_package_id {
} {
@@ -369,7 +265,7 @@
ad_proc -public ah::create_js_function {
-body:required
- {-name ""}
+ {-name ""}
{-parameters {} }
} {
Helper procedure to generate a javascript function
@@ -382,9 +278,7 @@
} {
set script "function ${name} ("
if { [exists_and_not_null parameters] } { append script [join $parameters ","] }
- append script ") \{ "
- append script $body
- append script " \} "
+ append script ") \{ $body \}"
return $script
}
@@ -401,11 +295,9 @@
@param text What you want to insert.
@param position Where you want to insert text. This is case sensitive. Possible values include After, Bottom, Before and Top. Defaults to After.
} {
- if { ![ah::is_js_sources_loaded -js_source "prototype"] } {
- global ajax_helper_js_sources
- lappend ajax_helper_js_sources "prototype"
- }
+ ah::requires -sources "prototype"
+
set script "new Insertion.${position}('${element}','${text}'); "
return $script
}
@@ -430,7 +322,7 @@
@param obs_function the funcion that will be executed when the event is detected
} {
- ah::requires -sources "prototype"
+ ah::requires -sources "prototype"
if { !$element_is_var_p } {
set element [ah::isnot_js_var $element]
@@ -526,6 +418,7 @@
@param asynchronous the default is true
} {
+
ah::requires -sources "prototype"
set preoptions "asynchronous:${asynchronous},method:'post'"
@@ -580,7 +473,7 @@
@error
} {
- ah::requires -sources "prototype,scriptaculous-effects"
+ ah::requires -sources "scriptaculous"
if { !$container_is_var_p } {
set container [ah::isnot_js_var $container]
@@ -686,7 +579,7 @@
} {
- ah::requires -sources "overlibmws,overlibmws_bubble"
+ ah::requires -sources "overlibmws_bubble"
set script "onmouseover=\""
append script [ah::popup -content "'$text'" -options "BUBBLE,BUBBLETYPE,'$type',TEXTSIZE,'$textsize'"]
@@ -719,7 +612,7 @@
@error
} {
- ah::requires -sources "overlibmws,overlibmws_bubble"
+ ah::requires -sources "overlibmws_bubble"
set popup [ah::popup -content "t.responseText" -options "BUBBLE,BUBBLETYPE,'$type',TEXTSIZE,'$textsize'"]
set request [ah::ajaxrequest -url $url -pars '$pars' -options "onSuccess: function(t) { $popup }" ]
@@ -754,7 +647,7 @@
@error
} {
- ah::requires -sources "prototype,scriptaculous-effects"
+ ah::requires -sources "scriptaculous"
if { !$element_is_var_p } {
set element [ah::isnot_js_var $element]
@@ -786,7 +679,7 @@
@error
} {
- ah::requires -sources "prototype,scriptaculous-effects"
+ ah::requires -sources "scriptaculous"
if { !$element_is_var_p } {
set element [ah::isnot_js_var $element]
@@ -821,7 +714,7 @@
@error
} {
- ah::requires -sources "prototype,scriptaculous-dragdrop"
+ ah::requires -sources "scriptaculous"
if { !$element_is_var_p } {
set element [ah::isnot_js_var $element]
@@ -855,7 +748,7 @@
@error
} {
- ah::requires -sources "prototype,scriptaculous-dragdrop"
+ ah::requires -sources "scriptaculous"
if { !$element_is_var_p } {
set element [ah::isnot_js_var $element]
@@ -886,7 +779,7 @@
} {
- ah::requires -sources "prototype,scriptaculous-dragdrop"
+ ah::requires -sources "scriptaculous"
if { !$element_is_var_p } {
set element [ah::isnot_js_var $element]
@@ -918,7 +811,7 @@
} {
- ah::requires -sources "prototype,scriptaculous-dragdrop"
+ ah::requires -sources "scriptaculous"
if { !$element_is_var_p } {
set element [ah::isnot_js_var $element]
@@ -990,7 +883,7 @@
} {
- ah::requires -sources "prototype,autosuggest"
+ ah::requires -sources "autosuggest"
if {[llength $array_list]} {
set suggestion_list $array_list
@@ -1044,4 +937,4 @@
return $suggestions_stub
-}
+}
\ No newline at end of file