Sha256: 22f2ceda8b9e1f91910a7668dd832b386049eb57445e24bd2822b9ea9420dd30

Contents?: true

Size: 1.53 KB

Versions: 62

Compression:

Stored size: 1.53 KB

Contents

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

    var createClonedID = function (index, id) {
            return id + '_cloned_' + index;
        },

        getDefaultValue = function () {
            return this.defaultValue;
        },

        cloneRow = function ($row) {
            var $clonedRow = $row.clone();

            $clonedRow
            .insertAfter($row)
                .find('[name],[for]')
                .val(getDefaultValue)
                .prop('id', createClonedID)  // needed to pass integration tests
                .prop('for', createClonedID);

            $row
                .find('.value__note')
                .remove();

            WORKAREA.initModules($clonedRow);
        },

        removeListeners = function ($row) {
            return $row.off('input.cloneableRows click.cloneableRows');
        },

        getTarget = function (event) {
            return $(event.delegateTarget);
        },

        handleInput = _.flowRight(cloneRow, removeListeners, getTarget),

        /**
         * @method
         * @name init
         * @memberof WORKAREA.cloneableRows
         */
        init = function ($scope) {
            $scope
                .find('[data-cloneable-row]')
                    .addBack('[data-cloneable-row]')
                    .on('input.cloneableRows', '[name]', handleInput)
                    .on('click.cloneableRows', 'input[type=file]', handleInput);
        };

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

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-admin-3.5.27 app/assets/javascripts/workarea/admin/modules/cloneable_rows.js
workarea-admin-3.5.26 app/assets/javascripts/workarea/admin/modules/cloneable_rows.js
workarea-admin-3.4.45 app/assets/javascripts/workarea/admin/modules/cloneable_rows.js
workarea-admin-3.5.25 app/assets/javascripts/workarea/admin/modules/cloneable_rows.js
workarea-admin-3.5.23 app/assets/javascripts/workarea/admin/modules/cloneable_rows.js
workarea-admin-3.4.44 app/assets/javascripts/workarea/admin/modules/cloneable_rows.js
workarea-admin-3.5.22 app/assets/javascripts/workarea/admin/modules/cloneable_rows.js
workarea-admin-3.4.43 app/assets/javascripts/workarea/admin/modules/cloneable_rows.js
workarea-admin-3.5.21 app/assets/javascripts/workarea/admin/modules/cloneable_rows.js
workarea-admin-3.4.42 app/assets/javascripts/workarea/admin/modules/cloneable_rows.js
workarea-admin-3.5.20 app/assets/javascripts/workarea/admin/modules/cloneable_rows.js
workarea-admin-3.4.41 app/assets/javascripts/workarea/admin/modules/cloneable_rows.js
workarea-admin-3.5.19 app/assets/javascripts/workarea/admin/modules/cloneable_rows.js
workarea-admin-3.4.40 app/assets/javascripts/workarea/admin/modules/cloneable_rows.js
workarea-admin-3.5.18 app/assets/javascripts/workarea/admin/modules/cloneable_rows.js
workarea-admin-3.4.39 app/assets/javascripts/workarea/admin/modules/cloneable_rows.js
workarea-admin-3.5.17 app/assets/javascripts/workarea/admin/modules/cloneable_rows.js
workarea-admin-3.4.38 app/assets/javascripts/workarea/admin/modules/cloneable_rows.js
workarea-admin-3.5.16 app/assets/javascripts/workarea/admin/modules/cloneable_rows.js
workarea-admin-3.4.37 app/assets/javascripts/workarea/admin/modules/cloneable_rows.js