~dongpo-deng/sahana-eden/test

« back to all changes in this revision

Viewing changes to static/scripts/gis/mapfish/widgets/toolbar/CheckItem.js

  • Committer: Deng Dongpo
  • Date: 2010-08-01 09:29:44 UTC
  • Revision ID: dongpo@dhcp-21193.iis.sinica.edu.tw-20100801092944-8t9obt4xtl7otesb
initial

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2009  Camptocamp
 
3
 *
 
4
 * This file is part of MapFish Client
 
5
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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/>.
 
18
 */
 
19
 
 
20
Ext.namespace('mapfish.widgets.toolbar');
 
21
 
 
22
/**
 
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.
 
26
 *
 
27
 * Simple example usage:
 
28
 * (start code)
 
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'
 
34
 * });
 
35
 * (end)
 
36
 *
 
37
 * Inherits from:
 
38
 * - {Ext.menu.CheckItem}
 
39
 */
 
40
 
 
41
/**
 
42
 * Constructor: mapfish.widgets.toolbar.CheckItem
 
43
 * Create a new CheckItem
 
44
 *
 
45
 * Parameters:
 
46
 * config - {Object} Config object
 
47
 */
 
48
 
 
49
mapfish.widgets.toolbar.CheckItem = function(config) {
 
50
    Ext.apply(this, config);
 
51
    mapfish.widgets.toolbar.CheckItem.superclass.constructor.call(this);
 
52
};
 
53
 
 
54
Ext.extend(mapfish.widgets.toolbar.CheckItem, Ext.menu.CheckItem, {
 
55
 
 
56
    /**
 
57
     * Property: controlAdded
 
58
     * {Boolean}
 
59
     */
 
60
    controlAdded: false,
 
61
    
 
62
    /**
 
63
     * Property: olHandler
 
64
     * {String}
 
65
     */
 
66
    olHandler: null,
 
67
 
 
68
    // private
 
69
    initComponent: function() {
 
70
        mapfish.widgets.toolbar.CheckItem.superclass.initComponent.call(this);
 
71
        Ext.QuickTips.init();
 
72
        if (this.control) {
 
73
            this.scope = this;
 
74
            this.checkHandler = this.handleChecked;
 
75
        }
 
76
    },
 
77
 
 
78
    handleChecked: function(item, checked) {
 
79
      if (!this.controlAdded) {
 
80
          this.map.addControl(this.control);
 
81
          this.controlAdded = true;
 
82
      }
 
83
      if (checked) {
 
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';
 
88
              }
 
89
          } else {
 
90
              // deactivate the other handlers
 
91
              this.control.deactivate();
 
92
              eval('this.control.'+this.olHandler+'.activate();');
 
93
          }
 
94
      } else {
 
95
          if (!this.olHandler) {
 
96
            // hide control, ideally also deregister the events but no API 
 
97
            // method currently
 
98
            if (this.control.div) {
 
99
                this.control.div.style.display = 'none';
 
100
            }
 
101
          } else {
 
102
              this.control.deactivate();
 
103
          }
 
104
      }
 
105
      this.saveState();
 
106
    },
 
107
 
 
108
    /**
 
109
     * Method: getState
 
110
     * Function that builds op the state of the checkitem and returns it
 
111
    */
 
112
    getState: function() {
 
113
        return {className: this.control.CLASS_NAME, 
 
114
                olHandler: this.olHandler, 
 
115
                active: this.checked};
 
116
    },
 
117
 
 
118
    /**
 
119
     * Method: applyState
 
120
     * Apply the state to the checkitem upon loading
 
121
     *
 
122
     * Parameters:
 
123
     * state - {<Object>}
 
124
    */
 
125
    applyState: function(state) {
 
126
        if (!state) {
 
127
            return false;
 
128
        }
 
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;
 
133
        }
 
134
        this.handleChecked(null, this.checked);
 
135
    },
 
136
 
 
137
    // private
 
138
    onRender: function(container, position) {
 
139
        mapfish.widgets.toolbar.CheckItem.superclass.onRender.apply(this, arguments);
 
140
        if (this.tooltip) {
 
141
            this.el.dom.qtip = this.tooltip;
 
142
        }
 
143
    }
 
144
});
 
145
Ext.reg('checkitem', mapfish.widgets.toolbar.CheckItem);