Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / src / AbstractPlugin.js
1 /*
2
3 This file is part of Ext JS 4
4
5 Copyright (c) 2011 Sencha Inc
6
7 Contact:  http://www.sencha.com/contact
8
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file.  Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
11
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
13
14 */
15 /**
16  * The AbstractPlugin class is the base class from which user-implemented plugins should inherit.
17  *
18  * This class defines the essential API of plugins as used by Components by defining the following methods:
19  *
20  *   - `init` : The plugin initialization method which the owning Component calls at Component initialization time.
21  *
22  *     The Component passes itself as the sole parameter.
23  *
24  *     Subclasses should set up bidirectional links between the plugin and its client Component here.
25  *
26  *   - `destroy` : The plugin cleanup method which the owning Component calls at Component destruction time.
27  *
28  *     Use this method to break links between the plugin and the Component and to free any allocated resources.
29  *
30  *   - `enable` : The base implementation just sets the plugin's `disabled` flag to `false`
31  *
32  *   - `disable` : The base implementation just sets the plugin's `disabled` flag to `true`
33  */
34 Ext.define('Ext.AbstractPlugin', {
35     disabled: false,
36
37     constructor: function(config) {
38         //<debug>
39         if (!config.cmp && Ext.global.console) {
40             Ext.global.console.warn("Attempted to attach a plugin ");
41         }
42         //</debug>
43         Ext.apply(this, config);
44     },
45
46     getCmp: function() {
47         return this.cmp;
48     },
49
50     /**
51      * @method
52      * The init method is invoked after initComponent method has been run for the client Component.
53      *
54      * The supplied implementation is empty. Subclasses should perform plugin initialization, and set up bidirectional
55      * links between the plugin and its client Component in their own implementation of this method.
56      * @param {Ext.Component} client The client Component which owns this plugin.
57      */
58     init: Ext.emptyFn,
59
60     /**
61      * @method
62      * The destroy method is invoked by the owning Component at the time the Component is being destroyed.
63      *
64      * The supplied implementation is empty. Subclasses should perform plugin cleanup in their own implementation of
65      * this method.
66      */
67     destroy: Ext.emptyFn,
68
69     /**
70      * The base implementation just sets the plugin's `disabled` flag to `false`
71      *
72      * Plugin subclasses which need more complex processing may implement an overriding implementation.
73      */
74     enable: function() {
75         this.disabled = false;
76     },
77
78     /**
79      * The base implementation just sets the plugin's `disabled` flag to `true`
80      *
81      * Plugin subclasses which need more complex processing may implement an overriding implementation.
82      */
83     disable: function() {
84         this.disabled = true;
85     }
86 });