Skip to content

Instantly share code, notes, and snippets.

@DrMabuse23
Created September 23, 2015 11:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DrMabuse23/77a475a9c33ccb091a9f to your computer and use it in GitHub Desktop.
Save DrMabuse23/77a475a9c33ccb091a9f to your computer and use it in GitHub Desktop.
/**
* Created by Pascal Brewing
* Copyright (c)
* 2015
* M-Way Solutions GmbH. All rights reserved.
* http://www.mwaysolutions.com
* Redistribution and use in source and binary forms, with or without
* modification, are not permitted.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
'use strict';
angular.module('tanga')
.factory('Backbone',
function Backbone($window, $http, $q) {
var _$q;
var _$http;
var _sync = $window.Backbone.sync;
_$q = $q;
_$http = $http;
$window.Backbone.sync = function (method, model, options) {
var dfd = _$q.defer();
_sync.apply(Backbone, [method, model, options]).then(function () {
dfd.resolve(model);
}, function (resp) {
dfd.reject(resp);
});
return dfd.promise;
};
$window.Backbone.ajax = function (options) {
// Set HTTP Verb as 'method'
options.method = options.type;
var dfd = _$q.defer();
// Use angulars $http implementation for requests
_$http.apply(angular, [options]).then(function (resp) {
if (options.success && typeof options.success === 'function') {
options.success(resp);
}
dfd.resolve(resp);
}, function (resp) {
if (options.error && typeof options.error === 'function') {
options.error(resp);
}
dfd.reject(resp);
});
return dfd.promise;
};
return $window.Backbone;
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment