2
* Copyright (C) 2009 Camptocamp
4
* This file is part of MapFish Client
6
* MapFish Client is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
11
* MapFish Client is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with MapFish Client. If not, see <http://www.gnu.org/licenses/>.
20
Ext.namespace('mapfish.widgets.toolbar');
23
* Class: mapfish.widgets.toolbar.CheckItem
24
* A Check item is associated with an OpenLayers Handler through an OpenLayers Control.
25
* This class also adds quicktips.
27
* Simple example usage:
29
* var checkItem = new mapfish.widgets.toolbar.CheckItem({
30
* text: 'My menu item',
31
* tooltip: 'My tooltip',
32
* control: new OpenLayers.Control.Navigation(),
33
* olHandler: 'wheelHandler'
38
* - {Ext.menu.CheckItem}
42
* Constructor: mapfish.widgets.toolbar.CheckItem
43
* Create a new CheckItem
46
* config - {Object} Config object
49
mapfish.widgets.toolbar.CheckItem = function(config) {
50
Ext.apply(this, config);
51
mapfish.widgets.toolbar.CheckItem.superclass.constructor.call(this);
54
Ext.extend(mapfish.widgets.toolbar.CheckItem, Ext.menu.CheckItem, {
57
* Property: controlAdded
69
initComponent: function() {
70
mapfish.widgets.toolbar.CheckItem.superclass.initComponent.call(this);
74
this.checkHandler = this.handleChecked;
78
handleChecked: function(item, checked) {
79
if (!this.controlAdded) {
80
this.map.addControl(this.control);
81
this.controlAdded = true;
84
if (!this.olHandler) {
85
// show control, there is currently no real API method to do this
86
if (this.control.div) {
87
this.control.div.style.display = 'block';
90
// deactivate the other handlers
91
this.control.deactivate();
92
eval('this.control.'+this.olHandler+'.activate();');
95
if (!this.olHandler) {
96
// hide control, ideally also deregister the events but no API
98
if (this.control.div) {
99
this.control.div.style.display = 'none';
102
this.control.deactivate();
110
* Function that builds op the state of the checkitem and returns it
112
getState: function() {
113
return {className: this.control.CLASS_NAME,
114
olHandler: this.olHandler,
115
active: this.checked};
120
* Apply the state to the checkitem upon loading
125
applyState: function(state) {
129
if (this.control.CLASS_NAME == state.className && this.olHandler == state.olHandler) {
130
this.checked = state.active;
131
} else if (this.control.CLASS_NAME == state.className) {
132
this.checked = state.active;
134
this.handleChecked(null, this.checked);
138
onRender: function(container, position) {
139
mapfish.widgets.toolbar.CheckItem.superclass.onRender.apply(this, arguments);
141
this.el.dom.qtip = this.tooltip;
145
Ext.reg('checkitem', mapfish.widgets.toolbar.CheckItem);