CGDevTools Forum

Welcome to the Official CGDevTools Support Community Forums.

Adding and removing buttons programmatically?

by kmccoy » 15 Mar 2013 20:14

What is the best practice for adding and removing buttons programmatically? My app needs to add/remove accordion buttons depending on if you have logged in correctly.

I have this feature working, but the accordion is now "sticky". When the screen renders and the user clicks on an accordion button, nothing happens. The user must click on an unwanted button to make that one expand. Then the user must click on the wanted button to make it expand.

Note that the accordion works properly until I change some buttons.

What Delphi steps must I take to make the accordion responsive after an update? I have zero Java experience, so I hope there is a Delphi/CGDevTools solution :-)

Here is my accordion code:

Code: Select all
PROCEDURE TMainFrm.UpdateSecurity(ValidLogin : Boolean);
BEGIN
    at_ApplyForMembership.Visible := NOT UserSession.IsMember; // existing members don't need to reapply

    IF ValidLogin THEN BEGIN
        {TODO -oKevin -cToDo : enable secure accordion tabs}
        pnllstEvents.Enabled            := TRUE;
        plApplication.Enabled           := FALSE;
        at_ContactInfo.Enabled          := TRUE;
        pnllstSecurity.Items[0].Visible := FALSE; // login
        pnllstSecurity.Items[1].Visible := TRUE;  // log out
        pnllstSecurity.Items[2].Visible := FALSE; // pw recover
        pnllstSecurity.Items[3].Visible := FALSE; // request guest account/password
    END
    ELSE BEGIN
        {TODO -oKevin -cToDo : disable secure accordion tabs}
        pnllstEvents.Enabled            := FALSE;
        plApplication.Enabled           := TRUE;
        at_ContactInfo.Enabled          := FALSE;
        pnllstSecurity.Items[0].Visible := TRUE;  // login
        pnllstSecurity.Items[1].Visible := FALSE; // log out
        pnllstSecurity.Items[2].Visible := TRUE;  // pw recover
        pnllstSecurity.Items[3].Visible := TRUE;  // request guest account/password
    END;
END;


Below is the form when a user (me) has logged in correctly - not that the membership application button is not visible:
Image
Best Regards,

Kevin G. McCoy
kmccoy
 
Posts: 90
Joined: 08 Oct 2012 13:01

by Jorge Sousa » 15 Mar 2013 21:38

Hi Kevin

What kind of buttons?

And you mean programmatically and within an AJAX/ASYNC, right?

Regards

cgdevtools
Best Regards
CGDevTools Develop / Support Team
Home Page: http://www.cgdevtools.com
Jorge Sousa
 
Posts: 4261
Joined: 17 May 2012 09:58

by kmccoy » 15 Mar 2013 22:04

cgdevtools_support wrote:What kind of buttons?


Top level Accordion buttons when it is stuck. The Accordion does not open and show the sub-buttons.

cgdevtools_support wrote:And you mean programmatically and within an AJAX/ASYNC, right?


I called the code I posted above from within a button click event in a child frame.

I also tried this and it still does not work:

The form itself:
Code: Select all
    TMainFrm = CLASS(TIWAppForm)
        acModeSelector:        TIWCGJQAccordion;
        at_ApplyForMembership: TIWCGJQAccordionTab;
        at_Committee:          TIWCGJQAccordionTab;
        at_ContactInfo:        TIWCGJQAccordionTab;
        at_Employment:         TIWCGJQAccordionTab;
        at_Events:             TIWCGJQAccordionTab;
        at_Home:               TIWCGJQAccordionTab;
        at_MemberServices:     TIWCGJQAccordionTab;
        at_Search:             TIWCGJQAccordionTab;
        at_Security:           TIWCGJQAccordionTab;
        at_TrainingOps:        TIWCGJQAccordionTab;
        imgLogo:               TIWCGJQImage;
        IWCGJQLockIndicator1:  TIWCGJQLockIndicator;
        lblFeature:            TIWCGJQLabel;
        plApplication:         TIWCGPanelList;
        plCommittee:           TIWCGPanelList;
        plEmployment:          TIWCGPanelList;
        pnllstContactInfo:     TIWCGPanelList;
        pnllstEvents:          TIWCGPanelList;
        pnllstHome:            TIWCGPanelList;
        pnllstMemberService:   TIWCGPanelList;
        pnllstSearch:          TIWCGPanelList;
        pnllstSecurity:        TIWCGPanelList;
        pnllstTrainingOps:     TIWCGPanelList;
        RegionProcessing:      TIWCGJQRegion;
        rgnBanner:             TIWCGJQRegion;
        rgnLeft:               TIWCGJQRegion;
        rgnMain:               TIWCGJQRegion;
        ThemeSwitcher:         TIWCGJQThemeSwitcher;
        PROCEDURE AccordionSubItemClick(Sender : TObject; AParams : TStringList);
        PROCEDURE imgLogoClick(Sender : TObject; AParams : TStringList);
        PROCEDURE IWAppFormRender(Sender : TObject);
    PRIVATE
        //        FCurTabIndex:          Integer;
        FFrameComp: TIWCGJQFrame;
        //        PROCEDURE SetCurTabIndex(CONST Value : Integer);
        //        PROPERTY CurTabIndex: Integer Read FCurTabIndex Write SetCurTabIndex;
        FUNCTION CreateNewFrame(AFrameClass : TIWCGFrameClass) : TFrame;
        FUNCTION GetFrameClassForSubTab(ATab : TMinorTabs) : TIWCGFrameClass;
        PROCEDURE SetFrameComp(CONST Value : TIWCGJQFrame);
    PUBLIC
        PROCEDURE ShowQuiescentFrame;
        PROCEDURE UpdateSecurity(ValidLogin : Boolean); OVERLOAD;
        PROCEDURE UpdateSecurity; OVERLOAD;
        PROPERTY FrameComp: TIWCGJQFrame Read FFrameComp Write SetFrameComp;
    END;


I added the async code below and it did not help. The accordion remains "stuck" until you click on several of its top level buttons, then it starts to work properly.

Code: Select all
PROCEDURE TMainFrm.UpdateSecurity(ValidLogin : Boolean);
VAR
    RenderAsync : Boolean;
BEGIN
    RenderAsync := CGIsCallBackProcessing;

    at_ApplyForMembership.Visible := NOT UserSession.IsMember;

    IF ValidLogin THEN BEGIN
        {TODO -oKevin -cToDo : enable secure accordion tabs}
        pnllstEvents.Enabled            := TRUE;
        plApplication.Enabled           := FALSE;
        at_ContactInfo.Enabled          := TRUE;
        pnllstSecurity.Items[0].Visible := FALSE; // login
        pnllstSecurity.Items[1].Visible := TRUE;  // log out
        pnllstSecurity.Items[2].Visible := FALSE; // pw recover
        pnllstSecurity.Items[3].Visible := FALSE; // request guest
    END
    ELSE BEGIN
        {TODO -oKevin -cToDo : disable secure accordion tabs}
        pnllstEvents.Enabled            := FALSE;
        plApplication.Enabled           := TRUE;
        at_ContactInfo.Enabled          := FALSE;
        pnllstSecurity.Items[0].Visible := TRUE;  // login
        pnllstSecurity.Items[1].Visible := FALSE; // log out
        pnllstSecurity.Items[2].Visible := TRUE;  // pw recover
        pnllstSecurity.Items[3].Visible := TRUE;  // request guest
    END;

    IF RenderAsync THEN BEGIN
        CGCallBackEnableAjaxResponse;
        RenderRegionAsync(rgnMain, FALSE, TRUE); // region holding child (center) frame
        RenderRegionAsync(rgnLeft, FALSE, TRUE);  // region holding the accordion
    END;
END;
Best Regards,

Kevin G. McCoy
kmccoy
 
Posts: 90
Joined: 08 Oct 2012 13:01

by Jorge Sousa » 15 Mar 2013 23:41

Hi Kevin

Please send us a demo,

We look at it during the weekend:

It's very difficult to know what are these:

pnllstEvents.Enabled := FALSE;
plApplication.Enabled := TRUE;
at_ContactInfo.Enabled := FALSE;
pnllstSecurity.Items[0].Visible := TRUE; // login

Tia

Regards

cgdevtools
Best Regards
CGDevTools Develop / Support Team
Home Page: http://www.cgdevtools.com
Jorge Sousa
 
Posts: 4261
Joined: 17 May 2012 09:58

by kmccoy » 16 Mar 2013 00:59

cgdevtools_support wrote:Please send us a demo,


That is very difficult, because it is a large database app and the security on the DB server is very tight (no unknown IP addresses allowed to connect + plus a very strict firewall)

We could set up a remote session though. How can we do that? I am in UTC -08:00 timezone (Pacific Time).
Best Regards,

Kevin G. McCoy
kmccoy
 
Posts: 90
Joined: 08 Oct 2012 13:01

by fduenas » 17 May 2013 22:54

I think most of the components are panel items and accordion items.

You're right to put the RenderAsync Methods, but they will only act after any other ASync event is executed,
Thats why they got stuck until there is another item clicked (another async method executed)

So maybe what you should do is to call your UpdateSecurity method in the the Async Click of your button that you use to login for example.

The RenderAsync what is does is to build an xml response (AJAx) to the browser, in this case it is an IW update protocol string that will tell the browser what to refresh after the call is returned from the server. so you have to call RenderAsync mostly inside AsyncXXXX events so your Interface should be refreshed as expected.
fduenas
 
Posts: 124
Joined: 29 May 2012 12:54


Return to JQAccordion

Who is online

Users browsing this forum: No registered users and 2 guests

Contact Us.