Skip to content

Commit 4930c16

Browse files
committed
funcao que verifica se usuario aceita cookies - #126 / documentacao do codigo #21
1 parent 7ee4692 commit 4930c16

File tree

1 file changed

+74
-14
lines changed

1 file changed

+74
-14
lines changed

app/django-bbx/bbx/static/js/modules/bbx/functions.js

+74-14
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ define([
2525
'text!/templates/' + BBX.userLang + '/common/UserProfile.html',
2626
'text!/templates/' + BBX.userLang + '/common/MucuaProfile.html'
2727
], function($, _, Backbone, jQueryCookie, HeaderView, HomeMucuaView, BuscadorView, MucuaModel, RepositoryModel, MediaFunctions, ContentTpl, SidebarTpl, UsageBarTpl, UserProfileTpl, MucuaProfileTpl) {
28-
28+
29+
/**
30+
* init function of bbx functions
31+
*
32+
* @return {None}
33+
*/
2934
var init = function() {
3035
__setConfig(BBX.config);
3136
BBXFunctions = this;
@@ -45,6 +50,22 @@ define([
4550
}
4651
}
4752

53+
/**
54+
* check if cookies are enabled
55+
*
56+
* @return {Bool} if cookies are enabled
57+
*
58+
*/
59+
var isCookiesEnabled = function() {
60+
// TODO: improve cookie detection
61+
if (!navigator.cookieEnabled) {
62+
console.log("Cookies not enabled, Baobaxia need cookies.");
63+
return false;
64+
} else {
65+
return true;
66+
}
67+
}
68+
4869
/**
4970
* adds value to cookie
5071
*
@@ -55,6 +76,10 @@ define([
5576
var cookieData = {},
5677
serializedCookie = '',
5778
cookie = null;
79+
80+
if(!isCookiesEnabled) {
81+
return false;
82+
}
5883

5984
console.log('addToCookie()');
6085
if ($.cookie('sessionBBX')) {
@@ -82,6 +107,11 @@ define([
82107
*/
83108
var getFromCookie = function(key) {
84109
var key = key || '*';
110+
111+
if(!isCookiesEnabled) {
112+
return false;
113+
}
114+
85115
if ($.cookie('sessionBBX')) {
86116
var cookieData = $.parseJSON($.cookie('sessionBBX'));
87117
if (key == '*') {
@@ -129,11 +159,12 @@ define([
129159
}
130160

131161
/**
132-
* render common for internal pages at baobaxia
162+
* render common elements for internal pages at baobaxia
133163
*
164+
* @el {String} HTML Element identifier
134165
* @return [jQuery modify #header]
135166
*/
136-
var renderCommon = function(name) {
167+
var renderCommon = function(el) {
137168
var data = {},
138169
config = BBX.config,
139170
tags = [];
@@ -142,14 +173,14 @@ define([
142173
data.isLogged = this.isLogged;
143174
data.isEditable = false;
144175

145-
$('body').removeClass().addClass(name);
176+
$('body').removeClass().addClass(el);
146177
if (config.mucua == config.MYMUCUA) {
147178
$('body').addClass('my-mucua');
148179
} else {
149180
$('body').addClass('other-mucua');
150181
}
151-
data.lastVisitedMucuas = __getLastVisitedMucuas(config);
152-
console.log('render common: ' + name);
182+
data.lastVisitedMucuas = __getLastVisitedMucuas();
183+
console.log('render common: ' + el);
153184
if ($('#sidebar').html() == "" ||
154185
(typeof $('#sidebar').html() === "undefined")) {
155186
$('#footer').before(_.template(SidebarTpl, data));
@@ -179,7 +210,7 @@ define([
179210
/**
180211
* render usage bar at footer
181212
*
182-
* @return [jquery modify #footer]
213+
* @return {None} [jquery modify #footer]
183214
*/
184215
var renderUsage = function() {
185216
console.log('render usage');
@@ -228,7 +259,13 @@ define([
228259
}
229260
}
230261
}
231-
262+
263+
/**
264+
* get mucua aditional data resources at API
265+
*
266+
* @uuid {String} Mucua UUID
267+
* @return {None} [jQuery modification]
268+
*/
232269
var __getMucuaResources = function(uuid) {
233270
var config = __getConfig(),
234271
url = config.apiUrl + '/mucua/' + uuid + '/info',
@@ -340,10 +377,11 @@ define([
340377
}
341378
}, 100);
342379
}
343-
344380

345381
/**
382+
* render elements at sidebar
346383
*
384+
* @return {None} [jQuery modification]
347385
*/
348386
var renderSidebar = function() {
349387
var config = __getConfig(),
@@ -485,10 +523,15 @@ define([
485523
}
486524
}
487525

488-
var __getLastVisitedMucuas = function(config) {
526+
/**
527+
* get last visited Mucua
528+
*
529+
* @return {Object} with list of last visited mucuas
530+
*/
531+
var __getLastVisitedMucuas = function() {
489532
// get last visited mucuas
490-
491-
var visitedMucuas = {'name': 'visitedMucuas',
533+
var config = __getConfig(),
534+
visitedMucuas = {'name': 'visitedMucuas',
492535
'values': []
493536
}
494537
visitedMucuas.values = getFromCookie('visitedMucuas') || [];
@@ -530,7 +573,7 @@ define([
530573
}
531574

532575
addToCookie(visitedMucuas);
533-
576+
console.log(visitedMucuas);
534577
return visitedMucuas.values;
535578
}
536579

@@ -611,10 +654,25 @@ define([
611654
}, 50);
612655
}
613656

657+
658+
/**
659+
* Get config data
660+
*
661+
* @return {Object} input object with config data
662+
*/
614663
var __getConfig = function() {
615664
return BBX.config;
616665
}
617-
666+
667+
668+
/**
669+
* Set navigation variables
670+
*
671+
* @repository {String} Repository name
672+
* @mucua {String} Mucua name
673+
* @subroute {String} Internal url subroute
674+
* @return {Object} input object with config data
675+
*/
618676
var setNavigationVars = function(repository, mucua, subroute) {
619677
var subroute = subroute || '',
620678
reMedia = /^[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}/, // padrao de uuid
@@ -676,9 +734,11 @@ define([
676734
}
677735
}
678736

737+
// public functions are defined above
679738
return {
680739
init: init,
681740
isLogged: isLogged,
741+
isCookiesEnabled: isCookiesEnabled,
682742
getFromCookie: getFromCookie,
683743
addToCookie: addToCookie,
684744
getDefaultHome: getDefaultHome,

0 commit comments

Comments
 (0)