7604 |
25 Feb 19 |
nicklas |
/* $Id $ |
7604 |
25 Feb 19 |
nicklas |
2 |
------------------------------------------------------------------ |
7604 |
25 Feb 19 |
nicklas |
Copyright (C) 2012 Nicklas Nordborg |
7604 |
25 Feb 19 |
nicklas |
4 |
|
7604 |
25 Feb 19 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
7604 |
25 Feb 19 |
nicklas |
Available at http://base.thep.lu.se/ |
7604 |
25 Feb 19 |
nicklas |
7 |
|
7604 |
25 Feb 19 |
nicklas |
BASE is free software; you can redistribute it and/or |
7604 |
25 Feb 19 |
nicklas |
modify it under the terms of the GNU General Public License |
7604 |
25 Feb 19 |
nicklas |
as published by the Free Software Foundation; either version 3 |
7604 |
25 Feb 19 |
nicklas |
of the License, or (at your option) any later version. |
7604 |
25 Feb 19 |
nicklas |
12 |
|
7604 |
25 Feb 19 |
nicklas |
BASE is distributed in the hope that it will be useful, |
7604 |
25 Feb 19 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
7604 |
25 Feb 19 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
7604 |
25 Feb 19 |
nicklas |
GNU General Public License for more details. |
7604 |
25 Feb 19 |
nicklas |
17 |
|
7604 |
25 Feb 19 |
nicklas |
You should have received a copy of the GNU General Public License |
7604 |
25 Feb 19 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
7604 |
25 Feb 19 |
nicklas |
20 |
------------------------------------------------------------------ |
7604 |
25 Feb 19 |
nicklas |
21 |
|
7604 |
25 Feb 19 |
nicklas |
@author Nicklas |
7604 |
25 Feb 19 |
nicklas |
23 |
*/ |
7604 |
25 Feb 19 |
nicklas |
'use strict'; |
7604 |
25 Feb 19 |
nicklas |
25 |
|
7604 |
25 Feb 19 |
nicklas |
var Preferences = function() |
7604 |
25 Feb 19 |
nicklas |
27 |
{ |
7604 |
25 Feb 19 |
nicklas |
var preferences = {}; |
7604 |
25 Feb 19 |
nicklas |
29 |
|
7604 |
25 Feb 19 |
nicklas |
var initialRememberDialogPositions; |
7604 |
25 Feb 19 |
nicklas |
31 |
|
7604 |
25 Feb 19 |
nicklas |
preferences.initPage = function() |
7604 |
25 Feb 19 |
nicklas |
33 |
{ |
7604 |
25 Feb 19 |
nicklas |
// Save + Close buttons |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnSave', Preferences.save); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('close', App.closeWindow); |
7604 |
25 Feb 19 |
nicklas |
37 |
|
7604 |
25 Feb 19 |
nicklas |
// Validation |
7604 |
25 Feb 19 |
nicklas |
TabControl.addTabValidator('settings.appearance', preferences.validateAppearance); |
7604 |
25 Feb 19 |
nicklas |
TabControl.addTabValidator('settings.plugins', preferences.validatePlugins); |
7604 |
25 Feb 19 |
nicklas |
TabControl.addTabValidator('settings.mostRecent', preferences.validateMostRecent); |
7604 |
25 Feb 19 |
nicklas |
42 |
|
7604 |
25 Feb 19 |
nicklas |
// Font size + scale options |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('fontsizeXS', 'click', Preferences.fontSizeOnClick); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('fontsizeS', 'click', Preferences.fontSizeOnClick); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('fontsizeM', 'click', Preferences.fontSizeOnClick); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('fontsizeL', 'click', Preferences.fontSizeOnClick); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('fontsizeXL', 'click', Preferences.fontSizeOnClick); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('scale', 'keypress', Events.integerOnly); |
7604 |
25 Feb 19 |
nicklas |
50 |
|
7604 |
25 Feb 19 |
nicklas |
// Color and date/time presets |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnMinColor', Preferences.selectColorOnClick); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnMidColor', Preferences.selectColorOnClick); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnMaxColor', Preferences.selectColorOnClick); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('mincolor', 'change', Preferences.colorOnChange); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('midcolor', 'change', Preferences.colorOnChange); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('maxcolor', 'change', Preferences.colorOnChange); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('colorPresets', 'change', Preferences.colorPresetOnChange); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('datePresets', 'change', Preferences.datePresetOnChange); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('dateTimePresets', 'change', Preferences.dateTimePresetOnChange); |
7604 |
25 Feb 19 |
nicklas |
61 |
|
7604 |
25 Feb 19 |
nicklas |
// Recently used items |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('maxViewed', 'keypress', Events.integerOnly); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('maxUsed', 'keypress', Events.integerOnly); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('moveUp', Preferences.moveStickyUpOrDown); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('moveDown', Preferences.moveStickyUpOrDown); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('moveLeft', Preferences.moveToSticky); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('moveRight', Preferences.moveFromSticky); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('stickyItems', 'dblclick', Preferences.moveFromSticky); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('allItems', 'dblclick', Preferences.moveToSticky); |
7604 |
25 Feb 19 |
nicklas |
71 |
|
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['preferences']; |
7604 |
25 Feb 19 |
nicklas |
initialRememberDialogPositions = frm.remember_positions.checked; |
7604 |
25 Feb 19 |
nicklas |
74 |
|
7604 |
25 Feb 19 |
nicklas |
if (!App.localStorage()) |
7604 |
25 Feb 19 |
nicklas |
76 |
{ |
7604 |
25 Feb 19 |
nicklas |
frm.remember_positions.checked = false; |
7604 |
25 Feb 19 |
nicklas |
frm.remember_positions.disabled = true; |
7604 |
25 Feb 19 |
nicklas |
Doc.element('rememberPositions').title = 'Your browser doesn\'t support this feature'; |
7604 |
25 Feb 19 |
nicklas |
Doc.addClass('rememberPositions', 'disabled'); |
7604 |
25 Feb 19 |
nicklas |
81 |
} |
7604 |
25 Feb 19 |
nicklas |
82 |
} |
7604 |
25 Feb 19 |
nicklas |
83 |
|
7604 |
25 Feb 19 |
nicklas |
// Validate the 'Appearance' tab |
7604 |
25 Feb 19 |
nicklas |
preferences.validateAppearance = function() |
7604 |
25 Feb 19 |
nicklas |
86 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['preferences']; |
7604 |
25 Feb 19 |
nicklas |
var scale = parseInt(frm.scale.value); |
7604 |
25 Feb 19 |
nicklas |
if (!Numbers.isInteger(frm.scale.value) || scale < 50 || scale > 200) |
7604 |
25 Feb 19 |
nicklas |
90 |
{ |
7604 |
25 Feb 19 |
nicklas |
Forms.showNotification(frm.scale, 'Please enter a scale value between 50 and 200.'); |
7604 |
25 Feb 19 |
nicklas |
return false; |
7604 |
25 Feb 19 |
nicklas |
93 |
} |
7604 |
25 Feb 19 |
nicklas |
return true; |
7604 |
25 Feb 19 |
nicklas |
95 |
} |
7604 |
25 Feb 19 |
nicklas |
96 |
|
7604 |
25 Feb 19 |
nicklas |
// Validate the 'Plugins' tab |
7604 |
25 Feb 19 |
nicklas |
preferences.validatePlugins = function() |
7604 |
25 Feb 19 |
nicklas |
99 |
{ |
7604 |
25 Feb 19 |
nicklas |
return true; |
7604 |
25 Feb 19 |
nicklas |
101 |
} |
7604 |
25 Feb 19 |
nicklas |
102 |
|
7604 |
25 Feb 19 |
nicklas |
// Validate the 'Recent items' tab |
7604 |
25 Feb 19 |
nicklas |
preferences.validateMostRecent = function() |
7604 |
25 Feb 19 |
nicklas |
105 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['preferences']; |
7604 |
25 Feb 19 |
nicklas |
var maxViewed = parseInt(frm.maxViewed.value); |
7604 |
25 Feb 19 |
nicklas |
if (!Numbers.isInteger(frm.maxViewed.value) || maxViewed < 0 || maxViewed > 10) |
7604 |
25 Feb 19 |
nicklas |
109 |
{ |
7604 |
25 Feb 19 |
nicklas |
Forms.showNotification(frm.maxViewed, 'Please enter a value between 0 and 10.'); |
7604 |
25 Feb 19 |
nicklas |
return false; |
7604 |
25 Feb 19 |
nicklas |
112 |
} |
7604 |
25 Feb 19 |
nicklas |
var maxUsed = parseInt(frm.maxUsed.value); |
7604 |
25 Feb 19 |
nicklas |
if (!Numbers.isInteger(frm.maxUsed.value) || maxUsed < 0 || maxUsed > 10) |
7604 |
25 Feb 19 |
nicklas |
115 |
{ |
7604 |
25 Feb 19 |
nicklas |
Forms.showNotification(frm.maxUsed, 'Please enter a value between 0 and 10.'); |
7604 |
25 Feb 19 |
nicklas |
return false; |
7604 |
25 Feb 19 |
nicklas |
118 |
} |
7604 |
25 Feb 19 |
nicklas |
return true; |
7604 |
25 Feb 19 |
nicklas |
120 |
} |
7604 |
25 Feb 19 |
nicklas |
121 |
|
7604 |
25 Feb 19 |
nicklas |
// Save the preferences |
7604 |
25 Feb 19 |
nicklas |
preferences.save = function() |
7604 |
25 Feb 19 |
nicklas |
124 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['preferences']; |
7604 |
25 Feb 19 |
nicklas |
if (TabControl.validateActiveTab('settings')) |
7604 |
25 Feb 19 |
nicklas |
127 |
{ |
7604 |
25 Feb 19 |
nicklas |
var sticky_items = frm.sticky_items; |
7604 |
25 Feb 19 |
nicklas |
for (var i = 0; i < sticky_items.length; i++) |
7604 |
25 Feb 19 |
nicklas |
130 |
{ |
7604 |
25 Feb 19 |
nicklas |
sticky_items.options[i].selected = true; |
7604 |
25 Feb 19 |
nicklas |
132 |
} |
7604 |
25 Feb 19 |
nicklas |
133 |
|
7604 |
25 Feb 19 |
nicklas |
if (initialRememberDialogPositions && !frm.remember_positions.checked) |
7604 |
25 Feb 19 |
nicklas |
135 |
{ |
7604 |
25 Feb 19 |
nicklas |
Dialogs.forgetDialogPositions(); |
7604 |
25 Feb 19 |
nicklas |
Data.set(document.body, 'no-dialog-position', 1); |
7604 |
25 Feb 19 |
nicklas |
138 |
} |
7604 |
25 Feb 19 |
nicklas |
139 |
|
7604 |
25 Feb 19 |
nicklas |
frm.submit(); |
7604 |
25 Feb 19 |
nicklas |
141 |
} |
7604 |
25 Feb 19 |
nicklas |
142 |
} |
7604 |
25 Feb 19 |
nicklas |
143 |
|
7604 |
25 Feb 19 |
nicklas |
144 |
|
7604 |
25 Feb 19 |
nicklas |
145 |
/** |
7604 |
25 Feb 19 |
nicklas |
Open a popup that allows the user to select a color for |
7604 |
25 Feb 19 |
nicklas |
the given field. |
7604 |
25 Feb 19 |
nicklas |
148 |
*/ |
7604 |
25 Feb 19 |
nicklas |
preferences.selectColorOnClick = function(event) |
7604 |
25 Feb 19 |
nicklas |
150 |
{ |
7604 |
25 Feb 19 |
nicklas |
var dialogTitle = Data.get(event.currentTarget, 'dialog-title'); |
7604 |
25 Feb 19 |
nicklas |
var colorBox = Data.get(event.currentTarget, 'color-box'); |
7604 |
25 Feb 19 |
nicklas |
Dialogs.openColorChart(colorBox, dialogTitle); |
7604 |
25 Feb 19 |
nicklas |
154 |
} |
7604 |
25 Feb 19 |
nicklas |
155 |
|
7604 |
25 Feb 19 |
nicklas |
156 |
/** |
7604 |
25 Feb 19 |
nicklas |
Event handler that update the visual color box |
7604 |
25 Feb 19 |
nicklas |
whenever the hidden rgb value is changed. |
7604 |
25 Feb 19 |
nicklas |
159 |
*/ |
7604 |
25 Feb 19 |
nicklas |
preferences.colorOnChange = function(event) |
7604 |
25 Feb 19 |
nicklas |
161 |
{ |
7604 |
25 Feb 19 |
nicklas |
var field = event.target.name; |
7604 |
25 Feb 19 |
nicklas |
var display = Doc.element(field+'.visual'); |
7604 |
25 Feb 19 |
nicklas |
display.style.background = '#' + event.target.value; |
7604 |
25 Feb 19 |
nicklas |
165 |
} |
7604 |
25 Feb 19 |
nicklas |
166 |
|
7604 |
25 Feb 19 |
nicklas |
167 |
/** |
7604 |
25 Feb 19 |
nicklas |
Set a color for the given field. |
7604 |
25 Feb 19 |
nicklas |
169 |
*/ |
7604 |
25 Feb 19 |
nicklas |
preferences.setColor = function(field, color) |
7604 |
25 Feb 19 |
nicklas |
171 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['preferences']; |
7604 |
25 Feb 19 |
nicklas |
frm[field].value = color; |
7604 |
25 Feb 19 |
nicklas |
var display = Doc.element(field+'.visual'); |
7604 |
25 Feb 19 |
nicklas |
display.style.background = '#' + color; |
7604 |
25 Feb 19 |
nicklas |
176 |
} |
7604 |
25 Feb 19 |
nicklas |
177 |
|
7604 |
25 Feb 19 |
nicklas |
178 |
/** |
7604 |
25 Feb 19 |
nicklas |
Event handler that update all 3 colors from a given preset. |
7604 |
25 Feb 19 |
nicklas |
180 |
*/ |
7604 |
25 Feb 19 |
nicklas |
preferences.colorPresetOnChange = function(event) |
7604 |
25 Feb 19 |
nicklas |
182 |
{ |
7604 |
25 Feb 19 |
nicklas |
var colors = event.target.value.split(','); |
7604 |
25 Feb 19 |
nicklas |
Preferences.setColor('mincolor', colors[0]); |
7604 |
25 Feb 19 |
nicklas |
Preferences.setColor('midcolor', colors[1]); |
7604 |
25 Feb 19 |
nicklas |
Preferences.setColor('maxcolor', colors[2]); |
7604 |
25 Feb 19 |
nicklas |
event.target.selectedIndex = 0; |
7604 |
25 Feb 19 |
nicklas |
188 |
} |
7604 |
25 Feb 19 |
nicklas |
189 |
|
7604 |
25 Feb 19 |
nicklas |
190 |
/** |
7604 |
25 Feb 19 |
nicklas |
Event handler that update the date format from a given preset. |
7604 |
25 Feb 19 |
nicklas |
192 |
*/ |
7604 |
25 Feb 19 |
nicklas |
preferences.datePresetOnChange = function(event) |
7604 |
25 Feb 19 |
nicklas |
194 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['preferences']; |
7604 |
25 Feb 19 |
nicklas |
frm.date_format.value = event.target.value; |
7604 |
25 Feb 19 |
nicklas |
event.target.selectedIndex = 0; |
7604 |
25 Feb 19 |
nicklas |
198 |
} |
7604 |
25 Feb 19 |
nicklas |
199 |
|
7604 |
25 Feb 19 |
nicklas |
200 |
/** |
7604 |
25 Feb 19 |
nicklas |
Event handler that update the date+time format from a given preset. |
7604 |
25 Feb 19 |
nicklas |
202 |
*/ |
7604 |
25 Feb 19 |
nicklas |
preferences.dateTimePresetOnChange = function(event) |
7604 |
25 Feb 19 |
nicklas |
204 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['preferences']; |
7604 |
25 Feb 19 |
nicklas |
frm.datetime_format.value = event.target.value; |
7604 |
25 Feb 19 |
nicklas |
event.target.selectedIndex = 0; |
7604 |
25 Feb 19 |
nicklas |
208 |
} |
7604 |
25 Feb 19 |
nicklas |
209 |
|
7604 |
25 Feb 19 |
nicklas |
210 |
/** |
7604 |
25 Feb 19 |
nicklas |
Set a new value for the 'scale' |
7604 |
25 Feb 19 |
nicklas |
212 |
*/ |
7604 |
25 Feb 19 |
nicklas |
preferences.fontSizeOnClick = function(event) |
7604 |
25 Feb 19 |
nicklas |
214 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['preferences']; |
7604 |
25 Feb 19 |
nicklas |
var newScale = Data.get(event.target, 'scale'); |
7604 |
25 Feb 19 |
nicklas |
frm.scale.value = newScale; |
7604 |
25 Feb 19 |
nicklas |
218 |
} |
7604 |
25 Feb 19 |
nicklas |
219 |
|
7604 |
25 Feb 19 |
nicklas |
220 |
/** |
7604 |
25 Feb 19 |
nicklas |
Move the selected options in the 'sticy items' list up or down. |
7604 |
25 Feb 19 |
nicklas |
222 |
*/ |
7604 |
25 Feb 19 |
nicklas |
preferences.moveStickyUpOrDown = function(event) |
7604 |
25 Feb 19 |
nicklas |
224 |
{ |
7604 |
25 Feb 19 |
nicklas |
var moveDown = Data.int(event.currentTarget, 'down'); |
7604 |
25 Feb 19 |
nicklas |
Forms.moveListOptions('stickyItems', moveDown); |
7604 |
25 Feb 19 |
nicklas |
227 |
} |
7604 |
25 Feb 19 |
nicklas |
228 |
|
7604 |
25 Feb 19 |
nicklas |
preferences.moveToSticky = function() |
7604 |
25 Feb 19 |
nicklas |
230 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['preferences']; |
7604 |
25 Feb 19 |
nicklas |
Forms.moveSelected(frm.all_items, frm.sticky_items); |
7604 |
25 Feb 19 |
nicklas |
233 |
} |
7604 |
25 Feb 19 |
nicklas |
234 |
|
7604 |
25 Feb 19 |
nicklas |
preferences.moveFromSticky = function() |
7604 |
25 Feb 19 |
nicklas |
236 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['preferences']; |
7604 |
25 Feb 19 |
nicklas |
Forms.moveSelected(frm.sticky_items, frm.all_items); |
7604 |
25 Feb 19 |
nicklas |
239 |
} |
7604 |
25 Feb 19 |
nicklas |
240 |
|
7604 |
25 Feb 19 |
nicklas |
return preferences; |
7604 |
25 Feb 19 |
nicklas |
242 |
}(); |
7604 |
25 Feb 19 |
nicklas |
243 |
|
7604 |
25 Feb 19 |
nicklas |
Doc.onLoad(Preferences.initPage); |
7604 |
25 Feb 19 |
nicklas |
245 |
|
7604 |
25 Feb 19 |
nicklas |
246 |
|