Class ::Generic::Form (public)
::xotcl::Class ::Generic::Form
Defined in
- Testcases:
-
No testcase defined.
Source code:
namespace eval ::Generic {}
::nsf::object::alloc ::xotcl::Class ::Generic::Form {set :__default_metaclass ::xotcl::Class
set :__default_superclass ::xotcl::Object}
::Generic::Form instproc on_submit item_id {
:request write
foreach __var [:form_vars] {
${:data} set $__var [:var $__var]
}
${:data} initialize_loaded_object
}
::Generic::Form instproc request privilege {
if {[nsf::is object ::${:package_id}] && ![::${:package_id} exists policy]} {
auth::require_login
permission::require_permission -object_id ${:package_id} -privilege $privilege
}
set :edit_form_page_title [if {$privilege eq "create"} {:add_page_title} {:edit_page_title}]
set :context [list ${:edit_form_page_title}]
}
::Generic::Form instproc generate {{-template "formTemplate"} {-mode "edit"} -export} {
set :$template ${:name}
set object_type [[${:data} info class] object_type]
set object_name [expr {[${:data} exists name] ? [${:data} set name] : ""}]
set exports [list [list object_type $object_type] [list folder_id ${:folder_id}] [list __object_name [::security::parameter::signed $object_name]]]
if {[info exists export]} {
foreach pair $export {lappend exports $pair}
}
ad_form -name ${:name} -form ${:fields} -mode $mode -export $exports -action [:action] -html [:html]
set new_data "set item_id \[[self] new_data\]"
set edit_data "set item_id \[[self] edit_data\]"
set new_request "[self] new_request"
set edit_request "[self] edit_request \$item_id"
set after_submit "[self] after_submit \$item_id"
set on_validation_error "[self] on_validation_error"
set on_submit "[self] on_submit \$item_id"
if {[:with_categories]} {
set coid [expr {[${:data} exists item_id] ? [${:data} set item_id] : ""}]
category::ad_form::add_widgets -form_name ${:name} -container_object_id ${:package_id} -categorized_object_id $coid
append edit_request {
category::ad_form::fill_widgets -container_object_id ${:package_id} -categorized_object_id $item_id
}
append new_data {
category::map_object -remove_old -object_id $item_id $category_ids
}
append edit_data {
category::map_object -remove_old -object_id $item_id $category_ids
}
append on_submit {
set category_ids [category::ad_form::get_categories -container_object_id ${:package_id}]
}
}
ad_form -extend -name ${:name} -validate [:validate] -new_data "xo::dc transaction \{ $new_data \}" -edit_data "xo::dc transaction \{ $edit_data \}" -on_submit $on_submit -new_request $new_request -edit_request $edit_request -on_validation_error $on_validation_error -after_submit $after_submit
}
::Generic::Form instproc init {} {
set level [template::adp_level]
:forward var uplevel #$level set
if {${:package_id} eq ""} {
set :package_id [${:data} package_id]
}
if {${:folder_id} < 0} {
set :folder_id [expr {[${:data} exists parent_id] ? [${:data} parent_id] : [::${:package_id} folder_id]}]
}
set class [${:data} info class]
set :data_id [$class id_column]
if {![info exists :add_page_title]} {
set :add_page_title [_ xotcl-core.create_new_type [list type [$class pretty_name]]]
}
if {![info exists :edit_page_title]} {
set :edit_page_title [_ xotcl-core.edit_type [list type [$class pretty_name]]]
}
if {![info exists :fields]} {
:mkFields
}
}
::Generic::Form instproc on_validation_error {} {
set :edit_form_page_title [:edit_page_title]
set :context [list ${:edit_form_page_title}]
}
::Generic::Form instproc set_form_data {} {
foreach var [${:data} info vars] {
if {![${:data} array exists $var]} {
:var $var [list [${:data} set $var]]
}
}
if {[${:data} exists ${:data_id}]} {
${:data} set object_id [${:data} set ${:data_id}]
}
}
::Generic::Form instproc new_request {} {
:request create
:set_form_data
}
::Generic::Form instproc new_data {} {
${:data} save_new
return [${:data} set [:get_id_field]]
}
::Generic::Form instproc after_submit item_id {
set link [:submit_link]
if {$link eq "view"} {
set link [export_vars -base $link {item_id}]
}
ad_returnredirect $link
ad_script_abort
}
::Generic::Form instproc edit_request item_id {
:request write
:set_form_data
}
::Generic::Form instproc form_vars {} {
set vars [list]
foreach varspec ${:fields} {
lappend vars [lindex [split [lindex $varspec 0] :] 0]
}
return $vars
}
::Generic::Form instproc edit_data {} {
${:data} save
if {[${:data} istype ::xo::db::CrItem]} {
set old_name [::xo::cc form_parameter __object_name:signed,convert ""]
set new_name [${:data} set name]
if {$old_name ne $new_name} {
${:data} rename -old_name $old_name -new_name $new_name
set url [${:data} changed_redirect_url]
if {$url ne ""} {
:submit_link $url
}
} else {
}
}
return [${:data} set [:get_id_field]]
}
::Generic::Form instproc get_id_field {} {
if {[${:data} istype ::xo::db::CrItem]} {
return item_id
}
return object_id
}
::Generic::Form instparametercmd submit_link
::Generic::Form instparametercmd with_categories
::Generic::Form instparametercmd add_page_title
::Generic::Form instparametercmd package_id
::Generic::Form instparametercmd folder_id
::Generic::Form instparametercmd name
::Generic::Form instparametercmd data
::Generic::Form instparametercmd validate
::Generic::Form instparametercmd edit_page_title
::Generic::Form instparametercmd html
::Generic::Form instparametercmd action
::Generic::Form instparametercmd fields
::nx::slotObj -container slot ::Generic::Form
::Generic::Form::slot eval {set :__parameter {
fields
data
{package_id ""}
{folder_id -100}
{name {[namespace tail [self]]}}
add_page_title
edit_page_title
{validate ""}
{html ""}
{with_categories false}
{submit_link "."}
{action "[::xo::cc url]"}
}}
::nsf::object::alloc ::xotcl::Attribute ::Generic::Form::slot::add_page_title {set :accessor public
set :configurable true
set :convert false
set :defaultmethods {}
set :disposition alias
set :domain ::Generic::Form
set :incremental 0
set :manager ::Generic::Form::slot::add_page_title
set :methodname add_page_title
set :multiplicity 1..1
set :name add_page_title
set :per-object false
set :position 0
set :required false
set :trace none
: init}
::nsf::object::alloc ::xotcl::Attribute ::Generic::Form::slot::package_id {set :accessor public
set :configurable true
set :convert false
set :default {}
set :defaultmethods {}
set :disposition alias
set :domain ::Generic::Form
set :incremental 0
set :manager ::Generic::Form::slot::package_id
set :methodname package_id
set :multiplicity 1..1
set :name package_id
set :per-object false
set :position 0
set :required false
set :substdefault 0b111
set :trace none
: init}
::nsf::object::alloc ::xotcl::Attribute ::Generic::Form::slot::with_categories {set :accessor public
set :configurable true
set :convert false
set :default false
set :defaultmethods {}
set :disposition alias
set :domain ::Generic::Form
set :incremental 0
set :manager ::Generic::Form::slot::with_categories
set :methodname with_categories
set :multiplicity 1..1
set :name with_categories
set :per-object false
set :position 0
set :required false
set :substdefault 0b111
set :trace none
: init}
::nsf::object::alloc ::xotcl::Attribute ::Generic::Form::slot::submit_link {set :accessor public
set :configurable true
set :convert false
set :default .
set :defaultmethods {}
set :disposition alias
set :domain ::Generic::Form
set :incremental 0
set :manager ::Generic::Form::slot::submit_link
set :methodname submit_link
set :multiplicity 1..1
set :name submit_link
set :per-object false
set :position 0
set :required false
set :substdefault 0b111
set :trace none
: init}
::nsf::object::alloc ::xotcl::Attribute ::Generic::Form::slot::name {set :accessor public
set :configurable true
set :convert false
set :default {[namespace tail [self]]}
set :defaultmethods {}
set :disposition alias
set :domain ::Generic::Form
set :incremental 0
set :manager ::Generic::Form::slot::name
set :methodname name
set :multiplicity 1..1
set :name name
set :per-object false
set :position 0
set :required false
set :substdefault 0b111
set :trace none
: init}
::nsf::object::alloc ::xotcl::Attribute ::Generic::Form::slot::validate {set :accessor public
set :configurable true
set :convert false
set :default {}
set :defaultmethods {}
set :disposition alias
set :domain ::Generic::Form
set :incremental 0
set :manager ::Generic::Form::slot::validate
set :methodname validate
set :multiplicity 1..1
set :name validate
set :per-object false
set :position 0
set :required false
set :substdefault 0b111
set :trace none
: init}
::nsf::object::alloc ::xotcl::Attribute ::Generic::Form::slot::data {set :accessor public
set :configurable true
set :convert false
set :defaultmethods {}
set :disposition alias
set :domain ::Generic::Form
set :incremental 0
set :manager ::Generic::Form::slot::data
set :methodname data
set :multiplicity 1..1
set :name data
set :per-object false
set :position 0
set :required false
set :trace none
: init}
::nsf::object::alloc ::xotcl::Attribute ::Generic::Form::slot::html {set :accessor public
set :configurable true
set :convert false
set :default {}
set :defaultmethods {}
set :disposition alias
set :domain ::Generic::Form
set :incremental 0
set :manager ::Generic::Form::slot::html
set :methodname html
set :multiplicity 1..1
set :name html
set :per-object false
set :position 0
set :required false
set :substdefault 0b111
set :trace none
: init}
::nsf::object::alloc ::xotcl::Attribute ::Generic::Form::slot::action {set :accessor public
set :configurable true
set :convert false
set :default {[::xo::cc url]}
set :defaultmethods {}
set :disposition alias
set :domain ::Generic::Form
set :incremental 0
set :manager ::Generic::Form::slot::action
set :methodname action
set :multiplicity 1..1
set :name action
set :per-object false
set :position 0
set :required false
set :substdefault 0b111
set :trace none
: init}
::nsf::object::alloc ::xotcl::Attribute ::Generic::Form::slot::fields {set :accessor public
set :configurable true
set :convert false
set :defaultmethods {}
set :disposition alias
set :domain ::Generic::Form
set :incremental 0
set :manager ::Generic::Form::slot::fields
set :methodname fields
set :multiplicity 1..1
set :name fields
set :per-object false
set :position 0
set :required false
set :trace none
: init}
::nsf::object::alloc ::xotcl::Attribute ::Generic::Form::slot::folder_id {set :accessor public
set :configurable true
set :convert false
set :default -100
set :defaultmethods {}
set :disposition alias
set :domain ::Generic::Form
set :incremental 0
set :manager ::Generic::Form::slot::folder_id
set :methodname folder_id
set :multiplicity 1..1
set :name folder_id
set :per-object false
set :position 0
set :required false
set :substdefault 0b111
set :trace none
: init}
::nsf::object::alloc ::xotcl::Attribute ::Generic::Form::slot::edit_page_title {set :accessor public
set :configurable true
set :convert false
set :defaultmethods {}
set :disposition alias
set :domain ::Generic::Form
set :incremental 0
set :manager ::Generic::Form::slot::edit_page_title
set :methodname edit_page_title
set :multiplicity 1..1
set :name edit_page_title
set :per-object false
set :position 0
set :required false
set :trace none
: init}
XQL Not present:Generic, PostgreSQL, Oracle
[
hide source ]
| [
make this the default ]