Version 22.49.2: Oct 18, 2022 Code refactoring related to forms.

This commit is contained in:
acanas 2022-10-18 00:42:47 +02:00
parent a9c5d4d1d0
commit 2349e67e1b
14 changed files with 49 additions and 30 deletions

View File

@ -312,7 +312,7 @@ void ID_WriteUsrIDs (struct Usr_Data *UsrDat,const char *Anchor)
ICanSeeUsrID = ID_ICanSeeOtherUsrIDs (UsrDat);
ICanConfirmUsrID = ICanSeeUsrID &&
(UsrDat->UsrCod != Gbl.Usrs.Me.UsrDat.UsrCod) && // Not me
!Gbl.Form.Inside && // Not inside another form
!Frm_CheckIfInside () && // Not inside another form
Act_GetBrowserTab (Gbl.Action.Act) == Act_BRW_1ST_TAB; // Only in main browser tab
for (NumID = 0;

View File

@ -606,10 +606,11 @@ TODO: Fix bug: error al enviar un mensaje a dos recipientes, error on duplicate
TODO: Attach pdf files in multimedia.
*/
#define Log_PLATFORM_VERSION "SWAD 22.49.1 (2022-10-17)"
#define Log_PLATFORM_VERSION "SWAD 22.49.2 (2022-10-18)"
#define CSS_FILE "swad22.49.css"
#define JS_FILE "swad22.49.js"
/*
Version 22.49.2: Oct 18, 2022 Code refactoring related to forms. (333189 lines)
Version 22.49.1: Oct 17, 2022 Fixed bug filtering projects. (333176 lines)
Version 22.49: Oct 16, 2022 Changes in project review form. (333161 lines)
Version 22.48: Oct 15, 2022 Code optimization related to nick links. (333157 lines)

View File

@ -905,7 +905,7 @@ void Cty_WriteSelectorOfCountry (void)
void Cty_WriteCountryName (long CtyCod)
{
char CtyName[Cty_MAX_BYTES_NAME + 1];
bool PutForm = !Gbl.Form.Inside && // Only if not inside another form
bool PutForm = !Frm_CheckIfInside () && // Only if not inside another form
Act_GetBrowserTab (Gbl.Action.Act) == Act_BRW_1ST_TAB; // Only in main browser tab
/***** Get country name *****/

View File

@ -41,6 +41,12 @@
extern struct Globals Gbl;
/*****************************************************************************/
/************************* Private global variables **************************/
/*****************************************************************************/
static bool Frm_Inside = false;
/*****************************************************************************/
/**************************** Private prototypes *****************************/
/*****************************************************************************/
@ -48,6 +54,8 @@ extern struct Globals Gbl;
static void Frm_BeginFormInternal (Act_Action_t NextAction,bool PutParameterLocationIfNoSesion,
const char *Id,const char *Anchor,const char *OnSubmit);
static inline void Frm_SetInside (bool Inside);
/*****************************************************************************/
/******************************** Begin a form *******************************/
/*****************************************************************************/
@ -88,7 +96,7 @@ static void Frm_BeginFormInternal (Act_Action_t NextAction,bool PutParameterLoca
extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES];
char ParamsStr[Frm_MAX_BYTES_PARAMS_STR + 1];
if (!Gbl.Form.Inside)
if (!Frm_CheckIfInside ())
{
/* Begin form */
HTM_TxtF ("<form method=\"post\" action=\"%s/%s",
@ -126,7 +134,7 @@ static void Frm_BeginFormInternal (Act_Action_t NextAction,bool PutParameterLoca
Frm_SetParamsForm (ParamsStr,NextAction,PutParameterLocationIfNoSesion);
HTM_Txt (ParamsStr);
Gbl.Form.Inside = true;
Frm_SetInside (true);
}
}
@ -139,13 +147,13 @@ static void Frm_BeginFormInternal (Act_Action_t NextAction,bool PutParameterLoca
*/
void Frm_BeginFormNoAction (void)
{
if (!Gbl.Form.Inside)
if (!Frm_CheckIfInside ())
{
/* Begin form */
HTM_Txt ("<form accept-charset=\"UTF-8\""
" onsubmit=\"return false;\">"); // Form that can not be submitted, to avoid enter key to send it
Gbl.Form.Inside = true;
Frm_SetInside (true);
}
}
@ -215,10 +223,10 @@ void Frm_SetParamsForm (char ParamsStr[Frm_MAX_BYTES_PARAMS_STR + 1],Act_Action_
void Frm_EndForm (void)
{
if (Gbl.Form.Inside)
if (Frm_CheckIfInside ())
{
HTM_Txt ("</form>");
Gbl.Form.Inside = false;
Frm_SetInside (false);
}
}
@ -299,3 +307,17 @@ void Frm_LabelColumn (const char *TDClass,const char *Id,const char *Label)
/***** Column/cell end *****/
HTM_TD_End ();
}
/*****************************************************************************/
/************** Set to true inside a form to avoid nested forms **************/
/*****************************************************************************/
static inline void Frm_SetInside (bool Inside)
{
Frm_Inside = Inside;
}
bool Frm_CheckIfInside (void)
{
return Frm_Inside;
}

View File

@ -64,4 +64,6 @@ void Frm_FreeAnchorStr (char *Anchor);
void Frm_LabelColumn (const char *TDClass,const char *Id,const char *Label);
bool Frm_CheckIfInside (void);
#endif

View File

@ -106,8 +106,6 @@ void Gbl_InitializeGlobals (void)
Gbl.F.XML = NULL;
Gbl.F.Rep = NULL; // Report
Gbl.Form.Inside = false; // Set to true inside a form to avoid nested forms
Gbl.Box.Nested = -1; // -1 means no box open
Gbl.Alerts.Num = 0; // No pending alerts to be shown

View File

@ -75,10 +75,6 @@ struct Globals
struct Files F;
MYSQL mysql;
pid_t PID; // PID of current process
struct
{
bool Inside; // Set to true inside a form to avoid nested forms
} Form;
struct
{
int Nested; // Index of top open box

View File

@ -362,7 +362,7 @@ void Grp_ShowFormToSelectSeveralGroups (void (*FuncParams) (void *Args),void *Ar
return;
/***** Begin box *****/
ICanEdit = !Gbl.Form.Inside &&
ICanEdit = !Frm_CheckIfInside () &&
(Gbl.Usrs.Me.Role.Logged == Rol_TCH ||
Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM);
if (ICanEdit)
@ -1706,8 +1706,8 @@ void Grp_ShowLstGrpsToChgMyGrps (void)
unsigned NumGrpTyp;
unsigned NumGrpsThisTypeIBelong;
unsigned NumGrpsIBelong = 0;
bool PutFormToChangeGrps = !Gbl.Form.Inside; // Not inside another form (record card)
bool ICanEdit = !Gbl.Form.Inside &&
bool PutFormToChangeGrps = !Frm_CheckIfInside (); // Not inside another form (record card)
bool ICanEdit = !Frm_CheckIfInside () &&
(Gbl.Usrs.Me.Role.Logged == Rol_TCH ||
Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM);
bool ICanChangeMyGrps = false;

View File

@ -205,7 +205,7 @@ void Ins_SeeInsWithPendingCtrs (void)
void Ins_DrawInstitutionLogoWithLink (struct Ins_Instit *Ins,unsigned Size)
{
bool PutLink = !Gbl.Form.Inside; // Don't put link to institution if already inside a form
bool PutLink = !Frm_CheckIfInside (); // Don't put link to institution if already inside a form
if (PutLink)
{

View File

@ -1831,7 +1831,7 @@ static void Med_AlertThirdPartyCookies (void)
Ale_ShowAlertAndButton1 (Ale_INFO,Txt_To_watch_multimedia_content_from_another_website_you_have_to_accept_third_party_cookies_in_your_personal_settings);
/* Put form to change cookies preferences */
if (!Gbl.Form.Inside)
if (!Frm_CheckIfInside ())
Lay_PutContextualLinkIconText (ActReqEdiSet,Coo_COOKIES_ID,
NULL,NULL,
"cog.svg",Ico_BLACK,

View File

@ -486,7 +486,7 @@ void Ntf_ShowMyNotifications (void)
if (PutLink)
{
Action = Ntf_StartFormGoToAction (NotifyEvent,Hie.Crs.CrsCod,&UsrDat,Cod,&Forums);
PutLink = Gbl.Form.Inside;
PutLink = Frm_CheckIfInside ();
}
if (PutLink)
@ -504,7 +504,7 @@ void Ntf_ShowMyNotifications (void)
if (PutLink)
{
Action = Ntf_StartFormGoToAction (NotifyEvent,Hie.Crs.CrsCod,&UsrDat,Cod,&Forums);
PutLink = Gbl.Form.Inside;
PutLink = Frm_CheckIfInside ();
HTM_BUTTON_Submit_Begin (Txt_NOTIFY_EVENTS_SINGULAR[NotifyEvent],
"class=\"LT %s_%s\"",
@ -537,7 +537,7 @@ void Ntf_ShowMyNotifications (void)
if (PutLink)
{
Action = Ntf_StartFormGoToAction (NotifyEvent,Hie.Crs.CrsCod,&UsrDat,Cod,&Forums);
PutLink = Gbl.Form.Inside;
PutLink = Frm_CheckIfInside ();
}
if (PutLink)
@ -561,7 +561,7 @@ void Ntf_ShowMyNotifications (void)
if (PutLink)
{
Action = Ntf_StartFormGoToAction (NotifyEvent,Hie.Crs.CrsCod,&UsrDat,Cod,&Forums);
PutLink = Gbl.Form.Inside;
PutLink = Frm_CheckIfInside ();
}
if (PutLink)
@ -815,7 +815,7 @@ static Act_Action_t Ntf_StartFormGoToAction (Ntf_NotifyEvent_t NotifyEvent,
}
/***** Parameter to go to another course/degree/center/institution *****/
if (Gbl.Form.Inside)
if (Frm_CheckIfInside ())
{
if (CrsCod > 0) // Course specified
{

View File

@ -1250,8 +1250,8 @@ void Pho_ShowUsrPhoto (const struct Usr_Data *UsrDat,const char *PhotoURL,
bool BrowserTabIs1stTab = (BrowserTab == Act_BRW_1ST_TAB ||
BrowserTab == Act_AJAX_NORMAL ||
BrowserTab == Act_AJAX_RFRESH);
bool PutLinkToPublicProfile = !Gbl.Form.Inside && // Only if not inside another form
BrowserTabIs1stTab; // Only in main browser tab (or AJAX)
bool PutLinkToPublicProfile = !Frm_CheckIfInside () && // Only if not inside another form
BrowserTabIs1stTab; // Only in main browser tab (or AJAX)
char *CaptionStr;
char *ImgStr;

View File

@ -2099,7 +2099,7 @@ void Rec_ShowSharedUsrRecord (Rec_SharedRecordViewType_t TypeOfView,
Rec_RecordHelp[Rec_SHA_RECORD_LIST] = Rec_RecordListHelp[UsrDat->Roles.InCurrentCrs];
PutFormLinks = !Gbl.Form.Inside && // Only if not inside another form
PutFormLinks = !Frm_CheckIfInside () && // Only if not inside another form
Act_GetBrowserTab (Gbl.Action.Act) == Act_BRW_1ST_TAB; // Only in main browser tab
Ins.InsCod = UsrDat->InsCod;
@ -2323,7 +2323,7 @@ static void Rec_PutIconsCommands (__attribute__((unused)) void *Args)
[Rol_SYS_ADM] = ActReqMdfOth,
};
if (!Gbl.Form.Inside && // Only if not inside another form
if (!Frm_CheckIfInside () && // Only if not inside another form
Act_GetBrowserTab (Gbl.Action.Act) == Act_BRW_1ST_TAB && // Only in main browser tab
Gbl.Usrs.Me.Logged) // Only if I am logged
{

View File

@ -598,7 +598,7 @@ static void TmlNot_PutFormGoToAction (const struct TmlNot_Note *Not,
};
if (Not->Unavailable || // File/notice... pointed by this note is unavailable
Gbl.Form.Inside) // Inside another form
Frm_CheckIfInside ()) // Inside another form
{
/***** Do not put form *****/
/* Begin container */