Code coverage report for app/views/sou/souView.js

Statements: 100% (22 / 22)      Branches: 100% (12 / 12)      Functions: 100% (5 / 5)      Lines: 100% (22 / 22)      Ignored: 1 branch     

All files » app/views/sou/ » souView.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149                1                                                       1                                                                           5 1   1     5 5   5 5   5                 1     1             1                   2       2 1 1   1                 3                 3   3   3      
/*global require, define, console */
/*jslint nomen: true, debug: true */
 
/**
 * @module souView
 * @extends module:defaultView
 */
 
define([
    "views/defaultView",
    "views/sou/souChartView",
    "text!templates/defaultTpl.hbs",
    "models/souModel",
    "framework",
    "utils"
 
], function (defaultView, SouChartView, tpl, Model, $, utils) {
    "use strict";
    /**
     * @name module:souView
     * @description SOU widget class
     * @class Backbone.View
     *
     * @requires module:defaultView
     * @requires module:souChartView
     * @requires text!templates/souTpl {String} SOU hbs template
     * @requires module:souModel
     *
     * @see module:defaultView
     * @see module:souChartView
     * @see module:souModel
     *
     * @constructor
     * @returns {Function} Backbone.View constructor
     */
 
    return defaultView.extend({
        /**
         * @name module:souView#template
         * @dectription Raw handlebars template
         * @property {String}
         */
        template: tpl,
 
        /**
         * @name module:souView#name
         * @dectription Template id (need for caching)
         * @property {String}
         */
        name: "souTpl",
 
        /**
         * @name module:souView#title
         * @dectription Default SOU widget title
         * @property {String}
         */
        title: "souTitle",
 
        /**
         * @name module:souView#ModelConstructor
         * @see module:defaultView#ModelConstructor
         * @dectription SOU model class
         * @construstor {String}
         */
        ModelConstructor: Model,
 
        /**
         * @name module:souView#renderData
         * @description SOU chart data update $ widget menu render
         * @function
         */
        renderData: function () {
            // Menu render
            /* istanbul ignore else */
            if (this.renderMenu) {
                this.renderMenu(["avg"].concat(this.model.get("unique") || []));
                // There's no need to render another one;
                this.renderMenu = undefined;
            }
            /* istanbul ignore else */
            Eif (this.chartView) {
                this.chartView.render(this.model.get("collection"), this.model.get("subtype"));
            }
            this.switchModeDelayed();
            this.showMsg();
 
            return this.model.attributes;
        },
        /**
         * @name module:souView#afterRender
         * @description Menu event bindings and SOU chart initialization
         * @see module:defaultView#afterRender
         * @function
         */
        afterRender: function () {
            var MENU_LINK_CLASSNAME = ".enw__menu__link",
                CHART_CLASSNAME = ".enw__chart";
 
            this.$el.on(
                "click",
                MENU_LINK_CLASSNAME,
                $.proxy(this.onMenuClick, this)
            );
 
            // Chart view init
            this.chartView = new SouChartView({
                el: this.$el.find(CHART_CLASSNAME).get(0)
            });
        },
        /**
         * @name module:souView#onMenuClick
         * @description Menu click handler
         * @function
         */
        onMenuClick: function (e) {
            var $target = $(e.target),
                mode = $target.data("href");
 
            // "Throttling": suspends handler while previous data request is being proceed
            if (this.status === 2) {
                this.switchMode(mode);
                return mode;
            }
            return;
        },
        /**
         * @name module:souView#switchMode
         * @description Updates model state by selected mode
         * @param [mode] {String} Widget state
         */
        switchMode: function (mode) {
            // "avg" mode has empty subtype
            var subject = (!mode || mode === "avg" ? "" : "/" + mode),
                model = this.model,
                /**
                 * @see module:defaultModel#url
                 */
                url = model.host + "/" + model.path + subject,
                MENU_SELECTOR = ".enw__menu";
 
            // Menu item class toggle
            this.selectMenuItem(mode, this.$el.find(MENU_SELECTOR));
 
            this.fetch(url);
 
            return mode;
        }
    });
});