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 SubTypes = function() |
7604 |
25 Feb 19 |
nicklas |
27 |
{ |
7604 |
25 Feb 19 |
nicklas |
var subTypes = {}; |
7604 |
25 Feb 19 |
nicklas |
var itemTypes; |
7604 |
25 Feb 19 |
nicklas |
var itemInfo; |
7604 |
25 Feb 19 |
nicklas |
31 |
|
7604 |
25 Feb 19 |
nicklas |
32 |
/** |
7604 |
25 Feb 19 |
nicklas |
Initialize the page. |
7604 |
25 Feb 19 |
nicklas |
34 |
*/ |
7604 |
25 Feb 19 |
nicklas |
subTypes.initPage = function() |
7604 |
25 Feb 19 |
nicklas |
36 |
{ |
7604 |
25 Feb 19 |
nicklas |
var pageId = Doc.getPageId(); |
7604 |
25 Feb 19 |
nicklas |
if (pageId == 'edit-page') |
7604 |
25 Feb 19 |
nicklas |
39 |
{ |
7604 |
25 Feb 19 |
nicklas |
// Load info about subtype relationships and capabilities |
7604 |
25 Feb 19 |
nicklas |
itemInfo = Data.json('page-data', 'item-info'); |
7604 |
25 Feb 19 |
nicklas |
itemTypes = Data.json('page-data', 'item-types'); |
7604 |
25 Feb 19 |
nicklas |
43 |
|
7604 |
25 Feb 19 |
nicklas |
// Save + Close buttons |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnSave', subTypes.save); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('close', App.closeWindow); |
7604 |
25 Feb 19 |
nicklas |
47 |
|
7604 |
25 Feb 19 |
nicklas |
// Tab validation |
7604 |
25 Feb 19 |
nicklas |
TabControl.addTabValidator('settings.info', subTypes.validateItemSubtype); |
7604 |
25 Feb 19 |
nicklas |
50 |
|
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('itemType', 'change', subTypes.itemTypeOnChange); |
7604 |
25 Feb 19 |
nicklas |
52 |
|
7604 |
25 Feb 19 |
nicklas |
// Associated subtypes |
7604 |
25 Feb 19 |
nicklas |
for (var i=0; i < itemTypes.length; i++) |
7604 |
25 Feb 19 |
nicklas |
55 |
{ |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('related.'+itemTypes[i]+'.select', subTypes.relatedItemOnClick) |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('related.'+itemTypes[i], 'base-selected', Items.onItemSelected); |
7604 |
25 Feb 19 |
nicklas |
58 |
} |
7604 |
25 Feb 19 |
nicklas |
subTypes.itemTypeOnChange(); |
7604 |
25 Feb 19 |
nicklas |
60 |
|
7604 |
25 Feb 19 |
nicklas |
// File types |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnAddFileTypes', subTypes.addFileTypesOnClick); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('btnAddFileTypes', 'base-selected', subTypes.fileTypeSelected); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('fileTypes', 'change', subTypes.fileTypesOnChange); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('required', subTypes.requiredOnClick); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('multiple', subTypes.requiredOnClick); |
7604 |
25 Feb 19 |
nicklas |
67 |
} |
7604 |
25 Feb 19 |
nicklas |
else if (pageId == 'view-page') |
7604 |
25 Feb 19 |
nicklas |
69 |
{ |
7604 |
25 Feb 19 |
nicklas |
var itemId = Data.get('page-data', 'item-id'); |
7604 |
25 Feb 19 |
nicklas |
var attributes = {'item-type': 'ITEMSUBTYPE', 'item-id': itemId}; |
7604 |
25 Feb 19 |
nicklas |
72 |
|
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('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 |
81 |
} |
7604 |
25 Feb 19 |
nicklas |
else if (pageId == 'list-page') |
7604 |
25 Feb 19 |
nicklas |
83 |
{ |
7604 |
25 Feb 19 |
nicklas |
var attributes = {'item-type': 'ITEMSUBTYPE'}; |
7604 |
25 Feb 19 |
nicklas |
var tableAttributes = {'table-id': 'subtypes'}; |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnNewItem', Buttons.newItem, attributes); |
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('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 |
93 |
|
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 |
96 |
} |
7604 |
25 Feb 19 |
nicklas |
97 |
} |
7604 |
25 Feb 19 |
nicklas |
98 |
|
7604 |
25 Feb 19 |
nicklas |
subTypes.validateItemSubtype = function() |
7604 |
25 Feb 19 |
nicklas |
100 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['subtype']; |
7604 |
25 Feb 19 |
nicklas |
if (Strings.trim(frm.name.value) == '') |
7604 |
25 Feb 19 |
nicklas |
103 |
{ |
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 |
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 |
// Submit the form |
7604 |
25 Feb 19 |
nicklas |
subTypes.save = function() |
7604 |
25 Feb 19 |
nicklas |
112 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['subtype']; |
7604 |
25 Feb 19 |
nicklas |
if (TabControl.validateActiveTab('settings')) |
7604 |
25 Feb 19 |
nicklas |
115 |
{ |
7604 |
25 Feb 19 |
nicklas |
Link.exportActions('fileTypes'); |
7604 |
25 Feb 19 |
nicklas |
frm.submit(); |
7604 |
25 Feb 19 |
nicklas |
118 |
} |
7604 |
25 Feb 19 |
nicklas |
119 |
} |
7604 |
25 Feb 19 |
nicklas |
120 |
|
7604 |
25 Feb 19 |
nicklas |
121 |
/** |
7604 |
25 Feb 19 |
nicklas |
Get the current main item type of the subtype that is being |
7604 |
25 Feb 19 |
nicklas |
edited. For existing items, this is stored in the 'page-data' tag, |
7604 |
25 Feb 19 |
nicklas |
for new items, the current selection from the 'itemType' list |
7604 |
25 Feb 19 |
nicklas |
is used. |
7604 |
25 Feb 19 |
nicklas |
126 |
*/ |
7604 |
25 Feb 19 |
nicklas |
subTypes.getCurrentItemType = function() |
7604 |
25 Feb 19 |
nicklas |
128 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['subtype']; |
7604 |
25 Feb 19 |
nicklas |
var itemType = Data.get('page-data', 'main-item-type'); |
7604 |
25 Feb 19 |
nicklas |
if (!itemType) |
7604 |
25 Feb 19 |
nicklas |
132 |
{ |
7604 |
25 Feb 19 |
nicklas |
itemType = frm.itemType.value; |
7604 |
25 Feb 19 |
nicklas |
134 |
} |
7604 |
25 Feb 19 |
nicklas |
return itemType; |
7604 |
25 Feb 19 |
nicklas |
136 |
} |
7604 |
25 Feb 19 |
nicklas |
137 |
|
7604 |
25 Feb 19 |
nicklas |
138 |
/** |
7604 |
25 Feb 19 |
nicklas |
Event handler called when changing the main item type. This |
7604 |
25 Feb 19 |
nicklas |
hide or show other 'related subtypes' sections depending on |
7604 |
25 Feb 19 |
nicklas |
which other item types that can be associated with the main |
7604 |
25 Feb 19 |
nicklas |
item type. |
7604 |
25 Feb 19 |
nicklas |
143 |
*/ |
7604 |
25 Feb 19 |
nicklas |
subTypes.itemTypeOnChange = function() |
7604 |
25 Feb 19 |
nicklas |
145 |
{ |
7604 |
25 Feb 19 |
nicklas |
var itemType = subTypes.getCurrentItemType(); |
7604 |
25 Feb 19 |
nicklas |
147 |
|
7604 |
25 Feb 19 |
nicklas |
for (var i = 0; i < itemTypes.length; i++) |
7604 |
25 Feb 19 |
nicklas |
149 |
{ |
7604 |
25 Feb 19 |
nicklas |
var item = itemTypes[i]; |
7604 |
25 Feb 19 |
nicklas |
Doc.showHide('section.'+item, itemInfo[itemType].related.indexOf(item) >= 0) |
7604 |
25 Feb 19 |
nicklas |
152 |
} |
7604 |
25 Feb 19 |
nicklas |
Doc.showHide('section.none', itemInfo[itemType].related.length == 0); |
7604 |
25 Feb 19 |
nicklas |
154 |
|
7604 |
25 Feb 19 |
nicklas |
if (itemInfo[itemType].fileStoreEnabled) |
7604 |
25 Feb 19 |
nicklas |
156 |
{ |
7604 |
25 Feb 19 |
nicklas |
Doc.show('filetypes.enabled'); |
7604 |
25 Feb 19 |
nicklas |
Doc.hide('filetypes.disabled'); |
7604 |
25 Feb 19 |
nicklas |
159 |
} |
7604 |
25 Feb 19 |
nicklas |
else |
7604 |
25 Feb 19 |
nicklas |
161 |
{ |
7604 |
25 Feb 19 |
nicklas |
Doc.hide('filetypes.enabled'); |
7604 |
25 Feb 19 |
nicklas |
Doc.show('filetypes.disabled'); |
7604 |
25 Feb 19 |
nicklas |
Doc.element('filetypes.disabled').innerHTML = '<div class="messagecontainer error">The selected main item type (' + itemType + ') has not support for attaching data files.</div>'; |
7604 |
25 Feb 19 |
nicklas |
165 |
} |
7604 |
25 Feb 19 |
nicklas |
Doc.showHide('section.pushAnnotations', itemInfo[itemType].supportsPushAnnotations); |
7604 |
25 Feb 19 |
nicklas |
167 |
} |
7604 |
25 Feb 19 |
nicklas |
168 |
|
7604 |
25 Feb 19 |
nicklas |
169 |
/** |
7604 |
25 Feb 19 |
nicklas |
Click handler for opening a popup window for selecting a |
7604 |
25 Feb 19 |
nicklas |
related item subtype. |
7604 |
25 Feb 19 |
nicklas |
172 |
*/ |
7604 |
25 Feb 19 |
nicklas |
subTypes.relatedItemOnClick = function(event) |
7604 |
25 Feb 19 |
nicklas |
174 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['subtype']; |
7604 |
25 Feb 19 |
nicklas |
var listName = Data.get(event.currentTarget, 'list-name'); |
7604 |
25 Feb 19 |
nicklas |
var itemType = Data.get(listName, 'item-type'); |
7604 |
25 Feb 19 |
nicklas |
178 |
|
7604 |
25 Feb 19 |
nicklas |
var url = '&resetTemporary=1&tmpfilter:INT:itemType=' + itemInfo[itemType].value; |
7604 |
25 Feb 19 |
nicklas |
if (frm[listName].length > 1) |
7604 |
25 Feb 19 |
nicklas |
181 |
{ |
7604 |
25 Feb 19 |
nicklas |
var id = Math.abs(parseInt(frm[listName].value)); |
7604 |
25 Feb 19 |
nicklas |
url += '&item_id='+id; |
7604 |
25 Feb 19 |
nicklas |
184 |
} |
7604 |
25 Feb 19 |
nicklas |
url += '&exclude='+Data.get('page-data', 'subtype-id'); |
7604 |
25 Feb 19 |
nicklas |
Dialogs.selectItem('ITEMSUBTYPE', listName, 0, url); |
7604 |
25 Feb 19 |
nicklas |
187 |
} |
7604 |
25 Feb 19 |
nicklas |
188 |
|
7604 |
25 Feb 19 |
nicklas |
189 |
/** |
7604 |
25 Feb 19 |
nicklas |
Open a popup dialog for selecting related file types. |
7604 |
25 Feb 19 |
nicklas |
191 |
*/ |
7604 |
25 Feb 19 |
nicklas |
subTypes.addFileTypesOnClick = function(event) |
7604 |
25 Feb 19 |
nicklas |
193 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['subtype']; |
7604 |
25 Feb 19 |
nicklas |
var itemType = subTypes.getCurrentItemType(); |
7604 |
25 Feb 19 |
nicklas |
var currentFileTypes = Link.getIdsInList(frm.fileTypes, 'DATAFILETYPE'); |
7604 |
25 Feb 19 |
nicklas |
var excludes = currentFileTypes.join(','); |
7604 |
25 Feb 19 |
nicklas |
var url = '&resetTemporary=1&tmpfilter:INT:itemType=' + itemInfo[itemType].value; |
7604 |
25 Feb 19 |
nicklas |
url += "&exclude="+excludes; |
7604 |
25 Feb 19 |
nicklas |
Dialogs.selectItem('DATAFILETYPE', event.currentTarget.id, 1, url); |
7604 |
25 Feb 19 |
nicklas |
201 |
} |
7604 |
25 Feb 19 |
nicklas |
202 |
|
7604 |
25 Feb 19 |
nicklas |
203 |
/** |
7604 |
25 Feb 19 |
nicklas |
Callback for adding selected file types to the list. |
7604 |
25 Feb 19 |
nicklas |
205 |
*/ |
7604 |
25 Feb 19 |
nicklas |
subTypes.fileTypeSelected = function(event) |
7604 |
25 Feb 19 |
nicklas |
207 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['subtype']; |
7604 |
25 Feb 19 |
nicklas |
var required = frm.required.checked; |
7604 |
25 Feb 19 |
nicklas |
var multiple = frm.multiple.checked; |
7604 |
25 Feb 19 |
nicklas |
211 |
|
7604 |
25 Feb 19 |
nicklas |
var detail = event.detail; |
7604 |
25 Feb 19 |
nicklas |
var newValue = 0; |
7604 |
25 Feb 19 |
nicklas |
if (required) newValue += 1; |
7604 |
25 Feb 19 |
nicklas |
if (multiple) newValue += 2; |
7604 |
25 Feb 19 |
nicklas |
216 |
|
7604 |
25 Feb 19 |
nicklas |
detail.name += required ? ' [×]' : ' [-]'; |
7604 |
25 Feb 19 |
nicklas |
detail.value = newValue; |
7604 |
25 Feb 19 |
nicklas |
219 |
|
7604 |
25 Feb 19 |
nicklas |
Link.addItem('fileTypes', 'DATAFILETYPE', event.detail); |
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 when a file type is selected that update the 'require' and |
7604 |
25 Feb 19 |
nicklas |
'multiple' checkboxes with the current status. |
7604 |
25 Feb 19 |
nicklas |
226 |
*/ |
7604 |
25 Feb 19 |
nicklas |
subTypes.fileTypesOnChange = function() |
7604 |
25 Feb 19 |
nicklas |
228 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['subtype']; |
7604 |
25 Feb 19 |
nicklas |
var item = frm.fileTypes[frm.fileTypes.selectedIndex].item; |
7604 |
25 Feb 19 |
nicklas |
if (item && item.id) |
7604 |
25 Feb 19 |
nicklas |
232 |
{ |
7604 |
25 Feb 19 |
nicklas |
frm.required.checked = (item.value & 1) > 0; |
7604 |
25 Feb 19 |
nicklas |
frm.multiple.checked = (item.value & 2) > 0; |
7604 |
25 Feb 19 |
nicklas |
235 |
} |
7604 |
25 Feb 19 |
nicklas |
else |
7604 |
25 Feb 19 |
nicklas |
237 |
{ |
7604 |
25 Feb 19 |
nicklas |
frm.required.checked = false; |
7604 |
25 Feb 19 |
nicklas |
frm.multiple.checked = false; |
7604 |
25 Feb 19 |
nicklas |
240 |
} |
7604 |
25 Feb 19 |
nicklas |
241 |
} |
7604 |
25 Feb 19 |
nicklas |
242 |
|
7604 |
25 Feb 19 |
nicklas |
243 |
/** |
7604 |
25 Feb 19 |
nicklas |
Event handler for the 'required' and 'multiple' checkboxes that update |
7604 |
25 Feb 19 |
nicklas |
the status for the selected file types in the list. |
7604 |
25 Feb 19 |
nicklas |
246 |
*/ |
7604 |
25 Feb 19 |
nicklas |
subTypes.requiredOnClick = function() |
7604 |
25 Feb 19 |
nicklas |
248 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['subtype']; |
7604 |
25 Feb 19 |
nicklas |
var required = frm.required.checked; |
7604 |
25 Feb 19 |
nicklas |
var multiple = frm.multiple.checked; |
7604 |
25 Feb 19 |
nicklas |
var newValue = 0; |
7604 |
25 Feb 19 |
nicklas |
if (required) newValue += 1; |
7604 |
25 Feb 19 |
nicklas |
if (multiple) newValue += 2; |
7604 |
25 Feb 19 |
nicklas |
for (var i = 0; i < frm.fileTypes.length; i++) |
7604 |
25 Feb 19 |
nicklas |
256 |
{ |
7604 |
25 Feb 19 |
nicklas |
var option = frm.fileTypes[i]; |
7604 |
25 Feb 19 |
nicklas |
if (option.selected && option.item.id) |
7604 |
25 Feb 19 |
nicklas |
259 |
{ |
7604 |
25 Feb 19 |
nicklas |
option.item.value = newValue; |
7604 |
25 Feb 19 |
nicklas |
var text = option.text.replace(/\[.*\]/, '['+(required ? '×' : '-') +']'); |
7604 |
25 Feb 19 |
nicklas |
option.text = text; |
7604 |
25 Feb 19 |
nicklas |
263 |
} |
7604 |
25 Feb 19 |
nicklas |
264 |
} |
7604 |
25 Feb 19 |
nicklas |
265 |
} |
7604 |
25 Feb 19 |
nicklas |
266 |
|
7604 |
25 Feb 19 |
nicklas |
267 |
|
7604 |
25 Feb 19 |
nicklas |
return subTypes; |
7604 |
25 Feb 19 |
nicklas |
269 |
}(); |
7604 |
25 Feb 19 |
nicklas |
270 |
|
7604 |
25 Feb 19 |
nicklas |
Doc.onLoad(SubTypes.initPage); |