Sha256: 8962ea38fb02c642f9ba534af96658c316b56887cedffc7835e9cfd6cf09a865

Contents?: true

Size: 1.77 KB

Versions: 62

Compression:

Stored size: 1.77 KB

Contents

/**
 *
 * TODO remove in v4, no longer used
 *
 * Sets up the link for looking up help for the current page
 *
 * @namespace WORKAREA.helpLookupButtons
 */
WORKAREA.registerModule('helpLookupButtons', (function () {
    'use strict';

    var fetchHelp = function (url) {
            $.get(url)
            .done(function(response) {
                WORKAREA.takeover.open(response, { 'takeoverClass': 'takeover--from-top' });
            })
            .fail(_.partial(WORKAREA.url.redirectTo, url));
        },

        getHelpUrl = function (keywords) {
            return WORKAREA.routes.admin.helpIndexPath({
                like_text: keywords,
                for_url: window.location.pathname
            });
        },

        sanitizeText = function (index, element) {
            var text = $(element).text();

            text = text.replace(/workarea|admin/ig, '');
            text = text.replace(/\s{2,}/g, ' ');

            return _.trim(text);
        },

        getKeywords = function ($scope) {
            var config = WORKAREA.config.helpLookupButtons;
            return $(config.keywordElements.join(','), $scope)
                .map(sanitizeText)
                .get()
                .join(' ');
        },

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

        openHelp = _.flow(stopEvent, getKeywords, getHelpUrl, fetchHelp),

       /**
        * @method
        * @name init
        * @memberof WORKAREA.helpLookupButtons
        */
        init = function ($scope) {
            $('[data-help-lookup-button]', $scope)
            .on('click', _.partial(openHelp, $scope));
        };

    return {
        init: init,
        sanitizeText: sanitizeText,
        getKeywords: getKeywords
    };
}()));

Version data entries

62 entries across 62 versions & 1 rubygems

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