Code coverage report for app/views/tableView.js

Statements: 100% (16 / 16)      Branches: 100% (10 / 10)      Functions: 100% (6 / 6)      Lines: 100% (16 / 16)      Ignored: 1 branch     

All files » app/views/ » tableView.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              1                                       1                 2 2       2 1   2   2                 1                   2 2 2                             2 1 1   1      
/*global require, define, console, Sortable */
/*jslint nomen: true, debug: true */
 
/**
 * @module tableView
 */
 
define([
    "backbone",
    "framework",
    "handlebars",
 
    "sortable"
],
    function (Backbone, $, Handlebars) {
        "use strict";
        /**
         * @name module:tableView
         * @description Table view
         * @class Backbone.View
         * @requires Backbone
         * @requires framework
         * @constructor
         * @returns {Function} Backbone.View constructor
         */
 
 
        return Backbone.View.extend({
            /**
             * @name module:tableView#create
             * @description Creates a new one table
             * @function
             * @returns {$|undefined} $-instance or undefined
             */
            create: function () {
                /* istanbul ignore else */
                Eif (!this.table && this.template) {
                    this.table = this.$el.append(Handlebars.compile(this.template)()).find("table");
 
                    // Row template morph: compiled after table.create
                    /* istanbul ignore else */
                    if (typeof this.rowTemplate === "string") {
                        this.rowTemplate = Handlebars.compile(this.rowTemplate);
                    }
                    this.afterRender();
                }
                return this.table;
            },
            /**
             * @name module:tableView#update
             * @description Updates table by new data
             * @function
             * @returns {boolean} true
             */
            update: function () {
                return true;
            },
            /**
             * @name module:tableView#render
             * @description Renders template and appends to DOM.
             * .render() also triggers this.update()
             * @function
             * @returns view {object} current view instance
             */
            render: function (data) {
                this.create();
                this.update.apply(this, arguments);
                return this;
            },
            /**
             * @name module:tableView#afterRender
             * @description After render
             * @function
             */
            afterRender: function () {
            },
            /**
             * @name module:tableView#initSortable
             * @description Adds sorting for the table
             * @function
             */
            initSortable: function () {
                if (Sortable && this.table) {
                    Sortable.initTable(this.table.get(0));
                    return true;
                }
                return false;
            }
        });
    });