Form S_190FB

LANSA

Form S_190FB

*===================================================================;
*;
* Component : S_190FB;
* Type : Form;
* Ancestor : PRIM_FORM (Primitive Form);
*;
* Description : Poll Attributes; ;
*;
* Full Description; This form allows maintenance of poll header attributes.;
* It includes changing the status of a poll; ;
*;
* Disclaimer : The following material is supplied as sample material;
* only. No warranty concerning this material or its use;
* in any way whatsoever is expressed or implied.;
*;
* ===================================================================;
;
FUNCTION OPTIONS(*DIRECT);
BEGIN_COM FORMPOSITION(ScreenCenter) FORMSTYLE(Owned) HEIGHT(165) LAYOUTMANAGER(#ATLM_3) LEFT(587) TOP(154) VISIBLE(False) VISUALSTYLE(#VS_NORM) WIDTH(418);
DEFINE_COM CLASS(#PRIM_STBR) NAME(#STBR_1) DISPLAYPOSITION(1) HEIGHT(25) LEFT(0) MESSAGEPOSITION(1) PARENT(#COM_OWNER) TABPOSITION(1) TOP(113) WIDTH(410);
DEFINE_COM CLASS(#PRIM_FWLM) NAME(#FWLM_1) FLOWOPERATION(Center) FLOWOPERATIONHOR(Spread);
DEFINE_COM CLASS(#PRIM_ATLM) NAME(#ATLM_1);
DEFINE_COM CLASS(#PRIM_GPBX) NAME(#GPBX_1) DISPLAYPOSITION(2) HEIGHT(113) LAYOUTMANAGER(#FWLM_2) LEFT(0) PARENT(#COM_OWNER) TABPOSITION(2) TABSTOP(False) TOP(0) WIDTH(310);
DEFINE_COM CLASS(#S_190PDS.Visual) NAME(#S_190PDS) DISPLAYPOSITION(1) HEIGHT(19) LEFT(7) MARGINLEFT(80) PARENT(#GPBX_1) TABPOSITION(1) TOP(13) WIDTH(294);
DEFINE_COM CLASS(#PRIM_FWLM) NAME(#FWLM_2) DIRECTION(TopToBottom) FLOWOPERATION(Center) FLOWOPERATIONVER(Spread) SPACING(2) SPACINGITEMS(2);
DEFINE_COM CLASS(#PRIM_FWLI) NAME(#FWLI_1) MANAGE(#S_190PDS) PARENT(#FWLM_2);
DEFINE_COM CLASS(#S_190PPW.Visual) NAME(#S_190PPW) DISPLAYPOSITION(2) HEIGHT(19) LEFT(7) MARGINLEFT(80) PARENT(#GPBX_1) TABPOSITION(2) TOP(36) WIDTH(166);
DEFINE_COM CLASS(#PRIM_FWLI) NAME(#FWLI_2) MANAGE(#S_190PPW) PARENT(#FWLM_2);
DEFINE_COM CLASS(#PRIM_FWLI) NAME(#FWLI_3) MANAGE(#S_190PST) PARENT(#FWLM_2);
DEFINE_COM CLASS(#PRIM_ATLM) NAME(#ATLM_2);
DEFINE_COM CLASS(#PRIM_PANL) NAME(#PANL_STATUS) DISPLAYPOSITION(4) HEIGHT(25) LEFT(7) PARENT(#GPBX_1) TABPOSITION(4) TABSTOP(False) TOP(82) WIDTH(295);
DEFINE_COM CLASS(#PRIM_FWLI) NAME(#FWLI_6) MANAGE(#PANL_STATUS) PARENT(#FWLM_2);
DEFINE_COM CLASS(#S_190PST.Visual) NAME(#S_190PST) DISPLAYPOSITION(1) HEIGHT(19) MARGINLEFT(80) PARENT(#PANL_STATUS) READONLY(True) TABPOSITION(1) TABSTOP(False) VISUALSTYLE(#VS_NOREAD) WIDTH(161);
DEFINE_COM CLASS(#PRIM_PHBN) NAME(#PHBN_CHGSTATUS) DISPLAYPOSITION(2) LEFT(168) PARENT(#PANL_STATUS) TABPOSITION(2) TOP(0) WIDTH(123);
DEFINE_COM CLASS(#PRIM_GPBX) NAME(#GPBX_CONFIRM) DISPLAYPOSITION(3) HEIGHT(113) LAYOUTMANAGER(#FWLM_3) LEFT(310) PARENT(#COM_OWNER) TABPOSITION(3) TABSTOP(False) TOP(0) WIDTH(100);
DEFINE_COM CLASS(#PRIM_FWLM) NAME(#FWLM_3) DIRECTION(TopToBottom) FLOWOPERATION(Center) FLOWOPERATIONHOR(Spread) SPACING(4) SPACINGITEMS(4);
DEFINE_COM CLASS(#PRIM_PHBN) NAME(#PHBN_CONFIRM) BUTTONDEFAULT(True) CAPTION('Confirm Delete') DISPLAYPOSITION(1) LEFT(7) PARENT(#GPBX_CONFIRM) TABPOSITION(1) TOP(11) WIDTH(85);
DEFINE_COM CLASS(#PRIM_FWLI) NAME(#FWLI_7) MANAGE(#PHBN_CONFIRM) PARENT(#FWLM_3);
DEFINE_COM CLASS(#PRIM_PHBN) NAME(#PHBN_CANCEL) CAPTION('Cancel ') DISPLAYPOSITION(2) LEFT(7) PARENT(#GPBX_CONFIRM) TABPOSITION(2) TOP(40) WIDTH(85);
DEFINE_COM CLASS(#PRIM_FWLI) NAME(#FWLI_8) MANAGE(#PHBN_CANCEL) PARENT(#FWLM_3);
DEFINE_COM CLASS(#PRIM_PHBN) NAME(#PHBN_CLOSE) CAPTION('Close') DISPLAYPOSITION(3) LEFT(7) PARENT(#GPBX_CONFIRM) TABPOSITION(3) TOP(69) WIDTH(85);
DEFINE_COM CLASS(#PRIM_FWLI) NAME(#FWLI_9) MANAGE(#PHBN_CLOSE) PARENT(#FWLM_3);
DEFINE_COM CLASS(#S_155RST) NAME(#S_155RST) HEIGHT(19) LEFT(110) PARENT(#STBR_1) TABSTOP(False) TOP(4) WIDTH(281);
DEFINE_COM CLASS(#S_190PBN.Visual) NAME(#S_190PBN) DISPLAYPOSITION(3) HEIGHT(19) LEFT(7) MARGINLEFT(80) PARENT(#GPBX_1) TABPOSITION(3) TOP(59) WIDTH(294);
DEFINE_COM CLASS(#PRIM_FWLI) NAME(#FWLI_4) MANAGE(#S_190PBN) PARENT(#FWLM_2);
DEFINE_COM CLASS(#PRIM_ATLM) NAME(#ATLM_3);
DEFINE_COM CLASS(#PRIM_ATLI) NAME(#ATLI_1) ATTACHMENT(Bottom) MANAGE(#STBR_1) PARENT(#ATLM_3);
DEFINE_COM CLASS(#PRIM_ATLI) NAME(#ATLI_2) ATTACHMENT(Center) MANAGE(#GPBX_1) PARENT(#ATLM_3);
DEFINE_COM CLASS(#PRIM_ATLI) NAME(#ATLI_3) ATTACHMENT(Right) MANAGE(#GPBX_CONFIRM) PARENT(#ATLM_3);
;
GROUP_BY NAME(#S_GRPPDF) FIELDS(#S_190PID #S_190PDS #S_190PPW #S_190PBN #S_190PST);
GROUP_BY NAME(#S_GRPPDFX) FIELDS(#S_190PDS #S_190PPW #S_190PBN #S_190PST);
;
Def_Cond *inputOK '(#S_190PDS *ne *Blanks) and (#S_190PPW *ne *Blanks) and (#S_190PBN *ne *Blanks)' ;
;
define_evt name(PollDetailsChanged);
define_evt name(PollChangesSaved) ;
define_evt name(PollDeleted) ;
;
define_pty name(CurrPoll) get(*auto #S_190PID) ;
;
* Handle form creation;
EvtRoutine handling(#Com_Owner.CreateInstance);
Set #S_155RST uShowDate(FALSE) uStatusText(' ') uStatusNumber(0);
EndRoutine;
;
* Allow an external function to display this form with poll details;
MthRoutine uShowPoll;
Define_Map *Input #S_190PID #mS_190PID Desc('Poll Identifier') Help(' If poll doesnt exist, assume this is a new poll');
Define_Map *Input #S_ACTIONX #mS_ACTIONX Desc('Action to be carried out') Help('Can be NEW EDIT DELETE OPEN CLOSE');
;
CHANGE #S_190PID #mS_190PID.Value;
CHANGE #S_ACTIONX #mS_ACTIONX.Value;
;
IF '#S_ACTIONX *EQ NEW';
* new poll - generate the next poll identifier, ignore the passed poll identifier;
CHANGE #S_190PID *S_190PID;
endif;
;
* Get the details (if any);
Execute Getdetails;
;
* Not Busy;
Set #S_155RST uBusy(False);
;
* Now show this form modally;
INVOKE METHOD(#COM_OWNER.ShowModalForm);
;
Endroutine;
;
* ;
* Get the details of a poll ready for display;
Subroutine GetDetails;
;
* Set up default values ;
CHANGE #S_GRPPDFX *NULL;
Set #S_190PPW Value('PASSWORD') ;
Set #S_190PBN Value('S_190BANNER.GIF') ;
;
* Overlay default values with actual values (if they exist);
FETCH #S_GRPPDF SETPDF with_key(#S_190PID);
;
* Set up the status field;
execute SETSTATUS;
;
* Turn off any visible errors;
Set (#S_190PDS #S_190PPW #S_190PBN #S_190PST) ShowError(False);
;
EndRoutine;
;
*;
* Set up the screen according to the status of the poll;
Subroutine SETSTATUS;
*;
USE BUILTIN(CLR_MESSAGES);
set (#PHBN_CHGSTATUS #PHBN_CLOSE) Visible(FALSE) ;
set (#PHBN_CANCEL) caption('Cancel') enabled(TRUE);
*;
CASE #S_ACTIONX;
WHEN VALUE_IS('= NEW' '= EDIT');
set #PHBN_CONFIRM caption('Save Changes') enabled(FALSE);
set #PHBN_CANCEL caption('Cancel Changes') enabled(FALSE);
set #PHBN_CLOSE Visible(TRUE);
CASE #S_190PST;
WHEN '= *BLANKS';
* newly defined poll - cannot be opened until saved;
CHANGE #S_190PST DEFINE;
;
WHEN '= DEFINE';
* defined poll - may be opened if the poll has questions;
CHECK_FOR SETPQU with_key(#S_190PID);
IF_STATUS *EQUALKEY;
set #PHBN_CHGSTATUS Visible(TRUE) Caption('Open this Poll');
ENDIF;
;
WHEN '= OPEN';
* an open poll - may be closed;
set #PHBN_CHGSTATUS Visible(TRUE) Caption('Close this Poll');
;
WHEN '= CLOSED';
* a closed poll - can be re-opened;
set #PHBN_CHGSTATUS Visible(TRUE) Caption('Re-Open this Poll');
ENDCASE;
Invoke #S_190PDS.SetFocus;
WHEN '= DELETE';
set #PHBN_CONFIRM caption('Confirm Delete') enabled(TRUE);
Invoke #PHBN_CONFIRM.SetFocus;
MESSAGE MSGTXT('Confirm delete of Poll and any questions and responses');
WHEN '= CLOSE';
set #PHBN_CONFIRM caption('Confirm Close') enabled(TRUE);
Invoke #PHBN_CONFIRM.SetFocus;
CHANGE #S_190PST CLOSED;
WHEN '= OPEN';
set #PHBN_CONFIRM caption('Confirm Open') enabled(TRUE);
Invoke #PHBN_CONFIRM.SetFocus;
CHANGE #S_190PST OPEN;
ENDCASE;
;
endroutine;
*;
* The user has changed the status of the poll;
EVTROUTINE HANDLING(#PHBN_CHGSTATUS.Click);
;
Set #S_155RST uBusy(True);
;
CASE #S_190PST;
;
WHEN '= DEFINE';
* defined poll - open;
CHANGE #S_190PST OPEN;
;
WHEN '= OPEN';
* an open poll - close;
CHANGE #S_190PST CLOSED;
;
WHEN '= CLOSED';
* a closed poll - re-open;
CHANGE #S_190PST OPEN;
;
ENDCASE;
;
* signal that a change to the poll has been made;
signal PollDetailsChanged ;
;
* disable the change status button until saved or cancelled;
set #PHBN_CHGSTATUS enabled(FALSE);
;
Set #S_155RST uBusy(False);
;
ENDROUTINE;
* ;
* User saves changes ;
EVTROUTINE HANDLING(#PHBN_CONFIRM.Click);
;
Set #S_155RST uBusy(True);
;
CASE #S_ACTIONX;
WHEN VALUE_IS('= DELETE');
;
MESSAGE MSGTXT('Deleting responses') TYPE(*STATUS);
DELETE FROM_FILE(SETPRA) WITH_KEY(#S_190PID) VAL_ERROR(*RETURN);
MESSAGE MSGTXT('Deleting respondents') TYPE(*STATUS);
DELETE FROM_FILE(SETPRE) WITH_KEY(#S_190PID) VAL_ERROR(*RETURN);
MESSAGE MSGTXT('Deleting question response options') TYPE(*STATUS);
DELETE FROM_FILE(SETPQS) WITH_KEY(#S_190PID) VAL_ERROR(*RETURN);
MESSAGE MSGTXT('Deleting questions') TYPE(*STATUS);
DELETE FROM_FILE(SETPQU) WITH_KEY(#S_190PID) VAL_ERROR(*RETURN);
DELETE FROM_FILE(SETPDF) WITH_KEY(#S_190PID) VAL_ERROR(*RETURN);
MESSAGE 'Poll deleted sucessfully';
;
signal PollDeleted;
;
OTHERWISE;
;
Message 'Saving Changes' type(*status);
;
CHECK_FOR SETPDF with_key(#S_190PID);
IF_STATUS *EQUALKEY;
UPDATE FIELDS(#S_GRPPDFX) IN_FILE(SETPDF) WITH_KEY(#S_190PID) VAL_ERROR(*NEXT);
ELSE;
INSERT FIELDS(#S_GRPPDF) TO_FILE(SETPDF) VAL_ERROR(*NEXT);
ENDIF;
* Handle error;
If_Status is_Not(*okay);
Set #S_155RST uBusy(False);
Return;
Endif;
;
* enable the change status button (if it was disabled when the user made a status change);
set #PHBN_CHGSTATUS enabled(TRUE);
*;
* Signal that changes to a poll have been saved (and hence the list of polls needs to be rebuilt);
signal PollChangesSaved;
ENDCASE;
;
;
CASE #S_ACTIONX;
WHEN VALUE_IS('= EDIT' '= NEW');
* user remains in this form;
CHANGE #S_ACTIONX EDIT;
execute SETSTATUS;
OTHERWISE;
* user goes back to the parent form;
invoke #Com_Owner.CloseForm;
ENDCASE;
;
Set #S_155RST uBusy(False);
;
ENDROUTINE;
*;
* User abandons changes;
EVTROUTINE HANDLING(#PHBN_CANCEL.Click);
Set #S_155RST uBusy(True);
CASE #S_ACTIONX;
WHEN VALUE_IS('= EDIT' '= NEW');
* user remains in this form with (re)freshed details;
Execute Getdetails;
* enable the change status button (if it was disabled when the user made a status change);
set #PHBN_CHGSTATUS enabled(TRUE);
OTHERWISE;
* user goes back to the parent form;
invoke #Com_Owner.CloseForm;
ENDCASE;
Set #S_155RST uBusy(False);
ENDROUTINE;
*;
* Changes have been made to any of the poll details;
EVTROUTINE HANDLING(#S_190PDS.Changed #S_190PPW.Changed #S_190PBN.Changed) OPTIONS(*NOCLEARMESSAGES *NOCLEARERRORS);
signal PollDetailsChanged;
ENDROUTINE;
*;
* Allow the user to save changes or undo the changes, if they have made changes;
evtroutine handling(#Com_Owner.PollDetailsChanged);
set #PHBN_CANCEL enabled(TRUE);
set #PHBN_CONFIRM enabled(*inputOK);
endroutine;
*;
* Close;
EVTROUTINE HANDLING(#PHBN_CLOSE.Click) ;
invoke #Com_Owner.CloseForm;
ENDROUTINE;
;
END_COM;
;