"alle" E-Mail-Adressen per Anhaken als Empfänger hinzufügen können
[kivitendo-erp.git] / js / kivi.PriceRule.js
index 736f3f2..aba5987 100644 (file)
@@ -1,4 +1,5 @@
 namespace('kivi.PriceRule', function(ns) {
+  "use strict";
 
   ns.add_new_row = function (type) {
     var data = {
@@ -6,7 +7,55 @@ namespace('kivi.PriceRule', function(ns) {
       type: type
     };
     $.post('controller.pl', data, kivi.eval_json_result);
-  }
+  };
+
+  ns.open_price_type_help_popup = function() {
+    kivi.popup_dialog({
+      url:    'controller.pl?action=PriceRule/price_type_help',
+      dialog: { title: kivi.t8('Price Types') },
+    });
+  };
+
+  ns.on_change_filter_type = function() {
+    var val = $('#price_rule_filter_type').val();
+    if (val == 'vendor') {
+      $('#price_rule_filter_customer').data('customer_vendor_picker').set_item({});
+      $('#price_rule_filter_customer_tr').hide();
+      $('#price_rule_filter_vendor_tr').show();
+    }
+    if (val == 'customer') {
+      $('#price_rule_filter_vendor').data('customer_vendor_picker').set_item({});
+      $('#price_rule_filter_vendor_tr').hide();
+      $('#price_rule_filter_customer_tr').show();
+    }
+    if (val === '') {
+      $('#price_rule_filter_customer_tr').show();
+      $('#price_rule_filter_vendor_tr').show();
+    }
+  };
+
+  ns.inline_report = function(target, source, data){
+    $.ajax({
+      url:        source,
+      success:    function (rsp) {
+        $(target).html(rsp);
+        $(target).find('.paginate').find('a').click(function(event){ ns.redirect_event(event, target) });
+        $(target).find('a.report-generator-header-link').click(function(event){ ns.redirect_event(event, target) });
+      },
+      data:       data,
+    });
+  };
+  ns.redirect_event = function(event, target){
+    event.preventDefault();
+    ns.inline_report(target, event.target + '', {});
+  };
+
+  ns.load_price_rules_for_part = function(id) {
+    window.setTimeout(function(){
+      ns.inline_report('#price_rules_customer_report', 'controller.pl', { action: 'PriceRule/list', 'filter.item_type_matches[].part': id, 'filter.type': 'customer', inline: 1 });
+      ns.inline_report('#price_rules_vendor_report', 'controller.pl', { action: 'PriceRule/list', 'filter.item_type_matches[].part': id, 'filter.type': 'vendor', inline: 1 });
+    }, 200);
+  };
 
   $(function() {
     $('#price_rule_item_add').click(function() {
@@ -15,5 +64,8 @@ namespace('kivi.PriceRule', function(ns) {
     $('#price_rule_items').on('click', 'a.price_rule_remove_line', function(){
       $(this).closest('div').remove();
     })
+    $('#price_rule_price_type_help').click(ns.open_price_type_help_popup);
+    $('#price_rule_filter_type').change(ns.on_change_filter_type);
   });
+
 });