-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathoptions.js
119 lines (100 loc) · 4.08 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
// Saves options to localStorage.
function isDebug() {
return localStorage["debug"];
}
function save_options() {
console.log("in save_options: ");
var debug = document.getElementById("debug");
localStorage["debug"] = debug.checked;
console.log("localStorage['debug']: " + localStorage["debug"]);
var percent = document.getElementById("percent");
localStorage["percent"] = percent.checked;
console.log("localStorage['percent']: " + localStorage["percent"]);
var filter_and_global = document.getElementById("filter_and_global");
localStorage["filter_and_global"] = filter_and_global.checked;
console.log("localStorage['filter_and_global']: "
+ localStorage["filter_and_global"]);
var pointsSequence=$('input[type=radio][name=pointsSequence]:checked').attr('value');
localStorage["pointsSequence"] = pointsSequence;
if (pointsSequence=="defaults") localStorage["pointsSequence-values"] = "0, 1, 2, 3, 5, 8, 13, 20";
else if(pointsSequence=="fibonacci") localStorage["pointsSequence-values"] = "1, 2, 3, 5, 8, 13, 21, 34, 55";
else if(pointsSequence=="tshirtsizes") localStorage["pointsSequence-values"] = "XXS, XS, S, M, L, XL, XXL, 3XL, 4XL";
else if(pointsSequence=="moscow") localStorage["pointsSequence-values"] = "W, C, S, M";
else localStorage["pointsSequence-values"] =$("#customPointSequence").val();
var refreshRate = $("#refreshRate").val();
if ( Number(refreshRate) >= 1) {
localStorage["refreshRate"] = refreshRate;
}
$("#refreshRate").val(localStorage["refreshRate"]);
console.log("localStorage['pointsSequence']: "
+ localStorage["pointsSequence"]);
console.log("localStorage['pointsSequence-values']: "
+ localStorage["pointsSequence-values"]);
console.log("localStorage['refreshRate']: "
+ localStorage["refreshRate"]);
showStatus("Options Saved.");
}
function showStatus(message) {
var status = $("#status");
var message = $("<a>").addClass("alert").addClass("alert-success").append(message).appendTo(status);
setTimeout(function() {
status.children().remove();
}, 750);
}
function restore_options() {
console.log("restore_options: ");
var debug = localStorage["debug"];
console.log("debug: " + debug);
if (debug == "true"|| debug == true) {
document.getElementById("debug").checked = "checked";
} else {
document.getElementById("debug").checked = "";
}
var percent = localStorage["percent"];
console.log("percent: " + percent);
if (percent == "true"|| percent == true) {
document.getElementById("percent").checked = "checked";
} else {
document.getElementById("percent").checked = "";
}
var filter_and_global = localStorage["filter_and_global"];
console.log("filter_and_global: " + filter_and_global);
if (filter_and_global == "true"|| filter_and_global == true) {
document.getElementById("filter_and_global").checked = "checked";
} else {
document.getElementById("filter_and_global").checked = "";
}
var pointsSequence = localStorage["pointsSequence"];
var pointsSequencevalues = localStorage["pointsSequence-values"];
console.log("pointsSequence: "+pointsSequence+" and "+pointsSequencevalues);
$('input[type=radio][name=pointsSequence][value='+pointsSequence+']').attr('checked','checked');
if (pointsSequence=="custom") {
$("#customPointSequence").val(pointsSequencevalues);
}
var refreshRate = localStorage["refreshRate"];
if(!isNumber(refreshRate)|| Number(refreshRate)<=0) {
localStorage["refreshRate"]=2;
refreshRate = localStorage["refreshRate"];
}
$("#refreshRate").val(refreshRate);
console.log("restored");
}
function restoreDefaults() {
localStorage["debug"]=false;
localStorage["percent"]=true;
localStorage["filter_and_global"]=true;
localStorage["pointsSequence"]="defaults";
localStorage.removeItem("pointsSequence-values");
localStorage["refreshRate"]=2;
showStatus("Default settings restored.");
restore_options();
}
document.addEventListener('DOMContentLoaded', function() {
restore_options();
$("#saveButton").on("click", save_options);
$("#restoreButton").on("click", restoreDefaults);
$('.ttip').tooltip({delay: { show: 500, hide: 100 }});
});
function isNumber(text) {
return !isNaN(Number(text));
};