kivitendo-CSS: auskommentierten Inhalt entfernt
[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       printer_id:         $('#cpa_printer_id').val(),
49       copy_printer_id:    $('#cpa_copy_printer_id').val(),
50       transdate:          $('#transdate').val()
51     };
52
53     $(filter).each(function(index, obj){ data[obj.name] = obj.value; });
54
55     $.post('controller.pl', data, kivi.eval_json_result);
56   };
57
58   this.createPrintAllFinishProcess = function() {
59     $('#create_print_all_dialog').dialog('close');
60     window.location.href = 'controller.pl?action=MassInvoiceCreatePrint%2flist_invoices&noshow=1';
61   };
62
63   this.massConversionStarted = function() {
64     $('#create_print_all_dialog').data('timerId', setInterval(function() {
65       $.get("controller.pl", {
66         action: 'MassInvoiceCreatePrint/create_print_all_status',
67         job_id: $('#cpa_job_id').val()
68       }, kivi.eval_json_result);
69     }, 5000));
70   };
71
72   this.massConversionFinished = function() {
73     clearInterval($('#create_print_all_dialog').data('timerId'));
74     $('.ui-dialog-titlebar button.ui-dialog-titlebar-close').prop('disabled', '')
75   };
76
77   this.setup = function() {
78     $('#create_button').click(kivi.MassInvoiceCreatePrint.submitMassCreationForm);
79     $('#create_print_all_button').click(kivi.MassInvoiceCreatePrint.createPrintAllInitialize);
80     $('#action_print').click(kivi.MassInvoiceCreatePrint.checkInvoiceSelection);
81   };
82 });
83
84 $(kivi.MassInvoiceCreatePrint.setup);