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 Settings = function() |
7604 |
25 Feb 19 |
nicklas |
27 |
{ |
7604 |
25 Feb 19 |
nicklas |
var extendedProperties = null; |
7604 |
25 Feb 19 |
nicklas |
29 |
|
7604 |
25 Feb 19 |
nicklas |
var settings = {}; |
7604 |
25 Feb 19 |
nicklas |
31 |
|
7604 |
25 Feb 19 |
nicklas |
settings.initPage = function() |
7604 |
25 Feb 19 |
nicklas |
33 |
{ |
7604 |
25 Feb 19 |
nicklas |
// Save + Close buttons |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnSave', Settings.save); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('close', App.closeWindow); |
7604 |
25 Feb 19 |
nicklas |
37 |
|
7604 |
25 Feb 19 |
nicklas |
// Tab validation |
7604 |
25 Feb 19 |
nicklas |
TabControl.addTabValidator('settings.contact', Settings.validateContact); |
7604 |
25 Feb 19 |
nicklas |
TabControl.addTabValidator('settings.password', Settings.validatePassword); |
7604 |
25 Feb 19 |
nicklas |
TabControl.addTabValidator('settings.other', Settings.validateExtendedProperties); |
7604 |
25 Feb 19 |
nicklas |
42 |
|
7604 |
25 Feb 19 |
nicklas |
// Extended properties |
7604 |
25 Feb 19 |
nicklas |
var pageData = Doc.element('page-data'); |
7604 |
25 Feb 19 |
nicklas |
extendedProperties = Data.json(pageData, 'extended-properties'); |
7604 |
25 Feb 19 |
nicklas |
for (var i = 0; i < extendedProperties.length; i++) |
7604 |
25 Feb 19 |
nicklas |
47 |
{ |
7604 |
25 Feb 19 |
nicklas |
var ep = extendedProperties[i]; |
7604 |
25 Feb 19 |
nicklas |
var valueType = ep.valueType; |
7604 |
25 Feb 19 |
nicklas |
var fieldName = 'ep.'+ep.name; |
7604 |
25 Feb 19 |
nicklas |
51 |
|
7604 |
25 Feb 19 |
nicklas |
if (valueType == 'INT' || valueType == 'LONG') |
7604 |
25 Feb 19 |
nicklas |
53 |
{ |
7604 |
25 Feb 19 |
nicklas |
// Block non-numeric keys from INT and LONG fields |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler(fieldName, 'keypress', Events.integerOnly); |
7604 |
25 Feb 19 |
nicklas |
56 |
} |
7604 |
25 Feb 19 |
nicklas |
else if (valueType == 'FLOAT' || valueType == 'DOUBLE') |
7604 |
25 Feb 19 |
nicklas |
58 |
{ |
7604 |
25 Feb 19 |
nicklas |
// Block non-numeric keys from FLOAT and DOUBLE fields |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler(fieldName, 'keypress', Events.numberOnly); |
7604 |
25 Feb 19 |
nicklas |
61 |
} |
7604 |
25 Feb 19 |
nicklas |
else if (valueType == 'DATE' || valueType == 'TIMESTAMP') |
7604 |
25 Feb 19 |
nicklas |
63 |
{ |
7604 |
25 Feb 19 |
nicklas |
// Add click handler to open calendar dialog for date/timestamp fields |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btn.'+fieldName, settings.openCalendar); |
7604 |
25 Feb 19 |
nicklas |
66 |
} |
7604 |
25 Feb 19 |
nicklas |
67 |
} |
7604 |
25 Feb 19 |
nicklas |
68 |
} |
7604 |
25 Feb 19 |
nicklas |
69 |
|
7604 |
25 Feb 19 |
nicklas |
// Open the calendar dialog |
7604 |
25 Feb 19 |
nicklas |
settings.openCalendar = function(event) |
7604 |
25 Feb 19 |
nicklas |
72 |
{ |
7604 |
25 Feb 19 |
nicklas |
var epName = Data.get(event.currentTarget, 'extended-property'); |
7604 |
25 Feb 19 |
nicklas |
var ep = null; |
7604 |
25 Feb 19 |
nicklas |
for (var i = 0; i < extendedProperties.length; i++) |
7604 |
25 Feb 19 |
nicklas |
76 |
{ |
7604 |
25 Feb 19 |
nicklas |
if (extendedProperties[i].name == epName) |
7604 |
25 Feb 19 |
nicklas |
78 |
{ |
7604 |
25 Feb 19 |
nicklas |
ep = extendedProperties[i]; |
7604 |
25 Feb 19 |
nicklas |
i = extendedProperties.length; |
7604 |
25 Feb 19 |
nicklas |
81 |
} |
7604 |
25 Feb 19 |
nicklas |
82 |
} |
7604 |
25 Feb 19 |
nicklas |
if (ep==null) return; |
7604 |
25 Feb 19 |
nicklas |
84 |
|
7604 |
25 Feb 19 |
nicklas |
var textarea = 'ep.'+ep.name; |
7604 |
25 Feb 19 |
nicklas |
var title = ep.title; |
7604 |
25 Feb 19 |
nicklas |
var useTime = ep.valueType != 'TIMESTAMP'; |
7604 |
25 Feb 19 |
nicklas |
var format = Data.get('page-data', useTime ? 'datetime-format' : 'date-format'); |
7604 |
25 Feb 19 |
nicklas |
Dialogs.openCalendar(textarea, title, format, useTime); |
7604 |
25 Feb 19 |
nicklas |
90 |
} |
7604 |
25 Feb 19 |
nicklas |
91 |
|
7604 |
25 Feb 19 |
nicklas |
// Validate the 'Contact information' tab |
7604 |
25 Feb 19 |
nicklas |
settings.validateContact = function() |
7604 |
25 Feb 19 |
nicklas |
94 |
{ |
7604 |
25 Feb 19 |
nicklas |
return true; |
7604 |
25 Feb 19 |
nicklas |
96 |
} |
7604 |
25 Feb 19 |
nicklas |
97 |
|
7604 |
25 Feb 19 |
nicklas |
// Validate the 'Password' tab |
7604 |
25 Feb 19 |
nicklas |
settings.validatePassword = function() |
7604 |
25 Feb 19 |
nicklas |
100 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['user']; |
7604 |
25 Feb 19 |
nicklas |
if (frm.password.value != frm.retype_password.value) |
7604 |
25 Feb 19 |
nicklas |
103 |
{ |
7604 |
25 Feb 19 |
nicklas |
Forms.showNotification(frm.retype_password, 'The two passwords do not match'); |
7604 |
25 Feb 19 |
nicklas |
return false; |
7604 |
25 Feb 19 |
nicklas |
106 |
} |
7604 |
25 Feb 19 |
nicklas |
return true; |
7604 |
25 Feb 19 |
nicklas |
108 |
} |
7604 |
25 Feb 19 |
nicklas |
109 |
|
7604 |
25 Feb 19 |
nicklas |
// Validate the 'Other information' tab with extended properties |
7604 |
25 Feb 19 |
nicklas |
settings.validateExtendedProperties = function() |
7604 |
25 Feb 19 |
nicklas |
112 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['user']; |
7604 |
25 Feb 19 |
nicklas |
var pageData = Doc.element('page-data'); |
7604 |
25 Feb 19 |
nicklas |
var dateFormat = Data.get(pageData, 'date-format'); |
7604 |
25 Feb 19 |
nicklas |
var dateTimeFormat = Data.get(pageData, 'datetime-format'); |
7604 |
25 Feb 19 |
nicklas |
117 |
|
7604 |
25 Feb 19 |
nicklas |
for (var i = 0; i < extendedProperties.length; i++) |
7604 |
25 Feb 19 |
nicklas |
119 |
{ |
7604 |
25 Feb 19 |
nicklas |
var ep = extendedProperties[i]; |
7604 |
25 Feb 19 |
nicklas |
var valueType = ep.valueType; |
7604 |
25 Feb 19 |
nicklas |
var field = frm['ep.'+ep.name]; |
7604 |
25 Feb 19 |
nicklas |
123 |
|
7604 |
25 Feb 19 |
nicklas |
if (ep.valueType == 'DATE') |
7604 |
25 Feb 19 |
nicklas |
125 |
{ |
7604 |
25 Feb 19 |
nicklas |
if (field.value != '' && !Dates.isDate(field.value, dateFormat)) |
7604 |
25 Feb 19 |
nicklas |
127 |
{ |
7604 |
25 Feb 19 |
nicklas |
Forms.showNotification(field, "'"+field.value+"' is not a valid date for '" + ep.title + "'"); |
7604 |
25 Feb 19 |
nicklas |
return false; |
7604 |
25 Feb 19 |
nicklas |
130 |
} |
7604 |
25 Feb 19 |
nicklas |
131 |
} |
7604 |
25 Feb 19 |
nicklas |
else if (ep.valueType == 'TIMESTAMP') |
7604 |
25 Feb 19 |
nicklas |
133 |
{ |
7604 |
25 Feb 19 |
nicklas |
if (field.value != '' && !Dates.isDate(field.value, dateTimeFormat)) |
7604 |
25 Feb 19 |
nicklas |
135 |
{ |
7604 |
25 Feb 19 |
nicklas |
Forms.showNotification(field, "'"+field.value+"' is not a valid timestamp for '" + ep.title + "'"); |
7604 |
25 Feb 19 |
nicklas |
return false; |
7604 |
25 Feb 19 |
nicklas |
138 |
} |
7604 |
25 Feb 19 |
nicklas |
139 |
} |
7604 |
25 Feb 19 |
nicklas |
if (!ep.nullable) |
7604 |
25 Feb 19 |
nicklas |
141 |
{ |
7604 |
25 Feb 19 |
nicklas |
if (ep.valueType == 'BOOLEAN') |
7604 |
25 Feb 19 |
nicklas |
143 |
{ |
7604 |
25 Feb 19 |
nicklas |
if (Forms.getCheckedRadio(field) == null) |
7604 |
25 Feb 19 |
nicklas |
145 |
{ |
7604 |
25 Feb 19 |
nicklas |
Forms.showNotification(field[0], "You must select a value for '" + ep.title + "'"); |
7604 |
25 Feb 19 |
nicklas |
return false; |
7604 |
25 Feb 19 |
nicklas |
148 |
} |
7604 |
25 Feb 19 |
nicklas |
149 |
} |
7604 |
25 Feb 19 |
nicklas |
else |
7604 |
25 Feb 19 |
nicklas |
151 |
{ |
7604 |
25 Feb 19 |
nicklas |
if (Strings.trim(field.value) == '') |
7604 |
25 Feb 19 |
nicklas |
153 |
{ |
7604 |
25 Feb 19 |
nicklas |
Forms.showNotification(field, "You must enter a value for '" + ep.title + "'"); |
7604 |
25 Feb 19 |
nicklas |
return false; |
7604 |
25 Feb 19 |
nicklas |
156 |
} |
7604 |
25 Feb 19 |
nicklas |
157 |
} |
7604 |
25 Feb 19 |
nicklas |
158 |
} |
7604 |
25 Feb 19 |
nicklas |
159 |
} |
7604 |
25 Feb 19 |
nicklas |
return true; |
7604 |
25 Feb 19 |
nicklas |
161 |
} |
7604 |
25 Feb 19 |
nicklas |
162 |
|
7604 |
25 Feb 19 |
nicklas |
settings.save = function() |
7604 |
25 Feb 19 |
nicklas |
164 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['user']; |
7604 |
25 Feb 19 |
nicklas |
if (TabControl.validateActiveTab('settings')) |
7604 |
25 Feb 19 |
nicklas |
167 |
{ |
7604 |
25 Feb 19 |
nicklas |
frm.submit(); |
7604 |
25 Feb 19 |
nicklas |
169 |
} |
7604 |
25 Feb 19 |
nicklas |
170 |
} |
7604 |
25 Feb 19 |
nicklas |
171 |
|
7604 |
25 Feb 19 |
nicklas |
return settings; |
7604 |
25 Feb 19 |
nicklas |
173 |
}(); |
7604 |
25 Feb 19 |
nicklas |
174 |
|
6166 |
11 Oct 12 |
nicklas |
Doc.onLoad(Settings.initPage); |