PriceRule: Inline Report JS ausgelagert
[kivitendo-erp.git] / js / kivi.PriceRule.js
index 00ed4fb..d3c6a2a 100644 (file)
@@ -33,6 +33,29 @@ namespace('kivi.PriceRule', function(ns) {
     }
   }
 
+  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() {
       ns.add_new_row($('#price_rules_empty_item_select').val());
@@ -43,4 +66,5 @@ namespace('kivi.PriceRule', function(ns) {
     $('#price_rule_price_type_help').click(ns.open_price_type_help_popup);
     $('#price_rule_filter_type').change(ns.on_change_filter_type);
   });
+
 });