BUGFIX: PDF:Table verwendet font_color in Folgezeile
[kivitendo-erp.git] / js / kivi.MassInvoiceCreatePrint.js
1 namespace('kivi.MassInvoiceCreatePrint', function(ns) {
2   this.checkSalesOrderSelection = function() {
3     if ($("[data-checkall=1]:checked").size() > 0)
4       return true;
5     alert(kivi.t8('No delivery orders have been selected.'));
6     return false;
7   };
8
9   this.checkDeliveryOrderSelection = function() {
10     if ($("[data-checkall=1]:checked").size() > 0)
11       return true;
12     alert(kivi.t8('No delivery orders have been selected.'));
13     return false;
14   };
15   this.checkInvoiceSelection = function() {
16     if ($("[data-checkall=1]:checked").size() > 0)
17       return true;
18     alert(kivi.t8('No invoices have been selected.'));
19     return false;
20   };
21
22   this.submitMassCreationForm = function() {
23     if (!kivi.MassInvoiceCreatePrint.checkDeliveryOrderSelection())
24       return false;
25
26     $('body').addClass('loading');
27     $('form').submit();
28     return false;
29   };
30
31   this.createPrintAllInitialize = function() {
32     kivi.popup_dialog({
33       id: 'create_print_all_dialog',
34       dialog: {
35         title: kivi.t8('Create and print all invoices')
36       }
37     });
38   };
39
40   this.createPrintAllStartProcess = function() {
41     $('#cpa_start_process_button,.ui-dialog-titlebar button.ui-dialog-titlebar-close').prop('disabled', 'disabled');
42     $('#cpa_start_process_abort_link').remove();
43
44     var filter = $('[name^=filter\\.]').serializeArray();
45     var data = {
46       action:             'MassInvoiceCreatePrint/create_print_all_start',
47       number_of_invoices: $('#cpa_number_of_invoices').val(),
48       bothsided:          $('#cpa_bothsided').val(),
49       printer_id:         $('#cpa_printer_id').val(),
50       copy_printer_id:    $('#cpa_copy_printer_id').val(),
51       transdate:          $('#transdate').val()
52     };
53
54     $(filter).each(function(index, obj){ data[obj.name] = obj.value; });
55
56     $.post('controller.pl', data, kivi.eval_json_result);
57   };
58
59   this.createPrintAllFinishProcess = function() {
60     $('#create_print_all_dialog').dialog('close');
61     window.location.href = 'controller.pl?action=MassInvoiceCreatePrint%2flist_invoices&noshow=1';
62   };
63
64   this.massConversionStarted = function() {
65     $('#create_print_all_dialog').data('timerId', setInterval(function() {
66       $.get("controller.pl", {
67         action: 'MassInvoiceCreatePrint/create_print_all_status',
68         job_id: $('#cpa_job_id').val()
69       }, kivi.eval_json_result);
70     }, 5000));
71   };
72
73   this.massConversionFinished = function() {
74     clearInterval($('#create_print_all_dialog').data('timerId'));
75     $('.ui-dialog-titlebar button.ui-dialog-titlebar-close').prop('disabled', '')
76   };
77
78   this.setup = function() {
79     $('#create_button').click(kivi.MassInvoiceCreatePrint.submitMassCreationForm);
80     $('#create_print_all_button').click(kivi.MassInvoiceCreatePrint.createPrintAllInitialize);
81     $('#action_print').click(kivi.MassInvoiceCreatePrint.checkInvoiceSelection);
82   };
83 });
84
85 $(kivi.MassInvoiceCreatePrint.setup);