Sha256: 8b5071c5ae370b7b4b972bfc97ad64343b235d9b7468cd95582afc1713079fb9

Contents?: true

Size: 1.77 KB

Versions: 2

Compression:

Stored size: 1.77 KB

Contents

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

    var findDocumentPositions = function (event) {
            var result = {},
                $documents = $('[data-sort-document-id]', event.target);

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

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

            return result;
        },

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

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

            $.post(url, findDocumentPositions(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.sortDocuments
         */
        init = function ($scope) {
            $('[data-sort-document]', $scope).sortable({
                axis: 'y',
                update: saveSort,
                tolerance: 'pointer',
                helper: setCellWidth,
                stop: resetCellWidth
            });
        };

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
workarea-product_documents-1.0.1 app/assets/javascripts/workarea/admin/modules/sort_documents.js
workarea-product_documents-1.0.0 app/assets/javascripts/workarea/admin/modules/sort_documents.js