-
Notifications
You must be signed in to change notification settings - Fork 21
/
options.js
229 lines (200 loc) · 7.48 KB
/
options.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
function showSavedPrompt(){
$("#status").html("Preferences saved.<br/><br/>" +
"Please refresh browser to make the changes effective." +
"<br/><br/>");
//clean up the text after 0.75 seconds
setTimeout(function() {
$("#status").text("");
}, 3000);
}
function savePreferences() {
//var hideListingNotes = $("#hide_listing_notes").is(":checked");
//localStorage["hideListingNotes"] = hideListingNotes;
var preferences = {};
for (var i=0; i < gPreferenceTypes.length; i++) {
var preferencesName = gPreferenceTypes[i]["name"];
var jsPreferencesName = "#" + preferencesName;
var type = gPreferenceTypes[i]["type"];
if (type === "select" || type === "color" || type === "textarea") {
preferences[preferencesName] = $(jsPreferencesName).val();
} else if (type === "checkbox") {
preferences[preferencesName] = String($(jsPreferencesName).is(":checked"));
}
}
var disabledAccounts = [];
$("#disabled_accounts input").each(function(){
if($(this).is(":checked")){
var email = $(this).attr("data-email");
disabledAccounts.push(email);
}
});
preferences["disabledAccounts"] = JSON.stringify(disabledAccounts);
pushPreferences(preferences);
showSavedPrompt();
}
function resetPreferences() {
pushPreferences({}); //clear all existing values
setTimeout(pullPreferences, 200); //get the default values
setTimeout(savePreferences, 400); //push back the default values
setTimeout(showSavedPrompt, 600);
}
function updateControls(preferences){
for (var i=0; i < gPreferenceTypes.length; i++) {
var preferencesName = gPreferenceTypes[i]["name"];
var jsPreferencesName = "#" + preferencesName;
var type = gPreferenceTypes[i]["type"];
var preferencesVal = preferences[preferencesName]
if (type === "color" || type === "select" || type === "textarea") {
if (type === "color") {
$(jsPreferencesName).setColor(preferencesVal.toUpperCase());
}
$(jsPreferencesName).val(preferencesVal);
} else if (type === "checkbox") {
$(jsPreferencesName).prop("checked", (preferencesVal !== "false"));
}
}
var disabledAccounts = JSON.parse(preferences["disabledAccounts"]);
for(var i=0; i < disabledAccounts.length; i++){
var disable_email = disabledAccounts[i];
$("#disabled_accounts").append("<label>" +
"<input type=checkbox data-email='" +
disable_email + "' checked='checked'> " +
disable_email +
"</label>");
}
if(!disabledAccounts.length){
$("#disabled_accounts_container").hide();
}
/*
$("#debug_page_info").text(String(preferences["debugPageInfo"]));
$("#debug_content_info").text(String(preferences["debugContentInfo"]));
$("#debug_background_info").text(String(preferences["debugBackgroundInfo"]));
$("#debug_gdrive_info").text(String(preferences["debugGdriveInfo"]));
*/
}
function initPreferencesSelect(preferencesName, title, index) {
var option = gPreferenceTypes[index]["option"];
var htmlOption = "";
for (var i=0; i< option.length; i++) {
var optionValue = option[i]["value"];
var optionText = option[i]["text"];
if (optionValue) {
htmlOption += "<option value=\"" + optionValue + "\">" + optionText + "</option>";
} else {
htmlOption += "<option>" + optionText + "</option>";
}
}
var htmlSelect = "<tr>" +
"<td>" +
title +
"</td>" +
"<td>" +
"<div class=select>" +
"<select id=" + preferencesName + ">" +
htmlOption +
"</select>" +
"</div>" +
"</td>" +
"</tr>";
return htmlSelect;
}
function initPreferencesCheckbox(preferencesName, title, index) {
var htmlCheckbox = "<tr>" +
"<td>" +
"<label for=" + preferencesName + ">" + title + "</label>" +
"</td>" +
"<td>" +
"<input type='checkbox' id=" + preferencesName + ">" +
"</td>" +
"</tr>";
return htmlCheckbox;
}
function initPreferencesInputText(preferencesName, title, index) {
var htmlInputText = "<tr>" +
"<td>" +
title +
"</td>" +
"<td>" +
"<input type=text id=" + preferencesName + ">" +
"</td>" +
"</tr>";
return htmlInputText;
}
function initPreferences(){
var i;
var gPreferencePanelNameDict = {"notesAppearance": "", "advancedFeatures": "", "simpleMobileCRM": ""};
for (var i=0; i < gPreferenceTypes.length; i++) {
var preferencesName = gPreferenceTypes[i]["name"];
var type = gPreferenceTypes[i]["type"];
var title = gPreferenceTypes[i]["title"];
var panelName = gPreferenceTypes[i]["panelName"];
var htmlContent = "";
if (type === 'textarea') {
continue;
} else if (type === "select") {
var htmlContent = initPreferencesSelect(preferencesName, title, i);
} else if (type === "color") {
var htmlContent = initPreferencesInputText(preferencesName, title, i);
} else if (type === "checkbox") {
var htmlContent = initPreferencesCheckbox(preferencesName, title, i);
}
gPreferencePanelNameDict[panelName] += htmlContent;
}
var gPreferencePanelNameList = Object.keys(gPreferencePanelNameDict);
for (var i =0; i < gPreferencePanelNameList.length; i++) {
var gPreferencePanelName = "#" + gPreferencePanelNameList[i];
$(gPreferencePanelName).append(gPreferencePanelNameDict[gPreferencePanelNameList[i]]);
}
for(i=2; i<=10; i++){
$("#abstractStyle").append("<option value=" + i + ">First " + i + " Characters</option>");
}
for(i=3; i<=10; i++){
$("#abstractStyle").append("<option value=" + i*5 + ">First " + i*5 + " Characters</option>");
}
for(i=1; i<=30; i++){
$("#noteHeight").append("<option>" + i + "</option>");
}
for(i=8; i<=20; i++){
$("#fontSize").append("<option>" + i + "</option>");
$("#abstractFontSize").append("<option>" + i + "</option>");
}
}
function initDebugMessage(){
background = SimpleGmailNotes.getBrowser().extension.getBackgroundPage();
var sgno = background.SimpleGmailNotes;
var pageInfo = sgno.getLog(background.debugPageScope);
var contentInfo = sgno.getLog(background.debugContentScope);
var backgroundInfo = sgno.getLog(background.debugBackGroundScope);
var gdriveInfo = sgno.getLog(background.debugGdriveScope);
$("#debug_page_info").text(pageInfo);
$("#debug_content_info").text(contentInfo);
$("#debug_background_info").text(backgroundInfo);
$("#debug_gdrive_info").text(gdriveInfo);
//$("#debug_gdrive_info").text(String(preferences["debugGdriveInfo"]));
}
$(document).ready(function(){
initPreferences();
var SGNO = SimpleGmailNotes;
for (var i=0; i < gPreferenceTypes.length; i++) {
var type = gPreferenceTypes[i]["type"];
if (type === "color") {
var preferencesName = gPreferenceTypes[i]["name"];
var jsPreferencesName = "#" + preferencesName;
$(jsPreferencesName).simpleColor({ displayColorCode: true, chooserCSS: {'z-index': '999'}});
}
}
$("#save").click(savePreferences);
$("#reset").click(resetPreferences);
$("#revoke").click(function(){
window.open("https://accounts.google.com/IssuedAuthSubTokens", "_blank");
});
$("#review").click(function(){
window.open(SGNO.getReviewUrl(), "_blank");
});
$("#donation").attr("href", SGNO.getDonationUrl("pr"));
$("#contact_us").attr("href", SGNO.getOfficalSiteUrl("pr"));
$("#bart_logo").attr("href", SGNO.getOfficalSiteUrl("pr"));
$("#support").attr("href", SGNO.getSupportUrl());
pullPreferences();
initDebugMessage();
});