Code coverage report for app/models/defaultModel.js

Statements: 100% (14 / 14)      Branches: 100% (4 / 4)      Functions: 100% (5 / 5)      Lines: 100% (14 / 14)      Ignored: 2 branches     

All files » app/models/ » defaultModel.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              1                           1     1 1 1 16     16 16       16 16   16       1             12                     17      
/*jslint nomen: true */
/*globals require, define, $*/
 
/**
 * @module defaultModel
 */
 
define(['backbone', "framework"], function (Backbone, $) {
    "use strict";
    /**
     * @name module:defaultModel
     * @description CORS capable Backbone.Model class
     * @extends Backbone.Model
     * @class Backbone.Model
     * @requires Backbone
     * @requires jQuery
     * @constructor
     * @returns {Function} Backbone.Model constructor
     */
 
 
    $.support.cors = true;
 
    // BB.sync injection
    (function () {
        var proxiedSync = Backbone.sync;
        Backbone.sync = function (method, model, options) {
            options = $.extend({}, options);
 
            /* istanbul ignore else */
            Eif (!options.crossDomain) {
                options.crossDomain = true;
            }
 
            /* istanbul ignore else */
            Eif (!options.xhrFields) {
                options.xhrFields = {withCredentials: true};
            }
            return proxiedSync(method, model, options);
        };
    }());
 
    return Backbone.Model.extend({
        /**
         * @name module:defaultModel#initialize
         * @description Constructs instance URL by path & host params from mixin
         * @function
         */
        initialize: function () {
            this.instanceUrl = this.host + "/" + this.path;
        },
        /**
         * @name module:defaultModel#url
         * @description Returns actual model URL
         * Full URL may be constructed at model init stage only: it depends from host attribute,
         * which is added via custom model extension
         * @function
         * @returns {string} Model instance url
         */
        url: function () {
            return this.instanceUrl;
        }
    });
});