1 #======================================================================
 
   4 #======================================================================
 
   6 # Saving and loading drafts
 
   8 #======================================================================
 
  14 require "bin/mozilla/common.pl";
 
  19   $main::lxdebug->enter_sub();
 
  21   my $form     = $main::form;
 
  22   my %myconfig = %main::myconfig;
 
  23   my $locale   = $main::locale;
 
  25   if (!$form->{draft_id} && !$form->{draft_description}) {
 
  26     restore_form($form->{SAVED_FORM}, 1) if ($form->{SAVED_FORM});
 
  27     delete $form->{SAVED_FORM};
 
  29     $form->{SAVED_FORM}   = save_form(qw(stylesheet login password));
 
  30     $form->{remove_draft} = 1;
 
  33     print($form->parse_html_template("drafts/save_new"));
 
  35     return $main::lxdebug->leave_sub();
 
  38   my ($draft_id, $draft_description) = ($form->{draft_id}, $form->{draft_description});
 
  40   restore_form($form->{SAVED_FORM}, 1);
 
  41   delete $form->{SAVED_FORM};
 
  43   Drafts->save(\%myconfig, $form, $draft_id, $draft_description);
 
  45   $form->{saved_message} = $locale->text("Draft saved.");
 
  49   $main::lxdebug->leave_sub();
 
  53   $main::lxdebug->enter_sub();
 
  55   my $form     = $main::form;
 
  56   my %myconfig = %main::myconfig;
 
  58   Drafts->remove(\%myconfig, $form, $form->{draft_id}) if ($form->{draft_id});
 
  60   delete @{$form}{qw(draft_id draft_description)};
 
  62   $main::lxdebug->leave_sub();
 
  65 sub load_draft_maybe {
 
  66   $main::lxdebug->enter_sub();
 
  68   my $form     = $main::form;
 
  69   my %myconfig = %main::myconfig;
 
  71   $main::lxdebug->leave_sub() and return 0 if ($form->{DONT_LOAD_DRAFT});
 
  73   my ($draft_nextsub) = @_;
 
  75   my @drafts = Drafts->list(\%myconfig, $form);
 
  77   $main::lxdebug->leave_sub() and return 0 unless (@drafts);
 
  79   $draft_nextsub = "add" unless ($draft_nextsub);
 
  81   delete $form->{action};
 
  82   my $saved_form = save_form(qw(stylesheet login password));
 
  85   print($form->parse_html_template("drafts/load",
 
  86                                    { "DRAFTS"        => \@drafts,
 
  87                                      "SAVED_FORM"    => $saved_form,
 
  88                                      "draft_nextsub" => $draft_nextsub }));
 
  90   $main::lxdebug->leave_sub();
 
  96   $main::lxdebug->enter_sub();
 
  98   my $form     = $main::form;
 
 100   my $draft_nextsub = $form->{draft_nextsub} || "add";
 
 102   restore_form($form->{SAVED_FORM}, 1);
 
 103   delete $form->{SAVED_FORM};
 
 105   $form->{DONT_LOAD_DRAFT} = 1;
 
 107   call_sub($draft_nextsub);
 
 109   $main::lxdebug->leave_sub();
 
 113   $main::lxdebug->enter_sub();
 
 115   my $form     = $main::form;
 
 116   my %myconfig = %main::myconfig;
 
 118   my ($old_form, $id, $description) = Drafts->load(\%myconfig, $form, $form->{id});
 
 121     $old_form = YAML::Load($old_form);
 
 123     my %dont_save_vars      = map { $_ => 1 } @Drafts::dont_save;
 
 124     my @restore_vars        = grep { !$dont_save_vars{$_} } keys %{ $old_form };
 
 126     @{$form}{@restore_vars} = @{$old_form}{@restore_vars};
 
 128     $form->{draft_id}              = $id;
 
 129     $form->{draft_description}     = $description;
 
 130     $form->{remove_draft}          = 'checked';
 
 135   $main::lxdebug->leave_sub();
 
 139   $main::lxdebug->enter_sub();
 
 141   my $form     = $main::form;
 
 142   my %myconfig = %main::myconfig;
 
 145   foreach (keys %{$form}) {
 
 146     push @ids, $1 if (/^checked_(.*)/ && $form->{$_});
 
 148   Drafts->remove(\%myconfig, $form, @ids) if (@ids);
 
 150   restore_form($form->{SAVED_FORM}, 1);
 
 151   delete $form->{SAVED_FORM};
 
 155   $main::lxdebug->leave_sub();
 
 158 sub draft_action_dispatcher {
 
 159   $main::lxdebug->enter_sub();
 
 161   my $form     = $main::form;
 
 162   my $locale   = $main::locale;
 
 164   if ($form->{draft_action} eq $locale->text("Skip")) {
 
 167   } elsif ($form->{draft_action} eq $locale->text("Delete drafts")) {
 
 171   $main::lxdebug->leave_sub();