Control refresh done by javascript is now correctly cancelled when the Refresh() method is called.

[GB.WEB.GUI]
* BUG: Control refresh done by javascript is now correctly cancelled when the Refresh() method is called.
This commit is contained in:
Benoît Minisini 2023-03-17 01:47:08 +01:00
parent 106de294d4
commit 779b1e6d74
19 changed files with 54 additions and 30 deletions

View File

@ -80,7 +80,7 @@ Public Sub _UpdateProperty(sProp As String, vValue As Variant)
WebForm._AddJavascript("$_(" & JS(vValue) & ").parentNode.addClass('gw-active');")
hMenu = WebForm.FromName(vValue)
sClick = PopupMenu(hMenu)
WebForm._AddJavascript("$_(" & JS(vValue) & ").parentNode.removeClass('gw-active');")
WebForm._AddJavascript("$_(" & JS(vValue) & ") && $_(" & JS(vValue) & ").parentNode.removeClass('gw-active');")
If sClick Then Me.Close(sClick)
Endif

View File

@ -179,7 +179,6 @@ Static Private Sub Brush_Write(Value As PaintBrush)
End
Static Public Sub DrawImage(Image As String, X As Float, Y As Float, Optional Width As Float, Height As Float, Opacity As Float = 1.0, Source As Rect)
$hCurrent.DrawImage(Image, X, Y, Width, Height, Opacity, Source)

View File

@ -51,9 +51,7 @@ Private Sub Text_Write(Value As String)
If $sText = Value Then Return
$sText = Value
If Me._CanRefresh() Then
WebForm._AddJavascript("gw.button.setText(" & JS(Me.Name) & "," & JS(Html(Value)) & ");")
Endif
If Me._CanRefresh() Then Me._AddRefresh("gw.button.setText(" & JS(Me.Name) & "," & JS(Html(Value)) & ");")
End

View File

@ -67,7 +67,7 @@ Private Sub Value_Write(Value As Boolean)
If $bChecked = Value Then Return
$bChecked = Value
If Me._CanRefresh() Then
WebForm._AddJavascript("$_(" & JS(Me.Name & ":input") & ").checked = " & JS($bChecked) & ";")
Me._AddRefresh("$_(" & JS(Me.Name & ":input") & ").checked = " & JS($bChecked) & ";")
Endif
Raise Click

View File

@ -130,7 +130,7 @@ Private Sub Index_Write(Value As Integer)
Endif
'Me.Refresh
If Me._CanRefresh() Then WebForm._AddJavascript("gw.combobox.update(" & JS(Me.Name) & "," & CStr($iIndex) & If($bReadOnly, "", "," & JS($sText)) & ");")
If Me._CanRefresh() Then Me._AddRefresh("gw.combobox.update(" & JS(Me.Name) & "," & CStr($iIndex) & If($bReadOnly, "", "," & JS($sText)) & ");")
Raise Click
@ -254,8 +254,7 @@ Private Sub Text_Write(Value As String)
$sText = Value
If Me._CanRefresh() Then WebForm._AddJavascript("gw.combobox.update(" & JS(Me.Name) & "," & CStr(iIndex) & "," & JS($sText) & ");")
'WebForm._AddJavascript("$_(" & JS(Me.Name & ":entry") & ").value = " & JS($sText))
If Me._CanRefresh() Then Me._AddRefresh("gw.combobox.update(" & JS(Me.Name) & "," & CStr(iIndex) & "," & JS($sText) & ");")
If iIndex <> $iIndex Then
$iIndex = iIndex

View File

@ -63,7 +63,7 @@ Public Sub _Remove(hChild As WebControl)
$aChildren.Remove($aChildren.Find(hChild.Name))
If Me._CanRefresh() Then
WebForm._AddJavascript("gw.removeElement(" & JS(hChild.Name) & ");")
WebForm._AddJavascriptBefore("gw.removeElement(" & JS(hChild.Name) & ");")
Endif
End

View File

@ -98,6 +98,8 @@ Static Public _NextName As String
Static Public _Shortcuts As New Collection
Static Public _RefreshJavascript As New Collection
Static Private $hCellParent As WebControl
Static Private $sCellId As String
@ -642,6 +644,7 @@ Public Sub Refresh()
_Refresh = True
WebForm._HasRefresh = True
_RefreshJavascript.Remove($iId)
Me._CancelChildrenRefresh()
@ -651,6 +654,7 @@ Public Sub _CancelRefresh()
'WebForm.PrintLog("Cancel refresh: " & Me.Name)
_Refresh = False
_RefreshJavascript.Remove($iId)
Me._CancelChildrenRefresh()
End
@ -680,8 +684,6 @@ Public Sub _RefreshReply() As Boolean
sResult = Close #hFile
Output To Default
'WebForm._AddRefresh("$_(" & JS(Me.Name) & ").outerHTML = " & JS(sResult) & ";")
If _Naked Then
Print "gw.setInnerHtml("; JS(Me.Name); ","; JS(sResult); ");"
Else
@ -790,7 +792,7 @@ Private Sub Visible_Write(Value As Boolean)
$bHidden = Not Value
If bCanRefresh Then
WebForm._AddJavascript("gw.setVisible(" & JS(Me.Name) & "," & JS(Not $bHidden) & ");")
Me._AddRefresh("gw.setVisible(" & JS(Me.Name) & "," & JS(Not $bHidden) & ");")
If Me.Parent Then
Me.Parent.Refresh
Else If Me Is WebContainer Then
@ -1296,3 +1298,9 @@ Public Sub _RaiseMouseEvent(sEvent As String, cEvent As Variant)
Object.Raise(Me, sEvent)
End
Public Sub _AddRefresh(sJavascript As String)
_RefreshJavascript[$iId] &= sJavascript
End

View File

@ -49,7 +49,7 @@ Private Sub Text_Write(Value As String)
If $sText = Value Then Return
$sText = Value
If Me._CanRefresh() Then
WebForm._AddJavascript("gw.button.setText(" & JS(Me.Name) & "," & JS(Html(Value)) & ");")
Me._AddRefresh("gw.button.setText(" & JS(Me.Name) & "," & JS(Html(Value)) & ");")
Endif
End

View File

@ -748,16 +748,27 @@ End
Static Private Sub PrintJavascript()
Dim sJavascript As Variant
If $aJavascriptBefore.Count Then
Print $aJavascriptBefore.Join("\n")
$aJavascriptBefore.Clear
Endif
' Handle full refreshes
If _HasRefresh Then
_HasRefresh = False
_Current._RefreshReply()
Endif
' Handle small refreshes done by javascript, and that were not cancelled by a full refreh
For Each sJavascript In WebControl._RefreshJavascript
Print sJavascript
Next
WebControl._RefreshJavascript.Clear
If $aJavascript.Count Then
Print $aJavascript.Join("\n")
$aJavascript.Clear
@ -1345,7 +1356,6 @@ Public Sub ShowPopup(Control As WebControl) As Variant
If _Window Then
hWindow = WebControl.FromId(_Window)
If hWindow.Visible Then Return
hWindow.Show()
Endif
If Not hWindow Then hWindow = New WebWindow(_Current._GetWindowContainer())
@ -1357,6 +1367,8 @@ Public Sub ShowPopup(Control As WebControl) As Variant
_Window = hWindow.Id
hWindow.Show()
hPrevious = _CurrentPopup
_CurrentPopup = Me

View File

@ -43,7 +43,7 @@ Private Sub Text_Write(Value As String)
$sText = Value
If Me._CanRefresh() Then
WebForm._AddJavascript("gw.setInnerHtml(" & JS(Me.Name) & "," & JS(GetRenderText()) & ");")
Me._AddRefresh("gw.setInnerHtml(" & JS(Me.Name) & "," & JS(GetRenderText()) & ");")
Endif
End

View File

@ -47,8 +47,8 @@ Private Sub Value_Write(Value As Float)
$fValue = Min(1, Max(0, Value))
If Me._CanRefresh() Then
WebForm._AddJavascript("$_(" & JS(Me.Name & ":p") & ").style.width = '" & CStr(CInt($fValue * 100)) & "." & CStr(CInt(Frac($fValue * 100) * 10)) & "%';")
If $bLabel Then WebForm._AddJavascript("gw.setInnerHtml(" & JS(Me.Name & ":l") & "," & JS(Html(Format($fValue, "0%"))) & ");")
Me._AddRefresh("$_(" & JS(Me.Name & ":p") & ").style.width = '" & CStr(CInt($fValue * 100)) & "." & CStr(CInt(Frac($fValue * 100) * 10)) & "%';")
If $bLabel Then Me._AddRefresh("gw.setInnerHtml(" & JS(Me.Name & ":l") & "," & JS(Html(Format($fValue, "0%"))) & ");")
Else
WebForm.PrintLog("Cannot refresh " & Me.Name & ": " & WebForm._InMessage & " / " & Me._NoRefresh & " / " & Me.IsHidden() & " / " & Me._Refresh)
Endif

View File

@ -66,7 +66,7 @@ Private Sub Value_Write(Value As Boolean)
If $bChecked <> Value Then
$bChecked = Value
If Me._CanRefresh() Then
WebForm._AddJavascript("$_(" & JS(Me.Name & ":input") & ").checked = " & JS($bChecked) & ";")
WebForm._AddJavascriptBefore("$_(" & JS(Me.Name & ":input") & ").checked = " & JS($bChecked) & ";")
Endif
Endif

View File

@ -101,7 +101,7 @@ Private Sub ScrollX_Write(Value As Integer)
If $iScrollX = Value Then Return
$iScrollX = Value
If Me._CanRefresh() Then WebForm._AddJavascript("gw.scrollview.scroll(" & JS(Me.Name) & "," & JS($iScrollX) & "," & JS($iScrollY) & "); // _ScrollX")
If Me._CanRefresh() Then Me._AddRefresh("gw.scrollview.scroll(" & JS(Me.Name) & "," & JS($iScrollX) & "," & JS($iScrollY) & "); // _ScrollX")
End
@ -116,7 +116,7 @@ Private Sub ScrollY_Write(Value As Integer)
If $iScrollY = Value Then Return
$iScrollY = Value
If Me._CanRefresh() Then WebForm._AddJavascript("gw.scrollview.scroll(" & JS(Me.Name) & "," & JS($iScrollX) & "," & JS($iScrollY) & "); // _ScrollY")
If Me._CanRefresh() Then Me._AddRefresh("gw.scrollview.scroll(" & JS(Me.Name) & "," & JS($iScrollX) & "," & JS($iScrollY) & "); // _ScrollY")
End
@ -126,7 +126,7 @@ Public Sub Scroll(X As Integer, Y As Integer)
$iScrollX = X
$iScrollY = Y
If Me._CanRefresh() Then WebForm._AddJavascript("gw.scrollview.scroll(" & JS(Me.Name) & "," & JS($iScrollX) & "," & JS($iScrollY) & ");")
If Me._CanRefresh() Then Me._AddRefresh("gw.scrollview.scroll(" & JS(Me.Name) & "," & JS($iScrollX) & "," & JS($iScrollY) & ");")
End

View File

@ -130,12 +130,12 @@ Private Sub SetCurrent(iIndex As Integer)
If $aTab[I].Visible = bShow Then Continue
$aTab[I].Visible = bShow
'If Not bShow Then
WebForm._AddJavascript("gw.setVisible(" & JS($aTab[I].Name) & "," & JS(bShow) & ");")
Me._AddRefresh("gw.setVisible(" & JS($aTab[I].Name) & "," & JS(bShow) & ");")
Next
Dec Me._NoRefresh
Me._SetContainer($aTab[iIndex])
WebForm._AddJavascript("gw.setOuterHtml(" & JS(Me.Name & ":header") & "," & JS(GetHeaderHTML()) & ");")
Me._AddRefresh("gw.setOuterHtml(" & JS(Me.Name & ":header") & "," & JS(GetHeaderHTML()) & ");")
'WebForm._AddJavascript("gw.setVisible(" & JS($aTab[iIndex].Name) & ",true);")
'$aTab[iIndex].Refresh

View File

@ -47,7 +47,9 @@ Private Sub SetText(Value As String, Optional bNoRefresh As Boolean)
$sText = Value
If Not bNoRefresh And If Me._CanRefresh() Then WebForm._AddJavascript("$_(" & JS(Me.Name & ":entry") & ").value = " & JS($sText) & ";")
If Not bNoRefresh And If Me._CanRefresh() Then
Me._AddRefresh("$_(" & JS(Me.Name & ":entry") & ").value = " & JS($sText) & ";")
Endif
Raise Change

View File

@ -66,9 +66,9 @@ Private Sub Enabled_Write(Value As Boolean)
If Me._CanRefresh() Then
If $bEnabled Then
WebForm._AddJavascript("gw.addTimer(" & JS(Me.Name) & "," & CStr($iDelay) & ");")
Me._AddRefresh("gw.addTimer(" & JS(Me.Name) & "," & CStr($iDelay) & ");")
Else
WebForm._AddJavascript("gw.removeTimer(" & JS(Me.Name) & ");")
Me._AddRefresh("gw.removeTimer(" & JS(Me.Name) & ");")
Endif
Endif

View File

@ -350,7 +350,7 @@ Private Sub Maximized_Write(Value As Boolean)
If $bMaximized = Value Then Return
$bMaximized = Value
If Me._CanRefresh() Then WebForm._AddJavascript("gw.window.maximize(" & JS(Me.Name) & ");")
If Me._CanRefresh() Then Me._AddRefresh("gw.window.maximize(" & JS(Me.Name) & ");")
End

View File

@ -283,7 +283,14 @@ gw = {
else
gw.log('--> ' + expr);
}
eval(expr);
try {
eval(expr);
}
catch(e)
{
gw.log('eval: ' + expr);
throw e;
}
if (!gw.focus)
gw.restoreFocus(save);

View File

@ -323,7 +323,6 @@ P:first-child,UL:first-child,OL:first-child {
.gw-popup {
position: absolute !important;
border: solid 1px #C0C0C0;
border-radius: 0;
box-shadow: none;
}