Commit 3f9a6b68 authored by Leo Iannacone's avatar Leo Iannacone

added web.ui preferences page - auto load user preferences on window.load

parent 3f4e6252
var socket = io.connect('//' + config.hostname );
new Preferences()
var preferences = new Preferences()
new Page_Generic().init(socket)
if (window.location.pathname == config.paths.distribution) {
new Page_Distrubion(socket).start()
}
else if (window.location.pathname == config.paths.preferences) {
preferences.initPage()
}
\ No newline at end of file
function Preferences() {
// update config.preferences according with user choices
this.load = function() {
for (setting in config.preferences) {
if ((value = localStorage.getItem(setting))) {
config.preferences[setting] = JSON.parse(value)
var load = function () {
for (key in config.preferences) {
if ((value = localStorage.getItem(key))) {
debug(2, 'loading preference', key, value)
config.preferences[key] = JSON.parse(value)
}
}
}
this.load()
// set prefence
var set = function (key, value) {
if (config.preferences.hasOwnProperty(key)) {
debug(1, 'setting preference', key, value)
localStorage.setItem(key, value)
config.preferences[key] = JSON.parse(value)
}
}
// init prefence page
this.initPage = function() {
$(window).on('load', function() {
// set view according with config.preferences
for (key in config.preferences) {
var element = $("#preferences #" + key)
if (element.attr('type') == "checkbox") {
element.prop('checked', config.preferences[key])
}
else {
element.val(config.preferences[key])
}
}
// on input change, set prefence
$("#preferences input, #preferences select").change(function() {
var key = $(this).attr('id')
var value = $(this).val()
if ($(this).attr('type') == 'checkbox')
value = $(this).is(':checked')
set(key,value)
})
})
}
load()
}
\ No newline at end of file
......@@ -89,3 +89,17 @@ footer {
right: 5px;
}
#preferences {
font-size: 15px;
}
#preferences .debug #debug {
width: 58px;
float:left;
margin-right: 10px;
}
#preferences .debug label {
font-weight: normal;
padding-top: 6px;
}
\ No newline at end of file
<div class="panel panel-primary">
<div id="preferences" class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Preferences</h3>
</div>
<div class="panel-body">
Panel content
<div class="checkbox">
<label>
<input id="header" type="checkbox"> Show header
</label>
</div>
<div class="checkbox">
<label>
<input id="sidebar" type="checkbox"> Show sidebar
</label>
</div>
<div class="checkbox">
<label>
<input id="autoscroll" type="checkbox"> Enable autoscroll
</label>
</div>
<div class="debug">
<select id="debug" class="form-control">
<option>0</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
<label for="debug">Set debug level</label>
</div>
</div>
</div>
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment