Sha256: eb3118a6608ecd3ac1aedbe3403fbc1d18a95b1816cbe4ea78a994bfd72bb3c3

Contents?: true

Size: 1.72 KB

Versions: 62

Compression:

Stored size: 1.72 KB

Contents

/**
 * @namespace WORKAREA.sortVariants
 */
WORKAREA.registerModule('sortVariants', (function () {
    'use strict';

    var findVariantPositions = function (event) {
            var result = {},
                $variants = $('[data-sort-variant-id]', event.target);

            $variants.each(function (index, menu) {
                var id = $(menu).data('sortVariantId');

                if (id) {
                    result['positions[' + id + ']'] = index;
                }
            });

            return result;
        },

        saveSort = function (event) {
            var productId = $(event.target)
                                .closest('[data-sort-variant]')
                                .data('productId'),

                url = WORKAREA.routes.admin.moveCatalogProductVariantsPath(
                    { catalog_product_id: productId }
                );

            $.post(url, findVariantPositions(event));
        },

        setCellWidth = function (event, ui) {
            $('td', ui.item).each(function (index, cell) {
                $(cell).width($(cell).width());
            });

            return ui;
        },

        resetCellWidth = function (event, ui) {
            $('td', ui.item).each(function (index, cell) {
                $(cell).width('auto');
            });

            return ui;
        },

        /**
         * @method
         * @name init
         * @memberof WORKAREA.sortVariants
         */
        init = function ($scope) {
            $('[data-sort-variant]', $scope).sortable({
                axis: 'y',
                update: saveSort,
                helper: setCellWidth,
                stop: resetCellWidth
            });
        };

    return {
        init: init
    };
}()));

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-admin-3.4.13 app/assets/javascripts/workarea/admin/modules/sort_variants.js
workarea-admin-3.4.12 app/assets/javascripts/workarea/admin/modules/sort_variants.js