PageSourceSearch

https://www.rafaela.gob.ar/Sitio/Scripts/Servicios/Utilidades.js

js rafaela.gob.ar collected 2026-09-24 11:09:12 UTC 10,469 bytes, 399 lines download raw bytes

1app.service("Utilidades", ['$rootScope', '$http', '$state', '$window', 'jwtHelper', 'Socialshare', '$timeout', function ($rootScope, $http, $state, $window, jwtHelper, Socialshare, $timeout) {
2	return {
3		BorrarToken: function () {
4			$window.localStorage.removeItem("Mu_Token");
5		},
6
7		CerrarSesion: function () {
8			var Utilidades = this;
9
10			window.location = "/Administracion/IniciarSesion.html";
11		},
12
13		CompartirEnFacebook: function (url, tamaño) {
14			if (tamaño == undefined) {
15				tamaño = {
16					Ancho: 480,
17					Alto: 320
18				};
19			}
20
21			Socialshare.share({
22				'provider': 'facebook',
23				'attrs': {
24					'socialshare-type': 'share',
25					'socialshare-url': url,
26					'socialshare-via': '1568777393430251',
27					'socialsharePopupWidth': tamaño.Ancho,
28					'socialsharePopupHeight': tamaño.Alto,
29				}
30			});
31		},
32
33		CompartirEnTwitter: function (url, titulo, tamaño) {
34			if (tamaño == undefined) {
35				tamaño = {
36					Ancho: 557,
37					Alto: 461
38				};
39			}
40
41			Socialshare.share({
42				'provider': 'twitter',
43				'attrs': {
44					'socialshareUrl': url,
45					'socialshareText': titulo,
46					'socialshareHashtags': 'RafaelaCiudad',
47					'socialsharePopupWidth': tamaño.Ancho,
48					'socialsharePopupHeight': tamaño.Alto
49				}
50			});
51		},
52
53		ControlarErrores: function (result) {
54			var Utilidades = this;
55			var Datos = {
56				Token: Utilidades.ObtenerToken(),
57				Resultado: "",
58				Error: []
59			};
60
61			switch (result.status) {
62				case 401:
63					//Datos.Error.push("No tiene permisos para realizar esta acción.");				    
64					$state.go("NoAutorizado");
65					break;
66
67				case 404:
68					Datos.Error.push("El recurso al cual quiere acceder no se encuentra disponible.");
69					break;
70
71				default:
72					Datos.Error.push("Ocurrió un problema durante la ejecución.");
73					break;
74			}
75
76			console.log(Datos);
77
78			return Datos;
79		},
80
81		ConvertirAHex: function (texto) {
82			var Hex, I;
83			var Rta = "";
84
85			for (I = 0; I < texto.length; I++) {
86				Hex = texto.charCodeAt(I).toString(16);
87				Rta += Hex;
88			}
89
90			return Rta;
91		},
92
93		ConvertirDeHex: function (texto) {
94			var J;
95			var Hexes = texto.match(/.{1,2}/g) || [];
96
97			var Rta = "";
98			for (J = 0; J < Hexes.length; J++) {
99				Rta += String.fromCharCode(parseInt(Hexes[J], 16));
100			}
101
102			return Rta;
103		},
104
105		//Sirve para encriptar texto. algoritmo es opcional.
106		Encriptar: function (texto, Algoritmo) {
107			if (Algoritmo == null) {
108				Algoritmo = "MD5";
109			}
110
111			var hashFunction;
112
113			if (Algoritmo === "MD5") {
114				hashFunction = CryptoJS.MD5;
115			} else if (Algoritmo === "SHA-1") {
116				hashFunction = CryptoJS.SHA1;
117			} else if (Algoritmo === "SHA-2-256") {
118				hashFunction = CryptoJS.SHA256;
119			} else if (Algoritmo === "SHA-2-512") {
120				hashFunction = CryptoJS.SHA512;
121			} else {
122				throw Error("El tipo de algoritmo no es válido:" + Algoritmo);
123			}
124
125			var objHashResult = hashFunction(texto);
126
127			var strHashResult = objHashResult.toString(CryptoJS.enc.Base64);
128
129			return strHashResult;
130		},
131
132		EsMovil: function () {
133			if (navigator.userAgent.match(/Android/i)
134				|| navigator.userAgent.match(/webOS/i)
135				|| navigator.userAgent.match(/iPhone/i)
136				|| navigator.userAgent.match(/iPad/i)
137				|| navigator.userAgent.match(/iPod/i)
138				|| navigator.userAgent.match(/BlackBerry/i)
139				|| navigator.userAgent.match(/Windows Phone/i)
140				|| navigator.userAgent.match(/IEMobile/i)
141				|| navigator.userAgent.match(/WPDesktop/i)
142				|| window.innerWidth <= 600
143			) {
144				return true;
145			}
146			else {
147				return false;
148			}
149		},
150
151		//Hace foco al control especificado. Ej: txtNombre.
152		FocoAControl: function (idControl) {
153			$timeout(function () { document.getElementById(idControl).focus() }, 0);
154		},
155
156		Get: function () {
157			/*
158				Si el primer parámetro es de tipo string
159					arguments[0] = Url
160					arguments[1] = parametros (puede ser nulo)
161
162				Si el primer parámetro es boolean
163					arguments[0] = Determina si la url es desde donde se encuentra el sistema o si es desde la raiz del sitio.
164					arguments[1] = Url
165					arguments[2] = parametros (puede ser nulo)
166			*/
167
168			var Utilidades = this;
169			var Url = "";
170			var Parametros;
171                        
172			if (typeof (arguments[0]) == "string") {
173                if (arguments[2] != null && arguments[2] == true) {
174                    Url = arguments[0];
175                }
176                else {
177                    Url = app.UrlBase + arguments[0];
178                }
179                Parametros = arguments[1];
180
181			}
182			else {
183				if (typeof (arguments[0]) == "boolean") {
184					if (arguments[0]) {
185						Url = app.UrlRoot + arguments[1];
186					}
187					else {
188						Url = app.UrlBase + arguments[1];
189					}
190
191					Parametros = arguments[2];
192				}
193			}
194
195			return $http
196                 .get(Url, Parametros)
197                 .then(function (result) {
198                 	console.log("GET: " + Url);
199
200                 	var Datos = angular.fromJson(result.data);
201
202					Utilidades.GuardarToken(Datos.Token);
203
204                 	return Datos;
205                 }, function (result) {
206                 	return Utilidades.ControlarErrores(result);
207                 });
208		},
209
210		//Guarda el token en el localStorage.
211		GuardarToken: function (token) {
212			var Utilidades = this;
213			//Busco el token guardado.
214			var TokenGuardado = Utilidades.ObtenerTokenPayload();
215
216			//Si lo que está guardado es nulo, guardo el token nuevo.
217			if (TokenGuardado == null) {
218				$window.localStorage.setItem("Mu_Token", token);
219			}
220			else {
221				if (token) {
222					//Obtengo el payload del nuevo token.
223					var NuevoToken = jwtHelper.decodeToken(token);
224
225					//Si el IdUsuario distinto de 0 lo guardo, sino dejo el token guardado.
226					if (NuevoToken.idUsuario != 0) {
227						$window.localStorage.setItem("Mu_Token", token);
228					}
229				}
230			}
231		},
232
233		Imprimir: function (idElemento, css) {
234			var elemToPrint = document.getElementById(idElemento);
235			if (elemToPrint) {
236				var ventimp = window.open(' ', 'popimpr');
237				//ventimp.document.write(ficha.innerHTML);
238
239				var strHtml = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
240				strHtml = strHtml + "<html xmlns=\"http://www.w3.org/1999/xhtml\">";
241
242				if (css != null && css != undefined) {
243					css.forEach(function (entry) {
244						strHtml = strHtml + "<head><link href=\"" + entry + "\" rel=\"stylesheet\" type=\"text/css\" />";
245					});
246				}
247
248				strHtml += "<head><body style=\"margin:0px\">";
249				strHtml = strHtml + elemToPrint.innerHTML;
250				strHtml = strHtml + "</body></html>";
251				ventimp.document.write(strHtml);
252
253				setTimeout(function () {
254					ventimp.document.close();
255					ventimp.print();
256					ventimp.close();
257				}, 250);
258
259			}
260		},
261
262		ObtenerMenu: function () {
263			var Utilidades = this;
264			app.Permisos = [];
265
266			return Utilidades.Get("Sistemas/Menu/", {}).then(function (Datos) {
267				if (Datos.Error == "") {
268					ObtenerPermisos(Datos.Resultado);
269					return Datos.Resultado;
270				} else {
271					return "";
272				}
273			});
274
275			function ObtenerPermisos(menu) {
276				angular.forEach(menu, function (Datos) {
277					app.Permisos.push(Datos.Estado);
278					if (Datos.Submenu != "") {
279						ObtenerPermisos(Datos.Submenu);
280					}
281				})
282			}
283		},
284
285		ObtenerToken: function () {
286			if ($window.localStorage.getItem("Mu_Token") != null || $window.localStorage.getItem("Mu_Token") != "") {
287				return $window.localStorage.getItem("Mu_Token");
288			}
289			else {
290				return null;
291			}
292		},
293
294		//Obtiene el payload del token que está guardado en el local storage.
295		ObtenerTokenPayload: function () {
296			var Utilidades = this;
297
298			var TokenGuardado = Utilidades.ObtenerToken();
299
300			//Verifico que el token guardado sea distinto de nulo.
301			if (TokenGuardado != null) {
302				//Verifico que sea distinto de vacío.
303				if (TokenGuardado != "") {
304					//Devuelvo el payload del token.
305					return jwtHelper.decodeToken(TokenGuardado);
306				}
307			}
308
309			//Si llega aca es porque no existe y devuelvo nulo.
310			return null;
311		},
312
313		Post: function () {
314			/*
315				Si el primer parámetro es de tipo string
316					arguments[0] = Url
317					arguments[1] = parametros (puede ser nulo)
318
319				Si el primer parámetro es boolean
320					arguments[0] = Determina si la url es desde donde se encuentra el sistema o si es desde la raiz del sitio.
321					arguments[1] = Url
322					arguments[2] = parametros (puede ser nulo)
323			*/
324            
325			var Utilidades = this;
326			var Url = "";
327			var Parametros;
328
329			if (typeof (arguments[0]) == "string") {
330				Url = app.UrlBase + arguments[0];
331				Parametros = arguments[1];
332			}
333			else {
334				if (typeof (arguments[0]) == "boolean") {
335					if (arguments[0]) {
336						Url = app.UrlRoot + arguments[1];
337					}
338					else {
339						Url = app.UrlBase + arguments[1];
340					}
341
342					Parametros = arguments[2];
343				}
344			}
345
346			if (app.Debug) {
347				console.log("Cuerpo: " + JSON.stringify(Parametros));
348			}
349
350			return $http
351				.post(Url, Parametros)
352				.then(function (result) {
353					console.log("POST: " + Url);
354
355					var Datos = angular.fromJson(result.data);
356
357					Utilidades.GuardarToken(Datos.Token);
358
359					return Datos;
360				}, function (result) {
361					return Utilidades.ControlarErrores(result);
362				});
363		},
364
365		TienePermiso: function (id) {
366			var resultado = false;
367
368			angular.forEach(app.Permisos, function (Estado) {
369				if (id == Estado) {
370					resultado = true;
371				}
372			})
373
374			return resultado;
375        },
376
377        PostArchivos: function (urlAbsoluta, parametros) {
378            var Utilidades = this;
379
380            return $http
381                .post(app.UrlBase + urlAbsoluta, parametros, {
382                    transformRequest: angular.identity,
383                    headers: { 'Content-Type': undefined }
384                })
385				.then(function (result) {
386					console.log("POST: " + urlAbsoluta);
387                    var Datos = angular.fromJson(result.data);
388
389                    Utilidades.GuardarToken(Datos.Token);
390
391                    return Datos;
392                }, function (result) {
393                    return Utilidades.ControlarErrores(result);
394                });
395        }
396
397
398	}
399}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.