PriceRule: Inline Report JS ausgelagert
authorSven Schöling <s.schoeling@linet-services.de>
Thu, 2 Apr 2015 13:29:15 +0000 (15:29 +0200)
committerSven Schöling <s.schoeling@linet-services.de>
Thu, 2 Apr 2015 13:29:15 +0000 (15:29 +0200)
Hatte sich mit dem SalesPriceInformation Javascript verheddert, welches
auch mal ausgelagert werden solle.

bin/mozilla/ic.pl
js/kivi.PriceRule.js
templates/webpages/ic/form_footer.html

index 0c1ab68..76f0869 100644 (file)
@@ -1633,7 +1633,8 @@ sub form_header {
   CVar->render_inputs('variables' => $form->{CUSTOM_VARIABLES}, show_disabled_message => 1, partsgroup_id => $partsgroup_id)
     if (scalar @{ $form->{CUSTOM_VARIABLES} });
 
-  $::request->layout->use_javascript("${_}.js") for qw(ckeditor/ckeditor ckeditor/adapters/jquery);
+  $::request->layout->use_javascript("${_}.js") for qw(ckeditor/ckeditor ckeditor/adapters/jquery kivi.PriceRule);
+  $::request->layout->add_javascripts_inline("\$(function(){kivi.PriceRule.load_price_rules_for_part(@{[ $::form->{id} * 1 ]})})") if $::form->{id};
   $form->header;
   #print $form->parse_html_template('ic/form_header', { ALL_PRICE_FACTORS => $form->{ALL_PRICE_FACTORS},
   #                                                     ALL_UNITS         => $form->{ALL_UNITS},
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);
   });
+
 });
index 977fafd..9e0cfa5 100644 (file)
 </form>
 
 <script type="text/javascript" src="js/wz_tooltip.js"></script>
-[%- IF id %]
-<script type='text/javascript'>
-  var 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,
-    });
-  };
-  var redirect_event = function(event, target){
-    event.preventDefault();
-    ns.inline_report(target, event.target + '', {});
-  };
-  $(function() {
-    window.setTimeout(function(){
-      inline_report('#price_rules_customer_report', 'controller.pl', { action: 'PriceRule/list', 'filter.item_type_matches[].part': [% id %], 'filter.type': 'customer', inline: 1 });
-      inline_report('#price_rules_vendor_report', 'controller.pl', { action: 'PriceRule/list', 'filter.item_type_matches[].part': [% id %], 'filter.type': 'vendor', inline: 1 });
-    }, 200);
-  });
-</script>
-[%- END %]