7604 |
25 Feb 19 |
nicklas |
/* $Id $ |
7604 |
25 Feb 19 |
nicklas |
2 |
------------------------------------------------------------------ |
7604 |
25 Feb 19 |
nicklas |
Copyright (C) 2013 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 DataFiles = function() |
7604 |
25 Feb 19 |
nicklas |
27 |
{ |
7604 |
25 Feb 19 |
nicklas |
var datafiles = {}; |
7604 |
25 Feb 19 |
nicklas |
var internal = {}; |
7604 |
25 Feb 19 |
nicklas |
30 |
|
7604 |
25 Feb 19 |
nicklas |
var fileTypes; |
7604 |
25 Feb 19 |
nicklas |
var fileActions = []; |
7604 |
25 Feb 19 |
nicklas |
var visibleRecentFilesDiv; |
7604 |
25 Feb 19 |
nicklas |
34 |
|
7604 |
25 Feb 19 |
nicklas |
var editFrameLoaded = false; |
7604 |
25 Feb 19 |
nicklas |
var lastPlatformId = null; |
7604 |
25 Feb 19 |
nicklas |
var lastVariantId = null; |
7604 |
25 Feb 19 |
nicklas |
var lastSubtypeId = null; |
7604 |
25 Feb 19 |
nicklas |
39 |
|
7604 |
25 Feb 19 |
nicklas |
datafiles.initPage = function() |
7604 |
25 Feb 19 |
nicklas |
41 |
{ |
7604 |
25 Feb 19 |
nicklas |
var pageId = Doc.getPageId(); |
7604 |
25 Feb 19 |
nicklas |
if (pageId == 'select-datafiles') |
7604 |
25 Feb 19 |
nicklas |
44 |
{ |
7604 |
25 Feb 19 |
nicklas |
// Parse the current filetype information |
7604 |
25 Feb 19 |
nicklas |
fileTypes = Data.json('page-data', 'filetypes'); |
7604 |
25 Feb 19 |
nicklas |
for (var i = 0; i < fileTypes.length; i++) |
7604 |
25 Feb 19 |
nicklas |
48 |
{ |
7604 |
25 Feb 19 |
nicklas |
var fileType = fileTypes[i]; |
7604 |
25 Feb 19 |
nicklas |
fileTypes['ID'+fileType.id] = fileType; |
7604 |
25 Feb 19 |
nicklas |
51 |
|
7604 |
25 Feb 19 |
nicklas |
var attributes = {'filetype-id': fileType.id}; |
7604 |
25 Feb 19 |
nicklas |
// 'Browse' button, click to open file dialog, 'base-selected' to receive selected files |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('browsefile.'+fileType.id, 'click', datafiles.browseOnClick, attributes); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('browsefile.'+fileType.id, 'base-selected', datafiles.onFileSelected); |
7604 |
25 Feb 19 |
nicklas |
56 |
|
7604 |
25 Feb 19 |
nicklas |
// 'Add' button, click to open file dialog, 'base-selected' to receive selected files |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('addfile.'+fileType.id, 'click', datafiles.addOnClick, attributes); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('addfile.'+fileType.id, 'base-selected', datafiles.onFileSelected); |
7604 |
25 Feb 19 |
nicklas |
60 |
|
7604 |
25 Feb 19 |
nicklas |
// Remove file handler is attached to file list, but need target file |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('filelist.'+fileType.id, 'click', datafiles.removeOnClick, attributes); |
7604 |
25 Feb 19 |
nicklas |
63 |
|
7604 |
25 Feb 19 |
nicklas |
// Show recent files list, and handle recent file selection |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('showrecent.'+fileType.id, 'click', datafiles.showRecentFilesOnClick, attributes); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('recentfiles.'+fileType.id, 'click', datafiles.recentFileOnClick, attributes); |
7604 |
25 Feb 19 |
nicklas |
67 |
|
7604 |
25 Feb 19 |
nicklas |
//Events.addEventHandler('addfile.'+fileType.id, 'click', datafiles.addOnClick, attributes); |
7604 |
25 Feb 19 |
nicklas |
69 |
} |
7604 |
25 Feb 19 |
nicklas |
70 |
|
7604 |
25 Feb 19 |
nicklas |
// Hide 'recently used files' list if visible |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler(document.body, 'click', datafiles.hideVisibleRecentFilesDiv); |
7604 |
25 Feb 19 |
nicklas |
73 |
} |
7604 |
25 Feb 19 |
nicklas |
74 |
} |
7604 |
25 Feb 19 |
nicklas |
75 |
|
7604 |
25 Feb 19 |
nicklas |
76 |
/* |
7604 |
25 Feb 19 |
nicklas |
Event handler for showing the list of recently used files for |
7604 |
25 Feb 19 |
nicklas |
a given data file type. |
7604 |
25 Feb 19 |
nicklas |
79 |
*/ |
7604 |
25 Feb 19 |
nicklas |
datafiles.showRecentFilesOnClick = function(event) |
7604 |
25 Feb 19 |
nicklas |
81 |
{ |
7604 |
25 Feb 19 |
nicklas |
var target = event.currentTarget; |
7604 |
25 Feb 19 |
nicklas |
var fileTypeId = Data.get(target, 'filetype-id'); |
7604 |
25 Feb 19 |
nicklas |
84 |
|
7604 |
25 Feb 19 |
nicklas |
var recentDiv = Doc.element('recentfiles.'+fileTypeId); |
7604 |
25 Feb 19 |
nicklas |
var currentDiv = visibleRecentFilesDiv; |
7604 |
25 Feb 19 |
nicklas |
datafiles.hideVisibleRecentFilesDiv(); |
7604 |
25 Feb 19 |
nicklas |
if (currentDiv == recentDiv) return; |
7604 |
25 Feb 19 |
nicklas |
89 |
|
7604 |
25 Feb 19 |
nicklas |
var fileContainer = Doc.element('container.'+fileTypeId); |
7604 |
25 Feb 19 |
nicklas |
var pos = Doc.getElementPosition(fileContainer, true); |
7604 |
25 Feb 19 |
nicklas |
Doc.show('recentfiles.'+fileTypeId); |
7604 |
25 Feb 19 |
nicklas |
93 |
|
7604 |
25 Feb 19 |
nicklas |
recentDiv.style.top = (pos.bottom-2) + 'px'; |
7604 |
25 Feb 19 |
nicklas |
recentDiv.style.left = (pos.left+2) + 'px'; |
7604 |
25 Feb 19 |
nicklas |
recentDiv.style.width = (pos.width-4) + 'px'; |
7604 |
25 Feb 19 |
nicklas |
97 |
|
7604 |
25 Feb 19 |
nicklas |
visibleRecentFilesDiv = recentDiv; |
7604 |
25 Feb 19 |
nicklas |
event.stopPropagation(); |
7604 |
25 Feb 19 |
nicklas |
100 |
} |
7604 |
25 Feb 19 |
nicklas |
101 |
|
7604 |
25 Feb 19 |
nicklas |
102 |
/* |
7604 |
25 Feb 19 |
nicklas |
Hide the currently visible 'recently used files' list. |
7604 |
25 Feb 19 |
nicklas |
104 |
*/ |
7604 |
25 Feb 19 |
nicklas |
datafiles.hideVisibleRecentFilesDiv = function() |
7604 |
25 Feb 19 |
nicklas |
106 |
{ |
7604 |
25 Feb 19 |
nicklas |
if (visibleRecentFilesDiv) |
7604 |
25 Feb 19 |
nicklas |
108 |
{ |
7604 |
25 Feb 19 |
nicklas |
visibleRecentFilesDiv.style.display = 'none'; |
7604 |
25 Feb 19 |
nicklas |
visibleRecentFilesDiv = null; |
7604 |
25 Feb 19 |
nicklas |
111 |
} |
7604 |
25 Feb 19 |
nicklas |
112 |
} |
7604 |
25 Feb 19 |
nicklas |
113 |
|
7604 |
25 Feb 19 |
nicklas |
114 |
/* |
7604 |
25 Feb 19 |
nicklas |
Event handler when a user selects a recently used file. The |
7604 |
25 Feb 19 |
nicklas |
event handler is attached to the list container, but the target is |
7604 |
25 Feb 19 |
nicklas |
an individual file entry. |
7604 |
25 Feb 19 |
nicklas |
118 |
*/ |
7604 |
25 Feb 19 |
nicklas |
datafiles.recentFileOnClick = function(event) |
7604 |
25 Feb 19 |
nicklas |
120 |
{ |
7604 |
25 Feb 19 |
nicklas |
var fileTarget = event.target; |
7604 |
25 Feb 19 |
nicklas |
var fileTypeTarget = event.currentTarget; |
7604 |
25 Feb 19 |
nicklas |
123 |
|
7604 |
25 Feb 19 |
nicklas |
var fileTypeId = Data.get(fileTypeTarget, 'filetype-id'); |
7604 |
25 Feb 19 |
nicklas |
var fileType = fileTypes['ID'+fileTypeId]; |
7604 |
25 Feb 19 |
nicklas |
126 |
|
7604 |
25 Feb 19 |
nicklas |
var file = {}; |
7604 |
25 Feb 19 |
nicklas |
file.id = Data.int(fileTarget, 'file-id'); |
7604 |
25 Feb 19 |
nicklas |
file.name = file.id ? Doc.element('recentfile.'+fileTypeId+'.'+file.id).innerHTML : ''; |
7604 |
25 Feb 19 |
nicklas |
130 |
|
7604 |
25 Feb 19 |
nicklas |
if (fileType.allowMultiple && file.id) |
7604 |
25 Feb 19 |
nicklas |
132 |
{ |
7604 |
25 Feb 19 |
nicklas |
internal.addFile(fileType, file); |
7604 |
25 Feb 19 |
nicklas |
134 |
} |
7604 |
25 Feb 19 |
nicklas |
else |
7604 |
25 Feb 19 |
nicklas |
136 |
{ |
7604 |
25 Feb 19 |
nicklas |
internal.setFile(fileType, file); |
7604 |
25 Feb 19 |
nicklas |
138 |
} |
7604 |
25 Feb 19 |
nicklas |
139 |
} |
7604 |
25 Feb 19 |
nicklas |
140 |
|
7604 |
25 Feb 19 |
nicklas |
datafiles.browseOnClick = function(event) |
7604 |
25 Feb 19 |
nicklas |
142 |
{ |
7604 |
25 Feb 19 |
nicklas |
var target = event.currentTarget; |
7604 |
25 Feb 19 |
nicklas |
var fileTypeId = Data.get(target, 'filetype-id'); |
7604 |
25 Feb 19 |
nicklas |
var fileType = fileTypes['ID'+fileTypeId]; |
7604 |
25 Feb 19 |
nicklas |
146 |
|
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['datafiles']; |
7604 |
25 Feb 19 |
nicklas |
var url = '../../filemanager/index.jsp?ID=' + App.getSessionId(); |
7604 |
25 Feb 19 |
nicklas |
url += '&cmd=SelectOne&callback='+target.id; |
7604 |
25 Feb 19 |
nicklas |
if (fileType.extension) |
7604 |
25 Feb 19 |
nicklas |
151 |
{ |
7604 |
25 Feb 19 |
nicklas |
url += '&resetTemporary=1&tmpfilter:STRING:name='+escape('%.' + fileType.extension); |
7604 |
25 Feb 19 |
nicklas |
153 |
} |
7604 |
25 Feb 19 |
nicklas |
else |
7604 |
25 Feb 19 |
nicklas |
155 |
{ |
7604 |
25 Feb 19 |
nicklas |
url += '&resetTemporary=1&filter:STRING:name='; |
7604 |
25 Feb 19 |
nicklas |
157 |
} |
7604 |
25 Feb 19 |
nicklas |
158 |
|
7604 |
25 Feb 19 |
nicklas |
Dialogs.openPopup(url, 'SelectFile', 1050, 700); |
7604 |
25 Feb 19 |
nicklas |
event.stopPropagation(); |
7604 |
25 Feb 19 |
nicklas |
161 |
} |
7604 |
25 Feb 19 |
nicklas |
162 |
|
7604 |
25 Feb 19 |
nicklas |
datafiles.onFileSelected = function(event) |
7604 |
25 Feb 19 |
nicklas |
164 |
{ |
7604 |
25 Feb 19 |
nicklas |
var target = event.currentTarget; |
7604 |
25 Feb 19 |
nicklas |
var fileTypeId = Data.get(target, 'filetype-id'); |
7604 |
25 Feb 19 |
nicklas |
var fileType = fileTypes['ID'+fileTypeId]; |
7604 |
25 Feb 19 |
nicklas |
var file = event.detail; |
7604 |
25 Feb 19 |
nicklas |
if (fileType.allowMultiple) |
7604 |
25 Feb 19 |
nicklas |
170 |
{ |
7604 |
25 Feb 19 |
nicklas |
internal.addFile(fileType, file); |
7604 |
25 Feb 19 |
nicklas |
172 |
} |
7604 |
25 Feb 19 |
nicklas |
else |
7604 |
25 Feb 19 |
nicklas |
174 |
{ |
7604 |
25 Feb 19 |
nicklas |
internal.setFile(fileType, file); |
7604 |
25 Feb 19 |
nicklas |
176 |
} |
7604 |
25 Feb 19 |
nicklas |
177 |
} |
7604 |
25 Feb 19 |
nicklas |
178 |
|
7604 |
25 Feb 19 |
nicklas |
internal.setFile = function(fileType, file) |
7604 |
25 Feb 19 |
nicklas |
180 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['datafiles']; |
7604 |
25 Feb 19 |
nicklas |
var fileDiv = Doc.element('filelist.'+fileType.id); |
7604 |
25 Feb 19 |
nicklas |
if (file.id) |
7604 |
25 Feb 19 |
nicklas |
184 |
{ |
7604 |
25 Feb 19 |
nicklas |
fileDiv.innerHTML = '<div id="filelist.'+fileType.id+'.'+file.id+'" class="file">'+file.name+'</div>'; |
7604 |
25 Feb 19 |
nicklas |
186 |
} |
7604 |
25 Feb 19 |
nicklas |
else |
7604 |
25 Feb 19 |
nicklas |
188 |
{ |
7604 |
25 Feb 19 |
nicklas |
fileDiv.innerHTML = ''; |
7604 |
25 Feb 19 |
nicklas |
190 |
} |
7604 |
25 Feb 19 |
nicklas |
if (fileType.hasValidator) frm['datafiles.validate'].checked = true; |
7604 |
25 Feb 19 |
nicklas |
internal.registerFileAction('setfile', fileType.id, file.id); |
7604 |
25 Feb 19 |
nicklas |
193 |
} |
7604 |
25 Feb 19 |
nicklas |
194 |
|
7604 |
25 Feb 19 |
nicklas |
datafiles.addOnClick = function(event) |
7604 |
25 Feb 19 |
nicklas |
196 |
{ |
7604 |
25 Feb 19 |
nicklas |
var target = event.currentTarget; |
7604 |
25 Feb 19 |
nicklas |
var fileTypeId = Data.get(target, 'filetype-id'); |
7604 |
25 Feb 19 |
nicklas |
var fileType = fileTypes['ID'+fileTypeId]; |
7604 |
25 Feb 19 |
nicklas |
200 |
|
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['datafiles']; |
7604 |
25 Feb 19 |
nicklas |
var url = '../../filemanager/index.jsp?ID=' + App.getSessionId(); |
7604 |
25 Feb 19 |
nicklas |
url += '&cmd=SelectMultiple&callback='+target.id; |
7604 |
25 Feb 19 |
nicklas |
if (fileType.extension) |
7604 |
25 Feb 19 |
nicklas |
205 |
{ |
7604 |
25 Feb 19 |
nicklas |
url += '&resetTemporary=1&tmpfilter:STRING:name='+escape('%.' + fileType.extension); |
7604 |
25 Feb 19 |
nicklas |
207 |
} |
7604 |
25 Feb 19 |
nicklas |
else |
7604 |
25 Feb 19 |
nicklas |
209 |
{ |
7604 |
25 Feb 19 |
nicklas |
url += '&resetTemporary=1&filter:STRING:name='; |
7604 |
25 Feb 19 |
nicklas |
211 |
} |
7604 |
25 Feb 19 |
nicklas |
Dialogs.openPopup(url, 'SelectFiles', 1050, 700); |
7604 |
25 Feb 19 |
nicklas |
event.stopPropagation(); |
7604 |
25 Feb 19 |
nicklas |
214 |
} |
7604 |
25 Feb 19 |
nicklas |
215 |
|
7604 |
25 Feb 19 |
nicklas |
internal.addFile = function(fileType, file) |
7604 |
25 Feb 19 |
nicklas |
217 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['datafiles']; |
7604 |
25 Feb 19 |
nicklas |
var fileDiv = Doc.element('filelist.'+fileType.id + '.' + file.id); |
7604 |
25 Feb 19 |
nicklas |
if (fileDiv) return; // This file has already been selected |
7604 |
25 Feb 19 |
nicklas |
221 |
|
7604 |
25 Feb 19 |
nicklas |
fileDiv = document.createElement('div'); |
7604 |
25 Feb 19 |
nicklas |
fileDiv.id = 'filelist.'+fileType.id+'.'+file.id; |
7604 |
25 Feb 19 |
nicklas |
224 |
|
7604 |
25 Feb 19 |
nicklas |
var html = file.name; |
7604 |
25 Feb 19 |
nicklas |
html += ' <span id="remove.'+fileType.id+'.'+file.id +'" class="icon link" title="Remove this file"'; |
7604 |
25 Feb 19 |
nicklas |
html += ' data-file-id="'+file.id+'">'; |
7604 |
25 Feb 19 |
nicklas |
html += '<img src="' + App.getRoot() + 'images/remove.png"></span>'; |
7604 |
25 Feb 19 |
nicklas |
229 |
|
7604 |
25 Feb 19 |
nicklas |
fileDiv.innerHTML = html; |
7604 |
25 Feb 19 |
nicklas |
Doc.element('filelist.'+fileType.id).appendChild(fileDiv); |
7604 |
25 Feb 19 |
nicklas |
if (fileType.hasValidator) frm['datafiles.validate'].checked = true; |
7604 |
25 Feb 19 |
nicklas |
internal.registerFileAction('addfile', fileType.id, file.id); |
7604 |
25 Feb 19 |
nicklas |
234 |
} |
7604 |
25 Feb 19 |
nicklas |
235 |
|
7604 |
25 Feb 19 |
nicklas |
datafiles.removeOnClick = function(event) |
7604 |
25 Feb 19 |
nicklas |
237 |
{ |
7604 |
25 Feb 19 |
nicklas |
var fileTarget = event.target.parentNode; |
7604 |
25 Feb 19 |
nicklas |
var fileId = Data.get(fileTarget, 'file-id'); |
7604 |
25 Feb 19 |
nicklas |
if (!fileId) return; |
7604 |
25 Feb 19 |
nicklas |
241 |
|
7604 |
25 Feb 19 |
nicklas |
var fileTypeTarget = event.currentTarget; |
7604 |
25 Feb 19 |
nicklas |
var fileTypeId = Data.get(fileTypeTarget, 'filetype-id'); |
7604 |
25 Feb 19 |
nicklas |
var fileType = fileTypes['ID'+fileTypeId]; |
7604 |
25 Feb 19 |
nicklas |
245 |
|
7604 |
25 Feb 19 |
nicklas |
var fileDiv = Doc.element('filelist.'+fileTypeId+'.'+fileId); |
7604 |
25 Feb 19 |
nicklas |
Doc.element('filelist.'+fileTypeId).removeChild(fileDiv); |
7604 |
25 Feb 19 |
nicklas |
if (fileType.hasValidator) frm['datafiles.validate'].checked = true; |
7604 |
25 Feb 19 |
nicklas |
internal.registerFileAction('removefile', fileTypeId, fileId); |
7604 |
25 Feb 19 |
nicklas |
event.stopPropagation(); |
7604 |
25 Feb 19 |
nicklas |
251 |
} |
7604 |
25 Feb 19 |
nicklas |
252 |
|
7604 |
25 Feb 19 |
nicklas |
datafiles.autoLoadEditFrame = function(platformId, variantId, subtypeId) |
7604 |
25 Feb 19 |
nicklas |
254 |
{ |
7604 |
25 Feb 19 |
nicklas |
if (editFrameLoaded && lastPlatformId == platformId && lastVariantId == variantId && lastSubtypeId == subtypeId) |
7604 |
25 Feb 19 |
nicklas |
256 |
{ |
7604 |
25 Feb 19 |
nicklas |
return; |
7604 |
25 Feb 19 |
nicklas |
258 |
} |
7604 |
25 Feb 19 |
nicklas |
lastPlatformId = platformId; |
7604 |
25 Feb 19 |
nicklas |
lastVariantId = variantId; |
7604 |
25 Feb 19 |
nicklas |
lastSubtypeId = subtypeId; |
7604 |
25 Feb 19 |
nicklas |
editFrameLoaded = true; |
7604 |
25 Feb 19 |
nicklas |
263 |
|
7604 |
25 Feb 19 |
nicklas |
var url = App.getRoot()+'common/datafiles/select_files.jsp?ID='+App.getSessionId(); |
7604 |
25 Feb 19 |
nicklas |
url += '&item_type='+Data.get('datafiles-data', 'item-type'); |
7604 |
25 Feb 19 |
nicklas |
url += '&item_id='+Data.get('datafiles-data', 'item-id'); |
7604 |
25 Feb 19 |
nicklas |
if (platformId) url += '&platform_id='+platformId; |
7604 |
25 Feb 19 |
nicklas |
if (variantId) url += '&variant_id='+variantId; |
7604 |
25 Feb 19 |
nicklas |
if (subtypeId) url += '&itemsubtype_id='+subtypeId; |
7604 |
25 Feb 19 |
nicklas |
frames['datafiles'].location.replace(url); |
7604 |
25 Feb 19 |
nicklas |
271 |
} |
7604 |
25 Feb 19 |
nicklas |
272 |
|
7604 |
25 Feb 19 |
nicklas |
273 |
/* |
7604 |
25 Feb 19 |
nicklas |
Write current actions to form. If called from outside, |
7604 |
25 Feb 19 |
nicklas |
re-direct call to 'datafiles' iframe. |
7604 |
25 Feb 19 |
nicklas |
276 |
*/ |
7604 |
25 Feb 19 |
nicklas |
datafiles.writeFileActionsToForm = function(toForm) |
7604 |
25 Feb 19 |
nicklas |
278 |
{ |
7604 |
25 Feb 19 |
nicklas |
var pageId = Doc.getPageId(); |
7604 |
25 Feb 19 |
nicklas |
if (pageId != 'select-datafiles') |
7604 |
25 Feb 19 |
nicklas |
281 |
{ |
7604 |
25 Feb 19 |
nicklas |
if (!editFrameLoaded) return; |
7604 |
25 Feb 19 |
nicklas |
frames['datafiles'].DataFiles.writeFileActionsToForm(toForm); |
7604 |
25 Feb 19 |
nicklas |
return; |
7604 |
25 Feb 19 |
nicklas |
285 |
} |
7604 |
25 Feb 19 |
nicklas |
286 |
|
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['datafiles']; |
7604 |
25 Feb 19 |
nicklas |
if (frm['datafiles.validate']) |
7604 |
25 Feb 19 |
nicklas |
289 |
{ |
7604 |
25 Feb 19 |
nicklas |
Forms.addHidden(toForm, 'datafiles.validate', frm['datafiles.validate'].checked ? 1 : 0); |
7604 |
25 Feb 19 |
nicklas |
291 |
} |
7604 |
25 Feb 19 |
nicklas |
for (var i = 0; i < fileActions.length; i++) |
7604 |
25 Feb 19 |
nicklas |
293 |
{ |
7604 |
25 Feb 19 |
nicklas |
var action = fileActions[i]; |
7604 |
25 Feb 19 |
nicklas |
Forms.addHidden(toForm, action.cmd + '.' + action.fileTypeId, action.fileId); |
7604 |
25 Feb 19 |
nicklas |
296 |
} |
7604 |
25 Feb 19 |
nicklas |
297 |
} |
7604 |
25 Feb 19 |
nicklas |
298 |
|
7604 |
25 Feb 19 |
nicklas |
299 |
/* |
7604 |
25 Feb 19 |
nicklas |
Register a new 'file action' for a given filetype and file. |
7604 |
25 Feb 19 |
nicklas |
The action cmd can be one of: |
7604 |
25 Feb 19 |
nicklas |
302 |
*/ |
7604 |
25 Feb 19 |
nicklas |
internal.registerFileAction = function(cmd, fileTypeId, fileId) |
7604 |
25 Feb 19 |
nicklas |
304 |
{ |
7604 |
25 Feb 19 |
nicklas |
// Check if other actions should be removed as a result of this one |
7604 |
25 Feb 19 |
nicklas |
for (var i = fileActions.length-1; i >= 0; i--) |
7604 |
25 Feb 19 |
nicklas |
307 |
{ |
7604 |
25 Feb 19 |
nicklas |
var other = fileActions[i]; |
7604 |
25 Feb 19 |
nicklas |
var remove = false; |
7604 |
25 Feb 19 |
nicklas |
if (cmd == 'setfile') |
7604 |
25 Feb 19 |
nicklas |
311 |
{ |
7604 |
25 Feb 19 |
nicklas |
// Remove all other actions for the given file type |
7604 |
25 Feb 19 |
nicklas |
remove = other.fileTypeId == fileTypeId; |
7604 |
25 Feb 19 |
nicklas |
314 |
} |
7604 |
25 Feb 19 |
nicklas |
else |
7604 |
25 Feb 19 |
nicklas |
316 |
{ |
7604 |
25 Feb 19 |
nicklas |
// Remove all other actions for the given file type+file |
7604 |
25 Feb 19 |
nicklas |
remove = other.fileTypeId == fileTypeId && other.fileId == fileId; |
7604 |
25 Feb 19 |
nicklas |
319 |
} |
7604 |
25 Feb 19 |
nicklas |
if (remove) fileActions.splice(i, 1); |
7604 |
25 Feb 19 |
nicklas |
321 |
} |
7604 |
25 Feb 19 |
nicklas |
322 |
|
7604 |
25 Feb 19 |
nicklas |
// Create and store the action |
7604 |
25 Feb 19 |
nicklas |
var action = {}; |
7604 |
25 Feb 19 |
nicklas |
action.cmd = cmd; |
7604 |
25 Feb 19 |
nicklas |
action.fileTypeId = fileTypeId, |
7604 |
25 Feb 19 |
nicklas |
action.fileId = fileId; |
7604 |
25 Feb 19 |
nicklas |
fileActions[fileActions.length] = action; |
7604 |
25 Feb 19 |
nicklas |
329 |
} |
7604 |
25 Feb 19 |
nicklas |
330 |
|
7604 |
25 Feb 19 |
nicklas |
return datafiles; |
7604 |
25 Feb 19 |
nicklas |
332 |
}(); |
7604 |
25 Feb 19 |
nicklas |
333 |
|
7604 |
25 Feb 19 |
nicklas |
Doc.onLoad(DataFiles.initPage); |