Index: openacs-4/packages/ams/ams.info =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/ams.info,v diff -u -N -r1.2 -r1.3 --- openacs-4/packages/ams/ams.info 30 Oct 2004 00:23:54 -0000 1.2 +++ openacs-4/packages/ams/ams.info 18 May 2005 17:11:48 -0000 1.3 @@ -8,15 +8,14 @@ t ams - + Matthew Geddert Store attributes via the Content Repository, and auto generate input forms AMS (Attribute Management System) helps in customizing your website. It lets you adjust what information is collected and displayed for any package that is integrated with it. AMS allows you to easily and dynamically add attributes to forms and display pages, using a Tcl API or an admin interface. AMS uses the content repository to store attribute history for any object on the system. - + - Index: openacs-4/packages/ams/catalog/ams.en_US.ISO-8859-1.xml =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/catalog/ams.en_US.ISO-8859-1.xml,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ams/catalog/ams.en_US.ISO-8859-1.xml 18 May 2005 17:11:48 -0000 1.1 @@ -0,0 +1,262 @@ + + + + Address + Checkbox - Multiple Options Allowed + Country + Andorra + United Arab Emirates + Afghanistan + Antigua and Barbuda + Anguilla + Albania + Armenia + Netherlands Antilles + Angola + Antarctica + Argentina + American Samoa + Austria + Australia + Aruba + Azerbaijan + Bosnia and Herzegovina + Barbados + Bangladesh + Belgium + Burkina Faso + Bulgaria + Bahrain + Burundi + Benin + Bermuda + Brunei Darussalam + Bolivia + Brazil + Bahamas + Bhutan + Bouvet Island + Botswana + Belarus + Belize + Canada + Cocos (Keeling) Islands + Congo, The Democratic Republic of the + Central African Republic + Congo + Switzerland + Cote D'ivoire + Cook Islands + Chile + Cameroon + China + Colombia + Costa Rica + Cuba + Cape Verde + Christmas Island + Cyprus + Czech Republic + Germany + Djibouti + Denmark + Dominica + Dominican Republic + Algeria + Ecuador + Estonia + Egypt + Western Sahara + Eritrea + Spain + Ethiopia + Finland + Fiji + Falkland Islands (Malvinas) + Micronesia, Federated States of + Faroe Islands + France + Gabon + United Kingdom + Grenada + Georgia + French Guiana + Ghana + Gibraltar + Greenland + Gambia + Guinea + Guadeloupe + Equatorial Guinea + Greece + South Georgia and the South Sandwich Islands + Guatemala + Guam + Guinea-Bissau + Guyana + Hong Kong + Heard Island and Mcdonald Islands + Honduras + Croatia + Haiti + Hungary + Indonesia + Ireland + Israel + India + British Indian Ocean Territory + Iraq + Iran, Islamic Republic of + Iceland + Italy + Jamaica + Jordan + Japan + Kenya + Kyrgyzstan + Cambodia + Kiribati + Comoros + Saint Kitts and Nevis + Korea, Democratic People's Republic of + Korea, Republic of + Kuwait + Cayman Islands + Kazakstan + Lao People's Democratic Republic + Lebanon + Saint Lucia + Liechtenstein + Sri Lanka + Liberia + Lesotho + Lithuania + Luxembourg + Latvia + Libyan Arab Jamahiriya + Morocco + Monaco + Moldova, Republic of + Madagascar + Marshall Islands + Macedonia, The Former Yugoslav Republic of + Mali + Myanmar + Mongolia + Macau + Northern Mariana Islands + Martinique + Mauritania + Montserrat + Malta + Mauritius + Maldives + Malawi + Mexico + Malaysia + Mozambique + Namibia + New Caledonia + Niger + Norfolk Island + Nigeria + Nicaragua + Netherlands + Norway + Nepal + Nauru + Niue + New Zealand + Oman + Panama + Peru + French Polynesia + Papua New Guinea + Philippines + Pakistan + Poland + Saint Pierre and Miquelon + Pitcairn + Puerto Rico + Palestinian Territory, Occupied + Portugal + Palau + Paraguay + Qatar + Reunion + Romania + Russian Federation + Rwanda + Saudi Arabia + Solomon Islands + Seychelles + Sudan + Sweden + Singapore + Saint Helena + Slovenia + Svalbard and Jan Mayen + Slovakia + Sierra Leone + San Marino + Senegal + Somalia + Suriname + Sao Tome and Principe + El Salvador + Syrian Arab Republic + Swaziland + Turks and Caicos Islands + Chad + French Southern Territories + Togo + Thailand + Tajikistan + Tokelau + Turkmenistan + Tunisia + Tonga + East Timor + Turkey + Trinidad And Tobago + Tuvalu + Taiwan, Province of China + Tanzania, United Republic of + Ukraine + Uganda + United States Minor Outlying Islands + United States + Uruguay + Uzbekistan + Holy See (Vatican City State) + Saint Vincent and the Grenadines + Venezuela + Virgin Islands, British + Virgin Islands, U.S. + Viet Nam + Vanuatu + Wallis And Futuna + Samoa + Yemen + Mayotte + Yugoslavia + South Africa + Zambia + Zimbabwe + Date + Street + Email + Integer + Menu - Multiple Options Allowed + City + Zip/Postal Code + Radio Buttons - One Option Allowed + State/Province + Richtext + Drop Down List - One Option Allowed + Select One + Phone Number + Textarea + Textbox + Website Url + Index: openacs-4/packages/ams/sql/postgresql/ams-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/sql/postgresql/ams-create.sql,v diff -u -N -r1.4 -r1.5 --- openacs-4/packages/ams/sql/postgresql/ams-create.sql 30 Oct 2004 00:23:54 -0000 1.4 +++ openacs-4/packages/ams/sql/postgresql/ams-create.sql 18 May 2005 17:11:48 -0000 1.5 @@ -1,382 +1,475 @@ --- --- packages/ams/sql/postgresql/ams-create.sql --- --- @author Matthew Geddert openacs@geddert.com --- @creation-date 2004-09-07 --- @cvs-id $Id$ --- --- - - ------- Widgets --------------------------------------------------------------------- - -create table ams_storage_types ( - storage_type varchar(20) - constraint ams_storage_type_nn not null - constraint ams_storage_type_pk primary key -); - -create table ams_widgets ( - widget_name varchar(100) - constraint ams_widgets_name_pk primary key, - pretty_name varchar(100) - constraint ams_widgets_pretty_name_nn not null, - pretty_plural varchar(100) - constraint ams_widgets_pretty_plural_nn not null, - storage_type varchar(20) - constraint ams_widgets_storage_type_nn not null - constraint contact_widgets_storage_type_fk references ams_storage_types(storage_type), - acs_datatype varchar(50) - constraint ams_widgets_acs_datatype_nn not null - constraint ams_widgets_acs_datatype_fk references acs_datatypes(datatype), - widget varchar(20) - constraint ams_widgets_widget_nn not null, - datatype varchar(20) - constraint ams_widgets_datatype_nn not null, - parameters varchar(1000) -); - - - ------- Attributes --------------------------------------------------------------------- - -create table ams_attributes ( - ams_attribute_id integer - constraint ams_attributes_ams_attribute_id_fk references acs_objects(object_id) - constraint ams_attributes_ams_attribute_id_pk primary key, - attribute_id integer - constraint ams_attributes_attribute_id_fk references acs_attributes(attribute_id) - constraint ams_attributes_attribute_id_nn not null, - widget_name varchar(100) - constraint ams_attributes_widget_name_fk references ams_widgets(widget_name) - constraint ams_attributes_widget_name_nn not null, - deprecated_p boolean default 'f' - constraint ams_attributes_deprecated_nn not null -); - -select acs_object_type__create_type ( - 'ams_attribute', -- object_type - 'AMS Attribute', -- pretty_name - 'AMS Attributes ', -- pretty_plural - 'acs_object', -- supertype - 'ams_attributes', -- table_name - 'ams_attribute_id', -- id_column - 'ams_attribute', -- package_name - 'f', -- abstract_p - null, -- type_extension_table - 'ams_attribute__name' -- name_method -); - -select acs_attribute__create_attribute ( - 'ams_attribute', -- object_type - 'attribute_id', -- attribute_name - 'integer', -- datatype - 'ACS Attribute ID', -- pretty_name - 'ACS Attribute IDs', -- pretty_plural -- default null - null, -- table_name -- default null - 'attribute_id', -- column_name -- default null - null, -- default_value -- default null - '1', -- min_n_values -- default 1 - '1', -- max_n_values -- default 1 - null, -- sort_order -- default null - 'type_specific', -- storage -- default 'type_specific' - null -- static_p -- default 'f' -); - -select acs_attribute__create_attribute ( - 'ams_attribute', -- object_type - 'widget_name', -- attribute_name - 'string', -- datatype - 'Widget Name', -- pretty_name - 'Widget Name', -- pretty_plural -- default null - null, -- table_name -- default null - 'widget_name', -- column_name -- default null - null, -- default_value -- default null - '1', -- min_n_values -- default 1 - '1', -- max_n_values -- default 1 - null, -- sort_order -- default null - 'type_specific', -- storage -- default 'type_specific' - null -- static_p -- default 'f' -); - -select acs_attribute__create_attribute ( - 'ams_attribute', -- object_type - 'deprecated_p', -- attribute_name - 'boolean', -- datatype - 'Deprecated', -- pretty_name - 'Deprecated', -- pretty_plural -- default null - null, -- table_name -- default null - 'deprecated_p', -- column_name -- default null - null, -- default_value -- default null - '1', -- min_n_values -- default 1 - '1', -- max_n_values -- default 1 - null, -- sort_order -- default null - 'type_specific', -- storage -- default 'type_specific' - null -- static_p -- default 'f' -); - - ------- Objects --------------------------------------------------------------------- - --- In order to allow for an acs_object to become a cr_item --- we need to do a one to one cr_item to acs_object map. This --- allows for no content repository controlled acs_objects --- to get revisions, via their associated ams_object - -create table ams_objects ( - ams_object_id integer - constraint ams_objects_ams_object_id_fk references cr_items(item_id) on delete cascade - constraint ams_objects_ams_object_id_pk primary key, - object_id integer - constraint ams_object_revisions_object_id_fk references acs_objects(object_id) - constraint ams_object_revisions_object_id_nn not null, - unique(object_id) -); - -create table ams_object_revisions ( - ams_object_revision_id integer - constraint ams_object_revisions_revision_id_fk references cr_revisions(revision_id) on delete cascade - constraint ams_object_revisions_revision_id_pk primary key -); - --- create the CR content type - -select content_type__create_type ( - 'ams_object_revision', -- content_type - 'content_revision', -- supertype - 'AMS Object', -- pretty_name - 'AMS Objects', -- pretty_plural - 'ams_object_revisions', -- table_name - 'ams_object_revision_id', -- id_column - 'ams_object_revision__name' -- name_method -); - - - ------- Options --------------------------------------------------------------------- - - -create sequence ams_options_seq; -create table ams_options ( - option_id integer - constraint ams_options_option_id_nn not null - constraint ams_options_option_id_nn primary key, - ams_attribute_id integer - constraint ams_options_ams_attribute_id_nn not null - constraint ams_options_ams_attribute_id_nn references ams_attributes (ams_attribute_id), - option varchar(200) - constraint ams_options_option_nn not null, - sort_order integer - constraint ams_options_sort_order not null, - unique (ams_attribute_id,sort_order) -); - -create sequence ams_option_map_id_seq; -create table ams_option_map_ids ( - option_map_id integer - constraint ams_option_map_ids_option_map_id_pk primary key -); - -create table ams_option_map ( - option_map_id integer - constraint ams_option_map_option_map_id_nn not null - constraint ams_option_map_option_map_id_fk references ams_option_map_ids(option_map_id), - option_id integer - constraint ams_option_map_option_id_fk references ams_options(option_id) - constraint ams_option_map_option_id_nn not null -); - - - ------- Attribute Values --------------------------------------------------------------------- - - - -create table ams_attribute_values ( - revision_id integer - constraint ams_attribute_values_revision_id_fk references cr_revisions(revision_id) - constraint ams_attribute_values_revision_id_nn not null, - superseed_revision_id integer - constraint ams_attribute_values_superseed_revision_id_fk references cr_revisions(revision_id), - ams_attribute_id integer - constraint ams_attribute_values_ams_attribute_id_fk references ams_attributes(ams_attribute_id) - constraint ams_attribute_values_ams_attribute_id_nn not null, - option_map_id integer - constraint ams_attribute_values_option_id_fk references ams_option_map_ids(option_map_id), - address_id integer - constraint ams_attribute_values_address_id_fk references postal_addresses(address_id), - number_id integer - constraint ams_attribute_values_number_id_fk references telecom_numbers(number_id), - time timestamptz, - value text, - value_mime_type character varying(50) default 'text/plain' - constraint ams_attribute_values_mime_type_fk references cr_mime_types(mime_type) -); - - - - - ------- Lists --------------------------------------------------------------------- - --- We now create groupings of ams attributes, we call them lists --- since these groupings will be used to create lists of elements --- for ad_form as well as lists of certain attributes to be used --- by other applications. - -create table ams_lists ( - list_id integer - constraint ams_lists_list_id_fk references acs_objects(object_id) - constraint ams_lists_list_id_pk primary key, - package_key varchar(100) - constraint ams_lists_package_key_fk references apm_package_types(package_key) - constraint ams_lists_package_key_nn not null, - object_type varchar(1000) - constraint ams_lists_object_type_fk references acs_object_types(object_type) - constraint ams_lists_object_type_nn not null, - list_name varchar(100) - constraint ams_lists_list_name_nn not null, - pretty_name varchar(200) - constraint ams_lists_pretty_name_nn not null, - description varchar(200), - description_mime_type varchar(200) - constraint ams_lists_description_mime_type_fk references cr_mime_types(mime_type), - UNIQUE(package_key,object_type,list_name) -); - -select acs_object_type__create_type ( - 'ams_list', -- object_type - 'AMS List', -- pretty_name - 'AMS Lists ', -- pretty_plural - 'acs_object', -- supertype - 'ams_lists', -- table_name - 'list_id', -- id_column - 'ams_list', -- package_name - 'f', -- abstract_p - null, -- type_extension_table - 'ams_list__name' -- name_method -); - -select acs_attribute__create_attribute ( - 'ams_list', -- object_type - 'package_key', -- attribute_name - 'string', -- datatype - 'Package Key', -- pretty_name - 'Package Keys', -- pretty_plural -- default null - null, -- table_name -- default null - 'object_type', -- column_name -- default null - null, -- default_value -- default null - '1', -- min_n_values -- default 1 - '1', -- max_n_values -- default 1 - null, -- sort_order -- default null - 'type_specific', -- storage -- default 'type_specific' - null -- static_p -- default 'f' -); - -select acs_attribute__create_attribute ( - 'ams_list', -- object_type - 'object_type', -- attribute_name - 'string', -- datatype - 'Object Type', -- pretty_name - 'Object Types', -- pretty_plural -- default null - null, -- table_name -- default null - 'object_type', -- column_name -- default null - null, -- default_value -- default null - '1', -- min_n_values -- default 1 - '1', -- max_n_values -- default 1 - null, -- sort_order -- default null - 'type_specific', -- storage -- default 'type_specific' - null -- static_p -- default 'f' -); - -select acs_attribute__create_attribute ( - 'ams_list', -- object_type - 'list_name', -- attribute_name - 'string', -- datatype - 'List Name', -- pretty_name - 'List Names', -- pretty_plural -- default null - null, -- table_name -- default null - 'list_name', -- column_name -- default null - null, -- default_value -- default null - '1', -- min_n_values -- default 1 - '1', -- max_n_values -- default 1 - null, -- sort_order -- default null - 'type_specific', -- storage -- default 'type_specific' - null -- static_p -- default 'f' -); - -select acs_attribute__create_attribute ( - 'ams_list', -- object_type - 'pretty_name', -- attribute_name - 'string', -- datatype - 'Pretty Name', -- pretty_name - 'Pretty Names', -- pretty_plural -- default null - null, -- table_name -- default null - 'pretty_name', -- column_name -- default null - null, -- default_value -- default null - '1', -- min_n_values -- default 1 - '1', -- max_n_values -- default 1 - null, -- sort_order -- default null - 'type_specific', -- storage -- default 'type_specific' - null -- static_p -- default 'f' -); - -select acs_attribute__create_attribute ( - 'ams_list', -- object_type - 'description', -- attribute_name - 'text', -- datatype - 'Description', -- pretty_name - 'Descriptions', -- pretty_plural -- default null - null, -- table_name -- default null - 'description', -- column_name -- default null - null, -- default_value -- default null - '1', -- min_n_values -- default 1 - '1', -- max_n_values -- default 1 - null, -- sort_order -- default null - 'type_specific', -- storage -- default 'type_specific' - null -- static_p -- default 'f' -); - -select acs_attribute__create_attribute ( - 'ams_list', -- object_type - 'description_mime_type', -- attribute_name - 'text', -- datatype - 'Description Mime Type', -- pretty_name - 'Descriptions Mime Types', -- pretty_plural -- default null - null, -- table_name -- default null - 'description_mime_type', -- column_name -- default null - null, -- default_value -- default null - '1', -- min_n_values -- default 1 - '1', -- max_n_values -- default 1 - null, -- sort_order -- default null - 'type_specific', -- storage -- default 'type_specific' - null -- static_p -- default 'f' -); - -create sequence ams_list_attribute_sort_order_seq; - -create table ams_list_attribute_map ( - list_id integer - constraint ams_list_attribute_map_list_id_fk references ams_lists(list_id) - constraint ams_list_attribute_map_list_id_nn not null, - ams_attribute_id integer - constraint ams_list_attribute_map_ams_attribute_id_fk references ams_attributes(ams_attribute_id) - constraint ams_list_attribute_map_ams_attribute_id_nn not null, - sort_order integer - constraint ams_list_attribute_map_sort_order_nn not null, - required_p boolean - constraint ams_list_attribute_map_required_p_nn not null, - section_heading varchar(200), - UNIQUE(list_id,ams_attribute_id), - UNIQUE(list_id,sort_order) -); - -\i ams-package-create.sql -\i populate.sql -\i telecom-number-missing-plsql.sql +-- +-- packages/ams/sql/postgresql/ams-create.sql +-- +-- @author Matthew Geddert openacs@geddert.com +-- @creation-date 2004-09-07 +-- @cvs-id $Id$ +-- +-- + + +------ Widgets +-------------------------------------------------------------------- +-- +-- each widget needs to have a ams::widget::${widget} proc associated with it +-- +-- the value_method is a reference to a proc that will convert the value_id into a useable string for +-- the tcl procs. If possible it is best to have a value_method, since this substantailly decreases +-- the number of trips that are needed to go the the database. See the example of widgets that come +-- with AMS for more details. + +create table ams_widgets ( + widget varchar(100) + constraint ams_widgets_name_pk primary key, + pretty_name varchar(100) + constraint ams_widgets_pretty_name_nn not null, + value_method varchar(100), + active_p boolean +); + + +------ Attributes +-------------------------------------------------------------------- + +create table ams_attribute_items ( + attribute_id integer + constraint ams_attribute_items_attribute_id_fk references acs_attributes(attribute_id) + constraint ams_attribute_items_attribute_id_nn not null, + ams_attribute_id integer + constraint ams_attribute_items_ams_attribute_id_fk references acs_objects(object_id) + constraint ams_attribute_items_ams_attribute_id_pk primary key, + widget varchar(100) + constraint ams_attribute_items_widget_fk references ams_widgets(widget) + constraint ams_attribute_items_widget_nn not null, + dynamic_p boolean default 'f' + constraint ams_attribute_items_dynamic_p_nn not null, + deprecated_p boolean default 'f' + constraint ams_attribute_items_deprecated_nn not null, + UNIQUE(attribute_id) +); + +create view ams_attributes as + select acs_attributes.*, + ams_attribute_items.ams_attribute_id, + ams_attribute_items.widget, + ams_attribute_items.dynamic_p, + ams_attribute_items.deprecated_p + from acs_attributes left join ams_attribute_items on ( acs_attributes.attribute_id = ams_attribute_items.attribute_id ); + +select acs_object_type__create_type ( + 'ams_attribute', -- object_type + 'AMS Attribute', -- pretty_name + 'AMS Attributes ', -- pretty_plural + 'acs_object', -- supertype + 'ams_attribute_items', -- table_name + 'ams_attribute_id', -- id_column + 'ams_attribute', -- package_name + 'f', -- abstract_p + null, -- type_extension_table + 'ams_attribute__name' -- name_method +); + +select acs_attribute__create_attribute ( + 'ams_attribute', -- object_type + 'attribute_id', -- attribute_name + 'integer', -- datatype + 'ACS Attribute ID', -- pretty_name + 'ACS Attribute IDs', -- pretty_plural -- default null + null, -- table_name -- default null + 'attribute_id', -- column_name -- default null + null, -- default_value -- default null + '1', -- min_n_values -- default 1 + '1', -- max_n_values -- default 1 + null, -- sort_order -- default null + 'type_specific', -- storage -- default 'type_specific' + null -- static_p -- default 'f' +); + +select acs_attribute__create_attribute ( + 'ams_attribute', -- object_type + 'widget', -- attribute_name + 'string', -- datatype + 'Widget', -- pretty_name + 'Widgets', -- pretty_plural -- default null + null, -- table_name -- default null + 'widget', -- column_name -- default null + null, -- default_value -- default null + '1', -- min_n_values -- default 1 + '1', -- max_n_values -- default 1 + null, -- sort_order -- default null + 'type_specific', -- storage -- default 'type_specific' + null -- static_p -- default 'f' +); + +-- if uninstalled we can delete acs_attributes dynamically created by +-- the ams ui. Howerver we cannot remove attributes added by other +-- packages because it could break those packages. + +select acs_attribute__create_attribute ( + 'ams_attribute', -- object_type + 'dynamic_p', -- attribute_name + 'boolean', -- datatype + 'Dynamic (added by AMS UI?)', -- pretty_name + 'Dynamic (added by AMS UI?)', -- pretty_plural -- default null + null, -- table_name -- default null + 'deprecated_p', -- column_name -- default null + null, -- default_value -- default null + '1', -- min_n_values -- default 1 + '1', -- max_n_values -- default 1 + null, -- sort_order -- default null + 'type_specific', -- storage -- default 'type_specific' + null -- static_p -- default 'f' +); + +select acs_attribute__create_attribute ( + 'ams_attribute', -- object_type + 'deprecated_p', -- attribute_name + 'boolean', -- datatype + 'Deprecated', -- pretty_name + 'Deprecated', -- pretty_plural -- default null + null, -- table_name -- default null + 'deprecated_p', -- column_name -- default null + null, -- default_value -- default null + '1', -- min_n_values -- default 1 + '1', -- max_n_values -- default 1 + null, -- sort_order -- default null + 'type_specific', -- storage -- default 'type_specific' + null -- static_p -- default 'f' +); + + + +------ Attribute Values +-------------------------------------------------------------------- + + + +create table ams_attribute_values ( + object_id integer + constraint ams_attribute_values_object_id_fk references acs_objects(object_id) + constraint ams_attribute_values_object_id_nn not null, + attribute_id integer + constraint ams_attribute_values_attribute_id_fk references acs_attributes(attribute_id) + constraint ams_attribute_values_attribute_id_nn not null, + value_id integer + constraint ams_attribute_values_nn not null +); + + +------ Options +-------------------------------------------------------------------- + +-- create sequence ams_options_seq; - replace with object key + +create table ams_option_types ( + option_id integer + constraint ams_options_option_id_fk references acs_objects(object_id) + constraint ams_options_option_id_pk primary key, + attribute_id integer + constraint ams_options_attribute_id_nn not null + constraint ams_options_attribute_id_nn references acs_attributes (attribute_id), + option varchar(200) + constraint ams_options_option_nn not null, + sort_order integer + constraint ams_options_sort_order not null, + deprecated_p boolean default 'f' + constraint ams_options_deprecated_nn not null, + unique (attribute_id,sort_order) +); + + +select acs_object_type__create_type ( + 'ams_option', -- object_type + 'AMS Option', -- pretty_name + 'AMS Options', -- pretty_plural + 'acs_object', -- supertype + 'ams_option_types', -- table_name + 'option_id', -- id_column + 'ams_option', -- package_name + 'f', -- abstract_p + null, -- type_extension_table + 'ams_option__name' -- name_method +); + +select acs_attribute__create_attribute ( + 'ams_option', -- object_type + 'attribute_id', -- attribute_name + 'integer', -- datatype + 'AMS Attribute ID', -- pretty_name + 'AMS Attribute IDs', -- pretty_plural -- default null + null, -- table_name -- default null + 'attribute_id', -- column_name -- default null + null, -- default_value -- default null + '1', -- min_n_values -- default 1 + '1', -- max_n_values -- default 1 + null, -- sort_order -- default null + 'type_specific', -- storage -- default 'type_specific' + null -- static_p -- default 'f' +); + +select acs_attribute__create_attribute ( + 'ams_option', -- object_type + 'option', -- attribute_name + 'string', -- datatype + 'Option', -- pretty_name + 'Options', -- pretty_plural -- default null + null, -- table_name -- default null + 'option', -- column_name -- default null + null, -- default_value -- default null + '1', -- min_n_values -- default 1 + '1', -- max_n_values -- default 1 + null, -- sort_order -- default null + 'type_specific', -- storage -- default 'type_specific' + null -- static_p -- default 'f' +); + +select acs_attribute__create_attribute ( + 'ams_option', -- object_type + 'sort_order', -- attribute_name + 'integer', -- datatype + 'Sort Order', -- pretty_name + 'Sort Orders', -- pretty_plural -- default null + null, -- table_name -- default null + 'sort_order', -- column_name -- default null + null, -- default_value -- default null + '1', -- min_n_values -- default 1 + '1', -- max_n_values -- default 1 + null, -- sort_order -- default null + 'type_specific', -- storage -- default 'type_specific' + null -- static_p -- default 'f' +); + +select acs_attribute__create_attribute ( + 'ams_option', -- object_type + 'deprecated_p', -- attribute_name + 'boolean', -- datatype + 'Deprecated', -- pretty_name + 'Deprecated', -- pretty_plural -- default null + null, -- table_name -- default null + 'deprecated_p', -- column_name -- default null + null, -- default_value -- default null + '1', -- min_n_values -- default 1 + '1', -- max_n_values -- default 1 + null, -- sort_order -- default null + 'type_specific', -- storage -- default 'type_specific' + null -- static_p -- default 'f' +); + +create table ams_option_ids ( + value_id integer + constraint ams_options_map_ids_value_id_pk primary key +); + +create table ams_options ( + value_id integer + constraint ams_options_value_id_fk references ams_option_ids(value_id) + constraint ams_options_value_id_nn not null, + option_id integer + constraint ams_option_option_id_fk references ams_option_types(option_id) + constraint ams_option_map_option_id_nn not null, + unique (value_id,option_id) +); + +------ AMS Texts +-------------------------------------------------------------------- + +-- use object_id sequence with object_id this allows +-- for future use of option values being converted into objects. + +create table ams_texts ( + value_id integer + constraint ams_texts_text_format_pk primary key, + text text + constraint ams_texts_text_format_nn not null, + text_format varchar(200) default 'text/plain' + constraint ams_texts_text_format_nn not null +); + +------ AMS Times +-------------------------------------------------------------------- + +-- use object_id sequence with object_id this allows +-- for future use of option values being converted into objects. + +create table ams_times ( + value_id integer + constraint ams_times_id_pk primary key, + time timestamptz + constraint ams_times_time_nn not null +); + +------ AMS Numbers +-------------------------------------------------------------------- + +-- use object_id sequence with object_id this allows +-- for future use of option values being converted into objects. + +create table ams_numbers ( + value_id integer + constraint ams_numbers_id_pk primary key, + number numeric + constraint ams_numbers_number_nn not null +); + + + + + +------ Lists +-------------------------------------------------------------------- + +-- We now create groupings of ams attributes, we call them lists +-- since these groupings will be used to create lists of elements +-- for ad_form as well as lists of certain attributes to be used +-- by other applications. + +create table ams_lists ( + list_id integer + constraint ams_lists_list_id_fk references acs_objects(object_id) + constraint ams_lists_list_id_pk primary key, + package_key varchar(100) + constraint ams_lists_package_key_fk references apm_package_types(package_key) + constraint ams_lists_package_key_nn not null, + object_type varchar(1000) + constraint ams_lists_object_type_fk references acs_object_types(object_type) + constraint ams_lists_object_type_nn not null, + list_name varchar(100) + constraint ams_lists_list_name_nn not null, + pretty_name varchar(200) + constraint ams_lists_pretty_name_nn not null, + description varchar(200), + description_mime_type varchar(200) + constraint ams_lists_description_mime_type_fk references cr_mime_types(mime_type), + UNIQUE(package_key,object_type,list_name) +); + +select acs_object_type__create_type ( + 'ams_list', -- object_type + 'AMS List', -- pretty_name + 'AMS Lists ', -- pretty_plural + 'acs_object', -- supertype + 'ams_lists', -- table_name + 'list_id', -- id_column + 'ams_list', -- package_name + 'f', -- abstract_p + null, -- type_extension_table + 'ams_list__name' -- name_method +); + +select acs_attribute__create_attribute ( + 'ams_list', -- object_type + 'package_key', -- attribute_name + 'string', -- datatype + 'Package Key', -- pretty_name + 'Package Keys', -- pretty_plural -- default null + null, -- table_name -- default null + 'object_type', -- column_name -- default null + null, -- default_value -- default null + '1', -- min_n_values -- default 1 + '1', -- max_n_values -- default 1 + null, -- sort_order -- default null + 'type_specific', -- storage -- default 'type_specific' + null -- static_p -- default 'f' +); + +select acs_attribute__create_attribute ( + 'ams_list', -- object_type + 'object_type', -- attribute_name + 'string', -- datatype + 'Object Type', -- pretty_name + 'Object Types', -- pretty_plural -- default null + null, -- table_name -- default null + 'object_type', -- column_name -- default null + null, -- default_value -- default null + '1', -- min_n_values -- default 1 + '1', -- max_n_values -- default 1 + null, -- sort_order -- default null + 'type_specific', -- storage -- default 'type_specific' + null -- static_p -- default 'f' +); + +select acs_attribute__create_attribute ( + 'ams_list', -- object_type + 'list_name', -- attribute_name + 'string', -- datatype + 'List Name', -- pretty_name + 'List Names', -- pretty_plural -- default null + null, -- table_name -- default null + 'list_name', -- column_name -- default null + null, -- default_value -- default null + '1', -- min_n_values -- default 1 + '1', -- max_n_values -- default 1 + null, -- sort_order -- default null + 'type_specific', -- storage -- default 'type_specific' + null -- static_p -- default 'f' +); + +select acs_attribute__create_attribute ( + 'ams_list', -- object_type + 'pretty_name', -- attribute_name + 'string', -- datatype + 'Pretty Name', -- pretty_name + 'Pretty Names', -- pretty_plural -- default null + null, -- table_name -- default null + 'pretty_name', -- column_name -- default null + null, -- default_value -- default null + '1', -- min_n_values -- default 1 + '1', -- max_n_values -- default 1 + null, -- sort_order -- default null + 'type_specific', -- storage -- default 'type_specific' + null -- static_p -- default 'f' +); + +select acs_attribute__create_attribute ( + 'ams_list', -- object_type + 'description', -- attribute_name + 'text', -- datatype + 'Description', -- pretty_name + 'Descriptions', -- pretty_plural -- default null + null, -- table_name -- default null + 'description', -- column_name -- default null + null, -- default_value -- default null + '1', -- min_n_values -- default 1 + '1', -- max_n_values -- default 1 + null, -- sort_order -- default null + 'type_specific', -- storage -- default 'type_specific' + null -- static_p -- default 'f' +); + +select acs_attribute__create_attribute ( + 'ams_list', -- object_type + 'description_mime_type', -- attribute_name + 'text', -- datatype + 'Description Mime Type', -- pretty_name + 'Descriptions Mime Types', -- pretty_plural -- default null + null, -- table_name -- default null + 'description_mime_type', -- column_name -- default null + null, -- default_value -- default null + '1', -- min_n_values -- default 1 + '1', -- max_n_values -- default 1 + null, -- sort_order -- default null + 'type_specific', -- storage -- default 'type_specific' + null -- static_p -- default 'f' +); + +-- create sequence ams_list_attribute_sort_order_seq; + +create table ams_list_attribute_map ( + list_id integer + constraint ams_list_attribute_map_list_id_fk references ams_lists(list_id) + constraint ams_list_attribute_map_list_id_nn not null, + attribute_id integer + constraint ams_list_attribute_map_attribute_id_fk references acs_attributes(attribute_id) + constraint ams_list_attribute_map_attribute_id_nn not null, + sort_order integer + constraint ams_list_attribute_map_sort_order_nn not null, + required_p boolean + constraint ams_list_attribute_map_required_p_nn not null, + section_heading varchar(200), + UNIQUE(list_id,attribute_id), + UNIQUE(list_id,sort_order) +); + +\i ams-package-create.sql +-- \i populate.sql +\i telecom-number-missing-plsql.sql Index: openacs-4/packages/ams/sql/postgresql/ams-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/sql/postgresql/ams-drop.sql,v diff -u -N -r1.3 -r1.4 --- openacs-4/packages/ams/sql/postgresql/ams-drop.sql 27 Oct 2004 02:04:18 -0000 1.3 +++ openacs-4/packages/ams/sql/postgresql/ams-drop.sql 18 May 2005 17:11:48 -0000 1.4 @@ -1,103 +1,86 @@ --- --- packages/ams/sql/postgresql/ams-drop.sql --- --- @author Matthew Geddert openacs@geddert.com --- @creation-date 2004-09-07 --- @cvs-id $Id$ --- --- - - -select content_folder__delete (folder_id, 't') - from cr_folders - where label = 'AMS Objects' - and description = 'AMS Object Repository'; - -delete from cr_folder_type_map where content_type = 'ams_object_revision'; -delete from acs_attribute_descriptions where description_key = 'ams_attribute_description'; - -select drop_package('ams_option'); -select drop_package('ams_attribute'); -select drop_package('ams_attribute_value'); -select drop_package('ams_object_revision'); - -drop function ams_object__new (integer,integer,timestamptz,integer,varchar); -drop function ams_object_id (integer); --- select drop_package('ams_object_id'); -select drop_package('ams_list'); - - -drop sequence ams_options_seq; -drop sequence ams_option_map_id_seq; -drop sequence ams_list_attribute_sort_order_seq; - -drop table ams_list_attribute_map; -drop table ams_lists; -drop view ams_object_revisionsx; -drop view ams_object_revisionsi; -drop table ams_object_revisions cascade; -drop table ams_objects cascade; - -create or replace function inline_1 () -returns varchar as ' -declare - rec RECORD; -begin - - FOR rec IN - select address_id - from ams_attribute_values - where address_id is not null - LOOP - delete from ams_attribute_values where address_id = rec.address_id; - PERFORM postal_address__del (rec.address_id); - END LOOP; - - return ''All Postal Addresses associated with AMS have been deleted''; -end;' language 'plpgsql'; - -select inline_1() as Notice; -drop function inline_1(); - -create or replace function inline_2 () -returns varchar as ' -declare - rec RECORD; -begin - - FOR rec IN - select number_id - from ams_attribute_values - where number_id is not null - LOOP - delete from ams_attribute_values where number_id = rec.number_id; - PERFORM telecom_number__del (rec.number_id); - END LOOP; - - - return ''All Telecom Numbers Addresses associated with AMS have been deleted''; -end;' language 'plpgsql'; - -select inline_2() as Notice; -drop function inline_2(); - - - --- select acs_object__delete(address_id) from ams_attribute_values where address_id is not null; --- select acs_object__delete(number_id) from ams_attribute_values where number_id is not null; - - -drop table ams_attribute_values cascade; -drop table ams_option_map cascade; -drop table ams_option_map_ids cascade; -drop table ams_options cascade; -drop table ams_attributes cascade; -drop table ams_widgets cascade; -drop table ams_storage_types cascade; -update cr_items set live_revision = null, latest_revision = null where content_type = 'ams_object_revision'; -delete from cr_revisions where item_id in ( select item_id from cr_items where content_type = 'ams_object_revision' ); -delete from cr_items where content_type = 'ams_object_revision'; -delete from acs_objects where object_type in ('ams_list','ams_object_revision','ams_attribute'); -select acs_object_type__drop_type('ams_list','f'); -select acs_object_type__drop_type('ams_object_revision','f'); -select acs_object_type__drop_type('ams_attribute','f'); +-- +-- packages/ams/sql/postgresql/ams-drop.sql +-- +-- @author Matthew Geddert openacs@geddert.com +-- @creation-date 2004-09-07 +-- @cvs-id $Id$ +-- +-- + + + + +create or replace function inline_1 () +returns varchar as ' +declare + rec RECORD; +begin + + FOR rec IN + select value_id + from ams_attribute_values + LOOP + delete from ams_attribute_values where address_id = rec.value_id; + PERFORM postal_address__del (rec.value_id); + END LOOP; + + return ''All Postal Addresses associated with AMS have been deleted''; +end;' language 'plpgsql'; + +select inline_1() as Notice; +drop function inline_1(); + +create or replace function inline_2 () +returns varchar as ' +declare + rec RECORD; +begin + + FOR rec IN + select value_id + from ams_attribute_values + where value_id is not null + LOOP + delete from ams_attribute_values where number_id = rec.value_id; + PERFORM telecom_number__del (rec.value_id); + END LOOP; + + + return ''All Telecom Numbers Addresses associated with AMS have been deleted''; +end;' language 'plpgsql'; + +select inline_2() as Notice; +drop function inline_2(); + + +delete from ams_attribute_values; +select ams_attribute__delete(attribute_id) + from ams_attributes + where ams_attribute_id is not null; + +select drop_package('ams_option'); +select drop_package('ams_attribute'); +select drop_package('ams_list'); +select drop_package('ams_value'); +select drop_package('ams_widget'); + +-- select acs_object__delete(address_id) from ams_attribute_values where address_id is not null; +-- select acs_object__delete(number_id) from ams_attribute_values where number_id is not null; + +drop table ams_list_attribute_map; +drop table ams_lists; +drop table ams_options; +drop table ams_option_ids; +drop table ams_numbers; +drop table ams_times; +drop table ams_texts; +drop table ams_option_types; +drop table ams_attribute_values; +drop view ams_attributes; +drop table ams_attribute_items; +drop table ams_widgets; + +delete from acs_objects where object_type in ('ams_attribute','ams_list','ams_option'); +select acs_object_type__drop_type('ams_attribute','f'); +select acs_object_type__drop_type('ams_list','f'); +select acs_object_type__drop_type('ams_option','f'); Index: openacs-4/packages/ams/sql/postgresql/ams-package-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/sql/postgresql/ams-package-create.sql,v diff -u -N -r1.4 -r1.5 --- openacs-4/packages/ams/sql/postgresql/ams-package-create.sql 27 Oct 2004 02:04:18 -0000 1.4 +++ openacs-4/packages/ams/sql/postgresql/ams-package-create.sql 18 May 2005 17:11:48 -0000 1.5 @@ -6,63 +6,73 @@ -- @cvs-id $Id$ -- -- +-- object_id | integer | not null +-- object_type | character varying(100) | not null +-- context_id | integer | +-- security_inherit_p | boolean | not null default true +-- creation_user | integer | +-- creation_date | timestamp with time zone | not null default ('now'::text)::timestamp(6) with time zone +-- creation_ip | character varying(50) | +-- last_modified | timestamp with time zone | not null default ('now'::text)::timestamp(6) with time zone +-- modifying_user | integer | +-- modifying_ip | character varying(50) | +-- tree_sortkey | bit varying | not null +-- max_child_sortkey | bit varying | - ------- Attributes +------ Widgets -------------------------------------------------------------------- +create or replace function ams_widget__save (varchar,varchar,varchar,boolean) +returns integer as ' +declare + p_widget alias for $1; + p_pretty_name alias for $2; + p_value_method alias for $3; + p_active_p alias for $4; + v_exists_p boolean; +begin + v_exists_p := ''1'' from ams_widgets where widget = p_widget; + if v_exists_p then -select define_function_args('ams_attribute__new','ams_attribute_id,object_type,attribute_name,pretty_name,pretty_plural,default_value,description,widget_name,deprecated_p;f,creation_date,creation_user,creation_ip,context_id'); + update ams_widgets + set pretty_name = p_pretty_name, + value_method = p_value_method, + active_p = p_active_p + where widget = p_widget; -create or replace function ams_attribute__new (integer,varchar,varchar,varchar,varchar,varchar,text,varchar,boolean,timestamptz,integer,varchar,integer) + else + insert into ams_widgets + (widget,pretty_name,value_method,active_p) + values + (p_widget,p_pretty_name,p_value_method,p_active_p); + end if; + + return ''1''; +end;' language 'plpgsql'; + + + +------ Attributes +-------------------------------------------------------------------- + +select define_function_args('ams_attribute__new','attribute_id,ams_attribute_id,widget,dynamic_p;f,deprecated_p;f,creation_date;now(),creation_user,creation_ip,context_id'); + +create or replace function ams_attribute__new (integer,integer,varchar,boolean,boolean,timestamptz,integer,varchar,integer) returns integer as ' declare - p_ams_attribute_id alias for $1; -- the AMS Attribute ID - p_object_type alias for $2; - p_attribute_name alias for $3; - p_pretty_name alias for $4; - p_pretty_plural alias for $5; - p_default_value alias for $6; - p_description alias for $7; - p_widget_name alias for $8; - p_deprecated_p alias for $9; - p_creation_date alias for $10; - p_creation_user alias for $11; - p_creation_ip alias for $12; - p_context_id alias for $13; - v_attribute_id integer; - v_acs_datatype varchar; + p_attribute_id alias for $1; + p_ams_attribute_id alias for $2; -- the Permissable AMS Attribute ID + p_widget alias for $3; + p_dynamic_p alias for $4; + p_deprecated_p alias for $5; + p_creation_date alias for $6; + p_creation_user alias for $7; + p_creation_ip alias for $8; + p_context_id alias for $9; v_ams_attribute_id integer; begin - v_acs_datatype := acs_datatype from ams_widgets where widget_name = p_widget_name; - - v_attribute_id := acs_attribute__create_attribute ( - p_object_type, - p_attribute_name, - v_acs_datatype, - p_pretty_name, - p_pretty_plural, - null, -- p_table_name - null, -- p_column_name - p_default_value, - ''0'', -- p_min_n_values - ''1'', -- p_max_n_values - null, -- p_sort_order - ''type_specific'', -- p_storage - ''f'' -- p_static_p - ); - - if p_description is not null then - PERFORM acs_attribute__add_description ( - p_object_type, - p_attribute_name, - ''ams_attribute_description'', - p_description - ); - end if; - v_ams_attribute_id := acs_object__new ( p_ams_attribute_id, ''ams_attribute'', @@ -72,10 +82,10 @@ p_context_id ); - insert into ams_attributes - (ams_attribute_id,attribute_id,widget_name,deprecated_p) + insert into ams_attribute_items + (attribute_id,ams_attribute_id,widget,dynamic_p,deprecated_p) values - (v_ams_attribute_id,v_attribute_id,p_widget_name,p_deprecated_p); + (p_attribute_id,v_ams_attribute_id,p_widget,p_dynamic_p,p_deprecated_p); return v_ams_attribute_id; end;' language 'plpgsql'; @@ -86,59 +96,44 @@ returns varchar as ' declare p_ams_attribute_id alias for $1; - v_name varchar; + v_name varchar; begin - v_name := acs_attributes.attribute_name - from acs_attributes, ams_attributes - where ams_attributes.ams_attribute_id = p_ams_attribute_id - and ams_attributes.attribute_id = acs_attributes.attribute_id; + v_name := attribute_name + from ams_attributes + where ams_attribute_id = p_ams_attribute_id; return v_name; end;' language 'plpgsql'; -create or replace function ams_attribute__pretty_name (integer) -returns varchar as ' -declare - p_ams_attribute_id alias for $1; - v_name varchar; -begin - v_name := acs_attributes.pretty_name - from acs_attributes, ams_attributes - where ams_attributes.ams_attribute_id = p_ams_attribute_id - and ams_attributes.attribute_id = acs_attributes.attribute_id; - - return v_name; -end;' language 'plpgsql'; - create or replace function ams_attribute__delete (integer) returns integer as ' declare p_ams_attribute_id alias for $1; - v_object_type varchar; - v_attribute_name varchar; + v_attribute_id integer; + v_object_type varchar; + v_attribute_name varchar; + v_dynamic_p boolean; begin - select acs_attributes.attribute_name, acs_attributes.object_type - into v_object_type, v_attribute_name - from acs_attributes, ams_attributes - where ams_attributes.attribute_id = acs_attributes.attribute_id; + select attribute_id, attribute_name, object_type, dynamic_p + info v_attribute_id, v_object_type, v_attribute_name, v_dynamic_p + from ams_attributes + where ams_attribute_id = :ams_attribute_id; - delete from ams_attribute_values where ams_attribute_id = p_ams_attribute_id; + delete from ams_attribute_values where attribute_id = v_attribute_id; PERFORM acs_object__delete ( p_ams_attribute_id ); - PERFORM acs_attribute__drop_description ( - v_object_type, - v_attribute_name, - ''ams_attribute_description'' - ); + if v_dynamic_p then PERFORM acs_attribute__drop_attribute ( v_object_type, v_attribute_name ); + end if; + return 0; end;' language 'plpgsql'; @@ -147,197 +142,104 @@ ------- Objects --------------------------------------------------------------------- -create or replace function ams_object_revision__root_folder (integer) -returns integer as ' -declare - p_package_id alias for $1; - v_folder_id integer; - v_count integer; - v_folder_name varchar; -begin - v_count := count(*) from cr_folders where package_id = p_package_id; - if v_count = 0 then - v_folder_name := package_key || ''_'' || p_package_id from apm_packages - where package_id = p_package_id; +------ Attribute Values +-------------------------------------------------------------------- - -- create a new root folder - v_folder_id := content_folder__new ( - v_folder_name, -- name - ''AMS Objects'', -- label - ''AMS Object Repository'', -- description - null, -- parent_id - p_package_id, -- parent_id - null, -- folder_id - null, -- creation_date - null, -- creation_user - null -- creation_ip - ); - - -- register folder content types - PERFORM content_folder__register_content_type ( - v_folder_id, -- folder_id - ''ams_object_revision'', -- content_type - ''f'' -- include_subtypes - ); - - -- there is no facility in the API for adding in the package_id, - -- so we have to do it ourselves - - update cr_folders - set package_id = p_package_id - where folder_id = v_folder_id; - - else - v_folder_id := folder_id from cr_folders where package_id = p_package_id; - end if; - - return v_folder_id; - -end; ' language 'plpgsql'; - - - --- select define_function_args('ams_object_id','object_id,package_id,creation_date;now(),creation_user,creation_ip'); --- get the ams_object_id, and none exists create a new content item - -create or replace function ams_object__new (integer,integer,timestamptz,integer,varchar) +create or replace function ams_attribute_value__save (integer,integer,integer) returns integer as ' declare - p_object_id alias for $1; - p_package_id alias for $2; - p_creation_date alias for $3; - p_creation_user alias for $4; - p_creation_ip alias for $5; - v_ams_object_id integer; - v_count integer; + p_object_id alias for $1; + p_attribute_id alias for $2; + p_value_id alias for $3; + v_count integer; begin - v_count := count(*) from ams_objects where object_id = p_object_id; - if v_count = 0 then + delete from ams_attribute_values + where object_id = p_object_id + and attribute_id = p_attribute_id; - -- create a new item - v_ams_object_id := content_item__new ( - p_object_id::varchar, -- name - ams_object_revision__root_folder(p_package_id), -- parent_id - null, -- item_id - null, -- locale - p_creation_date, -- creation_date - p_creation_user, -- creation_user - p_object_id, -- context_id - p_creation_ip, -- creation_ip - ''content_item'', -- item_subtype - ''ams_object_revision'', -- content_type - null, -- title - null, -- description - null, -- mime_type - null, -- nls_language - null -- data - ); - - insert into ams_objects - (ams_object_id,object_id) + if p_value_id is not null then + insert into ams_attribute_values + (object_id,attribute_id,value_id) values - (v_ams_object_id,p_object_id); + (p_object_id,p_attribute_id,p_value_id); + end if; - else - v_ams_object_id := ams_object_id(p_object_id); - end if; - - return v_ams_object_id; + return 0; end;' language 'plpgsql'; - -create or replace function ams_object_id (integer) -returns integer as ' +create or replace function ams_attribute_value__value (integer,integer) +returns text as ' declare - p_object_id alias for $1; - v_ams_object_id integer; + p_attribute_id alias for $1; + p_value_id alias for $2; + v_value_method varchar; + v_value text; + val record; begin - return ams_object_id from ams_objects where object_id = p_object_id; -end;' language 'plpgsql'; + v_value_method := value_method + from ams_widgets + where widget = ( select widget + from ams_attributes + where attribute_id = p_attribute_id ); + if v_value_method != '''' and v_value_method is NOT null then + for val in execute ''select '' || v_value_method || ''('' || p_value_id || '')::text as value'' loop + v_value := val.value; + exit; + end loop; + end if; -select define_function_args('ams_object_revision__new','object_id,package_id,creation_date;now(),creation_user,creation_ip'); + return v_value; + +end;' language 'plpgsql' stable strict; -create or replace function ams_object_revision__new (integer,integer,timestamptz,integer,varchar) -returns integer as ' -declare - p_object_id alias for $1; - p_package_id alias for $2; - p_creation_date alias for $3; - p_creation_user alias for $4; - p_creation_ip alias for $5; - v_ams_object_id integer; - v_ams_object_revision_id integer; -begin - - -- get the ams_object_id and create the content item if necessary - v_ams_object_id := ams_object__new ( - p_object_id, - p_package_id, - p_creation_date, - p_creation_user, - p_creation_ip - ); - - v_ams_object_revision_id := content_revision__new ( - null, -- title - null, -- description - now(), -- publish_date - null, -- mime_type - null, -- nls_language - null, -- data - v_ams_object_id, -- item_id - null, -- revision_id - p_creation_date, -- creation_date - p_creation_user, -- creation_user - p_creation_ip -- creation_ip - ); - - PERFORM content_item__set_live_revision (v_ams_object_revision_id); - - insert into ams_object_revisions - (ams_object_revision_id) - values - (v_ams_object_revision_id); - - return v_ams_object_revision_id; -end;' language 'plpgsql'; - - - ------ Options -------------------------------------------------------------------- -create or replace function ams_option__new (integer,varchar,integer) +select define_function_args('ams_option__new','option_id,attribute_id,option,sort_order,depreacted_p;f,creation_date,creation_user,creation_ip,context_id'); + +create or replace function ams_option__new (integer,integer,varchar,integer,boolean,timestamptz,integer,varchar,integer) returns integer as ' declare - p_ams_attribute_id alias for $1; - p_option alias for $2; - p_sort_order alias for $3; + p_option_id alias for $1; + p_attribute_id alias for $2; + p_option alias for $3; + p_sort_order alias for $4; + p_deprecated_p alias for $5; + p_creation_date alias for $6; + p_creation_user alias for $7; + p_creation_ip alias for $8; + p_context_id alias for $9; v_option_id integer; v_sort_order integer; begin - v_option_id := nextval(''ams_options_seq''); + v_option_id := acs_object__new ( + p_option_id, + ''ams_option'', + p_creation_date, + p_creation_user, + P_creation_ip, + p_context_id + ); + if p_sort_order is null then - v_sort_order := nextval(''ams_options_seq''); + v_sort_order := v_option_id; else v_sort_order := p_sort_order; end if; - insert into ams_options - (option_id,ams_attribute_id,option,sort_order) + insert into ams_option_types + (option_id,attribute_id,option,sort_order,deprecated_p) values - (v_option_id,p_ams_attribute_id,p_option,v_sort_order); + (v_option_id,p_attribute_id,p_option,v_sort_order,p_deprecated_p); return v_option_id; end;' language 'plpgsql'; @@ -349,206 +251,204 @@ p_option_id alias for $1; begin delete from ams_options where object_id = p_option_id; + PERFORM acs_object__delete ( + p_option_id + ); return 0; end;' language 'plpgsql'; +create or replace function ams_option__name (integer) +returns varchar as ' +declare + p_option_id alias for $1; + v_name varchar; +begin + v_name := option + from ams_option_types + where option_id = p_option_id; + + return v_name; +end;' language 'plpgsql'; + create or replace function ams_option__map (integer,integer) returns integer as ' declare - p_option_map_id alias for $1; + p_value_id alias for $1; p_option_id alias for $2; - v_option_map_id integer; + v_value_id integer; v_count integer; begin - v_count := count(*) from ams_option_map where option_map_id = p_option_map_id; + v_count := count(*) from ams_options where value_id = p_value_id; - if v_count = ''0'' then - v_option_map_id := nextval(''ams_option_map_id_seq''); - insert into ams_option_map_ids(option_map_id) values (v_option_map_id); + if v_count = ''0'' or p_value_id is null then + v_value_id := nextval from acs_object_id_seq; + insert into ams_option_ids(value_id) values (v_value_id); else - v_option_map_id := p_option_map_id; + v_value_id := p_value_id; end if; - insert into ams_option_map - (option_map_id,option_id) + insert into ams_options + (value_id,option_id) values - (v_option_map_id,p_option_id); + (v_value_id,p_option_id); - return v_option_map_id; + return v_value_id; end;' language 'plpgsql'; +create or replace function ams_value__options (integer) +returns text as ' +declare + p_value_id alias for $1; + v_name text; + rec RECORD; +begin + v_name := NULL; + if p_value_id is not null then + FOR rec IN + select option_id + from ams_options + where value_id = p_value_id + order by option_id + LOOP + IF v_name is null THEN + v_name := rec.option_id; + ELSE + v_name := v_name || '' '' || rec.option_id; + END IF; + END LOOP; + end if; ------- Attribute Values --------------------------------------------------------------------- + return v_name; +end;' language 'plpgsql'; --- Unlike the ams_attribute_value__save proc below this one, --- ams_attribute_value__new will save null entries (i.e. when --- no value was given for an attribute). this will chew up --- database space (with non-value rows). but it can be called --- upon by content repository managed objects to store attribute --- values with that objects revision_id (as opposed to the ams --- managed revision_id). This is useful when permissions are not --- set to hide certain attributes from users. If the attributes --- for an object are restrict based on permissions the ams_object --- container is preferred since it is made to deal with the --- retrieval and display of this more complex form of content --- revision. Note, this proc does not mark previous revisions as --- superseeded, so if another objects revisions are used you must --- make sure that the attribute has not already been entered for --- this particular revision. - - - -create or replace function ams_attribute_value__new (integer,integer,integer,integer,integer,timestamptz,text,varchar) +create or replace function ams_value__asses (text) returns integer as ' declare - p_revision_id alias for $1; - p_ams_attribute_id alias for $2; - p_option_map_id alias for $3; - p_address_id alias for $4; - p_number_id alias for $5; - p_time alias for $6; - p_value alias for $7; - p_value_mime_type alias for $8; + p_ams_value__options alias for $1; + v_value_id integer begin - insert into ams_attribute_values - (revision_id,ams_attribute_id,option_map_id,address_id,number_id,time,value,value_mime_type) - values - (p_revision_id,p_ams_attribute_id,p_option_map_id,p_address_id,p_number_id,p_time,p_value,p_value_mime_type); - return 0; + v_value_id := value_id + from ams_options_ids + where ams_value__options(value_id) = p_ams_value__options; + + return v_value_id; end;' language 'plpgsql'; +------ AMS Texts +-------------------------------------------------------------------- - -create or replace function ams_attribute_value__superseed (integer,integer,integer) +create or replace function ams_value__text_save (text,varchar) returns integer as ' declare - p_revision_id alias for $1; - p_ams_attribute_id alias for $2; - p_ams_object_id alias for $3; + p_text alias for $1; + p_text_format alias for $2; + v_value_id integer; begin - update ams_attribute_values - set superseed_ams_attribute_id = p_revision_id - where ams_attribute_id = p_ams_attribute_id - and superseed_revision_id is null - and revision_id in ( select revision_id - from cr_revisions - where item_id = p_ams_object_id ); + v_value_id := value_id + from ams_texts + where text = p_text + and text_format = p_text_format; + if v_value_id is null then + v_value_id := nextval from acs_object_id_seq; + insert into ams_texts + (value_id,text,text_format) + values + (v_value_id,p_text,p_text_format); + end if; - return 0; + return v_value_id; end;' language 'plpgsql'; +create or replace function ams_value__text(integer) +returns varchar as ' +declare + p_value_id alias for $1; + v_value text; +begin + v_value := ''{'' || text_format::text || ''} '' || text from ams_texts where value_id = p_value_id; + return v_value; +end;' language 'plpgsql'; +------ AMS Times +-------------------------------------------------------------------- -create or replace function ams_attribute_value__save (integer,integer,integer,integer,integer,timestamptz,text,varchar) +create or replace function ams_value__time_save (timestamptz) returns integer as ' declare - p_revision_id alias for $1; - p_ams_attribute_id alias for $2; - p_option_map_id alias for $3; - p_address_id alias for $4; - p_number_id alias for $5; - p_time alias for $6; - p_value alias for $7; - p_value_mime_type alias for $8; - v_ams_object_id integer; - v_count integer; - v_option_map_id integer; - v_address_id integer; - v_number_id integer; - v_time timestamptz; - v_value text; - v_value_mime_type varchar; - v_insert_new_p boolean; - v_duplicate_p boolean; + p_time alias for $1; + v_value_id integer; begin - v_ams_object_id := item_id from cr_revisions where revision_id = p_revision_id; + v_value_id := value_id + from ams_times + where time = p_time; - v_count := count(*) from ams_attribute_values - where superseed_revision_id is null - and revision_id in ( select revision_id - from cr_revisions - where item_id = v_ams_object_id ); + if v_value_id is null then + v_value_id := nextval from acs_object_id_seq; + insert into ams_times + (value_id,time) + values + (v_value_id,p_time); + end if; - if v_count > 0 then - select option_map_id, - address_id, - number_id, - time, - value, - value_mime_type - into v_option_map_id, - v_address_id, - v_number_id, - v_time, - v_value, - v_value_mime_type - from ams_attribute_values - where ams_attribute_id = p_ams_attribute_id - and revision_id in ( select revision_id - from cr_items - where item_id = v_ams_object_id ) - and superseed_revision_id is not null; + return v_value_id; +end;' language 'plpgsql'; - if v_option_map_id != p_option_map_id - or v_address_id != p_address_id - or v_number_id != p_number_id - or v_time != p_time - or v_value != p_value - then - PERFORM ams_attribute_value__superseed ( - p_revision_id, - p_ams_attribute_id, - v_ams_object_id - ); - - v_duplicate_p := ''f''; - else - v_duplicate_p := ''t''; +create or replace function ams_value__time(integer) +returns text as ' +declare + p_value_id alias for $1; + v_value text; +begin + v_value := to_char(time,''YYYY-MM-DD HH24:MI:SS TZ'')::text from ams_times where value_id = p_value_id; + return v_value; +end;' language 'plpgsql'; - end if; - else - v_duplicate_p := ''f''; - end if; - - if not v_duplicate_p then - -- we know that this is not duplicate - if p_option_map_id is not null - or p_address_id is not null - or p_number_id is not null - or p_time is not null - or p_value is not null - then - -- there is a not null value to this attribute - PERFORM ams_attribute_value__new ( - p_revision_id, - p_ams_attribute_id, - p_option_map_id, - p_address_id, - p_number_id, - p_time, - p_value, - p_value_mime_type - ); - end if; +------ AMS +-------------------------------------------------------------------- + +create or replace function ams_value__number_save (numeric) +returns integer as ' +declare + p_number alias for $1; + v_value_id integer; +begin + + v_value_id := value_id + from ams_numbers + where number = p_number; + + if v_value_id is null then + v_value_id := nextval from acs_object_id_seq; + insert into ams_numbers + (value_id,number) + values + (v_value_id,p_number); end if; + return v_value_id; +end;' language 'plpgsql'; - return 0; +create or replace function ams_value__number(integer) +returns text as ' +declare + p_value_id alias for $1; + v_value text; +begin + v_value := number::text from ams_numbers where value_id = p_value_id; + return v_value; end;' language 'plpgsql'; - ------- Groups +------ Lists -------------------------------------------------------------------- @@ -593,27 +493,27 @@ returns integer as ' declare p_list_id alias for $1; - p_ams_attribute_id alias for $2; + p_attribute_id alias for $2; p_sort_order alias for $3; p_required_p alias for $4; p_section_heading alias for $5; v_sort_order integer; begin if p_sort_order is null then - v_sort_order := nextval(''ams_list_attribute_sort_order_seq''); + v_sort_order := nextval from acs_object_id_seq; else v_sort_order := p_sort_order; end if; delete from ams_list_attribute_map - where ams_attribute_id = p_ams_attribute_id + where attribute_id = p_attribute_id and list_id = p_list_id; insert into ams_list_attribute_map - (list_id,ams_attribute_id,sort_order,required_p,section_heading) + (list_id,attribute_id,sort_order,required_p,section_heading) values - (p_list_id,p_ams_attribute_id,v_sort_order,p_required_p,p_section_heading); + (p_list_id,p_attribute_id,v_sort_order,p_required_p,p_section_heading); return ''1''; end;' language 'plpgsql'; @@ -622,7 +522,16 @@ +create or replace function ams_list__name (integer) +returns varchar as ' +declare + p_list_id alias for $1; + v_name varchar; +begin + v_name := pretty_name from ams_lists where list_id = p_list_id; + return v_name; +end;' language 'plpgsql'; @@ -631,11 +540,12 @@ + ------ Postal Address -------------------------------------------------------------------- -create or replace function ams_attribute__postal_address_string (integer) -returns varchar as ' +create or replace function ams_value__postal_address (integer) +returns text as ' declare p_address_id alias for $1; v_name text; @@ -659,14 +569,74 @@ return v_name; end;' language 'plpgsql'; +create or replace function ams_value__postal_address_save (varchar,varchar,varchar,varchar,char(2),varchar,integer) +returns integer as ' +declare + p_delivery_address alias for $1; + p_municipality alias for $2; + p_region alias for $3; + p_postal_code alias for $4; + p_country_code alias for $5; + p_additional_text alias for $6; + p_postal_type alias for $7; + v_address_id integer; +begin + if p_additional_text is null and p_postal_type is null then + v_address_id := address_id + from postal_addresses + where delivery_address = p_delivery_address + and municipality = p_municipality + and region = p_region + and postal_code = p_postal_code + and country_code = p_country_code + and additional_text is NULL + and postal_type is NULL; + + else + + v_address_id := address_id + from postal_addresses + where delivery_address = p_delivery_address + and municipality = p_municipality + and region = p_region + and postal_code = p_postal_code + and country_code = p_country_code + and additional_text = p_additional_text + and postal_type = p_postal_type; + + end if; + + if v_address_id is null then + + v_address_id := acs_object__new ( + null, + ''postal_address'', + now(), + NULL, + NULL, + NULL + ); + + insert into postal_addresses + ( address_id, delivery_address, municipality, region, postal_code, country_code, additional_text, postal_type ) + values + ( v_address_id, p_delivery_address, p_municipality, p_region, p_postal_code, p_country_code, p_additional_text, p_postal_type ); + + end if; + + return v_address_id; +end;' language 'plpgsql'; + + + ------ Telecom Number -------------------------------------------------------------------- -create or replace function ams_attribute__telecom_number_string (integer) -returns varchar as ' +create or replace function ams_value__telecom_number (integer) +returns text as ' declare p_number_id alias for $1; v_name text; @@ -692,33 +662,69 @@ return v_name; end;' language 'plpgsql'; +create or replace function ams_value__telecom_number_save (integer,varchar,varchar,varchar,varchar,boolean,varchar,varchar,integer) +returns integer as ' +declare + p_itu_id alias for $1; + p_national_number alias for $2; + p_area_city_code alias for $3; + p_subscriber_number alias for $4; + p_extension alias for $5; + p_sms_enabled_p alias for $6; + p_best_contact_time alias for $7; + p_location alias for $8; + p_phone_type_id alias for $9; + v_number_id integer; +begin ------- AMS Options --------------------------------------------------------------------- + v_number_id := number_id + from telecom_numbers + where itu_id = p_itu_id + and national_number = p_national_number + and area_city_code = p_area_city_code + and subscriber_number = p_subscriber_number + and extension = p_extension + and sms_enabled_p = p_sms_enabled_p + and best_contact_time = p_best_contact_time + and location = p_location + and p_phone_type_id = p_phone_type_id; -create or replace function ams_attribute__options_string (integer) -returns varchar as ' -declare - p_option_map_id alias for $1; - v_name text; - rec RECORD; -begin + if v_number_id is null then - v_name := NULL; - if p_option_map_id is not null then - FOR rec IN - select aom.option_id - from ams_option_map aom - where aom.option_map_id = p_option_map_id - order by aom.option_id - LOOP - IF v_name is null THEN - v_name := rec.option_id; - ELSE - v_name := v_name || '' '' || rec.option_id; - END IF; - END LOOP; - end if; + v_number_id := acs_object__new ( + null, + ''telecom_number'', + now(), + NULL, + NULL, + NULL + ); + + insert into telecom_numbers + ( number_id, itu_id, national_number, area_city_code, subscriber_number, extension, sms_enabled_p, best_contact_time, location, phone_type_id ) + values + ( v_number_id, p_itu_id, p_national_number, p_area_city_code, p_subscriber_number, p_extension, p_sms_enabled_p, p_best_contact_time, p_location, p_phone_type_id); - return v_name; + end if; + + return v_number_id; end;' language 'plpgsql'; + + + + + + + + + + + + + + + + + + + Index: openacs-4/packages/ams/sql/postgresql/populate.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/sql/postgresql/populate.sql,v diff -u -N -r1.2 -r1.3 --- openacs-4/packages/ams/sql/postgresql/populate.sql 30 Oct 2004 00:23:54 -0000 1.2 +++ openacs-4/packages/ams/sql/postgresql/populate.sql 18 May 2005 17:11:48 -0000 1.3 @@ -1,430 +1,430 @@ --- --- packages/ams/sql/postgresql/populate.sql --- --- @author Matthew Geddert openacs@geddert.com --- @creation-date 2004-09-07 --- @cvs-id $Id$ --- --- - -insert into ams_storage_types ( storage_type ) values ( 'telecom_number' ); -insert into ams_storage_types ( storage_type ) values ( 'postal_address' ); -insert into ams_storage_types ( storage_type ) values ( 'ams_options' ); -insert into ams_storage_types ( storage_type ) values ( 'time' ); -insert into ams_storage_types ( storage_type ) values ( 'value' ); -insert into ams_storage_types ( storage_type ) values ( 'value_with_mime_type' ); - --- --- Note, I am very open to adding new unique widgets. --- I am simply adding those I personally could imagine --- needing in the near future for my projects. I am sure --- that there will be others that other programmers need. --- So, If you would like a new widget and possibly a new --- storage type added to the default configuration of --- this package please contact me. --- -- Matthew --- - -insert into ams_widgets ( - widget_name, - pretty_name, - pretty_plural, - storage_type, - acs_datatype, - widget, - datatype, - parameters -) values ( - 'postal_address', - '#ams.Address#', - '#ams.Addresses#', - 'postal_address', - 'string', - 'address', - 'address', - null -); - -insert into ams_widgets ( - widget_name, - pretty_name, - pretty_plural, - storage_type, - acs_datatype, - widget, - datatype, - parameters -) values ( - 'telecom_number', - '#ams.Telecom_Number#', - '#ams.Telecom_Numbers#', - 'telecom_number', - 'string', - 'telecom_number', - 'telecom_number', - '{html {size 12 maxlenth 50}}' -); - -insert into ams_widgets ( - widget_name, - pretty_name, - pretty_plural, - storage_type, - acs_datatype, - widget, - datatype, - parameters -) values ( - 'date', - '#ams.Date#', - '#ams.Date#', - 'time', - 'date', - 'date', - 'date', - '{help}' -); - -insert into ams_widgets ( - widget_name, - pretty_name, - pretty_plural, - storage_type, - acs_datatype, - widget, - datatype, - parameters -) values ( - 'select', - '#ams.Select# - #ams.One_Option_Allowed#', - '#ams.Selects# - #ams.One_Option_Allowed#', - 'ams_options', - 'string', - 'select', - 'integer', - null -); - -insert into ams_widgets ( - widget_name, - pretty_name, - pretty_plural, - storage_type, - acs_datatype, - widget, - datatype, - parameters -) values ( - 'radio', - '#ams.Radio# - #ams.One_Option_Allowed#', - '#ams.Radios# - #ams.One_Option_Allowed#', - 'ams_options', - 'string', - 'radio', - 'integer', - null -); - -insert into ams_widgets ( - widget_name, - pretty_name, - pretty_plural, - storage_type, - acs_datatype, - widget, - datatype, - parameters -) values ( - 'checkbox', - '#ams.Checkboxes# - #ams.Multiple_Options_Allowed#', - '#ams.Checkboxes# - #ams.Multiple_Options_Allowed#', - 'ams_options', - 'string', - 'checkbox', - 'integer', - '{multiple}' -); - -insert into ams_widgets ( - widget_name, - pretty_name, - pretty_plural, - storage_type, - acs_datatype, - widget, - datatype, - parameters -) values ( - 'multiselect', - '#ams.Multiselect# - #ams.Multiple_Options_Allowed#', - '#ams.Multiselects# - #ams.Multiple_Options_Allowed#', - 'ams_options', - 'string', - 'multiselect', - 'integer', - '{multiple}' -); - -insert into ams_widgets ( - widget_name, - pretty_name, - pretty_plural, - storage_type, - acs_datatype, - widget, - datatype, - parameters -) values ( - 'multiselect_single', - '#ams.Multiselect# - #ams.One_Option_Allowed#', - '#ams.Multiselects# - #ams.One_Option_Allowed#', - 'ams_options', - 'string', - 'multiselect', - 'integer', - null -); - -insert into ams_widgets ( - widget_name, - pretty_name, - pretty_plural, - storage_type, - acs_datatype, - widget, - datatype, - parameters -) values ( - 'integer', - '#ams.Integer#', - '#ams.Integers#', - 'value', - 'integer', - 'text', - 'integer', - '{html {size 6}}' -); - -insert into ams_widgets ( - widget_name, - pretty_name, - pretty_plural, - storage_type, - acs_datatype, - widget, - datatype, - parameters -) values ( - 'textbox_small', - '#ams.Textbox# - #ams.Small#', - '#ams.Textboxes# - #ams.Small#', - 'value', - 'string', - 'text', - 'text', - '{html {size 18}}' -); - -insert into ams_widgets ( - widget_name, - pretty_name, - pretty_plural, - storage_type, - acs_datatype, - widget, - datatype, - parameters -) values ( - 'textbox_medium', - '#ams.Textbox# - #ams.Medium#', - '#ams.Textboxes# - #ams.Medium#', - 'value', - 'string', - 'text', - 'text', - '{html {size 30}}' -); - -insert into ams_widgets ( - widget_name, - pretty_name, - pretty_plural, - storage_type, - acs_datatype, - widget, - datatype, - parameters -) values ( - 'textbox_large', - '#ams.Textbox# - #ams.Large#', - '#ams.Textboxes# - #ams.Large#', - 'value', - 'string', - 'text', - 'text', - '{html {size 50}}' -); - -insert into ams_widgets ( - widget_name, - pretty_name, - pretty_plural, - storage_type, - acs_datatype, - widget, - datatype, - parameters -) values ( - 'textarea_small', - '#ams.Textarea# - #ams.Small#', - '#ams.Textareas# - #ams.Small#', - 'value', - 'text', - 'textarea', - 'text', - '{html {cols 60 rows 6}}' -); - -insert into ams_widgets ( - widget_name, - pretty_name, - pretty_plural, - storage_type, - acs_datatype, - widget, - datatype, - parameters -) values ( - 'textarea_small_nospell', - '#ams.Textarea# - #ams.Small# - #ams.No_Spellcheck#', - '#ams.Textareas# - #ams.Small# - #ams.No_Spellcheck#', - 'value', - 'text', - 'textarea', - 'text', - '{html {cols 60 rows 6}} {nospell}' -); - -insert into ams_widgets ( - widget_name, - pretty_name, - pretty_plural, - storage_type, - acs_datatype, - widget, - datatype, - parameters -) values ( - 'textarea_medium', - '#ams.Textarea# - #ams.Medium#', - '#ams.Textareas# - #ams.Medium#', - 'value', - 'text', - 'textarea', - 'text', - '{html {cols 80 rows 10}}' -); - -insert into ams_widgets ( - widget_name, - pretty_name, - pretty_plural, - storage_type, - acs_datatype, - widget, - datatype, - parameters -) values ( - 'textarea_large', - '#ams.Textarea# - #ams.Large#', - '#ams.Textareas# - #ams.Large#', - 'value', - 'text', - 'textarea', - 'text', - '{html {cols 80 rows 24}}' -); - -insert into ams_widgets ( - widget_name, - pretty_name, - pretty_plural, - storage_type, - acs_datatype, - widget, - datatype, - parameters -) values ( - 'richtext_medium', - '#ams.Richtext# - #ams.Medium#', - '#ams.Richtexts# - #ams.Medium#', - 'value_with_mime_type', - 'text', - 'richtext', - 'richtext', - '{html {cols 80 rows 10}}' -); - -insert into ams_widgets ( - widget_name, - pretty_name, - pretty_plural, - storage_type, - acs_datatype, - widget, - datatype, - parameters -) values ( - 'richtext_large', - '#ams.Richtext# - #ams.Large#', - '#ams.Richtexts# - #ams.Large#', - 'value_with_mime_type', - 'text', - 'richtext', - 'richtext', - '{html {cols 80 rows 24}}' -); - - -insert into ams_widgets ( - widget_name, - pretty_name, - pretty_plural, - storage_type, - acs_datatype, - widget, - datatype, - parameters -) values ( - 'email', - '#ams.Email_Address#', - '#ams.Email_Addresses#', - 'value', - 'email', - 'text', - 'email', - '{html {size 30}}' -); - -insert into ams_widgets ( - widget_name, - pretty_name, - pretty_plural, - storage_type, - acs_datatype, - widget, - datatype, - parameters -) values ( - 'url', - '#ams.Url#', - '#ams.Urls#', - 'value', - 'url', - 'text', - 'url', - '{html {size 30}}' -); - - - +-- +-- packages/ams/sql/postgresql/populate.sql +-- +-- @author Matthew Geddert openacs@geddert.com +-- @creation-date 2004-09-07 +-- @cvs-id $Id$ +-- +-- + +insert into ams_storage_types ( storage_type ) values ( 'telecom_number' ); +insert into ams_storage_types ( storage_type ) values ( 'postal_address' ); +insert into ams_storage_types ( storage_type ) values ( 'ams_options' ); +insert into ams_storage_types ( storage_type ) values ( 'time' ); +insert into ams_storage_types ( storage_type ) values ( 'value' ); +insert into ams_storage_types ( storage_type ) values ( 'value_with_mime_type' ); + +-- +-- Note, I am very open to adding new unique widgets. +-- I am simply adding those I personally could imagine +-- needing in the near future for my projects. I am sure +-- that there will be others that other programmers need. +-- So, If you would like a new widget and possibly a new +-- storage type added to the default configuration of +-- this package please contact me. +-- -- Matthew +-- + +insert into ams_widgets ( + widget_name, + pretty_name, + pretty_plural, + storage_type, + acs_datatype, + widget, + datatype, + parameters +) values ( + 'postal_address', + '#ams.Address#', + '#ams.Addresses#', + 'postal_address', + 'string', + 'address', + 'address', + null +); + +insert into ams_widgets ( + widget_name, + pretty_name, + pretty_plural, + storage_type, + acs_datatype, + widget, + datatype, + parameters +) values ( + 'telecom_number', + '#ams.Telecom_Number#', + '#ams.Telecom_Numbers#', + 'telecom_number', + 'string', + 'telecom_number', + 'telecom_number', + '{html {size 12 maxlenth 50}}' +); + +insert into ams_widgets ( + widget_name, + pretty_name, + pretty_plural, + storage_type, + acs_datatype, + widget, + datatype, + parameters +) values ( + 'date', + '#ams.Date#', + '#ams.Date#', + 'time', + 'date', + 'date', + 'date', + '{help}' +); + +insert into ams_widgets ( + widget_name, + pretty_name, + pretty_plural, + storage_type, + acs_datatype, + widget, + datatype, + parameters +) values ( + 'select', + '#ams.Select# - #ams.One_Option_Allowed#', + '#ams.Selects# - #ams.One_Option_Allowed#', + 'ams_options', + 'string', + 'select', + 'integer', + null +); + +insert into ams_widgets ( + widget_name, + pretty_name, + pretty_plural, + storage_type, + acs_datatype, + widget, + datatype, + parameters +) values ( + 'radio', + '#ams.Radio# - #ams.One_Option_Allowed#', + '#ams.Radios# - #ams.One_Option_Allowed#', + 'ams_options', + 'string', + 'radio', + 'integer', + null +); + +insert into ams_widgets ( + widget_name, + pretty_name, + pretty_plural, + storage_type, + acs_datatype, + widget, + datatype, + parameters +) values ( + 'checkbox', + '#ams.Checkboxes# - #ams.Multiple_Options_Allowed#', + '#ams.Checkboxes# - #ams.Multiple_Options_Allowed#', + 'ams_options', + 'string', + 'checkbox', + 'integer', + '{multiple}' +); + +insert into ams_widgets ( + widget_name, + pretty_name, + pretty_plural, + storage_type, + acs_datatype, + widget, + datatype, + parameters +) values ( + 'multiselect', + '#ams.Multiselect# - #ams.Multiple_Options_Allowed#', + '#ams.Multiselects# - #ams.Multiple_Options_Allowed#', + 'ams_options', + 'string', + 'multiselect', + 'integer', + '{multiple}' +); + +insert into ams_widgets ( + widget_name, + pretty_name, + pretty_plural, + storage_type, + acs_datatype, + widget, + datatype, + parameters +) values ( + 'multiselect_single', + '#ams.Multiselect# - #ams.One_Option_Allowed#', + '#ams.Multiselects# - #ams.One_Option_Allowed#', + 'ams_options', + 'string', + 'multiselect', + 'integer', + null +); + +insert into ams_widgets ( + widget_name, + pretty_name, + pretty_plural, + storage_type, + acs_datatype, + widget, + datatype, + parameters +) values ( + 'integer', + '#ams.Integer#', + '#ams.Integers#', + 'value', + 'integer', + 'text', + 'integer', + '{html {size 6}}' +); + +insert into ams_widgets ( + widget_name, + pretty_name, + pretty_plural, + storage_type, + acs_datatype, + widget, + datatype, + parameters +) values ( + 'textbox_small', + '#ams.Textbox# - #ams.Small#', + '#ams.Textboxes# - #ams.Small#', + 'value', + 'string', + 'text', + 'text', + '{html {size 18}}' +); + +insert into ams_widgets ( + widget_name, + pretty_name, + pretty_plural, + storage_type, + acs_datatype, + widget, + datatype, + parameters +) values ( + 'textbox_medium', + '#ams.Textbox# - #ams.Medium#', + '#ams.Textboxes# - #ams.Medium#', + 'value', + 'string', + 'text', + 'text', + '{html {size 30}}' +); + +insert into ams_widgets ( + widget_name, + pretty_name, + pretty_plural, + storage_type, + acs_datatype, + widget, + datatype, + parameters +) values ( + 'textbox_large', + '#ams.Textbox# - #ams.Large#', + '#ams.Textboxes# - #ams.Large#', + 'value', + 'string', + 'text', + 'text', + '{html {size 50}}' +); + +insert into ams_widgets ( + widget_name, + pretty_name, + pretty_plural, + storage_type, + acs_datatype, + widget, + datatype, + parameters +) values ( + 'textarea_small', + '#ams.Textarea# - #ams.Small#', + '#ams.Textareas# - #ams.Small#', + 'value', + 'text', + 'textarea', + 'text', + '{html {cols 60 rows 6}}' +); + +insert into ams_widgets ( + widget_name, + pretty_name, + pretty_plural, + storage_type, + acs_datatype, + widget, + datatype, + parameters +) values ( + 'textarea_small_nospell', + '#ams.Textarea# - #ams.Small# - #ams.No_Spellcheck#', + '#ams.Textareas# - #ams.Small# - #ams.No_Spellcheck#', + 'value', + 'text', + 'textarea', + 'text', + '{html {cols 60 rows 6}} {nospell}' +); + +insert into ams_widgets ( + widget_name, + pretty_name, + pretty_plural, + storage_type, + acs_datatype, + widget, + datatype, + parameters +) values ( + 'textarea_medium', + '#ams.Textarea# - #ams.Medium#', + '#ams.Textareas# - #ams.Medium#', + 'value', + 'text', + 'textarea', + 'text', + '{html {cols 80 rows 10}}' +); + +insert into ams_widgets ( + widget_name, + pretty_name, + pretty_plural, + storage_type, + acs_datatype, + widget, + datatype, + parameters +) values ( + 'textarea_large', + '#ams.Textarea# - #ams.Large#', + '#ams.Textareas# - #ams.Large#', + 'value', + 'text', + 'textarea', + 'text', + '{html {cols 80 rows 24}}' +); + +insert into ams_widgets ( + widget_name, + pretty_name, + pretty_plural, + storage_type, + acs_datatype, + widget, + datatype, + parameters +) values ( + 'richtext_medium', + '#ams.Richtext# - #ams.Medium#', + '#ams.Richtexts# - #ams.Medium#', + 'value_with_mime_type', + 'text', + 'richtext', + 'richtext', + '{html {cols 80 rows 10}}' +); + +insert into ams_widgets ( + widget_name, + pretty_name, + pretty_plural, + storage_type, + acs_datatype, + widget, + datatype, + parameters +) values ( + 'richtext_large', + '#ams.Richtext# - #ams.Large#', + '#ams.Richtexts# - #ams.Large#', + 'value_with_mime_type', + 'text', + 'richtext', + 'richtext', + '{html {cols 80 rows 24}}' +); + + +insert into ams_widgets ( + widget_name, + pretty_name, + pretty_plural, + storage_type, + acs_datatype, + widget, + datatype, + parameters +) values ( + 'email', + '#ams.Email_Address#', + '#ams.Email_Addresses#', + 'value', + 'email', + 'text', + 'email', + '{html {size 30}}' +); + +insert into ams_widgets ( + widget_name, + pretty_name, + pretty_plural, + storage_type, + acs_datatype, + widget, + datatype, + parameters +) values ( + 'url', + '#ams.Url#', + '#ams.Urls#', + 'value', + 'url', + 'text', + 'url', + '{html {size 30}}' +); + + + Index: openacs-4/packages/ams/sql/postgresql/telecom-number-missing-plsql.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/sql/postgresql/telecom-number-missing-plsql.sql,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/ams/sql/postgresql/telecom-number-missing-plsql.sql 20 Oct 2004 21:40:04 -0000 1.1 +++ openacs-4/packages/ams/sql/postgresql/telecom-number-missing-plsql.sql 18 May 2005 17:11:48 -0000 1.2 @@ -1,43 +1,43 @@ --- --- packages/ams/sql/postgresql/telecom-number-missing-plsql.sql --- --- @author Matthew Geddert openacs@geddert.com --- @creation-date 2004-09-07 --- @cvs-id $Id$ --- --- - --- --- This file can safely be deleted once telecom number fixes a bug #2099 --- I filed that has this code commented out --- - -create function inline_0 () -returns integer as ' -declare - v_telecom_number_p boolean; -begin - v_telecom_number_p := ''1'' from acs_object_types where object_type = ''telecom_number''; - - if v_telecom_number_p then - else - PERFORM acs_object_type__create_type ( - ''telecom_number'', -- object_type - ''Telecom Number'', -- pretty_name - ''Telecom Number'', -- pretty_plural - ''acs_object'', -- supertype - ''telecom_numbers'', -- table_name - ''number_id'', -- id_column - ''telecom_number'', -- package_name - ''f'', -- abstract_p - null, -- type_extension_table - null -- name_method - ); - end if; - - return 0; -end;' language 'plpgsql'; - -select inline_0 (); - -drop function inline_0 (); +-- +-- packages/ams/sql/postgresql/telecom-number-missing-plsql.sql +-- +-- @author Matthew Geddert openacs@geddert.com +-- @creation-date 2004-09-07 +-- @cvs-id $Id$ +-- +-- + +-- +-- This file can safely be deleted once telecom number fixes a bug #2099 +-- I filed that has this code commented out +-- + +create function inline_0 () +returns integer as ' +declare + v_telecom_number_p boolean; +begin + v_telecom_number_p := ''1'' from acs_object_types where object_type = ''telecom_number''; + + if v_telecom_number_p then + else + PERFORM acs_object_type__create_type ( + ''telecom_number'', -- object_type + ''Telecom Number'', -- pretty_name + ''Telecom Number'', -- pretty_plural + ''acs_object'', -- supertype + ''telecom_numbers'', -- table_name + ''number_id'', -- id_column + ''telecom_number'', -- package_name + ''f'', -- abstract_p + null, -- type_extension_table + null -- name_method + ); + end if; + + return 0; +end;' language 'plpgsql'; + +select inline_0 (); + +drop function inline_0 (); Index: openacs-4/packages/ams/tcl/address-widget-procs-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/tcl/address-widget-procs-postgresql.xql,v diff -u -N -r1.2 -r1.3 --- openacs-4/packages/ams/tcl/address-widget-procs-postgresql.xql 27 Feb 2005 17:07:17 -0000 1.2 +++ openacs-4/packages/ams/tcl/address-widget-procs-postgresql.xql 18 May 2005 17:11:48 -0000 1.3 @@ -1,11 +1,10 @@ -postgresql7.2 - select default_name, iso from countries order by default_name + select default_name, iso from countries s Index: openacs-4/packages/ams/tcl/address-widget-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/tcl/address-widget-procs.tcl,v diff -u -N -r1.2 -r1.3 --- openacs-4/packages/ams/tcl/address-widget-procs.tcl 21 Oct 2004 01:53:49 -0000 1.2 +++ openacs-4/packages/ams/tcl/address-widget-procs.tcl 18 May 2005 17:11:48 -0000 1.3 @@ -44,7 +44,29 @@ {postal_type {}} } { # MGEDDERT TODO, convert country code to country name via cached proc - set country $country_code + if { [ad_conn isconnected] } { + # We are in an HTTP connection (request) so use that locale + set locale [ad_conn locale] + } else { + # There is no HTTP connection - resort to system locale + set locale [lang::system::locale] + } + set key "ams.country_${country_code}" + if { [string is true [lang::message::message_exists_p $locale $key]] } { + set country [lang::message::lookup $locale $key] + } else { + # cache the country codes + template::util::address::country_options_not_cached -locale $locale + + if { [string is true [lang::message::message_exists_p $locale $key]] } { + set country [lang::message::lookup $locale $key] + } else { + # we get the default en_US key which was created with the + # template::util::address::country_options_not_cached proc + set country [lang::message::lookup "en_US" $key] + } + } + set address "$delivery_address $municipality, $region $postal_code $country" @@ -69,13 +91,51 @@ ad_proc -public template::util::address::country_options {} { Returns the country list. Cached. } { - return [util_memoize [list template::util::address::country_options_not_cached]] + if { [ad_conn isconnected] } { + # We are in an HTTP connection (request) so use that locale + set locale [ad_conn locale] + } else { + # There is no HTTP connection - resort to system locale + set locale [lang::system::locale] + } + return [util_memoize [list template::util::address::country_options_not_cached -locale $locale]] } -ad_proc -public template::util::address::country_options_not_cached {} { +ad_proc -public template::util::address::country_options_not_cached { + {-locale "en_US"} +} { Returns the country list. } { - return [db_list_of_lists get_countries {}] + set country_list [db_list_of_lists get_countries {}] + set return_country_list [list] + foreach country $country_list { + set this_locale $locale + set country_name_db [lindex $country 0] + set country_code_db [lindex $country 1] + set package_key "ams" + set message_key "country_${country_code_db}" + set key "${package_key}.${message_key}" + if { [string is false [lang::message::message_exists_p $locale $key]] } { + if { [string is false [lang::message::message_exists_p "en_US" $key]] } { + lang::message::register $locale $package_key $message_key $country_name_db + } else { + set this_locale "en_US" + } + } + # mgeddert customization for mbbs + if { [lsearch [list US CA] $country_code_db] < 0 } { + # the reason not to use the "list" command here is because a curly bracket + # needs to be used in the list for countries with a single word name + # so that alphabetizing (via lsort) works later on in this proc + lappend return_country_list "{[lang::message::lookup $this_locale $key]} {$country_code_db}" + } + } + set country_code [list] + lappend country_code [list "United States" US] + lappend country_code [list "Canada" CA] + lappend country_code [list "--" ""] + append country_code " [lsort $return_country_list]" + return $country_code } ad_proc -public template::data::validate::address { value_ref message_ref } { @@ -249,10 +309,12 @@ set country_code [template::util::address::get_property country_code $address_list] set additional_text [template::util::address::get_property additional_text $address_list] set postal_type [template::util::address::get_property postal_type $address_list] - return [template::util::address::html_view $delivery_address $postal_code $municipality $region $country_code $additional_text $postal_type] + return [template::util::address::html_view $delivery_address $municipality $region $postal_code $country_code $additional_text $postal_type] } default { - error "Parameter supplied to util::address::get_property 'what' must be one of: 'delivery_address', 'postal_code', 'municipality', 'region', 'country_code', 'additional_text', 'postal_type'. You specified: '$what'." + error "Parameter supplied to template::util::address::get_property 'what' must be one of: 'delivery_address', 'postal_code', 'municipality', 'region', 'country_code', 'additional_text', 'postal_type'. You specified: '$what'." + ns_log "AMS Address Widget Error: on page [ad_conn url] template::util::address::get_property asked for $what" + return "" } } @@ -294,25 +356,26 @@ if { [string equal $element(mode) "edit"] } { - set attributes(id) \"address__$element(form_id)__$element(id)\" +# set attributes(id) "address__$element(form_id)__$element(id)" + set attributes(class) "address-widget-country-code" append output " - +
- + - - - + + + - - - + + + Index: openacs-4/packages/ams/tcl/ams-init.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/tcl/ams-init.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ams/tcl/ams-init.tcl 18 May 2005 17:11:48 -0000 1.1 @@ -0,0 +1,9 @@ +ad_library { + Initialization for ams. + + @creation-date 2005-02-10 + @author Matthew Geddert (openacs@geddert.com) + @cvs-id $Id: ams-init.tcl,v 1.1 2005/05/18 17:11:48 matthewg Exp $ +} + +ams::widgets_init Index: openacs-4/packages/ams/tcl/ams-list-procs-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/tcl/ams-list-procs-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ams/tcl/ams-list-procs-postgresql.xql 18 May 2005 17:11:48 -0000 1.1 @@ -0,0 +1,95 @@ + + + + + + + select * + from ams_lists + where list_id = :list_id + + + + + + + select attribute_id + from ams_list_attribute_map + where list_id = :list_id + + + + + + + select '1' + from ams_lists + where package_key = :package_key + and object_type = :object_type + and list_name = :list_name + + + + + + select list_id + from ams_lists + where package_key = :package_key + and object_type = :object_type + and list_name = :list_name + + + + + + + select ams_list__attribute_map ( + :list_id, + :attribute_id, + :sort_order, + :required_p, + :section_heading + ) + + + + + + select sort_order + from ams_list_attribute_map + where list_id = :list_id + order by sort_order desc + limit 1 + + + + + + delete from ams_list_attribute_map + where list_id = :list_id + and attribute_id = :attribute_id + + + + + + update ams_list_attribute_map + set required_p = 't' + where list_id = :list_id + and attribute_id = :attribute_id + + + + + + update ams_list_attribute_map + set required_p = 'f' + where list_id = :list_id + and attribute_id = :attribute_id + + + + + + + Index: openacs-4/packages/ams/tcl/ams-list-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/tcl/ams-list-procs.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ams/tcl/ams-list-procs.tcl 18 May 2005 17:11:48 -0000 1.1 @@ -0,0 +1,232 @@ +ad_library { + + list procs for the ams package + + @author Matthew Geddert openacs@geddert.com + @creation-date 2005-02-14 + @cvs-id $Id: ams-list-procs.tcl,v 1.1 2005/05/18 17:11:48 matthewg Exp $ + +} + +namespace eval ams:: {} +namespace eval ams::list:: {} +namespace eval ams::list::attribute:: {} + +ad_proc -public ams::list::url { + -package_key:required + -object_type:required + -list_name:required + {-pretty_name ""} + {-description ""} + {-return_url ""} + {-return_url_label "Return to Where You Were"} +} { +} { + return [export_vars -base "/ams/list" -url {package_key object_type list_name pretty_name description return_url return_url_label}] +} + +ad_proc -public ams::list::get { + -list_id:required + -array:required +} { + Get the info on an ams_attribute +} { + upvar 1 $array row + db_1row select_list_info {} -column_array row +} + +ad_proc -private ams::list::ams_attribute_ids_not_cached { + -list_id:required +} { + Get a list of ams_attributes. + + @return list of ams_attribute_ids, in the correct order + + @see ams::list::ams_attribute_ids + @see ams::list::ams_attribute_ids_flush +} { + return [db_list ams_attribute_ids {}] +} + +ad_proc -private ams::list::ams_attribute_ids { + -list_id:required +} { + get this lists ams_attribute_ids. Cached. + + @return list of ams_attribute_ids, in the correct order + + @see ams::list::ams_attribute_ids_not_cached + @see ams::list::ams_attribute_ids_flush +} { + return [util_memoize [list ams::list::ams_attribute_ids_not_cached -list_id $list_id]] +} + +ad_proc -private ams::list::ams_attribute_ids_flush { + -list_id:required +} { + Flush this lists ams_attribute_ids cache. + + @return list of ams_attribute_ids, in the correct order + + @see ams::list::ams_attribute_ids_not_cached + @see ams::list::ams_attribute_ids +} { + return [util_memoize_flush [list ams::list::ams_attribute_ids_not_cached -list_id $list_id]] +} + + + +ad_proc -private ams::list::exists_p { + -package_key:required + -object_type:required + -list_name:required +} { + does an ams list like this exist? + + @return 1 if the list exists for this object_type and package_key and 0 if the does not exist +} { + set list_id [ams::list::get_list_id_not_cached -package_key $package_key -object_type $object_type -list_name $list_name] + if { [exists_and_not_null list_id] } { + return 1 + } else { + return 0 + } +} + +ad_proc -private ams::list::flush { + -package_key:required + -object_type:required + -list_name:required +} { + flush all inte info we have on an ams_list + + @return 1 if the list exists for this object_type and package_key and 0 if the does not exist +} { + ams::list::ams_attribute_ids_flush -list_id [ams::list::get_list_id_not_cached -package_key $package_key -object_type $object_type -list_name $list_name] + ams::list::get_list_id_flush -package_key $package_key -object_type $object_type -list_name $list_name +} + +ad_proc -private ams::list::get_list_id { + -package_key:required + -object_type:required + -list_name:required +} { + + return the list_id for the given parameters. Chached. + + @return list_id if none exists then it returns blank +} { + return [util_memoize [list ams::list::get_list_id_not_cached -package_key $package_key -object_type $object_type -list_name $list_name]] +} + + +ad_proc -private ams::list::get_list_id_not_cached { + -package_key:required + -object_type:required + -list_name:required +} { + return the list_id for the given parameters + + @return list_id if none exists then it returns blank +} { + + return [db_string get_list_id {} -default {}] +} + +ad_proc -private ams::list::get_list_id_flush { + -package_key:required + -object_type:required + -list_name:required +} { + + flush the memorized list_id for the given parameters. + + @return list_id if none exists then it returns blank +} { + return [util_memoize_flush [list ams::list::get_list_id_not_cached -package_key $package_key -object_type $object_type -list_name $list_name]] +} + +ad_proc -public ams::list::new { + {-list_id ""} + -package_key:required + -object_type:required + -list_name:required + -pretty_name:required + {-description ""} + {-description_mime_type "text/plain"} + {-context_id ""} +} { + create a new ams_group + + @return group_id +} { + if { [empty_string_p $context_id] } { + set context_id [ams::package_id] + } + if { ![exists_and_not_null description] } { + set description_mime_type "" + } + + set extra_vars [ns_set create] + oacs_util::vars_to_ns_set -ns_set $extra_vars -var_list { list_id package_key object_type list_name pretty_name description description_mime_type } + set list_id [package_instantiate_object -extra_vars $extra_vars ams_list] + + return $list_id +} + + + +ad_proc -public ams::list::attribute::map { + -list_id:required + -attribute_id:required + {-sort_order ""} + {-required_p "f"} + {-section_heading ""} +} { + Map an ams option for an attribute to an option_map_id, if no value is supplied for option_map_id a new option_map_id will be created. + + @param sort_order if null then the attribute will be placed as the last attribute in this groups sort order + + @return option_map_id +} { + if { ![exists_and_not_null sort_order] } { + set sort_order [expr 1 + [db_string get_highest_sort_order {} -default "0"]] + } + return [db_exec_plsql ams_list_attribute_map {}] +} + +ad_proc -public ams::list::attribute::unmap { + -list_id:required + -attribute_id:required +} { + Unmap an ams option from an ams list +} { + db_dml ams_list_attribute_unmap {} +} + +ad_proc -public ams::list::attribute::required { + -list_id:required + -attribute_id:required +} { + Specify and ams_attribute as required in an ams list +} { + db_dml ams_list_attribute_required {} +} + +ad_proc -public ams::list::attribute::optional { + -list_id:required + -attribute_id:required +} { + Specify and ams_attribute as optional in an ams list +} { + db_dml ams_list_attribute_optional {} +} + + + + + + + + + Index: openacs-4/packages/ams/tcl/ams-procs-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/tcl/ams-procs-postgresql.xql,v diff -u -N -r1.7 -r1.8 --- openacs-4/packages/ams/tcl/ams-procs-postgresql.xql 27 Feb 2005 17:07:17 -0000 1.7 +++ openacs-4/packages/ams/tcl/ams-procs-postgresql.xql 18 May 2005 17:11:48 -0000 1.8 @@ -1,748 +1,87 @@ - - -postgresql7.2 - - - - select ams_attribute_id, required_p - from ams_list_attribute_map - where list_id = :list_id - order by sort_order - - - - - - select ams_object_id(:object_id) - - - - - - select ams_object__new( - :object_id, - :package_id, - now(), - :creation_user, - :creation_ip - ); - - - - - - select ams_option__new (:ams_attribute_id,:option,:sort_order) - - - - - - select ams_option__delete (:option_id) - - - - - - - select ams_option__map (:option_map_id,:option_id) - - - - - - select ams.*, - acs.attribute_name, - acs.pretty_name, - acs.pretty_plural, - acs.object_type, - aw.storage_type - from ams_attributes ams, - acs_attributes acs, - ams_widgets aw - where ams.ams_attribute_id = :ams_attribute_id - and ams.attribute_id = acs.attribute_id - and ams.widget_name = aw.widget_name - - - - - - select ac.attribute_name, - ac.pretty_name, - ac.object_type, - aw.widget, - aw.datatype, - aw.parameters, - aw.storage_type - from ams_attributes aa, - acs_attributes ac, - ams_widgets aw - where aa.ams_attribute_id = :ams_attribute_id - and aa.attribute_id = ac.attribute_id - and aa.widget_name = aw.widget_name - - - - - - select option, option_id - from ams_options - where ams_attribute_id = :ams_attribute_id - order by sort_order - - - - - - select '1' from acs_attributes where object_type = :object_type and attribute_name = :attribute_name - - - - - - select ams.ams_attribute_id - from ams_attributes ams, acs_attributes acs - where acs.object_type = :object_type - and acs.attribute_name = :attribute_name - and acs.attribute_id = ams.attribute_id - - - - - - select ams_attribute__name (:ams_attribute_id) - - - - - - select aw.storage_type - from ams_widgets aw, ams_attributes aa - where aa.ams_attribute_id = :ams_attribute_id - and aw.widget_name = aa.widget_name - - - - - - select ams_attribute__delete (:ams_attribute_id) - - - - - - select aav.*, - ao.object_id, - ams_attribute__options_string(option_map_id) as options_string, - ams_attribute__postal_address_string(address_id) as address_string, - ams_attribute__telecom_number_string(number_id) as telecom_number_string - from ams_attribute_values aav, cr_revisions cr, ams_objects ao - where ao.object_id in ($sql_object_id_list) - and ao.ams_object_id = cr.item_id - and cr.revision_id = aav.revision_id - and aav.superseed_revision_id is null - order by ao.object_id, aav.ams_attribute_id - - - - - - select ams_attribute_value__new ( - :revision_id, - :ams_attribute_id, - :option_map_id, - :address_id, - :number_id, - :time, - :value, - :value_mime_type - ) - - - - - - - select ams_attribute_value__save ( - :revision_id, - :ams_attribute_id, - :option_map_id, - :address_id, - :number_id, - :time, - :value, - :value_mime_type - ) - - - - - - select acs_object__new ( - null, - 'telecom_number', - ( select creation_date from acs_objects where object_id = :revision_id ), - ( select creation_user from acs_objects where object_id = :revision_id ), - ( select creation_ip from acs_objects where object_id = :revision_id ), - :revision_id - ) - - - - - - insert into telecom_numbers ( - number_id, - itu_id, - national_number, - area_city_code, - subscriber_number, - extension, - sms_enabled_p, - best_contact_time, - location, - phone_type_id - ) values ( - :number_id, - :itu_id, - :national_number, - :area_city_code, - :subscriber_number, - :extension, - :sms_enabled_p, - :best_contact_time, - :location, - :phone_type_id - ) - - - - - - select acs_object__new ( - null, - 'postal_address', - ( select creation_date from acs_objects where object_id = :revision_id ), - ( select creation_user from acs_objects where object_id = :revision_id ), - ( select creation_ip from acs_objects where object_id = :revision_id ), - :revision_id - ) - - - - - - insert into postal_addresses ( - address_id, - delivery_address, - municipality, - region, - postal_code, - country_code, - additional_text, - postal_type - ) values ( - :address_id, - :delivery_address, - :municipality, - :region, - :postal_code, - :country_code, - :additional_text, - :postal_type - ) - - - - - - insert into ams_attribute_values - (revision_id,ams_attribute_id,option_map_id,address_id,number_id,time,value,value_mime_type) - values - (:revision_id,:ams_attribute_id,:option_map_id,:address_id,:number_id,:time,:value,:value_mime_type) - - - - - - update ams_attribute_values - set superseed_revision_id = :revision_id - where ams_attribute_id = :ams_attribute_id - and superseed_revision_id is null - and revision_id in ( select revision_id - from cr_revisions - where item_id = :ams_object_id - and revision_id <> :revision_id ) - - - - - - select * - from ams_lists - where list_id = :list_id - - - - - - - select ams_attribute_id - from ams_list_attribute_map - where list_id = :list_id - - - - - - - select '1' - from ams_lists - where package_key = :package_key - and object_type = :object_type - and list_name = :list_name - - - - - - select list_id - from ams_lists - where package_key = :package_key - and object_type = :object_type - and list_name = :list_name - - - - - - - select ams_list__attribute_map ( - :list_id, - :ams_attribute_id, - :sort_order, - :required_p, - :section_heading - ) - - - - - - select sort_order - from ams_list_attribute_map - where list_id = :list_id - order by sort_order desc - limit 1 - - - - - - delete from ams_list_attribute_map - where list_id = :list_id - and ams_attribute_id = :ams_attribute_id - - - - - - update ams_list_attribute_map - set required_p = 't' - where list_id = :list_id - and ams_attribute_id = :ams_attribute_id - - - - - - update ams_list_attribute_map - set required_p = 'f' - where list_id = :list_id - and ams_attribute_id = :ams_attribute_id - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - select * from postal_addresses where address_id = :address_id - - - - - - - select telecom_number__new ( - :area_city_code, - :best_contact_time, - :extension, - :itu_id, - :location, - :national_number, - null, - null, - null, - :sms_enabled_p, - :subscriber_number, - :creation_user, - :creation_ip, - null - ) - - - - - - - select * from telecom_numbers where number_id = :number_id - - - - - - - select * - from contact_attributes ca, - contact_widgets cw, - contact_attribute_object_map caom, - contact_attribute_names can - where caom.object_id = :object_id - and ca.ams_attribute_id = can.ams_attribute_id - and can.locale = :locale - and caom.ams_attribute_id = ca.ams_attribute_id - and ca.widget_id = cw.widget_id - and not ca.depreciated_p - and acs_permission__permission_p(ca.ams_attribute_id,:user_id,'write') - order by caom.sort_order - - - - - - - - select ca.ams_attribute_id, - ca.attribute, - cav.option_map_id, - cav.address_id, - cav.number_id, - to_char(cav.time,'YYYY MM DD') as time, - cav.value, - cav.value_format, - cw.storage_column - from contact_attributes ca, - contact_widgets cw, - contact_attribute_object_map caom left join - ( select * - from contact_attribute_values - where party_id = :party_id - and not deleted_p ) cav - on (caom.ams_attribute_id = cav.ams_attribute_id) - where caom.object_id = '$object_id' - and caom.ams_attribute_id = ca.ams_attribute_id - and ca.widget_id = cw.widget_id - and not ca.depreciated_p - and ( - cav.option_map_id is not null - or cav.address_id is not null - or cav.number_id is not null - or cav.value is not null - or cav.time is not null - or ca.attribute in ($custom_field_sql_list) - ) - and acs_permission__permission_p(ca.ams_attribute_id,'$user_id','$permission') - order by caom.sort_order - - - - - - - select name - from organizations - where organization_id = :party_id - - - - - - - select legal_name - from organizations - where organization_id = :party_id - - - - - - - select reg_number - from organizations - where organization_id = :party_id - - - - - - - select first_names - from persons - where person_id = :party_id - - - - - - - select cao.option_id, cao.option - from contact_attribute_options cao, - organization_types ot, - organization_type_map otm - where cao.option = ot.type - and cao.ams_attribute_id = :ams_attribute_id - and otm.organization_type_id = ot.organization_type_id - and otm.organization_id = :party_id - - - - - - - select first_names - from persons - where person_id = :party_id - - - - - - - select last_name - from persons - where person_id = :party_id - - - - - - - select email - from parties - where party_id = :party_id - - - - - - - select url - from parties - where party_id = :party_id - - - - - - - select cao.option, cao.option_id - from contact_attribute_options cao, - contact_attribute_option_map caom - where caom.option_id = cao.option_id - and caom.option_map_id = :option_map_id - - - - - - select * - from contact_attributes ca, - contact_widgets cw, - contact_attribute_object_map caom, - contact_attribute_names can - where caom.object_id = :object_id - and ca.ams_attribute_id = can.ams_attribute_id - and can.locale = :locale - and caom.ams_attribute_id = ca.ams_attribute_id - and ca.widget_id = cw.widget_id - and not ca.depreciated_p - and acs_permission__permission_p(ca.ams_attribute_id,:user_id,'write') - order by caom.sort_order - - - - - - - select cav.address_id as old_address_id - from contact_attribute_values cav, - postal_addresses pa - where cav.party_id = :party_id - and cav.ams_attribute_id = :ams_attribute_id - and not cav.deleted_p - and cav.address_id = pa.address_id - and pa.delivery_address = :delivery_address - and pa.municipality = :municipality - and pa.region = :region - and pa.postal_code = :postal_code - and pa.country_code = :country_code - - - - - - - select cav.number_id as old_number_id - from contact_attribute_values cav, - telecom_numbers tn - where cav.party_id = :party_id - and cav.ams_attribute_id = :ams_attribute_id - and not cav.deleted_p - and cav.number_id = tn.number_id - and tn.subscriber_number = :attribute_value_temp - - - - - - - select option_map_id - from contact_attribute_values - where party_id = :party_id - and ams_attribute_id = :ams_attribute_id and not deleted_p - - - - - - - select option_id - from contact_attribute_option_map - where option_map_id = :option_map_id - - - - - - - select nextval('contact_attribute_option_map_id_seq') as option_map_id - - - - - - - insert into contact_attribute_option_map - (option_map_id,party_id,option_id) - values - (:option_map_id,:party_id,:option_id) - - - - - - - update parties set email = :attribute_value_temp where party_id = :party_id - - - - - - - update parties set url = :attribute_value_temp where party_id = :party_id - - - - - - - update organizations set name = :attribute_value_temp where organization_id = :party_id - - - - - - - update organizations set legal_name = :attribute_value_temp where organization_id = :party_id - - - - - - - update organizations set reg_number = :attribute_value_temp where organization_id = :party_id - - - - - - - delete from organization_type_map where organization_id = :party_id - - - - - - - select organization_type_id - from contact_attribute_options cao, - organization_types ot - where cao.option = ot.type - and cao.option_id = :option_id - - - - - - - insert into organization_type_map - (organization_id, organization_type_id) - values - (:party_id, :organization_type_id) - - - - - - - update persons set first_names = :attribute_value_temp where person_id = :party_id - - - - - - - update persons set last_name = :attribute_value_temp where person_id = :party_id - - - - - + + + + + + select acs_attribute__create_attribute ( + :object_type, + :attribute_name, + :datatype, + :pretty_name, + :pretty_plural, + :table_name, + :column_name, + :default_value, + :min_n_values, + :max_n_values, + :sort_order, + :storage, + :static_p + ) + + + + + + select attribute_id + from acs_attributes + where object_type = :object_type + and attribute_name = :attribute_name + + + + + + select ams_attribute_value__save ( + :object_id, + :attribute_id, + :value_id + ) + + + + + + select alam.attribute_id, + alam.required_p, + alam.section_heading, + aa.attribute_name, + aa.pretty_name, + aa.widget + from ams_list_attribute_map alam, + ams_attributes aa + where alam.attribute_id = aa.attribute_id + and alam.list_id = :list_id + order by alam.sort_order + + + + + + select alam.attribute_id, + alam.required_p, + alam.section_heading, + aa.attribute_name, + aa.pretty_name, + aa.widget + from ams_list_attribute_map alam, + ams_attributes aa + where alam.attribute_id = aa.attribute_id + and alam.list_id = :list_id + order by alam.sort_order + + + + + + select aav.*, aa.attribute_name, aa.widget, aa.pretty_name, + ams_attribute_value__value(aav.attribute_id,aav.value_id) as value + from ams_attribute_values aav, + ams_attributes aa + where aav.object_id = :object_id + and aav.attribute_id = aa.attribute_id + and aa.attribute_id in ( select attribute_id from ams_list_attribute_map where list_id = :list_id ) + + + + Index: openacs-4/packages/ams/tcl/ams-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/tcl/ams-procs.tcl,v diff -u -N -r1.7 -r1.8 --- openacs-4/packages/ams/tcl/ams-procs.tcl 30 Oct 2004 00:23:54 -0000 1.7 +++ openacs-4/packages/ams/tcl/ams-procs.tcl 18 May 2005 17:11:48 -0000 1.8 @@ -9,216 +9,66 @@ } +namespace eval attribute:: {} +namespace eval ams:: {} +namespace eval ams::attribute {} +namespace eval ams::option {} +namespace eval ams::ad_form {} -ad_proc -public ams_object_id { - -object_id:required +ad_proc -public attribute::pretty_name { + {-attribute_id:required} } { - @param object_id - Returns the revision controlled ams_object_id for the given openacs object_id. Cached. - @return ams_object_id + get the pretty_name of an attribute } { - return [util_memoize [list ams_object_id_not_cached -object_id $object_id]] + return [db_string get_pretty_name { select pretty_name from ams_attributes where attribute_id = :attribute_id } -default {}] } -ad_proc -private ams_object_id_not_cached { - -object_id:required +ad_proc -public attribute::pretty_plural { + {-attribute_id:required} } { - @param object_id - Returns the revision controlled ams_object_id for the given openacs object_id. - @return ams_object_id + get the pretty_plural of an attribute } { - set ams_object_id [db_string select_ams_object_id {} -default {}] - if { [exists_and_not_null ams_object_id] } { - return $ams_object_id - } else { - set package_id [ams::package_id] - set creation_user [ad_conn user_id] - set creation_ip [ad_conn peeraddr] - return [db_string create_and_select_ams_object_id {}] - } + return [db_string get_pretty_name { select pretty_plural from ams_attributes where attribute_id = :attribute_id } -default {}] } -ad_proc -public ams_form { - -package_key:required +ad_proc -public attribute::new { -object_type:required - -list_name:required - -form_name:required - -object_id:required - -return_url:required -} { - TODO DOCUMENTATION -} { - - set edit_proc "ams::object::attribute::values -vars -object_id $object_id" - set submit_proc "ams::ad_form::save -package_key $package_key -object_type $object_type -list_name $list_name -form_name $form_name -object_id $object_id" - set after_submit_proc "ad_returnredirect $return_url" - - ad_form \ - -name $form_name \ - -form [ams::ad_form::elements -package_key $package_key -object_type $object_type -list_name $list_name -key "object_id"] \ - -edit_request $edit_proc \ - -on_submit $submit_proc \ - -after_submit $after_submit_proc - -} - - -namespace eval ams:: {} - - -ad_proc -public ams::define_list { - -package_key:required - -object_type:required - -list_name:required + -attribute_name:required + -datatype:required -pretty_name:required - {-description ""} - {-description_mime_type ""} - {-reset_order:boolean} - {-attributes} + -pretty_plural:required + {-table_name ""} + {-column_name ""} + {-default_value ""} + {-min_n_values "1"} + {-max_n_values "1"} + {-sort_order ""} + {-storage "generic"} + {-static_p "f"} + {-if_does_not_exist:boolean} } { - TODO: Need Documentation + create a new attribute - @param object_type the acs object_type these attributes are to belong to - @param attributes An array of attributes, if the attribute exists for this object this proc will make sure a duplicate is not created - - @see ams::define_attributes + @see ams::attribute::new } { - - # now we check to see if this list already exists - if { ![ams::list::exists_p -package_key $package_key -object_type $object_type -list_name $list_name] } { - set list_id [ams::list::new -list_name $list_name \ - -package_key $package_key \ - -object_type $object_type \ - -pretty_name $pretty_name \ - -description $description \ - -description_mime_type $description_mime_type] - + if { $if_does_not_exist_p } { + set attribute_id [attribute::id -object_type $object_type -attribute_name $attribute_name] + if { [string is false [exists_and_not_null attribute_id]] } { + set attribute_id [db_string create_attribute {}] + } } else { - set list_id [ams::list::get_list_id -package_key $package_key -object_type $object_type -list_name $list_name] + set attribute_id [db_string create_attribute {}] } - - foreach { attribute } $attributes { - # the attribute follows this order - # attribute_name widget_name pretty_name pretty_plural extra_args - set attribute_name [lindex $attribute 0] - set widget_name [lindex $attribute 1] - set pretty_name [lindex $attribute 2] - set pretty_plural [lindex $attribute 3] - # we set the defaults for values that are required - set required_p 0 - set default_name {} - set description {} - set default_value {} - set context_id {} - set options {} - # we now check for other values - set i 4 - while { $i < [llength $attribute] } { - set arg [lindex $attribute $i] - switch [lindex $arg 0] { - required { set required_p 1 } - default { set [lindex $arg 0] [lindex $arg 1] } - } - incr i - } - set ams_attribute_id [ams::attribute::new -object_type $object_type \ - -attribute_name $attribute_name \ - -widget_name $widget_name \ - -pretty_name $pretty_name \ - -pretty_plural $pretty_plural \ - -default_value $default_value \ - -description $description \ - -context_id $context_id \ - -options $options \ - -no_complain] - - if { ![exists_and_not_null ams_attribute_id] && $reset_order_p } { - set ams_attribute_id [ams::attribute::get_ams_attribute_id -object_type $object_type -attribute_name $attribute_name] - } - if { [exists_and_not_null ams_attribute_id] } { - ams::list::attribute::map -list_id $list_id \ - -ams_attribute_id $ams_attribute_id \ - -required_p $required_p - } - } - ams::list::get_list_id_flush -package_key $package_key -object_type $object_type -list_name $list_name - + return $attribute_id } - -ad_proc -public ams::define_attributes { +ad_proc -public attribute::id { -object_type:required - -attributes:required + -attribute_name:required } { - TODO: Need Documentation - TODO: Verify the attributes passed in - - @param object_type the acs object_type these attributes are to belong to - @param attributes An array of attributes, if the attribute exists for this object this proc will make sure a duplicate is not created - - @see ams::define_list - -

- This Procedure implements a high level declarative syntax for the generation of ams_attributes - and attribute lists. Those attribute lists can then be used to create ad_form elements, columns - in a listbuilder array or via your own custom choosing by integrating with an ams generated - multirow that you can use however you want in your package. -

-

-

-
- - Here is an example of the ams::define_list proc used by the contacts package: - -
-    ams::define_list -package_key "contacts" \
-        -object_type "ct_contact" \
-        -list_name "contact_person_ae" \
-        -pretty_name "The Fields used to Add/Edit a Contact Person" \
-        -attributes {
-            {first_names textbox {First Name(s)} {First Names} {} {} required}
-            {middle_names textbox {Middle Name(s)} {Middle Names} {} {}}
-            {last_name textbox {Last Name} {Last Names} {} {} required}
-            {email email {Email Address} {Email Addresses} {} {}}
-            {url url {Website} {Websites} {} {}}
-            {home_address address {Home Address} {Home Addresses}}
-            {organization_address address {Organization Address} {Organization Addresses}}
-        }
-    
- - -

Some form builder datatypes build values that do not directly correspond to database types. When using - the form builder directly these are converted by calls to datatype::get_property and datatype::acquire. - When using ad_form, "to_html(property)", "to_sql(property)" and "from_sql(property)" declare the appropriate - properties to be retrieved or set before calling code blocks that require the converted values. The "to_sql" - operation is performed before any on_submit, new_data or edit_data block is executed. The "from_sql" operation - is performed after a select_query or select_query_name query is executed. No automatic conversion is performed - for edit_request blocks (which manually set form values). The "to_html" operation is performed before execution - of a confirm template.

- -

Currently only the date and currency datatypes require these conversion operations.

- -

In the future the form builder will be enhanced so that ad_form can determine the proper conversion operation - automatically, freeing the programmer from the need to specify them. When this is implemented the current notation - will be retained for backwards compatibility.

- + return the attribute_id for the specified attribute } { - set returner "" - foreach { attribute } $attributes { - # the attribute follows this order - # attribute_name widget_name pretty_name pretty_plural default_value description - - ams::attribute::new -object_type $object_type \ - -attribute_name [lindex $attribute 0] \ - -widget_name [lindex $attribute 1] \ - -pretty_name [lindex $attribute 2] \ - -pretty_plural [lindex $attribute 3] \ - -default_value [lindex $attribute 4] \ - -description [lindex $attribute 5] \ - -no_complain - - } - return $returner + return [db_string get_attribute_id {} -default {}] } ad_proc -public ams::package_id {} { @@ -231,1096 +81,200 @@ return [ad_conn package_id] } - -ad_proc -public ams::lang_key_encode { - {-len "175"} - -string:required -} { - @param len the default value was chosen because the lang key length must be less than 200 due to a character limit on the lang_messages.message_key column and because ams depends on using some of that length for key definitions. - - @return an acs_lang encoded message key string -} { - # we add the space at the end to prevent ellipsis at the and then remove it with string trim in order to prevent ellipsis - return [string trim [string_truncate -len [expr $len + 1] -ellipsis " " [ad_urlencode $string]]] -} - - -namespace eval ams::ad_form {} - -ad_proc -public ams::ad_form::save { - -package_key:required +ad_proc -public ams::object_parents { -object_type:required - -list_name:required - -form_name:required - -object_id:required + -sql:boolean + -hide_current:boolean + -show_root:boolean } { - this code saves attributes input in a form + @param sql if selected the list will be formatted in a way suitable for inclusion in sql statements + @param hide_current hide the current object_type + @param show_root show the root object_type (the acs_object object type) + @return a list of the parent object_types } { - - set list_id [ams::list::get_list_id -package_key $package_key -object_type $object_type -list_name $list_name] - - ams::object::attribute::values -ids -array "oldvalues" -object_id $object_id - set ams_attribute_ids [ams::list::ams_attribute_ids -list_id $list_id] - set variables {} - - foreach ams_attribute_id $ams_attribute_ids { - set storage_type [ams::attribute::storage_type -ams_attribute_id $ams_attribute_id] - set attribute_name [ams::attribute::name -ams_attribute_id $ams_attribute_id] - set attribute_value [template::element::get_value $form_name $attribute_name] - if { $storage_type == "ams_options" } { - # we always order the options_string in the order of the option_id - # when doing internal processing - set attribute_value [lsort [template::element::get_values $form_name $attribute_name]] - } - if { [info exists oldvalues($ams_attribute_id)] } { - if { $attribute_value != $oldvalues($ams_attribute_id) } { - lappend variables $ams_attribute_id $attribute_value - } - } else { - if { [exists_and_not_null attribute_value] } { - lappend variables $ams_attribute_id $attribute_value - } - } + if { [string is false $hide_current_p] } { + set object_types [list $object_type] } - if { [exists_and_not_null variables] } { -# ns_log Notice "$object_id changed vars: $variables" - db_transaction { - ams::object::attribute::values_flush -object_id $object_id - set revision_id [ams::object::revision::new -object_id $object_id] - set ams_object_id [ams_object_id -object_id $object_id] - foreach { ams_attribute_id attribute_value } $variables { - ams::attribute::value::superseed -revision_id $revision_id -ams_attribute_id $ams_attribute_id -ams_object_id $ams_object_id - if { [exists_and_not_null attribute_value] } { - ams::attribute::value::new -revision_id $revision_id -ams_attribute_id $ams_attribute_id -attribute_value $attribute_value - } - } - } + while { $object_type != "acs_object" } { + set object_type [db_string get_next_object_type { select supertype from acs_object_types where object_type = :object_type }] + if { $object_type != "acs_object" } { + lappend object_types $object_type + } } - ams::object::attribute::values -object_id $object_id - return 1 -} - -ad_proc -public ams::ad_form::elements { - -package_key:required - -object_type:required - -list_name:required - {-key ""} -} { - this code saves retrieves ad_form elements -} { - set list_id [ams::list::get_list_id -package_key $package_key -object_type $object_type -list_name $list_name] - - set element_list "" - if { [exists_and_not_null key] } { - lappend element_list "$key\:key" + if { $show_root_p } { + lappend object_types "acs_object" } - db_foreach select_elements {} { - if { $required_p } { - lappend element_list [ams::attribute::widget -ams_attribute_id $ams_attribute_id -required] - } else { - lappend element_list [ams::attribute::widget -ams_attribute_id $ams_attribute_id] - } + if { $sql_p } { + return "'[join $object_types "','"]'" + } else { + return $object_types } - return $element_list } - - -namespace eval ams::option {} - -ad_proc -public ams::option::new { - -ams_attribute_id:required - -option:required - {-locale ""} - {-sort_order ""} +ad_proc -public ams::object_copy { + -from:required + -to:required } { - Create a new ams option for an attribute - - TODO validate that the attribute is in fact one that accepts options.
- TODO auto input sort order if none is supplied
- TODO validate that option from the the string input from ams::lang_key_encode is equal to a pre-existing ams message if it is we need conflict resolution. - - @param ams_attribute_id - @param option This a pretty name option - @param locale This is the locale the option name is in - @param sort_order if null, this option will be sorted after last previously entered option for this attribute - - @return option_id } { - - set lang_key "ams.option:[ams::lang_key_encode -string $option]" - _mr en $lang_key $option - set option $lang_key - - return [db_exec_plsql ams_option_new {}] + db_transaction { + db_dml copy_object { + insert into ams_attribute_values + (object_id,attribute_id,value_id) + ( select :to, + attribute_id, + value_id + from ams_attribute_values + where object_id = :object_id ) + } + } } - -ad_proc -public ams::option::delete { - -option_id:required -} { - Delete an ams option - - @param option_id -} { - db_exec_plsql ams_option_delete {} -} - - -ad_proc -public ams::option::map { - {-option_map_id ""} - -option_id:required -} { - Map an ams option for an attribute to an option_map_id, if no value is supplied for option_map_id a new option_map_id will be created. - - @param option_map_id - @param option_id - - @return option_map_id -} { - return [db_exec_plsql ams_option_map {}] -} - - -namespace eval ams::attribute {} - ad_proc -public ams::attribute::get { - -ams_attribute_id:required + -attribute_id:required -array:required } { Get the info on an ams_attribute } { upvar 1 $array row - db_1row select_attribute_info {} -column_array row + db_1row select_attribute_info { select * from ams_attributes where attribute_id = :attribute_id } -column_array row } -ad_proc -public ams::attribute::flush { - -ams_attribute_id:required -} { - Get the info on an ams_attribute -} { - ams::attribute::get -ams_attribute_id $ams_attribute_id -array attribute_info - - set object_type $attribute_info(object_type) - set attribute_name $attribute_info(attribute_name) - ams::attribute::widget_flush -ams_attribute_id $ams_attribute_id - ams::attribute::exists_p_flush -object_type $object_type -attribute_name $attribute_name - ams::attribute::get_ams_attribute_id_flush -object_type $object_type -attribute_name $attribute_name - ams::attribute::name_flush -ams_attribute_id $ams_attribute_id - ams::attribute::storage_type_flush -ams_attribute_id $ams_attribute_id - -} - - -ad_proc -public ams::attribute::widget { - -ams_attribute_id:required - {-required:boolean} -} { - @return an ad_form encoded attribute widget -} { - set attribute_widget [ams::attribute::widget_cached -ams_attribute_id $ams_attribute_id] - - if { [string is false $required_p] } { - # we need to add the optional flag - set optional_attribute_widget "" - set i "0" - while { $i < [llength $attribute_widget] } { - if { $i == "0" } { - # it is the first element in the list, so we add optional - lappend optional_attribute_widget "[lindex $attribute_widget $i],optional" - } else { - # this is not the first element in the list so we simple add - # it back to the list - lappend optional_attribute_widget [lindex $attribute_widget $i] - } - incr i - } - set attribute_widget $optional_attribute_widget - } - - return $attribute_widget -} - -ad_proc -private ams::attribute::widget_not_cached { - -ams_attribute_id:required -} { - Returns an ad_form encoded attribute widget list, as used by other procs. - @see ams::attribute::widget_cached -} { - db_1row select_attribute {} - - set attribute_widget "${attribute_name}:${datatype}(${widget})" - - lappend attribute_widget [list "label" "\#${pretty_name}\#"] - - if { [exists_and_not_null parameters] } { - # the parameters are already stored in list format - # in the database so we just add them to the list - append attribute_widget " ${parameters}" - } - - if { $storage_type == "ams_options" } { - set options {} - db_foreach select_options {} { - lappend options [list [_ $option] [lindex $option_id]] - } - lappend attribute_widget [list "options" $options] - } - return $attribute_widget -} - -ad_proc -private ams::attribute::widget_cached { - -ams_attribute_id:required -} { - Returns an ad_form encoded attribute widget list, as used by other procs. Cached. - @see ams::attribute::widget_not_cached -} { - return [util_memoize [list ams::attribute::widget_not_cached -ams_attribute_id $ams_attribute_id]] -} - - -ad_proc -private ams::attribute::widget_flush { - -ams_attribute_id:required -} { - Returns an ad_form encoded attribute widget list, as used by other procs. Flush. - @see ams::attribute::widget_not_cached -} { - return [util_memoize_flush [list ams::attribute::widget_not_cached -ams_attribute_id $ams_attribute_id]] -} - - - - - - -ad_proc -private ams::attribute::exists_p { - -object_type:required - -attribute_name:required -} { - - does an attribute with this given attribute_name for this object type exists? - - @return 1 if the attribute_name exists for this object_type and 0 if the attribute_name does not exist -} { - set ams_attribute_id [ams::attribute::get_ams_attribute_id -object_type $object_type -attribute_name $attribute_name] - if { [exists_and_not_null ams_attribute_id] } { - return 1 - } else { - return 0 - } -} - -ad_proc -private ams::attribute::exists_p_flush { - -object_type:required - -attribute_name:required -} { - - does an attribute with this given attribute_name for this object type exists? Flush. - - @return ams_attribute_id if none exists then it returns blank -} { - return [util_memoize_flush [list ams::attribute::get_ams_attribute_id_not_cached -object_type $object_type -attribute_name $attribute_name]] -} - - -ad_proc -private ams::attribute::get_ams_attribute_id { - -object_type:required - -attribute_name:required -} { - - return the ams_attribute_id for the given ams_attriubte_name belonging to this object_type. Cached. - - @return ams_attribute_id if none exists then it returns blank -} { - - return [util_memoize [list ams::attribute::get_ams_attribute_id_not_cached -object_type $object_type -attribute_name $attribute_name]] -} - -ad_proc -private ams::attribute::get_ams_attribute_id_not_cached { - -object_type:required - -attribute_name:required -} { - - return the ams_attribute_id for the given ams_attriubte_name belonging to this object_type. - - @return ams_attribute_id if none exists then it returns blank -} { - - return [db_string get_ams_attribute_id {} -default {}] -} - -ad_proc -private ams::attribute::get_ams_attribute_id_flush { - -object_type:required - -attribute_name:required -} { - - return the ams_attribute_id for the given ams_attriubte_name belonging to this object_type. Flush. - - @return ams_attribute_id if none exists then it returns blank -} { - - return [util_memoize_flush [list ams::attribute::get_ams_attribute_id_not_cached -object_type $object_type -attribute_name $attribute_name]] -} - ad_proc -public ams::attribute::new { + -attribute_id:required {-ams_attribute_id ""} - -object_type:required - -attribute_name:required - -pretty_name:required - -pretty_plural:required - {-default_value ""} - {-description ""} - -widget_name:required - {-deprecated:boolean} + -widget:required + {-dynamic_p "0"} + {-deprecated_p "0"} {-context_id ""} - {-no_complain:boolean} - {-options} } { create a new ams_attribute -

widget_name

-

- This should be a widget_name used by ams. All available widgets can be found at /ams/widgets. -
- - - - @param context_id defaults to package_id - @param no_complain silently ignore attributes that already exist. - @param options a list of options for an ams_object that has the ams_options storage type the options will be ordered in the order of the list - @return ams_attribute_id + @see attribute::new } { + set existing_ams_attribute_id [db_string get_it { select ams_attribute_id from ams_attributes where attribute_id = :attribute_id } -default {}] - switch $widget_name { - textbox { set widget_name "textbox_medium" } - textarea { set widget_name "textarea_medium" } - richtext { set widget_name "richtext_medium" } - address { set widget_name "postal_address" } - phone { set widget_name "telecom_number" } - } - ams::attribute::exists_p_flush -object_type $object_type -attribute_name $attribute_name - if { [ams::attribute::exists_p -object_type $object_type -attribute_name $attribute_name] } { - if { !$no_complain_p } { - error "Attribute $attribute_name Already Exists" "The attribute \"$attribute_name\" already exists for object_type \"$object_type\"" - } else { - return [ams::attribute::get_ams_attribute_id -object_type $object_type -attribute_name $attribute_name] - } + if { [exists_and_not_null existing_ams_attribute_id] } { + return $existing_ams_attribute_id } else { - set lang_key "ams.$object_type\:$attribute_name\:" - set pretty_name_key "$lang_key\pretty_name" - set pretty_plural_key "$lang_key\pretty_plural" - # register lang messages - _mr en $pretty_name_key $pretty_name - _mr en $pretty_plural_key $pretty_plural - - set pretty_name $pretty_name_key - set pretty_plural $pretty_plural_key - - - if { [exists_and_not_null description] } { - set description_key "$lang_key\description" - # register lang messages - _mr en $description_key $description - set description $description_key - } - - - if { [empty_string_p $context_id] } { - set context_id [ams::package_id] - } set extra_vars [ns_set create] - oacs_util::vars_to_ns_set -ns_set $extra_vars -var_list {ams_attribute_id object_type attribute_name pretty_name pretty_plural default_value description widget_name deprecated_p context_id} + oacs_util::vars_to_ns_set -ns_set $extra_vars -var_list {attribute_id ams_attribute_id widget dynamic_p deprecated_p context_id} set ams_attribute_id [package_instantiate_object -extra_vars $extra_vars ams_attribute] - - # now we define options for an attribute - if they are provided and the attribute accepts options - if { [string equal [ams::attribute::storage_type -ams_attribute_id $ams_attribute_id] "ams_options"] && [exists_and_not_null options] } { - foreach { option } $options { - ams::option::new -ams_attribute_id $ams_attribute_id -option $option - } - } return $ams_attribute_id } } - -ad_proc -private ams::attribute::name_not_cached { - -ams_attribute_id:required +ad_proc -public ams::attribute::value_save { + -object_id:required + -attribute_id:required + -value_id:required } { - get the name of an ams_attribute - @return attribute_name - - @see ams::attribute::name - @see ams::attribute::name_flush + save and attribute value } { - return [db_string ams_attribute_name {}] + db_exec_plsql attribute_value_save {} } -ad_proc -public ams::attribute::name { - -ams_attribute_id:required -} { - get the name of an ams_attribute. Cached. - @return attribute pretty_name - - @see ams::attribute::name_not_cached - @see ams::attribute::name_flush +ad_proc -public ams::option::new { + {-option_id ""} + -attribute_id:required + -option:required + {-sort_order ""} + {-deprecated_p "0"} + {-context_id ""} } { - return [util_memoize [list ams::attribute::name_not_cached -ams_attribute_id $ams_attribute_id]] -} - - -ad_proc -private ams::attribute::name_flush { - -ams_attribute_id:required + Create a new ams option for an attribute } { - Flush the storage_type of an ams_attribute. - - @return attribute pretty_name - - @see ams::attribute::name_not_cached - @see ams::attribute::name_flush -} { - util_memoize_flush [list ams::attribute::name_not_cached -ams_attribute_id $ams_attribute_id] + set extra_vars [ns_set create] + oacs_util::vars_to_ns_set -ns_set $extra_vars -var_list {option_id attribute_id option sort_order deprecated_p} + set option_id [package_instantiate_object -extra_vars $extra_vars ams_option] + return $option_id } -ad_proc -public ams::attribute::delete { - -ams_attribute_id:required +ad_proc -public ams::option::delete { + -option_id:required } { - Delete an ams attribute, and all associated attribute values + Delete an ams option @param option_id } { - db_exec_plsql ams_attribute_delete {} + db_exec_plsql ams_option_delete {} } - -ad_proc -private ams::attribute::storage_type_not_cached { - -ams_attribute_id:required +ad_proc -public ams::option::name { + -option_id:required } { - get the storage_type of an ams_attribute + Delete an ams option - @return storage_type - - @see ams::attribute::storage_type - @see ams::attribute::storage_type_flush + @param option_id } { - return [db_string ams_attribute_storage_type {}] + return [db_string get_it { select option from ams_option_types where option_id = :option_id } -default {}] } -ad_proc -public ams::attribute::storage_type { - -ams_attribute_id:required -} { - get the storage_type of an ams_attribute. Cached. - @return attribute pretty_name - - @see ams::attribute::storage_type_not_cached - @see ams::attribute::storage_type_flush -} { - return [util_memoize [list ams::attribute::storage_type_not_cached -ams_attribute_id $ams_attribute_id]] -} - - -ad_proc -private ams::attribute::storage_type_flush { - -ams_attribute_id:required -} { - Flush the storage_type of a cached ams_attribute. - - @return attribute pretty_name - - @see ams::attribute::storage_type_not_cached - @see ams::attribute::storage_type_flush -} { - util_memoize_flush [list ams::attribute::storage_type_not_cached -ams_attribute_id $ams_attribute_id] -} - -ad_proc -public ams::attribute::value { - -object_id:required - -ams_attribute_id:required -} { - this code returns the cached attribute value for a specific ams_attribute -} { - set attribute_values_and_ids [ams::object::attributes::list_format -object_id $object_id] - set attribute_value "" - foreach attribute_value_and_id $attribute_values_and_ids { - if { [lindex $attribute_value_and_id 0] == $ams_attribute_id } { - set attribute_value [lindex $attribute_value_and_id 1] - } - } - return $attribute_value -} - -ad_proc -public ams::attribute::value_from_name { +ad_proc -public ams::ad_form::save { + -package_key:required -object_type:required - -attribute_name:required + -list_name:required + -form_name:required -object_id:required + {-copy_object_id ""} } { - this code returns the cached attribute value for a specific ams_attribute -} { - return [ams::attribute::value -object_id $object_id [ams::attribute::get_ams_attribute_id -object_type $object_type -attribute_name $attribute_name]] -} - - -namespace eval ams::attribute::value {} - -ad_proc -public ams::attribute::value::new { - -revision_id:required - -ams_attribute_id:required - -attribute_value:required -} { this code saves attributes input in a form } { - set storage_type [ams::attribute::storage_type -ams_attribute_id $ams_attribute_id] - set option_map_id "" - set address_id "" - set number_id "" - set time "" - set value "" - set value_mime_type "" - - switch $storage_type { - telecom_number { - # i'm not using the telecom_number plsql code here - # since it creates unnecessary permissions by explicitly - # granting the address creation_user admin rights, This - # is taken care of the the ams_attribute permissions. - # - # plus we want this info to be the bound to the revision_id - # not the associated address_id so we pull it from the database - set itu_id [template::util::telecom_number::get_property itu_id $attribute_value] - set national_number [template::util::telecom_number::get_property national_number $attribute_value] - set area_city_code [template::util::telecom_number::get_property area_city_code $attribute_value] - set subscriber_number [template::util::telecom_number::get_property subscriber_number $attribute_value] - set extension [template::util::telecom_number::get_property extension $attribute_value] - set sms_enabled_p [template::util::telecom_number::get_property sms_enabled_p $attribute_value] - set best_contact_time [template::util::telecom_number::get_property best_contact_time $attribute_value] - set location [template::util::telecom_number::get_property location $attribute_value] - set phone_type_id [template::util::telecom_number::get_property phone_type_id $attribute_value] - - set number_id [db_string create_telecom_number_object {}] - - db_dml create_telecom_number {} - - } - - postal_address { - # i'm not using the postal_address plsql code here - # since it creates unnecessary permissions by explicitly - # granting the address creation_user admin rights, This - # is taken care of the the ams_attribute permissions. - # - # plus we want this info to be the bound to the revision_id - # not the associated address_id so we pull it from the database - set delivery_address [template::util::address::get_property delivery_address $attribute_value] - set postal_code [template::util::address::get_property postal_code $attribute_value] - set municipality [template::util::address::get_property municipality $attribute_value] - set region [template::util::address::get_property region $attribute_value] - set country_code [template::util::address::get_property country_code $attribute_value] - set additional_text [template::util::address::get_property additional_text $attribute_value] - set postal_type [template::util::address::get_property postal_type $attribute_value] - - set address_id [db_string create_postal_address_object {}] - - db_dml create_postal_address {} - } - - ams_options { - # we need to loop through the values - # on the first option_map_id the option_map_id - # will be set. - foreach { option_id } $attribute_value { - set option_map_id [ams::option::map -option_map_id $option_map_id -option_id $option_id] - } - } - - time { - set value $attribute_value - } - - value { - set value $attribute_value - } - - value_with_mime_type { - set value [template::util::richtext::get_property contents $attribute_value] - set value_mime_type [template::util::richtext::get_property format $attribute_value] - } + if { [exists_and_not_null copy_object_id] } { + ams::object_copy -from $object_id -to $copy_object_id } - - db_dml insert_attribute_value {} + set list_id [ams::list::get_list_id -package_key $package_key -object_type $object_type -list_name $list_name] + db_transaction { + db_foreach select_elements {} { + set value_id [ams::widget -widget $widget -request "form_save_value" -attribute_name $attribute_name -pretty_name $pretty_name -form_name $form_name -attribute_id $attribute_id] + ams::attribute::value_save -object_id $object_id -attribute_id $attribute_id -value_id $value_id + } + } } - -ad_proc -public ams::attribute::value::superseed { - -revision_id:required - -ams_attribute_id:required - -ams_object_id:required -} { - superseed an attribute value -} { - db_dml superseed_attribute_value {} -} - -namespace eval ams::multirow {} - -ad_proc -private ams::multirow::extend { +ad_proc -public ams::ad_form::elements { -package_key:required -object_type:required -list_name:required - -multirow:required - -key:required + {-key ""} } { - append ams_attribute_values to a multirow + this code saves retrieves ad_form elements } { - set list_id [ams::list::get_list_id \ - -package_key $package_key \ - -object_type $object_type \ - -list_name $list_name] + set list_id [ams::list::get_list_id -package_key $package_key -object_type $object_type -list_name $list_name] - - # first we make sure all the attribute_values are efficiently cached - # i.e. we only do one trip to the database, instead of one for - # each object in the multirow - set object_id_list "" - template::multirow foreach $multirow { - lappend object_id_list [set $key] + set element_list "" + if { [exists_and_not_null key] } { + lappend element_list "$key\:key" } - if { [exists_and_not_null object_id_list] } { - ams::object::attribute::values_batch_process -object_id_list $object_id_list + db_foreach select_elements {} { + set element [ams::widget -widget $widget -request "ad_form_widget" -attribute_name $attribute_name -pretty_name $pretty_name -optional_p [string is false $required_p] -attribute_id $attribute_id] + if { [exists_and_not_null section_heading] } { + lappend element [list section $section_heading] + } + lappend element_list $element } - - # now we extend the multirow with the ams_attribute_names - set ams_attribute_ids [ams::list::ams_attribute_ids -list_id $list_id] - set ams_attribute_names {} - foreach ams_attribute_id $ams_attribute_ids { - set ams_attribute_name [ams::attribute::name -ams_attribute_id $ams_attribute_id] - lappend ams_attribute_names $ams_attribute_name - template::multirow extend $multirow $ams_attribute_name - } - - # now we populate the multirow with ams_attribute_values - template::multirow foreach $multirow { - # first we set a null value for all ams_attribute_names - # since the ams::object::attribute::values proc only - # returns those ams_attribute_values that do not - # have a null value - foreach ams_attribute_name ams_attribute_names { - set [set $ams_attribute_name] {} - } - ams::object::attribute::values -vars -object_id [set $key] - } + return $element_list } - - -namespace eval ams::object {} - -namespace eval ams::object::attribute {} - - - - -ad_proc -private ams::object::attribute::value_memoize { - -object_id:required - -ams_attribute_id:required - -attribute_value:required -} { - memoize an ams::object::attribute::value -} { - if { [string is true [util_memoize_cached_p [list ams::object::attribute::values_not_cached -object_id $object_id]]] } { - array set $object_id [util_memoize [list ams::object::attribute::values_not_cached -object_id $object_id]] - } - # if a value previously existed it will be superseeded - set ${object_id}($ams_attribute_id) $attribute_value - util_memoize_seed [list ams::object::attribute::values_not_cached -object_id $object_id] [array get ${object_id}] -} - -ad_proc -public ams::object::attribute::value { - -object_id:required - -ams_attribute_id:required -} { -} { - ams::object::attribute::values -array $object_id -object_id $object_id - if { [info exists ${object_id}($ams_attribute_id)] } { - return ${object_id}($ams_attribute_id) - } else { - return {} - } -} - -ad_proc -public ams::object::attribute::values { - -object_id:required - {-ids:boolean} - {-vars:boolean} - {-array ""} -} { - @param ids - if specified we will return the ams_attribute_id instead of the attribute_name - @param array - if specified the attribute values are returned in the given array - @param vars - if sepecified the attribute values vars are returned to the calling environment - - if neither array nor vars are specified then a list is returned -} { - set attribute_values_list [util_memoize [list ams::object::attribute::values_not_cached -object_id $object_id]] - if { !$ids_p } { - set attribute_values_list_with_names "" - foreach { key value } $attribute_values_list { - lappend attribute_values_list_with_names [ams::attribute::name -ams_attribute_id $key] - lappend attribute_values_list_with_names $value - } - set attribute_values_list $attribute_values_list_with_names - } - if { [exists_and_not_null array] } { - upvar $array row - array set row $attribute_values_list - } elseif { $vars_p } { - set attribute_value_info [ns_set create] - foreach { key value } $attribute_values_list { - ns_set put $attribute_value_info $key $value - } - # Now, set the variables in the caller's environment - ad_ns_set_to_tcl_vars -level 2 $attribute_value_info - ns_set free $attribute_value_info - } else { - return $attribute_values_list - } -} - - -ad_proc -private ams::object::attribute::values_not_cached { - -object_id:required -} { -} { - ams::object::attribute::values_batch_process -object_id_list $object_id - if { [string is true [util_memoize_cached_p [list ams::object::attribute::values_not_cached -object_id $object_id]]] } { - return [util_memoize [list ams::object::attribute::values_not_cached -object_id $object_id]] - } else { - return {} - } -} - - -ad_proc -private ams::object::attribute::values_flush { - -object_id:required -} { -} { - return [util_memoize_flush [list ams::object::attribute::values_not_cached -object_id $object_id]] -} - - -ad_proc -private ams::object::attribute::values_batch_process { - -object_id_list:required -} { - @param object_ids a list of object_ids for which to save attributes in their respective caches. - get these objects attribute values in a list format -} { - set objects_to_cache "" - foreach object_id_from_list $object_id_list { - if { [string is false [util_memoize_cached_p [list ams::object::attribute::values -object_id $object_id_from_list]]] } { - lappend objects_to_cache $object_id_from_list - } - } - if { [exists_and_not_null objects_to_cache] } { - set sql_object_id_list [ams::util::sqlify_list -list $objects_to_cache] - db_foreach get_attr_values "" { - switch [ams::attribute::storage_type -ams_attribute_id $ams_attribute_id] { - telecom_number { - set attribute_value $telecom_number_string - } - postal_address { - set attribute_value $address_string - } - ams_options { - set attribute_value $options_string - } - time { - set attribute_value $time - } - value { - set attribute_value $value - } - value_with_mime_type { - set attribute_value [list $value $value_mime_type] - } - } - set ${object_id}($ams_attribute_id) $attribute_value - } - foreach object_id_from_list $object_id_list { - util_memoize_seed [list ams::object::attribute::values_not_cached -object_id $object_id_from_list] [array get ${object_id_from_list}] - } - } -} - - - -namespace eval ams::object::revision {} - - -ad_proc -public ams::object::revision::new { - {-package_id ""} - -object_id:required -} { - create a new ams_object_revision - - @return revision_id -} { - if { [empty_string_p $package_id] } { - set package_id [ams::package_id] - } - set extra_vars [ns_set create] - oacs_util::vars_to_ns_set -ns_set $extra_vars -var_list { object_id package_id } - set revision_id [package_instantiate_object -extra_vars $extra_vars ams_object_revision] - - return $revision_id -} - - - - - - - - - - - - -namespace eval ams::list {} - -ad_proc -public ams::list::get { - -list_id:required - -array:required -} { - Get the info on an ams_attribute -} { - upvar 1 $array row - db_1row select_list_info {} -column_array row -} - -ad_proc -private ams::list::ams_attribute_ids_not_cached { - -list_id:required -} { - Get a list of ams_attributes. - - @return list of ams_attribute_ids, in the correct order - - @see ams::list::ams_attribute_ids - @see ams::list::ams_attribute_ids_flush -} { - return [db_list ams_attribute_ids {}] -} - -ad_proc -private ams::list::ams_attribute_ids { - -list_id:required -} { - get this lists ams_attribute_ids. Cached. - - @return list of ams_attribute_ids, in the correct order - - @see ams::list::ams_attribute_ids_not_cached - @see ams::list::ams_attribute_ids_flush -} { - return [util_memoize [list ams::list::ams_attribute_ids_not_cached -list_id $list_id]] -} - -ad_proc -private ams::list::ams_attribute_ids_flush { - -list_id:required -} { - Flush this lists ams_attribute_ids cache. - - @return list of ams_attribute_ids, in the correct order - - @see ams::list::ams_attribute_ids_not_cached - @see ams::list::ams_attribute_ids -} { - return [util_memoize_flush [list ams::list::ams_attribute_ids_not_cached -list_id $list_id]] -} - - - -ad_proc -private ams::list::exists_p { +ad_proc -public ams::ad_form::values { -package_key:required -object_type:required -list_name:required + -form_name:required + -object_id:required } { - does an ams list like this exist? - - @return 1 if the list exists for this object_type and package_key and 0 if the does not exist + this code populates ad_form values } { - set list_id [ams::list::get_list_id_not_cached -package_key $package_key -object_type $object_type -list_name $list_name] - if { [exists_and_not_null list_id] } { - return 1 - } else { - return 0 + set list_id [ams::list::get_list_id -package_key $package_key -object_type $object_type -list_name $list_name] + db_transaction { + db_foreach select_values {} { +# ns_log notice "$widget $attribute_name $value" + ams::widget -widget $widget -request "form_set_value" -attribute_name $attribute_name -pretty_name $pretty_name -form_name $form_name -attribute_id $attribute_id -value $value + } } } - -ad_proc -private ams::list::flush { - -package_key:required - -object_type:required - -list_name:required -} { - flush all inte info we have on an ams_list - - @return 1 if the list exists for this object_type and package_key and 0 if the does not exist -} { - ams::list::ams_attribute_ids_flush -list_id [ams::list::get_list_id_not_cached -package_key $package_key -object_type $object_type -list_name $list_name] - ams::list::get_list_id_flush -package_key $package_key -object_type $object_type -list_name $list_name -} - -ad_proc -private ams::list::get_list_id { - -package_key:required - -object_type:required - -list_name:required -} { - - return the list_id for the given parameters. Chached. - - @return list_id if none exists then it returns blank -} { - return [util_memoize [list ams::list::get_list_id_not_cached -package_key $package_key -object_type $object_type -list_name $list_name]] -} - - -ad_proc -private ams::list::get_list_id_not_cached { - -package_key:required - -object_type:required - -list_name:required -} { - return the list_id for the given parameters - - @return list_id if none exists then it returns blank -} { - - return [db_string get_list_id {} -default {}] -} - -ad_proc -private ams::list::get_list_id_flush { - -package_key:required - -object_type:required - -list_name:required -} { - - flush the memorized list_id for the given parameters. - - @return list_id if none exists then it returns blank -} { - return [util_memoize_flush [list ams::list::get_list_id_not_cached -package_key $package_key -object_type $object_type -list_name $list_name]] -} - -ad_proc -public ams::list::new { - {-list_id ""} - -package_key:required - -object_type:required - -list_name:required - -pretty_name:required - {-description ""} - {-description_mime_type "text/plain"} - {-context_id ""} -} { - create a new ams_group - - @return group_id -} { - if { [empty_string_p $context_id] } { - set context_id [ams::package_id] - } - if { ![exists_and_not_null description] } { - set description_mime_type "" - } - set lang_key "ams.$package_key\:$object_type\:$list_name" - _mr en $lang_key $pretty_name - set pretty_name $lang_key - - if { [exists_and_not_null description] } { - set lang_key "ams.$package_key\:$object_type\:$list_name\:description" - _mr en $lang_key $description - set description $lang_key - } - - set extra_vars [ns_set create] - oacs_util::vars_to_ns_set -ns_set $extra_vars -var_list { list_id package_key object_type list_name pretty_name description description_mime_type } - set list_id [package_instantiate_object -extra_vars $extra_vars ams_list] - - return $list_id -} - - -namespace eval ams::list::attribute {} - -ad_proc -public ams::list::attribute::map { - -list_id:required - -ams_attribute_id:required - {-sort_order ""} - {-required_p "f"} - {-section_heading ""} -} { - Map an ams option for an attribute to an option_map_id, if no value is supplied for option_map_id a new option_map_id will be created. - - @param sort_order if null then the attribute will be placed as the last attribute in this groups sort order - - @return option_map_id -} { - if { ![exists_and_not_null sort_order] } { - set sort_order [expr 1 + [db_string get_highest_sort_order {} -default "0"]] - } - return [db_exec_plsql ams_list_attribute_map {}] -} - -ad_proc -public ams::list::attribute::unmap { - -list_id:required - -ams_attribute_id:required -} { - Unmap an ams option from an ams list -} { - db_dml ams_list_attribute_unmap {} -} - -ad_proc -public ams::list::attribute::required { - -list_id:required - -ams_attribute_id:required -} { - Specify and ams_attribute as required in an ams list -} { - db_dml ams_list_attribute_required {} -} - -ad_proc -public ams::list::attribute::optional { - -list_id:required - -ams_attribute_id:required -} { - Specify and ams_attribute as optional in an ams list -} { - db_dml ams_list_attribute_optional {} -} - - - - - - - - - - - - -namespace eval ams::util {} - - - -ad_proc -public ams::util::sqlify_list { - -list:required -} { - set output_list {} - foreach item $list { - if { [exists_and_not_null output_list] } { - append output_list ", " - } - regsub -all {'} $item {''} item - append output_list "'$item'" - } - return $output_list -} Index: openacs-4/packages/ams/tcl/ams-widget-procs-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/tcl/ams-widget-procs-postgresql.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ams/tcl/ams-widget-procs-postgresql.xql 18 May 2005 17:11:48 -0000 1.1 @@ -0,0 +1,107 @@ + + + + + + select option, + option_id + from ams_option_types + where attribute_id = :attribute_id + and not deprecated_p + order by sort_order + + + + + + select * + from ams_widgets + where active_p is true + and widget not in ($sql_list_of_valid_procs) + + + + + + select ams_widget__save ( + :widget, + :pretty_name, + :value_method, + :active_p + ) + + + + + + select ams_value__text_save ( + :text, + :text_format + ) + + + + + + select ams_value__time_save ( + :time + ) + + + + + + select ams_value__number_save ( + :number + ) + + + + + + select ams_value__postal_address_save ( + :delivery_address, + :municipality, + :region, + :postal_code, + :country_code, + :additional_text, + :postal_type + ) + + + + + + select ams_value__telecom_number_save ( + :itu_id, + :national_number, + :area_city_code, + :subscriber_number, + :extension, + :sms_enabled_p, + :best_contact_time, + :location, + :phone_type_id + ) + + + + + + select value_id + from ams_option_ids + where ams_value__options(value_id) = :options + + + + + + select ams_option__map ( + :value_id, + :option_id + ) + + + + Index: openacs-4/packages/ams/tcl/ams-widget-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/tcl/ams-widget-procs.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ams/tcl/ams-widget-procs.tcl 18 May 2005 17:11:48 -0000 1.1 @@ -0,0 +1,1211 @@ +ad_library { + + Support procs for the ams package + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-09-28 + @cvs-id $Id: ams-widget-procs.tcl,v 1.1 2005/05/18 17:11:48 matthewg Exp $ + +} + +namespace eval ams {} +namespace eval ams::widget {} +namespace eval ams::util {} + +ad_proc -public ams::widget { + -widget:required + -request:required + {-attribute_id ""} + {-attribute_name ""} + {-pretty_name ""} + {-form_name ""} + {-value ""} + {-optional_p "1"} +} { + This proc defers its responses to all other ams::widget::${widget} procs. + + @param widget the ams::widget::${widget} we defer to + @param request + must be one of the following: +
    +
  • ad_form_widget - returns element(s) string(s) suitable for inclusion in the form section of ad_form
  • +
  • template_form_widget -
  • +
  • form_set_value - sets the form value(s), in both ad_form and template_form using the template::element::set_value proc
  • +
  • form_save_value - saves the form value(s), and returns a value_id suitable for inclusion in the ams_attribute_values table. This value_id can be an object_id or any other integer id. The value id is used by the value_method command to get a value suitable for use with ams::widget procs.
  • +
  • value_text - returns the value formatted as text/plain
  • +
  • value_html - returns the value formatted as text/html
  • +
  • csv_value - not yet implemented
  • +
  • csv_headers - not yet implemented
  • +
  • csv_save - not yet implemented
  • +
  • widget_datetypes - the acs_datatype(s) associated with this widget
  • +
  • widget_name - a pretty (human readable) name for this widget
  • +
  • value_method - the name of a database procedure to be called when returning a value to this procedure. The procedure will only get the value_id supplied in the form_save_value request and must convert that to whatever format it wants. In the simplest case it would return the value_id itself and then when you use form_set_value, value_text, value_html, csv_value actions a trip would need to be made to the database to return the appropriate values. If at all possible this procedure should return all the information necessary to format the value with this procedure (and thus not require another trip to the database which would siginifcantly decrease performance).
  • +
+ @param attribute_name + @param pretty_name The name for the widget or to be used as a description of the attribute value + @param form_name The name of the template_form or ad_form being used + @param value The attribute value to be manipulated by this widget + @param optional_p Whether or not an answer to this widget is required +} { + + if { [::ams::widget_proc_exists_p -widget $widget] } { + switch $request { + ad_form_widget - template_form_widget - form_save_value { + if { [::ams::widget_has_options_p -widget $widget] } { + set options [::ams::widget_options -attribute_id $attribute_id] + } else { + set options {} + } + } + default { + set options {} + } + } + return [::ams::widget::${widget} -request $request -attribute_name $attribute_name -pretty_name $pretty_name -value $value -optional_p $optional_p -form_name $form_name -options $options] + + } else { + # the widget requested did not exist + ns_log notice "AMS: the ams widget \"${widget}\" was requested and the associated ::ams::widget::${widget} procedure does not exist" + + } +} + +ad_proc -private ams::widget_options { + -attribute_id:required +} { + Return all widget procs. Each list element is a list of the first then pretty_name then the widget +} { + return [db_list_of_lists get_options {}] +} + +ad_proc -private ams::widget_list { +} { + Return all widget procs. Each list element is a list of the first then pretty_name then the widget +} { + set widgets [list] + set all_procs [::info procs "::ams::widget::*"] + foreach widget $all_procs { + if { [string is false [regsub {__arg_parser} $widget {} widget]] } { + regsub {::ams::widget::} $widget {} widget + lappend widgets [list [::ams::widget -widget $widget -request "widget_name"] $widget] + } + } + return $widgets +} + +ad_proc -private ams::widgets_init { +} { + Initialize all widgets. Deprecated widgets that no longer exist in the tcl api. +} { + set proc_widgets [list] + foreach widget [ams::widget_list] { + lappend proc_widgets [lindex $widget 1] + } + set sql_list_of_valid_procs "'[join $proc_widgets {','}]'" + db_transaction { + db_foreach select_widgets_to_deactivate "" { + set active_p 0 + db_1row save_widget {} + } + foreach widget $proc_widgets { + # is the widget in the database? + set pretty_name [ams::widget -widget $widget -request "widget_name"] + set value_method [ams::widget -widget $widget -request "value_method"] + set active_p 1 + db_1row save_widget {} + } + } +} + +ad_proc -private ams::widget_proc_exists_p { + -widget:required +} { + Does the procedure ams::widget::\${widget} exist? + + @return 0 if false 1 if true +} { + return [string is false [empty_string_p [info procs "::ams::widget::${widget}"]]] +} + +ad_proc -private ams::widget_has_options_p { + -widget:required +} { + Is the procedure ams::widget::\${widget} one that depends on options? + + @return 0 if false 1 if true +} { + if { [ams::widget_proc_exists_p -widget $widget] } { + if { [ams::widget -widget $widget -request "value_method"] == "ams_value__options" } { + return 1 + } else { + return 0 + } + } else { + return 0 + } +} + + +ad_proc -private ams::widget::postal_address { + -request:required + -attribute_name:required + -pretty_name:required + -form_name:required + -value:required + -optional_p:required + -options:required +} { + This proc responds to the ams::widget procs. + + @see ams::widget +} { + + switch $request { + ad_form_widget { + if { [string is true $optional_p] } { + return "${attribute_name}:address(address),optional {[list label ${pretty_name}]}" + } else { + return "${attribute_name}:address(address) {[list label ${pretty_name}]}" + } + } + template_form_widget { + if { [string is true $optional_p] } { + ::template::element::create ${form_name} ${attribute_name} \ + -label ${pretty_name} \ + -datatype address \ + -widget address \ + -optional + } else { + ::template::element::create ${form_name} ${attribute_name} \ + -label ${pretty_name} \ + -datatype address \ + -widget address + } + } + form_set_value { + ::template::element::set_value ${form_name} ${attribute_name} ${value} + } + form_save_value { + set value [::template::element::get_value ${form_name} ${attribute_name}] + return [ams::util::postal_address_save \ + -delivery_address [template::util::address::get_property delivery_address $value] \ + -municipality [template::util::address::get_property municipality $value] \ + -region [template::util::address::get_property region $value] \ + -postal_code [template::util::address::get_property postal_code $value] \ + -country_code [template::util::address::get_property country_code $value] \ + -additional_text [template::util::address::get_property additional_text $value] \ + -postal_type [template::util::address::get_property postal_type $value]] + } + value_text { + return ${value} + } + value_html { + return [ad_html_text_convert -from "text/plain" -to "text/html" ${value}] + } + csv_value { + # not yet implemented + } + csv_headers { + # not yet implemented + } + csv_save { + # not yet implemented + } + widget_datatypes { + return [list "string"] + } + widget_name { + return [_ "ams.Address"] + } + value_method { + return "ams_value__postal_address" + } + } +} + + +ad_proc -private ams::widget::telecom_number { + -request:required + -attribute_name:required + -pretty_name:required + -form_name:required + -value:required + -optional_p:required + -options:required +} { + This proc responds to the ams::widget procs. + + @see ams::widget +} { + + switch $request { + ad_form_widget { + if { [string is true $optional_p] } { + return "${attribute_name}:telecom_number(telecom_number),optional {[list label ${pretty_name}]}" + } else { + return "${attribute_name}:telecom_number(telecom_number) {[list label ${pretty_name}]}" + } + } + template_form_widget { + if { [string is true $optional_p] } { + ::template::element::create ${form_name} ${attribute_name} \ + -label ${pretty_name} \ + -datatype telecom_number \ + -widget telecom_number \ + -optional + } else { + ::template::element::create ${form_name} ${attribute_name} \ + -label ${pretty_name} \ + -datatype telecom_number \ + -widget telecom_number + } + } + form_set_value { + ::template::element::set_value ${form_name} ${attribute_name} $value + } + form_save_value { + set value [::template::element::get_value ${form_name} ${attribute_name}] + return [ams::util::telecom_number_save \ + -itu_id [template::util::telecom_number::get_property itu_id $value] \ + -national_number [template::util::telecom_number::get_property national_number $value] \ + -area_city_code [template::util::telecom_number::get_property area_city_code $value] \ + -subscriber_number [template::util::telecom_number::get_property subscriber_number $value] \ + -extension [template::util::telecom_number::get_property extension $value] \ + -sms_enabled_p [template::util::telecom_number::get_property sms_enabled_p $value] \ + -best_contact_time [template::util::telecom_number::get_property best_contact_time $value] \ + -location [template::util::telecom_number::get_property location $value] \ + -phone_type_id [template::util::telecom_number::get_property phone_type_id $value]] + } + value_text { + return ${value} + } + value_html { + return [ad_html_text_convert -from "text/plain" -to "text/html" ${value}] + } + csv_value { + # not yet implemented + } + csv_headers { + # not yet implemented + } + csv_save { + # not yet implemented + } + widget_datatypes { + return [list "string"] + } + widget_name { + return [_ "ams.Telecom_Number"] + } + value_method { + return "ams_value__telecom_number" + } + } +} + + +ad_proc -private ams::widget::date { + -request:required + -attribute_name:required + -pretty_name:required + -form_name:required + -value:required + -optional_p:required + -options:required +} { + This proc responds to the ams::widget procs. + + @see ams::widget +} { + + switch $request { + ad_form_widget { + if { [string is true $optional_p] } { + return "${attribute_name}:date(date),optional {[list label ${pretty_name}]}" + } else { + return "${attribute_name}:date(date) {[list label ${pretty_name}]}" + } + } + template_form_widget { + if { [string is true $optional_p] } { + ::template::element::create ${form_name} ${attribute_name} \ + -label ${pretty_name} \ + -datatype date \ + -widget date \ + -help \ + -optional + } else { + ::template::element::create ${form_name} ${attribute_name} \ + -label ${pretty_name} \ + -datatype date \ + -widget date \ + -help + } + } + form_set_value { + regsub -all {\-} $value { } value + regsub -all {:} $value { } value + ::template::element::set_value ${form_name} ${attribute_name} ${value} + } + form_save_value { + set value [::template::element::get_value ${form_name} ${attribute_name}] + return [ams::util::time_save -time [template::util::date::get_property ansi $value]] + } + value_text { + return ${value} + } + value_html { + return [ad_html_text_convert -from "text/plain" -to "text/html" ${value}] + } + csv_value { + # not yet implemented + } + csv_headers { + # not yet implemented + } + csv_save { + # not yet implemented + } + widget_datatypes { + return [list "date"] + } + widget_name { + return [_ "ams.Date"] + } + value_method { + return "ams_value__time" + } + } +} + + +ad_proc -private ams::widget::select { + -request:required + -attribute_name:required + -pretty_name:required + -form_name:required + -value:required + -optional_p:required + -options:required +} { + This proc responds to the ams::widget procs. + + @see ams::widget +} { + + switch $request { + ad_form_widget { + if { [string is true $optional_p] } { + set options [concat [list [list "" ""]] $options] + return "${attribute_name}:integer(select),optional {[list label ${pretty_name}]} {[list options $options]}" + } else { + set options [concat [list [list "- [_ ams.select_one] -" ""]] $options] + return "${attribute_name}:integer(select) {[list label ${pretty_name}]} {[list options $options]}" + } + } + template_form_widget { + if { [string is true $optional_p] } { + ::template::element::create ${form_name} ${attribute_name} \ + -label ${pretty_name} \ + -datatype integer \ + -widget select \ + -optional + } else { + ::template::element::create ${form_name} ${attribute_name} \ + -label ${pretty_name} \ + -datatype integer \ + -widget select + } + } + form_set_value { + ::template::element::set_value ${form_name} ${attribute_name} ${value} + } + form_save_value { + set value [::template::element::get_value ${form_name} ${attribute_name}] + return [ams::util::options_save -options $value] + } + value_text { + return ${value} + } + value_html { + return [ad_html_text_convert -from "text/plain" -to "text/html" ${value}] + } + csv_value { + # not yet implemented + } + csv_headers { + # not yet implemented + } + csv_save { + # not yet implemented + } + widget_datatypes { + return [list "string"] + } + widget_name { + return [_ "ams.Select"] + } + value_method { + return "ams_value__options" + } + } +} + + +ad_proc -private ams::widget::radio { + -request:required + -attribute_name:required + -pretty_name:required + -form_name:required + -value:required + -optional_p:required + -options:required +} { + This proc responds to the ams::widget procs. + + @see ams::widget +} { + + switch $request { + ad_form_widget { + if { [string is true $optional_p] } { + return "${attribute_name}:integer(radio),optional {[list label ${pretty_name}]} {[list options $options]}" + } else { + return "${attribute_name}:integer(radio) {[list label ${pretty_name}]} {[list options $options]}" + } + } + template_form_widget { + if { [string is true $optional_p] } { + ::template::element::create ${form_name} ${attribute_name} \ + -label ${pretty_name} \ + -datatype integer \ + -widget radio \ + -optional + } else { + ::template::element::create ${form_name} ${attribute_name} \ + -label ${pretty_name} \ + -datatype integer \ + -widget radio + } + } + form_set_value { + ::template::element::set_value ${form_name} ${attribute_name} ${value} + } + form_save_value { + set value [::template::element::get_value ${form_name} ${attribute_name}] + return [ams::util::options_save -options $value] + } + value_text { + return ${value} + } + value_html { + return [ad_html_text_convert -from "text/plain" -to "text/html" ${value}] + } + csv_value { + # not yet implemented + } + csv_headers { + # not yet implemented + } + csv_save { + # not yet implemented + } + widget_datatypes { + return [list "string"] + } + widget_name { + return [_ "ams.Radio"] + } + value_method { + return "ams_value__options" + } + } +} + + +ad_proc -private ams::widget::checkbox { + -request:required + -attribute_name:required + -pretty_name:required + -form_name:required + -value:required + -optional_p:required + -options:required +} { + This proc responds to the ams::widget procs. + + @see ams::widget +} { + + switch $request { + ad_form_widget { + if { [string is true $optional_p] } { + return "${attribute_name}:integer(checkbox),multiple,optional {[list label ${pretty_name}]} {[list options $options]}" + } else { + return "${attribute_name}:integer(checkbox),multiple {[list label ${pretty_name}]} {[list options $options]}" + } + } + template_form_widget { + if { [string is true $optional_p] } { + ::template::element::create ${form_name} ${attribute_name} \ + -label ${pretty_name} \ + -datatype integer \ + -widget checkbox \ + -multiple \ + -optional + } else { + ::template::element::create ${form_name} ${attribute_name} \ + -label ${pretty_name} \ + -datatype integer \ + -widget checkbox \ + -multiple + } + } + form_set_value { + ::template::element::set_values ${form_name} ${attribute_name} ${value} + } + form_save_value { + set values [::template::element::get_values ${form_name} ${attribute_name}] + return [ams::util::options_save -options $values] + } + value_text { + return ${value} + } + value_html { + return [ad_html_text_convert -from "text/plain" -to "text/html" ${value}] + } + csv_value { + # not yet implemented + } + csv_headers { + # not yet implemented + } + csv_save { + # not yet implemented + } + widget_datatypes { + return [list "string"] + } + widget_name { + return [_ "ams.Checkbox"] + } + value_method { + return "ams_value__options" + } + } +} + + +ad_proc -private ams::widget::multiselect { + -request:required + -attribute_name:required + -pretty_name:required + -form_name:required + -value:required + -optional_p:required + -options:required +} { + This proc responds to the ams::widget procs. + + @see ams::widget +} { + + switch $request { + ad_form_widget { + if { [string is true $optional_p] } { + return "${attribute_name}:integer(multiselect),multiple,optional {[list label ${pretty_name}]} {[list options $options]}" + } else { + return "${attribute_name}:integer(multiselect),multiple {[list label ${pretty_name}]} {[list options $options]}" + } + } + template_form_widget { + if { [string is true $optional_p] } { + ::template::element::create ${form_name} ${attribute_name} \ + -label ${pretty_name} \ + -datatype integer \ + -widget multiselect \ + -multiple \ + -optional + } else { + ::template::element::create ${form_name} ${attribute_name} \ + -label ${pretty_name} \ + -datatype integer \ + -widget multiselect \ + -multiple + } + } + form_set_value { + ::template::element::set_values ${form_name} ${attribute_name} ${value} + } + form_save_value { + set values [::template::element::get_values ${form_name} ${attribute_name}] + return [ams::util::options_save -options $values] + } + value_text { + return ${value} + } + value_html { + return [ad_html_text_convert -from "text/plain" -to "text/html" ${value}] + } + csv_value { + # not yet implemented + } + csv_headers { + # not yet implemented + } + csv_save { + # not yet implemented + } + widget_datatypes { + return [list "string"] + } + widget_name { + return [_ "ams.Multiselect"] + } + value_method { + return "ams_value__options" + } + } +} + + + + +ad_proc -private ams::widget::integer { + -request:required + -attribute_name:required + -pretty_name:required + -form_name:required + -value:required + -optional_p:required + -options:required +} { + This proc responds to the ams::widget procs. + + @see ams::widget +} { + + switch $request { + ad_form_widget { + if { [string is true $optional_p] } { + return "${attribute_name}:integer(text),optional {html {size 6}} {[list label ${pretty_name}]}" + } else { + return "${attribute_name}:integer(text) {html {size 6}} {[list label ${pretty_name}]}" + } + } + template_form_widget { + if { [string is true $optional_p] } { + ::template::element::create ${form_name} ${attribute_name} \ + -label ${pretty_name} \ + -datatype integer \ + -widget text \ + -html {size 6} \ + -optional + } else { + ::template::element::create ${form_name} ${attribute_name} \ + -label ${pretty_name} \ + -datatype integer \ + -widget text \ + -html {size 6} + } + } + form_set_value { + ::template::element::set_value ${form_name} ${attribute_name} ${value} + } + form_save_value { + set value [::template::element::get_value ${form_name} ${attribute_name}] + return [ams::util::number_save -number $value] + } + value_text { + return ${value} + } + value_html { + return [ad_html_text_convert -from "text/plain" -to "text/html" ${value}] + } + csv_value { + # not yet implemented + } + csv_headers { + # not yet implemented + } + csv_save { + # not yet implemented + } + widget_datatypes { + return [list "integer"] + } + widget_name { + return [_ "ams.Integer"] + } + value_method { + return "ams_value__number" + } + } +} + + +ad_proc -private ams::widget::textbox { + -request:required + -attribute_name:required + -pretty_name:required + -form_name:required + -value:required + -optional_p:required + -options:required +} { + This proc responds to the ams::widget procs. + + @see ams::widget +} { + set value_format [lindex $value 0] + set value [lrange $value 1 end] + switch $request { + ad_form_widget { + if { [string is true $optional_p] } { + return "${attribute_name}:text(text),optional {html {size 30}} {[list label ${pretty_name}]}" + } else { + return "${attribute_name}:text(text) {html {size 30}} {[list label ${pretty_name}]}" + } + } + template_form_widget { + if { [string is true $optional_p] } { + ::template::element::create ${form_name} ${attribute_name} \ + -label ${pretty_name} \ + -datatype text \ + -widget text \ + -html {size 30} \ + -optional + } else { + ::template::element::create ${form_name} ${attribute_name} \ + -label ${pretty_name} \ + -datatype text \ + -widget text \ + -html {size 30} + } + } + form_set_value { + ::template::element::set_value ${form_name} ${attribute_name} ${value} + } + form_save_value { + set value [::template::element::get_value ${form_name} ${attribute_name}] + return [ams::util::text_save -text $value -text_format "text/plain"] + } + value_text { + return ${value} + } + value_html { + return [ad_html_text_convert -from "text/plain" -to "text/html" ${value}] + } + csv_value { + # not yet implemented + } + csv_headers { + # not yet implemented + } + csv_save { + # not yet implemented + } + widget_datatypes { + return [list "string"] + } + widget_name { + return [_ "ams.Textbox"] + } + value_method { + return "ams_value__text" + } + } +} + + +ad_proc -private ams::widget::textarea { + -request:required + -attribute_name:required + -pretty_name:required + -form_name:required + -value:required + -optional_p:required + -options:required +} { + This proc responds to the ams::widget procs. + + @see ams::widget +} { + set value_format [lindex $value 0] + set value [lrange $value 1 end] + switch $request { + ad_form_widget { + if { [string is true $optional_p] } { + return "${attribute_name}:text(textarea),optional {html {cols 60 rows 6}} {[list label ${pretty_name}]}" + } else { + return "${attribute_name}:text(textarea) {html {cols 60 rows 10}} {[list label ${pretty_name}]}" + } + } + template_form_widget { + if { [string is true $optional_p] } { + ::template::element::create ${form_name} ${attribute_name} \ + -label ${pretty_name} \ + -datatype text \ + -widget textarea \ + -html {cols 60 rows 10} \ + -optional + } else { + ::template::element::create ${form_name} ${attribute_name} \ + -label ${pretty_name} \ + -datatype text \ + -widget textarea \ + -html {cols 60 rows 10} + } + } + form_set_value { + ::template::element::set_value ${form_name} ${attribute_name} ${value} + } + form_save_value { + set value [::template::element::get_value ${form_name} ${attribute_name}] + return [ams::util::text_save -text $value -text_format "text/plain"] + } + value_text { + return ${value} + } + value_html { + return [ad_html_text_convert -from "text/plain" -to "text/html" ${value}] + } + csv_value { + # not yet implemented + } + csv_headers { + # not yet implemented + } + csv_save { + # not yet implemented + } + widget_datatypes { + return [list "text"] + } + widget_name { + return [_ "ams.Textarea"] + } + value_method { + return "ams_value__text" + } + } +} + + +ad_proc -private ams::widget::richtext { + -request:required + -attribute_name:required + -pretty_name:required + -form_name:required + -value:required + -optional_p:required + -options:required +} { + This proc responds to the ams::widget procs. + + @see ams::widget +} { + set value_format [lindex $value 0] + set value [lrange $value 1 end] + switch $request { + ad_form_widget { + if { [string is true $optional_p] } { + return "${attribute_name}:richtext(richtext),optional {html {cols 60 rows 14}} {[list label ${pretty_name}]}" + } else { + return "${attribute_name}:richtext(richtext) {html {cols 60 rows 14}} {[list label ${pretty_name}]}" + } + } + template_form_widget { + if { [string is true $optional_p] } { + ::template::element::create ${form_name} ${attribute_name} \ + -label ${pretty_name} \ + -datatype richtext \ + -widget richtext \ + -html {cols 60 rows 14} \ + -optional + } else { + ::template::element::create ${form_name} ${attribute_name} \ + -label ${pretty_name} \ + -datatype richtext \ + -widget richtext \ + -html {cols 60 rows 14} + } + } + form_set_value { + ::template::element::set_value ${form_name} ${attribute_name} [list ${value} ${value_format}] + } + form_save_value { + set value [::template::element::get_value ${form_name} ${attribute_name}] + return [ams::util::text_save \ + -text [template::util::richtext::get_property contents $value] \ + -text_format [template::util::richtext::get_property format $value]] + } + value_text { + return ${value} + } + value_html { + return [ad_html_text_convert -from "text/plain" -to "text/html" ${value}] + } + csv_value { + # not yet implemented + } + csv_headers { + # not yet implemented + } + csv_save { + # not yet implemented + } + widget_datatypes { + return [list "text"] + } + widget_name { + return [_ "ams.Richtext"] + } + value_method { + return "ams_value__text" + } + } +} + + +ad_proc -private ams::widget::email { + -request:required + -attribute_name:required + -pretty_name:required + -form_name:required + -value:required + -optional_p:required + -options:required +} { + This proc responds to the ams::widget procs. + + @see ams::widget +} { + set value_format [lindex $value 0] + set value [lrange $value 1 end] + switch $request { + ad_form_widget { + if { [string is true $optional_p] } { + return "${attribute_name}:email(text),optional {html {size 30}} {[list label ${pretty_name}]}" + } else { + return "${attribute_name}:email(text) {html {size 30}} {[list label ${pretty_name}]}" + } + } + template_form_widget { + if { [string is true $optional_p] } { + ::template::element::create ${form_name} ${attribute_name} \ + -label ${pretty_name} \ + -datatype email \ + -widget text \ + -html {size 30} \ + -optional + } else { + ::template::element::create ${form_name} ${attribute_name} \ + -label ${pretty_name} \ + -datatype email \ + -widget text \ + -html {size 30} + } + } + form_set_value { + ::template::element::set_value ${form_name} ${attribute_name} ${value} + } + form_save_value { + set value [::template::element::get_value ${form_name} ${attribute_name}] + return [ams::util::text_save -text $value -text_format "text/plain"] + } + value_text { + return ${value} + } + value_html { + return [ad_html_text_convert -from "text/plain" -to "text/html" ${value}] + } + csv_value { + # not yet implemented + } + csv_headers { + # not yet implemented + } + csv_save { + # not yet implemented + } + widget_datatypes { + return [list "email"] + } + widget_name { + return [_ "ams.Email"] + } + value_method { + return "ams_value__text" + } + } +} + + +ad_proc -private ams::widget::url { + -request:required + -attribute_name:required + -pretty_name:required + -form_name:required + -value:required + -optional_p:required + -options:required +} { + This proc responds to the ams::widget procs. + + @see ams::widget +} { + set value_format [lindex $value 0] + set value [lrange $value 1 end] + switch $request { + ad_form_widget { + if { [string is true $optional_p] } { + return "${attribute_name}:url(text),optional {html {size 30}} {[list label ${pretty_name}]}" + } else { + return "${attribute_name}:url(text) {html {size 30}} {[list label ${pretty_name}]}" + } + } + template_form_widget { + if { [string is true $optional_p] } { + ::template::element::create ${form_name} ${attribute_name} \ + -label ${pretty_name} \ + -datatype url \ + -widget text \ + -html {size 30} \ + -optional + } else { + ::template::element::create ${form_name} ${attribute_name} \ + -label ${pretty_name} \ + -datatype url \ + -widget text \ + -html {size 30} + } + } + form_set_value { + ::template::element::set_value ${form_name} ${attribute_name} ${value} + } + form_save_value { + set value [::template::element::get_value ${form_name} ${attribute_name}] + return [ams::util::text_save -text $value -text_format "text/plain"] + } + value_text { + return ${value} + } + value_html { + return [ad_html_text_convert -from "text/plain" -to "text/html" ${value}] + } + csv_value { + # not yet implemented + } + csv_headers { + # not yet implemented + } + csv_save { + # not yet implemented + } + widget_datatypes { + return [list "url"] + } + widget_name { + return [_ "ams.Url"] + } + value_method { + return "ams_value__text" + } + } +} + + + + + + + + + + +ad_proc -private ams::util::text_save { + -text:required + -text_format:required +} { + return a value_id +} { + if { [exists_and_not_null text] } { + return [db_string save_value {} -default {}] + } +} + +ad_proc -private ams::util::time_save { + -time:required +} { + return a value_id +} { + if { [exists_and_not_null time] } { + return [db_string save_value {} -default {}] + } +} + +ad_proc -private ams::util::number_save { + -number:required +} { + return a value_id +} { + if { [exists_and_not_null number] } { + return [db_string save_value {} -default {}] + } +} + +ad_proc -private ams::util::postal_address_save { + -delivery_address:required + -municipality:required + -region:required + -postal_code:required + -country_code:required + {-additional_text ""} + {-postal_type ""} +} { + return a value_id +} { + if { [exists_and_not_null delivery_address] } { + return [db_string save_value {} -default {}] + } +} + +ad_proc -private ams::util::telecom_number_save { + {-itu_id ""} + {-national_number ""} + {-area_city_code ""} + -subscriber_number:required + {-extension ""} + {-sms_enabled_p ""} + {-best_contact_time ""} + {-location ""} + {-phone_type_id ""} +} { + return a value_id +} { + if { [exists_and_not_null subscriber_number] } { + return [db_string save_value {} -default {}] + } +} + +ad_proc -public ams::util::options_save { + -options:required +} { + Map an ams option for an attribute to an option_map_id, if no value is supplied for option_map_id a new option_map_id will be created. + + @param option_map_id + @param option_id + + @return option_map_id +} { + set options [lsort $options] + set value_id [db_string options_value_id {} -default {}] + if { [string is false [exists_and_not_null value_id]] } { + foreach option_id $options { + set value_id [db_string option_map {}] + } + } + return $value_id +} + Index: openacs-4/packages/ams/tcl/recurrence-widget-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/tcl/recurrence-widget-procs.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ams/tcl/recurrence-widget-procs.tcl 18 May 2005 17:11:48 -0000 1.1 @@ -0,0 +1,265 @@ +ad_library { + + Address input widget and datatype for the OpenACS templating system. + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-09-28 + @cvs-id $Id: recurrence-widget-procs.tcl,v 1.1 2005/05/18 17:11:48 matthewg Exp $ + +} + +namespace eval template {} +namespace eval template::data {} +namespace eval template::data::transform {} +namespace eval template::data::validate {} +namespace eval template::util {} +namespace eval template::util::recurrence {} +namespace eval template::widget {} + +ad_proc -public template::util::recurrence { command args } { + Dispatch procedure for the recurrence object +} { + eval template::util::recurrence::$command $args +} + +ad_proc -public template::util::recurrence::create { + {every_n {}} + {interval_type {}} + {days_of_week {}} + {recur_until {}} +} { + return [list $every_n $interval_type $days_of_week $recur_until] +} + +ad_proc -public template::util::recurrence::html_view { + {every_n {}} + {interval_type {}} + {days_of_week {}} + {recur_until {}} +} { + set recurrence "Every $every_n $interval_type" + if { [exists_and_not_null days_of_week] } { + append recurrence $days_of_week + } + if { [exists_and_not_null recur_until] } { + append recurrence $recur_until + } + return [ad_text_to_html $recurrence] +} + +ad_proc -public template::util::recurrence::acquire { type { value "" } } { + Create a new recurrence value with some predefined value + Basically, create and set the recurrence value +} { + set recurrence_list [template::util::recurrence::create] + return [template::util::recurrence::set_property $type $recurrence_list $value] +} + + +ad_proc -public template::data::validate::recurrence { value_ref message_ref } { + + upvar 2 $message_ref message $value_ref recurrence_list + + set delivery_recurrence [template::util::recurrence::get_property delivery_recurrence $recurrence_list] + set municipality [template::util::recurrence::get_property municipality $recurrence_list] + set region [template::util::recurrence::get_property region $recurrence_list] + set postal_code [template::util::recurrence::get_property postal_code $recurrence_list] + set country_code [template::util::recurrence::get_property country_code $recurrence_list] + set additional_text [template::util::recurrence::get_property additional_text $recurrence_list] + set postal_type [template::util::recurrence::get_property postal_type $recurrence_list] + + set message "" + # this is used to make sure there are no invalid characters in the recurrence + set recurrence_temp "$delivery_recurrence $municipality $region $postal_code $country_code $additional_text $postal_type" + if { [::string match "\{" $recurrence_temp] || [::string match "\}" $recurrence_temp] } { + # for built in display purposes these characters are not allowed, if you need it + # to be allowed make SURE that retrieval procs in AMS are also updated + # to deal with this change + if { [exists_and_not_null message_temp] } { append message " " } + append message "[_ ams.Your_entry_must_not_contain_the_following_characters]: \{ \}." + } + if { $country_code == "US" } { + # this should check a cached list + # this proc cannot for some reason go in the postgresql file... + if { ![db_0or1row validate_state { + select 1 from us_states where abbrev = upper(:region) or state_name = upper(:region) +} ] } { + if { [exists_and_not_null message_temp] } { append message " " } + append message "\"$region\" [_ ams.is_not_a_valid_US_state]." + } + } + if { [exists_and_not_null message_temp] } { + return 0 + } else { + return 1 + } +} + + +ad_proc -public template::data::transform::recurrence { element_ref } { + + upvar $element_ref element + set element_id $element(id) + + set every_n [ns_queryget $element_id.delivery_recurrence] + set interval_type [ns_queryget $element_id.municipality] + set days_of_week [ns_queryget $element_id.region] + set recur_until [ns_queryget $element_id.postal_code] + + if { [empty_string_p $every_n] } { + # We need to return the empty list in order for form builder to think of it + # as a non-value in case of a required element. + return [list] + } else { + return [list [list $every_n $interval_type $days_of_week $recur_until]] + } +} + +ad_proc -public template::util::recurrence::set_property { what recurrence_list value } { + Set a property of the recurrence datatype. + + @param what One of +
    +
  • every_n +
  • interval_type +
  • days_of_week +
  • recur_until +
+ + @param recurrence_list the recurrence list to modify + @param value the new value + + @return the modified list +} { + + set every_n [template::util::recurrence::get_property every_n $recurrence_list] + set interval_type [template::util::recurrence::get_property interval_type $recurrence_list] + set days_of_week [template::util::recurrence::get_property days_of_week $recurrence_list] + set recur_until [template::util::recurrence::get_property recur_until $recurrence_list] + + switch $what { + every_n { + return [list $value $interval_type $days_of_week $recur_until] + } + interval_type { + return [list $every_n $value $days_of_week $recur_until] + } + days_of_week { + return [list $every_n $interval_type $value $recur_until] + } + recur_until { + return [list $every_n $interval_type $days_of_week $value ] + } + default { + error "Parameter supplied to util::recurrence::set_property 'what' must be one of: 'every_n', 'interval_type', 'days_of_week', 'recur_until', 'html_view'. You specified: '$what'." + } + } +} + +ad_proc -public template::util::recurrence::get_property { what recurrence_list } { + + Get a property of the recurrence datatype. Valid properties are: + + @param what the name of the property. Must be one of: +
    +
  • every_n +
  • interval_type +
  • days_of_week +
  • recur_until +
  • html_view - this returns an nice html formatted view of the recurrence +
+ @param recurrence_list a recurrence datatype value, usually created with ad_form. +} { + + switch $what { + every_n { + return [lindex $recurrence_list 0] + } + interval_type { + return [lindex $recurrence_list 1] + } + days_of_week { + return [lindex $recurrence_list 2] + } + recur_until { + return [lindex $recurrence_list 3] + } + html_view { + set every_n [template::util::recurrence::get_property every_n $recurrence_list] + set interval_type [template::util::recurrence::get_property interval_type $recurrence_list] + set days_of_week [template::util::recurrence::get_property days_of_week $recurrence_list] + set recur_until [template::util::recurrence::get_property recur_until $recurrence_list] + return [template::util::recurrence::html_view $every_n $interval_type $days_of_week $recur_until] + } + default { + error "Parameter supplied to util::recurrence::get_property 'what' must be one of: 'every_n', 'interval_type', 'days_of_week', 'recur_until', 'html_view'. You specified: '$what'." + } + + } +} + +ad_proc -public template::widget::recurrence { element_reference tag_attributes } { + Implements the recurrence widget. + +} { + + upvar $element_reference element + + if { [info exists element(value)] } { + set every_n [template::util::recurrence::get_property delivery_recurrence $element(value)] + set interval_type [template::util::recurrence::get_property postal_code $element(value)] + set days_of_week [template::util::recurrence::get_property municipality $element(value)] + set recur_until [template::util::recurrence::get_property region $element(value)] + } else { + set every_n {} + set interval_type {} + set days_of_week {} + set recur_until {} + } + + set output {} + + if { [string equal $element(mode) "edit"] } { + + set every_n_options { + {"Every" 1} + {"Every Other" 2} + {"Every Third" 3} + {"Every Forth" 4} + } + + set interval_type_options { + {"Day" day} + {"Week" week} + {"Month on this Date" month_by_date} + {"Month on this Day" month_by_day} + {"Year" year} + } + + set menuattributes(id) \"recurrence__$element(form_id)__$element(id)\" + set dateattributes [list "name" "$element(id).recur_until"] + + append output " +
[_ ams.delivery_address]
      
[_ ams.municipality][_ ams.region][_ ams.postal_code][_ ams.municipality][_ ams.region][_ ams.postal_code]
[menu $element(id).country_code [template::util::address::country_options] $country_code attributes]
+ + + + + + +
Repeat [menu $element(id).every_n $every_n_options $every_n menuattributes] [menu $element(id).interval_type $interval_type_options $interval_type menuattributes]
Until [text $element(id).recur_until $dateattributes]
+" + + } else { + # Display mode + if { [info exists element(value)] } { + append output [template::util::recurrence::get_property html_view $element(value)] + append output "" + append output "" + append output "" + append output "" + } + } + + return $output +} Index: openacs-4/packages/ams/tcl/telecom-number-widget-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/tcl/telecom-number-widget-procs.tcl,v diff -u -N -r1.2 -r1.3 --- openacs-4/packages/ams/tcl/telecom-number-widget-procs.tcl 27 Oct 2004 03:33:25 -0000 1.2 +++ openacs-4/packages/ams/tcl/telecom-number-widget-procs.tcl 18 May 2005 17:11:48 -0000 1.3 @@ -47,7 +47,18 @@ {location {}} {phone_type_id {}} } { - set telecom_number "$national_number $area_city_code-$subscriber_number\x$extension" + set telecom_number $national_number + ns_log notice "mgeddert natnum \"$telecom_number\"" + if { [exists_and_not_null telecom_number] } { append telecom_number " " } + ns_log notice "mgeddert bacity \"$telecom_number\"" + append telecom_number $area_city_code + ns_log notice "mgeddert aacity \"$telecom_number\"" + if { [exists_and_not_null telecom_number] } { append telecom_number "-" } + ns_log notice "mgeddert bsubnu \"$telecom_number\"" + append telecom_number $subscriber_number + ns_log notice "mgeddert asubnu \"$telecom_number\"" + if { [exists_and_not_null extension] } { append telecom_number " x$extension" } + ns_log notice "mgeddert aextnu \"$telecom_number\"" return [ad_text_to_html $telecom_number] } @@ -202,9 +213,9 @@ } { set itu_id [template::util::telecom_number::get_property itu_id $telecom_number_list] - set subscriber_number [template::util::telecom_number::get_property subscriber_number $telecom_number_list] set national_number [template::util::telecom_number::get_property national_number $telecom_number_list] set area_city_code [template::util::telecom_number::get_property area_city_code $telecom_number_list] + set subscriber_number [template::util::telecom_number::get_property subscriber_number $telecom_number_list] set extension [template::util::telecom_number::get_property extension $telecom_number_list] set sms_enabled_p [template::util::telecom_number::get_property sms_enabled_p $telecom_number_list] set best_contact_time [template::util::telecom_number::get_property best_contact_time $telecom_number_list] @@ -252,12 +263,15 @@ @param what the name of the property. Must be one of:
  • itu_id (synonyms street_telecom_number, street) -
  • subscriber_number (synonyms zip_code, zip)
  • national_number (synonyms city, town)
  • area_city_code (synonyms state, province) +
  • subscriber_number (synonyms zip_code, zip)
  • extension (synonym country)
  • addtional_text (this is not implemented in the default US widget)
  • best_contact_time (this is not implemented in the default US widget) +
  • sms_enabled_p (this is not implemented in the default US widget) +
  • location (this is not implemented in the default US widget) +
  • phone_type_id (this is not implemented in the default US widget)
  • html_view - this returns an nice html formatted view of the telecom_number
@param telecom_number_list a telecom_number datatype value, usually created with ad_form. @@ -301,7 +315,7 @@ set best_contact_time [template::util::telecom_number::get_property best_contact_time $telecom_number_list] set location [template::util::telecom_number::get_property location $telecom_number_list] set phone_type_id [template::util::telecom_number::get_property phone_type_id $telecom_number_list] - return [template::util::telecom_number::html_view $itu_id $subscriber_number $national_number $area_city_code $extension $sms_enabled_p $best_contact_time $location $phone_type_id] + return [template::util::telecom_number::html_view $itu_id $national_number $area_city_code $subscriber_number $extension $sms_enabled_p $best_contact_time $location $phone_type_id] } default { error "Parameter supplied to util::telecom_number::get_property 'what' must be one of: 'itu_id', 'subscriber_number', 'national_number', 'area_city_code', 'extension', 'sms_enabled_p', 'best_contact_time', 'location', 'phone_type_id'. You specified: '$what'." @@ -325,9 +339,9 @@ if { [info exists element(value)] } { set itu_id [template::util::telecom_number::get_property itu_id $element(value)] - set subscriber_number [template::util::telecom_number::get_property subscriber_number $element(value)] set national_number [template::util::telecom_number::get_property national_number $element(value)] set area_city_code [template::util::telecom_number::get_property area_city_code $element(value)] + set subscriber_number [template::util::telecom_number::get_property subscriber_number $element(value)] set extension [template::util::telecom_number::get_property extension $element(value)] set sms_enabled_p [template::util::telecom_number::get_property sms_enabled_p $element(value)] set best_contact_time [template::util::telecom_number::get_property best_contact_time $element(value)] Index: openacs-4/packages/ams/www/attribute-add-2.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/www/attribute-add-2.adp,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/ams/www/attribute-add-2.adp 30 Oct 2004 00:23:54 -0000 1.1 +++ openacs-4/packages/ams/www/attribute-add-2.adp 18 May 2005 17:11:48 -0000 1.2 @@ -1,8 +1,8 @@ - -@title@ -@context@ - - - - - + +@title@ +@context@ + + + + + Index: openacs-4/packages/ams/www/attribute-add-2.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/www/attribute-add-2.tcl,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/ams/www/attribute-add-2.tcl 30 Oct 2004 00:23:54 -0000 1.1 +++ openacs-4/packages/ams/www/attribute-add-2.tcl 18 May 2005 17:11:48 -0000 1.2 @@ -1,121 +1,121 @@ -ad_page_contract { - - @author Matthew Geddert openacs@geddert.com - @creation-date 2004-07-28 - @cvs-id $Id$ -} { - {ams_attribute_id:integer,notnull} - {object_type:notnull} - {widget_name:notnull} - {attribute_name:notnull} - {pretty_name:notnull} - {pretty_plural:notnull} - {list_id:integer} - {description ""} -} - -acs_object_type::get -object_type $object_type -array "object_info" - -set title "Define Options" -set context [list [list objects Objects] [list "object?object_type=$object_type" $object_info(pretty_name)] [list "attribute-add?object_type=$object_type" "Add Attribute"] $title] - -db_1row select_widget_pretty_and_storage_type { select storage_type from ams_widgets where widget_name = :widget_name } - -acs_object_type::get -object_type $object_type -array "object_info" - - - - -if { [exists_and_not_null list_id] } { - set return_url "list-attributes-map?[export_vars -url {ams_attribute_id list_id}]" - set user_message "AMS Attribute $pretty_name Created and Mapped." -} else { - set return_url "object?[export_vars -url {object_type}]" - set user_message "AMS Attribute $pretty_name Created." -} - - - - -if { ![string equal $storage_type "ams_options"] } { - - ams::attribute::new \ - -ams_attribute_id $ams_attribute_id \ - -object_type $object_type \ - -attribute_name $attribute_name \ - -pretty_name $pretty_name \ - -pretty_plural $pretty_plural \ - -description $description \ - -widget_name $widget_name - -# {-options} - - util_user_message -html -message $user_message - ad_returnredirect $return_url - ad_script_abort -} - -ad_form -name attribute_form -form { - {ams_attribute_id:key} - {list_id:integer(hidden)} - {object_type:text(hidden)} - {widget_name:text(inform) {label "Widget"}} - {attribute_name:text(inform) {label "Attribute Name"}} - {pretty_name:text(inform) {label "Pretty Name"}} - {pretty_plural:text(inform) {label "Pretty Plural"}} -} - -if { [exists_and_not_null description] } { - ad_form -extend -name attribute_form -form { - {description:text(inform) {label "Description"}} - } -} else { - ad_form -extend -name attribute_form -form { - {description:text(hidden),optional} - } -} - -ad_form -extend -name attribute_form -form { - {option1:text {label "Option 1"} {html {size 50}}} - {option2:text,optional {label "Option 2"} {html {size 50}}} - {option3:text,optional {label "Option 3"} {html {size 50}}} - {option4:text,optional {label "Option 4"} {html {size 50}}} - {option5:text,optional {label "Option 5"} {html {size 50}}} - {option6:text,optional {label "Option 6"} {html {size 50}}} - {option7:text,optional {label "Option 7"} {html {size 50}}} - {option8:text,optional {label "Option 8"} {html {size 50}}} - {option9:text,optional {label "Option 9"} {html {size 50}} {help_text {If you need to add more options you will be able to do so by editing this attributes details}}} -} -new_request { -} -edit_request { -} -validate { -} -on_submit { - - set i 1 - set options [list] - while { $i <= "9" } { - set option_value [string trim [set option${i}]] - ns_log notice $option_value - if { [exists_and_not_null option_value] } { - lappend options $option_value - } - incr i - } - - ams::attribute::new \ - -ams_attribute_id $ams_attribute_id \ - -object_type $object_type \ - -attribute_name $attribute_name \ - -pretty_name $pretty_name \ - -pretty_plural $pretty_plural \ - -description $description \ - -widget_name $widget_name \ - -options $options - -} -after_submit { - util_user_message -html -message $user_message - ad_returnredirect $return_url - ad_script_abort -} - - -ad_return_template +ad_page_contract { + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id$ +} { + {ams_attribute_id:integer,notnull} + {object_type:notnull} + {widget_name:notnull} + {attribute_name:notnull} + {pretty_name:notnull} + {pretty_plural:notnull} + {list_id:integer} + {description ""} +} + +acs_object_type::get -object_type $object_type -array "object_info" + +set title "Define Options" +set context [list [list objects Objects] [list "object?object_type=$object_type" $object_info(pretty_name)] [list "attribute-add?object_type=$object_type" "Add Attribute"] $title] + +db_1row select_widget_pretty_and_storage_type { select storage_type from ams_widgets where widget_name = :widget_name } + +acs_object_type::get -object_type $object_type -array "object_info" + + + + +if { [exists_and_not_null list_id] } { + set return_url "list-attributes-map?[export_vars -url {ams_attribute_id list_id}]" + set user_message "AMS Attribute $pretty_name Created and Mapped." +} else { + set return_url "object?[export_vars -url {object_type}]" + set user_message "AMS Attribute $pretty_name Created." +} + + + + +if { ![string equal $storage_type "ams_options"] } { + + ams::attribute::new \ + -ams_attribute_id $ams_attribute_id \ + -object_type $object_type \ + -attribute_name $attribute_name \ + -pretty_name $pretty_name \ + -pretty_plural $pretty_plural \ + -description $description \ + -widget_name $widget_name + +# {-options} + + util_user_message -html -message $user_message + ad_returnredirect $return_url + ad_script_abort +} + +ad_form -name attribute_form -form { + {ams_attribute_id:key} + {list_id:integer(hidden)} + {object_type:text(hidden)} + {widget_name:text(inform) {label "Widget"}} + {attribute_name:text(inform) {label "Attribute Name"}} + {pretty_name:text(inform) {label "Pretty Name"}} + {pretty_plural:text(inform) {label "Pretty Plural"}} +} + +if { [exists_and_not_null description] } { + ad_form -extend -name attribute_form -form { + {description:text(inform) {label "Description"}} + } +} else { + ad_form -extend -name attribute_form -form { + {description:text(hidden),optional} + } +} + +ad_form -extend -name attribute_form -form { + {option1:text {label "Option 1"} {html {size 50}}} + {option2:text,optional {label "Option 2"} {html {size 50}}} + {option3:text,optional {label "Option 3"} {html {size 50}}} + {option4:text,optional {label "Option 4"} {html {size 50}}} + {option5:text,optional {label "Option 5"} {html {size 50}}} + {option6:text,optional {label "Option 6"} {html {size 50}}} + {option7:text,optional {label "Option 7"} {html {size 50}}} + {option8:text,optional {label "Option 8"} {html {size 50}}} + {option9:text,optional {label "Option 9"} {html {size 50}} {help_text {If you need to add more options you will be able to do so by editing this attributes details}}} +} -new_request { +} -edit_request { +} -validate { +} -on_submit { + + set i 1 + set options [list] + while { $i <= "9" } { + set option_value [string trim [set option${i}]] + ns_log notice $option_value + if { [exists_and_not_null option_value] } { + lappend options $option_value + } + incr i + } + + ams::attribute::new \ + -ams_attribute_id $ams_attribute_id \ + -object_type $object_type \ + -attribute_name $attribute_name \ + -pretty_name $pretty_name \ + -pretty_plural $pretty_plural \ + -description $description \ + -widget_name $widget_name \ + -options $options + +} -after_submit { + util_user_message -html -message $user_message + ad_returnredirect $return_url + ad_script_abort +} + + +ad_return_template Index: openacs-4/packages/ams/www/attribute-add.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/www/attribute-add.adp,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/ams/www/attribute-add.adp 30 Oct 2004 00:23:54 -0000 1.1 +++ openacs-4/packages/ams/www/attribute-add.adp 18 May 2005 17:11:48 -0000 1.2 @@ -1,9 +1,9 @@ - -@title@ -@context@ - - - - - - + +@title@ +@context@ + + + + + + Index: openacs-4/packages/ams/www/attribute-add.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/www/attribute-add.tcl,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/ams/www/attribute-add.tcl 30 Oct 2004 00:23:54 -0000 1.1 +++ openacs-4/packages/ams/www/attribute-add.tcl 18 May 2005 17:11:48 -0000 1.2 @@ -1,49 +1,195 @@ -ad_page_contract { - - @author Matthew Geddert openacs@geddert.com - @creation-date 2004-07-28 - @cvs-id $Id$ -} { - {object_type:notnull} - {list_id:integer} -} - -acs_object_type::get -object_type $object_type -array "object_info" - -set title "Add Attribute" -set context [list [list objects Objects] [list "object?object_type=$object_type" $object_info(pretty_name)] "Add Attribute"] - -set widget_options " [db_list_of_lists select_widgets { select widget_name, widget_name from ams_widgets order by widget_name } ]" - - -ad_form -name attribute_form -form { - {ams_attribute_id:key} - {list_id:integer(hidden)} - {object_type:text(hidden)} - {widget_name:text(multiselect) {label "Widget"} {options $widget_options } {help_text {Widgets descriptions are available}}} - {attribute_name:text {label "Attribute Name"} {html {size 30 maxlength 100}} {help_text {This name must be lower case, contain only letters and underscores, and contain no spaces}}} - {pretty_name:text {label "Pretty Name"} {html {size 30 maxlength 100}}} - {pretty_plural:text {label "Pretty Plural"} {html {size 30 maxlength 100}}} - {description:text(textarea),optional {label "Description"} {html {cols 55 rows 4}}} -} -new_request { -} -edit_request { -} -validate { - # i need to add validation that the attribute isn't already in the database - { attribute_name - { [::regexp {^([0-9]|[a-z]|\_){1,}$} $attribute_name match attribute_name_validate] } - "You have used invalid characters." - } - { attribute_name - { ![::attribute::exists_p $object_type $attribute_name] } - "Attribute $attribute_name already exists for $object_info(pretty_name)." - } -} -on_submit { -} -new_data { -} -edit_data { -} -after_submit { - ad_returnredirect "attribute-add-2?[export_vars -url {ams_attribute_id object_type widget_name attribute_name pretty_name pretty_plural description list_id}]" - ad_script_abort -} - - -ad_return_template +ad_page_contract { + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id$ +} { + {return_url:optional ""} + {return_url_label:optional ""} + {list_id:optional ""} + {object_type:notnull} + {widget:optional ""} + {attribute_name:optional ""} +} + +acs_object_type::get -object_type $object_type -array "object_info" + +set title "Add Attribute" +set context [list [list objects Objects] [list "object?object_type=$object_type" $object_info(pretty_name)] "Add Attribute"] + +ad_form -name attribute_form -form { + {ams_attribute_id:key} + {return_url:text(hidden),optional} + {return_url_label:text(hidden),optional} + {list_id:integer(hidden),optional} + {object_type:text(hidden)} + {mode:text(hidden),optional} + {widget:text(radio),optional {label "Widget"} {options {[lsort [::ams::widget_list]]}}} + {attribute_name:text,optional {label "Attribute Name"} {html {size 30 maxlength 100}} {help_text {This name must be lower case, contain only letters and underscores, and contain no spaces. If not specified one will be generated for you.}}} + {pretty_name:text,optional {label "Pretty Name"} {html {size 30 maxlength 100}}} + {pretty_plural:text,optional {label "Pretty Plural"} {html {size 30 maxlength 100}}} +} + + +#if { [ams::widget_has_options_p -widget $widget] } { +# foreach elemement [list option1 option2 option3 option4 option4] { +# ::template::element::set_properties attribute_form $element -widget text +# } +#} +if { [ams::widget_has_options_p -widget $widget] } { + set default_number_of_options 5 + set option_fields_count $default_number_of_options + set i 1 + set elements [list] + lappend elements [list option_fields_count:integer(hidden) [list value $option_fields_count]] +# lappend elements [list options_on_last_screen:integer(hidden),optional] + while { $i <= $option_fields_count } { + set element [list option${i}:text(text),optional [list label "Option $i"] [list html [list size 50]]] + if { $i == $option_fields_count } { + lappend element [list help_text "If you need to add more options you will be able to do so by editing this attributes again ($default_number_of_options new fields are added to the preexisting count each time you edit an attribute)"] + } + if { $i == 1 } { + lappend element [list section "Predefined Options"] + } + lappend elements $element + incr i + } + ad_form -extend -name attribute_form -form $elements +} + + + +ad_form -extend -name attribute_form -on_request { + set mode "new" + if { [::attribute::exists_p -convert_p 0 $object_type $attribute_name] } { + # this attribute already exists - so we are in "edit" mode for + ::template::element::set_properties attribute_form attribute_name -mode display + db_1row get_attr_info { select pretty_name, pretty_plural from acs_attributes where attribute_name = :attribute_name and object_type = :object_type } + set mode "edit" + } + if { [exists_and_not_null widget] } { + if { [string is false [ams::widget_proc_exists_p -widget $widget]] } { + ad_return_error "There was a problem with your input" "The widget specified does not exist" + } + ::template::element::set_properties attribute_form widget -widget select -mode display + } + set option_on_last_screen 1 +#::template::element set_properties attribute_form pretty_plural -widget hidden +# foreach field [list attribute_name pretty_name pretty_plural] { +# ::template::element set_properties attribute_form $field -mode display +# } +} -on_submit { + ams::widgets_init + if { [exists_and_not_null attribute_name] } { + if { [string is false [::regexp {^([0-9]|[a-z]|\_){1,}$} $attribute_name match attribute_name_matcher]] } { + ::template::form::set_error attribute_form attribute_name "You have used invalid characters." + } else { + ::template::element::set_properties attribute_form attribute_name -mode display + } + } else { + if { [exists_and_not_null pretty_name] } { + set attribute_name [util_text_to_url -replacement "_" -text $pretty_name] + set attribute_name_generated_p 1 + ::template::element::set_value attribute_form attribute_name $attribute_name + } + } + set required_fields [list widget pretty_name pretty_plural] + if { [exists_and_not_null option_fields_count] } { + lappend required_fields "option1" + } + foreach required_field $required_fields { + if { [string is false [exists_and_not_null ${required_field}]] } { + ::template::form::set_error attribute_form $required_field "[::template::element::get_property attribute_form $required_field label] is required" + } + } + + + + if { [exists_and_not_null widget] } { + ::template::element::set_properties attribute_form widget -widget select -mode display + } + if { $mode == "new" } { + if { [::attribute::exists_p -convert_p 0 $object_type $attribute_name] } { + if { [exists_and_not_null attribute_name_generated_p] } { + set message "The attribute name automatically generated for conflicts with an attribute that is already in the database. Please make sure you are not creating a duplicate attribute and change the name if not." + } else { + set message "This attribute name already exists. Please make sure you are not creating a duplicate attribute and change the name if not." + } + ::template::element::set_error attribute_form attribute_name $message + ::template::element::set_properties attribute_form attribute_name -mode edit + } + } +# ::template::form::set_error attribute_form attribute_name "$mode $attribute_name $object_type" + +# element::create attribute_form change_widget -datatype text -widget submit -label "Change Widget" +# { ![::attribute::exists_p $object_type $attribute_name] } +# "Attribute $attribute_name already exists for $object_info(pretty_name)." + +# if { [exists_and_not_null option_fields_count] } { +# if { xists_and_not_null options_on_last_screen] && [string is false [exists_and_not_null option1]] } { +# ::template::form::set_error attribute_form option1 "Option 1 is required" +# } else { +# ::template::element::set_value attribute_form options_on_last_screen 1 +# } +# } + + + if { [::template::form::is_valid attribute_form] } { + + + db_transaction { + # the form has passed all validation blocks +# ::template::element::set_error attribute_form attribute_name "valid" + if { $mode == "new" } { + set attribute_id [attribute::new \ + -object_type $object_type \ + -attribute_name $attribute_name \ + -datatype [::ams::widget -widget $widget -request "widget_datatypes"] \ + -pretty_name $pretty_name \ + -pretty_plural $pretty_plural] + set dynamic_p 1 + } else { + set attribute_id [attribute::id \ + -object_type $object_type \ + -attribute_name $attribute_name] + set dynamic_p 0 + } + ams::attribute::new \ + -attribute_id $attribute_id \ + -ams_attribute_id $ams_attribute_id \ + -widget $widget \ + -dynamic_p $dynamic_p + + if { [ams::widget_has_options_p -widget $widget] && [exists_and_not_null option_fields_count] } { + set i 1 + while { $i <= $option_fields_count } { + set option [set "option${i}"] + if { [exists_and_not_null option] } { + ams::option::new \ + -attribute_id $attribute_id \ + -option $option + } + incr i + } + } + } + } else { + break + } +} -after_submit { + if { [exists_and_not_null list_id] } { + ams::list::attribute::map -list_id $list_id -attribute_id $attribute_id + ams::list::get -list_id $list_id -array list_info + set list_name $list_info(list_name) + set object_type $list_info(object_type) + set package_key $list_info(package_key) + set return_url [export_vars -base "list" -url {list_name object_type package_key return_url return_url_label}] + } else { + set return_url [export_vars -base "object" -url {object_type return_url return_url_label}] + } + ad_returnredirect -message "$pretty_name has been added as an attribute to $object_type" $return_url + ad_script_abort +} + + +ad_return_template Index: openacs-4/packages/ams/www/attribute-option-delete.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/www/attribute-option-delete.tcl,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/ams/www/attribute-option-delete.tcl 30 Oct 2004 00:23:54 -0000 1.1 +++ openacs-4/packages/ams/www/attribute-option-delete.tcl 18 May 2005 17:11:48 -0000 1.2 @@ -1,25 +1,25 @@ -ad_page_contract { - - Update sort order - - @author Matthew Geddert openacs@geddert.com - @creation-date 2004-07-28 - @cvs-id $Id$ - - -} { - option_id:integer,notnull -} -validate { - option_has_no_entries -requires {option_id} { - if { ![string match [db_string get_count { select count(*) from ams_option_map where option_id = :option_id } -default {0}] {0}] } { - ad_complain {You cannot delete an option that already has entries on it} - } - } -} - -db_1row get_option_info { select * from ams_options where option_id = :option_id } - -db_dml delete_option { delete from ams_options where option_id = :option_id } - - -ad_returnredirect -message "Option Deleted" "attribute?[export_vars -url {ams_attribute_id}]" +ad_page_contract { + + Update sort order + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id$ + + +} { + option_id:integer,notnull +} -validate { + option_has_no_entries -requires {option_id} { + if { ![string match [db_string get_count { select count(*) from ams_option_map where option_id = :option_id } -default {0}] {0}] } { + ad_complain {You cannot delete an option that already has entries on it} + } + } +} + +db_1row get_option_info { select * from ams_options where option_id = :option_id } + +db_dml delete_option { delete from ams_options where option_id = :option_id } + + +ad_returnredirect -message "Option Deleted" "attribute?[export_vars -url {ams_attribute_id}]" Index: openacs-4/packages/ams/www/attribute-options-update.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/www/attribute-options-update.tcl,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/ams/www/attribute-options-update.tcl 30 Oct 2004 00:23:54 -0000 1.1 +++ openacs-4/packages/ams/www/attribute-options-update.tcl 18 May 2005 17:11:48 -0000 1.2 @@ -1,51 +1,50 @@ -ad_page_contract { - - Update sort order - - @author Matthew Geddert openacs@geddert.com - @creation-date 2004-07-28 - @cvs-id $Id$ - - -} { - option:array - sort_key:array - ams_attribute_id:integer,notnull -} -# first we check to see if there are new options. -# if yes we add them -foreach option_key [list new1 new2 new3] { - set option_string [string trim $option(${option_key})] - if { [exists_and_not_null option_string] } { - set option_id [ams::option::new -ams_attribute_id $ams_attribute_id -option $option_string] - set sort_key(${option_id}) $sort_key(${option_key}) - } -} - -# now that all the options are in the database we get the "old" sort order -# if not value for sort_key is provided we will keep the same order as before -set option_ids [db_list get_option_ids { select option_id from ams_options where ams_attribute_id = :ams_attribute_id order by sort_order }] - -# first we get the highest sort_order so variables without a sort_order can be given one -set highest_sort 0 -foreach option_id $option_ids { - if { $sort_key(${option_id}) > $highest_sort } { - set highest_sort $sort_key(${option_id}) - } -} - - -db_transaction { - foreach option_id $option_ids { - set sort_order $sort_key(${option_id}) - incr highest_sort - db_dml update_sort_order { update ams_options set sort_order = :highest_sort where sort_order = :sort_order and ams_attribute_id = :ams_attribute_id } - if { ![exists_and_not_null sort_order] } { - incr highest_sort 1 - set sort_order $highest_sort - } - db_dml update_sort_order { update ams_options set sort_order = :sort_order where option_id = :option_id } - } -} -ams::attribute::flush -ams_attribute_id $ams_attribute_id -ad_returnredirect -message "Options Updated" "attribute?[export_vars -url {ams_attribute_id}]" +ad_page_contract { + + Update sort order + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id$ + + +} { + option:array + sort_key:array + attribute_id:integer,notnull +} +# first we check to see if there are new options. +# if yes we add them +foreach option_key [list new1 new2 new3] { + set option_string [string trim $option(${option_key})] + if { [exists_and_not_null option_string] } { + set option_id [ams::option::new -attribute_id $attribute_id -option $option_string] + set sort_key(${option_id}) $sort_key(${option_key}) + } +} + +# now that all the options are in the database we get the "old" sort order +# if not value for sort_key is provided we will keep the same order as before +set option_ids [db_list get_option_ids { select option_id from ams_option_types where attribute_id = :attribute_id order by sort_order }] + +# first we get the highest sort_order so variables without a sort_order can be given one +set highest_sort 0 +foreach option_id $option_ids { + if { $sort_key(${option_id}) > $highest_sort } { + set highest_sort $sort_key(${option_id}) + } +} + + +db_transaction { + foreach option_id $option_ids { + set sort_order $sort_key(${option_id}) + incr highest_sort + db_dml update_sort_order { update ams_option_types set sort_order = :highest_sort where sort_order = :sort_order and attribute_id = :attribute_id } + if { ![exists_and_not_null sort_order] } { + incr highest_sort 1 + set sort_order $highest_sort + } + db_dml update_sort_order { update ams_option_types set sort_order = :sort_order where option_id = :option_id } + } +} +ad_returnredirect -message "Options Updated" "attribute?[export_vars -url {attribute_id}]" Index: openacs-4/packages/ams/www/attribute.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/www/attribute.adp,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/ams/www/attribute.adp 30 Oct 2004 00:23:54 -0000 1.1 +++ openacs-4/packages/ams/www/attribute.adp 18 May 2005 17:11:48 -0000 1.2 @@ -1,12 +1,13 @@ - - -@title@ -@context@ - -

Pretty Name: @pretty_name@

-

Pretty Plural: @pretty_plural@

-

Widget: @attribute_info.widget_name@

- - - - + + +@title@ +@context@ + +

Pretty Name: @pretty_name@

+

Pretty Plural: @pretty_plural@

+

Widget: @attribute_info.widget@

+ + + + + Index: openacs-4/packages/ams/www/attribute.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/www/attribute.tcl,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/ams/www/attribute.tcl 30 Oct 2004 00:23:54 -0000 1.1 +++ openacs-4/packages/ams/www/attribute.tcl 18 May 2005 17:11:48 -0000 1.2 @@ -1,129 +1,108 @@ -ad_page_contract { - - @author Matthew Geddert openacs@geddert.com - @creation-date 2004-07-28 - @cvs-id $Id$ - - -} { - {ams_attribute_id:notnull} - orderby:optional -} - -ams::attribute::get -ams_attribute_id $ams_attribute_id -array "attribute_info" -acs_object_type::get -object_type $attribute_info(object_type) -array "object_info" - - -set pretty_name [_ $attribute_info(pretty_name)] -set pretty_plural [_ $attribute_info(pretty_plural)] -set title $pretty_name -set context [list [list objects Objects] [list "object?object_type=$attribute_info(object_type)" $object_info(pretty_name)] $title] - - - - -list::create \ - -name options \ - -multirow options \ - -key option_id \ - -row_pretty_plural "Options" \ - -checkbox_name checkbox \ - -selected_format "normal" \ - -class "list" \ - -main_class "list" \ - -sub_class "narrow" \ - -pass_properties { - } -actions { - } -bulk_action_export_vars { - ams_attribute_id - } -bulk_actions { - "Update" "attribute-options-update" "Update Options" - } -elements { - edit { - label {} - } - option { - label "Option" - display_template { - - @options.option@ - - - - - } - } - sort_order { - label "Sort Order" - display_template { - - } - } - actions { - label "" - display_template { - Delete - } - } - } -filters { - } -groupby { - } -orderby { - default_value default_sort,asc - default_sort { - label default_sort - multirow_cols {sort_key option} - } - } -formats { - normal { - label "Table" - layout table - row { - option {} - sort_order {} - actions {} - } - } - } - - -set sort_count 10 -set sort_key_count 10000 -db_multirow -extend { sort_order sort_key } options select_options { - select option_id, option, - CASE WHEN ( select '1' from ams_option_map where ams_option_map.option_id = ams_options.option_id limit 1 ) IS NULL THEN 0 ELSE 1 END as in_use_p - from ams_options - where ams_attribute_id = :ams_attribute_id - order by sort_order -} { - set option [_ $option] - set sort_order $sort_count - set sort_key $sort_key_count - incr sort_count 10 - incr sort_key_count 1 -} - - -set sort_order $sort_count -set sort_key $sort_key_count -template::multirow append options {new1} {} 1 $sort_count $sort_key -template::multirow append options {new2} {} 1 [incr sort_count 10] [incr sort_key 1] -template::multirow append options {new3} {} 1 [incr sort_count 10] [incr sort_key 1] - - - - - - - - - - - - - - - - - - -ad_return_template +ad_page_contract { + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id$ + +} { + {attribute_id:notnull} + orderby:optional +} + +#db_1row get_attribute_info {} +ams::attribute::get -attribute_id $attribute_id -array "attribute_info" +acs_object_type::get -object_type $attribute_info(object_type) -array "object_info" + + +set pretty_name $attribute_info(pretty_name) +set pretty_plural $attribute_info(pretty_plural) +set title $pretty_name +set context [list [list objects Objects] [list "object?object_type=$attribute_info(object_type)" $object_info(pretty_name)] $title] + +list::create \ + -name options \ + -multirow options \ + -key option_id \ + -row_pretty_plural "Options" \ + -checkbox_name checkbox \ + -selected_format "normal" \ + -class "list" \ + -main_class "list" \ + -sub_class "narrow" \ + -pass_properties { + } -actions { + } -bulk_action_export_vars { + attribute_id + } -bulk_actions { + "Update" "attribute-options-update" "Update Options" + } -elements { + edit { + label {} + } + option { + label "Option" + display_template { + + @options.option@ + + + + + } + } + sort_order { + label "Sort Order" + display_template { + + } + } + actions { + label "" + display_template { + Delete + } + } + } -filters { + } -groupby { + } -orderby { + default_value default_sort,asc + default_sort { + label default_sort + multirow_cols {sort_key option} + } + } -formats { + normal { + label "Table" + layout table + row { + option {} + sort_order {} + actions {} + } + } + } + + +set sort_count 10 +set sort_key_count 10000 +db_multirow -extend { sort_order sort_key } options select_options { + select option_id, option, + CASE WHEN ( select '1' from ams_options where ams_options.option_id = ams_option_types.option_id limit 1 ) IS NULL THEN 0 ELSE 1 END as in_use_p + from ams_option_types + where attribute_id = :attribute_id + order by sort_order +} { + set sort_order $sort_count + set sort_key $sort_key_count + incr sort_count 10 + incr sort_key_count 1 +} + +if { [template::multirow size options] > 0 } { + set sort_order $sort_count + set sort_key $sort_key_count + template::multirow append options {new1} {} 1 $sort_count $sort_key + template::multirow append options {new2} {} 1 [incr sort_count 10] [incr sort_key 1] + template::multirow append options {new3} {} 1 [incr sort_count 10] [incr sort_key 1] +} +ad_return_template Index: openacs-4/packages/ams/www/index.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/www/index.adp,v diff -u -N -r1.3 -r1.4 --- openacs-4/packages/ams/www/index.adp 30 Oct 2004 00:23:54 -0000 1.3 +++ openacs-4/packages/ams/www/index.adp 18 May 2005 17:11:48 -0000 1.4 @@ -1,9 +1,9 @@ - -@title@ -@context@ - - + +@title@ +@context@ +@fred@ + Index: openacs-4/packages/ams/www/index.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/www/index.tcl,v diff -u -N -r1.5 -r1.6 --- openacs-4/packages/ams/www/index.tcl 30 Oct 2004 00:23:54 -0000 1.5 +++ openacs-4/packages/ams/www/index.tcl 18 May 2005 17:11:48 -0000 1.6 @@ -1,102 +1,112 @@ -ad_page_contract { - - @author Matthew Geddert openacs@geddert.com - @creation-date 2004-07-28 - @cvs-id $Id$ - - -} { -} - -set title "Attribute Management System" -set context {} - - - -# Once done comment out the error line -# ad_return_error "You need to specify and valid object id in the packages/ams/www/index.tcl file" "Once done comment out this line." - - - -#set package_key "ams" -#set object_type "ams_list" -#set list_name "ams_list_demo3" -#set pretty_name "The Fields used to Add/Edit a Contact Person" -# -#ams::define_list -package_key $package_key \ -# -object_type $object_type \ -# -list_name $list_name \ -# -pretty_name $pretty_name \ -# -attributes { -# {first_names textbox {First Name(s)} {First Names} required {description {this is my description of first names}}} -# {middle_names textbox {Middle Name(s)} {Middle Names}} -# {last_name textbox {Last Name} {Last Names} required} -# {email email {Email Address} {Email Addresses}} -# {url url {Website} {Websites}} -# {home_address address {Home Address} {Home Addresses}} -# {organization_address address {Organization Address} {Organization Addresses}} -# {home_phone telecom_number {Home Phone} {Home Phones}} -# {gender radio {Gender} {Genders} {options {{Male} {Female}}} required} -# } -# -#set object_id [ams::list::get_list_id \ -# -package_key $package_key \ -# -object_type $object_type \ -# -list_name $list_name] -#set object_id "452" -##ad_form -name entry \ -## -form [ams::ad_form::elements -package_key $package_key \ -## -object_type $object_type \ -## -list_name $list_name \ -## -key "object_id"] \ -# -edit_request { -# ams::object::attribute::values -vars -object_id $object_id -# } -on_submit { -# ams::ad_form::save -package_key $package_key \ -# -object_type $object_type \ -# -list_name $list_name \ -# -form_name "entry" \ -# -object_id $object_id -# } -after_submit { -# if { ![exists_and_not_null return_url] } { -# set return_url "./" -# } -# } -# - -#ams_form -package_key $package_key \ -# -object_type $object_type \ -# -list_name $list_name \ -# -form_name "entry" \ -# -object_id $object_id \ -# -return_url "./" -# -# set attr_list [ams::object::attribute::values_flush -object_id $object_id] -#set attr_list [ams::object::attribute::values -object_id $object_id] -# -# -#db_multirow lists get_list { select list_id, pretty_name from ams_lists } -# -#ams::multirow::extend \ -# -package_key $package_key \ -# -object_type $object_type \ -# -list_name $list_name \ -# -multirow "lists" \ -# -key "list_id" -## -##template::multirow extend lists [list first_names last_name home_address first_names] -## -## -#set key_id "list_id" -#template::multirow foreach lists { -# set object_id [set $key_id] -# ams::object::attribute::values -vars -object_id $object_id -#} -## set attr_list $rowcount -#template::multirow foreach lists { -# ns_log Notice "$first_names $last_name $home_address" -#} - - - -ad_return_template +ad_page_contract { + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id$ + + +} { +} + +set title "Attribute Management System" +set context {} + + + +# Once done comment out the error line +# ad_return_error "You need to specify and valid object id in the packages/ams/www/index.tcl file" "Once done comment out this line." + + + +#set package_key "ams" +#set object_type "ams_list" +#set list_name "ams_list_demo3" +#set pretty_name "The Fields used to Add/Edit a Contact Person" +# +#ams::define_list -package_key $package_key \ +# -object_type $object_type \ +# -list_name $list_name \ +# -pretty_name $pretty_name \ +# -attributes { +# {first_names textbox {First Name(s)} {First Names} required {description {this is my description of first names}}} +# {middle_names textbox {Middle Name(s)} {Middle Names}} +# {last_name textbox {Last Name} {Last Names} required} +# {email email {Email Address} {Email Addresses}} +# {url url {Website} {Websites}} +# {home_address address {Home Address} {Home Addresses}} +# {organization_address address {Organization Address} {Organization Addresses}} +# {home_phone telecom_number {Home Phone} {Home Phones}} +# {gender radio {Gender} {Genders} {options {{Male} {Female}}} required} +# } +# +#set object_id [ams::list::get_list_id \ +# -package_key $package_key \ +# -object_type $object_type \ +# -list_name $list_name] +#set object_id "452" +##ad_form -name entry \ +## -form [ams::ad_form::elements -package_key $package_key \ +## -object_type $object_type \ +## -list_name $list_name \ +## -key "object_id"] \ +# -edit_request { +# ams::object::attribute::values -vars -object_id $object_id +# } -on_submit { +# ams::ad_form::save -package_key $package_key \ +# -object_type $object_type \ +# -list_name $list_name \ +# -form_name "entry" \ +# -object_id $object_id +# } -after_submit { +# if { ![exists_and_not_null return_url] } { +# set return_url "./" +# } +# } +# + +#ams_form -package_key $package_key \ +# -object_type $object_type \ +# -list_name $list_name \ +# -form_name "entry" \ +# -object_id $object_id \ +# -return_url "./" +# +# set attr_list [ams::object::attribute::values_flush -object_id $object_id] +#set attr_list [ams::object::attribute::values -object_id $object_id] +# +# +#db_multirow lists get_list { select list_id, pretty_name from ams_lists } +# +#ams::multirow::extend \ +# -package_key $package_key \ +# -object_type $object_type \ +# -list_name $list_name \ +# -multirow "lists" \ +# -key "list_id" +## +##template::multirow extend lists [list first_names last_name home_address first_names] +## +## +#set key_id "list_id" +#template::multirow foreach lists { +# set object_id [set $key_id] +# ams::object::attribute::values -vars -object_id $object_id +#} +## set attr_list $rowcount +#template::multirow foreach lists { +# ns_log Notice "$first_names $last_name $home_address" +#} + + +set fred "" + +foreach { arg_parser procedure } [info procs "::ams::widget::*"] { + regsub "::ams::widget::" $procedure "" widget + if { [exists_and_not_null widget] } { + lappend fred $widget + } +} +set fred "date" +set fred [info procs "::ams::widget::${fred}"] + +ad_return_template Index: openacs-4/packages/ams/www/list-add.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/www/list-add.adp,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/ams/www/list-add.adp 30 Oct 2004 00:23:54 -0000 1.1 +++ openacs-4/packages/ams/www/list-add.adp 18 May 2005 17:11:48 -0000 1.2 @@ -1,11 +1,11 @@ - -@title@ -@context@ - -

Note: Adding an AMS List here is primarily for demonstration purposes. In order for AMS Lists to be useful you need to integrated them with your package.

- - - - - - + +@title@ +@context@ + +

Note: Adding an AMS List here is primarily for demonstration purposes. In order for AMS Lists to be useful you need to integrated them with your package.

+ + + + + + Index: openacs-4/packages/ams/www/list-add.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/www/list-add.tcl,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/ams/www/list-add.tcl 30 Oct 2004 00:23:54 -0000 1.1 +++ openacs-4/packages/ams/www/list-add.tcl 18 May 2005 17:11:48 -0000 1.2 @@ -1,65 +1,98 @@ -ad_page_contract { - - @author Matthew Geddert openacs@geddert.com - @creation-date 2004-07-28 - @cvs-id $Id$ -} { - {object_type:notnull} - {package_key ""} -} - -acs_object_type::get -object_type $object_type -array "object_info" - -set title "Add List" -set context [list [list objects Objects] [list "object?object_type=$object_type" $object_info(pretty_name)] "Add List"] - -set package_options " [db_list_of_lists select_packages { select package_key, package_key from apm_package_types order by package_key } ]" - -if { [exists_and_not_null package_key] && [exists_and_not_null object_type] && [exists_and_not_null list_name] } { - ams::list::flush -package_key $package_key -object_type $object_type -list_name $list_name -} - -ad_form -name list_form -form { - {list_id:key} - {package_key:text(select) {label "Package Key"} {options $package_options}} - {object_type:text(inform) {label "Object Type"}} - {list_name:text {label "List Name"} {html {size 30 maxlength 100}} {help_text {This name must be lower case, contain only letters and underscores, and contain no spaces}}} - {pretty_name:text {label "Pretty Name"} {html {size 30 maxlength 100}}} - {pretty_plural:text {label "Pretty Plural"} {html {size 30 maxlength 100}}} - {description:text(textarea),optional {label "Description"} {html {cols 55 rows 4}}} -} -new_request { -} -edit_request { -} -validate { - # i need to add validation that the attribute isn't already in the database - { list_name - { [::regexp {^([0-9]|[a-z]|\_){1,}$} $list_name match list_name_validate] } - "You have used invalid characters." - } - { list_name - { ![::ams::list::exists_p -package_key $package_key -object_type $object_type -list_name $list_name] } - "List name $list_name already exists for $object_info(pretty_name)." - } -} -on_submit { - - ams::list::flush -package_key $package_key -object_type $object_type -list_name $list_name - - ams::list::new -list_id $list_id \ - -package_key $package_key \ - -object_type $object_type \ - -list_name $list_name \ - -pretty_name $pretty_name \ - -description $description \ - -description_mime_type "text/plain" \ - -context_id "" - - ams::list::flush -package_key $package_key -object_type $object_type -list_name $list_name - - -} -edit_data { -} -after_submit { - ad_returnredirect "list?[export_vars -url {package_key object_type list_name}]" - ad_script_abort -} - - -ad_return_template +ad_page_contract { + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id$ +} { + {object_type:notnull} + {package_key ""} + {list_name ""} + {pretty_name ""} + {description ""} + {return_url ""} + {return_url_label ""} +} + +acs_object_type::get -object_type $object_type -array "object_info" + +set title "Add List" +set context [list [list objects Objects] [list "object?object_type=$object_type" $object_info(pretty_name)] "Add List"] + +set package_options " [db_list_of_lists select_packages { select package_key, package_key from apm_package_types order by package_key } ]" + +if { [exists_and_not_null package_key] && [exists_and_not_null object_type] && [exists_and_not_null list_name] } { + ams::list::flush -package_key $package_key -object_type $object_type -list_name $list_name +} + +ad_form -name list_form -form { + {list_id:key} + {package_key:text(select) {label "Package Key"} {options $package_options}} + {object_type:text(inform) {label "Object Type"}} + {list_name:text {label "List Name"} {html {size 30 maxlength 100}} {help_text {This name must be lower case, contain only letters and underscores, and contain no spaces}}} + {pretty_name:text {label "Pretty Name"} {html {size 30 maxlength 100}}} + {description:text(textarea),optional {label "Description"} {html {cols 55 rows 4}}} + return_url:text(hidden),optional + return_url_label:text(hidden),optional +} -new_request { + set uneditable_attributes [list package_key object_type list_name pretty_name description] + set blank_required_attributes [list] + foreach attribute $uneditable_attributes { + if { [set $attribute] != "" } { + template::element::set_properties list_form $attribute mode display + } else { + if { $attribute != "description" } { + lappend blank_required_attributes $attribute + } + } + } + # if the only blank attribute is description we can create this list (since all the data was + # provided by the request of this page + if { [string is false [exists_and_not_null blank_required_attributes]] } { + util_user_message -replace + ams::list::flush -package_key $package_key -object_type $object_type -list_name $list_name + ams::list::new -package_key $package_key \ + -object_type $object_type \ + -list_name $list_name \ + -pretty_name $pretty_name \ + -description $description \ + -description_mime_type "text/plain" \ + -context_id "" + ams::list::flush -package_key $package_key -object_type $object_type -list_name $list_name + ad_returnredirect "list?[export_vars -url {package_key object_type list_name return_url return_url_label}]" + ad_script_abort + } +} -edit_request { +} -validate { + # i need to add validation that the attribute isn't already in the database + { list_name + { [::regexp {^([0-9]|[a-z]|\_){1,}$} $list_name match list_name_validate] } + "You have used invalid characters." + } + { list_name + { ![::ams::list::exists_p -package_key $package_key -object_type $object_type -list_name $list_name] } + "List name $list_name already exists for $object_info(pretty_name)." + } +} -on_submit { + + ams::list::flush -package_key $package_key -object_type $object_type -list_name $list_name + + ams::list::new -list_id $list_id \ + -package_key $package_key \ + -object_type $object_type \ + -list_name $list_name \ + -pretty_name $pretty_name \ + -description $description \ + -description_mime_type "text/plain" \ + -context_id "" + + ams::list::flush -package_key $package_key -object_type $object_type -list_name $list_name + + +} -edit_data { +} -after_submit { + ad_returnredirect "list?[export_vars -url {package_key object_type list_name return_url return_url_label}]" + ad_script_abort +} + + +ad_return_template Index: openacs-4/packages/ams/www/list-attribute-section-heading.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/www/list-attribute-section-heading.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ams/www/list-attribute-section-heading.adp 18 May 2005 17:11:48 -0000 1.1 @@ -0,0 +1,10 @@ + +@title@ +@context@ + + + + + + + Index: openacs-4/packages/ams/www/list-attribute-section-heading.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/www/list-attribute-section-heading.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ams/www/list-attribute-section-heading.tcl 18 May 2005 17:11:48 -0000 1.1 @@ -0,0 +1,53 @@ +ad_page_contract { + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id: list-attribute-section-heading.tcl,v 1.1 2005/05/18 17:11:48 matthewg Exp $ +} { + {list_id:integer,notnull} + {attribute_id:integer,notnull} +} + +db_0or1row get_heading { select aa.pretty_name as attribute_pretty_name, + al.package_key, + al.object_type, + al.list_name, + al.pretty_name as list_pretty_name, + alam.section_heading + from ams_list_attribute_map alam, + ams_attributes aa, + ams_lists al + where alam.attribute_id = aa.attribute_id + and alam.list_id = al.list_id + and alam.list_id = :list_id + and alam.attribute_id = :attribute_id +} +set title "Add a Heading Above: ${attribute_pretty_name}" +set context [list [list lists Lists] [list [ams::list::url -package_key $package_key -object_type $object_type -list_name $list_name] ${list_pretty_name}] $title] + +set package_options " [db_list_of_lists select_packages { select package_key, package_key from apm_package_types order by package_key } ]" + +ad_form -name list_form -form { + list_id:integer(hidden) + attribute_id:integer(hidden) + {section_heading:text {label "Heading"} {html {size 40 maxlength 200}}} + {save:text(submit) {label "Save"}} + {delete:text(submit) {label "Delete Heading"}} +} -on_request { +} -on_submit { + if { [string is true [exists_and_not_null delete]] } { + set section_heading "" + } + db_dml update_section_heading { + update ams_list_attribute_map + set section_heading = :section_heading + where list_id = :list_id + and attribute_id = :attribute_id + } +} -after_submit { + ad_returnredirect "list?[export_vars -url {package_key object_type list_name}]" + ad_script_abort +} + + +ad_return_template Index: openacs-4/packages/ams/www/list-attributes-map.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/www/list-attributes-map.tcl,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/ams/www/list-attributes-map.tcl 30 Oct 2004 00:23:54 -0000 1.1 +++ openacs-4/packages/ams/www/list-attributes-map.tcl 18 May 2005 17:11:48 -0000 1.2 @@ -1,23 +1,22 @@ -ad_page_contract { - - - @author Matthew Geddert openacs@geddert.com - @creation-date 2004-07-28 - @cvs-id $Id$ - -} { - {ams_attribute_id:integer,multiple} - {list_id:integer,notnull} -} - -foreach ams_attribute_id $ams_attribute_id { - ams::list::attribute::map -list_id $list_id -ams_attribute_id $ams_attribute_id -} - -ams::list::get -list_id $list_id -array "list_info" -set package_key $list_info(package_key) -set object_type $list_info(object_type) -set list_name $list_info(list_name) - -ad_returnredirect "list?[export_vars -url {package_key object_type list_name}]" -ad_script_abort +ad_page_contract { + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id$ + +} { + {attribute_id:integer,multiple} + {list_id:integer,notnull} +} + +foreach attribute_id $attribute_id { + ams::list::attribute::map -list_id $list_id -attribute_id $attribute_id +} + +ams::list::get -list_id $list_id -array "list_info" +set package_key $list_info(package_key) +set object_type $list_info(object_type) +set list_name $list_info(list_name) + +ad_returnredirect "list?[export_vars -url {package_key object_type list_name}]" +ad_script_abort Index: openacs-4/packages/ams/www/list-attributes-optional.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/www/list-attributes-optional.tcl,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/ams/www/list-attributes-optional.tcl 30 Oct 2004 00:23:54 -0000 1.1 +++ openacs-4/packages/ams/www/list-attributes-optional.tcl 18 May 2005 17:11:48 -0000 1.2 @@ -1,23 +1,23 @@ -ad_page_contract { - - - @author Matthew Geddert openacs@geddert.com - @creation-date 2004-07-28 - @cvs-id $Id$ - -} { - {ams_attribute_id:integer,multiple,notnull} - {list_id:integer,notnull} -} - -foreach ams_attribute_id $ams_attribute_id { - ams::list::attribute::optional -list_id $list_id -ams_attribute_id $ams_attribute_id -} - -ams::list::get -list_id $list_id -array "list_info" -set package_key $list_info(package_key) -set object_type $list_info(object_type) -set list_name $list_info(list_name) - -ad_returnredirect "list?[export_vars -url {package_key object_type list_name}]" -ad_script_abort +ad_page_contract { + + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id$ + +} { + {attribute_id:integer,multiple,notnull} + {list_id:integer,notnull} +} + +foreach attribute_id $attribute_id { + ams::list::attribute::optional -list_id $list_id -attribute_id $attribute_id +} + +ams::list::get -list_id $list_id -array "list_info" +set package_key $list_info(package_key) +set object_type $list_info(object_type) +set list_name $list_info(list_name) + +ad_returnredirect "list?[export_vars -url {package_key object_type list_name}]" +ad_script_abort Index: openacs-4/packages/ams/www/list-attributes-required.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/www/list-attributes-required.tcl,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/ams/www/list-attributes-required.tcl 30 Oct 2004 00:23:54 -0000 1.1 +++ openacs-4/packages/ams/www/list-attributes-required.tcl 18 May 2005 17:11:48 -0000 1.2 @@ -1,23 +1,23 @@ -ad_page_contract { - - - @author Matthew Geddert openacs@geddert.com - @creation-date 2004-07-28 - @cvs-id $Id$ - -} { - {ams_attribute_id:integer,multiple,notnull} - {list_id:integer,notnull} -} - -foreach ams_attribute_id $ams_attribute_id { - ams::list::attribute::required -list_id $list_id -ams_attribute_id $ams_attribute_id -} - -ams::list::get -list_id $list_id -array "list_info" -set package_key $list_info(package_key) -set object_type $list_info(object_type) -set list_name $list_info(list_name) - -ad_returnredirect "list?[export_vars -url {package_key object_type list_name}]" -ad_script_abort +ad_page_contract { + + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id$ + +} { + {attribute_id:integer,multiple,notnull} + {list_id:integer,notnull} +} + +foreach attribute_id $attribute_id { + ams::list::attribute::required -list_id $list_id -attribute_id $attribute_id +} + +ams::list::get -list_id $list_id -array "list_info" +set package_key $list_info(package_key) +set object_type $list_info(object_type) +set list_name $list_info(list_name) + +ad_returnredirect "list?[export_vars -url {package_key object_type list_name}]" +ad_script_abort Index: openacs-4/packages/ams/www/list-attributes-unmap.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/www/list-attributes-unmap.tcl,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/ams/www/list-attributes-unmap.tcl 30 Oct 2004 00:23:54 -0000 1.1 +++ openacs-4/packages/ams/www/list-attributes-unmap.tcl 18 May 2005 17:11:48 -0000 1.2 @@ -1,22 +1,22 @@ -ad_page_contract { - - @author Matthew Geddert openacs@geddert.com - @creation-date 2004-07-28 - @cvs-id $Id$ - -} { - {ams_attribute_id:integer,multiple} - {list_id:integer,notnull} -} - -foreach ams_attribute_id $ams_attribute_id { - ams::list::attribute::unmap -list_id $list_id -ams_attribute_id $ams_attribute_id -} - -ams::list::get -list_id $list_id -array "list_info" -set package_key $list_info(package_key) -set object_type $list_info(object_type) -set list_name $list_info(list_name) - -ad_returnredirect "list?[export_vars -url {package_key object_type list_name}]" -ad_script_abort +ad_page_contract { + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id$ + +} { + {attribute_id:integer,multiple} + {list_id:integer,notnull} +} + +foreach attribute_id $attribute_id { + ams::list::attribute::unmap -list_id $list_id -attribute_id $attribute_id +} + +ams::list::get -list_id $list_id -array "list_info" +set package_key $list_info(package_key) +set object_type $list_info(object_type) +set list_name $list_info(list_name) + +ad_returnredirect "list?[export_vars -url {package_key object_type list_name}]" +ad_script_abort Index: openacs-4/packages/ams/www/list-attributes.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/www/list-attributes.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ams/www/list-attributes.tcl 18 May 2005 17:11:48 -0000 1.1 @@ -0,0 +1,23 @@ +ad_page_contract { + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id: list-attributes.tcl,v 1.1 2005/05/18 17:11:48 matthewg Exp $ + +} { + {attribute_id:integer,multiple} + {list_id:integer,notnull} + {command "map"} +} + +foreach attribute_id $attribute_id { + ams::list::attribute::${command} -list_id $list_id -attribute_id $attribute_id +} + +ams::list::get -list_id $list_id -array "list_info" +set package_key $list_info(package_key) +set object_type $list_info(object_type) +set list_name $list_info(list_name) + +ad_returnredirect "list?[export_vars -url {package_key object_type list_name}]" +ad_script_abort Index: openacs-4/packages/ams/www/list-code.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/www/list-code.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ams/www/list-code.adp 18 May 2005 17:11:48 -0000 1.1 @@ -0,0 +1,47 @@ + +@title@ +@context@ + +

Here is the code necessary to re-create this ams-list on a new system. You may insert this into your appliation code if you would like to.

+
+set list_id [ams::list::new \
+                -package_key "@list_info.package_key@" \
+                -object_type "@list_info.object_type@" \
+                -list_name "@list_info.list_name@" \
+                -pretty_name "@list_info.pretty_name@" \
+                -description "@list_info.description@" \
+                -description_mime_type "@list_info.description_mime_type@"
+
+
+
+
+set attribute_id [attribute::new \
+              -object_type "@attributes.object_type@" \
+              -attribute_name "@attributes.attribute_name@" \
+              -datatype "@attributes.datatype@" \
+              -pretty_name "@attributes.pretty_name@" \
+              -pretty_plural "@attributes.pretty_plural@" \
+              -table_name "@attributes.table_name@" \
+              -column_name "@attributes.column_name@" \
+              -default_value "@attributes.default_value@" \
+              -min_n_values "@attributes.min_n_values@" \
+              -max_n_values "@attributes.max_n_values@" \
+              -sort_order "@attributes.sort_order@" \
+              -storage "@attributes.storage@" \
+              -static_p "@attributes.static_p@" \
+              -if_does_not_exist]
+
+ams::attribute::new \
+              -attribute_id $attribute_id \
+              -widget "@attributes.widget@" \
+              -dynamic_p "@attributes.dynamic_p@"
+
+ams::list::attribute::map \
+              -list_id $list_id \
+              -attribute_id $attribute_id \
+              -sort_order "@attributes.list_sort_order@" \
+              -required_p "@attributes.required_p@" \
+              -section_heading "@attributes.section_heading@"
+
+
+
\ No newline at end of file Index: openacs-4/packages/ams/www/list-code.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/www/list-code.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ams/www/list-code.tcl 18 May 2005 17:11:48 -0000 1.1 @@ -0,0 +1,53 @@ +ad_page_contract { + + This page lets users manage ams lists + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id: list-code.tcl,v 1.1 2005/05/18 17:11:48 matthewg Exp $ + +} { + package_key:notnull + object_type:notnull + list_name:notnull + {pretty_name ""} + {description ""} + groupby:optional + orderby:optional + {format "normal"} + {status "normal"} +} + +set list_id [ams::list::get_list_id -package_key $package_key -object_type $object_type -list_name $list_name] +ams::list::get -list_id $list_id -array "list_info" +set title $list_info(pretty_name) +set context [list [list lists Lists] $title] + +regsub -all {"} $list_info(description) {\"} list_info(description) + + +db_multirow -unclobber attributes select_mapped_attributes { + select alam.required_p, + alam.section_heading, + alam.sort_order as list_sort_order, + ams.* + from ams_list_attribute_map alam, + ams_attributes ams + where alam.list_id = :list_id + and alam.attribute_id = ams.attribute_id + order by alam.sort_order +} { + regsub -all {"} $section_heading {\"} section_heading + regsub -all {"} $pretty_name {\"} pretty_name + regsub -all {"} $pretty_plural {\"} pretty_plural +} + + + + +ad_return_template + + + + + Index: openacs-4/packages/ams/www/list-form-preview.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/www/list-form-preview.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ams/www/list-form-preview.adp 18 May 2005 17:11:48 -0000 1.1 @@ -0,0 +1,9 @@ + +@title@ +@context@ + + + + + + Index: openacs-4/packages/ams/www/list-form-preview.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/www/list-form-preview.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ams/www/list-form-preview.tcl 18 May 2005 17:11:48 -0000 1.1 @@ -0,0 +1,139 @@ +ad_page_contract { + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id: list-form-preview.tcl,v 1.1 2005/05/18 17:11:48 matthewg Exp $ + + +} { + list_id:integer,notnull +} + + +ams::list::get -list_id $list_id -array list_info +set list_name $list_info(list_name) +set object_type $list_info(object_type) +set package_key $list_info(package_key) +set pretty_name [_ $list_info(pretty_name)] + +set title "Form Preview" +set context [list [list lists Lists] [list [export_vars -base "list" -url {package_key object_type list_name}] $pretty_name] $title] +#ams::widget_options -attribute_id "130" +ad_form -name form_preview \ + -form [ams::ad_form::elements -package_key $package_key \ + -object_type $object_type \ + -list_name $list_name -key list_id] \ + -edit_request { +# ams::ad_form::values -package_key $package_key \ +# -object_type $object_type \ +# -list_name $list_name \ +# -form_name "form_preview" \ +# -object_id $list_id + } -on_submit { +# ams::ad_form::save -package_key $package_key \ +# -object_type $object_type \ +# -list_name $list_name \ +# -form_name "form_preview" \ +# -object_id $list_id + } -after_submit { + ad_returnredirect -message "Submitting the preview form does not save any information." [export_vars -base "list" -url {list_name object_type package_key}] + } + + +# Once done comment out the error line +# ad_return_error "You need to specify and valid object id in the packages/ams/www/index.tcl file" "Once done comment out this line." + + + +#set package_key "ams" +#set object_type "ams_list" +#set list_name "ams_list_demo3" +#set pretty_name "The Fields used to Add/Edit a Contact Person" +# +#ams::define_list -package_key $package_key \ +# -object_type $object_type \ +# -list_name $list_name \ +# -pretty_name $pretty_name \ +# -attributes { +# {first_names textbox {First Name(s)} {First Names} required {description {this is my description of first names}}} +# {middle_names textbox {Middle Name(s)} {Middle Names}} +# {last_name textbox {Last Name} {Last Names} required} +# {email email {Email Address} {Email Addresses}} +# {url url {Website} {Websites}} +# {home_address address {Home Address} {Home Addresses}} +# {organization_address address {Organization Address} {Organization Addresses}} +# {home_phone telecom_number {Home Phone} {Home Phones}} +# {gender radio {Gender} {Genders} {options {{Male} {Female}}} required} +# } +# +#set object_id [ams::list::get_list_id \ +# -package_key $package_key \ +# -object_type $object_type \ +# -list_name $list_name] +#set object_id "452" +##ad_form -name entry \ +## -form [ams::ad_form::elements -package_key $package_key \ +## -object_type $object_type \ +## -list_name $list_name \ +## -key "object_id"] \ +# -edit_request { +# ams::object::attribute::values -vars -object_id $object_id +# } -on_submit { +# ams::ad_form::save -package_key $package_key \ +# -object_type $object_type \ +# -list_name $list_name \ +# -form_name "entry" \ +# -object_id $object_id +# } -after_submit { +# if { ![exists_and_not_null return_url] } { +# set return_url "./" +# } +# } +# + +#ams_form -package_key $package_key \ +# -object_type $object_type \ +# -list_name $list_name \ +# -form_name "entry" \ +# -object_id $object_id \ +# -return_url "./" +# +# set attr_list [ams::object::attribute::values_flush -object_id $object_id] +#set attr_list [ams::object::attribute::values -object_id $object_id] +# +# +#db_multirow lists get_list { select list_id, pretty_name from ams_lists } +# +#ams::multirow::extend \ +# -package_key $package_key \ +# -object_type $object_type \ +# -list_name $list_name \ +# -multirow "lists" \ +# -key "list_id" +## +##template::multirow extend lists [list first_names last_name home_address first_names] +## +## +#set key_id "list_id" +#template::multirow foreach lists { +# set object_id [set $key_id] +# ams::object::attribute::values -vars -object_id $object_id +#} +## set attr_list $rowcount +#template::multirow foreach lists { +# ns_log Notice "$first_names $last_name $home_address" +#} + + +#set fred "" + +#foreach { arg_parser procedure } [info procs "::ams::widget::*"] { +# regsub "::ams::widget::" $procedure "" widget +# if { [exists_and_not_null widget] } { +# lappend fred $widget +# } +#} +#set fred "date" +#set fred [info procs "::ams::widget::${fred}"] + +ad_return_template Index: openacs-4/packages/ams/www/list-order-update.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/www/list-order-update.tcl,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/ams/www/list-order-update.tcl 30 Oct 2004 00:23:54 -0000 1.1 +++ openacs-4/packages/ams/www/list-order-update.tcl 18 May 2005 17:11:48 -0000 1.2 @@ -1,49 +1,49 @@ -ad_page_contract { - - Update sort order - - @author Matthew Geddert openacs@geddert.com - @creation-date 2004-07-28 - @cvs-id $Id$ - - -} { - sort_key:array - list_id:integer,notnull -} - - -set ams_attribute_ids [db_list get_attribute_ids { select ams_attribute_id from ams_list_attribute_map where list_id = :list_id order by sort_order }] - - -# first we get the highest sort_order so variables without a sort_order can be given one -set highest_sort 0 -set used_sorts [list] -foreach ams_attribute_id $ams_attribute_ids { - if { $sort_key(${ams_attribute_id}) > $highest_sort } { - set highest_sort $sort_key(${ams_attribute_id}) - } -} - -db_transaction { - foreach ams_attribute_id $ams_attribute_ids { - set sort_order $sort_key(${ams_attribute_id}) - incr highest_sort 1 - db_dml update_sort_order { update ams_list_attribute_map set sort_order = :highest_sort where sort_order = :sort_order and list_id = :list_id } - if { ![exists_and_not_null sort_order] } { - incr highest_sort 1 - set sort_order $highest_sort - } - db_dml update_sort_order { update ams_list_attribute_map set sort_order = :sort_order where ams_attribute_id = :ams_attribute_id and list_id = :list_id } - } -} - -ams::list::get -list_id $list_id -array "list_info" -set package_key $list_info(package_key) -set object_type $list_info(object_type) -set list_name $list_info(list_name) - -ad_returnredirect "list?[export_vars -url {package_key object_type list_name}]" -ad_script_abort - -ad_returnredirect "object-map?object_id=$object_id" +ad_page_contract { + + Update sort order + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id$ + + +} { + sort_key:array + list_id:integer,notnull +} + + +set attribute_ids [db_list get_attribute_ids { select attribute_id from ams_list_attribute_map where list_id = :list_id order by sort_order }] + + +# first we get the highest sort_order so variables without a sort_order can be given one +set highest_sort 0 +set used_sorts [list] +foreach attribute_id $attribute_ids { + if { $sort_key(${attribute_id}) > $highest_sort } { + set highest_sort $sort_key(${attribute_id}) + } +} + +db_transaction { + foreach attribute_id $attribute_ids { + set sort_order $sort_key(${attribute_id}) + incr highest_sort 1 + db_dml update_sort_order { update ams_list_attribute_map set sort_order = :highest_sort where sort_order = :sort_order and list_id = :list_id } + if { ![exists_and_not_null sort_order] } { + incr highest_sort 1 + set sort_order $highest_sort + } + db_dml update_sort_order { update ams_list_attribute_map set sort_order = :sort_order where attribute_id = :attribute_id and list_id = :list_id } + } +} + +ams::list::get -list_id $list_id -array "list_info" +set package_key $list_info(package_key) +set object_type $list_info(object_type) +set list_name $list_info(list_name) + +ad_returnredirect "list?[export_vars -url {package_key object_type list_name}]" +ad_script_abort + +ad_returnredirect "object-map?object_id=$object_id" Index: openacs-4/packages/ams/www/list.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/www/list.adp,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/ams/www/list.adp 30 Oct 2004 00:23:54 -0000 1.1 +++ openacs-4/packages/ams/www/list.adp 18 May 2005 17:11:48 -0000 1.2 @@ -1,21 +1,30 @@ - -@title@ -@context@ - - -

Package Key: @package_key@

-

Object Type: @object_type@

-

List Name: @list_name@

- -

Mapped Attributes

- - - - -

Unmapped Attributes

- - - - + +@title@ +@context@ + + + +

+ +@return_url_label@ + +Preview Input Form +

+ +

Package Key: @package_key@

+

Object Type: @object_type@

+

List Name: @list_name@

+ +

Mapped Attributes

+ + + + +

Unmapped Attributes

+ + + + Index: openacs-4/packages/ams/www/list.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/www/list.tcl,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/ams/www/list.tcl 30 Oct 2004 00:23:54 -0000 1.1 +++ openacs-4/packages/ams/www/list.tcl 18 May 2005 17:11:48 -0000 1.2 @@ -1,238 +1,249 @@ -ad_page_contract { - - This page lets users manage ams lists - - @author Matthew Geddert openacs@geddert.com - @creation-date 2004-07-28 - @cvs-id $Id$ - -} { - package_key:notnull - object_type:notnull - list_name:notnull - groupby:optional - orderby:optional - {format "normal"} - {status "normal"} -} - -set list_id [ams::list::get_list_id -package_key $package_key -object_type $object_type -list_name $list_name] -ams::list::get -list_id $list_id -array "list_info" -set title [_ $list_info(pretty_name)] -set context [list [list lists Lists] $title] - -list::create \ - -name mapped_attributes \ - -multirow mapped_attributes \ - -key ams_attribute_id \ - -row_pretty_plural "Mapped Attributes" \ - -checkbox_name checkbox \ - -selected_format $format \ - -class "list" \ - -main_class "list" \ - -sub_class "narrow" \ - -pass_properties { - } -actions { - } -bulk_actions { - "Answer Required" "list-attributes-required" "Require an answer from the checked attributes" - "Answer Optional" "list-attributes-optional" "An answer from the checked attributes is optional" - "Unmap" "list-attributes-unmap" "Unmap check attributes" - "Update Ordering" "list-order-update" "Update ordering from values in list" - } -bulk_action_export_vars { - list_id - } -elements { - attribute_name { - label "Attribute" - display_col attribute_name - } - pretty_name { - label "Pretty Name" - display_col pretty_name - link_url_eval $attribute_url - } - widget { - label "Widget" - display_col widget - link_url_eval widgets - } - action { - label "Action" - display_template { - Unmap - } - } - answer { - label "Required" - display_template { - - - - - - - } - } - sort_order { - label "Ordering" - display_template { - - } - } - } -filters { - } -groupby { - } -orderby { - } -formats { - normal { - label "Table" - layout table - row { - checkbox {} - pretty_name {} - sort_order {} - answer {} - action {} - } - } - } - - -# Table "public.ams_lists" -# Column | Type | Modifiers -#-----------------------+-------------------------+----------- -# list_id | integer | not null -# package_key | character varying(100) | not null -# object_type | character varying(1000) | not null -# list_name | character varying(100) | not null -# pretty_name | character varying(200) | not null -# description | character varying(200) | -# description_mime_type | character varying(200) | - - -# Table "public.ams_list_attribute_map" -# Column | Type | Modifiers -#------------------+------------------------+----------- -# list_id | integer | not null -# ams_attribute_id | integer | not null -# sort_order | integer | not null -# required_p | boolean | not null -# section_heading | character varying(200) | - - -set sort_order_count 10 - -db_multirow -extend { sort_order_key attribute_url } mapped_attributes select_mapped_attributes { - select alam.required_p, - alam.section_heading, - ams.ams_attribute_id, - ams.widget_name, - ams.deprecated_p, - acs.attribute_name, - acs.pretty_name, - acs.pretty_plural, - acs.object_type - from ams_list_attribute_map alam, - ams_attributes ams, - acs_attributes acs - where alam.list_id = :list_id - and alam.ams_attribute_id = ams.ams_attribute_id - and ams.attribute_id = acs.attribute_id - order by alam.sort_order -} { - set pretty_name [_ $pretty_name] - set attribute_url "attribute?[export_vars -url {ams_attribute_id}]" - set sort_order_key $sort_order_count - incr sort_order_count 10 -} - - -#---------------------------------------------------------------------- -# List builder -#---------------------------------------------------------------------- - - - - - -list::create \ - -name unmapped_attributes \ - -multirow unmapped_attributes \ - -key ams_attribute_id \ - -row_pretty_plural "Unmapped Attributes" \ - -checkbox_name checkbox \ - -selected_format "normal" \ - -class "list" \ - -main_class "list" \ - -sub_class "narrow" \ - -pass_properties { - } -actions { - } -bulk_actions { - "Map" "list-attributes-map" "Map the selected attributes" - } -bulk_action_export_vars { - list_id - } -elements { - attribute_name { - label "Attribute" - display_col attribute_name - } - pretty_name { - label "Pretty Name" - display_col pretty_name - link_url_eval $attribute_url - } - widget { - label "Widget" - display_col widget_name - link_url_eval widgets - } - action { - label "Action" - display_template { - Map - } - } - } -filters { - } -groupby { - } -orderby { - } -formats { - normal { - label "Table" - layout table - row { - checkbox {} - pretty_name {} - widget {} - action {} - } - } - } - - - -# This query will override the ad_page_contract value entry_id - -db_multirow -extend { attribute_url } -unclobber unmapped_attributes get_unmapped_attributes { - select ams.ams_attribute_id, - ams.widget_name, - ams.deprecated_p, - acs.attribute_name, - acs.pretty_name, - acs.pretty_plural, - acs.object_type - from ams_attributes ams, - acs_attributes acs - where ams.ams_attribute_id not in ( select alam.ams_attribute_id from ams_list_attribute_map alam where alam.list_id = :list_id ) - and ams.attribute_id = acs.attribute_id -} { - set pretty_name [_ $pretty_name] - set attribute_url "attribute?[export_vars -url {ams_attribute_id}]" - -} - - - -ad_return_template - - - - - +ad_page_contract { + + This page lets users manage ams lists + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id$ + +} { + package_key:notnull + object_type:notnull + list_name:notnull + {pretty_name ""} + {description ""} + groupby:optional + orderby:optional + {format "normal"} + {status "normal"} + {return_url ""} + {return_url_label "Return to Where You Were"} +} + +set provided_return_url $return_url +set provided_return_url_label $return_url_label + +set this_url [export_vars -url -base "list" {package_key object_type list_name }] +set code_url [export_vars -url -base "list-code" {package_key object_type list_name return_url return_url_label}] + + + +if { ![ams::list::exists_p -package_key $package_key -object_type $object_type -list_name $list_name] } { + ad_returnredirect -message "The list specified does not exists. You may create it if you like." [export_vars -base "list-add" -url {package_key object_type list_name pretty_name description return_url return_url_label}] + ad_script_abort +} +set list_id [ams::list::get_list_id -package_key $package_key -object_type $object_type -list_name $list_name] + + +set create_attribute_url [export_vars -base "attribute-add" -url {object_type list_id return_url return_url_label}] + + + + +ams::list::get -list_id $list_id -array "list_info" +set title $list_info(pretty_name) +set context [list [list lists Lists] $title] + +list::create \ + -name mapped_attributes \ + -multirow mapped_attributes \ + -key attribute_id \ + -row_pretty_plural "Mapped Attributes" \ + -checkbox_name checkbox \ + -selected_format $format \ + -class "list" \ + -main_class "list" \ + -sub_class "narrow" \ + -pass_properties { + } -actions { + } -bulk_actions { + "Answer Required" "list-attributes-required" "Require an answer from the checked attributes" + "Answer Optional" "list-attributes-optional" "An answer from the checked attributes is optional" + "Unmap" "list-attributes-unmap" "Unmap check attributes" + "Update Ordering" "list-order-update" "Update ordering from values in list" + } -bulk_action_export_vars { + list_id + } -elements { + attribute_name { + label "Attribute" + display_col attribute_name + } + pretty_name { + label "Pretty Name" + display_template { + @mapped_attributes.pretty_name@ (Parent Object Type: @mapped_attributes.object_type@) + } + } + widget { + label "Widget" + display_col widget + link_url_eval widgets + } + section_heading { + label "Heading" + display_col section_heading + } + action { + label "Action" + display_template { + Unmap + Add HeadingEdit/Delete Heading + } + } + answer { + label "Required" + display_template { + + + + + + + } + } + sort_order { + label "Ordering" + display_template { + + } + } + } -filters { + } -groupby { + } -orderby { + } -formats { + normal { + label "Table" + layout table + row { + checkbox {} + pretty_name {} + sort_order {} + answer {} + action {} + section_heading {} + } + } + } + + + +set sort_order_count 10 + +db_multirow -extend { sort_order_key attribute_url } -unclobber mapped_attributes select_mapped_attributes { + select alam.required_p, + alam.section_heading, + ams.attribute_id, + ams.widget, + ams.deprecated_p, + ams.attribute_name, + ams.pretty_name, + ams.pretty_plural, + ams.object_type + from ams_list_attribute_map alam, + ams_attributes ams + where alam.list_id = :list_id + and alam.attribute_id = ams.attribute_id + order by alam.sort_order +} { + set attribute_url "attribute?[export_vars -url {attribute_id}]" + set sort_order_key $sort_order_count + incr sort_order_count 10 +} + + +#---------------------------------------------------------------------- +# List builder +#---------------------------------------------------------------------- + + + + +# } -bulk_actions [list "Map" "list-attributes" "Map the selected attributes"] \ +# -bulk_action_export_vars { +# list_id + +list::create \ + -name unmapped_attributes \ + -multirow unmapped_attributes \ + -key attribute_id \ + -row_pretty_plural "Unmapped Attributes" \ + -checkbox_name checkbox \ + -selected_format "normal" \ + -class "list" \ + -main_class "list" \ + -sub_class "narrow" \ + -pass_properties { + } -actions { + } -elements { + attribute_name { + label "Attribute" + display_col attribute_name + } + pretty_name { + label "Pretty Name" + display_col pretty_name + link_url_eval $attribute_url + } + widget { + label "Widget" + display_col widget + link_url_eval widgets + } + action { + label "Action" + display_template { + + Define Widget + + + Map + + } + } + } -filters { + } -groupby { + } -orderby { + } -formats { + normal { + label "Table" + layout table + row { + pretty_name {} + widget {} + action {} + } + } + } +# checkbox {} + + + +# This query will override the ad_page_contract value entry_id + +db_multirow -extend { attribute_url attribute_add_url } -unclobber unmapped_attributes get_unmapped_attributes " + select attribute_id, + widget, + deprecated_p, + attribute_name, + pretty_name, + pretty_plural, + object_type + from ams_attributes + where attribute_id not in ( select alam.attribute_id from ams_list_attribute_map alam where alam.list_id = :list_id ) + and object_type in ([ams::object_parents -sql -object_type $object_type]) +" { + set return_url $this_url + set attribute_add_url [export_vars -base "attribute-add" -url {object_type attribute_name return_url}] + set attribute_url [export_vars -base "attribute" -url {attribute_id}] +} + +set return_url $provided_return_url +set return_url_label $provided_return_url_label + + +ad_return_template + + + + + Index: openacs-4/packages/ams/www/lists.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/www/lists.adp,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/ams/www/lists.adp 30 Oct 2004 00:23:54 -0000 1.1 +++ openacs-4/packages/ams/www/lists.adp 18 May 2005 17:11:48 -0000 1.2 @@ -1,11 +1,11 @@ - - -@title@ -@context@ - -

You can create a list by selecting an acs_object. Note that list creation should be done with contracting packages. These lists shows what ams can do for your package.

- - - - - + + +@title@ +@context@ + +

You can create a list by selecting an acs_object. Note that list creation should be done with contracting packages. These lists shows what ams can do for your package.

+ + + + + Index: openacs-4/packages/ams/www/lists.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/www/lists.tcl,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/ams/www/lists.tcl 30 Oct 2004 00:23:54 -0000 1.1 +++ openacs-4/packages/ams/www/lists.tcl 18 May 2005 17:11:48 -0000 1.2 @@ -1,76 +1,76 @@ -ad_page_contract { - - @author Matthew Geddert openacs@geddert.com - @creation-date 2004-07-28 - @cvs-id $Id$ - - -} { - {orderby "name"} -} - -set title "AMS Lists" -set context [list $title] - -list::create \ - -name lists \ - -multirow lists \ - -key list_id \ - -row_pretty_plural "AMS Lists" \ - -checkbox_name checkbox \ - -selected_format "normal" \ - -class "list" \ - -main_class "list" \ - -sub_class "narrow" \ - -actions { - } -bulk_actions { - } -elements { - edit { - label {} - } - pretty_name { - display_col pretty_name - label "Pretty Name" - } - package_key { - display_col package_key - label "Package Key" - } - list_name { - display_col list_name - label "List Name" - link_url_eval $list_url - } - object_type { - display_col object_type - label "Object Type" - link_url_eval $object_url - } - } -filters { - } -groupby { - } -orderby { - } -formats { - normal { - label "Table" - layout table - row { - package_key {} - object_type {} - list_name {} - pretty_name {} - } - } - } - - -db_multirow -extend { list_url object_url } lists select_lists { - select list_id, package_key, object_type, list_name, pretty_name - from ams_lists -} { - set object_url "list?[export_vars -url {object_type}]" - set list_url "list?[export_vars -url {package_key object_type list_name}]" - set pretty_name [_ $pretty_name] -} - - -ad_return_template +ad_page_contract { + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id$ + + +} { + {orderby "name"} +} + +set title "AMS Lists" +set context [list $title] + +list::create \ + -name lists \ + -multirow lists \ + -key list_id \ + -row_pretty_plural "AMS Lists" \ + -checkbox_name checkbox \ + -selected_format "normal" \ + -class "list" \ + -main_class "list" \ + -sub_class "narrow" \ + -actions { + } -bulk_actions { + } -elements { + edit { + label {} + } + pretty_name { + display_col pretty_name + label "Pretty Name" + } + package_key { + display_col package_key + label "Package Key" + } + list_name { + display_col list_name + label "List Name" + link_url_eval $list_url + } + object_type { + display_col object_type + label "Object Type" + link_url_eval $object_url + } + } -filters { + } -groupby { + } -orderby { + } -formats { + normal { + label "Table" + layout table + row { + package_key {} + object_type {} + list_name {} + pretty_name {} + } + } + } + + +db_multirow -extend { list_url object_url } lists select_lists { + select list_id, package_key, object_type, list_name, pretty_name + from ams_lists +} { + set object_url "list?[export_vars -url {object_type}]" + set list_url "list?[export_vars -url {package_key object_type list_name}]" + set pretty_name [_ $pretty_name] +} + + +ad_return_template Index: openacs-4/packages/ams/www/object-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/www/object-postgresql.xql,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/ams/www/object-postgresql.xql 30 Oct 2004 00:27:00 -0000 1.1 +++ openacs-4/packages/ams/www/object-postgresql.xql 18 May 2005 17:11:48 -0000 1.2 @@ -1,25 +1,25 @@ - - - - postgresql7.1 - - - - update contact_attribute_object_map set sort_order = '-1' where object_id = :object_id - - - - - - select attribute_id from contact_attribute_object_map where object_id = :object_id - - - - - - update contact_attribute_object_map set sort_order = :sort_order_temp where object_id = :object_id and attribute_id = :attribute_id - - - - - + + + + postgresql7.1 + + + + update contact_attribute_object_map set sort_order = '-1' where object_id = :object_id + + + + + + select attribute_id from contact_attribute_object_map where object_id = :object_id + + + + + + update contact_attribute_object_map set sort_order = :sort_order_temp where object_id = :object_id and attribute_id = :attribute_id + + + + + Index: openacs-4/packages/ams/www/object.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/www/object.adp,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/ams/www/object.adp 30 Oct 2004 00:23:54 -0000 1.1 +++ openacs-4/packages/ams/www/object.adp 18 May 2005 17:11:48 -0000 1.2 @@ -1,15 +1,13 @@ - - -@title@ -@context@ - - - -

AMS Attributes

- - -

Attributes not managed by AMS

- - -

AMS Lists associated with @object_info.pretty_plural@

- + + +@title@ +@context@ + + + +

AMS Attributes

+ + + +

AMS Lists associated with @object_info.pretty_plural@

+ Index: openacs-4/packages/ams/www/object.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/www/object.tcl,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/ams/www/object.tcl 30 Oct 2004 00:23:54 -0000 1.1 +++ openacs-4/packages/ams/www/object.tcl 18 May 2005 17:11:48 -0000 1.2 @@ -1,296 +1,213 @@ -ad_page_contract { - - @author Matthew Geddert openacs@geddert.com - @creation-date 2004-07-28 - @cvs-id $Id$ - - -} { - {object_type:notnull} - orderby:optional -} - -acs_object_type::get -object_type $object_type -array "object_info" - -set title "$object_info(pretty_name)" -set context [list [list objects Objects] $title] - - -list::create \ - -name object_attributes \ - -multirow object_attributes \ - -key attribute_name \ - -row_pretty_plural "AMS Attributes" \ - -checkbox_name checkbox \ - -selected_format "normal" \ - -class "list" \ - -main_class "list" \ - -sub_class "narrow" \ - -pass_properties { - object_type - } -actions [list "Add" "attribute-add?object_type=$object_type" "Add an AMS Attribute"] \ - -bulk_actions { - } -elements { - edit { - label {} - } - pretty_name { - display_col pretty_name - label "Pretty Name" - link_url_eval $ams_attribute_url - } - attribute_name { - display_col attribute_name - label "Attribute Name" - link_url_eval $ams_attribute_url - } - widget_name { - display_col widget_name - label "Widget Name" - link_url_eval widgets - } - actions { - label "" - display_template { - Upgrade to AMS Attribute - } - } - } -filters { - object_type {} - } -groupby { - } -orderby { - default_value default_sort,asc - default_sort { - label default_sort - multirow_cols {ams_attribute_p pretty_name attribute_name} - } - pretty_name { - label pretty_name - multirow_cols {ams_attribute_p pretty_name attribute_name} - } - attribute_name { - label attribute_name - multirow_cols {ams_attribute_p attribute_name pretty_name} - } - widget_name { - label widget_name - multirow_cols {ams_attribute_p widget_name pretty_name attribute_name} - } - } -formats { - normal { - label "Table" - layout table - row { - pretty_name {} - attribute_name {} - widget_name {} - actions {} - } - } - } - - -db_multirow -extend { ams_attribute_url ams_attribute_p } object_attributes select_object_attributes { - select acs.attribute_name, - acs.pretty_name, - acs.pretty_plural, - acs.attribute_id, - ams.ams_attribute_id, - ams.widget_name - from acs_attributes acs, ams_attributes ams - where acs.object_type = :object_type - and acs.attribute_id = ams.attribute_id -} { - if { [exists_and_not_null ams_attribute_id] } { set ams_attribute_p 1 } else { set ams_attribute_p 0 } - - if { [exists_and_not_null ams_attribute_id] } { - set ams_attribute_url "attribute?ams_attribute_id=$ams_attribute_id" - } else { - set ams_attribute_url "" - } - if { [lang::message::message_exists_p en_US $pretty_name] } { - set pretty_name [_ $pretty_name] - } -} - - - - - - - - - - - - - - - - -# This code lets me setup AMS Attribute Upgrades for Attributes that were not created by AMS -# -# eventually we will allow these attributes to be "upgraded" to ams_attributes. We first need to provision a way -# for them to not be deleted at package drop time, since other packages created these attributes they may need them. - -list::create \ - -name non_ams_attributes \ - -multirow non_ams_object_attributes \ - -key attribute_name \ - -row_pretty_plural "Attributes not managed by AMS" \ - -checkbox_name checkbox \ - -selected_format "normal" \ - -class "list" \ - -main_class "list" \ - -sub_class "narrow" \ - -pass_properties { - variable - } -actions { - } -bulk_actions { - } -elements { - pretty_name { - display_col pretty_name - label "Pretty Name" - } - attribute_name { - display_col attribute_name - label "Attribute Name" - } - actions { - label "" - display_template { - Upgrade to AMS Attribute - } - } - } -filters { - object_type {} - } -groupby { - } -orderby { - } -formats { - normal { - label "Table" - layout table - row { - pretty_name {} - attribute_name {} - } - } - } - - -db_multirow non_ams_object_attributes select_non_ams_object_attributess { - select acs.attribute_name, - acs.pretty_name, - acs.pretty_plural, - acs.attribute_id - from acs_attributes acs - where acs.object_type = :object_type - and acs.attribute_id not in ( select attribute_id from ams_attributes ) -} { -} - - - - - - - - - - - - - - - - - - - - -# AMS Lists associated with this object type - -list::create \ - -name ams_lists \ - -multirow ams_lists \ - -key list_id \ - -row_pretty_plural "Attributes not managed by AMS" \ - -checkbox_name checkbox \ - -selected_format "normal" \ - -class "list" \ - -main_class "list" \ - -sub_class "narrow" \ - -pass_properties { - variable - } -actions [list "Add" "list-add?object_type=$object_type" "Add an AMS List"] \ - -bulk_actions { - } -elements { - package_key { - label "Package Key" - display_col package_key - } - object_type { - label "Object Type" - display_col object_type - } - list_name { - label "List Name" - display_col list_name - link_url_eval $list_link - } - pretty_name { - display_col pretty_name - label "Pretty Name" - } - description { - display_col description_html;noquote - label "Description" - } - actions { - label "" - display_template { - - } - } - } -filters { - object_type {} - } -groupby { - } -orderby { - } -formats { - normal { - label "Table" - layout table - row { - package_key {} - list_name {} - pretty_name {} - description {} - } - } - } - - -db_multirow -extend { description_html list_link } ams_lists select_ams_lists { - select * - from ams_lists - where object_type = :object_type -} { - set pretty_name [_ $pretty_name] - set list_link "list?[export_vars -url {package_key object_type list_name}]" - set description_html [ad_html_text_convert -from $description_mime_type -to "text/html" -truncate_len "175" $description] -} - - - - - - - - - - - - - - -ad_return_template +ad_page_contract { + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id$ + + +} { + {object_type:notnull} + orderby:optional +} + +acs_object_type::get -object_type $object_type -array "object_info" + +set title "$object_info(pretty_name)" +set context [list [list objects Objects] $title] + + +list::create \ + -name object_attributes \ + -multirow object_attributes \ + -key attribute_name \ + -row_pretty_plural "AMS Attributes" \ + -checkbox_name checkbox \ + -selected_format "normal" \ + -class "list" \ + -main_class "list" \ + -sub_class "narrow" \ + -pass_properties { + object_type + } -actions [list "Add" "attribute-add?object_type=$object_type" "Add an AMS Attribute"] \ + -bulk_actions { + } -elements { + edit { + label {} + } + pretty_name { + display_col pretty_name + label "Pretty Name" + link_url_eval $ams_attribute_url + } + attribute_name { + display_col attribute_name + label "Attribute Name" + } + widget { + label "Widget" + display_template { + Define Widget@object_attributes.widget@ + } + } + } -filters { + object_type {} + } -groupby { + } -orderby { + default_value default_sort,asc + default_sort { + label default_sort + multirow_cols {ams_attribute_p pretty_name attribute_name} + } + pretty_name { + label pretty_name + multirow_cols {ams_attribute_p pretty_name attribute_name} + } + attribute_name { + label attribute_name + multirow_cols {ams_attribute_p attribute_name pretty_name} + } + widget { + label widget_name + multirow_cols {ams_attribute_p widget pretty_name attribute_name} + } + } -formats { + normal { + label "Table" + layout table + row { + pretty_name {} + attribute_name {} + widget {} + } + } + } + + +db_multirow -extend { ams_attribute_url ams_attribute_p } object_attributes select_object_attributes { + select attribute_name, + pretty_name, + pretty_plural, + attribute_id, + widget + from ams_attributes + where object_type = :object_type + order by upper(pretty_name) +} { + if { [exists_and_not_null ams_attribute_id] } { set ams_attribute_p 1 } else { set ams_attribute_p 0 } + set ams_attribute_url "attribute?attribute_id=$attribute_id" + if { [lang::message::message_exists_p en_US $pretty_name] } { + set pretty_name [_ $pretty_name] + } +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +# AMS Lists associated with this object type + +list::create \ + -name ams_lists \ + -multirow ams_lists \ + -key list_id \ + -row_pretty_plural "Attributes not managed by AMS" \ + -checkbox_name checkbox \ + -selected_format "normal" \ + -class "list" \ + -main_class "list" \ + -sub_class "narrow" \ + -pass_properties { + variable + } -actions [list "Add" "list-add?object_type=$object_type" "Add an AMS List"] \ + -bulk_actions { + } -elements { + package_key { + label "Package Key" + display_col package_key + } + object_type { + label "Object Type" + display_col object_type + } + list_name { + label "List Name" + display_col list_name + link_url_eval $list_link + } + pretty_name { + display_col pretty_name + label "Pretty Name" + } + description { + display_col description_html;noquote + label "Description" + } + actions { + label "" + display_template { + + } + } + } -filters { + object_type {} + } -groupby { + } -orderby { + } -formats { + normal { + label "Table" + layout table + row { + package_key {} + list_name {} + pretty_name {} + description {} + } + } + } + + +db_multirow -extend { description_html list_link } ams_lists select_ams_lists { + select * + from ams_lists + where object_type = :object_type +} { + set pretty_name [_ $pretty_name] + set list_link "list?[export_vars -url {package_key object_type list_name}]" + set description_html [ad_html_text_convert -from $description_mime_type -to "text/html" -truncate_len "175" $description] +} + + + + + + +ad_return_template Index: openacs-4/packages/ams/www/objects.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/www/objects.adp,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/ams/www/objects.adp 30 Oct 2004 00:23:54 -0000 1.1 +++ openacs-4/packages/ams/www/objects.adp 18 May 2005 17:11:48 -0000 1.2 @@ -1,11 +1,11 @@ - - -@title@ -@context@ - - - - - - - + + +@title@ +@context@ + + + + + + + Index: openacs-4/packages/ams/www/objects.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/www/objects.tcl,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/ams/www/objects.tcl 30 Oct 2004 00:23:54 -0000 1.1 +++ openacs-4/packages/ams/www/objects.tcl 18 May 2005 17:11:48 -0000 1.2 @@ -1,66 +1,66 @@ -ad_page_contract { - - @author Matthew Geddert openacs@geddert.com - @creation-date 2004-07-28 - @cvs-id $Id$ - - -} { - {orderby "name"} -} - -set title "Objects" -set context [list $title] - -list::create \ - -name object_types \ - -multirow object_types \ - -key object_type \ - -row_pretty_plural "Object Types" \ - -checkbox_name checkbox \ - -selected_format "normal" \ - -class "list" \ - -main_class "list" \ - -sub_class "narrow" \ - -actions { - } -bulk_actions { - } -elements { - edit { - label {} - } - pretty_name { - display_col pretty_name - label "Pretty Name" - link_url_eval $object_attributes_url - } - object_type { - display_col object_type - label "Object Type" - link_url_eval $object_attributes_url - } - } -filters { - } -groupby { - } -orderby { - } -formats { - normal { - label "Table" - layout table - row { - pretty_name {} - object_type {} - } - } - } - - -db_multirow -extend { object_attributes_url } object_types select_object_types { - select object_type, - pretty_name - from acs_object_types - order by lower(pretty_name) -} { - set object_attributes_url "object?object_type=$object_type" -} - - -ad_return_template +ad_page_contract { + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id$ + + +} { + {orderby "name"} +} + +set title "Objects" +set context [list $title] + +list::create \ + -name object_types \ + -multirow object_types \ + -key object_type \ + -row_pretty_plural "Object Types" \ + -checkbox_name checkbox \ + -selected_format "normal" \ + -class "list" \ + -main_class "list" \ + -sub_class "narrow" \ + -actions { + } -bulk_actions { + } -elements { + edit { + label {} + } + pretty_name { + display_col pretty_name + label "Pretty Name" + link_url_eval $object_attributes_url + } + object_type { + display_col object_type + label "Object Type" + link_url_eval $object_attributes_url + } + } -filters { + } -groupby { + } -orderby { + } -formats { + normal { + label "Table" + layout table + row { + pretty_name {} + object_type {} + } + } + } + + +db_multirow -extend { object_attributes_url } object_types select_object_types { + select object_type, + pretty_name + from acs_object_types + order by lower(pretty_name) +} { + set object_attributes_url "object?object_type=$object_type" +} + + +ad_return_template Index: openacs-4/packages/ams/www/widgets.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/www/widgets.adp,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/ams/www/widgets.adp 30 Oct 2004 00:23:54 -0000 1.1 +++ openacs-4/packages/ams/www/widgets.adp 18 May 2005 17:11:48 -0000 1.2 @@ -1,13 +1,13 @@ - -@title@ -@context@ - - - - - - - - - - + +@title@ +@context@ + + + + + + + + + + Index: openacs-4/packages/ams/www/widgets.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/www/widgets.tcl,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/ams/www/widgets.tcl 30 Oct 2004 00:23:54 -0000 1.1 +++ openacs-4/packages/ams/www/widgets.tcl 18 May 2005 17:11:48 -0000 1.2 @@ -1,99 +1,99 @@ -ad_page_contract { - - @author Matthew Geddert openacs@geddert.com - @creation-date 2004-07-28 - @cvs-id $Id$ - - -} { -} - - -set title "Widgets" -set context [list $title] - - - - -list::create \ - -name widgets \ - -multirow widgets \ - -key widget_name \ - -row_pretty_plural "Object Types" \ - -checkbox_name checkbox \ - -selected_format "normal" \ - -class "list" \ - -main_class "list" \ - -sub_class "narrow" \ - -pass_properties { - variable - } -actions { - } -bulk_actions { - } -elements { - widget_name { - display_col widget_name - label "Widget Name" - } - pretty_name { - display_col pretty_name - label "Pretty Name" - } - pretty_plural { - display_col pretty_plural - label "Pretty Plural" - } - widget { - display_col widget - label "Widget" - } - datatype { - display_col datatype - label "Datatype" - } - parameters { - display_col parameters - label "Parameters" - } - } -filters { - object_type {} - } -groupby { - } -orderby { - } -formats { - normal { - label "Table" - layout table - row { - widget_name {} - pretty_name {} - widget {} - datatype {} - parameters {} - } - } - } - - -db_multirow widgets get_widgets { - select * - from ams_widgets - order by widget_name -} { -} - -template::multirow foreach widgets { - set form_element "${widget_name}_widget:${datatype}(${widget}),optional" - if { [string equal $storage_type "ams_options"] } { - append form_element { {options { {"Demo Example One" 1} {"Demo Example Two" 2} {"Demo Example Three" 3} {"Demo Example Four" 4} {"Demo Example Five" 5} {"Demo Example Six" 6} }}} - } - if { [exists_and_not_null parameters] } { - append form_element " ${parameters}" - } - lappend form_element [list "label" "

$widget_name

$pretty_plural

widget: $widget
datatype: $datatype
parameters: $parameters

"] - lappend form_elements $form_element -} - -ad_form -name widgets_form -form $form_elements -on_submit {} - - - -ad_return_template +ad_page_contract { + + @author Matthew Geddert openacs@geddert.com + @creation-date 2004-07-28 + @cvs-id $Id$ + + +} { +} + + +set title "Widgets" +set context [list $title] + + + + +list::create \ + -name widgets \ + -multirow widgets \ + -key widget_name \ + -row_pretty_plural "Object Types" \ + -checkbox_name checkbox \ + -selected_format "normal" \ + -class "list" \ + -main_class "list" \ + -sub_class "narrow" \ + -pass_properties { + variable + } -actions { + } -bulk_actions { + } -elements { + widget_name { + display_col widget_name + label "Widget Name" + } + pretty_name { + display_col pretty_name + label "Pretty Name" + } + pretty_plural { + display_col pretty_plural + label "Pretty Plural" + } + widget { + display_col widget + label "Widget" + } + datatype { + display_col datatype + label "Datatype" + } + parameters { + display_col parameters + label "Parameters" + } + } -filters { + object_type {} + } -groupby { + } -orderby { + } -formats { + normal { + label "Table" + layout table + row { + widget_name {} + pretty_name {} + widget {} + datatype {} + parameters {} + } + } + } + + +db_multirow widgets get_widgets { + select * + from ams_widgets + order by widget_name +} { +} + +template::multirow foreach widgets { + set form_element "${widget_name}_widget:${datatype}(${widget}),optional" + if { [string equal $storage_type "ams_options"] } { + append form_element { {options { {"Demo Example One" 1} {"Demo Example Two" 2} {"Demo Example Three" 3} {"Demo Example Four" 4} {"Demo Example Five" 5} {"Demo Example Six" 6} }}} + } + if { [exists_and_not_null parameters] } { + append form_element " ${parameters}" + } + lappend form_element [list "label" "

$widget_name

$pretty_plural

widget: $widget
datatype: $datatype
parameters: $parameters

"] + lappend form_elements $form_element +} + +ad_form -name widgets_form -form $form_elements -on_submit {} + + + +ad_return_template Index: openacs-4/packages/ams/www/doc/index.html =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/www/doc/index.html,v diff -u -N -r1.4 -r1.5 --- openacs-4/packages/ams/www/doc/index.html 25 Oct 2004 00:10:43 -0000 1.4 +++ openacs-4/packages/ams/www/doc/index.html 18 May 2005 17:11:49 -0000 1.5 @@ -1,139 +1,177 @@ - - -AMS (Attribute Management System) - - - - - -

AMS (Attribute Management System)

- -

AMS lets developers (via tcl api) and site wide administrators (via the the ams admin UI) add attributes to acs_object. These attributes can be dynamically added at any time on a live system. AMS then helps you collect attribute information for these defined acs_objects via input forms and helps you present them to users via your website. Whenever AMS stores ams attribute information about an object it keeps track of changes made via the content repository. This way you can see who and when a user changed an object's attributes and are able to revert back to a previous state.

- -

Defining an Attribute

- -

Ams attributes can either be defined via the ams admin user interface or via the ams::attribute::new proc. Every ams_attribute has an ams_widget associated with it. ams_widgets define what type of information the attribute contains the information necessary to generate forms and save various funcationally different types of information. View the documentation for ams::attribute::new to see what types of widgets are available. In most cases using the ams::attribute::new proc will be too tedious to do, instead it would be a good idea to use the shorthand as defined in creating and ams_list. - -

AMS Lists

- -

AMS stores attributes in ams_lists. These lists are an ordered collection of attributes and can be called upon a variety of ways. Ams_lists can be used to generate ad_forms, or return attribute information for use with your packages UI. The attributes associated with your acs_object can be returned as named variables in your calling environment, as an array or as a list via the ams::object::attribute::values proc.

- -

To define an ams_list of the elements you use the ams::define_list. That procedure has extensive documentation about the nuances of defining an ams_list. For example, lets assume that you are developing a package called "contacts" with the object_type of "ct_contact" and you want to define a list to collect information about a contact. You might choose to run the following procedure in when your system restarts:

-
-ams::define_list -package_key "contacts" \
-        -object_type "ct_contact" \
-        -list_name "contact_person" \
-        -pretty_name "The Fields used to Add/Edit a Contact Person" \
-        -attributes {
-                {first_names textbox {First Name(s)} {First Names} required}
-                {middle_names textbox {Middle Name(s)} {Middle Names}}
-                {last_name textbox {Last Name} {Last Names} required}
-                {email email {Email Address} {Email Addresses}}
-                {url url {Website} {Websites}}
-                {home_address address {Home Address} {Home Addresses}}
-                {home_phone telecom_number {Home Phone} {Home Phones}}
-                {gender radio {Gender} {Genders} {options {{Male} {Female}}}}
-        }
-
- -

This will create an ams_list, define any attributes that haven't previously been defined for the ct_contact object and order the list in the order the attributes are specified.

- -

AMS and ad_form

-

You have two options when dealing with ams and ad_form. Shorthand and detailed.

-

Shorthand

-

Shorthands is a completely simple way of creating forms without many options. These forms must only contain attributes defined in an ams_list. The supplied object_id must already exist in the acs_object table. The shorthand procs is ams_form, which is simply a wrapper for ad_form. For example, to create and ad_form named "contact_person_ae" create a page contacts/www/contact-person-ae.tcl with the following content:

-
-ad_page_contract {
-} {
-        {ct_contact_id:integer,notnull}
-}
-set title "Contact Person Add/Edit"
-set context [list $title]
-
-ams_form -package_key "contacts" \
-         -object_type "ct_contact" \
-         -list_name "contact_person" \
-         -form_name "contact_person_ae" \
-         -object_id $ct_contact_id \
-         -return_url "./"
-
-ad_return_template
-
-

The contacts/www/contact-person-ae.adp would contain

-
-<master>
-<property name="title">@title@</property">
-<property name="context">@context@</property">
-
-<formtemplate id="contact_person_ae"></formtemplate">
-
-

That's it. If this isn't flexible enough you can also go with the detailed method.

- - -

Detailed

-

For many application the AMS and ad_form shorthand will be too simplistic. For those situations, you can use ams to interface with ad_form. You need to define ad_from -form elements like this: -

-ad_form ... -form [ams::ad_form::elements -package_key "contacts" -object_type "ct_contact" -list_name "contact_person"] ...
-
-

Note that this procedure returns an ad form appropriate element list. If you intending to define other elements you will need to ad_from -extend -name form_name -form ...

-

-

In the ad_form -edit_request block put

-
-ad_form ... -edit_request {
-        ams::object::attribute::values -vars -object_id $object_id
-    } ...
-
-

This returns the variables upvared into your page, i.e. the first_names attribute could be returned with a value of "Jane" and the last_name attribute with a value of "Doe"... etc. ad_from looks for all form elements and appropriately pre-fills the form with the given values.

- -

In the -on_submit block you enter the following:

-
-ad_from ... -on_submit {
-        ams::ad_form::save \
-            -package_key "contacts" \
-            -object_type "ct_contact" \
-            -list_name "contact_person" \
-            -form_name "contact_person_ae" \
-            -object_id $ct_contact_id
-    }
-
-

This is how you interface with AMS and ad_form. You may also specify other code in the -form -on_submit and -on_submit blocks.

- -

AMS and your package's UI

- - -

to display attributes you can call ams::object::attribute::values to get the results back as upvared variables, as an array or as a list however you want. So, if on the contact-view page you do, for example to get an array with all attribute_values that are not null represented in. -

-
-ams::object::attribute::values -array "contact_info" -object_id $ct_contact_id
-
-

To add ams_attribute_values to a multirow you call ams::multirow::extend to efficiently extend your multirow with ams_attribute_values. For example:

-
-db_multirow contacts get_contacts { select ct_contact_id from ct_contacts }
-
-ams::multirow::extend \
-    -package_key "contacts" \
-    -object_type "ct_contact" \
-    -list_name "contact_person" \
-    -multirow "contacts" \
-    -key "ct_contact_id"
-
-

-

AMS Permissions

-

THIS SECTION NEEDS TO BE PROGRAMMED AN DOCUMENTED

- - + + +AMS (Attribute Management System) + + + + + + + +

AMS (Attribute Management System)

+ +

AMS lets developers (via tcl api) and site wide administrators (via the the ams admin UI) add attributes to acs_object. These attributes can be dynamically added at any time on a live system. AMS then helps you collect attribute information for these defined acs_objects via input forms and helps you present them to users via your website. Whenever AMS stores ams attribute information about an object it keeps track of changes made via the content repository. This way you can see who and when a user changed an object's attributes and are able to revert back to a previous state.

+ +

Widgets

+

The following procs associated with it in the tcl files, this is done via tcl so +people can actually have a "widget" represent a series of widgets in ad_form or template::form

+
+::widget::${widget}::ad_form_widget       - returns a string suitable for input into ad_form, it gets: attribute, pretty_name, value
+::widget::${widget}::ad_form_save         - saves the input to an ad_form widget and returns a value_id
+::widget::${widget}::ad_form_value        - returns a value suitable for input into ad_form, it gets, attribute, attribute_id and value
+::widget::${widget}::template_form_widget - runs a proc suitable for template::form, it gets: pretty_name, attribute, attribute_id, value
+::widget::${widget}::template_form_save   - saves the input to an termplate::form widget and returns a value_id
+::widget::${widget}::template_form_value  - returns a value suitable for input into ad_form, it gets, attribute, attribute_id and value
+::widget::${widget}::value_text           - return the value formatted for text output, value is provided - this in the future will allow for search indexing of this data
+::widget::${widget}::value_html           - return the value formatted for html output, value is provided
+::widget::${widget}::csv_value            - return the value formatted for csv output, value and attribute are provided
+::widget::${widget}::csv_headers          - return the value formatted for csv output, attribute is provided, for example, if returning a postal address we woudl return ${attribute}__country and ${attribute}__city, etc. For something such as gender we would simply return ${attribute}
+::widget::${widget}::csv_save             - save the value provided by csv, the input into this proc will be ${attribute}__subitem $value ${attribute}__subitem $value, its assumed that the cvs_headers will all be provided and that if there is no input a blank field will be supplied.
+
+
+
+::widget::${widget}::datatypes
+
+-- ams_widget_datatype_map is simplifies the selection of widgets to associate
+-- with an attribute. This allows us to present an administrator with list of valid
+-- widgets she can select for assocation with a particular datatype.
+
+create table ams_widget_datatype_map (
+        widget                  varchar(100)
+                                constraint ams_widget_datatype_map_fk references ams_widgets(widget)
+                                constraint ams_widget_datatype_map_nn not null,
+        datatype                varchar(50)
+                                constraint ams_widget_datatype_map_datatype_fk references acs_datatypes(datatype)
+                                constraint ams_widget_datatype_map_datatype_nn not null
+);
+
+
+
+ +

Defining an Attribute

+ +

Ams attributes can either be defined via the ams admin user interface or via the ams::attribute::new proc. Every ams_attribute has an ams_widget associated with it. ams_widgets define what type of information the attribute contains the information necessary to generate forms and save various funcationally different types of information. View the documentation for ams::attribute::new to see what types of widgets are available. In most cases using the ams::attribute::new proc will be too tedious to do, instead it would be a good idea to use the shorthand as defined in creating and ams_list. + +

AMS Lists

+ +

AMS stores attributes in ams_lists. These lists are an ordered collection of attributes and can be called upon a variety of ways. Ams_lists can be used to generate ad_forms, or return attribute information for use with your packages UI. The attributes associated with your acs_object can be returned as named variables in your calling environment, as an array or as a list via the ams::object::attribute::values proc.

+ +

To define an ams_list of the elements you use the ams::define_list. That procedure has extensive documentation about the nuances of defining an ams_list. For example, lets assume that you are developing a package called "contacts" with the object_type of "ct_contact" and you want to define a list to collect information about a contact. You might choose to run the following procedure in when your system restarts:

+
+ams::define_list -package_key "contacts" \
+        -object_type "ct_contact" \
+        -list_name "contact_person" \
+        -pretty_name "The Fields used to Add/Edit a Contact Person" \
+        -attributes {
+                {first_names textbox {First Name(s)} {First Names} required}
+                {middle_names textbox {Middle Name(s)} {Middle Names}}
+                {last_name textbox {Last Name} {Last Names} required}
+                {email email {Email Address} {Email Addresses}}
+                {url url {Website} {Websites}}
+                {home_address address {Home Address} {Home Addresses}}
+                {home_phone telecom_number {Home Phone} {Home Phones}}
+                {gender radio {Gender} {Genders} {options {{Male} {Female}}}}
+        }
+
+ +

This will create an ams_list, define any attributes that haven't previously been defined for the ct_contact object and order the list in the order the attributes are specified.

+ +

AMS and ad_form

+

You have two options when dealing with ams and ad_form. Shorthand and detailed.

+

Shorthand

+

Shorthands is a completely simple way of creating forms without many options. These forms must only contain attributes defined in an ams_list. The supplied object_id must already exist in the acs_object table. The shorthand procs is ams_form, which is simply a wrapper for ad_form. For example, to create and ad_form named "contact_person_ae" create a page contacts/www/contact-person-ae.tcl with the following content:

+
+ad_page_contract {
+} {
+        {ct_contact_id:integer,notnull}
+}
+set title "Contact Person Add/Edit"
+set context [list $title]
+
+ams_form -package_key "contacts" \
+         -object_type "ct_contact" \
+         -list_name "contact_person" \
+         -form_name "contact_person_ae" \
+         -object_id $ct_contact_id \
+         -return_url "./"
+
+ad_return_template
+
+

The contacts/www/contact-person-ae.adp would contain

+
+<master>
+<property name="title">@title@</property">
+<property name="context">@context@</property">
+
+<formtemplate id="contact_person_ae"></formtemplate">
+
+

That's it. If this isn't flexible enough you can also go with the detailed method.

+ + +

Detailed

+

For many application the AMS and ad_form shorthand will be too simplistic. For those situations, you can use ams to interface with ad_form. You need to define ad_from -form elements like this: +

+ad_form ... -form [ams::ad_form::elements -package_key "contacts" -object_type "ct_contact" -list_name "contact_person"] ...
+
+

Note that this procedure returns an ad form appropriate element list. If you intending to define other elements you will need to ad_from -extend -name form_name -form ...

+

+

In the ad_form -edit_request block put

+
+ad_form ... -edit_request {
+        ams::object::attribute::values -vars -object_id $object_id
+    } ...
+
+

This returns the variables upvared into your page, i.e. the first_names attribute could be returned with a value of "Jane" and the last_name attribute with a value of "Doe"... etc. ad_from looks for all form elements and appropriately pre-fills the form with the given values.

+ +

In the -on_submit block you enter the following:

+
+ad_from ... -on_submit {
+        ams::ad_form::save \
+            -package_key "contacts" \
+            -object_type "ct_contact" \
+            -list_name "contact_person" \
+            -form_name "contact_person_ae" \
+            -object_id $ct_contact_id
+    }
+
+

This is how you interface with AMS and ad_form. You may also specify other code in the -form -on_submit and -on_submit blocks.

+ +

AMS and your package's UI

+ + +

to display attributes you can call ams::object::attribute::values to get the results back as upvared variables, as an array or as a list however you want. So, if on the contact-view page you do, for example to get an array with all attribute_values that are not null represented in. +

+
+ams::object::attribute::values -array "contact_info" -object_id $ct_contact_id
+
+

To add ams_attribute_values to a multirow you call ams::multirow::extend to efficiently extend your multirow with ams_attribute_values. For example:

+
+db_multirow contacts get_contacts { select ct_contact_id from ct_contacts }
+
+ams::multirow::extend \
+    -package_key "contacts" \
+    -object_type "ct_contact" \
+    -list_name "contact_person" \
+    -multirow "contacts" \
+    -key "ct_contact_id"
+
+

+

AMS Permissions

+

THIS SECTION NEEDS TO BE PROGRAMMED AN DOCUMENTED

+ +