Commit 77af8368 authored by Benoît Minisini's avatar Benoît Minisini

Fix management of dynamically created popups.

[GB.WEB.FORM]
* BUG: Fix management of dynamically created popups.
parent 5bd12ffe
# Gambas Project File 3.0
Startup=Webform8
Startup=Embed1
UseHttpServer=1
Version=3.14.90
VersionFile=1
......
' Gambas class file
''' This class provides the constants that defined the arrangement mode of a container.
Export
Public Enum None, Vertical, Horizontal, Row, Column
'' This constant is used when a container does not arrange its contents.
Public Const None As Integer = 0
'' This constant is used for a vertical arrangement.
Public Const Vertical As Integer = 1
'' This constant is used for an horizontal arrangement.
Public Const Horizontal As Integer = 2
'' This constant is used for arranging controls in rows.
Public Const Row As Integer = 3
'' This constant is used for arranging controls in columns.
Public Const Column As Integer = 4
' Gambas class file
Export
Public Sub WebButton1_Click()
'Dim hForm As Embed2
'hForm = New Embed2(WebContainer1) ', Webform1)
Dim hChild As WebDateBox
hChild = New WebDateBox(WebContainer1)
End
Public Sub WebForm_Open()
WebForm.Debug = True
End
# Gambas Form File 3.0
{ WebForm WebForm
#MoveScaled(0,0,64,91)
{ WebButton1 WebButton
#MoveScaled(1,2,29,3)
Text = ("Load Form")
}
{ WebContainer1 WebVBox
#MoveScaled(1,7,62,43)
}
}
' Gambas class file
Export
Public Sub WebForm_Open()
WebDateBox1.Value = Now
End
# Gambas Form File 3.0
{ WebForm WebForm
#MoveScaled(0,0,64,91)
{ WebContainer1 WebContainer
#MoveScaled(1,1,62,5)
Arrangement = Arrange.Horizontal
Spacing = True
{ WebLabel1 WebLabel
#MoveScaled(1,1,12,3)
Text = ("Date")
}
{ WebDateBox1 WebDateBox
#MoveScaled(14,1,30,3)
}
}
}
' Gambas class file
Export
'Export
Public Sub WebUploader1_Upload()
......
......@@ -141,15 +141,15 @@
Index = 0
Text = ("General")
{ WebTextBox1 WebTextBox
#MoveScaled(1,1,131.7143,4)
#MoveScaled(1,1,131.75,4)
Text = ("Hello !")
}
{ WebCheckBox1 WebCheckBox
#MoveScaled(1,6,131.7143,4)
#MoveScaled(1,6,131.75,4)
Text = ("Check and uncheck me!")
}
{ WebContainer5 WebHBox
#MoveScaled(1,11,131.7143,6)
#MoveScaled(1,11,131.75,6)
Spacing = True
{ WebComboBox2 WebComboBox
#MoveScaled(1,1,22,4)
......@@ -171,36 +171,36 @@
}
}
{ WebContainer3 WebHBox
#MoveScaled(1,18,131.7143,6)
#MoveScaled(1,18,131.75,6)
Spacing = True
{ WebDateBox1 WebDateBox
#MoveScaled(1,1,24,4)
}
{ WebComboBox1 WebComboBox
#MoveScaled(26,1,65.7143,4)
#MoveScaled(26,1,65.75,4)
Width = "30em"
List = [("Élément 1"), ("Élément 2"), ("Élément 3"), ("Élément 4")]
ReadOnly = False
}
{ WebButton4 WebButton
#MoveScaled(92.7143,1,19,4)
#MoveScaled(92.75,1,19,4)
Text = ("New element")
}
{ WebButton5 WebButton
#MoveScaled(112.7143,1,19,4)
#MoveScaled(112.75,1,19,4)
Text = ("Clear")
}
{ WebSeparator3 WebSeparator
#MoveScaled(132.7143,1,11,4)
#MoveScaled(132.75,1,11,4)
Ignore = True
}
}
{ WebSeparator7 WebSeparator
#MoveScaled(1,25,131.7143,2)
#MoveScaled(1,25,131.75,2)
Height = "1em"
}
{ WebContainer7 WebExpander
#MoveScaled(1,28,131.7143,32)
#MoveScaled(1,28,131.75,32)
Background = &HA0FF7F00&
Arrangement = Arrange.Horizontal
Spacing = True
......@@ -208,7 +208,7 @@
Text = ("This is an expander container")
Hidden = True
{ WebContainer4 WebVBox
#MoveScaled(1.1429,1.1429,64,25.7143)
#MoveScaled(1.125,1.125,64,25.75)
Expand = True
Background = &H80FFFF00&
Margin = True
......@@ -231,15 +231,15 @@
}
}
{ WebContainer8 WebVBox
#MoveScaled(66.1429,1.1429,58.4286,25.7143)
#MoveScaled(66.125,1.125,58.375,25.75)
Expand = True
Spacing = True
{ WebLabel2 WebLabel
#MoveScaled(1,1,56.4286,4)
#MoveScaled(1,1,56.375,4)
Text = ("Please enter some text:")
}
{ WebTextArea1 WebTextArea
#MoveScaled(1,6,56.4286,24)
#MoveScaled(1,6,56.375,24)
Height = "20em"
Expand = True
Wrap = True
......@@ -247,7 +247,7 @@
}
}
{ WebHBox2 WebHBox
#MoveScaled(1,61,131.7143,11)
#MoveScaled(1,61,131.75,11)
{ WebImage1 WebImage
#MoveScaled(1,1,9,9)
Width = "8em"
......@@ -257,13 +257,13 @@
Index = 1
Text = ("Options")
{ WebButton3 WebButton
#MoveScaled(1,1,131.7143,8)
#MoveScaled(1,1,131.75,8)
Text = ("Test")
}
Index = 2
Text = ("Application state")
{ WebContainer2 WebContainer
#MoveScaled(1,1,131.7143,32)
#MoveScaled(1,1,131.75,32)
}
Index = 0
}
......
' Gambas class file
Export
'Export
Public Sub WebButton1_Click()
......
' Gambas class file
''' This class implements a push button.
Export
Inherits WebControl
......@@ -8,16 +10,36 @@ Public Const _Properties As String = "*,Border=True,Text,Image{WebImage},Immedia
Public Const _DefaultEvent As String = "Click"
Public Const _DefaultSize As String = "16,4"
'' This event is raised when the button is pressed.
''
'' ### See also
'' [../immediate]
Event Click
'' Return or set the button text.
Property Text As String
'' Return or set the button image relative path.
Property Image As String
'' If the Immediate property is set, the [../click] event is raised to generate javascript code that will be executed on the client side when
'' the button is clicked.
''
'' In that case, the Click event handler should only call methods that generate javascript on the client side:
'' - [../../webform/exec](WebForm.Exec)
'' - [../../webtextbox/copy](WebTextBox.Copy)
'' - ...
Property Immediate As Boolean
Private $sText As String
Private $sImage As String
Private $bImmediate As Boolean
'' Create a new WebButton control.
Public Sub _new()
End
Private Function Text_Read() As String
Return $sText
......@@ -96,6 +118,8 @@ Public Sub _AfterRender()
End
'' Click on the button.
Public Sub Click()
Object.Raise(Me, "Click")
......
' Gambas class file
''' This class implements a check-box control.
Export
Inherits WebControl
......@@ -9,14 +11,22 @@ Public Const _DefaultSize As String = "24,4"
Public Const _Similar As String = "WebButton"
Public Const _DefaultEvent As String = "Click"
'' This event is raised when the check-box is toggled.
Event Click
'' Return or set if the control is checked.
Property Value, Checked As Boolean
'' Return or set the text displayed beside the check mark.
Property Text As String
Private $sText As String
Private $bChecked As Boolean
'' Create a new WebCheckBox control.
Public Sub _new()
End
Private Function Text_Read() As String
......
' Gambas class file
''' This class implements a combo-box control.
Export
Inherits WebControl
......@@ -9,15 +11,24 @@ Public Const _DefaultSize As String = "24,4"
Public Const _Similar As String = "WebTextBox"
Public Const _DefaultEvent As String = "Click"
'' This event is raised when an item is selected in the list box.
Event Click
'' This event is raised when the combo-box text has changed. Works only if the combo-box is editable.
Event Change
'' This event is raised when the ENTER key is hit. Works only if the combo-box is editable.
Event Activate
'' Return or set the combo-box text.
Property Text As String
'' Return the number of items in the combo-box popup.
Property Read Count As Integer
'' Return or set the index of the current selected item.
Property Index As Integer
'' Return or set the contents of the combo-box popup as a string array.
Property List As String[]
'' Return or set if the combo-box is read-only, i.e. not editable.
Property ReadOnly As Boolean
'' Return or set the placeholder text displayed when the editable combo-box is empty.
Property PlaceHolder As String
Private $iIndex As Integer
......@@ -26,6 +37,8 @@ Private $aList As New String[]
Private $bReadOnly As Boolean = True
Private $sPlaceHolder As String
'' Create a new WebComboBox control.
Public Sub _new()
Me._Proxy = ":entry"
......@@ -94,7 +107,6 @@ Public Sub _UpdateProperty(sProp As String, vValue As Variant)
End
Private Function Index_Read() As Integer
Return $iIndex
......@@ -156,6 +168,7 @@ Private Sub List_Write(Value As String[])
End
'' Clear the contents of the combo-box and its popup.
Public Sub Clear()
$aList.Clear
......@@ -183,6 +196,11 @@ Private Sub ReadOnly_Write(Value As Boolean)
End
'' Add an item to the popup list.
''
'' - ~Item~ is the text of the item to add.
'' - ~Index~ is the position the item will be inserted from. If not specified, the item is added at the end of the popup list.
Public Sub Add(Item As String, Optional Index As Integer = -1)
$aList.Add(Item, Index)
......@@ -191,6 +209,10 @@ Public Sub Add(Item As String, Optional Index As Integer = -1)
End
'' Remove an item from the popup list.
''
'' - ~Index~ is the index of the item to remove, between 0 and [../count] - 1.
Public Sub Remove(Index As Integer)
$aList.Remove(Index)
......@@ -199,7 +221,6 @@ Public Sub Remove(Index As Integer)
End
Private Function Text_Read() As String
If $bReadOnly Then
......
' Gambas class file
''' This class implements a generic container for other controls.
'''
''' It is also the parent class of every other container.
Export
Inherits WebControl
......@@ -10,12 +14,28 @@ Public Const _Properties As String = "*,Arrangement{Arrange.*},Margin,Spacing,In
Public Const _DefaultArrangement As String = "F"
Public Const _DefaultSize As String = "32,32"
'' Return or set the how the container arrange its contents.
''
'' The value of that property can be one of the value of the [../arrange] class.
Property Arrangement As Integer
'' Return or set if there is a margin between the container border and all its children.
''
'' The margin size is 0.5em.
Property Margin As Boolean
'' Return or set if the children of the container are spaced out.
''
'' The amount of space is 0.5em.
Property Spacing As Boolean
'' Return or set if the container has a border.
Property Border As Boolean
'' Return or set if the children controls of the container are indented.
''
'' The direction of the indentation follows the direction of the container arrangement.
''
'' The amount of indentation is 0.5em.
Property Indent As Boolean
'' Return an array of all container's children.
Property Read Children As WebControl[]
Public _Container As WebContainer
......@@ -28,6 +48,13 @@ Private $bSpacing As Boolean
Private $bBorder As Boolean
Private $bIndent As Boolean
'' Create a new WebContainer.
Public Sub _new()
End
Public Sub _Add(hChild As WebControl)
Dim aExtraChild As String[]
......@@ -383,6 +410,7 @@ Public Sub _Lower(sName As String)
End
'' Delete all container's children.
Public Sub DeleteChildren()
......@@ -392,6 +420,8 @@ Public Sub DeleteChildren()
End
'' Delete the container with all its children.
Public Sub Delete()
Inc WebForm._DisableRefresh
......
......@@ -10,8 +10,13 @@ Public Const _Properties As String = "Class,Width{WebCoord},Height{WebCoord},Vis
Public Const _Family As String = "WebForm"
Public Const _DefaultEvent As String = "Render"
'' This event is raised just after the rendering of the control, so that you can add your own HTML contents.
Event Render
'' This event is raised after a message box has been closed.
'' - ~Source~ is the source control, i.e. the control owning the method that opened the message box.
'' - ~Action~ is the text of the message box button that has been clicked.
Event Message(Source As WebControl, Action As String)
Event Dialog(Dialog As WebForm, Result As Variant)
'' Return the server control identifier.
......@@ -110,6 +115,7 @@ Private $bNoBorder As Boolean
Private $sClass As String
Private $sTooltip As String
'' Create a new WebControl.
Public Sub _new(Optional Parent As WebContainer)
......@@ -190,12 +196,16 @@ Private Function Id_Read() As Integer
End
'' Return a WebControl from its server identifier.
Static Public Sub FromId(Id As Integer) As WebControl
Return $cFromId[Id]
End
'' Return a WebControl from its name.
Static Public Sub FromName(Name As String) As WebControl
Try Return $cFromId[$cFromName[Name]]
......@@ -375,8 +385,6 @@ Public Sub _EndStyleSheet()
End
Private Function Expand_Read() As Boolean
Return $bExpand
......@@ -471,6 +479,8 @@ Public Sub Style_Change()
End
'' Return if the control or one of its parent is hidden.
Public Sub IsHidden() As Boolean
Dim hCtrl As WebControl
......@@ -494,6 +504,7 @@ Public Sub _CanRefresh() As Boolean
End
'' Refresh the control.
Public Sub Refresh()
......@@ -667,6 +678,10 @@ Private Sub Ignore_Write(Value As Boolean)
End
'' Set the focus on the control.
''
'' - ~Highlight~ is an optional argument that specify if the control contents must be highlighted. It usually works only for TextBox or TextArea controls.
Public Sub SetFocus(Optional Highlight As Boolean)
Dim sName As String
......@@ -744,6 +759,8 @@ Static Public Sub _GetColor(iCol As Integer) As String
End
'' Raise the control.
Public Sub Raise()
Dim hParent As WebContainer
......@@ -753,6 +770,8 @@ Public Sub Raise()
End
'' Lower the control.
Public Sub Lower()
Dim hParent As WebContainer
......@@ -774,6 +793,8 @@ Static Public Sub _GetNames() As String
End
'' Delete the control
Public Sub Delete()
Dim hParent As WebContainer
......@@ -790,18 +811,28 @@ Public Sub Delete()
End
'' Show the control.
''
'' Setting the [../visible] property to TRUE has the same effect.
Public Sub Show()
Me.Visible = True
End
'' Hide the control.
''
'' Setting the [../visible] property to FALSE has the same effect.
Public Sub Hide()
Me.Visible = False
End
'' Return the custom data associated with the string ~Key~.
Public Sub _get(Key As String) As Variant
Dim cData As Collection
......@@ -813,6 +844,8 @@ Public Sub _get(Key As String) As Variant
End
'' Associate the some custom data with the string ~Key~.
Public Sub _put(Value As Variant, Key As String)
Dim cData As Collection
......@@ -825,6 +858,8 @@ Public Sub _put(Value As Variant, Key As String)
End
'' Clear all custom data associated with the control
Public Sub Reset()
Session[$sName & ":data"] = Null
......@@ -904,11 +939,14 @@ Private Sub Name_Write(Value As String)
End
Public Sub AddClass(sClass As String)
'' Add a specific class to the [../class] property.
Public Sub AddClass((Class) As String)
Dim aClass As String[]
Dim sClass As String
sClass = Trim(sClass)
sClass = Trim(Class)
If Not sClass Then Return
aClass = Split($sClass, " ")
......@@ -924,12 +962,15 @@ Public Sub AddClass(sClass As String)
End
Public Sub RemoveClass(sClass As String)
'' Remove a specific class from the [../class] property.
Public Sub RemoveClass((Class) As String)
Dim aClass As String[]
Dim iPos As Integer
Dim sClass As String
sClass = Trim(sClass)
sClass = Trim(Class)
If Not sClass Then Return
aClass = Split($sClass, " ")
......
......@@ -6,7 +6,7 @@ Create Static
Inherits WebContainer
Public Const _IsForm As Boolean = True
Public Const _HiddenControls As String = "WebControl,WebForm,WebWindow,Timer"
Public Const _HiddenControls As String = "WebControl,WebForm,Timer"
Public Const _Properties As String = "*,Title,Resizable,Persistent"
Public Const _DefaultEvent As String = "Open"
......@@ -215,10 +215,10 @@ Catch
Response.Cancel
Response.Begin
Print "<html><body><script type\"text/javascript\">"
If sPath <> "x" Then Print "<html><body><script type\"text/javascript\">"
Print "console.log("; JS(sErr); ");"
Print "alert("; JS(sErr); ");"
Print "</script></body></html>"
If sPath <> "x" Then Print "</script></body></html>"
Response.End
'System.Log("End request")
......@@ -274,11 +274,18 @@ Public Sub _ready()
Endif
_Loaded = True
'If Me.Parent And If Then Raise Open
End
Public Sub _BeforeRender()
If Me.Parent Then
Super._BeforeRender()
Return
Endif
Print "<div class=\"gw-form";
If Me.Class Then Print " "; Me.Class;
Print "\" id=\""; Me.Name; "\"";
......@@ -587,6 +594,11 @@ Public Sub Hide()
Dim hWindow As WebControl
If Me.Parent Then
Super.Hide()
Return
Endif
If _Window = 0 Then Return
hWindow = WebControl.FromId(_Window)
......@@ -616,7 +628,7 @@ End
Public Sub Show()
If Me.Parent Then Error.Raise("Form is embedded")
If Me.Parent Then Return
DoShow
Raise Open
......@@ -633,7 +645,7 @@ Public Sub ShowModal(Optional Parent As WebControl)
If hWindow Then
hWindow.Modal = True
If IsMissing(Parent) Then Parent = Last
If Parent Then hWindow.ParentControl = Parent
If Parent Then hWindow.ParentControl = Parent.Name
Endif
Raise Open
......@@ -651,7 +663,7 @@ Public Sub ShowPopup(Control As WebControl, Optional Alignment As Integer = Alig
hWindow.Child = Me
hWindow.Resizable = $bResizable
hWindow.PopupAlignment = Alignment
hWindow.PopupControl = Control
hWindow.PopupControl = Control.Name
hWindow.Modal = True
_Window = hWindow.Id
......@@ -660,8 +672,6 @@ Public Sub ShowPopup(Control As WebControl, Optional Alignment As Integer = Alig
End
Public Sub Move(X As String, Y As String, Optional Width As String, Optional Height As String)
Dim hWindow As WebWindow = WebControl.FromId(_Window)
......@@ -788,7 +798,8 @@ Private Sub Height_Write(Value As String)
End
Public Sub _GetWindowContainer() As WebContainer
'If Me.Parent Then Return Me.Form._GetWindowContainer()
Return $hWindowContainer
End
......@@ -817,7 +828,7 @@ End
Private Function PopupParent_Read() As WebControl
Dim hWindow As WebWindow = WebForm.FromId(Me._Window)
If hWindow Then Return hWindow.PopupControl
If hWindow Then Return WebControl.FromName(hWindow.PopupControl)
End
......
......@@ -15,9 +15,9 @@ Property Child As WebForm
Property Resizable As Boolean
Property Modal As Boolean
Property PopupControl As WebControl
Property PopupControl As String
Property PopupAlignment As Integer
Property ParentControl As WebControl
Property ParentControl As String
Private $sX As String
Private $sY As String
......@@ -26,13 +26,13 @@ Private $sHeight As String
Private $iFormId As Integer
Private $bResizable As Boolean
Private $bModal As Boolean
Private $iPopupControlId As Integer
Private $sPopupControl As String
Private $iPopupAlignment As Integer
Private $iParentControlId As Integer
Private $sParentControl As String
Public Sub IsPopup() As Boolean
Return $iPopupControlId
Return $sPopupControl