Index: openacs-4/packages/xowiki/tcl/yui-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/yui-procs.tcl,v diff -u -N -r1.5 -r1.6 --- openacs-4/packages/xowiki/tcl/yui-procs.tcl 22 Jul 2015 08:41:21 -0000 1.5 +++ openacs-4/packages/xowiki/tcl/yui-procs.tcl 7 Aug 2017 23:48:31 -0000 1.6 @@ -74,6 +74,7 @@ http://developer.yahoo.com/yui/menu/ } { my append CSSclass " yuimenu" + my set extrajs "" # I want the menu to show up when JS is disabled # This gets overridden by JS, so its only relevant for the non-JS version @@ -109,12 +110,19 @@ # JavaScript # only "root-level" menus need JS # TODO: is this parent-check sufficient / future-safe? - if {![my exists __parent]} { - html::script -type "text/javascript" { + if {[my exists __parent]} { + # + # propagate extrajs from rendering + # + #ns_log notice "### propagate extrajs <[my set extrajs]> from [my info class] to [[my set __parent] info class]" + [my set __parent] append extrajs [my set extrajs] + } else { + html::script -nonce [security::csp::nonce] -type "text/javascript" { html::t "var [my js_name] = new YAHOO.widget.Menu(\"[my id]\", [my set configuration]);" html::t " [my js_name].render(); [my js_name].show(); + [my set extrajs] " } } @@ -135,6 +143,15 @@ html::li [my get_attributes id {CSSclass class} style] { # if we have no href, mark entry as disabled if {![my exists href] || [my href] eq ""} {my append linkclass " disabled"} + if {[my exists listener] && [my set listener] ne ""} { + #ns_log notice "menuitem has id [my id] listener [my listener] parent [my set __parent] [[my set __parent] info class]" + lassign [my listener] type body + [my set __parent] append extrajs [subst { + document.getElementById('[my id]').addEventListener('$type', function (event) { + $body; + }, false); + }] + } html::a [my get_attributes target href {linkclass class} title] { html::t [my text] if {[my exists helptext]} { @@ -163,6 +180,7 @@ MenuBar looks best without a header and with one MenuItemList only } { my append CSSclass " yuimenubar" + my set extrajs "" if {[my navbar]} {my append CSSclass " yuimenubarnav"} html::div [my get_attributes id {CSSclass class}] { html::div -class "bd" { @@ -177,6 +195,7 @@ ::xo::Page requireJS "YAHOO.util.Event.onDOMReady(function () { var [my js_name] = new YAHOO.widget.MenuBar('[my id]', [my set configuration]); [my js_name].render(); + [my set extrajs] });" } } @@ -197,7 +216,18 @@ } } - + YUIMenuBarItem ad_instproc render {} {} { + my set extrajs "" + set result [next] + if {[my exists __parent]} { + # + # propagate extrajs from rendering + # + #ns_log notice "### propagate extrajs <[my set extrajs]> from [my info class] to [[my set __parent] info class]" + [my set __parent] append extrajs [my set extrajs] + } + } + # # YUIContextMenu # @@ -221,7 +251,7 @@ foreach li [my children] {$li render} } } - html::script -type "text/javascript" { + html::script -nonce [security::csp::nonce] -type "text/javascript" { html::t "var [my js_name] = new YAHOO.widget.ContextMenu('[my id]', { trigger: '[my set trigger]' } );" html::t "[my js_name].render(document.body);" } @@ -234,28 +264,26 @@ ::xo::tdom::Class create YUIContextMenuItem \ -superclass YUIMenuItem - - ::xowiki::MenuBar instproc render-yui {} { - set M [my content] - set mb [::xowiki::YUIMenuBar -id [my get_prop $M id] -configuration { + set dict [my content] + set mb [::xowiki::YUIMenuBar -id [my get_prop $dict id] -configuration { {autosubmenudisplay: false, keepopen: true, lazyload: false} } { - foreach {menu_att menu} $M { + foreach {menu_att menu} $dict { if {$menu_att eq "id"} continue - if {[llength $menu_att] > 1} { - # We expect a dict as second list element.. but ignore here for the time being - lassign $menu_att menu_att props - } - ::xowiki::YUIMenuBarItem -text [my get_prop $menu text] { + set kind [my get_prop $menu kind] + #ns_log notice "entry: kind $kind <$menu_att> <$menu>" + + if {$kind ne "MenuButton"} continue + ::xowiki::YUIMenuBarItem -text [my get_prop $menu label] { ::xowiki::YUIMenu { foreach {item_att item} $menu { if {[string match {[a-z]*} $item_att]} continue - set text [my get_prop $item text] - set url [my get_prop $item url] - set group [my get_prop $item group] - #my msg "ia=$item_att group '$group' // t=$text item=$item" - ::xowiki::YUIMenuItem -text $text -href $url -group $group {} + ::xowiki::YUIMenuItem \ + -text [my get_prop $item label] \ + -href [my get_prop $item url] \ + -group [my get_prop $item group] \ + -listener [my get_prop $item listener] {} } } } @@ -318,7 +346,7 @@ menubar { # # We should not have two different versions of the YUI - # library on one page, because YUI2 (afaik) doesnt support + # library on one page, because YUI2 (afaik) doesn't support # "sandboxing". If we use e.g. the yui-hosted utilities.js file here # we may end up with two YAHOO object definitions, because e.g. # the tree-procs uses the local yahoo-dom-event. @@ -465,7 +493,7 @@ set datasource ${id}_datasource set datatable ${id}_datatable set coldef ${id}_coldef - + set finaljs "" set js "var $datasource = new YAHOO.util.DataSource(YAHOO.util.Dom.get('$id')); \n" append js "$datasource.responseType = YAHOO.util.DataSource.TYPE_HTMLTABLE; \n" append js "$datasource.responseSchema = \{ \n" @@ -482,8 +510,17 @@ if {[$field hide]} continue if {[$field istype HiddenField]} continue if {[$field istype BulkAction]} { - set label "" + set subid [::xowiki::Includelet html_id $field] + set label "" + if {[info exists ::__csrf_token]} { + append label "" + } set sortable false + append finaljs [subst { + document.getElementById('$subid').addEventListener('click', function (event) { + acs_ListCheckAll('objects', this.checked); + }, false); + }] } else { set label [lang::util::localize [$field label]] set sortable [expr {[$field exists sortable] ? [$field set sortable] : true}] @@ -492,6 +529,7 @@ } append js [join $js_fields ", "] "\];\n" append js "var $datatable = new YAHOO.widget.DataTable('$container', $coldef, $datasource);\n" + append js $finaljs return $js }