summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordakkar <dakkar@luxion>2005-11-07 17:14:03 +0000
committerdakkar <dakkar@luxion>2005-11-07 17:14:03 +0000
commit585dd7c4c5fe4f089952fea47c0d0849d808e114 (patch)
tree315eba58b7b6c574ae3078eaac45cc36875fe7b6
parentaggiunto retrieve per tag multipli (diff)
downloadBookmarks-585dd7c4c5fe4f089952fea47c0d0849d808e114.tar.gz
Bookmarks-585dd7c4c5fe4f089952fea47c0d0849d808e114.tar.bz2
Bookmarks-585dd7c4c5fe4f089952fea47c0d0849d808e114.zip
form di aggiunta bookmark funzionante
-rw-r--r--lib/Bookmarks/C/Main.pm64
-rw-r--r--root/add_form14
-rw-r--r--root/closewin1
-rwxr-xr-xscript/bookmarks_load.pl3
4 files changed, 82 insertions, 0 deletions
diff --git a/lib/Bookmarks/C/Main.pm b/lib/Bookmarks/C/Main.pm
index 3434e00..2cab5ee 100644
--- a/lib/Bookmarks/C/Main.pm
+++ b/lib/Bookmarks/C/Main.pm
@@ -2,6 +2,8 @@ package Bookmarks::C::Main;
use strict;
use base 'Catalyst::Base';
+use Bookmarks::Utils;
+use YAML;
=head1 NAME
@@ -62,17 +64,79 @@ sub icon : Global {
}
}
+sub favicon : Path('favicon.ico') {
+ my ( $self, $c ) = @_;
+ $c->res->status(404);
+ $c->res->body('nonce');
+}
+
sub jump : Global {
my ( $self, $c ) = @_;
my $link=Bookmarks::M::DB::Links->retrieve($c->req->param('link'));
$link->access_count($link->access_count()+1);
+ $link->last_access_date(time());
$link->update();
$c->res->status(302);
$c->res->location($link->url());
}
+sub add : Global {
+ my ( $self, $c ) = @_;
+
+ my %pre_link=();
+ for my $i (qw(url title descr)) {
+ $pre_link{$i}=$c->req->param($i);
+ }
+ my @tags=split /[ +]/,($c->req->param('tag')||'');
+
+ print {*STDERR} Dump(\%pre_link);
+ print {*STDERR} Dump($c->req);
+
+ # GET: prepare the form from the URL params
+ if ($c->req->method eq 'GET') {
+ $c->stash->{link}=\%pre_link;
+ $c->stash->{tags}=\@tags;
+ $c->stash->{template}='add_form';
+ }
+ # POST: accept data and create link+tags
+ elsif ($c->req->method eq 'POST') {
+ my ($dblink)=Bookmarks::M::DB::Links->search({url=>$pre_link{url}});
+ if (!defined $dblink) { # devo crearlo
+ $dblink=Bookmarks::M::DB::Links->create({});
+ $dblink->add_date(time());
+ $dblink->access_count(0);
+ }
+ $dblink->set(%pre_link);
+ $dblink->set_icon(Bookmarks::Utils::get_site_icon($pre_link{url}));
+ $dblink->update();
+
+ # tags
+ Bookmarks::M::DB::LinksTags->search({
+ link => $dblink->pk()
+ })->delete_all();
+
+ for my $tagname (@tags) {
+ my $dbtag=Bookmarks::M::DB::Tags->find_or_create({
+ name => $tagname,
+ });
+
+ Bookmarks::M::DB::LinksTags->find_or_create({
+ tag => $dbtag->pk(),
+ link => $dblink->pk(),
+ });
+ }
+
+ if ($c->req->param('close')) {
+ $c->stash->{template}='closewin';
+ }
+ else {
+ $c->res->redirect($c->req->base.'tags');
+ }
+ }
+}
+
=back
diff --git a/root/add_form b/root/add_form
new file mode 100644
index 0000000..bbb608a
--- /dev/null
+++ b/root/add_form
@@ -0,0 +1,14 @@
+<html>
+<head>
+<title>add</title>
+</head>
+<body>
+<form action="[% base _ 'add' %]" method="post">
+<p>Link: <input name="url" type="text" value="[% link.url %]" /></p>
+<p>Title: <input name="title" type="text" value="[% link.title %]" /></p>
+<p>Description: <input name="descr" type="text" value="[% link.descr %]" /></p>
+<p>Tags: <input name="tag" type="text" value="[% tags.join(' ') %]" /></p>
+<input type="submit" />
+</form>
+</body>
+</html> \ No newline at end of file
diff --git a/root/closewin b/root/closewin
new file mode 100644
index 0000000..2e1d5eb
--- /dev/null
+++ b/root/closewin
@@ -0,0 +1 @@
+close this window
diff --git a/script/bookmarks_load.pl b/script/bookmarks_load.pl
index 2b2983d..7b16fa1 100755
--- a/script/bookmarks_load.pl
+++ b/script/bookmarks_load.pl
@@ -42,10 +42,13 @@ for my $link (@$links) {
$dblink->set_icon(Bookmarks::Utils::get_site_icon($link->{href}));
$dblink->update();
+ Bookmarks::M::DB::LinksTags->search({link => $dblink->pk()})->delete_all();
+
for my $tagname (@{$link->{tags}}) {
my $dbtag=Bookmarks::M::DB::Tags->find_or_create({
name => $tagname,
});
+
Bookmarks::M::DB::LinksTags->find_or_create({
tag => $dbtag->pk(),
link => $dblink->pk(),