Skip to main content

How to handle LoadMask effectively?

How to use Ext.LoadMask component for a stateless web application?

I found an issue where loadMask z-index DIV element conflicted with modal window object z-index DIV element.
loadmask component created for different target views for each screen and hidden but not destroyed.
I spend good time to investigate issue in my application code.
Version: EXT 4.2.0
Chrome - Browser

Issues:
var myMask = new Ext.LoadMask(mypanel , {msg:"Loading..."});
myMask.hide();
// Why myMask.hide(); simply destroy LoadMask instance, here DOM still exist in browser with style "visibility: hidden"
Like this for more DIV element with this style are added to DOM.

To work on my fix, I still see 'x-mask' element exist in dom even when my target view is destroyed.
I want to understand difference between Ext.getBody().mask() /unmask() and
var maskobj = new Ext.LoadMask({
msg: message,
hideMode: 'display',
target: targetComponent
} );
maskobj.show();

Example:
If I have 2 async calls, fired in parallel in same screen.
First async call has target component as Ext.body()
second async call has target component as Ext.Panel
what is best way of add mask element and destroy() /unmask it

Method1:
Ext.getBody().mask('Loading..');
call Async function (); here
Ext.getBody().unmask(); // this line used inside async success callback()

Method2:
var mypanel = Ext.create('Ext.Panel', { });
var myMask = new Ext.LoadMask(mypanel , {msg:"Loading..."});
myMask.show();
call Async function(); here
onsuccess: function(){
myMask.destroy();
}
-------------------------------------------------------------------------------------
Sencha support team replied as,
A loadmask element will never be deleted if you manually create one (as you have done above). You must manually destroy it when no longer required. maskobj.hide() will still keep the underlying div around for future use. The loadmask
will be automatically destroyed when the target component is destroyed as well.

Actually both should be removing the mask. I do notice you are using a fairly old version of Ext and that beginning with Ext 4.2.2 the panel itself has a functioning mask/unmask method as well (just like the body) which will automatically create and destroy the mask when these methods are called.

Solution -1:
Use mask() , unmask() applied on body
Ext.getBody().mask('Loading...');
Ext.getBody().unmask();

unmask() will destroy() masking DOM element from body by default.

Solution-2:
Example:
Ext.define('MyApp.util.LoadMaskUtil', {

     /* set instance of loadmask object when created and loadmask.show() called,
        we can destroy loadmask instance when loadmask is hidden */
    loadmasking : null,

    statics : {
        /* method accepts custom status message to display when masked
        * @param {component} targetComponent
        * @param {String} customMsg , to display msg when masked
        */
        loadMask : function(targetComponent,customMsg) {
            var message =  'Please wait...';
            if (!Ext.isEmpty(customMsg) && Ext.isString(customMsg)) {
                message = customMsg;
            }

            var maskObj = new Ext.LoadMask({
                msg: message,
                hideMode: 'display',
                target: targetComponent,
                listeners: {
                    beforedestroy: function(lmask) {
                        console.log('beforedestroy',lmask.id);
                    },
                    hide: function(lmask) {                      
                        console.log('hide',lmask);
                    }
                }
            });
                   
            return maskObj;
        },

        /* method accepts custom status message to display when masked
         * @param {component} targetComponent
         * @param {String} customMsg , to display msg when masked
         */
        showLoadMask : function(targetComponent,message) {
            this.loadmasking = this.loadMask(targetComponent,message);
            this.loadmasking.show();          
        },

        /* method to unmask on target element */
        hideLoadMask : function(targetComponent) {
            /* when targetComponent not passed or undefined, remove masking object */
            if(this.loadmasking){
                console.log('hide',this.loadmasking);
                this.loadmasking.destroy();

            }
         
        }
}
});

// call loadmask
fnShowLoadMask : function(){



 var mypanel =  Ext.create('Ext.panel.Panel', {
        title : 'LoadMask with Ajax call ',
        renderTo: 'example-grid',
        width: 500,
        height: 280,
        items : [
        {
            xtype:'button',
            text : 'Make ajax call',
            handler(){
 
       MyApp.util.LoadMaskUtil.showLoadMask(mypanel);              
         Ext.defer(function() {
            Ext.Ajax.request({
                        url: '/echo/js/?delay=5&js=',
                        method: 'GET',        
                        async: false
                    });
                    MyApp.util.LoadMaskUtil.hideLoadMask();

        }, 5000);

             
            }
          }]
     
    });


}


        

Comments

  1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here.
    Kindly keep blogging. If anyone wants to become a Front end developer learn from Javascript Online Training from India . or learn thru JavaScript Online Training from India. Nowadays JavaScript has tons of job opportunities on various vertical industry.
    ES6 Training in Chennai

    ReplyDelete
  2. Hey buddy!! What amazing and useful information you are sharing here, thanks for sharing. I would love to share this information on mine post also so that the visitors of my blog also get a chance to become familiar with this information.

    Sencha Touch Development Company
    Hire Sencha Touch Developer

    ReplyDelete
  3. Excellent idea!!! I really enjoyed reading your post. Thank you for your efforts. Share more like this.
    Software Testing Courses Online Certification

    ReplyDelete
  4. This post is so helpfull and informative.keep updating more information...
    Software System Testing
    System Tests

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete

Post a Comment

Popular posts from this blog

ExtJS - Grid panel features

What can we do with ExtJS GridPanel? I have to develop a lot of applications in my web app and I see that grid component of ExtJS may fit in. However, I am not aware of what all things I can do with the - off the shelf available framework pieces - available plug-ins in the marketplace and - custom development through my own developers This is a typical question that we hear from the business users who wants to design an application by keeping the framework’s capability in perspective. In this article I have tried to put the list of stuff you can do with grid and hopefully that shall enable you to take advantage of the beauty of ExtJS. Pre-requisites This article assumes that you are familiar with basics of ExtJS What are the available options? In this section I will be taking you through some of the commonly seen usage of ExtJS grid panel. While covering all the capabilities of grid may not be possible, I am sure it will be helpful for the business users who want to...

ExtJS 4 with Spring MVC Example

Introduction When developing a brand new application for the company I work for, one of the first thing I implement is "authentication". Not only is this process generally a prerequisite to access many other functions but it is also very simple and covers every layer of an application, from GUI to the database. So instead of another minimalistic "Hello World" tutorial, here is a "Login/Password" example, using 2 famous technologies : Spring MVC and ExtJS 4.   Prerequisites Because this tutorial is quite long, I won't go into the details of each technology I used but I will mainly focus on how ExtJS and Spring can be nicely used together. So here are the things you should know before continuing : Spring framework (good knowledge) Spring MVC (basic knowledge. See  Spring MVC Official Documentation  for details) ExtJS "application architecture" (see  Sencha Docs  for details) Eclipse IDE + Tomcat 6 (or any other web container) You a...

Ext4 Apply Store Filtering

In extjs4.1: There are many way for store filtering . Some of code i give here Filtering by single field: store . filter ( 'eyeColor' , 'Brown' );   Alternatively, if filters are configured with an  id , then existing filters store may be  replaced by new filters having the same  id . Filtering by single field: store . filter ( "email" , /\.com$/ );   Using multiple filters: store . filter ([ { property : "email" , value : /\.com$/ }, { filterFn : function ( item ) { return item . get ( "age" ) > 10 ; }} ]);   Using  Ext.util.Filter  instances instead of config objects (note that we need to specify the root config option in this case): store . filter ([ Ext . create ( ' Ext.util.Filter ' , {   property : "email" , value : /\.com$/ , root : 'data' }),   Ext . create ( ' Ext.util.Filter ' , {   filterFn : function ( item ) {   return item . get ( ...