Auftrags-Controller: Mini-Refactoring: js-save-Funktionen zusammengefasst
authorBernd Bleßmann <bernd@kivitendo-premium.de>
Thu, 22 Feb 2018 15:15:59 +0000 (16:15 +0100)
committerBernd Bleßmann <bernd@kivitendo-premium.de>
Thu, 22 Feb 2018 15:15:59 +0000 (16:15 +0100)
SL/Controller/Order.pm
js/kivi.Order.js

index c081e42..8ee73f9 100644 (file)
@@ -1395,24 +1395,24 @@ sub _setup_edit_action_bar {
       combobox => [
         action => [
           t8('Save'),
-          call      => [ 'kivi.Order.save', $::instance_conf->get_order_warn_duplicate_parts ],
+          call      => [ 'kivi.Order.save', 'save', $::instance_conf->get_order_warn_duplicate_parts ],
           checks    => [ 'kivi.Order.check_save_active_periodic_invoices' ],
         ],
         action => [
           t8('Save as new'),
-          call      => [ 'kivi.Order.save_as_new', $::instance_conf->get_order_warn_duplicate_parts ],
+          call      => [ 'kivi.Order.save', 'save_as_new', $::instance_conf->get_order_warn_duplicate_parts ],
           checks    => [ 'kivi.Order.check_save_active_periodic_invoices' ],
           disabled  => !$self->order->id ? t8('This object has not been saved yet.') : undef,
         ],
         action => [
           t8('Save and Delivery Order'),
-          call      => [ 'kivi.Order.save_and_delivery_order', $::instance_conf->get_order_warn_duplicate_parts ],
+          call      => [ 'kivi.Order.save', 'save_and_delivery_order', $::instance_conf->get_order_warn_duplicate_parts ],
           checks    => [ 'kivi.Order.check_save_active_periodic_invoices' ],
           only_if   => (any { $self->type eq $_ } (_sales_order_type(), _purchase_order_type()))
         ],
         action => [
           t8('Save and Invoice'),
-          call      => [ 'kivi.Order.save_and_invoice', $::instance_conf->get_order_warn_duplicate_parts ],
+          call      => [ 'kivi.Order.save', 'save_and_invoice', $::instance_conf->get_order_warn_duplicate_parts ],
           checks    => [ 'kivi.Order.check_save_active_periodic_invoices' ],
         ],
       ], # end of combobox "Save"
index fc7bb23..1a5924c 100644 (file)
@@ -35,42 +35,12 @@ namespace('kivi.Order', function(ns) {
     return true;
   };
 
-  ns.save = function(warn_on_duplicates) {
+  ns.save = function(action, warn_on_duplicates) {
     if (!ns.check_cv()) return;
     if (warn_on_duplicates && !ns.check_save_duplicate_parts()) return;
 
     var data = $('#order_form').serializeArray();
-    data.push({ name: 'action', value: 'Order/save' });
-
-    $.post("controller.pl", data, kivi.eval_json_result);
-  };
-
-  ns.save_as_new = function(warn_on_duplicates) {
-    if (!ns.check_cv()) return;
-    if (warn_on_duplicates && !ns.check_save_duplicate_parts()) return;
-
-    var data = $('#order_form').serializeArray();
-    data.push({ name: 'action', value: 'Order/save_as_new' });
-
-    $.post("controller.pl", data, kivi.eval_json_result);
-  };
-
-  ns.save_and_delivery_order = function(warn_on_duplicates) {
-    if (!ns.check_cv()) return;
-    if (warn_on_duplicates && !ns.check_save_duplicate_parts()) return;
-
-    var data = $('#order_form').serializeArray();
-    data.push({ name: 'action', value: 'Order/save_and_delivery_order' });
-
-    $.post("controller.pl", data, kivi.eval_json_result);
-  };
-
-  ns.save_and_invoice = function(warn_on_duplicates) {
-    if (!ns.check_cv()) return;
-    if (warn_on_duplicates && !ns.check_save_duplicate_parts()) return;
-
-    var data = $('#order_form').serializeArray();
-    data.push({ name: 'action', value: 'Order/save_and_invoice' });
+    data.push({ name: 'action', value: 'Order/' + action });
 
     $.post("controller.pl", data, kivi.eval_json_result);
   };