diff --git a/swad_browser.h b/swad_browser.h index 6953710f..7b52f35b 100644 --- a/swad_browser.h +++ b/swad_browser.h @@ -214,7 +214,7 @@ void Brw_RecLinkFileBrowser (void); void Brw_SetDocumentAsVisible (void); void Brw_SetDocumentAsHidden (void); HidVis_HiddenOrVisible_t Brw_CheckIfFileOrFolderIsSetAsHiddenInDB (Brw_FileType_t FileType, - const char *Path); + const char *Path); void Brw_ShowFileMetadata (void); void Brw_GetLinkToDownloadFile (const char *PathInTree,const char *FileName,char *URL); diff --git a/swad_changelog.h b/swad_changelog.h index 25bcba30..a917ac6a 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -633,10 +633,11 @@ Me sale este error, no s "can npt create received message (duplicated entry '243218-2160773' for key 'UsrCod_MsgCod') */ -#define Log_PLATFORM_VERSION "SWAD 23.39 (2023-10-27)" +#define Log_PLATFORM_VERSION "SWAD 23.40 (2023-10-28)" #define CSS_FILE "swad23.35.1.css" #define JS_FILE "swad22.49.js" /* + Version 23.40: Oct 28, 2023 Code refactoring in view/edit. (335273 lines) Version 23.39: Oct 27, 2023 Code refactoring in contracted/expanded and rubrics. (335209 lines) Version 23.38.3: Oct 27, 2023 When clicking on edition of a program item, expand it if contracted. (335155 lines) Version 23.38.2: Oct 27, 2023 Fix bug showing the question just edited. (335152 lines) diff --git a/swad_contracted_expanded.h b/swad_contracted_expanded.h index a3cd915d..3b3b9e6b 100644 --- a/swad_contracted_expanded.h +++ b/swad_contracted_expanded.h @@ -40,8 +40,4 @@ typedef enum ConExp_EXPANDED = 1, } ConExp_ContractedOrExpanded_t; -/*****************************************************************************/ -/****************************** Public prototypes ****************************/ -/*****************************************************************************/ - #endif diff --git a/swad_program.c b/swad_program.c index b348379f..d33c3db0 100644 --- a/swad_program.c +++ b/swad_program.c @@ -54,6 +54,7 @@ #include "swad_role.h" #include "swad_setting.h" #include "swad_string.h" +#include "swad_view_edit.h" /*****************************************************************************/ /************** External global variables from others modules ****************/ @@ -128,8 +129,8 @@ static void Prg_WriteRowItem (Prg_ListingType_t ListingType, long SelectedItmCod, long SelectedRscCod); static void Prg_PutIconToContractOrExpandItem (struct Prg_Item *Item, - ConExp_ContractedOrExpanded_t ContractedOrExpanded, - bool Editing); + ConExp_ContractedOrExpanded_t ContractedOrExpanded, + VieEdi_ViewOrEdit_t ViewingOrEditing); static void Prg_WriteItemText (long ItmCod,HidVis_HiddenOrVisible_t HiddenOrVisible); static void Prg_WriteRowToCreateItem (long ParentItmCod,unsigned FormLevel); static void Prg_SetTitleClass (char **TitleClass,unsigned Level); @@ -472,20 +473,20 @@ static void Prg_WriteRowItem (Prg_ListingType_t ListingType, { extern const char *HidVis_PrgClass[HidVis_NUM_HIDDEN_VISIBLE]; static unsigned UniqueId = 0; - static bool EditingProgram[Prg_NUM_LISTING_TYPES] = + static VieEdi_ViewOrEdit_t ViewingOrEditingProgram[Prg_NUM_LISTING_TYPES] = { - [Prg_PRINT ] = false, - [Prg_VIEW ] = false, - [Prg_EDIT_ITEMS ] = true, - [Prg_FORM_NEW_END_ITEM ] = true, - [Prg_FORM_NEW_CHILD_ITEM ] = true, - [Prg_FORM_EDIT_ITEM ] = true, - [Prg_END_EDIT_ITEM ] = true, - [Prg_RECEIVE_ITEM ] = true, - [Prg_EDIT_RESOURCES ] = true, - [Prg_EDIT_RESOURCE_LINK ] = true, - [Prg_CHANGE_RESOURCE_LINK] = true, - [Prg_END_EDIT_RES ] = true, + [Prg_PRINT ] = VieEdi_VIEW, + [Prg_VIEW ] = VieEdi_VIEW, + [Prg_EDIT_ITEMS ] = VieEdi_EDIT, + [Prg_FORM_NEW_END_ITEM ] = VieEdi_EDIT, + [Prg_FORM_NEW_CHILD_ITEM ] = VieEdi_EDIT, + [Prg_FORM_EDIT_ITEM ] = VieEdi_EDIT, + [Prg_END_EDIT_ITEM ] = VieEdi_EDIT, + [Prg_RECEIVE_ITEM ] = VieEdi_EDIT, + [Prg_EDIT_RESOURCES ] = VieEdi_EDIT, + [Prg_EDIT_RESOURCE_LINK ] = VieEdi_EDIT, + [Prg_CHANGE_RESOURCE_LINK] = VieEdi_EDIT, + [Prg_END_EDIT_RES ] = VieEdi_EDIT, }; static const char *RowSpan[ConExp_NUM_CONTRACTED_EXPANDED] = { @@ -512,7 +513,8 @@ static void Prg_WriteRowItem (Prg_ListingType_t ListingType, break; } - if (EditingProgram[ListingType] || HiddenOrVisible == HidVis_VISIBLE) + if (ViewingOrEditingProgram[ListingType] == VieEdi_EDIT || + HiddenOrVisible == HidVis_VISIBLE) { /***** Increase number in level *****/ Prg_IncreaseNumberInLevel (Item->Hierarchy.Level); @@ -541,11 +543,12 @@ static void Prg_WriteRowItem (Prg_ListingType_t ListingType, /* Expand/contract this program item */ HTM_TD_Begin ("class=\"LT %s\"%s", The_GetColorRows (),RowSpan[ContractedOrExpanded]); - Prg_PutIconToContractOrExpandItem (Item,ContractedOrExpanded,EditingProgram[ListingType]); + Prg_PutIconToContractOrExpandItem (Item,ContractedOrExpanded, + ViewingOrEditingProgram[ListingType]); HTM_TD_End (); /* Forms to remove/edit this program item */ - if (EditingProgram[ListingType]) + if (ViewingOrEditingProgram[ListingType] == VieEdi_EDIT) { HTM_TD_Begin ("class=\"PRG_COL1 LT %s\"%s", The_GetColorRows (),RowSpan[ContractedOrExpanded]); @@ -666,15 +669,15 @@ static void Prg_WriteRowItem (Prg_ListingType_t ListingType, /*****************************************************************************/ static void Prg_PutIconToContractOrExpandItem (struct Prg_Item *Item, - ConExp_ContractedOrExpanded_t ContractedOrExpanded, - bool Editing) + ConExp_ContractedOrExpanded_t ContractedOrExpanded, + VieEdi_ViewOrEdit_t ViewingOrEditing) { static const Act_Action_t NextAction[ConExp_NUM_CONTRACTED_EXPANDED][2] = { - [ConExp_CONTRACTED][false] = ActExpSeePrgItm, // Contracted, Not editing ==> action to expand - [ConExp_CONTRACTED][true ] = ActExpEdiPrgItm, // Contracted, Editing ==> action to expand - [ConExp_EXPANDED ][false] = ActConSeePrgItm, // Expanded , Not editing ==> action to contract - [ConExp_EXPANDED ][true ] = ActConEdiPrgItm, // Expanded , Editing ==> action to contract + [ConExp_CONTRACTED][VieEdi_VIEW] = ActExpSeePrgItm, // Contracted, Not editing ==> action to expand + [ConExp_CONTRACTED][VieEdi_EDIT] = ActExpEdiPrgItm, // Contracted, Editing ==> action to expand + [ConExp_EXPANDED ][VieEdi_VIEW] = ActConSeePrgItm, // Expanded , Not editing ==> action to contract + [ConExp_EXPANDED ][VieEdi_EDIT] = ActConEdiPrgItm, // Expanded , Editing ==> action to contract }; static void (*PutContextualIcon[ConExp_NUM_CONTRACTED_EXPANDED]) (const Act_Action_t NextAction,const char *Anchor, void (*FuncPars) (void *Args),void *Args) = @@ -684,7 +687,7 @@ static void Prg_PutIconToContractOrExpandItem (struct Prg_Item *Item, }; /***** Icon to hide/unhide program item *****/ - PutContextualIcon[ContractedOrExpanded] (NextAction[ContractedOrExpanded][Editing], + PutContextualIcon[ContractedOrExpanded] (NextAction[ContractedOrExpanded][ViewingOrEditing], Prg_HIGHLIGHTED_SECTION_ID, Prg_PutParItmCod,&Item->Hierarchy.ItmCod); } diff --git a/swad_program_resource.c b/swad_program_resource.c index ce77c4e2..ca06ea06 100644 --- a/swad_program_resource.c +++ b/swad_program_resource.c @@ -43,6 +43,7 @@ #include "swad_program.h" #include "swad_program_database.h" #include "swad_resource_database.h" +#include "swad_view_edit.h" /*****************************************************************************/ /************** External global variables from others modules ****************/ @@ -79,9 +80,11 @@ static void PrgRsc_GetResourceDataFromRow (MYSQL_RES *mysql_res, static void PrgRsc_WriteRowViewResource (unsigned NumRsc, const struct Prg_Item *Item); static void PrgRsc_WriteRowEditResource (unsigned NumRsc,unsigned NumResources, - struct Prg_Item *Item,bool EditLink); + struct Prg_Item *Item, + VieEdi_ViewOrEdit_t ViewOrEditLink); static void PrgRsc_WriteRowNewResource (unsigned NumResources, - struct Prg_Item *Item,bool EditLink); + struct Prg_Item *Item, + VieEdi_ViewOrEdit_t ViewOrEditLink); static void PrgRsc_PutFormsToRemEditOneResource (struct Prg_Item *Item, unsigned NumRsc, unsigned NumResources); @@ -152,37 +155,42 @@ void PrgRsc_ListItemResources (Prg_ListingType_t ListingType, MYSQL_RES *mysql_res; unsigned NumRsc; unsigned NumResources; - bool EditingResourcesOfThisItem; + VieEdi_ViewOrEdit_t ViewingOrEditingResourcesOfThisItem; char *Title; - static bool Editing[Prg_NUM_LISTING_TYPES] = + static VieEdi_ViewOrEdit_t ViewingOrEditing[Prg_NUM_LISTING_TYPES] = { - [Prg_PRINT ] = false, - [Prg_VIEW ] = false, - [Prg_EDIT_ITEMS ] = true, - [Prg_FORM_NEW_END_ITEM ] = true, - [Prg_FORM_NEW_CHILD_ITEM ] = true, - [Prg_FORM_EDIT_ITEM ] = true, - [Prg_END_EDIT_ITEM ] = true, - [Prg_RECEIVE_ITEM ] = true, - [Prg_EDIT_RESOURCES ] = true, - [Prg_EDIT_RESOURCE_LINK ] = true, - [Prg_CHANGE_RESOURCE_LINK] = true, - [Prg_END_EDIT_RES ] = true, + [Prg_PRINT ] = VieEdi_VIEW, + [Prg_VIEW ] = VieEdi_VIEW, + [Prg_EDIT_ITEMS ] = VieEdi_EDIT, + [Prg_FORM_NEW_END_ITEM ] = VieEdi_EDIT, + [Prg_FORM_NEW_CHILD_ITEM ] = VieEdi_EDIT, + [Prg_FORM_EDIT_ITEM ] = VieEdi_EDIT, + [Prg_END_EDIT_ITEM ] = VieEdi_EDIT, + [Prg_RECEIVE_ITEM ] = VieEdi_EDIT, + [Prg_EDIT_RESOURCES ] = VieEdi_EDIT, + [Prg_EDIT_RESOURCE_LINK ] = VieEdi_EDIT, + [Prg_CHANGE_RESOURCE_LINK] = VieEdi_EDIT, + [Prg_END_EDIT_RES ] = VieEdi_EDIT, }; - static bool EditingResources[Prg_NUM_LISTING_TYPES] = + static VieEdi_ViewOrEdit_t ViewingOrEditingResources[Prg_NUM_LISTING_TYPES] = { - [Prg_PRINT ] = false, - [Prg_VIEW ] = false, - [Prg_EDIT_ITEMS ] = false, - [Prg_FORM_NEW_END_ITEM ] = false, - [Prg_FORM_NEW_CHILD_ITEM ] = false, - [Prg_FORM_EDIT_ITEM ] = false, - [Prg_END_EDIT_ITEM ] = false, - [Prg_RECEIVE_ITEM ] = false, - [Prg_EDIT_RESOURCES ] = true, - [Prg_EDIT_RESOURCE_LINK ] = true, - [Prg_CHANGE_RESOURCE_LINK] = true, - [Prg_END_EDIT_RES ] = false, + [Prg_PRINT ] = VieEdi_VIEW, + [Prg_VIEW ] = VieEdi_VIEW, + [Prg_EDIT_ITEMS ] = VieEdi_VIEW, + [Prg_FORM_NEW_END_ITEM ] = VieEdi_VIEW, + [Prg_FORM_NEW_CHILD_ITEM ] = VieEdi_VIEW, + [Prg_FORM_EDIT_ITEM ] = VieEdi_VIEW, + [Prg_END_EDIT_ITEM ] = VieEdi_VIEW, + [Prg_RECEIVE_ITEM ] = VieEdi_VIEW, + [Prg_EDIT_RESOURCES ] = VieEdi_EDIT, + [Prg_EDIT_RESOURCE_LINK ] = VieEdi_EDIT, + [Prg_CHANGE_RESOURCE_LINK] = VieEdi_EDIT, + [Prg_END_EDIT_RES ] = VieEdi_VIEW, + }; + static void (*PrgRsc_PutIconsResources[VieEdi_NUM_VIEW_EDIT]) (void *ItmCod) = + { + PrgRsc_PutIconsViewResources, + PrgRsc_PutIconsEditResources, }; /***** Trivial check *****/ @@ -191,9 +199,9 @@ void PrgRsc_ListItemResources (Prg_ListingType_t ListingType, /***** Get list of item resources from database *****/ NumResources = Prg_DB_GetListResources (&mysql_res,Item->Hierarchy.ItmCod, - EditingResources[ListingType]); + ViewingOrEditingResources[ListingType] == VieEdi_EDIT); - if (NumResources || Editing[ListingType]) + if (NumResources || ViewingOrEditing[ListingType] == VieEdi_EDIT) { if (Item->Hierarchy.ItmCod == SelectedItmCod) { @@ -211,24 +219,27 @@ void PrgRsc_ListItemResources (Prg_ListingType_t ListingType, } /***** Begin box *****/ - EditingResourcesOfThisItem = EditingResources[ListingType] && - (Item->Hierarchy.ItmCod == SelectedItmCod); + ViewingOrEditingResourcesOfThisItem = ViewingOrEditingResources[ListingType] == VieEdi_EDIT && + (Item->Hierarchy.ItmCod == SelectedItmCod) ? VieEdi_EDIT : + VieEdi_VIEW; - if (Editing[ListingType]) + switch (ViewingOrEditing[ListingType]) { - if (asprintf (&Title,Txt_Resources_of_X,Item->Title) < 0) - Err_NotEnoughMemoryExit (); - Box_BoxBegin ("100%",Title, - EditingResourcesOfThisItem ? PrgRsc_PutIconsViewResources : - PrgRsc_PutIconsEditResources, - &Item->Hierarchy.ItmCod, - Hlp_COURSE_Program,Box_NOT_CLOSABLE); - free (Title); + case VieEdi_VIEW: + Box_BoxBegin ("100%",NULL, + NULL,NULL, + NULL,Box_NOT_CLOSABLE); + break; + case VieEdi_EDIT: + if (asprintf (&Title,Txt_Resources_of_X,Item->Title) < 0) + Err_NotEnoughMemoryExit (); + Box_BoxBegin ("100%",Title, + PrgRsc_PutIconsResources[ViewingOrEditingResourcesOfThisItem], + &Item->Hierarchy.ItmCod, + Hlp_COURSE_Program,Box_NOT_CLOSABLE); + free (Title); + break; } - else - Box_BoxBegin ("100%",NULL, - NULL,NULL, - NULL,Box_NOT_CLOSABLE); /***** Table *****/ HTM_TABLE_BeginWidePadding (2); @@ -243,21 +254,27 @@ void PrgRsc_ListItemResources (Prg_ListingType_t ListingType, PrgRsc_GetResourceDataFromRow (mysql_res,Item); /* Show item */ - if (EditingResourcesOfThisItem) - PrgRsc_WriteRowEditResource (NumRsc,NumResources,Item, - (ListingType == Prg_EDIT_RESOURCE_LINK && - Item->Resource.Hierarchy.RscCod == SelectedRscCod)); // Edit this link? - else - PrgRsc_WriteRowViewResource (NumRsc,Item); + switch (ViewingOrEditingResourcesOfThisItem) + { + case VieEdi_VIEW: + PrgRsc_WriteRowViewResource (NumRsc,Item); + break; + case VieEdi_EDIT: + PrgRsc_WriteRowEditResource (NumRsc,NumResources,Item, + (ListingType == Prg_EDIT_RESOURCE_LINK && + Item->Resource.Hierarchy.RscCod == SelectedRscCod) ? VieEdi_EDIT : + VieEdi_VIEW); + } } /***** Form to create a new resource *****/ - if (EditingResourcesOfThisItem) + if (ViewingOrEditingResourcesOfThisItem == VieEdi_EDIT) { Prg_ResetResource (Item); PrgRsc_WriteRowNewResource (NumResources,Item, (ListingType == Prg_EDIT_RESOURCE_LINK && - Item->Resource.Hierarchy.RscCod == SelectedRscCod)); // Edit this link? + Item->Resource.Hierarchy.RscCod == SelectedRscCod) ? VieEdi_EDIT : + VieEdi_VIEW); } /***** End table *****/ @@ -395,7 +412,8 @@ static void PrgRsc_WriteRowViewResource (unsigned NumRsc, /*****************************************************************************/ static void PrgRsc_WriteRowEditResource (unsigned NumRsc,unsigned NumResources, - struct Prg_Item *Item,bool EditLink) + struct Prg_Item *Item, + VieEdi_ViewOrEdit_t ViewOrEditLink) { /***** Begin row *****/ HTM_TR_Begin (NULL); @@ -427,17 +445,20 @@ static void PrgRsc_WriteRowEditResource (unsigned NumRsc,unsigned NumResources, HTM_BR (); /* Edit link showing clipboard / Show current link */ - if (EditLink) - { - /* Show clipboard to change resource link */ - Frm_BeginFormAnchor (ActChgLnkPrgRsc,PrgRsc_RESOURCE_SECTION_ID); - ParCod_PutPar (ParCod_Rsc,Item->Resource.Hierarchy.RscCod); - Rsc_ShowClipboardToChangeLink (&Item->Resource.Link); - Frm_EndForm (); + switch (ViewOrEditLink) + { + case VieEdi_VIEW: + /* Show current link */ + Rsc_WriteLinkName (&Item->Resource.Link,Frm_PUT_FORM_TO_GO); + break; + case VieEdi_EDIT: + /* Show clipboard to change resource link */ + Frm_BeginFormAnchor (ActChgLnkPrgRsc,PrgRsc_RESOURCE_SECTION_ID); + ParCod_PutPar (ParCod_Rsc,Item->Resource.Hierarchy.RscCod); + Rsc_ShowClipboardToChangeLink (&Item->Resource.Link); + Frm_EndForm (); + break; } - else - /* Show current link */ - Rsc_WriteLinkName (&Item->Resource.Link,Frm_PUT_FORM_TO_GO); HTM_TD_End (); @@ -450,7 +471,8 @@ static void PrgRsc_WriteRowEditResource (unsigned NumRsc,unsigned NumResources, /*****************************************************************************/ static void PrgRsc_WriteRowNewResource (unsigned NumResources, - struct Prg_Item *Item,bool EditLink) + struct Prg_Item *Item, + VieEdi_ViewOrEdit_t ViewOrEditLink) { extern const char *Txt_New_resource; @@ -483,7 +505,7 @@ static void PrgRsc_WriteRowNewResource (unsigned NumResources, Frm_EndForm (); /* Edit link showing clipboard? */ - if (EditLink) + if (ViewOrEditLink == VieEdi_EDIT) { HTM_BR (); diff --git a/swad_syllabus.c b/swad_syllabus.c index bbe5f293..cf815a04 100644 --- a/swad_syllabus.c +++ b/swad_syllabus.c @@ -136,7 +136,7 @@ void Syl_ResetSyllabus (struct Syl_Syllabus *Syllabus) { Syllabus->PathDir[0] = '\0'; Syllabus->NumItem = 0; - Syllabus->EditionIsActive = false; + Syllabus->ViewingOrEditing = VieEdi_VIEW; Syllabus->WhichSyllabus = Syl_DEFAULT_WHICH_SYLLABUS; } @@ -244,14 +244,15 @@ bool Syl_CheckAndEditSyllabus (struct Syl_Syllabus *Syllabus) case ActLftIteSylLec: case ActLftIteSylPra: case ActInsIteSylLec: case ActInsIteSylPra: case ActModIteSylLec: case ActModIteSylPra: - Syllabus->EditionIsActive = true; + Syllabus->ViewingOrEditing = VieEdi_EDIT; break; default: - Syllabus->EditionIsActive = false; + Syllabus->ViewingOrEditing = VieEdi_VIEW; break; } - if (Syllabus->EditionIsActive || Syl_LstItemsSyllabus.NumItems) + if (Syllabus->ViewingOrEditing == VieEdi_EDIT || + Syl_LstItemsSyllabus.NumItems) { /***** Write the current syllabus *****/ Syl_ShowSyllabus (Syllabus); @@ -521,81 +522,84 @@ static void Syl_ShowSyllabus (struct Syl_Syllabus *Syllabus) extern const char *Hlp_COURSE_Syllabus; extern const char *Txt_Done; unsigned NumItem; - int i; - int NumButtons = Syllabus->EditionIsActive ? 5 : - 0; + int Col; + static const char **HelpLink[VieEdi_NUM_VIEW_EDIT] = + { + [VieEdi_VIEW] = &Hlp_COURSE_Syllabus, + [VieEdi_EDIT] = &Hlp_COURSE_Syllabus_edit, + }; + static int NumButtons[VieEdi_NUM_VIEW_EDIT] = + { + [VieEdi_VIEW] = 0, + [VieEdi_EDIT] = 5, + }; bool ShowRowInsertNewItem = (Gbl.Action.Act == ActInsIteSylLec || Gbl.Action.Act == ActInsIteSylPra || Gbl.Action.Act == ActModIteSylLec || Gbl.Action.Act == ActModIteSylPra || Gbl.Action.Act == ActRgtIteSylLec || Gbl.Action.Act == ActRgtIteSylPra || Gbl.Action.Act == ActLftIteSylLec || Gbl.Action.Act == ActLftIteSylPra); bool ICanEdit = Gbl.Usrs.Me.Role.Logged == Rol_TCH || Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM; - bool PutIconToEdit = ICanEdit && !Syllabus->EditionIsActive; + bool PutIconToEdit = Syllabus->ViewingOrEditing == VieEdi_VIEW && ICanEdit; /***** Begin box *****/ - if (PutIconToEdit) - Box_BoxBegin (NULL,Txt_INFO_TITLE[Gbl.Crs.Info.Type], - Inf_PutIconToEditInfo,&Gbl.Crs.Info.Type, - Syllabus->EditionIsActive ? Hlp_COURSE_Syllabus_edit : - Hlp_COURSE_Syllabus, - Box_NOT_CLOSABLE); - else - Box_BoxBegin (NULL,Txt_INFO_TITLE[Gbl.Crs.Info.Type], - NULL,NULL, - Syllabus->EditionIsActive ? Hlp_COURSE_Syllabus_edit : - Hlp_COURSE_Syllabus, - Box_NOT_CLOSABLE); + Box_BoxBegin (NULL,Txt_INFO_TITLE[Gbl.Crs.Info.Type], + PutIconToEdit ? Inf_PutIconToEditInfo : + NULL, + PutIconToEdit ? &Gbl.Crs.Info.Type : + NULL, + *HelpLink[Syllabus->ViewingOrEditing],Box_NOT_CLOSABLE); - Syl_PutFormWhichSyllabus (Syllabus->WhichSyllabus); + /****** Form to select syllabus *****/ + Syl_PutFormWhichSyllabus (Syllabus->WhichSyllabus); - /***** Begin table *****/ - HTM_TABLE_BeginWide (); + /***** Begin table *****/ + HTM_TABLE_BeginWide (); - /***** Set width of columns of the table *****/ - HTM_Txt (""); - for (i = 0; - i < NumButtons; - i++) - HTM_Txt (""); - for (i = 1; - i <= Syl_LstItemsSyllabus.NumLevels; - i++) - HTM_TxtF ("",i * Syl_WIDTH_NUM_SYLLABUS); - HTM_Txt (""); - HTM_Txt (""); + /***** Set width of columns of the table *****/ + HTM_Txt (""); + for (Col = 0; + Col < NumButtons[Syllabus->ViewingOrEditing]; + Col++) + HTM_Txt (""); + for (Col = 1; + Col <= Syl_LstItemsSyllabus.NumLevels; + Col++) + HTM_TxtF ("",Col * Syl_WIDTH_NUM_SYLLABUS); + HTM_Txt (""); + HTM_Txt (""); - if (Syl_LstItemsSyllabus.NumItems) - /***** Loop writing all items of the syllabus *****/ - for (NumItem = 0; - NumItem < Syl_LstItemsSyllabus.NumItems; - NumItem++) - { - Syl_ShowRowSyllabus (Syllabus,NumItem, - Syl_LstItemsSyllabus.Lst[NumItem].Level, - Syl_LstItemsSyllabus.Lst[NumItem].CodItem, - Syl_LstItemsSyllabus.Lst[NumItem].Text,false); - if (ShowRowInsertNewItem && NumItem == Syllabus->NumItem) - // Mostrar a new row where se puede insert a new item - Syl_ShowRowSyllabus (Syllabus,NumItem + 1, - Syl_LstItemsSyllabus.Lst[NumItem].Level,NULL, - "",true); - } - else if (Syllabus->EditionIsActive) - /***** If the syllabus is empty ==> - show form to add a iten to the end *****/ - Syl_ShowRowSyllabus (Syllabus,0, - 1,Syl_LstItemsSyllabus.Lst[0].CodItem,"",true); + if (Syl_LstItemsSyllabus.NumItems) + /***** Loop writing all items of the syllabus *****/ + for (NumItem = 0; + NumItem < Syl_LstItemsSyllabus.NumItems; + NumItem++) + { + Syl_ShowRowSyllabus (Syllabus,NumItem, + Syl_LstItemsSyllabus.Lst[NumItem].Level, + Syl_LstItemsSyllabus.Lst[NumItem].CodItem, + Syl_LstItemsSyllabus.Lst[NumItem].Text,false); + if (ShowRowInsertNewItem && NumItem == Syllabus->NumItem) + // Mostrar a new row where se puede insert a new item + Syl_ShowRowSyllabus (Syllabus,NumItem + 1, + Syl_LstItemsSyllabus.Lst[NumItem].Level,NULL, + "",true); + } + else if (Syllabus->ViewingOrEditing == VieEdi_EDIT) + /***** If the syllabus is empty ==> + show form to add a iten to the end *****/ + Syl_ShowRowSyllabus (Syllabus,0, + 1,Syl_LstItemsSyllabus.Lst[0].CodItem,"",true); - /***** End table *****/ - HTM_TABLE_End (); + /***** End table *****/ + HTM_TABLE_End (); - if (Syllabus->EditionIsActive) - { /***** Button to view *****/ - Frm_BeginForm (Inf_ActionsSeeInfo[Gbl.Crs.Info.Type]); - Btn_PutConfirmButton (Txt_Done); - Frm_EndForm (); - } + if (Syllabus->ViewingOrEditing == VieEdi_EDIT) + { + Frm_BeginForm (Inf_ActionsSeeInfo[Gbl.Crs.Info.Type]); + Btn_PutConfirmButton (Txt_Done); + Frm_EndForm (); + } /***** End box *****/ Box_BoxEnd (); @@ -625,115 +629,115 @@ static void Syl_ShowRowSyllabus (struct Syl_Syllabus *Syllabus,unsigned NumItem, /***** Begin the row *****/ HTM_TR_Begin (NULL); - if (Syllabus->EditionIsActive) - { - if (NewItem) - { - HTM_TD_Begin ("colspan=\"5\" class=\"%s\"", - The_GetColorRows ()); - HTM_TD_End (); - } - else - { - /***** Icon to remove the row *****/ - HTM_TD_Begin ("class=\"BM %s\"",The_GetColorRows ()); - if (Syl_LstItemsSyllabus.Lst[NumItem].HasChildren) - Ico_PutIconRemovalNotAllowed (); - else - Ico_PutContextualIconToRemove (Gbl.Crs.Info.Type == Inf_LECTURES ? ActDelItmSylLec : - ActDelItmSylPra,NULL, - Syl_PutParNumItem,&Syllabus->ParNumItem); + switch (Syllabus->ViewingOrEditing) + { + case VieEdi_VIEW: + /***** Indent depending on the level *****/ + if (Level > 1) + { + HTM_TD_Begin ("colspan=\"%d\" class=\"%s\"", + Level - 1,The_GetColorRows ()); + HTM_TD_End (); + } + + /***** Code of the item *****/ + HTM_TD_Begin ("class=\"RT %s_%s %s\" style=\"width:%dpx;\"", + ClassSyllabus[Level],The_GetSuffix (), + The_GetColorRows (), + Level * Syl_WIDTH_NUM_SYLLABUS); + if (Level == 1) + HTM_NBSP (); + HTM_TxtF ("%s ",StrItemCod); HTM_TD_End (); - /***** Icon to get up an item *****/ - Syl_CalculateUpSubtreeSyllabus (&Subtree,NumItem); - HTM_TD_Begin ("class=\"BM %s\"",The_GetColorRows ()); - if (Subtree.MovAllowed) - Lay_PutContextualLinkOnlyIcon (Gbl.Crs.Info.Type == Inf_LECTURES ? ActUp_IteSylLec : - ActUp_IteSylPra, - NULL, - Syl_PutParNumItem,&Syllabus->ParNumItem, - "arrow-up.svg",Ico_BLACK); - else - Ico_PutIconOff ("arrow-up.svg",Ico_BLACK, - Txt_Movement_not_allowed); + /***** Text of the item *****/ + HTM_TD_Begin ("colspan=\"%d\" class=\"LT %s_%s %s\"", + Syl_LstItemsSyllabus.NumLevels - Level + 1, + ClassSyllabus[Level],The_GetSuffix (), + The_GetColorRows ()); + HTM_Txt (Text); HTM_TD_End (); + break; + case VieEdi_EDIT: + if (NewItem) + { + HTM_TD_Begin ("colspan=\"5\" class=\"%s\"", + The_GetColorRows ()); + HTM_TD_End (); + } + else + { + /***** Icon to remove the row *****/ + HTM_TD_Begin ("class=\"BM %s\"",The_GetColorRows ()); + if (Syl_LstItemsSyllabus.Lst[NumItem].HasChildren) + Ico_PutIconRemovalNotAllowed (); + else + Ico_PutContextualIconToRemove (Gbl.Crs.Info.Type == Inf_LECTURES ? ActDelItmSylLec : + ActDelItmSylPra,NULL, + Syl_PutParNumItem,&Syllabus->ParNumItem); + HTM_TD_End (); - /***** Icon to get down item *****/ - Syl_CalculateDownSubtreeSyllabus (&Subtree,NumItem); - HTM_TD_Begin ("class=\"BM %s\"",The_GetColorRows ()); - if (Subtree.MovAllowed) - Lay_PutContextualLinkOnlyIcon (Gbl.Crs.Info.Type == Inf_LECTURES ? ActDwnIteSylLec : - ActDwnIteSylPra, - NULL, - Syl_PutParNumItem,&Syllabus->ParNumItem, - "arrow-down.svg",Ico_BLACK); - else - Ico_PutIconOff ("arrow-down.svg",Ico_BLACK, - Txt_Movement_not_allowed); - HTM_TD_End (); + /***** Icon to get up an item *****/ + Syl_CalculateUpSubtreeSyllabus (&Subtree,NumItem); + HTM_TD_Begin ("class=\"BM %s\"",The_GetColorRows ()); + if (Subtree.MovAllowed) + Lay_PutContextualLinkOnlyIcon (Gbl.Crs.Info.Type == Inf_LECTURES ? ActUp_IteSylLec : + ActUp_IteSylPra, + NULL, + Syl_PutParNumItem,&Syllabus->ParNumItem, + "arrow-up.svg",Ico_BLACK); + else + Ico_PutIconOff ("arrow-up.svg",Ico_BLACK, + Txt_Movement_not_allowed); + HTM_TD_End (); - /***** Icon to increase the level of an item *****/ - HTM_TD_Begin ("class=\"BM %s\"",The_GetColorRows ()); - if (Level > 1) - Lay_PutContextualLinkOnlyIcon (Gbl.Crs.Info.Type == Inf_LECTURES ? ActRgtIteSylLec : - ActRgtIteSylPra, - NULL, - Syl_PutParNumItem,&Syllabus->ParNumItem, - "arrow-left.svg",Ico_BLACK); - else - Ico_PutIconOff ("arrow-left.svg",Ico_BLACK, - Txt_Movement_not_allowed); - HTM_TD_End (); + /***** Icon to get down item *****/ + Syl_CalculateDownSubtreeSyllabus (&Subtree,NumItem); + HTM_TD_Begin ("class=\"BM %s\"",The_GetColorRows ()); + if (Subtree.MovAllowed) + Lay_PutContextualLinkOnlyIcon (Gbl.Crs.Info.Type == Inf_LECTURES ? ActDwnIteSylLec : + ActDwnIteSylPra, + NULL, + Syl_PutParNumItem,&Syllabus->ParNumItem, + "arrow-down.svg",Ico_BLACK); + else + Ico_PutIconOff ("arrow-down.svg",Ico_BLACK, + Txt_Movement_not_allowed); + HTM_TD_End (); - /***** Icon to decrease level item *****/ - HTM_TD_Begin ("class=\"BM %s\"",The_GetColorRows ()); - if (Level < LastLevel + 1 && - Level < Syl_MAX_LEVELS_SYLLABUS) - Lay_PutContextualLinkOnlyIcon (Gbl.Crs.Info.Type == Inf_LECTURES ? ActLftIteSylLec : - ActLftIteSylPra, - NULL, - Syl_PutParNumItem,&Syllabus->ParNumItem, - "arrow-right.svg",Ico_BLACK); - else - Ico_PutIconOff ("arrow-right.svg",Ico_BLACK, - Txt_Movement_not_allowed); - HTM_TD_End (); + /***** Icon to increase the level of an item *****/ + HTM_TD_Begin ("class=\"BM %s\"",The_GetColorRows ()); + if (Level > 1) + Lay_PutContextualLinkOnlyIcon (Gbl.Crs.Info.Type == Inf_LECTURES ? ActRgtIteSylLec : + ActRgtIteSylPra, + NULL, + Syl_PutParNumItem,&Syllabus->ParNumItem, + "arrow-left.svg",Ico_BLACK); + else + Ico_PutIconOff ("arrow-left.svg",Ico_BLACK, + Txt_Movement_not_allowed); + HTM_TD_End (); - LastLevel = Level; - } - } + /***** Icon to decrease level item *****/ + HTM_TD_Begin ("class=\"BM %s\"",The_GetColorRows ()); + if (Level < LastLevel + 1 && + Level < Syl_MAX_LEVELS_SYLLABUS) + Lay_PutContextualLinkOnlyIcon (Gbl.Crs.Info.Type == Inf_LECTURES ? ActLftIteSylLec : + ActLftIteSylPra, + NULL, + Syl_PutParNumItem,&Syllabus->ParNumItem, + "arrow-right.svg",Ico_BLACK); + else + Ico_PutIconOff ("arrow-right.svg",Ico_BLACK, + Txt_Movement_not_allowed); + HTM_TD_End (); - if (Syllabus->EditionIsActive) - Syl_PutFormItemSyllabus (Syllabus,NewItem,NumItem,Level,CodItem,Text); - else - { - /***** Indent depending on the level *****/ - if (Level > 1) - { - HTM_TD_Begin ("colspan=\"%d\" class=\"%s\"", - Level - 1,The_GetColorRows ()); - HTM_TD_End (); - } + LastLevel = Level; + } - /***** Code of the item *****/ - HTM_TD_Begin ("class=\"RT %s_%s %s\" style=\"width:%dpx;\"", - ClassSyllabus[Level],The_GetSuffix (), - The_GetColorRows (), - Level * Syl_WIDTH_NUM_SYLLABUS); - if (Level == 1) - HTM_NBSP (); - HTM_TxtF ("%s ",StrItemCod); - HTM_TD_End (); - - /***** Text of the item *****/ - HTM_TD_Begin ("colspan=\"%d\" class=\"LT %s_%s %s\"", - Syl_LstItemsSyllabus.NumLevels - Level + 1, - ClassSyllabus[Level],The_GetSuffix (), - The_GetColorRows ()); - HTM_Txt (Text); - HTM_TD_End (); - } + Syl_PutFormItemSyllabus (Syllabus,NewItem,NumItem,Level,CodItem,Text); + break; + } /***** End of the row *****/ HTM_TR_End (); @@ -931,7 +935,7 @@ void Syl_RemoveItemSyllabus (void) /***** Load syllabus from XML file to memory *****/ Syl_LoadListItemsSyllabusIntoMemory (&Syllabus,Gbl.Hierarchy.Node[Hie_CRS].HieCod); - Syllabus.EditionIsActive = true; + Syllabus.ViewingOrEditing = VieEdi_EDIT; /***** Get item number *****/ Syllabus.NumItem = Syl_GetParItemNumber (); @@ -1008,7 +1012,7 @@ static void Syl_ChangePlaceItemSyllabus (Syl_ChangePosItem_t UpOrDownPos) /***** Load syllabus from XML file to memory *****/ Syl_LoadListItemsSyllabusIntoMemory (&Syllabus,Gbl.Hierarchy.Node[Hie_CRS].HieCod); - Syllabus.EditionIsActive = true; + Syllabus.ViewingOrEditing = VieEdi_EDIT; /***** Get item number *****/ Syllabus.NumItem = Syl_GetParItemNumber (); @@ -1194,7 +1198,7 @@ static void Syl_ChangeLevelItemSyllabus (Syl_ChangeLevelItem_t IncreaseOrDecreas /***** Load syllabus from XML file to memory *****/ Syl_LoadListItemsSyllabusIntoMemory (&Syllabus,Gbl.Hierarchy.Node[Hie_CRS].HieCod); - Syllabus.EditionIsActive = true; + Syllabus.ViewingOrEditing = VieEdi_EDIT; /***** Get item number *****/ Syllabus.NumItem = Syl_GetParItemNumber (); @@ -1257,7 +1261,7 @@ void Syl_InsertItemSyllabus (void) /***** Load syllabus from XML file to memory *****/ Syl_LoadListItemsSyllabusIntoMemory (&Syllabus,Gbl.Hierarchy.Node[Hie_CRS].HieCod); - Syllabus.EditionIsActive = true; + Syllabus.ViewingOrEditing = VieEdi_EDIT; /***** Get item number *****/ Syllabus.NumItem = Syl_GetParItemNumber (); @@ -1326,14 +1330,14 @@ void Syl_ModifyItemSyllabus (void) /***** Load syllabus from XML file to memory *****/ Syl_LoadListItemsSyllabusIntoMemory (&Syllabus,Gbl.Hierarchy.Node[Hie_CRS].HieCod); - Syllabus.EditionIsActive = true; + Syllabus.ViewingOrEditing = VieEdi_EDIT; /***** Get item number *****/ Syllabus.NumItem = Syl_GetParItemNumber (); /***** Get item body *****/ Par_GetParHTML ("Txt",Syl_LstItemsSyllabus.Lst[Syllabus.NumItem].Text, - Syl_MAX_BYTES_TEXT_ITEM); + Syl_MAX_BYTES_TEXT_ITEM); /***** Create a new file where make the update *****/ Syl_BuildPathFileSyllabus (&Syllabus,PathFile); diff --git a/swad_syllabus.h b/swad_syllabus.h index 592cbde6..4ef1e27a 100644 --- a/swad_syllabus.h +++ b/swad_syllabus.h @@ -23,6 +23,12 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ +/*****************************************************************************/ +/********************************* Headers ***********************************/ +/*****************************************************************************/ + +#include "swad_view_edit.h" + /*****************************************************************************/ /************************ Public constants and types *************************/ /*****************************************************************************/ @@ -69,9 +75,9 @@ struct MoveSubtrees struct Syl_Syllabus { char PathDir[PATH_MAX + 1]; - unsigned NumItem; // Item being edited + unsigned NumItem; // Item being edited unsigned ParNumItem; // Used as parameter in forms - bool EditionIsActive; + VieEdi_ViewOrEdit_t ViewingOrEditing; Syl_WhichSyllabus_t WhichSyllabus; }; diff --git a/swad_view_edit.h b/swad_view_edit.h new file mode 100644 index 00000000..c920aab2 --- /dev/null +++ b/swad_view_edit.h @@ -0,0 +1,43 @@ +// swad_view_edit.h: types and constants related to view/edit + +#ifndef _SWAD_VIE_EDI +#define _SWAD_VIE_EDI +/* + SWAD (Shared Workspace At a Distance in Spanish), + is a web platform developed at the University of Granada (Spain), + and used to support university teaching. + + This file is part of SWAD core. + Copyright (C) 1999-2023 Antonio Caņas Vargas + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +/*****************************************************************************/ +/***************************** Public constants ******************************/ +/*****************************************************************************/ + +#define VieEdi_NUM_VIEW_EDIT 2 + +/*****************************************************************************/ +/******************************* Public types ********************************/ +/*****************************************************************************/ + +typedef enum + { + VieEdi_VIEW = 0, + VieEdi_EDIT = 1, + } VieEdi_ViewOrEdit_t; + +#endif