Basically I create all of the frames I need at the start of the app. When I get ready to pop up the modal dialog, I assign the frame's parent to the dialog, set some properties and before I show the dialog I call the Frame.Initialize. Just keep in mind that I also have an .UnInitialize that needs to be called when the dialog closes.
Here is the code for my dialog editing function:
- Code: Select all
procedure TframeEditContact.EditContactChildData(ID: Integer; FrameName, FrameTitle: String; FrameWidth, FrameHeight: Integer);
var
buttonDialog: TIWCGJQCustomDialogButton;
IsAsync: Boolean;
iCancelButtonIndex, iCloseButtonIndex, iSaveButtonIndex: Integer;
begin
IsAsync:= WebApplication.CallBackProcessing;
try
if IsAsync then
CGCallBackDisableAjaxResponse;
Self.dialogModal.ExtraTagParams.Clear;
Self.dialogModal.ExtraTagParams.Add(FrameName);
Self.dialogModal.Visible := True;
Self.dialogModal.JQDialogOptions.Modal := True;
Self.dialogModal.JQDialogOptions.Title := FrameTitle;
Self.dialogModal.Width := FrameWidth;
Self.dialogModal.Height := FrameHeight + 90;
Self.dialogModal.JQDialogOptions.Buttons.Clear;
buttonDialog := Self.dialogModal.JQDialogOptions.Buttons.Add;
buttonDialog.Text := C_DIALOG_BUTTON_CAPTION_CANCEL;
buttonDialog.OnClick.OnEvent := Self.CloseModalDialog;
iCancelButtonIndex := buttonDialog.Index;
buttonDialog := Self.dialogModal.JQDialogOptions.Buttons.Add;
buttonDialog.Text := C_DIALOG_BUTTON_CAPTION_CLOSE;
buttonDialog.OnClick.OnEvent := Self.CloseModalDialog;
iCloseButtonIndex := buttonDialog.Index;
buttonDialog := Self.dialogModal.JQDialogOptions.Buttons.Add;
buttonDialog.Text := C_DIALOG_BUTTON_CAPTION_SAVE;
buttonDialog.OnClick.OnEvent := Self.CloseModalDialog;
iSaveButtonIndex := buttonDialog.Index;
// since all buttons are not visible or enabled, default
Self.dialogModal.JQDialogOptions.Buttons[iSaveButtonIndex].Visible := True;
Self.dialogModal.JQDialogOptions.Buttons[iCancelButtonIndex].Visible := True;
Self.dialogModal.JQDialogOptions.Buttons[iCancelButtonIndex].Visible := True;
Self.dialogModal.JQDialogOptions.Buttons[iSaveButtonIndex].Disabled := False;
Self.dialogModal.JQDialogOptions.Buttons[iCancelButtonIndex].Disabled := False;
Self.dialogModal.JQDialogOptions.Buttons[iCancelButtonIndex].Disabled := True;
if (FrameName = Self.FframeEditContactAddress.Name) then
begin
Self.FframeEditContactAddress.ID := ID;
Self.FframeEditContactAddress.Initialize;
end
else if (FrameName = Self.FframeEditContactPhone.Name) then
begin
Self.FframeEditContactPhone.ID := ID;
Self.FframeEditContactPhone.Initialize;
end
else if (FrameName = Self.FframeEditContactEmail.Name) then
begin
Self.FframeEditContactEmail.ID := ID;
Self.FframeEditContactEmail.Initialize;
end
else if (FrameName = Self.FframeEditContactActivity.Name) then
begin
Self.FframeEditContactActivity.ID := ID;
Self.FframeEditContactActivity.Initialize;
end;
finally
if IsAsync then
CGCallBackEnableAjaxResponse;
Self.dialogModal.AjaxReRender;
end;
end;
And here is one of my small frames, notice the public properties that are being set from the procedure EditContactChildData above:
- Code: Select all
unit EditContactEmailAddressFrame;
interface
uses
SysUtils, Classes, Controls, Math, Forms, IWCGFrame, IWVCLBaseContainer, IWColor, IWContainer, IWRegion,
IWHTMLContainer, IWHTML40Container, IWCGJQControl, IWCGJQButton, IWCGJQRegion, IWCGJQButtons, ServerController, IWCGJQEdit,
Dialogs, xmldom, XMLIntf, msxmldom, XMLDoc, StdCtrls,
IWVCLBaseControl, IWBaseControl, IWBaseHTMLControl, IWControl, IWCompLabel, IWCGJQLabel, IWCGPanelList, IWCGJQComboBox, IWCGJQShowMessage,
IWCGJQMemo, IWCGJQAccordion, IWCGAsyncRender, IWCompGrids, IWBaseComponent, IWBaseHTMLComponent, IWCGJQDialog,
IWBaseHTML40Component, IWCGJQComp, IWCGJQLockIndicator, IWCGJQDatePicker, IWCGJQDateTimePicker, IWCGJQDropDown, IWCGJQCheckBox,
IWCompExtCtrls, IdBaseComponent, IdComponent, IdRawBase, IdRawClient, IdIcmpClient,
Data.Win.ADODB, Data.DB,
UserSessionUnit;
type
TframeEditContactEmailAddress = class(TIWCGJQFrame)
IWFrameRegion: TIWCGJQRegion;
IWCGJQShowMessage: TIWCGJQShowMessage;
IWCGJQLabel2: TIWCGJQLabel;
editEmailAddress: TIWCGJQEdit;
dsData: TDataSource;
adoData: TADODataSet;
adoTypeList: TADODataSet;
dsTypeList: TDataSource;
editEmailTypeID: TIWCGJQDropDown;
editDefaultEmailAddress: TIWCGJQCheckBoxEx;
IWCGJQLabel4: TIWCGJQLabel;
procedure IWFrameRegionCreate(Sender: TObject);
private
FTitle: String;
FLockIndicator: TIWCGJQLockIndicator;
FID: Integer;
FContactID: Integer;
FADOContact: TADODataSet;
function GetZIndex: Integer;
public
property Title: String read FTitle;
property LockIndicator: TIWCGJQLockIndicator read FLockIndicator write FLockIndicator;
property ZIndex: Integer read GetZIndex;
property ID: Integer read FID write FID;
property ContactID: Integer read FContactID write FContactID;
property adoContact: TADODataSet read FADOContact write FADOContact;
procedure Initialize;
procedure UnInitialize;
procedure SaveData;
procedure CancelData;
end;
implementation
{$R *.dfm}
uses IWCGJQCommon,
Include,
S2Snax;
{ TframeEditContactEmail }
procedure TframeEditContactEmailAddress.IWFrameRegionCreate(Sender: TObject);
begin
Self.FTitle := 'Update Email Address';
end;
function TframeEditContactEmailAddress.GetZIndex: Integer;
begin
GetZIndex := (Self.Parent AS TIWCGJQDialog).ZIndex + 100;
end;
procedure TframeEditContactEmailAddress.Initialize;
begin
UserSession.SetZIndex(Self.IWFrameRegion, Self.ZIndex, True);
UserSession.OpenADOWithOptions(Self.adoTypeList);
Self.adoData.Parameters.ParamByName('ID').Value := Self.FID;
UserSession.OpenADOWithOptions(Self.adoData);
if (Self.FID = 0) then
begin
Self.adoData.Insert;
Self.adoData.FieldByName('contact_id').AsInteger := Self.FContactID;
Self.adoData.FieldByName('email_type_id').AsInteger := Self.adoTypeList.FieldByName('id').AsInteger;
UserSession.PostADODataSet(Self.adoData);
Self.FID := Self.adoData.FieldByName('id').AsInteger;
end;
UserSession.EditADODataSet(Self.adoData);
Self.editDefaultEmailAddress.Checked := (Self.adoContact.FieldByName('default_email_id').AsInteger = Self.FID);
Self.editEmailAddress.SetFocus;
Self.Show;
end;
procedure TframeEditContactEmailAddress.UnInitialize;
begin
UserSession.CloseADODataSet(Self.adoData);
UserSession.CloseADODataSet(Self.adoTypeList);
Self.Hide;
end;
procedure TframeEditContactEmailAddress.SaveData;
begin
if (Self.editDefaultEmailAddress.Checked) then
begin
UserSession.EditADODataSet(Self.adoContact);
Self.adoContact.FieldByName('default_email_id').AsInteger := Self.FID;
UserSession.PostADODataSet(Self.adoContact);
end;
UserSession.PostADODataSet(Self.adoData);
UserSession.EditADODataSet(Self.adoData);
end;
procedure TframeEditContactEmailAddress.CancelData;
begin
UserSession.CancelADODataSet(Self.adoData);
UserSession.EditADODataSet(Self.adoData);
end;
end.
And finally, the CloseModalDialog event that I'm assigning to the dialog buttons above:
- Code: Select all
procedure TframeEditContact.CloseModalDialog(Sender: TObject; AParams: TStringList);
var
buttonDialog: TIWCGJQCustomDialogButton;
strFrameName: String;
begin
buttonDialog := (Sender AS TIWCGJQCustomDialogButton);
strFrameName := Self.dialogModal.ExtraTagParams[0];
if (strFrameName = Self.FframeEditContactAddress.Name) then
begin
if (buttonDialog.Text = Include.C_DIALOG_BUTTON_CAPTION_SAVE) then
Self.FframeEditContactAddress.SaveData
else
Self.FframeEditContactAddress.CancelData;
Self.FframeEditContactAddress.UnInitialize;
Self.RefreshGrid(Self.gridAddresses);
end
else if (strFrameName = Self.FframeEditContactPhone.Name) then
begin
if (buttonDialog.Text = Include.C_DIALOG_BUTTON_CAPTION_SAVE) then
Self.FframeEditContactPhone.SaveData
else
Self.FframeEditContactPhone.CancelData;
Self.FframeEditContactPhone.UnInitialize;
Self.RefreshGrid(Self.gridTelephoneNumbers);
end
else if (strFrameName = Self.FframeEditContactEmail.Name) then
begin
if (buttonDialog.Text = Include.C_DIALOG_BUTTON_CAPTION_SAVE) then
Self.FframeEditContactEmail.SaveData
else
Self.FframeEditContactEmail.CancelData;
Self.FframeEditContactEmail.UnInitialize;
Self.RefreshGrid(Self.gridEmailAddresses);
end
else if (strFrameName = Self.FframeEditContactActivity.Name) then
begin
if (buttonDialog.Text = Include.C_DIALOG_BUTTON_CAPTION_SAVE) then
Self.FframeEditContactActivity.SaveData
else
Self.FframeEditContactActivity.CancelData;
Self.FframeEditContactActivity.UnInitialize;
Self.RefreshGrid(Self.gridActivity);
end;
Self.dialogModal.Visible := False;
Self.dialogModal.JQDialogOptions.Close(False);
end;
You are welcomed to email me directly Scottwgast at g mail dot com