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 AnnotationTypes = function() |
7604 |
25 Feb 19 |
nicklas |
27 |
{ |
7604 |
25 Feb 19 |
nicklas |
var annotationTypes = {}; |
7604 |
25 Feb 19 |
nicklas |
29 |
|
7604 |
25 Feb 19 |
nicklas |
30 |
/** |
7604 |
25 Feb 19 |
nicklas |
Initialize the page. |
7604 |
25 Feb 19 |
nicklas |
32 |
*/ |
7604 |
25 Feb 19 |
nicklas |
annotationTypes.initPage = function() |
7604 |
25 Feb 19 |
nicklas |
34 |
{ |
7604 |
25 Feb 19 |
nicklas |
var pageId = Doc.getPageId(); |
7604 |
25 Feb 19 |
nicklas |
if (pageId == 'edit-page') |
7604 |
25 Feb 19 |
nicklas |
37 |
{ |
7604 |
25 Feb 19 |
nicklas |
// Save + Close buttons |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnSave', annotationTypes.save); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('close', App.closeWindow); |
7604 |
25 Feb 19 |
nicklas |
41 |
|
7604 |
25 Feb 19 |
nicklas |
// Tab validation |
7604 |
25 Feb 19 |
nicklas |
TabControl.addTabValidator('settings.info', annotationTypes.validateAnnotationType); |
7604 |
25 Feb 19 |
nicklas |
44 |
|
7604 |
25 Feb 19 |
nicklas |
// Options |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('interfaceBox', annotationTypes.interfaceOnClick); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('interfaceList', annotationTypes.interfaceOnClick); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('interfaceButtons', annotationTypes.interfaceOnClick); |
7604 |
25 Feb 19 |
nicklas |
annotationTypes.interfaceOnClick(); |
7604 |
25 Feb 19 |
nicklas |
50 |
|
7604 |
25 Feb 19 |
nicklas |
// Item type lists |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnMoveLeft', Forms.moveSelectedOnClick); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnMoveRight', Forms.moveSelectedOnClick); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('enabled', 'dblclick', Forms.moveSelectedOnClick); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('disabled', 'dblclick', Forms.moveSelectedOnClick); |
7604 |
25 Feb 19 |
nicklas |
56 |
|
7604 |
25 Feb 19 |
nicklas |
// Units |
7604 |
25 Feb 19 |
nicklas |
annotationTypes.initQuantities(); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('quantity_id', 'change', annotationTypes.quantityOnChange); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnAddUsableUnits', annotationTypes.addToUsableUnits); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('allUnits', 'dblclick', annotationTypes.addToUsableUnits); |
7604 |
25 Feb 19 |
nicklas |
62 |
} |
7604 |
25 Feb 19 |
nicklas |
else if (pageId == 'view-page') |
7604 |
25 Feb 19 |
nicklas |
64 |
{ |
7604 |
25 Feb 19 |
nicklas |
var itemId = Data.get('page-data', 'item-id'); |
7604 |
25 Feb 19 |
nicklas |
var attributes = {'item-type': 'ANNOTATIONTYPE', 'item-id': itemId}; |
7604 |
25 Feb 19 |
nicklas |
67 |
|
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnEdit', Buttons.editItem, attributes); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnDelete', Buttons.deleteItem, attributes); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnRestore', Buttons.restoreItem, attributes); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnUsingItems', Buttons.showUsingItems, attributes); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnDeletePermanently', Buttons.deleteItemPermanently, attributes); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnShare', Buttons.shareItem, attributes); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnSetOwner', Buttons.setOwner, attributes); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnExport', Buttons.runPlugin, attributes); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnImport', Buttons.runPlugin, attributes); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnRunPlugin', Buttons.runPlugin, attributes); |
7604 |
25 Feb 19 |
nicklas |
78 |
|
7604 |
25 Feb 19 |
nicklas |
TabControl.addTabActivateListener('main.history', History.loadOnce); |
7604 |
25 Feb 19 |
nicklas |
80 |
} |
7604 |
25 Feb 19 |
nicklas |
else if (pageId == 'list-page') |
7604 |
25 Feb 19 |
nicklas |
82 |
{ |
7604 |
25 Feb 19 |
nicklas |
var attributes = {'item-type': 'ANNOTATIONTYPE'}; |
7604 |
25 Feb 19 |
nicklas |
var tableAttributes = {'table-id': 'annotationTypes'}; |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('mnuNewAnnotationType', annotationTypes.newItem); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnDeleteItems', Buttons.deleteItems, tableAttributes); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnRestoreItems', Buttons.restoreItems, tableAttributes); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnShareItems', Buttons.shareItems, tableAttributes); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnSetOwner', Buttons.setOwnerOfItems, tableAttributes); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnColumns', Buttons.configureColumns, tableAttributes); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnExport', Buttons.runListPlugin, tableAttributes); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnImport', Buttons.runListPlugin, tableAttributes); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnRunPlugin', Buttons.runListPlugin, tableAttributes); |
7604 |
25 Feb 19 |
nicklas |
94 |
|
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('close', App.closeWindow); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnOk', Buttons.returnSelected, tableAttributes); |
7604 |
25 Feb 19 |
nicklas |
97 |
} |
7604 |
25 Feb 19 |
nicklas |
98 |
} |
7604 |
25 Feb 19 |
nicklas |
99 |
|
7604 |
25 Feb 19 |
nicklas |
annotationTypes.newItem = function(event) |
7604 |
25 Feb 19 |
nicklas |
101 |
{ |
7604 |
25 Feb 19 |
nicklas |
var valueType = Data.get(event.target, 'value-type'); |
7604 |
25 Feb 19 |
nicklas |
Items.newItem('ANNOTATIONTYPE', '&value_type='+valueType); |
7604 |
25 Feb 19 |
nicklas |
104 |
} |
7604 |
25 Feb 19 |
nicklas |
105 |
|
7604 |
25 Feb 19 |
nicklas |
annotationTypes.validateAnnotationType = function() |
7604 |
25 Feb 19 |
nicklas |
107 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['annotationType']; |
7604 |
25 Feb 19 |
nicklas |
if (Strings.trim(frm.name.value) == '') |
7604 |
25 Feb 19 |
nicklas |
110 |
{ |
7604 |
25 Feb 19 |
nicklas |
Forms.showNotification(frm.name, 'You must enter a name'); |
7604 |
25 Feb 19 |
nicklas |
return false; |
7604 |
25 Feb 19 |
nicklas |
113 |
} |
7604 |
25 Feb 19 |
nicklas |
return true; |
7604 |
25 Feb 19 |
nicklas |
115 |
} |
7604 |
25 Feb 19 |
nicklas |
116 |
|
7604 |
25 Feb 19 |
nicklas |
annotationTypes.save = function() |
7604 |
25 Feb 19 |
nicklas |
118 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['annotationType']; |
7604 |
25 Feb 19 |
nicklas |
if (TabControl.validateActiveTab('settings')) |
7604 |
25 Feb 19 |
nicklas |
121 |
{ |
7604 |
25 Feb 19 |
nicklas |
var enabled = frm.enabled; |
7604 |
25 Feb 19 |
nicklas |
for (var i = 0; i < enabled.length; i++) |
7604 |
25 Feb 19 |
nicklas |
124 |
{ |
7604 |
25 Feb 19 |
nicklas |
enabled.options[i].selected = true; |
7604 |
25 Feb 19 |
nicklas |
126 |
} |
7604 |
25 Feb 19 |
nicklas |
Link.exportActions('categories'); |
7604 |
25 Feb 19 |
nicklas |
if (Doc.element('usableUnits')) |
7604 |
25 Feb 19 |
nicklas |
129 |
{ |
7604 |
25 Feb 19 |
nicklas |
Link.exportActions('usableUnits'); |
7604 |
25 Feb 19 |
nicklas |
131 |
} |
7604 |
25 Feb 19 |
nicklas |
frm.project_annotations.disabled = false; |
7604 |
25 Feb 19 |
nicklas |
frm.submit(); |
7604 |
25 Feb 19 |
nicklas |
134 |
} |
7604 |
25 Feb 19 |
nicklas |
135 |
} |
7604 |
25 Feb 19 |
nicklas |
136 |
|
7604 |
25 Feb 19 |
nicklas |
annotationTypes.interfaceOnClick = function() |
7604 |
25 Feb 19 |
nicklas |
138 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['annotationType']; |
7604 |
25 Feb 19 |
nicklas |
if (frm['interface']) |
7604 |
25 Feb 19 |
nicklas |
141 |
{ |
7604 |
25 Feb 19 |
nicklas |
var isEnum = Forms.getCheckedRadio(frm['interface']).value != 'box'; |
7604 |
25 Feb 19 |
nicklas |
if (frm.minValue) frm.minValue.disabled = isEnum; |
7604 |
25 Feb 19 |
nicklas |
if (frm.maxValue) frm.maxValue.disabled = isEnum; |
7604 |
25 Feb 19 |
nicklas |
if (frm.width) frm.width.disabled = isEnum; |
7604 |
25 Feb 19 |
nicklas |
if (frm.maxLength) frm.maxLength.disabled = isEnum; |
7604 |
25 Feb 19 |
nicklas |
if (frm.values) frm.values.disabled = !isEnum; |
7604 |
25 Feb 19 |
nicklas |
148 |
} |
7604 |
25 Feb 19 |
nicklas |
149 |
} |
7604 |
25 Feb 19 |
nicklas |
150 |
|
7604 |
25 Feb 19 |
nicklas |
151 |
/** |
7604 |
25 Feb 19 |
nicklas |
Initialize the 'Quantities'. If a current |
7604 |
25 Feb 19 |
nicklas |
quantity is specified the 'Default unit' list is initialized |
7604 |
25 Feb 19 |
nicklas |
as well. |
7604 |
25 Feb 19 |
nicklas |
155 |
*/ |
7604 |
25 Feb 19 |
nicklas |
annotationTypes.initQuantities = function() |
7604 |
25 Feb 19 |
nicklas |
157 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['annotationType']; |
7604 |
25 Feb 19 |
nicklas |
var quantities = Data.json('page-data', 'units'); |
7604 |
25 Feb 19 |
nicklas |
var currentQuantityId = Data.int('page-data', 'current-quantity'); |
7604 |
25 Feb 19 |
nicklas |
161 |
|
7604 |
25 Feb 19 |
nicklas |
for (var i = 0; i < quantities.length; i++) |
7604 |
25 Feb 19 |
nicklas |
163 |
{ |
7604 |
25 Feb 19 |
nicklas |
var quantity = quantities[i]; |
7604 |
25 Feb 19 |
nicklas |
var option = new Option(quantity.name, quantity.id, false, quantity.id == currentQuantityId); |
7604 |
25 Feb 19 |
nicklas |
option.quantity = quantity; |
7604 |
25 Feb 19 |
nicklas |
frm.quantity_id[frm.quantity_id.length] = option; |
7604 |
25 Feb 19 |
nicklas |
168 |
} |
7604 |
25 Feb 19 |
nicklas |
169 |
|
7604 |
25 Feb 19 |
nicklas |
// Initialize units for the current quantity |
7604 |
25 Feb 19 |
nicklas |
if (currentQuantityId > 0) |
7604 |
25 Feb 19 |
nicklas |
172 |
{ |
7604 |
25 Feb 19 |
nicklas |
annotationTypes.quantityOnChange(); |
7604 |
25 Feb 19 |
nicklas |
174 |
} |
7604 |
25 Feb 19 |
nicklas |
175 |
} |
7604 |
25 Feb 19 |
nicklas |
176 |
|
7604 |
25 Feb 19 |
nicklas |
177 |
/** |
7604 |
25 Feb 19 |
nicklas |
If the selected quantity is changed, we need to update the list of |
7604 |
25 Feb 19 |
nicklas |
default units and also the two 'usable units' lists. |
7604 |
25 Feb 19 |
nicklas |
180 |
*/ |
7604 |
25 Feb 19 |
nicklas |
annotationTypes.quantityOnChange = function(event) |
7604 |
25 Feb 19 |
nicklas |
182 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['annotationType']; |
7604 |
25 Feb 19 |
nicklas |
var quantity = frm.quantity_id[frm.quantity_id.selectedIndex].quantity; |
7604 |
25 Feb 19 |
nicklas |
var currentUnitId = Data.int('page-data', 'current-unit'); |
7604 |
25 Feb 19 |
nicklas |
186 |
|
7604 |
25 Feb 19 |
nicklas |
// Update the default unit list with units from the selected quantity |
7604 |
25 Feb 19 |
nicklas |
frm.unit_id.length = 0; |
7604 |
25 Feb 19 |
nicklas |
frm.allUnits.length = 0; |
7604 |
25 Feb 19 |
nicklas |
190 |
|
7604 |
25 Feb 19 |
nicklas |
if (event) |
7604 |
25 Feb 19 |
nicklas |
192 |
{ |
7604 |
25 Feb 19 |
nicklas |
// Clear the 'usable units' list |
7604 |
25 Feb 19 |
nicklas |
Link.removeAll(frm.usableUnits); |
7604 |
25 Feb 19 |
nicklas |
195 |
} |
7604 |
25 Feb 19 |
nicklas |
196 |
|
7604 |
25 Feb 19 |
nicklas |
if (quantity) |
7604 |
25 Feb 19 |
nicklas |
198 |
{ |
7604 |
25 Feb 19 |
nicklas |
for (var i = 0; i < quantity.units.length; i++) |
7604 |
25 Feb 19 |
nicklas |
200 |
{ |
7604 |
25 Feb 19 |
nicklas |
var unit = quantity.units[i]; |
7604 |
25 Feb 19 |
nicklas |
var option = new Option(unit.name + ' [ '+unit.symbol+' ]', unit.id, false, currentUnitId == unit.id); |
7604 |
25 Feb 19 |
nicklas |
option.unit = unit; |
7604 |
25 Feb 19 |
nicklas |
frm.unit_id[frm.unit_id.length] = option; |
7604 |
25 Feb 19 |
nicklas |
205 |
|
7604 |
25 Feb 19 |
nicklas |
var addToAllUnits = true; |
7604 |
25 Feb 19 |
nicklas |
for (var j = 0; j < frm.usableUnits.length; j++) |
7604 |
25 Feb 19 |
nicklas |
208 |
{ |
7604 |
25 Feb 19 |
nicklas |
if (frm.usableUnits[j].value == 'UNIT.'+unit.id) |
7604 |
25 Feb 19 |
nicklas |
210 |
{ |
7604 |
25 Feb 19 |
nicklas |
addToAllUnits = false; |
7604 |
25 Feb 19 |
nicklas |
j = frm.usableUnits.length; |
7604 |
25 Feb 19 |
nicklas |
213 |
} |
7604 |
25 Feb 19 |
nicklas |
214 |
} |
7604 |
25 Feb 19 |
nicklas |
if (addToAllUnits) |
7604 |
25 Feb 19 |
nicklas |
216 |
{ |
7604 |
25 Feb 19 |
nicklas |
frm.allUnits[frm.allUnits.length] = new Option(unit.name + ' [ '+unit.symbol+' ]', unit.id); |
7604 |
25 Feb 19 |
nicklas |
218 |
} |
7604 |
25 Feb 19 |
nicklas |
219 |
} |
7604 |
25 Feb 19 |
nicklas |
220 |
} |
7604 |
25 Feb 19 |
nicklas |
221 |
} |
7604 |
25 Feb 19 |
nicklas |
222 |
|
7604 |
25 Feb 19 |
nicklas |
223 |
/** |
7604 |
25 Feb 19 |
nicklas |
Event handler for adding selected units from the 'All units' list to |
7604 |
25 Feb 19 |
nicklas |
the 'Usable units' list. |
7604 |
25 Feb 19 |
nicklas |
226 |
*/ |
7604 |
25 Feb 19 |
nicklas |
annotationTypes.addToUsableUnits = function(event) |
7604 |
25 Feb 19 |
nicklas |
228 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['annotationType']; |
7604 |
25 Feb 19 |
nicklas |
for (var i = 0; i < frm.allUnits.length; i++) |
7604 |
25 Feb 19 |
nicklas |
231 |
{ |
7604 |
25 Feb 19 |
nicklas |
var option = frm.allUnits[i]; |
7604 |
25 Feb 19 |
nicklas |
if (option.selected) |
7604 |
25 Feb 19 |
nicklas |
234 |
{ |
7604 |
25 Feb 19 |
nicklas |
Link.addItem(frm.usableUnits, 'UNIT', {'id': option.value, 'name': option.text }); |
7604 |
25 Feb 19 |
nicklas |
frm.allUnits[i--] = null; |
7604 |
25 Feb 19 |
nicklas |
237 |
} |
7604 |
25 Feb 19 |
nicklas |
238 |
} |
7604 |
25 Feb 19 |
nicklas |
239 |
} |
7604 |
25 Feb 19 |
nicklas |
240 |
|
7604 |
25 Feb 19 |
nicklas |
return annotationTypes; |
7604 |
25 Feb 19 |
nicklas |
242 |
}(); |
7604 |
25 Feb 19 |
nicklas |
243 |
|
7604 |
25 Feb 19 |
nicklas |
if (Doc.getPageId() == 'edit-page') |
7604 |
25 Feb 19 |
nicklas |
245 |
{ |
7604 |
25 Feb 19 |
nicklas |
Doc.addElementInitializer(Forms.numberOnlyInitializer); |
7604 |
25 Feb 19 |
nicklas |
247 |
} |
7604 |
25 Feb 19 |
nicklas |
Doc.onLoad(AnnotationTypes.initPage); |