Forum OpenACS Q&A: Automatic list generation

Collapse
Posted by kousalya S on
Hi Everyone,

I am trying to add a new feature.

The tried the following code,

sample.tcl

#packages/sample/www/new.tcl

ad_page_contract {
This page allows the users to add bus tickets.
} {
{sample_id: "" }
{number: ""}
{samplenew: ""}
{form_mode "edit" }
}
---------------------------------------------------------------
# Create the Form
# ---------------------------------------------------------------

set form_id "sample"
ad_form -name sample -export {user_id package_id} -mode $form_mode -form {

{number:text(text),optional {label "Number"}}
} -has_submit 1

template::form create samplenew -has_submit 1
template::element create samplenew Type -widget select -datatype text -options
template::element create samplenew No -widget text -datatype text
template::element create samplenew Age -widget text -datatype text
template::element create samplenew Class -widget select -datatype text -options
template::element create samplenew TicketNr -widget text -datatype text
template::element create samplenew Amount -widget text -datatype text

set headers {Type Number Age Class TicketNr Amount}
set title {Enter the Details}

sample.adp

<master>
<property name="doc(title)">@page_title@</property>
<formtemplate id=sample></formtemplate>

<formtemplate id=samplenew style=grid cols=6 headers=@headers@ title=@title@>
</formtemplate>

Here the generated a list showing the fields in horizontal view.

What I need is if I click an option, the same set of rows(I mean the set of fields) should be generated again in the list.

Thanks in advance

Collapse
Posted by Jim Lynch on
could you show pictures of what you want... I don't want to look at anyone else's code at this moment
Collapse
Posted by kousalya S on
Hi Jim,

Please look into the following link,

http://www.airfares.com.sg/forms_new/AirTicket_Booking.aspx

I need exactly the same form.

Below the block 4 "passenger details", on selecting the total number of passengers based on the value the grid is generated.

Please help me out.
I also need these values to be updated in the database table.

Awaiting for your reply

Collapse
Posted by kousalya S on
And Jim, I need ad_form to be included. Since dynfield extend form feature is based on ad_form.
Collapse
Posted by kousalya S on
Hi,

Here is my code to generate the list as what I have mentioned. But I need same form to display some columns in horizontal grid format and some in list format. Thing is I need dynfield feature to be included.

My code includes all the functions except one feature which embeds grid and list field view in same ad_form.

sample.tcl
#packages/sample/www/multiple3.tcl

ad_page_contract {

} {
sample_id:optional
{sample_nr: ""}
{end_date: ""}
{end_date_$i: ""}
{ticketnr_$i: ""}
ticketnr:array,optional
end_date:array,optional
{form_mode "edit" }
{number: ""}
}
#----------------------
#Defaults
#---------------------
set page_title ""
set user_id [ad_conn user_id]
set package_id [ad_conn package_id]
set ip_address [ad_conn peeraddr]

# ---------------------------------------------------------------
# Create the Form
# ---------------------------------------------------------------
set headers {Date TicketNr}
set title {Details}

set form_id "sample"
ad_form -name sample -mode $form_mode -form {
sample_id:key
{sample_nr:text(text),optional {label "Sample Nr" } }
{number:text(text) {html
{ onchange "document.sample.__refreshing_p.value='1';document.sample.submit()" } } }
}
# Add DynFields to the form
set my_sample_id 0
if {[info exists sample_id]} { set my_sample_id $sample_id }
im_dynfield::append_attributes_to_form \
    -object_type "im_sample" \
    -form_id $form_id \
    -object_id $my_sample_id

# ---------------------------------------------------------------
# Define Form Actions
# ---------------------------------------------------------------

ad_form -extend -name $form_id\

set date [list]
for {set i 1} {$i <= $number} {incr i} {

append date "
    {end_date_$i:text,optional
        {label \"End_Date #$i\"}
    }"
append date "
    {ticketnr_$i:text,optional
        {label \"TicketNr #$i\"}
    }"

}

ad_form -extend -name sample -form $date \

if { $i > 0 } {
    ad_form -extend -name sample -on_request {
        foreach name [array names date] {
            set $name $date($name)
        }
    } -on_submit {
        set task_revisions [list]
        for {set i 1} {$i <= $number} {incr i} {
      set sample_item_id [db_nextval "im_sample_items_seq"]
            set task_revisions [db_dml new_task_item "
            insert into im_sample
              ( sample_id, sample_item_id, type, ticketnr)
            values
              (:sample_id,:sample_item_id, :end_date_$i, :ticketnr_$i)"]
        }

    im_dynfield::attribute_store \
            -object_type "im_sample" \
            -object_id $object_id \
            -form_id $form_id
    } -select_query {
    select    s.*
      from im_sample s,
          acs_objects obj
      where s.sample_id = :object_id
      and obj.object_id = s.sample_id
      and obj.creation_user = :user_id
      and obj.context_id = :package_id

} -edit_data {
  # update the information on our table
  db_dml im_sample_update "
      update im_sample
        set  type=::end_date_$i, ticket_nr= :ticketnr_$i
where sample_item_id = :sample_item_id"

# update the last modified information on the object
  db_exec_plsql sample_form_obj_item_object_update {
      select acs_object__update_last_modified(:sample_id,:user_id,:ip_address)
  }
im_dynfield::attribute_store \
            -object_type "im_sample" \
            -object_id $object_id \
            -form_id $form_id
} -after_submit {
        ad_returnredirect multiple3
        ad_script_abort
    }
}

sample.adp
<master>
<property name="doc(title)">@page_title@</property>
<formtemplate id=sample style=wizard> </formtemplate>

Please do help me out!

Collapse
Posted by Jim Lynch on
OK, let me break this down... I see two parts to this...

Part 1, you say "I want to add feature xyz"

Part 2, you show the source

What's missing from part 1, is the work you've done to design the feature, its api and how you will invoke it from your code...

I'm not totally understanding yet what you're asking for... do you want help on a specific part of openacs you're not understanding? Or, do you want someone to literally do the work of building the site?

If you want to understand one specific piece, what is it?

If you want someone to come onboard to help you build the site, there is a lot of talent here that can help you, and suitable arrangements can be made, assuming you want to go in that direction.

Collapse
Posted by kousalya S on
I am trying to bring grid and list view in one page using ad_form where i can add fields for list in dynfield.

For example :

id :
Budget :
No of passangers: ( if the input is 3)

I should get 3 three rows of below grid where my input of
"No of passangers" is 3.

Name | Type | Age | ticket nr | status |
---------------------------------------

1)

2)

3)

Where i will have one submit button.

Two tables will be involved

Table 1 : Columns (id , Budget ,no of passangers)

Table 2 : Columns ( internal id( generated for each row), Name , type, age, ticker nr, status , id( id of table1),

I should be able to add fields of this form in dynfield
( For list view or grid view), so we want to use ad_form.

------------------------------------------------------------Please reply us asap. Thank you for your great support.