E-Mail-Versand: CC: nur kivi-Benutzer mit hinterlegter E-Mail-Adresse anzeigen
[kivitendo-erp.git] / js / kivi.PriceRule.js
1 namespace('kivi.PriceRule', function(ns) {
2   "use strict";
3
4   ns.add_new_row = function (type) {
5     var data = {
6       action: 'PriceRule/add_item_row',
7       type: type
8     };
9     $.post('controller.pl', data, kivi.eval_json_result);
10   };
11
12   ns.open_price_type_help_popup = function() {
13     kivi.popup_dialog({
14       url:    'controller.pl?action=PriceRule/price_type_help',
15       dialog: { title: kivi.t8('Price Types') },
16     });
17   };
18
19   ns.on_change_filter_type = function() {
20     var val = $('#price_rule_filter_type').val();
21     if (val == 'vendor') {
22       $('#price_rule_filter_customer').data('customer_vendor_picker').set_item({});
23       $('#price_rule_filter_customer_tr').hide();
24       $('#price_rule_filter_vendor_tr').show();
25     }
26     if (val == 'customer') {
27       $('#price_rule_filter_vendor').data('customer_vendor_picker').set_item({});
28       $('#price_rule_filter_vendor_tr').hide();
29       $('#price_rule_filter_customer_tr').show();
30     }
31     if (val === '') {
32       $('#price_rule_filter_customer_tr').show();
33       $('#price_rule_filter_vendor_tr').show();
34     }
35   };
36
37   ns.inline_report = function(target, source, data){
38     $.ajax({
39       url:        source,
40       success:    function (rsp) {
41         $(target).html(rsp);
42         $(target).find('.paginate').find('a').click(function(event){ ns.redirect_event(event, target) });
43         $(target).find('a.report-generator-header-link').click(function(event){ ns.redirect_event(event, target) });
44       },
45       data:       data,
46     });
47   };
48   ns.redirect_event = function(event, target){
49     event.preventDefault();
50     ns.inline_report(target, event.target + '', {});
51   };
52
53   ns.load_price_rules_for_part = function(id) {
54     window.setTimeout(function(){
55       ns.inline_report('#price_rules_customer_report', 'controller.pl', { action: 'PriceRule/list', 'filter.item_type_matches[].part': id, 'filter.type': 'customer', inline: 1 });
56       ns.inline_report('#price_rules_vendor_report', 'controller.pl', { action: 'PriceRule/list', 'filter.item_type_matches[].part': id, 'filter.type': 'vendor', inline: 1 });
57     }, 200);
58   };
59
60   $(function() {
61     $('#price_rule_item_add').click(function() {
62       ns.add_new_row($('#price_rules_empty_item_select').val());
63     });
64     $('#price_rule_items').on('click', 'a.price_rule_remove_line', function(){
65       $(this).closest('div').remove();
66     })
67     $('#price_rule_price_type_help').click(ns.open_price_type_help_popup);
68     $('#price_rule_filter_type').change(ns.on_change_filter_type);
69   });
70
71 });