Sha256: 1d387cefb1d5ed3a3378ebcd54da9b24729dc1b181b71e62315f6bebee89bb9d

Contents?: true

Size: 1.78 KB

Versions: 10

Compression:

Stored size: 1.78 KB

Contents

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

    var getConfig = function ($select) {
            var $option = $('option:selected', $select);

            return _.merge(WORKAREA.config.remoteSelects, {
                ajax: {
                    url: $option.data('newNavigationTaxonEndpoint')
                },
                placeholder: '',
                allowClear: true
              });
        },

        destroyRemoteSelect = function ($select) {
            $select.val(null).trigger('change').select2('destroy');
        },

        createRemoteSelect = function (event) {
            var $typeSelect = $(event.currentTarget),
                $idSelect = $('[name=navigable_id]', event.delegateTarget),
                $section = $typeSelect.closest('[data-new-navigation-taxon]'),
                settings = getConfig($typeSelect),
                selected = $section.data('newNavigationTaxon');

            if ($idSelect.is('.select2-hidden-accessible') && _.isUndefined(selected)) {
                destroyRemoteSelect($idSelect);
            }

            $idSelect.select2(settings).val(selected);
        },

        changeRemoteSelect = function (index, element) {
            var $navigationLink = $(element);

            $navigationLink
            .on('change', '[name=navigable_type]', createRemoteSelect)
                .find('[name=navigable_type]')
                .trigger('change');
        },

        /**
         * @method
         * @name init
         * @memberof WORKAREA.newNavigationTaxons
         */
        init = function ($scope) {
            $('[data-new-navigation-taxon]', $scope)
            .each(changeRemoteSelect);
        };

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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
workarea-admin-3.5.27 app/assets/javascripts/workarea/admin/modules/new_navigation_taxons.js
workarea-admin-3.5.26 app/assets/javascripts/workarea/admin/modules/new_navigation_taxons.js
workarea-admin-3.4.45 app/assets/javascripts/workarea/admin/modules/new_navigation_taxons.js
workarea-admin-3.5.25 app/assets/javascripts/workarea/admin/modules/new_navigation_taxons.js
workarea-admin-3.5.23 app/assets/javascripts/workarea/admin/modules/new_navigation_taxons.js
workarea-admin-3.4.44 app/assets/javascripts/workarea/admin/modules/new_navigation_taxons.js
workarea-admin-3.5.22 app/assets/javascripts/workarea/admin/modules/new_navigation_taxons.js
workarea-admin-3.4.43 app/assets/javascripts/workarea/admin/modules/new_navigation_taxons.js
workarea-admin-3.5.21 app/assets/javascripts/workarea/admin/modules/new_navigation_taxons.js
workarea-admin-3.4.42 app/assets/javascripts/workarea/admin/modules/new_navigation_taxons.js