2205 |
29 Jan 14 |
nicklas |
1 |
/* |
2205 |
29 Jan 14 |
nicklas |
Copyright (C) 2014 Nicklas Nordborg |
2205 |
29 Jan 14 |
nicklas |
3 |
|
2205 |
29 Jan 14 |
nicklas |
This file is part of the Example Code Package for BASE. |
2205 |
29 Jan 14 |
nicklas |
Available at http://baseplugins.thep.lu.se/ |
2205 |
29 Jan 14 |
nicklas |
BASE main site: http://base.thep.lu.se/ |
2205 |
29 Jan 14 |
nicklas |
7 |
|
2205 |
29 Jan 14 |
nicklas |
This is free software; you can redistribute it and/or |
2205 |
29 Jan 14 |
nicklas |
modify it under the terms of the GNU General Public License |
2205 |
29 Jan 14 |
nicklas |
as published by the Free Software Foundation; either version 3 |
2205 |
29 Jan 14 |
nicklas |
of the License, or (at your option) any later version. |
2205 |
29 Jan 14 |
nicklas |
12 |
|
2205 |
29 Jan 14 |
nicklas |
The software is distributed in the hope that it will be useful, |
2205 |
29 Jan 14 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
2205 |
29 Jan 14 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2205 |
29 Jan 14 |
nicklas |
GNU General Public License for more details. |
2205 |
29 Jan 14 |
nicklas |
17 |
|
2205 |
29 Jan 14 |
nicklas |
You should have received a copy of the GNU General Public License |
2205 |
29 Jan 14 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
2205 |
29 Jan 14 |
nicklas |
20 |
*/ |
2205 |
29 Jan 14 |
nicklas |
var HistoryFile = function() |
2205 |
29 Jan 14 |
nicklas |
22 |
{ |
2205 |
29 Jan 14 |
nicklas |
var history = {}; |
2205 |
29 Jan 14 |
nicklas |
24 |
|
2205 |
29 Jan 14 |
nicklas |
history.initPage = function() |
2205 |
29 Jan 14 |
nicklas |
26 |
{ |
2205 |
29 Jan 14 |
nicklas |
// Add an event handler to the 'Browse' button that open the 'Select file' dialog |
2205 |
29 Jan 14 |
nicklas |
Buttons.addClickHandler('history_file_id.select', history.selectHistoryFile); |
2205 |
29 Jan 14 |
nicklas |
// Add an event handler for the custom 'base-selected' event that is sent |
2205 |
29 Jan 14 |
nicklas |
// when the user selects a file |
2205 |
29 Jan 14 |
nicklas |
Events.addEventHandler('history_file_id', 'base-selected', history.onFileSelected); |
2205 |
29 Jan 14 |
nicklas |
32 |
} |
2205 |
29 Jan 14 |
nicklas |
33 |
|
2205 |
29 Jan 14 |
nicklas |
34 |
/** |
2205 |
29 Jan 14 |
nicklas |
Open the 'Select file' dialog. |
2205 |
29 Jan 14 |
nicklas |
36 |
*/ |
2205 |
29 Jan 14 |
nicklas |
history.selectHistoryFile = function() |
2205 |
29 Jan 14 |
nicklas |
38 |
{ |
2205 |
29 Jan 14 |
nicklas |
var fileList = Doc.element('history_file_id.list'); |
2205 |
29 Jan 14 |
nicklas |
var url = '&resetTemporary=1&title=Select+history+file'; |
2205 |
29 Jan 14 |
nicklas |
if (fileList.length > 1) |
2205 |
29 Jan 14 |
nicklas |
42 |
{ |
2205 |
29 Jan 14 |
nicklas |
var id = Math.abs(parseInt(fileList[1].value)); |
2205 |
29 Jan 14 |
nicklas |
url += '&item_id='+id; |
2205 |
29 Jan 14 |
nicklas |
45 |
} |
2205 |
29 Jan 14 |
nicklas |
// Dialog for selecting 'FILE' items |
2205 |
29 Jan 14 |
nicklas |
// Callback events (base-selected) are sent to the 'history_file_id' element |
2205 |
29 Jan 14 |
nicklas |
Dialogs.selectItem('FILE', 'history_file_id', 0, url); |
2205 |
29 Jan 14 |
nicklas |
49 |
} |
2205 |
29 Jan 14 |
nicklas |
50 |
|
2205 |
29 Jan 14 |
nicklas |
51 |
/** |
2205 |
29 Jan 14 |
nicklas |
Called when the user selects a file. The event.details object contain |
2205 |
29 Jan 14 |
nicklas |
the 'id' and 'name' of the selected file. |
2205 |
29 Jan 14 |
nicklas |
54 |
*/ |
2205 |
29 Jan 14 |
nicklas |
history.onFileSelected = function(event) |
2205 |
29 Jan 14 |
nicklas |
56 |
{ |
2205 |
29 Jan 14 |
nicklas |
var fileList = Doc.element('history_file_id.list'); |
2205 |
29 Jan 14 |
nicklas |
if (fileList.length < 2 || fileList[1].value == '0') |
2205 |
29 Jan 14 |
nicklas |
59 |
{ |
2205 |
29 Jan 14 |
nicklas |
Forms.addListOption(fileList, 1, new Option()); |
2205 |
29 Jan 14 |
nicklas |
61 |
} |
2205 |
29 Jan 14 |
nicklas |
fileList[1].value = event.detail.id; |
2205 |
29 Jan 14 |
nicklas |
fileList[1].text = event.detail.name; |
2205 |
29 Jan 14 |
nicklas |
fileList.selectedIndex = 1; |
2205 |
29 Jan 14 |
nicklas |
65 |
} |
2205 |
29 Jan 14 |
nicklas |
66 |
|
2205 |
29 Jan 14 |
nicklas |
return history; |
2205 |
29 Jan 14 |
nicklas |
68 |
}(); |
2205 |
29 Jan 14 |
nicklas |
69 |
|
2205 |
29 Jan 14 |
nicklas |
Doc.onLoad(HistoryFile.initPage); |