Jump to content

Show Mask after some seconds


irigsoft

Recommended Posts

12 hours ago, irigsoft said:

is it possible to display a screen mask after a few seconds with some delay.

If you press the button and it takes more than 2 seconds, then the screen mask will be displayed, otherwise the screen mask will not be displayed

Hello,

In the simplest case...

1. UniButton1 -> ScreenMask -> Enabled = False

2. UniButton1 -> ClientEvents ->

function afterrender(sender, eOpts)
{
    sender.delayedTask = Ext.create('Ext.util.DelayedTask', function() {
        sender.btnMask = new Ext.LoadMask({
            msg: 'Please wait...',
            target: MainForm.window //?
        });
        sender.btnMask.show()
    }, this);
    
    sender.getEl().on('click', function() {
         sender.setDisabled(true);
         sender.delayedTask.delay(2000);
    });
}

3. 

procedure TMainForm.UniButton1Click(Sender: TObject);
begin
  //some long-running task
  
  with (Sender as TUniButton).JSInterface do
  begin
    JSCall('delayedTask.cancel', []);
    JSCode('if ('#1'.btnMask) {'#1'.btnMask.hide()};');
    JSCall('setDisabled', [False]);
  end;
end;

 

Link to comment
Share on other sites

4 minutes ago, Sherzod said:

Hello,

In the simplest case...

1. UniButton1 -> ScreenMask -> Enabled = False

2. UniButton1 -> ClientEvents ->


function afterrender(sender, eOpts)
{
    sender.delayedTask = Ext.create('Ext.util.DelayedTask', function() {
        sender.btnMask = new Ext.LoadMask({
            msg: 'Please wait...',
            target: MainForm.window //?
        });
        sender.btnMask.show()
    }, this);
    
    sender.getEl().on('click', function() {
         sender.setDisabled(true);
         sender.delayedTask.delay(2000);
    });
}

3. 


procedure TMainForm.UniButton1Click(Sender: TObject);
begin
  //some long-running task
  
  with (Sender as TUniButton).JSInterface do
  begin
    JSCall('delayedTask.cancel', []);
    JSCode('if ('#1'.btnMask) {'#1'.btnMask.hide()};');
    JSCall('setDisabled', [False]);
  end;
end;

 

Thanks,

is this posible to make this with global script on mainform?

 

Link to comment
Share on other sites

Sorry, but

sender.delayedTask.delay(2000);

it is not what i looking for.

https://docs.sencha.com/extjs/6.5.1/classic/Ext.util.DelayedTask.html

 

I want to start the execution by clicking the button, but if the execution takes less than 3 seconds not to show the mask on the screen, if it is more than 3 seconds, then to show the mask.

Link to comment
Share on other sites

37 minutes ago, irigsoft said:

Sorry, but


sender.delayedTask.delay(2000);

it is not what i looking for.

https://docs.sencha.com/extjs/6.5.1/classic/Ext.util.DelayedTask.html

 

I want to start the execution by clicking the button, but if the execution takes less than 3 seconds not to show the mask on the screen, if it is more than 3 seconds, then to show the mask.

Here, delayedTask is exactly for showing the mask, and the code works immediately after clicking on the button. :) 

  • Like 1
Link to comment
Share on other sites

5 hours ago, Sherzod said:

Here, delayedTask is exactly for showing the mask, and the code works immediately after clicking on the button. :) 

OK, I try to apply this on tuniBitBtn, TunISpeedButton, tuniButton and get error

image.png.4e5f218d0fc6a4e3de0eae5f6e83b32b.png

 

after create Control, there is my code:

 

      IF TuniControl (UniMainModule.NewComponent).ClassNameIs('TuniButton')
      OR TuniControl (UniMainModule.NewComponent).ClassNameIs('TuniBitBtn')
      OR TuniControl (UniMainModule.NewComponent).ClassNameIs('TColorButton')
      OR TuniControl (UniMainModule.NewComponent).ClassNameIs('TUniSpeedButton')
      then begin
          TuniBitBtn (UniMainModule.NewComponent).ClientEvents.ExtEvents.Values['onafterrender'] :=
'function afterrender(sender, eOpts)'
+ '{'
+ '    sender.delayedTask = Ext.create(''Ext.util.DelayedTask'', function() {'
+ '        sender.btnMask = new Ext.LoadMask({'
+ '            msg: ''Please wait...'','
+ '            target: MainForm.window //?'
+ '        });'
+ '        sender.btnMask.show()'
+ '    }, this);'
+ '    sender.getEl().on(''click'', function() {'
+ '         sender.setDisabled(true);'
+ '         sender.delayedTask.delay(2000);'
+ '    });'
+ '}'
    end;
 

Link to comment
Share on other sites

Just now, Sherzod said:

Please make a simple testcase.

there is my code, after create Control on form creation:

      IF TuniControl (UniMainModule.NewComponent).ClassNameIs('TuniButton')
      OR TuniControl (UniMainModule.NewComponent).ClassNameIs('TuniBitBtn')
      OR TuniControl (UniMainModule.NewComponent).ClassNameIs('TColorButton')
      OR TuniControl (UniMainModule.NewComponent).ClassNameIs('TUniSpeedButton')
      then begin
          TuniBitBtn (UniMainModule.NewComponent).ClientEvents.ExtEvents.Values['onafterrender'] :=
'function afterrender(sender, eOpts)'
+ '{'
+ '    sender.delayedTask = Ext.create(''Ext.util.DelayedTask'', function() {'
+ '        sender.btnMask = new Ext.LoadMask({'
+ '            msg: ''Please wait...'','
+ '            target: MainForm.window //?'
+ '        });'
+ '        sender.btnMask.show()'
+ '    }, this);'
+ '    sender.getEl().on(''click'', function() {'
+ '         sender.setDisabled(true);'
+ '         sender.delayedTask.delay(2000);'
+ '    });'
+ '}'
    end;
 

Link to comment
Share on other sites

4 minutes ago, irigsoft said:

+ '            target: MainForm.window //?'

Try this:

ClientEvents.ExtEvents.Values['onafterrender'] :=
  'function afterrender(sender, eOpts)'
  + '{'
  + '    sender.delayedTask = Ext.create(''Ext.util.DelayedTask'', function() {'
  + '        sender.btnMask = new Ext.LoadMask({'
  + '            msg: ''Please wait...'','
  + '            target: MainForm.window '
  + '        });'
  + '        sender.btnMask.show()'
  + '    }, this);'
  + '    sender.getEl().on(''click'', function() {'
  + '         sender.setDisabled(true);'
  + '         sender.delayedTask.delay(2000);'
  + '    });'
  + '}'

 

Link to comment
Share on other sites

22 minutes ago, Sherzod said:

Try this:


ClientEvents.ExtEvents.Values['onafterrender'] :=
  'function afterrender(sender, eOpts)'
  + '{'
  + '    sender.delayedTask = Ext.create(''Ext.util.DelayedTask'', function() {'
  + '        sender.btnMask = new Ext.LoadMask({'
  + '            msg: ''Please wait...'','
  + '            target: MainForm.window '
  + '        });'
  + '        sender.btnMask.show()'
  + '    }, this);'
  + '    sender.getEl().on(''click'', function() {'
  + '         sender.setDisabled(true);'
  + '         sender.delayedTask.delay(2000);'
  + '    });'
  + '}'

 

Thanks it's ok now.

but i get screenmask for milliseconds visible, maybe if mainform.screenmask is enabled this is result , did You know?

Link to comment
Share on other sites

Now, I use Suspend and ResumeLayouts on BtnClick.

after applying a method, parental control (TuniPanel, uniGroupbox) becomes deactivated

 

  TuniForm (TuniControl (sSender).OwnerForm).SuspendLayouts;  

................... procedure .....................

TuniForm (TuniControl (sSender).OwnerForm).ResumeLayouts;
TuniForm (TuniControl (sSender).OwnerForm).HideMask;

    if ((TuniControl (sSender).ClassNameIs('TUniBitBtn'))
        OR (TuniControl (sSender).ClassNameIs('TUniButton'))
        OR (TuniControl (sSender).ClassNameIs('TUniSpeedButton'))
    )
    then begin
      with TUniBitBtn (sSender).JSInterface do begin
          JSCall('delayedTask.cancel', []);
          JSCode('if ('#1'.btnMask) {'#1'.btnMask.hide()};');
          JSCall('setDisabled', [False]);
      end;
    end;

Link to comment
Share on other sites

Just now, Sherzod said:

?

I found the problem: 

ClientEvents.ExtEvents.Values['onafterrender'] :=
  'function afterrender(sender, eOpts)'
  + '{'
  + '    sender.delayedTask = Ext.create(''Ext.util.DelayedTask'', function() {'
  + '        sender.btnMask = new Ext.LoadMask({'
  + '            msg: ''Please wait...'','
  + '            target: MainForm.window '
  + '        });'
  + '        sender.btnMask.show()'
  + '    }, this);'
  + '    sender.getEl().on(''click'', function() {'
  + '         sender.setDisabled(true);'
  + '         sender.delayedTask.delay(2000);'
  + '    });'
  + '}'
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...