Sha256: e5690bee40c2596190136e9f5deab172902d3757b82ad4836577479e8d849fda

Contents?: true

Size: 1.88 KB

Versions: 62

Compression:

Stored size: 1.88 KB

Contents

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

    var announceEvent = function (summary) {
            var data = $(summary).data('asset');

            $(window).trigger('assetPickers:insert', data);

            WORKAREA.takeover.close();
        },

        requestPage = function (requestData) {
            $.get(requestData.endpoint, requestData.data || {})
            .done(WORKAREA.takeover.update);
        },

        getRequestData = function (element) {
            var requestData = {};

            if (_.isUndefined(element.action)) {
                requestData.endpoint = element.href;
            } else {
                requestData.endpoint = element.action;
                requestData.data = $(element).serialize();
            }

            return requestData;
        },

        stopEvent = function (event) {
            event.preventDefault();
            return event.currentTarget;
        },

        handleSummaryClick = _.flow(stopEvent, announceEvent),

        /**
         * Handles a click or submit event asyncronously, replacing the current
         * Takeover with the content from the async call.
         * @type {function}
         * @param {event} event the click or submit event
         */
        handleInteraction = _.flow(stopEvent, getRequestData, requestPage),

        /**
         * @method
         * @name init
         * @memberof WORKAREA.assetPickers
         */
        init = function ($scope) {
            $('[data-asset-picker]', $scope)
                .addBack('[data-asset-picker]')
                .on('submit', 'form', handleInteraction)
                .on('click', 'a:not([data-asset])', handleInteraction)
                .on('click', '[data-asset]', handleSummaryClick);
        };

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

Version data entries

62 entries across 62 versions & 1 rubygems

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