Index: openacs-4/contrib/packages/bcms-ui-base/resources/file-form.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/bcms-ui-base/resources/file-form.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/contrib/packages/bcms-ui-base/resources/file-form.tcl 9 Oct 2003 09:58:21 -0000 1.2 +++ openacs-4/contrib/packages/bcms-ui-base/resources/file-form.tcl 27 Oct 2003 10:17:21 -0000 1.3 @@ -1,77 +1,43 @@ -ad_page_contract { - a form to create or edit a file +# this file is meant to be included with the following parameters +# +# folder_id - if you are creating a new file +# revision_id - if you are editing a file 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" - this file is meant to be included with the following parameters +bcms::ui::base::check_include_vars - folder_id - if you are creating a new file - file_id - if you are creating a new revision of a file - revision_id - if you are editing a file revision - return_url - requires a return_url, so after creating or editing a folder it redirect to this url - -} { - {file_name:optional ""} -} - -# check if the parameters exists and set them to their defaults -if {![info exists folder_id]} { - if {![info exists file_id] && ![info exists revision_id]} { - error "folder_id does not exists, please pass in the folder_id if you are creating a new file" - } - set folder_id "" -} -if {![info exists file_id]} { - if {![info exists folder_id] && ![info exists revision_id]} { - error "file_id does not exists, please pass in the file_id if you are creating a new revision" - } - set file_id "" -} - -# lets get an existing file with name $file_name -if {![string equal $file_name ""]} { - array set existing_file [bcms::item::get_item_by_url -root_id $folder_id -url $file_name] -} - -ad_form -name simpleform -html {enctype multipart/form-data} -form { +ad_form -name simpleform -mode $form_mode -html {enctype multipart/form-data} -form { revision_id:key -} -if {![string equal $folder_id ""] || [info exists revision_id]} { - ad_form -extend -name simpleform -form { - {file_name:text(text) {help_text {no spaces, no special characters}} {label "File Name"}} - } -validate { - {file_name - {([array size existing_file] == 0) || ([info exists file_id] && ($existing_file(item_id) == $file_id))} - "File Name already exists,
please use another File Name" - } - } -} - -ad_form -extend -name simpleform -form { - + {name:text(text) {help_text {no spaces, no special characters}} {label "File Name"}} {title:text(text) {label "Title"}} {description:text(textarea),optional {html {rows 5 cols 80}} {label "Description"}} {upload_file:file(file),optional {label "File"}} {folder_id:integer(hidden),optional {value $folder_id}} - {file_id:integer(hidden),optional {value $file_id}} + {item_id:integer(hidden),optional {value $item_id}} {return_url:text(hidden) {value $return_url}} } -validate { - # require file only we are uploading a new file, otherwise it ok to just edit the other fields {upload_file {!$__new_p || [exists_and_not_null upload_file]} + # require file only we are uploading a new file, otherwise it ok to just edit the other fields "File is required" } + {name + {![bcms::item::is_item_duplicate_p -url $name -root_id $folder_id -item_id $item_id]} + "File Name already exists,
please use another File Name" + } } -edit_request { array set one_revision [bcms::revision::get_revision -revision_id $revision_id] - set file_id $one_revision(item_id) - set file_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 file_id file_name title content description - } -edit_data { if {[exists_and_not_null upload_file]} { @@ -81,27 +47,17 @@ bcms::revision::set_revision -revision_id $revision_id \ -title $title -description $description } - if {[info exists file_name]} { - bcms::item::set_item -item_id $file_id -name $file_name + if {[info exists name]} { + bcms::item::set_item -item_id $item_id -name $name # we have renamed the file, we need to redirect on the new name - set path [ns_set get [lindex [bcms::item::get_item_path -item_id $file_id -prepend_path [ad_conn package_url] -return_list -no_parent] 1] path] - ad_returnredirect $path + bcms::ui::base::redirect_after_rename -item_id $item_id } } -new_data { - if {![string equal $file_id ""]} { - # just create the revision the file is existing -# set revision_id [bcms::revision::add_revision -item_id $file_id \ -# -title $title -content $content -description $description \ -# -mime_type "text/html"] - } elseif {![string equal $folder_id ""] && ![string equal $file_name ""]} { - # if the file does not exists, create the file and revision - set file_id [bcms::upload_file -file_name $file_name -folder_id $folder_id \ - -title $title -description $description -upload_file $upload_file] - } else { - ns_log notice "bcms: file not created" - } + # create the file and revision + set item_id [bcms::upload_file -file_name $name -folder_id $folder_id \ + -title $title -description $description -upload_file $upload_file] } -after_submit {