1 #======================================================================
4 #======================================================================
6 # Saving and loading drafts
8 #======================================================================
14 require "bin/mozilla/common.pl";
17 $main::lxdebug->enter_sub();
19 my $form = $main::form;
20 my %myconfig = %main::myconfig;
21 my $locale = $main::locale;
23 if (!$form->{draft_id} && !$form->{draft_description}) {
24 restore_form($form->{SAVED_FORM}, 1) if ($form->{SAVED_FORM});
25 delete $form->{SAVED_FORM};
27 $form->{SAVED_FORM} = save_form(qw(stylesheet login password));
28 $form->{remove_draft} = 1;
31 print($form->parse_html_template("drafts/save_new"));
33 return $main::lxdebug->leave_sub();
36 my ($draft_id, $draft_description) = ($form->{draft_id}, $form->{draft_description});
38 restore_form($form->{SAVED_FORM}, 1);
39 delete $form->{SAVED_FORM};
41 Drafts->save(\%myconfig, $form, $draft_id, $draft_description);
43 $form->{saved_message} = $locale->text("Draft saved.");
47 $main::lxdebug->leave_sub();
51 $main::lxdebug->enter_sub();
53 my $form = $main::form;
54 my %myconfig = %main::myconfig;
56 Drafts->remove(\%myconfig, $form, $form->{draft_id}) if ($form->{draft_id});
58 delete @{$form}{qw(draft_id draft_description)};
60 $main::lxdebug->leave_sub();
63 sub load_draft_maybe {
64 $main::lxdebug->enter_sub();
66 my $form = $main::form;
67 my %myconfig = %main::myconfig;
69 $main::lxdebug->leave_sub() and return 0 if ($form->{DONT_LOAD_DRAFT});
71 my ($draft_nextsub) = @_;
73 my @drafts = Drafts->list(\%myconfig, $form);
75 $main::lxdebug->leave_sub() and return 0 unless (@drafts);
77 $draft_nextsub = "add" unless ($draft_nextsub);
79 delete $form->{action};
80 my $saved_form = save_form(qw(stylesheet login password));
83 print($form->parse_html_template("drafts/load",
84 { "DRAFTS" => \@drafts,
85 "SAVED_FORM" => $saved_form,
86 "draft_nextsub" => $draft_nextsub }));
88 $main::lxdebug->leave_sub();
94 $main::lxdebug->enter_sub();
96 my $form = $main::form;
98 my $draft_nextsub = $form->{draft_nextsub} || "add";
100 restore_form($form->{SAVED_FORM}, 1);
101 delete $form->{SAVED_FORM};
103 $form->{DONT_LOAD_DRAFT} = 1;
105 call_sub($draft_nextsub);
107 $main::lxdebug->leave_sub();
111 $main::lxdebug->enter_sub();
113 my $form = $main::form;
114 my %myconfig = %main::myconfig;
116 my ($old_form, $id, $description) = Drafts->load(\%myconfig, $form, $form->{id});
119 $old_form = YAML::Load($old_form);
121 my %dont_save_vars = map { $_ => 1 } @Drafts::dont_save;
122 my @restore_vars = grep { !$dont_save_vars{$_} } keys %{ $old_form };
124 @{$form}{@restore_vars} = @{$old_form}{@restore_vars};
126 $form->{draft_id} = $id;
127 $form->{draft_description} = $description;
128 $form->{remove_draft} = 'checked';
133 $main::lxdebug->leave_sub();
137 $main::lxdebug->enter_sub();
139 my $form = $main::form;
140 my %myconfig = %main::myconfig;
143 foreach (keys %{$form}) {
144 push @ids, $1 if (/^checked_(.*)/ && $form->{$_});
146 Drafts->remove(\%myconfig, $form, @ids) if (@ids);
148 restore_form($form->{SAVED_FORM}, 1);
149 delete $form->{SAVED_FORM};
153 $main::lxdebug->leave_sub();
156 sub draft_action_dispatcher {
157 $main::lxdebug->enter_sub();
159 my $form = $main::form;
160 my $locale = $main::locale;
162 if ($form->{draft_action} eq $locale->text("Skip")) {
165 } elsif ($form->{draft_action} eq $locale->text("Delete drafts")) {
169 $main::lxdebug->leave_sub();