1 #======================================================================
4 #======================================================================
6 # Saving and loading drafts
8 #======================================================================
14 require "bin/mozilla/common.pl";
17 $lxdebug->enter_sub();
19 if (!$form->{draft_id} && !$form->{draft_description}) {
20 restore_form($form->{SAVED_FORM}, 1) if ($form->{SAVED_FORM});
21 delete $form->{SAVED_FORM};
23 $form->{SAVED_FORM} = save_form(qw(stylesheet login password));
24 $form->{remove_draft} = 1;
27 print($form->parse_html_template("drafts/save_new"));
29 return $lxdebug->leave_sub();
32 my ($draft_id, $draft_description) = ($form->{draft_id}, $form->{draft_description});
34 restore_form($form->{SAVED_FORM}, 1);
35 delete $form->{SAVED_FORM};
37 Drafts->save(\%myconfig, $form, $draft_id, $draft_description);
39 $form->{saved_message} = $locale->text("Draft saved.");
43 $lxdebug->leave_sub();
47 $lxdebug->enter_sub();
49 Drafts->remove(\%myconfig, $form, $form->{draft_id}) if ($form->{draft_id});
51 delete @{$form}{qw(draft_id draft_description)};
53 $lxdebug->leave_sub();
56 sub load_draft_maybe {
57 $lxdebug->enter_sub();
59 $lxdebug->leave_sub() and return 0 if ($form->{DONT_LOAD_DRAFT});
61 my ($draft_nextsub) = @_;
63 my @drafts = Drafts->list(\%myconfig, $form);
65 $lxdebug->leave_sub() and return 0 unless (@drafts);
67 $draft_nextsub = "add" unless ($draft_nextsub);
69 delete $form->{action};
70 my $saved_form = save_form(qw(stylesheet login password));
73 print($form->parse_html_template("drafts/load",
74 { "DRAFTS" => \@drafts,
75 "SAVED_FORM" => $saved_form,
76 "draft_nextsub" => $draft_nextsub }));
78 $lxdebug->leave_sub();
84 $lxdebug->enter_sub();
86 my $draft_nextsub = $form->{draft_nextsub} || "add";
88 restore_form($form->{SAVED_FORM}, 1);
89 delete $form->{SAVED_FORM};
91 $form->{DONT_LOAD_DRAFT} = 1;
93 call_sub($draft_nextsub);
95 $lxdebug->leave_sub();
99 $lxdebug->enter_sub();
101 my ($old_form, $id, $description) = Drafts->load(\%myconfig, $form, $form->{id});
104 $old_form = YAML::Load($old_form);
106 my %dont_save_vars = map { $_ => 1 } @Drafts::dont_save;
107 my @restore_vars = grep { !$skip_vars{$_} } keys %{ $old_form };
109 @{$form}{@restore_vars} = @{$old_form}{@restore_vars};
111 $form->{draft_id} = $id;
112 $form->{draft_description} = $description;
113 $form->{remove_draft} = 'checked';
118 $lxdebug->leave_sub();
122 $lxdebug->enter_sub();
125 foreach (keys %{$form}) {
126 push @ids, $1 if (/^checked_(.*)/ && $form->{$_});
128 Drafts->remove(\%myconfig, $form, @ids) if (@ids);
130 restore_form($form->{SAVED_FORM}, 1);
131 delete $form->{SAVED_FORM};
135 $lxdebug->leave_sub();
138 sub draft_action_dispatcher {
139 $lxdebug->enter_sub();
141 if ($form->{draft_action} eq $locale->text("Skip")) {
144 } elsif ($form->{draft_action} eq $locale->text("Delete drafts")) {
148 $lxdebug->leave_sub();