Index: openacs-4/packages/news-aggregator/www/subscriptions.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/news-aggregator/www/subscriptions.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/packages/news-aggregator/www/subscriptions.tcl 28 Aug 2003 09:41:57 -0000 1.2 +++ openacs-4/packages/news-aggregator/www/subscriptions.tcl 20 Mar 2004 11:12:29 -0000 1.3 @@ -1,59 +1,155 @@ -#packages/news-aggregator/subscriptions.tcl - ad_page_contract { The News Aggregator subscription page. @author Simon Carstensen (simon@bcuni.net) @creation-date Jan 2003 } { - source_id:integer,notnull,optional,multiple + aggregator_id:integer + new_source_id:integer,optional + {source_id:integer,multiple ""} {feed_url ""} -} -properties { - context_bar:onevalue + {orderby ""} } -ad_maybe_redirect_for_registration - permission::require_permission \ - -object_id [ad_conn package_id] \ + -object_id $aggregator_id \ -privilege write -set user_id [ad_conn user_id] +set page_title "Subscriptions" +set context [list $page_title] -set context_bar [ad_context_bar "Add Subscription"] - +set user_id [ad_conn user_id] set package_id [ad_conn package_id] +set package_url [ad_conn package_url] -ad_form -name add_subscription -form { +set opml_url "${package_url}opml/$aggregator_id/mySubscriptions.opml" - new_source_id:key +# This is done in case we want to implement some user interface +# stuff in the future where it might be useful. +if { [empty_string_p $feed_url] } { + set feed_url_val "" +} else { + set feed_url_val $feed_url +} + + #ad_returnredirect "[ad_conn package_url]opml/$aggregator_id/mySubscriptions.opml" + #ad_script_abort - {feed_url:text(text) {value "http://"} {label "URL:"} {html { size 55 }}} - {add_submit:text(submit) {label "Add"}} -} -validate { - {feed_url - {[exists_and_not_null feed_url] && ![string equal "http://" $feed_url]} "You must specify a URL." +if { [exists_and_not_null source_id] } { + foreach delete_id $source_id { + news_aggregator::subscription::delete \ + -source_id $delete_id \ + -aggregator_id $aggregator_id } -} -new_data { - na_add_source $feed_url $user_id $package_id :key - ad_returnredirect "subscriptions" - ad_script_abort } -db_multirow sources sources { *SQL* } +set aggregator_count [db_string count_aggregators {}] -ad_form -name delete_subscription -form { +set bulk_actions { + Unsubscribe subscriptions Unsubscribe +} - {delete_submit:text(submit) {label "Unsubscribe" } } -} -on_submit { - if {[exists_and_not_null source_id]} { - foreach delete_id $source_id { - db_exec_plsql delete_source { *SQL* } +if { $aggregator_count > 1 } { + # user has more than 1 aggregator, let's present our fancy move and copy features + if { $aggregator_count > 2 } { + set title "another aggregator" + } else { + set title [db_string select_name {}] + } + lappend bulk_actions \ + Copy subscription-copy "Copy selected subscriptions to $title" \ + Move subscription-move "Move selected subscriptions to $title" + +} + +list::create \ + -name sources \ + -multirow sources \ + -key source_id \ + -row_pretty_plural "subscriptions" \ + -actions { + "Export Subscriptions" "opml" "Export your subscriptions as an OPML file" + "Import Subscriptions" "opml-import" "Import your subscriptions from an OPML file" + } -bulk_actions $bulk_actions -elements { + title { + label "Name" + link_url_eval $link + } + last_scanned { + label "Last Scan" + } + last_modified { + label "Last Update" } + updates { + label "Updates" + html {align center} + } + feed_url { + label "Source" + display_template { + View the XML source for this subscription + } + } + } -orderby { + default_value title,asc + title { + label "Name" + orderby_asc "lower(title) asc" + orderby_desc "lower(title) desc" + } + last_scanned { + label "Last Updated" + orderby_desc "last_scanned desc" + orderby_asc "last_scanned asc" + } + last_modified { + label "Last Update" + orderby_desc "last_modified_stamp desc" + orderby_asc "last_modified_stamp asc" + } + updates { + label "Updates" + orderby_asc "updates asc" + orderby_desc "updates desc" + } } - ad_returnredirect "subscriptions" - ad_script_abort +set package_url [ad_conn package_url] + +db_multirow -extend {xml_graphics_url} sources sources {} { + if { [exists_and_not_null new_source_id] && $source_id == $new_source_id } { + set new_source_title $title + } + set xml_graphics_url "${package_url}graphics/xml.gif" } -ad_return_template +ad_form -name add_subscription -form { + {subscription_id:integer(hidden),key} + {feed_url:text(text) + {value $feed_url_val} + {label "URL:"} + {html {size 55}} + } + {add_submit:text(submit) + {label "Add"} + } +} -validate { + {feed_url + { [exists_and_not_null feed_url] && ![string equal "http://" $feed_url] } + { You must specify a URL } + } +} -new_data { + set new_source_id [news_aggregator::source::new \ + -feed_url $feed_url \ + -aggregator_id $aggregator_id \ + -user_id $user_id \ + -package_id $package_id] + + + ad_returnredirect [export_vars -base subscriptions {new_source_id}] + ad_script_abort +}