Locales
[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
16   this.checkInvoiceSelection = function() {
17     if ($("[data-checkall=1]:checked").size() > 0)
18       return true;
19     alert(kivi.t8('No invoices have been selected.'));
20     return false;
21   };
22
23   this.createPrintAllInitialize = function() {
24     kivi.popup_dialog({
25       id: 'create_print_all_dialog',
26       dialog: {
27         title: kivi.t8('Create and print all invoices')
28       }
29     });
30   };
31
32   this.createPrintAllStartProcess = function() {
33     $('#cpa_start_process_button,.ui-dialog-titlebar button.ui-dialog-titlebar-close').prop('disabled', 'disabled');
34     $('#cpa_start_process_abort_link').remove();
35
36     var filter = $('[name^=filter\\.]').serializeArray();
37     var data = {
38       action:             'MassInvoiceCreatePrint/create_print_all_start',
39       number_of_invoices: $('#cpa_number_of_invoices').val(),
40       bothsided:          $('#cpa_bothsided').val(),
41       printer_id:         $('#cpa_printer_id').val(),
42       copy_printer_id:    $('#cpa_copy_printer_id').val(),
43       transdate:          $('#transdate').val()
44     };
45
46     $(filter).each(function(index, obj){ data[obj.name] = obj.value; });
47
48     $.post('controller.pl', data, kivi.eval_json_result);
49   };
50
51   this.createPrintAllFinishProcess = function() {
52     $('#create_print_all_dialog').dialog('close');
53     window.location.href = 'controller.pl?action=MassInvoiceCreatePrint%2flist_invoices&noshow=1';
54   };
55
56   this.massConversionStarted = function() {
57     $('#create_print_all_dialog').data('timerId', setInterval(function() {
58       $.get("controller.pl", {
59         action: 'MassInvoiceCreatePrint/create_print_all_status',
60         job_id: $('#cpa_job_id').val()
61       }, kivi.eval_json_result);
62     }, 5000));
63   };
64
65   this.massConversionFinished = function() {
66     clearInterval($('#create_print_all_dialog').data('timerId'));
67     $('.ui-dialog-titlebar button.ui-dialog-titlebar-close').prop('disabled', '')
68   };
69
70   ns.showMassPrintOptions = function() {
71     $('#printer_options_printer_id').val($('#printer_id').val());
72
73     kivi.popup_dialog({
74       id: 'print_options',
75       dialog: {
76         title: kivi.t8('Print options'),
77         width:  600,
78         height: 200
79       }
80     });
81
82     return true;
83   };
84
85   ns.showMassPrintOptionsOrDownloadDirectly = function() {
86     if (!kivi.MassInvoiceCreatePrint.checkInvoiceSelection())
87       return false;
88
89     if ($('#print_options_printer_id').length === 0)
90       return kivi.MassInvoiceCreatePrint.massPrint();
91     return kivi.MassInvoiceCreatePrint.showMassPrintOptions();
92   };
93
94   ns.massPrint = function() {
95     $('#print_options').dialog('close');
96
97     $('#printer_id').val($('#print_options_printer_id').val());
98     $('#bothsided').val($('#print_options_bothsided').prop('checked') ? 1 : 0);
99     $('#action').val('MassInvoiceCreatePrint/print');
100
101     $('#report_form').submit();
102
103     return true;
104   };
105
106   this.resetSearchForm = function() {
107     $("#filter_table input").val("");
108   };
109 });