/**
* @ngdoc service
* @name Parametros
* @module s4c.services.Parametros
*
* @description Componente para acesso a api do backend e/ou comunicação entre controllers
*
*
*/
(function () {
'use strict';
/**
* @method ParametrosS4C
* @param {*} $http
* @param {*} $q
* @param {*} API_ENDPOINT
* @param {*} BlackList
*/
function ParametrosS4C($http, $q, API_ENDPOINT, BlackList) {
this.parametros = {};
this.blackList = [];
/**
* @method downloadBlackList
*/
function downloadBlackList() {
var deferred = $q.defer();
if (!_.isEmpty(this.blackList)) {
deferred.resolve(this.blackList);
}
BlackList.obter()
.then(function (res) {
if (typeof res === 'object') {
this.blackList = res;
deferred.resolve(this.blackList);
} else {
deferred.reject();
}
}.bind(this));
return deferred.promise;
}
/**
* @method downloadParametros
*/
function downloadParametros() {
var deferred = $q.defer();
if (!_.isEmpty(this.parametros)) {
deferred.resolve(this.parametros);
}
$http.get(API_ENDPOINT + 'parametros')
.then(function (res) {
if (typeof res.data === 'object') {
this.parametros = res.data;
deferred.resolve(this.parametros);
} else {
// Fallback para parametros default..
deferred.reject();
}
}.bind(this));
return deferred.promise;
}
/**
* @method atualizarParametros
* @param {*} parametros
*/
function atualizarParametros(parametros) {
var deferred = $q.defer();
$http.post(API_ENDPOINT + 'parametros', parametros)
.then(function (res) {
if (typeof res.data === 'object') {
this.parametros = res.data;
deferred.resolve(this.parametros);
} else {
// Fallback para parametros default..
deferred.reject();
}
}.bind(this));
return deferred.promise;
}
return {
downloadBlackList: downloadBlackList,
parametros: this.parametros,
blackList: this.blackList,
downloadParametros: downloadParametros,
atualizarParametros: atualizarParametros
};
}
angular.module('s4c.services.ParametrosS4C', [])
.factory('ParametrosS4C', ParametrosS4C);
ParametrosS4C.$inject = ['$http', '$q', 'API_ENDPOINT', 'BlackList'];
}());