Index: openacs-4/contrib/packages/bcms-ui-base/resources/template-form.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/bcms-ui-base/resources/template-form.tcl,v diff -u -N -r1.1 -r1.2 --- openacs-4/contrib/packages/bcms-ui-base/resources/template-form.tcl 27 Aug 2003 17:33:49 -0000 1.1 +++ openacs-4/contrib/packages/bcms-ui-base/resources/template-form.tcl 27 Oct 2003 10:17:21 -0000 1.2 @@ -1,92 +1,69 @@ -ad_page_contract { - a form to create or edit a tempalte +# this file is meant to be included with the following parameters - this file is meant to be included with the following parameters +# folder_id - if you are creating a new template +# revision_id - if you are editing a template revision +# return_url - requires a return_url, so after creating or editing a folder it redirect to this url +# form_mode - either "edit" or "display" - folder_id - if you are creating a new template - template_id - if you are creating a new revision of a template - revision_id - if you are editing a template revision - return_url - requires a return_url, so after creating or editing a folder it redirect to this url +bcms::ui::base::check_include_vars -} { - {template_name:optional ""} +set cms_context [parameter::get -parameter cms_context -default ""] +if {[string equal $cms_context ""]} { + error "no cms context defined" } -# check if the parameters exists and set them to their defaults -if {![info exists folder_id]} { - if {![info exists template_id] && ![info exists revision_id]} { - error "folder_id does not exists, please pass in the folder_id if you are creating a new tempate" - } - set folder_id "" -} -if {![info exists template_id]} { - if {![info exists folder_id] && ![info exists revision_id]} { - error "template_id does not exists, please pass in the template_id if you are creating a new revision" - } - set template_id "" -} - -# lets get an existing template with name $template_name -if {![string equal $template_name ""]} { - array set existing_template [bcms::item::get_item_by_url -root_id $folder_id -url $template_name] -} - -ad_form -name simpleform -form { +ad_form -name simpleform -mode $form_mode -form { revision_id:key -} -if {![string equal $folder_id ""]} { - ad_form -extend -name simpleform -form { - {template_name:text(text) {label "Template Name"}} - } -validate { - {template_name - {([array size existing_template] == 0) || ([info exists template_id] && ($existing_template(item_id) == $template_id))} - "Template Name already exists,
please use another Template Name" - } - } -} - - -ad_form -extend -name simpleform -form { - + {name:text(text) {label "Template Name"}} {title:text(text) {label "Title"}} {description:text(textarea),optional {html {rows 5 cols 80}} {label "Description"}} {content:text(textarea),optional {html {rows 20 cols 80}} {label "Template Content"}} {folder_id:integer(hidden),optional {value $folder_id}} - {template_id:integer(hidden),optional {value $template_id}} + {item_id:integer(hidden),optional {value $item_id}} {return_url:text(hidden) {value $return_url}} +} -validate { + {name + {![bcms::item::is_item_duplicate_p -url $name -root_id $folder_id -item_id $item_id]} + "Template Name already exists,
please use another Template Name" + } } -edit_request { array set one_revision [bcms::revision::get_revision -revision_id $revision_id] - set template_id $one_revision(item_id) - set template_name $one_revision(name) + set item_id $one_revision(item_id) + set name $one_revision(name) set title $one_revision(title) - set content $one_revision(content) set description $one_revision(description) + set folder_id $one_revision(parent_id) - ad_set_form_values template_id template_name title content description + set template_filename "[acs_root_dir]/templates/${cms_context}/${name}.adp" + # read the file contents from the file system + if {[file exists $template_filename]} { + set content [template::util::read_file $template_filename] + } else { + set content $one_revision(content) + } } -edit_data { bcms::revision::set_revision -revision_id $revision_id \ -title $title -content $content -description $description + array set template [bcms::item::get_item -item_id $item_id] + + if {![empty_string_p $template(live_revision)]} { + set template_filename "[acs_root_dir]/templates/${cms_context}/${name}.adp" + template::util::write_file $template_filename $content + } + } -new_data { - if {![string equal $template_id ""]} { - # just create the revision the template is existing - set revision_id [bcms::template::add_template -template_id $template_id \ + # create the template and revision + db_transaction { + set item_id [bcms::template::create_template -template_name $name -parent_id $folder_id] + set revision_id [bcms::template::add_template -template_id $item_id \ -title $title -content $content -description $description] - } elseif {![string equal $folder_id ""] && ![string equal $template_name ""]} { - # if the template does not exists, create the template and revision - db_transaction { - set template_id [bcms::template::create_template -template_name $template_name -parent_id $folder_id] - set revision_id [bcms::template::add_template -template_id $template_id \ - -title $title -content $content -description $description] - } - } else { - ns_log notice "bcms: template not created" } } -after_submit {