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