Build a Conference App part 2
In the video above I go through some of the things you can do in order to get a better flow in your application. There are some things that you need to code by hand and in this post I'll try to explain some of it.
First I want to remind you that if you work in a country where you might have to copy your database between two computers setup to use different languages, then it is a good idea to reindex the tables. You do that by opening the Tools -> Database Builder and then select Reindex in the Maintenance menu. Just select all and then press Reindex, click both the buttons in order to select all again and click Reindex once more and your done.
The next thing we will look at is the Navigation. In addition to NavigateForward, that is used to change views, DataFlex also provides NavigateCloseTo that brings you back to a sertain level in the breadcrumb and NavigateCancelTo that brings you back to a point in the navigation so that you can navigate forward from there. We use the later procedure as follows:
Get GetViewIndex of ghoWebViewStack oAgendeSelect to iIndex If (iIndex>-1) Begin Send NavigateCancelTo oAgendeSelect End Send NavigateForward of oSpeakerZoom Self
The GetViewIndex starts out by checking if the view is in the breadcrumb stack and if so we cancel back to it before NavigateForward
As default the Speaker Select list is looking at the Presenter table that relates the agenda with an attendee to make that attendee a speaker. But one speaker can have more than one presentation, which means that the list of speakers is full of duplicates. We can easily fix this by telling DataFlex that it should use the Attendee table as main DataDictionary instead. In the Attendee table there is only one of each user, so then the list of speakers wont show more than one of each either.
- Set Main_DD to oPresenter_DD - Set Server to oPresenter_DD // Changed to + Set Main_DD to oAttendee_DD + Set Server to oAttendee_DD
Add speakers to talk
When we are in the TalkZoom view we might want to add a Speaker to the Agenda item. We do this by adding an "Add"-button to the view. And then we create a new view called SpeakerPick that shows a list of attendees that we can add as users.
Object oWebButton1 is a cWebButton Set piColumnSpan to 4 Set piColumnIndex to 0 Set psCaption to "Add Speaker" Procedure OnClick Register_Object oSpeakerPick Send NavigateForward of oSpeakerPick Self End_Procedure Procedure OnGetNavigateForwardData tWebNavigateData ByRef NavigateData Handle hoToView Move True to NavigateData.bSaveBeforeNavigate Get NamedValueAdd NavigateData.NamedValues "AgendaNr" Agenda.AgendaNr to NavigateData.NamedValues End_Procedure End_Object
In the OnRowClick procedure of the SpeakerPick list we add a procedure call to a function that adds the selected user to the presenter table, using the NavigateData array to pass the AgendaNr from the talk to the pick view.
tWebNavigateData NavigateData Get GetNavigateData to NavigateData String psAgendaNr Get NamedValueGet NavigateData.NamedValues "AgendaNr" to psAgendaNr Send addSpeaker of oPresenters_DD psAgendaNr Attendee.AttendeeNr
Then I created the addSpeaker procedure in the DataDictionary. The reason for this is that this is a procedure that I might want to use from other views and though you can call procedures directly from other views I feel that it is more natural to keep procedures that should be used in many views in the DataDictionary that manages the data.
Procedure addSpeaker Integer iAgenaNr Integer iSpeakerNr Reread Presenters Clear Presenters Move iAgenaNr to Presenters.Agenda Move iSpeakerNr to Presenters.Presenter SaveRecord Presenters Unlock Reread Attendee Move 1 to Attendee.Speaker SaveRecord Attendee Unlock End_Procedure
The addSpeaker takes two parameters as input, AgendaNr and SpeakerNr and adds them to the presenter table. Then it also sets the speaker switch to 1 in the attendee marking that attendee to be a speaker. And while I was at it I also create a removeSpeaker procedure that starts by removing the speaker from the talk and then checks if the speaker has any other talks. If not, then reset the speaker switch to zero.
Procedure removeSpeaker Integer iAgenaNr Integer iSpeakerNr Move iAgenaNr to Presenters.Agenda Move iSpeakerNr to Presenters.Presenter Find eq Presenters by Index.3 Delete Presenters Clear Presenters Move iSpeakerNr to Presenters.Presenter Find ge Presenters by Index.1 If (iSpeakerNr Presenters.Presenter) Begin Clear Attendee Move iSpeakerNr to Attendee.AttendeeNr Find eq Attendee by Index.1 Reread Attendee Move 0 to Attendee.Speaker SaveRecord Attendee Unlock End End_Procedure
Now we do not want everyone to be able to add speakers to talks, so we need some kind of login. This is provided by the DataFlex framework, so we can just use the default functionality. In order to check if a user is logged in you use the IsLoggedIn function and you do that check right before you open your view in the procedure called OnNavigateForward.
Boolean bLoggedIn WebSet pbRender of oWebButton1 to False Get IsLoggedIn of ghoWebSessionManager to bLoggedIn If (bLoggedIn) Begin WebSet pbRender of oWebButton1 to True End
Then you can use the pbRender, pbVisible or pbEnabled to change the accessibility of components in your view.
This part contains quite a lot of code so I recommend you take a look at the SalesPerson view in the Mobile Order Entry example that comes with the DataFlex installation. That is one of the best resources to see how things are done in DataFlex. But you should also make yourself familiar with the help tool, just press F1. And if you need any more help you have the DataAccess Support Forum
If you enjoy this video then don't forget to go into the channel on youtube and subscribe or add your mail to my newsletter. You may also want to see the entire course Discovering DataFlex available on youtube.
- DataFlex Conference App Mobile Coding