DataInterface.prototype.get = function(path, localOnly) { // Check for hydrated data var hydratedData = dataProvider.getDataByPath(path); if(Object.getOwnPropertyNames(hydratedData).length !== 0 || localOnly){ _response = hydratedData; if (localOnly && !_response) { _response = {}; } return this; } else { if (_inDom) { var $ = require("jquery"); // Check if we need artificial server delay for testing return Q.when($.get("http://" + window.location.host + path)).delay((devSettings.serverDelay) ? devSettings.serverDelayValue : 0).then(function(result) { return result; }); } else { _response = dataProvider.getDataByPath(path); // Profiling if (_profiling) { _profile.get.push(path); } return this; } } };
DataInterface.prototype.get = function(path) { // Check for hydrated data var hydratedData = dataProvider.getDataByPath(path); if(Object.getOwnPropertyNames(hydratedData).length !== 0){ _response = hydratedData; return this; } else { if (_inDom) { var $ = require("jquery"); return Q.when($.get("http://" + serverAddress + path)).then(function (result) { //console.log("di(dom) get (" + path + "): ", result); return jsonDate(result); }); } else { //console.log("di(node) get: ", path); _response = dataProvider.getDataByPath(path); // Profiling if (_profiling) { _profile.get.push(path); } return this; } } };
DataInterface.prototype.delete = function (path) { if (_inDom) { var $ = require("jquery"); return Q.when( $.ajax({ type: 'DELETE', url: "http://" + serverAddress + path, contentType: "application/json", dataType: "json" })).then(function (result) { //console.log("di(dom) post (" + path + "): ", result); return result; }); } else { //console.log("di(node) post: ", path, data); var dataProvider = require("client/core/syncDataProvider"); _response = dataProvider.getDataByPath(path); // Profiling if (_profiling) { _profile.post.push(path); } return this; } };
DataInterface.prototype.post = function(path, data) { if (_inDom) { var $ = require("jquery"); return Q.when($.post("http://" + window.location.host + path, data)).then(function(result) { return result; }); } else { var dataProvider = require("client/core/syncDataProvider"); _response = dataProvider.getDataByPath(path); // Profiling if (_profiling) { _profile.post.push(path); } return this; } };