Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 91ab1ef6

Von Sven Schöling vor etwa 17 Jahren hinzugefügt

  • ID 91ab1ef646193de9359076a876a33a74d7691145
  • Vorgänger d1e4ee79
  • Nachfolger ac7a6ae3

Um die Benutzung des Template Systems mal ein wenig zu foerdern.

Die bin/mozilla/oe.pl noch einmal umgeschrieben, so dass jetzt noch mehr Funktionen ins Frontend ausgelagert sind.

Ein neues Highlight ist die template/generic/multibox.html, die es erlaubt aus wenigen Steuerkommandos ein HTML-Eingabefeld zu erstellen, was bei kleinen Datenmengen als Dropdownbox erscheint, udn bei grossen asl Textfeld, mit dazugehörigem Popup-Button, um eine Auswahlliste aufzumachen. Saemtliche Funktionen lassen sich ueber Perlfunktionsreferenzen wieder zurück ins Backend leiten, und dort wieder mit komplexer Logik füllen. Dokumentation ist im Template direkt enthalten.

Die Customer/Vendor Eingabe macht auch gleich Gebrauch davon und erzeugt bei zu grosser Anzahl ein Textfeld, und daneben einen Suchbutton, der die passenden Kunden in einer Liste anzeigt.

Der "Kundendetails"-Button wurde von "?" umbenannt in "D" (immernoch gruselig)

Auf Wunsch von Moritz habe ich die display_row von bin/mozilla/oe.pl wieder verlagert in die bin/mozilla/io.pl, und dafuer die Version in bin/mozilla/invoice_io.pl deaktiviert.

Unterschiede anzeigen:

bin/mozilla/common.pl
80 80
  $lxdebug->leave_sub();
81 81
}
82 82

  
83
## Customers/Vendors
84

  
85
sub check_customer_or_vendor {
86
  $lxdebug->enter_sub();
87

  
88
  my ($field, $cov_selected_nextsub, $is_vendor) = @_;
89

  
90
  if ($form->{"f_${field}"} eq $form->{"f_old_${field}"}) {
91
    $lxdebug->leave_sub();
92
    return 1;
93
  }
94

  
95
  my $type = $is_vendor ? $locale->text("vendor") : $locale->text("customer");
96

  
97
  my $old_form = save_form();
98
  $form->{"name"} = $form->{"f_${field}"};
99
  $form->{"obsolete"} = 1;
100
  my $covs;
101
  $covs = Common->retrieve_customers_or_vendors(\%myconfig, $form, "name", 1, $is_vendor);
102
  restore_form($old_form);
103

  
104
  if (0 == scalar(@{$covs})) {
105
    $form->header();
106
    $form->show_generic_error(sprintf($locale->text("There is no %s whose name matches '%s'."), $type, $form->{"f_${field}"}));
107

  
108
    $lxdebug->leave_sub();
109
    return 0;
110

  
111
  }
112

  
113
  if (1 != scalar(@{$covs})) {
114
    # If there is more than one CoV with the same name
115
    # then we have to check if the ID is set, too. Otherwise
116
    # we'd be stuck in an endless loop.
117
    if ($form->{"f_${field}_id"}) {
118
      foreach my $cov (@{$covs}) {
119
        if (($form->{"f_${field}_id"} == $cov->{"id"}) &&
120
            ($form->{"f_${field}"} eq $cov->{"name"})) {
121
          $lxdebug->leave_sub();
122
          return 1;
123
        }
124
      }
125
    }
126

  
127
    $form->{"cov_selected_nextsub"} = $cov_selected_nextsub;
128
    $form->{"check_cov_field"} = $field;
129
    select_customer_or_vendor("cov_selected", $is_vendor, @{$covs});
130
    $lxdebug->leave_sub();
131
    return 0;
132
  }
133

  
134
  $form->{"f_${field}_id"} = $covs->[0]->{"id"};
135
  $form->{"f_${field}"} = $covs->[0]->{"name"};
136

  
137
  $lxdebug->leave_sub();
138

  
139
  return 1;
140
}
141

  
142
sub select_customer_or_vendor {
143
  $lxdebug->enter_sub();
144

  
145
  my ($callback_sub, $is_vendor, @covs) = @_;
146

  
147
  my $old_form = save_form();
148

  
149
  if (0 == scalar(@covs)) {
150
    delete($form->{"name"});
151
    $form->{"obsolete"} = 1;
152
    my $c = Common->retrieve_customers_or_vendors(\%myconfig, $form, "name", 1, $is_vendor);
153
    restore_form($old_form);
154
    @covs = @{$c};
155
  }
156

  
157
  $form->header();
158
  print($form->parse_html_template("generic/select_customer_or_vendor",
159
                                   { "COVS" => \@covs,
160
                                     "old_form" => $old_form,
161
                                     "title" => $is_vendor ? $locale->text("Select a vendor") : $locale->text("Select a customer"),
162
                                     "nextsub" => "select_cov_internal",
163
                                     "callback_sub" => $callback_sub }));
164

  
165
  $lxdebug->leave_sub();
166
}
167

  
168
sub cov_selected {
169
  $lxdebug->enter_sub();
170
  my ($new_id, $new_name) = @_;
171

  
172
  my $field = $form->{"check_cov_field"};
173
  delete($form->{"check_cov_field"});
174

  
175
  $form->{"f_${field}_id"} = $new_id;
176
  $form->{"f_${field}"} = $new_name;
177
  $form->{"f_old_${field}"} = $new_name;
178

  
179
  &{ $form->{"cov_selected_nextsub"} }();
180

  
181
  $lxdebug->leave_sub();
182
}
183

  
184
sub select_cov_internal {
185
  $lxdebug->enter_sub();
186

  
187
  my ($new_id, $new_name, $callback_sub);
188

  
189
  my $new_id = $form->{"new_id_" . $form->{"selection"}};
190
  my $new_name = $form->{"new_name_" . $form->{"selection"}};
191
  my $callback_sub = $form->{"callback_sub"};
192

  
193
  restore_form($form->{"old_form"});
194

  
195
  &{ $callback_sub }($new_id, $new_name);
196

  
197
  $lxdebug->leave_sub();
198
}
199

  
83 200
sub select_part {
84 201
  $lxdebug->enter_sub();
85 202

  
......
588 705
  $lxdebug->leave_sub();
589 706
}
590 707

  
708
sub cov_selection_internal {
709
  $lxdebug->enter_sub();
710

  
711
  $order_by = "name";
712
  $order_by = $form->{"order_by"} if (defined($form->{"order_by"}));
713
  $order_dir = 1;
714
  $order_dir = $form->{"order_dir"} if (defined($form->{"order_dir"}));
715

  
716
  my $type = $form->{"is_vendor"} ? $locale->text("vendor") : $locale->text("customer");
717

  
718
  $covs = Common->retrieve_customers_or_vendors(\%myconfig, $form, $order_by, $order_dir, $form->{"is_vendor"}, $form->{"allow_both"});
719
  map({ $covs->[$_]->{"selected"} = $_ ? 0 : 1; } (0..$#{$covs}));
720
  if (0 == scalar(@{$covs})) {
721
    $form->show_generic_information(sprintf($locale->text("No %s was found matching the search parameters."), $type));
722
  } elsif (1 == scalar(@{$covs})) {
723
    $onload = "cov_selected('1')";
724
  }
725

  
726
  my $callback = "$form->{script}?action=cov_selection_internal&";
727
  map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
728
      (qw(login path password name input_name input_id is_vendor allow_both), grep({ /^[fl]_/ } keys %$form)));
729

  
730
  my @header_sort = qw(name address contact);
731
  my %header_title = ( "name" => $locale->text("Name"),
732
                       "address" => $locale->text("Address"),
733
                       "contact" => $locale->text("Contact"),
734
                       );
735

  
736
  my @header =
737
    map(+{ "column_title" => $header_title{$_},
738
           "column" => $_,
739
           "callback" => $callback . "order_by=${_}&order_dir=" . ($order_by eq $_ ? 1 - $order_dir : $order_dir),
740
         },
741
        @header_sort);
742

  
743
  foreach my $cov (@{ $covs }) {
744
    $cov->{address} = "$cov->{street}, $cov->{zipcode} $cov->{city}";
745
    $cov->{address} =~ s{^,}{}x;
746
    $cov->{address} =~ s{\ +}{\ }gx;
747

  
748
    $cov->{contact} = join " ", map { $cov->{$_} } qw(cp_greeting cp_title cp_givenname cp_name);
749
    $cov->{contact} =~ s{\ +}{\ }gx;
750
  }
751

  
752
  $form->{"title"} = $form->{is_vendor} ? $locale->text("Select a vendor") : $locale->text("Select a customer");
753
  $form->header();
754
  print($form->parse_html_template("generic/cov_selection", { "HEADER" => \@header,
755
                                                              "COVS" => $covs,
756
                                                              "onload" => $onload }));
757

  
758
  $lxdebug->leave_sub();
759
}
760

  
761
sub check_cov2 {
762
  $lxdebug->enter_sub();
763

  
764
  my $callback_sub = shift;
765

  
766
  if (!$form->{customer}
767
      || ($form->{customer} eq $form->{old_customer})
768
      || ("$form->{customer}--$form->{customer_id}" eq $form->{old_customer})) {
769
    $lxdebug->leave_sub();
770
    return;
771
  }
772

  
773
  $old_name     = $form->{name};
774
  $form->{name} = $form->{customer};
775

  
776
  my $covs = Common->retrieve_customers_or_vendors(\%myconfig, $form, "name", "ASC", 0, 1);
777

  
778
  $form->{name} = $old_name;
779

  
780
  if (0 == scalar @{$covs}) {
781
    $form->show_generic_information(sprintf($locale->text("No %s was found matching the search parameters."), $type));
782

  
783
  } elsif (1 == scalar @{ $covs }) {
784
    $form->{customer}           = $covs->[0]->{name};
785
    $form->{old_customer}       = $covs->[0]->{name};
786
    $form->{customer_id}        = $covs->[0]->{id};
787
    $form->{customer_is_vendor} = $covs->[0]->{customer_is_vendor};
788

  
789
  } else {
790
    $form->{new_cov_nextsub} = $callback_sub;
791

  
792
    delete @{$form}{qw(customer customer_is_vendor customer_id old_customer action)};
793
    my @hidden = map { { 'key' => $_, 'value' => $form->{$_} } } grep { '' eq ref $form->{$_} } keys %{ $form };
794

  
795
    foreach my $cov (@{ $covs }) {
796
      $cov->{address} = "$cov->{street}, $cov->{zipcode} $cov->{city}";
797
      $cov->{address} =~ s{^,}{}x;
798
      $cov->{address} =~ s{\ +}{\ }gx;
799

  
800
      $cov->{contact} = join " ", map { $cov->{$_} } qw(cp_greeting cp_title cp_givenname cp_name);
801
      $cov->{contact} =~ s{\ +}{\ }gx;
802
    }
803

  
804
    $form->{title} = $locale->text("Select a vendor or customer");
805
    $form->header();
806

  
807
    print $form->parse_html_template("generic/cov_selection2", { "COVS" => $covs, "HIDDEN" => \@hidden });
808

  
809
    exit 0;
810
  }
811

  
812
  $lxdebug->leave_sub();
813
}
814

  
815
sub cov_selected2 {
816
  $lxdebug->enter_sub();
817

  
818
  if (!$form->{new_cov} || !$form->{new_cov_nextsub}) {
819
    $form->error($locale->text('No customer has been selected.'));
820
  }
821

  
822
  map { $form->{$_} = $form->{"new_cov_${_}_$form->{new_cov}"} } qw(customer customer_id customer_is_vendor);
823
  $form->{old_customer} = $form->{customer};
824

  
825
  &{ $form->{new_cov_nextsub} }();
826

  
827
  $lxdebug->leave_sub();
828
}
829

  
830
sub select_item_selection_internal {
831
  $lxdebug->enter_sub();
832

  
833
  @items = SystemBrace->retrieve_select_items(\%myconfig, $form, $form->{"select_item_type"});
834
  if (0 == scalar(@items)) {
835
    $form->show_generic_information($locale->text("No item was found."));
836
  } elsif (1 == scalar(@items)) {
837
    $onload = "select_item_selected('1')";
838
  }
839

  
840
  $form->{"title"} = $locale->text("Select an entry");
841
  $form->header();
842
  print($form->parse_html_template("generic/select_item_selection", { "SELECT_ITEMS" => \@items,
843
                                                                      "onload" => $onload }));
844

  
845
  $lxdebug->leave_sub();
846
}
591 847
1;

Auch abrufbar als: Unified diff