CGDevTools Forum

Welcome to the Official CGDevTools Support Community Forums.

New Event (OnBeforeOpen)

by ScottWGast » 19 May 2016 21:16

Monte,

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
ScottWGast
 
Posts: 875
Joined: 23 May 2012 11:02

by ScottWGast » 19 May 2016 21:24

I just realized that you are using the DropDown component... are you actually getting an error that pops up, or is the collection of dropdown items empty? I swapped out the dropdown component with ComboBoxEx.

Scott
ScottWGast
 
Posts: 875
Joined: 23 May 2012 11:02

by assapan » 20 May 2016 10:20

ScottWGast wrote: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.


Hi sorry to interfere in your conversation but i'd want to understand what leads you to do so .
Do you use Dialog frame ?
Why create the frames at start and not when required ?
there is processcommand procedure which can be used = to your initialize.

do not misunderstand my intention , i want to know how other programmers operate to lead to a better coding for myself.

Claude
Want to visit Ardeche http://leclosdelarc.fr/index.php
The Pont d’Arc Cavern http://en.cavernedupontdarc.fr
Image
User avatar
assapan
 
Posts: 600
Joined: 16 Dec 2013 12:04
Location: France

by ScottWGast » 20 May 2016 17:46

All of the frames are used, in every session. It only takes about 1 second to create the frames at startup, right after they login. Then I can use the frames whenever I want without having to check if whether or not I have to create it on the fly.

I like using the modal dialog because it provides a clean reliable interface for drilling down into a database.



Plus, my code is easier to read, IMO.

Hope this answers your questions!

Scott
ScottWGast
 
Posts: 875
Joined: 23 May 2012 11:02

by assapan » 20 May 2016 17:55

Hi Scott,
I understand your point of view but then you face a problem of refresh of the frame.
I also have separate frame for each dialog it is more "readable" and customizable but i create frame on the fly and rendering time is not due to frame creation but to its content.
so i think if you compare creation + actualization versus actualization only time will be nearly the same because creation time is server dependent when actualization is client dependent.
My 2 cents.
Want to visit Ardeche http://leclosdelarc.fr/index.php
The Pont d’Arc Cavern http://en.cavernedupontdarc.fr
Image
User avatar
assapan
 
Posts: 600
Joined: 16 Dec 2013 12:04
Location: France

by ScottWGast » 20 May 2016 19:35

I agree that the creation time is very short and the rendering time is content dependent. This is another reason, IMO, to go ahead and create the frames that will be used during the session.

All that being said, there's always more than one way to skin a cat :)
ScottWGast
 
Posts: 875
Joined: 23 May 2012 11:02

Previous

Return to JQDialogEx

cron

Who is online

Users browsing this forum: No registered users and 1 guest

Contact Us.