From 0e7732ad86b901a1799da5a3edee22f8c542a0ba Mon Sep 17 00:00:00 2001
From: Pasqualino Ferrentino
Date: Tue, 16 Oct 2007 12:06:44 +0200
Subject: [PATCH] On the way to edit the presences
---
.../Bcd/Commands/GetUserPresencesSummaryCommand.pm | 2 +-
.../lib/breadcrumbs/Controller/BcController.pm | 14 ++++
.../lib/breadcrumbs/Controller/UserAds.pm | 28 ++++----
.../lib/breadcrumbs/Controller/UserPresences.pm | 75 ++++++++++++++++++++++
.../Dialogs/SelectPresenceInSiteDialog.pm | 19 ++++--
.../breadcrumbs/lib/breadcrumbs/Model/BcdModel.pm | 46 +++----------
.../breadcrumbs/root/src/enter_new_presence.tt | 11 ++++
.../root/src/up_choose_similar_presence.tt | 19 ++++++
.../breadcrumbs/root/src/up_edit_presence_done.tt | 1 +
.../breadcrumbs/root/src/up_presence_details.tt | 2 +-
.../root/src/user_trust_net_with_limit.tt | 2 +-
.../breadcrumbs/root/src/view_user_presences.tt | 2 +-
12 files changed, 160 insertions(+), 61 deletions(-)
create mode 100644 web-site/breadcrumbs/root/src/enter_new_presence.tt
create mode 100644 web-site/breadcrumbs/root/src/up_choose_similar_presence.tt
create mode 100644 web-site/breadcrumbs/root/src/up_edit_presence_done.tt
diff --git a/src/lib/Bcd/Commands/GetUserPresencesSummaryCommand.pm b/src/lib/Bcd/Commands/GetUserPresencesSummaryCommand.pm
index 986842e..36edd12 100644
--- a/src/lib/Bcd/Commands/GetUserPresencesSummaryCommand.pm
+++ b/src/lib/Bcd/Commands/GetUserPresencesSummaryCommand.pm
@@ -80,7 +80,7 @@ sub _exec{
($stash, $my_id, Bcd::Constants::PublicSitesConstants::HOMEMADE_PRESENCE);
$self->_add_the_ads_count($stash, $homemade_presences);
- $self->{object_presences} = $homemade_presences;
+ $self->{homemade_presences} = $homemade_presences;
#ok, it should be all ok
diff --git a/web-site/breadcrumbs/lib/breadcrumbs/Controller/BcController.pm b/web-site/breadcrumbs/lib/breadcrumbs/Controller/BcController.pm
index 6327d05..e462375 100644
--- a/web-site/breadcrumbs/lib/breadcrumbs/Controller/BcController.pm
+++ b/web-site/breadcrumbs/lib/breadcrumbs/Controller/BcController.pm
@@ -439,5 +439,19 @@ sub valid_session_presence{
}
}
+#this function simply should get a recordset and return an hash keyed in
+#a particular field
+sub _hashify_a_recordset{
+ my ($self, $dataset, $key) = @_;
+
+ my %hash;
+ foreach(@{$dataset}){
+ $hash{$_->{$key}} = $_;
+ delete $_->{$key};
+ }
+
+ return \%hash;
+}
+
1;
diff --git a/web-site/breadcrumbs/lib/breadcrumbs/Controller/UserAds.pm b/web-site/breadcrumbs/lib/breadcrumbs/Controller/UserAds.pm
index b110667..74ae44b 100644
--- a/web-site/breadcrumbs/lib/breadcrumbs/Controller/UserAds.pm
+++ b/web-site/breadcrumbs/lib/breadcrumbs/Controller/UserAds.pm
@@ -444,7 +444,7 @@ sub entered_locality_on_ok : Local {
($c, "NULL", $loc, $c->session->{steps}->{ad_type});
my $presences = $res->{presences};
- my $presences_hashified = $self->_hashify_the_presences($presences);
+ my $presences_hashified = $self->_hashify_a_recordset($presences, "id");
$c->session->{steps}->{presences} = $presences_hashified;
if (scalar(keys(%{$presences_hashified})) == 0){
@@ -457,20 +457,20 @@ sub entered_locality_on_ok : Local {
}
}
-sub _hashify_the_presences{
- my ($self, $presences) = @_;
+# sub _hashify_the_presences{
+# my ($self, $presences) = @_;
- my %hash;
- foreach(@{$presences}){
- $hash{$_->{id}} =
- {
- on_request => $_->{on_request},
- presence => $_->{presence},
- }
- }
+# my %hash;
+# foreach(@{$presences}){
+# $hash{$_->{id}} =
+# {
+# on_request => $_->{on_request},
+# presence => $_->{presence},
+# }
+# }
- return \%hash;
-}
+# return \%hash;
+# }
sub entered_ad_text_on_ok : Local {
my ($self, $c) = @_;
@@ -507,7 +507,7 @@ sub choose_loc_ok : Local {
($c, $public_site_id, "NULL", $c->session->{steps}->{ad_type});
my $presences = $res->{presences};
- my $presences_hashified = $self->_hashify_the_presences($presences);
+ my $presences_hashified = $self->_hashify_a_recordset($presences, "id");
$c->session->{steps}->{presences} = $presences_hashified;
if (scalar(keys(%{$presences_hashified})) == 0){
diff --git a/web-site/breadcrumbs/lib/breadcrumbs/Controller/UserPresences.pm b/web-site/breadcrumbs/lib/breadcrumbs/Controller/UserPresences.pm
index 06f05cf..5879006 100644
--- a/web-site/breadcrumbs/lib/breadcrumbs/Controller/UserPresences.pm
+++ b/web-site/breadcrumbs/lib/breadcrumbs/Controller/UserPresences.pm
@@ -5,6 +5,7 @@ use warnings;
use breadcrumbs::Controller::BcController;
use base 'breadcrumbs::Controller::BcController';
use NEXT;
+use breadcrumbs::Dialogs::PresenceInPublicSiteDialog;
=head1 NAME
@@ -47,8 +48,82 @@ sub view_presence_details : LocalRegex('^view_(\d+)$') {
my $res = $c->model("BcdModel")->get_ads_for_locus($c, $id_locus);
$c->stash->{ads_in_locus} = $res->{ads_in_locus};
$c->stash->{presence} = $res->{presence};
+ $c->stash->{id_locus} = $id_locus;
$c->stash->{template} = "up_presence_details.tt";
+
+ #this is used if the user wants to edit the presence
+ $c->session->{sack}->{presence} = $res->{presence};
+ $c->session->{hold_the_sack} = 1;
+}
+
+sub modify_presence : LocalRegex('^edit_(\d+)$') {
+ my ( $self, $c) = @_;
+ my $id_locus= $c->req->captures->[0];
+
+ $c->session->{hold_the_sack} = 1;
+
+ #ok, I should get the similar presences to this one...
+ my $res = $c->model("BcdModel")->get_similar_presences_in_space($c, $id_locus);
+ $c->stash->{similar_presences} = $res->{similar_presences};
+
+ #Now let's see if there are similar presences
+ if (scalar(@{$res->{similar_presences}}) == 0){
+ #ok, I must go to modify the presence
+ $c->detach('edit_presence');
+ } else {
+ #I make a wizard, just to let the user choose the presence to put in place
+
+ #I should hashify the similar presences
+ my $presences_hashified = $self->_hashify_a_recordset($res->{similar_presences}, "id");
+
+ my $dlg0 = breadcrumbs::Dialogs::SelectPresenceInSiteDialog->new($c, 1, $presences_hashified);
+ my $dlg1 = breadcrumbs::Dialogs::PresenceInPublicSiteDialog->new($c, 1);
+
+ #ok, then I make the wizard
+ my @step0 = ($dlg0, "up_choose_similar_presence.tt", "choose_similar_presence_on_ok");
+ my @step1 = ($dlg1, "enter_new_presence.tt", "edit_presence_on_ok");
+ my @step2 = (undef, "up_edit_presence_done.tt");
+
+ my @steps = (\@step0, \@step1, \@step2);
+ $self->_make_wizard($c, \@steps, '', "Modifica di una presenza");
+ $c->session->{steps}->{presence} = $c->session->{sack}->{presence};
+ }
+
+}
+
+sub choose_similar_presence_on_ok : Local {
+ my ($self, $c) = @_;
+
+ $c->stash->{old_presence} = $c->session->{steps}->{presence};
+
+ return 1;
+}
+
+sub edit_presence : Private {
+ my ( $self, $c) = @_;
+ #mmm, I should simply present a dialog to the user...
+ $c->session->{hold_the_sack} = 1;
+
+ my $dlg = breadcrumbs::Dialogs::PresenceInPublicSiteDialog->new($c);
+
+ $self->_process_this_dialog
+ ($c,
+ $dlg,
+ "enter_new_presence.tt",
+ 'edit_presence_on_ok');
+ $c->stash->{old_presence} = $c->session->{sack}->{presence};
+
+ $c->detach();
+}
+
+sub edit_presence_on_ok : Local {
+ my ( $self, $c) = @_;
+
+ $c->res->{body} = "ma che bello,,,,";
+
+ #all ok, for now...
+ return 0;
}
diff --git a/web-site/breadcrumbs/lib/breadcrumbs/Dialogs/SelectPresenceInSiteDialog.pm b/web-site/breadcrumbs/lib/breadcrumbs/Dialogs/SelectPresenceInSiteDialog.pm
index 5a2d122..afc3c6e 100644
--- a/web-site/breadcrumbs/lib/breadcrumbs/Dialogs/SelectPresenceInSiteDialog.pm
+++ b/web-site/breadcrumbs/lib/breadcrumbs/Dialogs/SelectPresenceInSiteDialog.pm
@@ -28,10 +28,9 @@ use breadcrumbs::Dialogs::BcDialog;
use base(qw/breadcrumbs::Dialogs::BcDialog/);
sub new{
- my ($class, $c, $for_wizard_d) = @_;
+ my ($class, $c, $for_wizard_d, $presences) = @_;
my $for_wizard = defined($for_wizard_d) ? $for_wizard_d : 0;
-
my $w = $c->widget('choose_presence_form')->method('post');
my $fs = $w->element('Fieldset', 'presence_select')
@@ -48,18 +47,21 @@ sub new{
$self->{widget} = $w;
bless ($self, $class);
+ if (defined($presences)){
+ $self->init_with_presences($c, $presences);
+ }
+
return $self;
}
-sub on_init_dialog{
- my ($self, $c) = @_;
+sub init_with_presences{
+ my ($self, $c, $presences) = @_;
#Ok, I should now have the presences....
my $e = $self->{widget}
->get_element( type => "Fieldset" )
->get_element(type => "Select");
- my $presences = $c->session->{steps}->{presences};
my %options;
$options{NULL} = "Nessuna di queste va bene";
@@ -76,5 +78,12 @@ sub on_init_dialog{
$e->options(%options);
}
+sub on_init_dialog{
+ my ($self, $c) = @_;
+
+ my $presences = $c->session->{steps}->{presences};
+ $self->init_with_presences($c, $presences) if defined($presences);
+}
+
1;
diff --git a/web-site/breadcrumbs/lib/breadcrumbs/Model/BcdModel.pm b/web-site/breadcrumbs/lib/breadcrumbs/Model/BcdModel.pm
index f28b77f..9c2121a 100644
--- a/web-site/breadcrumbs/lib/breadcrumbs/Model/BcdModel.pm
+++ b/web-site/breadcrumbs/lib/breadcrumbs/Model/BcdModel.pm
@@ -790,6 +790,14 @@ sub write_to_boss{
("an.write_to_boss", $id_ant_nest, $subject, $comment);
}
+sub get_similar_presences_in_space{
+ my ($self, $c, $id_locus) = @_;
+ my $session = $c->user->{server_session};
+ return $self->_issue_command_to_daemon
+ ("si.get_similar_presences", $session, $id_locus, "space");
+
+}
+
sub _dead_socket{
my $self = shift;
$self->_clean_last_socket();
@@ -802,23 +810,6 @@ sub _clean_last_socket{
close delete $self->{"sock"} if $self->{"sock"};; #the socket is useless now
}
-sub _send_quoted_printable_blob{
- my ($self, $blob) = @_;
-
- my $sock = $self->_get_safe_sock();
-
- my $encoded = MIME::QuotedPrint::encode_qp($blob, "\015\012");
-
- $encoded =~ s/^(\.?)/$1$1/sg; #also at the start of the string...
- $encoded =~ s/^(eot)/$1$1/sg; #also at the start of the string...
- $encoded =~ s/\015?\012(\.?)/\015\012$1$1/sg;
- $encoded =~ s/\015?\012(eot)/\015\012$1$1/sg;
-
- print $sock $encoded . EOL;
- #this is the end of the blob...
- print $sock "." . EOL;
-}
-
#this method should simply connect to the daemon
sub _issue_command_to_daemon{
@@ -827,31 +818,10 @@ sub _issue_command_to_daemon{
my $sock = $self->_get_safe_sock();
return $self->_dead_socket if (!defined($sock));
- #my @output = (); #empty for now...
#first of all I issue the command
print $sock $command . EOL or $self->_dead_socket();
- #then the parameters
-# for(@args){
-
-# if (ref ($_) eq "HASH"){
-# #ok, this is a "complex" argument, a "blob" like...
-
-# if ($_->{type} eq 'qp'){
-# $self->_send_quoted_printable_blob($_->{blob});
-# next;
-# }
-# }
-
-# #duplicate the eot if present
-# if (/^eot/){
-# $_ = "eot" . $_;
-# }
-
-# print $sock $_ . EOL or $self->_dead_socket();
-# }
-
#I simply freeze the input array
my $dumped_u = freeze \@args;
my $must_compress = 0;
diff --git a/web-site/breadcrumbs/root/src/enter_new_presence.tt b/web-site/breadcrumbs/root/src/enter_new_presence.tt
new file mode 100644
index 0000000..43056c6
--- /dev/null
+++ b/web-site/breadcrumbs/root/src/enter_new_presence.tt
@@ -0,0 +1,11 @@
+
+La vecchia presenza era:
+
+[% old_presence.presence %][% IF old_presence.on_request == 1 %] a richiesta [% END %]
+
+Dammi per favore la nuova presenza:
+
+
+
+[% widget_result.as_xml | replace ("_ampersand_", '&')%]
+
\ No newline at end of file
diff --git a/web-site/breadcrumbs/root/src/up_choose_similar_presence.tt b/web-site/breadcrumbs/root/src/up_choose_similar_presence.tt
new file mode 100644
index 0000000..44ade6f
--- /dev/null
+++ b/web-site/breadcrumbs/root/src/up_choose_similar_presence.tt
@@ -0,0 +1,19 @@
+
+
+
+ Sembra che ci siano già delle altre presenze che hai scelto
+per svolgere questa attività. A questo punto puoi per esempio migrare
+tutti gli annunci relativi all'attività che vuoi modificare in una di
+queste che ti presento qui sotto. Altrimenti, se nessuna di queste va
+bene, puoi anche modificare direttamente la presenza.
+
+
+
+ Tieni però conto che la modifica di una presenza è possibile
+solo se non ci sono affari in corso (ovvero fatture da pagare o da
+incassare relative a quell'annuncio).
+
+
+
+[% widget_result.as_xml | replace ("_ampersand_", '&')%]
+
\ No newline at end of file
diff --git a/web-site/breadcrumbs/root/src/up_edit_presence_done.tt b/web-site/breadcrumbs/root/src/up_edit_presence_done.tt
new file mode 100644
index 0000000..1d9c543
--- /dev/null
+++ b/web-site/breadcrumbs/root/src/up_edit_presence_done.tt
@@ -0,0 +1 @@
+Ok, modifiche effettuate
\ No newline at end of file
diff --git a/web-site/breadcrumbs/root/src/up_presence_details.tt b/web-site/breadcrumbs/root/src/up_presence_details.tt
index 76033d6..e048ce2 100644
--- a/web-site/breadcrumbs/root/src/up_presence_details.tt
+++ b/web-site/breadcrumbs/root/src/up_presence_details.tt
@@ -22,7 +22,7 @@
Quando: [% presence.presence %][% IF presence.on_request == 1 %] a richiesta[% END %].
- Modifica
+ Modifica
Per questo o questi annunci:
diff --git a/web-site/breadcrumbs/root/src/user_trust_net_with_limit.tt b/web-site/breadcrumbs/root/src/user_trust_net_with_limit.tt
index 800b1b8..75925d6 100644
--- a/web-site/breadcrumbs/root/src/user_trust_net_with_limit.tt
+++ b/web-site/breadcrumbs/root/src/user_trust_net_with_limit.tt
@@ -20,6 +20,6 @@
%]
-[% MACRO row_filter IF row.trust < trust_limit ; 1 ; ELSE; 0; END; %]
+[% MACRO row_filter IF row.trust <= trust_limit ; 1 ; ELSE; 0; END; %]
[% PROCESS sortable_dataset_table.tt %]
\ No newline at end of file
diff --git a/web-site/breadcrumbs/root/src/view_user_presences.tt b/web-site/breadcrumbs/root/src/view_user_presences.tt
index ff6f668..a6c045f 100644
--- a/web-site/breadcrumbs/root/src/view_user_presences.tt
+++ b/web-site/breadcrumbs/root/src/view_user_presences.tt
@@ -10,7 +10,7 @@
custom_cell => '[' _ '% IF row.id_site != undef %' _ ']' _
'[' _ '% row.name %' _ ']' _
'[' _ '% ELSE %' _ ']' _
- '[' _ '% IF row.id_special_site == 0 %' _ ']' _
+ '[' _ '% IF row.special_site == 0 %' _ ']' _
'Casa tua' _
'[' _ '% ELSE %' _ ']' _
'Casa del cliente' _
--
2.11.4.GIT