Code coverage report for src/kendo.breeze.datasource.js

Statements: 4.17% (1 / 24)      Branches: 0% (0 / 8)      Functions: 0% (0 / 8)      Lines: 4.17% (1 / 24)     

All files » src/ » kendo.breeze.datasource.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 631                                                                                                                            
(function ($, kendo, breeze) {
  'use strict';
 
  kendo.data.extensions = kendo.data.extensions || {};
 
  function BreezeTransport(entityManager, endPoint){
    this.entityManager = entityManager;
    this.endPoint = endPoint;
  }
 
  $.extend(BreezeTransport.prototype, {
    read: function (options) {
      var orderVal = "",
      sortOps = options.data.sort;
 
      if (sortOps) {
        orderVal = sortOps.field + " " + sortOps.dir;
      }
 
      var query = new breeze.EntityQuery(this.endpoint)
      .orderBy(orderVal)
      .skip(options.data.skip)
      .take(options.data.take);
 
      this.entityManager.executeQuery(query).then(function(xhr){
        options.success(xhr.results);
      });
    },
 
    create: function (options) {
      options.success(options.data);
    },
    update: function (options) {
      options.success(options.data);
    },
    destroy: function (options) {
      options.success(options.data);
    }
  });
 
  // Create the custom DataSource by extending a kendo.data.DataSource
  // and specify an init method that wires up needed functionality.
  kendo.data.extensions.BreezeDataSource = kendo.data.DataSource.extend({
    init: function (options) {
      // The endpoint and entityManager fields are required. If not specified, throw an error
      if (!options.entityManager) {
        throw new Error('A Breeze EntityManager object is required in order to use the DataSource with Breeze. Please specify an "entityManager" property in your options object.');
      } 
 
      if (!options.endpoint) {
        throw new Error('An "endpoint" option is required in order to work with Breeze. Please specify an "endpoint" property in your options object.');
      }
 
      // build the transport and final options objects
      var breezeTransport = new BreezeTransport(options.entityManager, options.endpoint);
      options = $.extend({}, { transport: breezeTransport }, options);
 
      // Call the "base" DataSource init function and provide our custom transport object
      kendo.data.DataSource.fn.init.call(this, options);
    }
  });
})($, kendo, breeze);