# -*- Tcl -*- ######################################################################## # Workflow for editing test items # =============================== # # This worflow can be used edit test items of different types, # where the type of the item can be provided via a query parameter. # See e.g.: # # {entry -name New.Item.TextInteraction -form en:edit-interaction.wf -query p.item_type=Text} # set :policy ::xowf::test_item::test-item-policy-edit Action initialize -proc activate {obj} { set name [$obj name] if {[$obj is_new_entry $name]} { set container [[$obj wf_context] wf_container] set item_type [$container item_type $obj] $obj title "Fresh '$item_type' interaction ($name)" } } Action save -next_state created -label #xowiki.Form-submit_button# Action tryout -next_state created -label #xowf.Preview# -proc activate {obj} { # # The action tryout renders the current test-item (question, # exercise, ...) the same was as it is shown in an quiz/exam. The # tryout action uses the workflow "en:answer-single-question.wf" for # rendering it. The instance for filling out the question is created # as a child object of the test-item. # set package_id [$obj package_id] set wf [$package_id instantiate_forms \ -forms en:answer-single-question.wf \ -default_lang en \ -parent_id [$obj parent_id]] # # Call "create-or-use" on the current item and provide the # parent_id. # set url [export_vars -base [$wf pretty_link] { {m create-or-use} {p.return_url "[::xo::cc url]"} {title "[$obj title]"} {parent_id "[$obj item_id]" } }] # # For launching the URL we have two options: # # (a) just render it, and potentially forget the last edit # operations of the user (same as "view" above) # # ad_returnredirect $url # ad_script_abort # # (b) save page first (like usual workflow options) and call then # the try-out page. # set current_return_url [::xo::cc query_parameter return_url [ad_return_url]] $obj set instance_attributes \ [dict merge [$obj set instance_attributes] [list return_url $current_return_url]] ::xo::cc set_query_parameter return_url $url } Action view -label #xowiki.view# -proc activate {obj} { set url [export_vars -base [$obj pretty_link] { {m view} {p.return_url "[::xo::cc url]"} }] ad_returnredirect $url ad_script_abort } State initial -actions {save tryout} State created \ -actions {save tryout} \ -in_role swa { -actions {save view tryout} } :proc item_type {obj} { set item_type [$obj property item_type] if {$item_type eq ""} { set item_type [ns_queryget p.item_type] if {$item_type eq ""} {set item_type ShortText} $obj set_property -new 1 item_type $item_type } return $item_type } :proc form_name_from_item_type {obj} { return en:TestItem[:item_type $obj].form } :object-specific { set container [[:wf_context] wf_container] set form_name [${container} form_name_from_item_type [self]] ${container}::initial form $form_name ${container}::created form $form_name ${container}::created actions {save tryout} #${container}::created in_role swa { -actions {save view tryout} } } # # Local variables: # mode: tcl # tcl-indent-level: 2 # indent-tabs-mode: nil # End: