1 namespace('kivi.PriceRule', function(ns) {
4 ns.add_new_row = function (type) {
6 action: 'PriceRule/add_item_row',
9 $.post('controller.pl', data, kivi.eval_json_result);
12 ns.open_price_type_help_popup = function() {
14 url: 'controller.pl?action=PriceRule/price_type_help',
15 dialog: { title: kivi.t8('Price Types') },
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();
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();
32 $('#price_rule_filter_customer_tr').show();
33 $('#price_rule_filter_vendor_tr').show();
37 ns.inline_report = function(target, source, data){
40 success: function (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) });
48 ns.redirect_event = function(event, target){
49 event.preventDefault();
50 ns.inline_report(target, event.target + '', {});
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 });
61 $('#price_rule_item_add').click(function() {
62 ns.add_new_row($('#price_rules_empty_item_select').val());
64 $('#price_rule_items').on('click', 'a.price_rule_remove_line', function(){
65 $(this).closest('div').remove();
67 $('#price_rule_price_type_help').click(ns.open_price_type_help_popup);
68 $('#price_rule_filter_type').change(ns.on_change_filter_type);