# -*- Tcl -*- ######################################################################## # Workflow for editing test items # =============================== # # This workflow 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 [_ xowf.Fresh_item_type_interaction_name \ [list item_type $item_type name $name]] } } Action save -next_state created -label #xowiki.Form-submit_button# Action preview -next_state created -label #xowf.Preview# -proc activate {obj} { # # The action preview renders the current test-item (question, # exercise, ...) the same as if it was shown in an quiz/exam. The # preview 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 preview} State created \ -actions {save preview} \ -in_role swa { -actions {save view preview} } :proc item_type {obj} { set item_type [$obj property item_type] if {$item_type eq ""} { set item_type [ns_queryget p.item_type] # validate item_type set item_types {} foreach class [::xowiki::formfield::TestItemField info subclass -closure] { if {[$class exists item_type]} { lappend item_types {*}[$class set item_type] } } if {$item_type eq "" || $item_type ni $item_types} { 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 preview} #${container}::created in_role swa { -actions {save view preview} } :proc render_icon {} { return [subst {text "#xowf.menu-New-Item-[:property item_type]Interaction#" is_richtext false}] } } # # Local variables: # mode: tcl # tcl-indent-level: 2 # indent-tabs-mode: nil # End: