Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 94b66849

Von Sven Schöling vor fast 18 Jahren hinzugefügt

  • ID 94b6684903ced3d8b112830780ecde323795315f
  • Vorgänger 0965925a
  • Nachfolger 71196b75

io.pl print_options auf templateing umgeschireben.

Soweit ich weiss ist das eine der ersten frontend Funktionen aus SQL Ledger die auf templating umgeschrieben wurde.
Funktionalitaet wurde eins zu eins erhalten, die einzige gewollte Aenderung betrifft die Moeglichkeit
nicht direkt auf den Bildschirm auszugeben sondern die Optionen in einer Variable zurueckzugeben.

Ansonsten kleinere Aenderungen bedingt durch Programmierstil und Beschraenkungen von HTML::Template:
- der Check ob einige Selects angezeigt werden funktioniert jetzt ueber einen Referenzcheck,
da languages und printers aus irgendeinem Grund als hashref initialisiert werden und dann als array gespeichert werden
- die Auswahl zwischen form und myconfigvariablen funktioniert leicht anders und wird vermutlich noch geaendert werden.

Unterschiede anzeigen:

bin/mozilla/io.pl
1474 1474
  $lxdebug->leave_sub();
1475 1475
}
1476 1476

  
1477
# generate the printing options displayed at the bottom of oe and is forms.
1478
# this function will attempt to guess what type of form is displayed, and will generate according options
1479
#
1480
# about the coding: 
1481
# this version builds the arrays of options pretty directly. if you have trouble understanding how,
1482
# the opthash function builds hashrefs which are then pieced together for the template arrays.
1483
# unneeded options are "undef"ed out, and then grepped out. 
1484
#
1485
# the inline options is untested, but intended to be used later in metatemplating
1477 1486
sub print_options {
1478
  $lxdebug->enter_sub();
1479
  $form->{sendmode} = "attachment";
1487
  $lxdebug->enter_sub() and my ($inline) = @_;
1480 1488

  
1481
  $form->{"format"} =
1482
    $form->{"format"} ? $form->{"format"} :
1483
    $myconfig{"template_format"} ? $myconfig{"template_format"} :
1484
    "pdf";
1489
  # names 3 parameters and returns a hashref, for use in templates
1490
  sub opthash { +{ value => shift, selected => shift, oname => shift } }
1485 1491

  
1486
  $form->{"copies"} =
1487
    $form->{"copies"} ? $form->{"copies"} :
1488
    $myconfig{"copies"} ? $myconfig{"copies"} :
1489
    3;
1490

  
1491
  $form->{"media"} =
1492
    $form->{"media"} ? $form->{"media"} :
1493
    $myconfig{"default_media"} ? $myconfig{"default_media"} :
1494
    "screen";
1495

  
1496
  $form->{"printer_id"} =
1497
    defined($form->{"printer_id"}) ? $form->{"printer_id"} :
1498
    $myconfig{"default_printer_id"} ? $myconfig{"default_printer_id"} :
1499
    "";
1492
  # note: "||"-selection is only correct for values where "0" is _not_ a correct entry
1493
  $form->{sendmode}   = "attachment";
1494
  $form->{format}     = $form->{format} || $myconfig{template_format} || "pdf";
1495
  $form->{copies}     = $form->{copies} || $myconfig{copies} || 3;
1496
  $form->{media}      = $form->{media} || $myconfig{default_media} || "screen";
1497
  $form->{printer_id} = $form->{printer_id} || $myconfig{default_printer_id} || "";
1500 1498

  
1501 1499
  $form->{PD}{ $form->{formname} } = "selected";
1502 1500
  $form->{DF}{ $form->{format} }   = "selected";
1503 1501
  $form->{OP}{ $form->{media} }    = "selected";
1504
  $form->{SM}{ $form->{sendmode} } = "selected";
1505

  
1506
  if ($form->{type} eq 'purchase_order') {
1507
    $type = qq|<select name=formname>
1508
	    <option value=purchase_order $form->{PD}{purchase_order}>|
1509
      . $locale->text('Purchase Order') . qq|
1510
	    <option value=bin_list $form->{PD}{bin_list}>|
1511
      . $locale->text('Bin List');
1512
  }
1513

  
1514
  if ($form->{type} eq 'credit_note') {
1515
    $type = qq|<select name=formname>
1516
	    <option value=credit_note $form->{PD}{credit_note}>|
1517
      . $locale->text('Credit Note');
1518
  }
1519

  
1520
  if ($form->{type} eq 'sales_order') {
1521
    $type = qq|<select name=formname>
1522
	    <option value=sales_order $form->{PD}{sales_order}>|
1523
      . $locale->text('Confirmation') . qq|
1524
      <option value=proforma $form->{PD}{proforma}>|
1525
      . $locale->text('Proforma Invoice') . qq|
1526
	    <option value=pick_list $form->{PD}{pick_list}>|
1527
      . $locale->text('Pick List') . qq|
1528
	    <option value=packing_list $form->{PD}{packing_list}>|
1529
      . $locale->text('Packing List');
1530
  }
1531

  
1532
  if ($form->{type} =~ /_quotation$/) {
1533
    $type = qq|<select name=formname>
1534
	    <option value="$`_quotation" $form->{PD}{"$`_quotation"}>|
1535
      . $locale->text('Quotation');
1536
  }
1537

  
1538
  if ($form->{type} eq 'invoice') {
1539
    $type = qq|<select name=formname>
1540
	    <option value=invoice $form->{PD}{invoice}>|
1541
      . $locale->text('Invoice') . qq|
1542
      <option value=proforma $form->{PD}{proforma}>|
1543
      . $locale->text('Proforma Invoice') . qq|
1544
      <option value=packing_list $form->{PD}{packing_list}>|
1545
      . $locale->text('Packing List');
1546
  }
1502
  $form->{SM}{ $form->{formname} } = "selected";
1503

  
1504
  push @FORMNAME, grep $_,
1505
    ($form->{type} eq 'purchase_order') ? (
1506
      opthash("purchase_order", $form->{PD}{purchase_order}, $locale->text('Purchase Order')),
1507
      opthash("bin_list", $form->{PD}{bin_list}, $locale->text('Bin List')) 
1508
    ) : undef,
1509
    ($form->{type} eq 'credit_note') ?
1510
      opthash("credit_note", $form->{PD}{credit_note}, $locale->text('Credit Note')) : undef,
1511
    ($form->{type} eq 'sales_order') ? (
1512
      opthash("sales_order", $form->{PD}{sales_order}, $locale->text('Confirmation')),
1513
      opthash("proforma", $form->{PD}{proforma}, $locale->text('Proforma Invoice')),
1514
      opthash("pick_list", $form->{PD}{pick_list}, $locale->text('Pick List')),
1515
      opthash("packing_list", $form->{PD}{packing_list}, $locale->text('Packing List')) 
1516
    ) : undef,
1517
    ($form->{type} =~ /_quotation$/) ?
1518
      opthash("$`_quotation", $form->{PD}{"$`_quotation"}, $locale->text('Quotation')) : undef,
1519
    ($form->{type} eq 'invoice') ? (
1520
      opthash("invoice", $form->{PD}{invoice}, $locale->text('Invoice')),
1521
      opthash("proforma", $form->{PD}{proforma}, $locale->text('Proforma Invoice')),
1522
      opthash("packing_list", $form->{PD}{packing_list}, $locale->text('Packing List'))
1523
    ) : undef,
1524
    ($form->{type} eq 'invoice' && $form->{storno}) ? (
1525
      opthash("storno_invoice", $form->{PD}{storno_invoice}, $locale->text('Storno Invoice')),
1526
      opthash("storno_packing_list", $form->{PD}{storno_packing_list}, $locale->text('Storno Packing List')) 
1527
    ) : undef,
1528
    ($form->{type} eq 'credit_note') ?
1529
      opthash("credit_note", $form->{PD}{credit_note}, $locale->text('Credit Note')) : undef;
1530

  
1531
  push @SENDMODE, 
1532
    opthash("attachment", $form->{SM}{attachment}, $locale->text('Attachment')),
1533
    opthash("inline", $form->{SM}{inline}, $locale->text('In-line'))
1534
      if ($form->{media} eq 'email');
1535

  
1536
  push @MEDIA, grep $_,
1537
      opthash("screen", $form->{OP}{screen}, $locale->text('Screen')),
1538
    (scalar keys %{ $form->{printers} } && $latex_templates) ?
1539
      opthash("printer", $form->{OP}{printer}, $locale->text('Printer')) : undef,
1540
    ($latex_templates) ? 
1541
      opthash("queue", $form->{OP}{queue}, $locale->text('Queue')) : undef
1542
        if ($form->{media} ne 'email');
1543

  
1544
  push @FORMAT, grep $_,
1545
    ($opendocument_templates && $openofficeorg_writer_bin && $xvfb_bin && (-x $openofficeorg_writer_bin) && (-x $xvfb_bin)) ?
1546
      opthash("opendocument_pdf", $form->{DF}{"opendocument_pdf"}, $locale->text("PDF (OpenDocument/OASIS)")) : undef,
1547
    ($latex_templates) ? (
1548
      opthash("pdf", $form->{DF}{pdf}, $locale->text('PDF')),
1549
      opthash("postscript", $form->{DF}{postscript}, $locale->text('Postscript'))
1550
    ) : undef,
1551
      opthash("html", $form->{DF}{html}, "HTML"),
1552
    ($opendocument_templates) ?
1553
      opthash("opendocument", $form->{DF}{opendocument}, $locale->text("OpenDocument/OASIS")) : undef;
1554

  
1555
  push @LANGUAGE_ID, 
1556
    map { opthash($_->{id}, ($_->{id} eq $form->{language} ? 'selected' : ''), $_->{description}) } +{}, @{ $form->{languages} }
1557
      if (ref $form->{languages} eq 'ARRAY');
1558

  
1559
  push @PRINTER_ID, 
1560
    map { opthash($_->{id}, ($_->{id} eq $form->{printer_id} ? 'selected' : ''), $_->{description}) } +{}, @{ $form->{printers} }
1561
      if (ref $form->{printers} eq 'ARRAY');
1562

  
1563
  @SELECTS = map { sname => lc $_, DATA => \@$_, show => scalar @$_ }, qw(FORMNAME LANGUAGE_ID FORMAT SENDMODE MEDIA PRINTER_ID);
1564

  
1565
  %template_vars = (
1566
    display_copies       => scalar keys %{ $form->{printers} } && $latex_templates && $form->{media} ne 'email',
1567
    display_remove_draft => (!$form->{id} && $form->{draft_id}),
1568
    groupitems_checked   => $form->{groupitems} ? "checked" : '',
1569
    remove_draft_checked => $form->{remove_draft} ? "checked" : ''
1570
  );
1547 1571

  
1548
  if ($form->{type} eq 'invoice' && $form->{storno}) {
1549
    $type = qq|<select name=formname>
1550
	    <option value=storno_invoice $form->{PD}{storno_invoice}>|
1551
      . $locale->text('Storno Invoice') . qq|
1552
      <option value=storno_packing_list $form->{PD}{storno_packing_list}>|
1553
      . $locale->text('Storno Packing List');
1554
  }
1572
  my $print_options = $form->parse_html_template("generic/print_options", { SELECTS  => \@SELECTS, %template_vars } );
1555 1573

  
1556
  if ($form->{type} eq 'credit_note') {
1557
    $type = qq|<select name=formname>
1558
	    <option value=credit_note $form->{PD}{credit_note}>|
1559
      . $locale->text('Credit Note');
1560
  }
1561

  
1562
  if ($form->{media} eq 'email') {
1563
    $media = qq|<select name=sendmode>
1564
	    <option value=attachment $form->{SM}{attachment}>|
1565
      . $locale->text('Attachment') . qq|
1566
	    <option value=inline $form->{SM}{inline}>| . $locale->text('In-line');
1574
  if ($inline) {
1575
    $lxdebug->leave_sub() and return $print_options;
1567 1576
  } else {
1568
    $media = qq|<select name=media>
1569
	    <option value=screen $form->{OP}{screen}>| . $locale->text('Screen');
1570
    if (scalar(keys (%{ $form->{printers} })) !=0 && $latex_templates) {
1571
      $media .= qq|
1572
            <option value=printer $form->{OP}{printer}>|
1573
        . $locale->text('Printer');
1574
    }
1575
    if ($latex_templates) {
1576
      $media .= qq|
1577
            <option value=queue $form->{OP}{queue}>| . $locale->text('Queue');
1578
    }
1579
  }
1580

  
1581
  $format = qq|<select name=format>|;
1582
  if ($opendocument_templates && $openofficeorg_writer_bin &&
1583
      $xvfb_bin && (-x $openofficeorg_writer_bin) && (-x $xvfb_bin)) {
1584
    $format .= qq|<option value=opendocument_pdf | .
1585
      $form->{DF}{"opendocument_pdf"} . qq|>| .
1586
      $locale->text("PDF (OpenDocument/OASIS)") . qq|</option>|;
1587
  }
1588

  
1589
  if ($latex_templates) {
1590
    $format .= qq|<option value=pdf $form->{DF}{pdf}>| .
1591
      $locale->text('PDF') . qq|</option>|;
1592
  }
1593

  
1594
  $format .= qq|<option value=html $form->{DF}{html}>HTML</option>|;
1595

  
1596
  if ($latex_templates) {
1597
    $format .= qq|<option value=postscript $form->{DF}{postscript}>| .
1598
      $locale->text('Postscript') . qq|</option>|;
1577
    print $print_options; $lxdebug->leave_sub();
1599 1578
  }
1600

  
1601
  if ($opendocument_templates) {
1602
    $format .= qq|<option value=opendocument $form->{DF}{opendocument}>| .
1603
      $locale->text("OpenDocument/OASIS") . qq|</option>|;
1604
  }
1605
  $format .= qq|</select>|;
1606

  
1607
  if (scalar(keys (%{ $form->{languages} })) !=0) {
1608
    $language_select = qq|<select name=language_id>
1609
		<option value=""></option>}|;
1610
    foreach $item (@{ $form->{languages} }) {
1611
      if ($form->{language_id} eq $item->{id}) {
1612
        $language_select .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
1613
      } else {
1614
        $language_select .= qq|<option value="$item->{id}">$item->{description}</option>|;
1615
      }
1616
    }
1617
  }
1618

  
1619
  if (scalar(keys (%{ $form->{printers} })) !=0) {
1620
    my $selected = !$form->{"printer_id"} ? "selected" : "";
1621
    $printer_select = qq|<select name=printer_id $selected>
1622
                  <option value=""></option>|;
1623
    foreach $item (@{ $form->{printers} }) {
1624
      $selected = $item->{"id"} == $form->{"printer_id"} ? "selected" : "";
1625
      $printer_select .= qq|<option value="$item->{id}" $selected>$item->{printer_description}</option>|;
1626
    }
1627
  }
1628

  
1629

  
1630

  
1631
  print qq|
1632
<table width=100% cellspacing=0 cellpadding=0>
1633
  <tr>
1634
    <td>
1635
      <table>
1636
	<tr>
1637
	  <td>$type</select></td>|;
1638
  if (scalar(keys (%{ $form->{languages} })) !=0) {
1639
  print qq|
1640
          <td>${language_select}</select></td>|;
1641
  }
1642
  print qq|
1643
	  <td>$format</select></td>
1644
	  <td>$media</select></td>|;
1645
  if (scalar(keys (%{ $form->{printers} })) !=0) {
1646
  print qq|
1647
	  <td>$printer_select</select></td>
1648
|;
1649
  }
1650

  
1651
  if (scalar(keys (%{ $form->{printers} })) !=0 && $latex_templates && $form->{media} ne 'email') {
1652
    print qq|
1653
	  <td>| . $locale->text('Copies') . qq|
1654
	  <input name=copies size=2 value=$form->{copies}></td>
1655
|;
1656
  }
1657

  
1658
  $form->{groupitems} = "checked" if $form->{groupitems};
1659
  $form->{remove_draft} = "checked" if $form->{remove_draft};
1660

  
1661
  print qq|
1662
          <td>| . $locale->text('Group Items') . qq|</td>
1663
          <td><input name=groupitems type=checkbox class=checkbox $form->{groupitems}></td>|;
1664

  
1665
  print qq|
1666
          <td>| . $locale->text('Remove Draft') . qq|</td>
1667
          <td><input name=remove_draft type=checkbox class=checkbox $form->{remove_draft}></td>| if (!$form->{id} && $form->{draft_id});
1668
  print qq|
1669
        </tr>
1670
      </table>
1671
    </td>
1672
    <td align=right>
1673
      <table>
1674
        <tr>
1675
|;
1676

  
1677
  if ($form->{printed} =~ /$form->{formname}/) {
1678
    print qq|
1679
	  <th>\|| . $locale->text('Printed') . qq|\|</th>
1680
|;
1681
  }
1682

  
1683
  if ($form->{emailed} =~ /$form->{formname}/) {
1684
    print qq|
1685
	  <th>\|| . $locale->text('E-mailed') . qq|\|</th>
1686
|;
1687
  }
1688

  
1689
  if ($form->{queued} =~ /$form->{formname}/) {
1690
    print qq|
1691
	  <th>\|| . $locale->text('Queued') . qq|\|</th>
1692
|;
1693
  }
1694

  
1695
  print qq|
1696
        </tr>
1697
      </table>
1698
    </td>
1699
  </tr>
1700
</table>
1701
|;
1702

  
1703
  $lxdebug->leave_sub();
1704 1579
}
1705 1580

  
1706 1581
sub print {

Auch abrufbar als: Unified diff