<commit_before>/* global Backbone, Promise, _, window */
(function(NS) {
	"use strict";
	//Filename: promisify_helper.js
	NS = NS || {};
	var isInBrowser = typeof module === 'undefined' && typeof window !== 'undefined';
	var odataHelper = isInBrowser ? NS.Helpers.odataHelper : require("./odata_helper");
	var httpResponseParser = isInBrowser ? NS.Core.httpResponseParser : require('../core/http_response_parser');
	var ArgumentNullException = isInBrowser ? NS.Helpers.Exceptions.ArgumentNullException : require("./custom_exception").ArgumentNullException;
	var ArgumentInvalidException = isInBrowser ? NS.Helpers.Exceptions.ArgumentInvalidException : require("./custom_exception").ArgumentInvalidException;



	// Backbone model with **promise** CRUD method instead of its own methods.
	var PromiseModel = Backbone.Model.extend({
		/**
		 * Set the data for a promise model.
		 * @param  {object} json to set in the model.
		 * @param  {object} options on the save function such as the url.
		 * @return {undefined}
		 */
		setData: function setDataPromiseModel(json, options) {
			options = options || {};
			if (_.isString(options.url)) {
				this.urlRoot = options.url;
			}
			this.clear({
				silent: true
			});
			this.set(json, {
				silent: true
			});
		},
		/**
		 * Save the data for a promise model.
		 * @param  {object} json to save in the model.
		 * @param  {object} options on the save function such as the url.
		 * @return {objet} a promise of save.
		 */
		saveData: function setDataPromiseModel(json, options) {
			this.setData(json, options);
			return this.save();
		},
		/**
		 * Fetch the model.
		 * @param  {object} json to set to the model before loading.
		 * @param  {object} options on the save function such as the url.
		 * @return {objet} a promise of fetch.
		 */
		fetchData: function fetchDataPromiseModel(json, options) {
			this.setData(json, options);
			return this.fetch();
		},
		//Ovverride the save method on the model in order to Return a promise.
		save: function saveModel() {
			var model = this;
			var method = this.isNew() ? 'create' : 'update';
			return new Promise(
				function(resolve, reject) {
					Backbone.sync(method, model, {
						success: function(data, textStatus, jqXHR) {
							resolve(httpResponseParser.parse(jqXHR));
						},
						error: reject
					});
				}
			);
		},
		//Replacing the classic destroy model with a promise.
		destroy: function promiseDestroyModel() {
			var model = this;
			return new Promise(
				function(resolve, reject) {
					Backbone.sync('delete', model, {
						success: resolve,
						error: reject
					});
				}
			);
		},
		//Replacing the classic backbone fetch with a promise, resolve and reject are givent as options.success, and options.error of the ajax.
		fetch: function promiseFetchModel(options) {
			options = options || {};
			var model = this;
			//console.log('promiseFetchModel', model);
			return new Promise(function(resolve, reject) {
				/*Don't use underscore but could have because bacckbone has a dependency on it.*/
				options.success = function(data, textStatus, jqXHR) {
					resolve(httpResponseParser.parse(jqXHR));
				};
				options.error = reject;<commit_msg>Add the jqxhr options to the save method.<commit_after>/* global Backbone, Promise, _, window */
(function(NS) {
	"use strict";
	//Filename: promisify_helper.js
	NS = NS || {};
	var isInBrowser = typeof module === 'undefined' && typeof window !== 'undefined';
	var odataHelper = isInBrowser ? NS.Helpers.odataHelper : require("./odata_helper");
	var httpResponseParser = isInBrowser ? NS.Core.httpResponseParser : require('../core/http_response_parser');
	var ArgumentNullException = isInBrowser ? NS.Helpers.Exceptions.ArgumentNullException : require("./custom_exception").ArgumentNullException;
	var ArgumentInvalidException = isInBrowser ? NS.Helpers.Exceptions.ArgumentInvalidException : require("./custom_exception").ArgumentInvalidException;



	// Backbone model with **promise** CRUD method instead of its own methods.
	var PromiseModel = Backbone.Model.extend({
		/**
		 * Set the data for a promise model.
		 * @param  {object} json to set in the model.
		 * @param  {object} options on the save function such as the url.
		 * @return {undefined}
		 */
		setData: function setDataPromiseModel(json, options) {
			options = options || {};
			if (_.isString(options.url)) {
				this.urlRoot = options.url;
			}
			this.clear({
				silent: true
			});
			this.set(json, {
				silent: true
			});
		},
		/**
		 * Save the data for a promise model.
		 * @param  {object} json to save in the model.
		 * @param  {object} options on the save function such as the url.
		 * @return {objet} a promise of save.
		 */
		saveData: function setDataPromiseModel(json, options) {
			this.setData(json, options);
			return this.save();
		},
		/**
		 * Fetch the model.
		 * @param  {object} json to set to the model before loading.
		 * @param  {object} options on the save function such as the url.
		 * @return {objet} a promise of fetch.
		 */
		fetchData: function fetchDataPromiseModel(json, options) {
			this.setData(json, options);
			return this.fetch();
		},
		//Ovverride the save method on the model in order to Return a promise.
		save: function saveModel(options) {
			var model = this;
			var method = this.isNew() ? 'create' : 'update';
			return new Promise(
				function(resolve, reject) {
					var opts = _.extend({
						success: function(data, textStatus, jqXHR) {
							resolve(httpResponseParser.parse(jqXHR));
						},
						error: reject
					}, options);
					Backbone.sync(method, model, opts);
				}
			);
		},
		//Replacing the classic destroy model with a promise.
		destroy: function promiseDestroyModel() {
			var model = this;
			return new Promise(
				function(resolve, reject) {
					Backbone.sync('delete', model, {
						success: resolve,
						error: reject
					});
				}
			);
		},
		//Replacing the classic backbone fetch with a promise, resolve and reject are givent as options.success, and options.error of the ajax.
		fetch: function promiseFetchModel(options) {
			options = options || {};
			var model = this;
			//console.log('promiseFetchModel', model);
			return new Promise(function(resolve, reject) {
				/*Don't use underscore but could have because bacckbone has a dependency on it.*/
				options.success = function(data, textStatus, jqXHR) {
					resolve(httpResponseParser.parse(jqXHR));
				};
				options.error = reject;
{'fraction_non_alphanumeric': 0.12040185471406492, 'fraction_numerical': 0.0, 'mean_word_length': 3.35464333781965, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2952403', 'n_tokens_mistral': 2250, 'n_tokens_neox': 1878, 'n_words': 597}