initial import
[roojs1] / Roo / LoadMask.js
1 /*
2  * Based on:
3  * Ext JS Library 1.1.1
4  * Copyright(c) 2006-2007, Ext JS, LLC.
5  *
6  * Originally Released Under LGPL - original licence link has changed is not relivant.
7  *
8  * Fork - LGPL
9  * <script type="text/javascript">
10  */
11  
12 /**
13  * @class Roo.LoadMask
14  * A simple utility class for generically masking elements while loading data.  If the element being masked has
15  * an underlying {@link Roo.data.Store}, the masking will be automatically synchronized with the store's loading
16  * process and the mask element will be cached for reuse.  For all other elements, this mask will replace the
17  * element's UpdateManager load indicator and will be destroyed after the initial load.
18  * @constructor
19  * Create a new LoadMask
20  * @param {String/HTMLElement/Roo.Element} el The element or DOM node, or its id
21  * @param {Object} config The config object
22  */
23 Roo.LoadMask = function(el, config){
24     this.el = Roo.get(el);
25     Roo.apply(this, config);
26     if(this.store){
27         this.store.on('beforeload', this.onBeforeLoad, this);
28         this.store.on('load', this.onLoad, this);
29         this.store.on('loadexception', this.onLoad, this);
30         this.removeMask = false;
31     }else{
32         var um = this.el.getUpdateManager();
33         um.showLoadIndicator = false; // disable the default indicator
34         um.on('beforeupdate', this.onBeforeLoad, this);
35         um.on('update', this.onLoad, this);
36         um.on('failure', this.onLoad, this);
37         this.removeMask = true;
38     }
39 };
40
41 Roo.LoadMask.prototype = {
42     /**
43      * @cfg {Boolean} removeMask
44      * True to create a single-use mask that is automatically destroyed after loading (useful for page loads),
45      * False to persist the mask element reference for multiple uses (e.g., for paged data widgets).  Defaults to false.
46      */
47     /**
48      * @cfg {String} msg
49      * The text to display in a centered loading message box (defaults to 'Loading...')
50      */
51     msg : 'Loading...',
52     /**
53      * @cfg {String} msgCls
54      * The CSS class to apply to the loading message element (defaults to "x-mask-loading")
55      */
56     msgCls : 'x-mask-loading',
57
58     /**
59      * Read-only. True if the mask is currently disabled so that it will not be displayed (defaults to false)
60      * @type Boolean
61      */
62     disabled: false,
63
64     /**
65      * Disables the mask to prevent it from being displayed
66      */
67     disable : function(){
68        this.disabled = true;
69     },
70
71     /**
72      * Enables the mask so that it can be displayed
73      */
74     enable : function(){
75         this.disabled = false;
76     },
77
78     // private
79     onLoad : function(){
80         this.el.unmask(this.removeMask);
81     },
82
83     // private
84     onBeforeLoad : function(){
85         if(!this.disabled){
86             this.el.mask(this.msg, this.msgCls);
87         }
88     },
89
90     // private
91     destroy : function(){
92         if(this.store){
93             this.store.un('beforeload', this.onBeforeLoad, this);
94             this.store.un('load', this.onLoad, this);
95             this.store.un('loadexception', this.onLoad, this);
96         }else{
97             var um = this.el.getUpdateManager();
98             um.un('beforeupdate', this.onBeforeLoad, this);
99             um.un('update', this.onLoad, this);
100             um.un('failure', this.onLoad, this);
101         }
102     }
103 };