2204 |
28 Jan 14 |
nicklas |
1 |
/* |
2204 |
28 Jan 14 |
nicklas |
Copyright (C) 2014 Nicklas Nordborg |
2204 |
28 Jan 14 |
nicklas |
3 |
|
2204 |
28 Jan 14 |
nicklas |
This file is part of the Example Code Package for BASE. |
2204 |
28 Jan 14 |
nicklas |
Available at http://baseplugins.thep.lu.se/ |
2204 |
28 Jan 14 |
nicklas |
BASE main site: http://base.thep.lu.se/ |
2204 |
28 Jan 14 |
nicklas |
7 |
|
2204 |
28 Jan 14 |
nicklas |
This is free software; you can redistribute it and/or |
2204 |
28 Jan 14 |
nicklas |
modify it under the terms of the GNU General Public License |
2204 |
28 Jan 14 |
nicklas |
as published by the Free Software Foundation; either version 3 |
2204 |
28 Jan 14 |
nicklas |
of the License, or (at your option) any later version. |
2204 |
28 Jan 14 |
nicklas |
12 |
|
2204 |
28 Jan 14 |
nicklas |
The software is distributed in the hope that it will be useful, |
2204 |
28 Jan 14 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
2204 |
28 Jan 14 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2204 |
28 Jan 14 |
nicklas |
GNU General Public License for more details. |
2204 |
28 Jan 14 |
nicklas |
17 |
|
2204 |
28 Jan 14 |
nicklas |
You should have received a copy of the GNU General Public License |
2204 |
28 Jan 14 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
2204 |
28 Jan 14 |
nicklas |
20 |
*/ |
2204 |
28 Jan 14 |
nicklas |
var ExampleToolbarButtons = function() |
2204 |
28 Jan 14 |
nicklas |
22 |
{ |
2204 |
28 Jan 14 |
nicklas |
var buttons = {}; |
2204 |
28 Jan 14 |
nicklas |
24 |
|
2205 |
29 Jan 14 |
nicklas |
25 |
/** |
2205 |
29 Jan 14 |
nicklas |
Executed once when the page is loaded. Typically |
2205 |
29 Jan 14 |
nicklas |
used to bind events to fixed control elements. |
2205 |
29 Jan 14 |
nicklas |
28 |
*/ |
2204 |
28 Jan 14 |
nicklas |
buttons.initPage = function() |
2204 |
28 Jan 14 |
nicklas |
30 |
{ |
2205 |
29 Jan 14 |
nicklas |
// Bind event handlers to the toolbar buttons |
2204 |
28 Jan 14 |
nicklas |
Buttons.addClickHandler('more-info-button', buttons.showMoreInfo); |
2204 |
28 Jan 14 |
nicklas |
Buttons.addClickHandler('annotation-filter', buttons.annotationFilter); |
2204 |
28 Jan 14 |
nicklas |
34 |
} |
2205 |
29 Jan 14 |
nicklas |
35 |
|
2205 |
29 Jan 14 |
nicklas |
36 |
/** |
2205 |
29 Jan 14 |
nicklas |
An alternate approach to event binding. Usually used when the number |
2205 |
29 Jan 14 |
nicklas |
of elements on a page is not known and the initPage method is of limited use. |
2205 |
29 Jan 14 |
nicklas |
39 |
|
2205 |
29 Jan 14 |
nicklas |
This method is called once for every element with class="auto-init". |
2205 |
29 Jan 14 |
nicklas |
Check the autoInit parameter if something needs to be done. |
2205 |
29 Jan 14 |
nicklas |
42 |
*/ |
2205 |
29 Jan 14 |
nicklas |
buttons.initElements = function(element, autoInit) |
2205 |
29 Jan 14 |
nicklas |
44 |
{ |
2205 |
29 Jan 14 |
nicklas |
if (autoInit == 'click-me') |
2205 |
29 Jan 14 |
nicklas |
46 |
{ |
2205 |
29 Jan 14 |
nicklas |
Buttons.addClickHandler(element, buttons.clickMe); |
2205 |
29 Jan 14 |
nicklas |
48 |
} |
2205 |
29 Jan 14 |
nicklas |
49 |
} |
2204 |
28 Jan 14 |
nicklas |
50 |
|
2205 |
29 Jan 14 |
nicklas |
buttons.clickMe = function(event) |
2205 |
29 Jan 14 |
nicklas |
52 |
{ |
2205 |
29 Jan 14 |
nicklas |
var message = Data.get(event.currentTarget, 'message'); |
2205 |
29 Jan 14 |
nicklas |
alert(message); |
2205 |
29 Jan 14 |
nicklas |
55 |
} |
2205 |
29 Jan 14 |
nicklas |
56 |
|
2204 |
28 Jan 14 |
nicklas |
buttons.showMoreInfo = function(event) |
2204 |
28 Jan 14 |
nicklas |
58 |
{ |
2204 |
28 Jan 14 |
nicklas |
var itemType = Data.get(event.currentTarget, 'item-type'); |
2204 |
28 Jan 14 |
nicklas |
var itemId = Data.get(event.currentTarget, 'item-id'); |
2204 |
28 Jan 14 |
nicklas |
var url = Data.get(event.currentTarget, 'url'); |
2204 |
28 Jan 14 |
nicklas |
url += '?ID='+App.getSessionId(); |
2204 |
28 Jan 14 |
nicklas |
url += '&item_type=' + itemType; |
2204 |
28 Jan 14 |
nicklas |
url += '&item_id='+itemId; |
2204 |
28 Jan 14 |
nicklas |
Dialogs.openPopup(url, 'ItemInfo', 600, 400); |
2204 |
28 Jan 14 |
nicklas |
66 |
} |
2204 |
28 Jan 14 |
nicklas |
67 |
|
2204 |
28 Jan 14 |
nicklas |
buttons.annotationFilter = function(event) |
2204 |
28 Jan 14 |
nicklas |
69 |
{ |
2204 |
28 Jan 14 |
nicklas |
var itemType = Data.get(event.currentTarget, 'item-type'); |
2204 |
28 Jan 14 |
nicklas |
var url = Data.get(event.currentTarget, 'url'); |
2204 |
28 Jan 14 |
nicklas |
url += '?ID='+App.getSessionId(); |
2204 |
28 Jan 14 |
nicklas |
url += '&item_type=' + itemType; |
2204 |
28 Jan 14 |
nicklas |
Dialogs.openPopup(url, 'AnnotationFilter', 450, 300); |
2204 |
28 Jan 14 |
nicklas |
75 |
} |
2204 |
28 Jan 14 |
nicklas |
76 |
|
2204 |
28 Jan 14 |
nicklas |
return buttons; |
2204 |
28 Jan 14 |
nicklas |
78 |
}(); |
2204 |
28 Jan 14 |
nicklas |
79 |
|
2205 |
29 Jan 14 |
nicklas |
// Register the page and element initializer method with the BASE core |
2204 |
28 Jan 14 |
nicklas |
Doc.onLoad(ExampleToolbarButtons.initPage); |
2205 |
29 Jan 14 |
nicklas |
Doc.addElementInitializer(ExampleToolbarButtons.initElements); |
2205 |
29 Jan 14 |
nicklas |
83 |
|