-
Notifications
You must be signed in to change notification settings - Fork 0
/
webwear-popup.js
139 lines (109 loc) · 3.72 KB
/
webwear-popup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
$(document).ready(function() {
addEventHandlers();
populateForms();
});
function addEventHandlers(){
$('#history').click(
function(){
chrome.tabs.create({'url': chrome.extension.getURL('history.html')});
}
);
$('#tracking-on').click(
function(e){
localStorage['trackingOn'] = $('#tracking-on').prop('checked').toString();
}
)
$('#seewear').click(
function(e){
if ($('#seewear').prop('checked')){
localStorage['visibilityOn'] = 'true';
}
else{
localStorage['visibilityOn'] = 'false';
}
}
);
$('#set-username').click(
function(e){
var username = $('#username').val();
if (username && username!=''){
localStorage['username'] = username;
alert('Wear Username updated');
}
else{
alert('Please enter a value for the username and try again.');
}
}
);
$('#set-collection').click(
function(e){
var username = $('#collection').val();
if (collection && collection!=''){
localStorage['collectionPrefix'] = username;
alert('Wear collection was updated');
}
else{
alert('Please enter a value for the collection and try again.');
}
}
);
}
function populateForms(){
var trackingOn = (localStorage['trackingOn'] == 'true');
$('#tracking-on').prop('checked',trackingOn);
var visibilityOn = (localStorage['visibilityOn'] == 'true');
if (visibilityOn){
$('#seewear').prop('checked',true);
}
var username = localStorage['username'];
$('#username').val(username);
var collection = localStorage['collectionPrefix'];
$('#collection').val(collection);
//get unique users and populate the user filter
$.ajax(
{
type: 'GET',
url: WebWearData+'/_distinct?criteria={"key":"user"}',
success: handleGetUniqueUsers,
async:true
}
);
}
function handleGetUniqueUsers(data){
$.each(data.values,function(i,user){
var userObject = $('<div class="webwear-filter-user" id="'+user+'"></div>');
var filterUsers = JSON.parse(localStorage['filterUsers']);
var img = util.getPortrait(user);
var imgObject = '<img class="webwear-filter-user-img" src="'+img+'" alt="'+img+'\' pic" />';
userObject.append(imgObject);
userObject.append('<smaller>'+user+'</smaller>');
userObject.click(
function(e){
var username = $(this).data('username');
var filterUsers = JSON.parse(localStorage['filterUsers']);
if ($(this).hasClass('webwear-people-selected')){
$(this).removeClass('webwear-people-selected');
$(this).addClass('webwear-people-not-selected');
//add the user to the list of people to exclude
filterUsers.push(username);
}
else{
$(this).addClass('webwear-people-selected');
$(this).removeClass('webwear-people-not-selected');
//remove the user from the list of filtered users
var index = filterUsers.indexOf(username);
filterUsers.splice(index,1);
}
localStorage['filterUsers'] = JSON.stringify(filterUsers);
}
);
if ($.inArray(user,filterUsers) != -1){
userObject.addClass('webwear-people-not-selected');
}
else{
userObject.addClass('webwear-people-selected');
}
userObject.data('username',user);
$('#webwear-people-filter').append(userObject);
});
}