<commit_before>/**
 * FoodCoopShop - The open source software for your foodcoop
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @since         FoodCoopShop 3.1.0
 * @license       https://opensource.org/licenses/mit-license.php MIT License
 * @author        <NAME> <<EMAIL>>
 * @copyright     Copyright (c) <NAME>, https://www.rothauer-it.com
 * @link          https://www.foodcoopshop.com
 */
foodcoopshop.ModalProductCalculateSellingPriceWithSurcharge = {

    init : function() {

        var modalSelector = '#modal-product-calculate-selling-price-with-surcharge';

        var button = $('#calculateSellingPriceWithSurchargForSelectedProducts');
        foodcoopshop.Helper.disableButton(button);

        $('table.list').find('input.row-marker[type="checkbox"]').on('click', function () {
            foodcoopshop.Admin.updateObjectSelectionActionButton(button);
        });

        button.on('click', function () {

            var productIds = foodcoopshop.Admin.getSelectedProductIds();
            var title = 'Verkaufspreis berechnen';
            //var title = productIds.length == 1 ? foodcoopshop.LocalizedJs.admin.Product : foodcoopshop.LocalizedJs.admin.Products;

            var products = [];
            for (var i in productIds) {
                products.push($('tr#product-' + productIds[i] + ' span.product-name').html());
            }
            var html = '<ul><li>' + products.join('</li><li>') + '</li></ul>';

            html += '<label for="dialogProductSurcharge">Aufschlag: </label><br />';
            html += '<input type="number" step="0.01" min="0.01" name="dialogProductSurcharge" id="dialogProductSurcharge" value="" />';
            html += ' % vom Netto-Einkaufspreis';

            foodcoopshop.Modal.appendModalToDom(
                modalSelector,
                title,
                html
            );

            foodcoopshop.Modal.bindSuccessButton(modalSelector, function() {
                foodcoopshop.ModalProductCalculateSellingPriceWithSurcharge.getSuccessHandler(modalSelector, productIds);
            });

            $(modalSelector).on('hidden.bs.modal', function (e) {
                foodcoopshop.ModalProductCalculateSellingPriceWithSurcharge.getCloseHandler(modalSelector);
            });
            foodcoopshop.ModalProductCalculateSellingPriceWithSurcharge.getOpenHandler(modalSelector);

        });

    },

    getCloseHandler : function(modalSelector) {
        $(modalSelector).remove();
    },

    getSuccessHandler : function(modalSelector, productIds) {
        foodcoopshop.Helper.ajaxCall(
            '/admin/products/calculate-selling-price-with-surcharge',
            {
                productIds: productIds,
                surcharge: $('#dialogProductSurcharge').val()
            },
            {
                onOk: function (data) {
                    document.location.reload();
                },
                onError: function (data) {
                    var message = '<p>';
                    if (productIds.length == 1) {
                        message += foodcoopshop.LocalizedJs.admin.ErrorsOccurredWhileProductWasDeleted;
                    } else {
                        message += foodcoopshop.LocalizedJs.admin.ErrorsOccurredWhileProductsWereDeleted;
                    }
                    message += ':</p>';
                    message = message + data.msg;
                    foodcoopshop.Modal.appendFlashMessage(modalSelector, message);
                    foodcoopshop.Modal.resetButtons(modalSelector);
                }
            }
        );
    },

    getOpenHandler : function(modalSelector) {
        $(modalSelector).modal();
    }

};<commit_msg>set focus<commit_after>/**
 * FoodCoopShop - The open source software for your foodcoop
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @since         FoodCoopShop 3.1.0
 * @license       https://opensource.org/licenses/mit-license.php MIT License
 * @author        <NAME> <<EMAIL>>
 * @copyright     Copyright (c) Mario Rothauer, https://www.rothauer-it.com
 * @link          https://www.foodcoopshop.com
 */
foodcoopshop.ModalProductCalculateSellingPriceWithSurcharge = {

    init : function() {

        var modalSelector = '#modal-product-calculate-selling-price-with-surcharge';

        var button = $('#calculateSellingPriceWithSurchargForSelectedProducts');
        foodcoopshop.Helper.disableButton(button);

        $('table.list').find('input.row-marker[type="checkbox"]').on('click', function () {
            foodcoopshop.Admin.updateObjectSelectionActionButton(button);
        });

        button.on('click', function () {

            var productIds = foodcoopshop.Admin.getSelectedProductIds();
            var title = 'Verkaufspreis berechnen';
            //var title = productIds.length == 1 ? foodcoopshop.LocalizedJs.admin.Product : foodcoopshop.LocalizedJs.admin.Products;

            var products = [];
            for (var i in productIds) {
                products.push($('tr#product-' + productIds[i] + ' span.product-name').html());
            }
            var html = '<ul><li>' + products.join('</li><li>') + '</li></ul>';

            html += '<label for="dialogProductSurcharge">Aufschlag: </label><br />';
            html += '<input type="number" step="0.01" min="0.01" name="dialogProductSurcharge" id="dialogProductSurcharge" value="" />';
            html += ' % vom Netto-Einkaufspreis';

            foodcoopshop.Modal.appendModalToDom(
                modalSelector,
                title,
                html
            );

            foodcoopshop.Modal.bindSuccessButton(modalSelector, function() {
                foodcoopshop.ModalProductCalculateSellingPriceWithSurcharge.getSuccessHandler(modalSelector, productIds);
            });

            $(modalSelector).on('hidden.bs.modal', function (e) {
                foodcoopshop.ModalProductCalculateSellingPriceWithSurcharge.getCloseHandler(modalSelector);
            });
            foodcoopshop.ModalProductCalculateSellingPriceWithSurcharge.getOpenHandler(modalSelector);

        });

    },

    getCloseHandler : function(modalSelector) {
        $(modalSelector).remove();
    },

    getSuccessHandler : function(modalSelector, productIds) {
        foodcoopshop.Helper.ajaxCall(
            '/admin/products/calculate-selling-price-with-surcharge',
            {
                productIds: productIds,
                surcharge: $('#dialogProductSurcharge').val()
            },
            {
                onOk: function (data) {
                    document.location.reload();
                },
                onError: function (data) {
                    var message = '<p>';
                    if (productIds.length == 1) {
                        message += foodcoopshop.LocalizedJs.admin.ErrorsOccurredWhileProductWasDeleted;
                    } else {
                        message += foodcoopshop.LocalizedJs.admin.ErrorsOccurredWhileProductsWereDeleted;
                    }
                    message += ':</p>';
                    message = message + data.msg;
                    foodcoopshop.Modal.appendFlashMessage(modalSelector, message);
                    foodcoopshop.Modal.resetButtons(modalSelector);
                }
            }
        );
    },

    getOpenHandler : function(modalSelector) {
        $(modalSelector).modal();
        $(modalSelector + ' #dialogProductSurcharge').focus();

    }

};
{'fraction_non_alphanumeric': 0.1190722985229334, 'fraction_numerical': 0.0028504793988079814, 'mean_word_length': 2.1162696810658055, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 34, 'https://': 6, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2374969', 'n_tokens_mistral': 2082, 'n_tokens_neox': 1997, 'n_words': 328}