Index: openacs-4/packages/acs-object-management/sql/postgresql/acs-templating-changes-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-object-management/sql/postgresql/acs-templating-changes-create.sql,v diff -u -r1.3 -r1.4 --- openacs-4/packages/acs-object-management/sql/postgresql/acs-templating-changes-create.sql 22 Dec 2009 19:59:15 -0000 1.3 +++ openacs-4/packages/acs-object-management/sql/postgresql/acs-templating-changes-create.sql 2 Jan 2010 14:03:59 -0000 1.4 @@ -179,7 +179,7 @@ insert into acs_form_widget_params (param_id, widget, param, required_p, html_p, tcl_allowed_p, default_value) values - (40, 'radio', 'options', 't', 'f', 't', null); + (40, 'radio', 'options', 't', 'f', 't', '{ -- {} }'); insert into acs_form_widget_params (param_id, widget, param, required_p, html_p, tcl_allowed_p, default_value) @@ -192,7 +192,7 @@ insert into acs_form_widget_params (param_id, widget, param, required_p, html_p, tcl_allowed_p, default_value) values - (50, 'checkbox', 'options', 't', 'f', 't', null); + (50, 'checkbox', 'options', 't', 'f', 't', '{ -- {} }'); insert into acs_form_widget_params (param_id, widget, param, required_p, html_p, tcl_allowed_p, default_value) @@ -223,7 +223,7 @@ insert into acs_form_widget_params (param_id, widget, param, required_p, html_p, tcl_allowed_p, default_value) values - (80, 'multiselect', 'options', 't', 'f', 't', null); + (80, 'multiselect', 'options', 't', 'f', 't', '{ -- {} }'); insert into acs_form_widget_params (param_id, widget, param, required_p, html_p, tcl_allowed_p, default_value) @@ -664,4 +664,29 @@ values ('text','search'); + insert into acs_form_allowable_widgets + (datatype, widget) + values + ('string','radio'); + + insert into acs_form_allowable_widgets + (datatype, widget) + values + ('string','checkbox'); + + insert into acs_form_allowable_widgets + (datatype, widget) + values + ('string','select'); + + insert into acs_form_allowable_widgets + (datatype, widget) + values + ('string','multiselect'); + + insert into acs_form_allowable_widgets + (datatype, widget) + values + ('string','search'); + end; \ No newline at end of file Index: openacs-4/packages/acs-object-management/tcl/form-param-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-object-management/tcl/form-param-procs.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/acs-object-management/tcl/form-param-procs.tcl 2 Jan 2010 14:04:00 -0000 1.1 @@ -0,0 +1,12 @@ +ad_library { + procs to set form widget parameters: + value, options, values +} + +namespace eval form::param_procs {} + +ad_proc -private form::param_procs::example {} { + Example proc +} { + return {} +} Index: openacs-4/packages/acs-object-management/tcl/form-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-object-management/tcl/form-procs.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/packages/acs-object-management/tcl/form-procs.tcl 11 Dec 2009 00:19:09 -0000 1.2 +++ openacs-4/packages/acs-object-management/tcl/form-procs.tcl 2 Jan 2010 14:04:00 -0000 1.3 @@ -62,11 +62,15 @@ set html_params {} set params {} + db_foreach get_params {} { if { $html_p } { lappend html_params $param lappend html_params $value } else { + if {$param_source eq "eval"} { + set value [eval $value] + } lappend params [list $param $value] } } Index: openacs-4/packages/acs-object-management/tcl/form-procs.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-object-management/tcl/form-procs.xql,v diff -u -r1.3 -r1.4 --- openacs-4/packages/acs-object-management/tcl/form-procs.xql 22 Dec 2009 19:59:15 -0000 1.3 +++ openacs-4/packages/acs-object-management/tcl/form-procs.xql 2 Jan 2010 14:04:00 -0000 1.4 @@ -25,11 +25,19 @@ union select afwp2.param, afwp2.html_p, afwp2.default_value as value, '' as param_source from acs_form_widget_params afwp2 - where not exists (select 1 - from acs_view_attribute_widgets - where object_view = :object_view - and attribute_id = :attribute_id) + where afwp2.param_id not in (select avawp.param_id + from acs_view_attribute_widget_params avawp + where avawp.object_view = :object_view + and avawp.attribute_id = :attribute_id) and afwp2.default_value is not null + and afwp2.widget in (select afwp3.widget + from acs_view_attribute_widgets avaw2, + acs_view_attribute_widget_params avawp2, + acs_form_widget_params afwp3 + where afwp3.param_id = avawp2.param_id + and afwp3.widget = avaw2.widget + and avawp2.object_view = :object_view + and avawp2.attribute_id = :attribute_id) Index: openacs-4/packages/acs-object-management/www/admin/widget-add-edit-2.js =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-object-management/www/admin/widget-add-edit-2.js,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/acs-object-management/www/admin/widget-add-edit-2.js 2 Jan 2010 14:04:00 -0000 1.1 @@ -0,0 +1,20 @@ +function restrict_value_widget(param) { + eval('var el = document.widget_register.'+param+'_source;'); + for (i=0;i -1} { + set param_source_options {{#acs-object-management.literal# literal}} + if { $tcl_allowed_p } { + lappend param_source_options {#acs-object-management.tcl_proc# eval} + } ad_form -extend -name widget_register -form { - {${param}_source:text(radio) - {label {$param #acs-object-management.source#}} + {${param}_source:text(radio),optional + {label "$param #acs-object-management.source#"} {options $param_source_options} {value $param_source} + {html {id ${param}_source onClick restrict_value_widget('$param')}} + } + {${param}_literal:text(textarea),optional + {label "$param literal"} } + {${param}_eval:text(select),optional + {label "$param tcl proc"} + {options $param_procs} + } + } + } else { + ad_form -extend -name widget_register -form { + {${param}:text(textarea)$optional_flag} } } - ad_form -extend -name widget_register -form { - {${param}:text(textarea)$optional_flag {html {rows 6 cols 50}}} - } } + ad_form -extend -name widget_register -on_request { db_1row get_attr_info "" set object_view_pretty [lang::util::localize $object_view_pretty] set attribute_name_pretty [lang::util::localize $attribute_name_pretty] ad_set_form_values object_view_pretty attribute_name_pretty widget for { set i 1 } { $i <= [template::multirow size params] } { incr i } { - ad_set_element_value -element [template::multirow get params $i param] \ - [template::multirow get params $i value] + set param [template::multirow get params $i param] + set value [template::multirow get params $i value] + ad_set_element_value -element $param $value + if {[lsearch -exact {value values options} $param] > -1} { + set param_source [template::element::get_value widget_register ${param}_source] + if {$param_source eq "literal"} { + ad_set_element_value -element ${param}_literal $value + } else { + ad_set_element_value -element ${param}_eval $value + } + template::add_body_handler -event onload \ + -script restrict_value_widget('$param') + } } wizard submit widget_register -buttons { back next } } -on_submit { for { set i 1 } { $i <= [template::multirow size params] } { incr i } { - set param [template::multirow get params $i param] - set value [template::element::get_value widget_register [template::multirow get params $i param]] + set param [template::multirow get params $i param] set param_id [template::multirow get params $i param_id] set param_source literal if {[lsearch -exact {value values options} $param] > -1} { set param_source [template::element::get_value widget_register ${param}_source] + if {$param_source eq "literal"} { + set value [template::element::get_value widget_register ${param}_literal] + } else { + set value [template::element::get_value widget_register ${param}_eval] + } + } else { + set value [template::element::get_value widget_register [template::multirow get params $i param]] } if {$param_source eq "literal"} { # escape malicious characters set value [string map {$ \\$ [ \\[ ] \\] \\ \\\\} $value] - } + } if { $value eq "" } { object_view::attribute::widget::param::delete \ -object_view $object_view \ @@ -85,7 +121,9 @@ -value $value } } + wizard forward ad_script_abort } +template::head::add_javascript -src widget-add-edit-2.js \ No newline at end of file