From a34501e32494a6a9beb0833fabcbf2cca45a77c0 Mon Sep 17 00:00:00 2001 From: acanas Date: Sun, 21 Feb 2021 21:30:06 +0100 Subject: [PATCH] Version 20.33: Feb 21, 2021 New module swad_timeline_form. --- Makefile | 6 +- swad_changelog.h | 3 +- swad_timeline.c | 35 ----- swad_timeline.h | 11 -- swad_timeline_comment.c | 83 +----------- swad_timeline_favourite.c | 23 +--- swad_timeline_form.c | 264 ++++++++++++++++++++++++++++++++++++++ swad_timeline_form.h | 80 ++++++++++++ swad_timeline_note.c | 3 +- swad_timeline_post.c | 3 +- swad_timeline_share.c | 12 +- swad_timeline_user.c | 88 ------------- swad_timeline_user.h | 10 -- 13 files changed, 371 insertions(+), 250 deletions(-) create mode 100644 swad_timeline_form.c create mode 100644 swad_timeline_form.h diff --git a/Makefile b/Makefile index b39c0ae7..e8e9ffdb 100644 --- a/Makefile +++ b/Makefile @@ -63,9 +63,9 @@ OBJS = swad_account.o swad_action.o swad_agenda.o swad_alert.o \ swad_test_import.o swad_test_print.o swad_test_visibility.o \ swad_theme.o \ swad_timeline.o swad_timeline_comment.o swad_timeline_favourite.o \ - swad_timeline_note.o swad_timeline_notification.o swad_timeline_post.o \ - swad_timeline_publication.o swad_timeline_share.o swad_timeline_user.o \ - swad_timeline_who.o \ + swad_timeline_form.o swad_timeline_note.o swad_timeline_notification.o \ + swad_timeline_post.o swad_timeline_publication.o swad_timeline_share.o \ + swad_timeline_user.o swad_timeline_who.o \ swad_timetable.o \ swad_user.o \ swad_xml.o \ diff --git a/swad_changelog.h b/swad_changelog.h index b91783c0..4c600c20 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -553,7 +553,7 @@ enscript -2 --landscape --color --file-align=2 --highlight --line-numbers -o - * En OpenSWAD: ps2pdf source.ps destination.pdf */ -#define Log_PLATFORM_VERSION "SWAD 20.32.2 (2021-02-21)" +#define Log_PLATFORM_VERSION "SWAD 20.33 (2021-02-21)" #define CSS_FILE "swad20.8.css" #define JS_FILE "swad20.6.2.js" /* @@ -601,6 +601,7 @@ TODO: DNI de un estudiante sale err TODO: BUG: Cuando un tipo de grupo sólo tiene un grupo, inscribirse es voluntario, el estudiante sólo puede pertenecer a un grupo, y se inscribe en él, debería poder desapuntarse. Ahora no puede. TODO: Salvador Romero Cortés: @acanas opción para editar posts + Version 20.33: Feb 21, 2021 New module swad_timeline_form. (304866 lines) Version 20.32.2: Feb 21, 2021 Code refactoring in timeline related to actions. (304771 lines) Version 20.32.1: Feb 15, 2021 Fixed bug in forums. (304756 lines) Version 20.32: Feb 15, 2021 Fixed bugs in copy of strings. diff --git a/swad_timeline.c b/swad_timeline.c index 31bbc55d..7eb021ee 100644 --- a/swad_timeline.c +++ b/swad_timeline.c @@ -503,41 +503,6 @@ static void TL_PutIconsTimeline (__attribute__((unused)) void *Args) Fig_PutIconToShowFigure (Fig_TIMELINE); } -/*****************************************************************************/ -/***************** Start a form in global or user timeline *******************/ -/*****************************************************************************/ - -void TL_FormStart (const struct TL_Timeline *Timeline,TL_FormAction_t Action) - { - static const Act_Action_t ActionGbl[TL_NUM_ACTIONS] = - { - [TL_RECEIVE_POST] = ActRcvTL_PstGbl, - [TL_RECEIVE_COMM] = ActRcvTL_ComGbl, - [TL_REQ_REM_NOTE] = ActReqRemTL_PubGbl, - [TL_REQ_REM_COMM] = ActReqRemTL_ComGbl, - }; - static const Act_Action_t ActionUsr[TL_NUM_ACTIONS] = - { - [TL_RECEIVE_POST] = ActRcvTL_PstUsr, - [TL_RECEIVE_COMM] = ActRcvTL_ComUsr, - [TL_REQ_REM_NOTE] = ActReqRemTL_PubUsr, - [TL_REQ_REM_COMM] = ActReqRemTL_ComUsr, - }; - - if (Gbl.Usrs.Other.UsrDat.UsrCod > 0) - { - /***** Start form in user timeline *****/ - Frm_StartFormAnchor (ActionUsr[Action],"timeline"); - Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EnUsrCod); - } - else - { - /***** Start form in global timeline *****/ - Frm_StartForm (ActionGbl[Action]); - Usr_PutHiddenParamWho (Timeline->Who); - } - } - /*****************************************************************************/ /******************* Write the date of creation of a note ********************/ /*****************************************************************************/ diff --git a/swad_timeline.h b/swad_timeline.h index bb0c0714..c77e6466 100644 --- a/swad_timeline.h +++ b/swad_timeline.h @@ -103,15 +103,6 @@ typedef enum TL_SHOW_ALONE, } TL_ShowAlone_t; -#define TL_NUM_ACTIONS 4 -typedef enum - { - TL_RECEIVE_POST, // Receive post - TL_RECEIVE_COMM, // Receive comment - TL_REQ_REM_NOTE, // Request removal note - TL_REQ_REM_COMM, // Request removal comment - } TL_FormAction_t; - /*****************************************************************************/ /****************************** Public prototypes ****************************/ /*****************************************************************************/ @@ -134,8 +125,6 @@ void TL_RefreshNewTimelineGbl (void); void TL_RefreshOldTimelineGbl (void); void TL_RefreshOldTimelineUsr (void); -void TL_FormStart (const struct TL_Timeline *Timeline,TL_FormAction_t Action); - void TL_WriteDateTime (time_t TimeUTC); #endif diff --git a/swad_timeline_comment.c b/swad_timeline_comment.c index 8c13b670..a49fb656 100644 --- a/swad_timeline_comment.c +++ b/swad_timeline_comment.c @@ -37,6 +37,7 @@ #include "swad_profile.h" #include "swad_timeline.h" #include "swad_timeline_favourite.h" +#include "swad_timeline_form.h" #include "swad_timeline_note.h" #include "swad_timeline_publication.h" #include "swad_timeline_share.h" @@ -65,10 +66,6 @@ extern struct Globals Gbl; /***************************** Private prototypes ****************************/ /*****************************************************************************/ -static void TL_Com_FormToShowHiddenComments (Act_Action_t ActionGbl,Act_Action_t ActionUsr, - long NotCod, - char IdComments[Frm_MAX_BYTES_ID + 1], - unsigned NumInitialComments); static unsigned TL_Com_WriteHiddenComments (struct TL_Timeline *Timeline, long NotCod, char IdComments[Frm_MAX_BYTES_ID + 1], @@ -159,7 +156,7 @@ void TL_Com_PutHiddenFormToWriteNewComment (const struct TL_Timeline *Timeline, HTM_DIV_Begin ("class=\"TL_COM_CONT TL_COMM_WIDTH\""); /* Begin form to write the post */ - TL_FormStart (Timeline,TL_RECEIVE_COMM); + TL_Frm_FormStart (Timeline,TL_Frm_RECEIVE_COMM); TL_Not_PutHiddenParamNotCod (NotCod); /* Textarea and button */ @@ -293,10 +290,9 @@ void TL_Com_WriteCommentsInNote (struct TL_Timeline *Timeline, /***** Div which content will be updated via AJAX *****/ HTM_DIV_Begin ("id=\"%s\" class=\"TL_RIGHT_WIDTH\"",IdComments); - TL_Com_FormToShowHiddenComments (ActShoHidTL_ComGbl,ActShoHidTL_ComUsr, - Not->NotCod, - IdComments, - NumInitialComments); + TL_Frm_FormToShowHiddenComments (Not->NotCod, + IdComments, + NumInitialComments); HTM_DIV_End (); } @@ -315,73 +311,6 @@ void TL_Com_WriteCommentsInNote (struct TL_Timeline *Timeline, DB_FreeMySQLResult (&mysql_res); } -/*****************************************************************************/ -/********** Form to show hidden coments in global or user timeline ***********/ -/*****************************************************************************/ - -static void TL_Com_FormToShowHiddenComments (Act_Action_t ActionGbl,Act_Action_t ActionUsr, - long NotCod, - char IdComments[Frm_MAX_BYTES_ID + 1], - unsigned NumInitialComments) - { - extern const char *The_ClassFormLinkInBox[The_NUM_THEMES]; - extern const char *Txt_See_the_previous_X_COMMENTS; - char *OnSubmit; - - HTM_DIV_Begin ("id=\"exp_%s\" class=\"TL_EXPAND_COM TL_RIGHT_WIDTH\"", - IdComments); - - /***** Form and icon-text to show hidden comments *****/ - /* Begin form */ - if (Gbl.Usrs.Other.UsrDat.UsrCod > 0) - { - if (asprintf (&OnSubmit,"toggleComments('%s');" - "updateDivHiddenComments(this," - "'act=%ld&ses=%s&NotCod=%ld&IdComments=%s&NumHidCom=%u&OtherUsrCod=%s');" - " return false;", // return false is necessary to not submit form - IdComments, - Act_GetActCod (ActionUsr), - Gbl.Session.Id, - NotCod, - IdComments, - NumInitialComments, - Gbl.Usrs.Other.UsrDat.EnUsrCod) < 0) - Lay_NotEnoughMemoryExit (); - Frm_StartFormUniqueAnchorOnSubmit (ActUnk,"timeline",OnSubmit); - } - else - { - if (asprintf (&OnSubmit,"toggleComments('%s');" - "updateDivHiddenComments(this," - "'act=%ld&ses=%s&NotCod=%ld&IdComments=%s&NumHidCom=%u');" - " return false;", // return false is necessary to not submit form - IdComments, - Act_GetActCod (ActionGbl), - Gbl.Session.Id, - NotCod, - IdComments, - NumInitialComments) < 0) - Lay_NotEnoughMemoryExit (); - Frm_StartFormUniqueAnchorOnSubmit (ActUnk,NULL,OnSubmit); - } - - /* Put icon and text with link to show the first hidden comments */ - HTM_BUTTON_SUBMIT_Begin (NULL,The_ClassFormLinkInBox[Gbl.Prefs.Theme],NULL); - Ico_PutIconTextLink ("angle-up.svg", - Str_BuildStringLong (Txt_See_the_previous_X_COMMENTS, - (long) NumInitialComments)); - Str_FreeString (); - HTM_BUTTON_End (); - - /* End form */ - Frm_EndForm (); - - /* Free allocated memory */ - free (OnSubmit); - - HTM_DIV_End (); - } - /*****************************************************************************/ /********************** Write hidden comments via AJAX ***********************/ /*****************************************************************************/ @@ -695,7 +624,7 @@ static void TL_Com_PutFormToRemoveComment (const struct TL_Timeline *Timeline, extern const char *Txt_Remove; /***** Form to remove publication *****/ - TL_FormStart (Timeline,TL_REQ_REM_COMM); + TL_Frm_FormStart (Timeline,TL_Frm_REQ_REM_COMM); TL_Pub_PutHiddenParamPubCod (PubCod); Ico_PutIconLink ("trash.svg",Txt_Remove); Frm_EndForm (); diff --git a/swad_timeline_favourite.c b/swad_timeline_favourite.c index 3ad5d741..dad952ab 100644 --- a/swad_timeline_favourite.c +++ b/swad_timeline_favourite.c @@ -29,6 +29,7 @@ #include "swad_global.h" #include "swad_timeline.h" #include "swad_timeline_favourite.h" +#include "swad_timeline_form.h" #include "swad_timeline_notification.h" #include "swad_timeline_publication.h" @@ -110,9 +111,7 @@ static void TL_Fav_PutFormToFavNote (long ParamCod) extern const char *Txt_Mark_as_favourite; /***** Form and icon to mark note as favourite *****/ - TL_Usr_FormFavSha (ActFavTL_NotGbl, - ActFavTL_NotUsr, - "NotCod=%ld",ParamCod, + TL_Frm_FormFavSha (TL_Frm_FAV_NOTE,"NotCod=%ld",ParamCod, TL_Fav_ICON_FAV,Txt_Mark_as_favourite); } @@ -121,9 +120,7 @@ static void TL_Fav_PutFormToUnfNote (long ParamCod) extern const char *Txt_TIMELINE_NOTE_Favourite; /***** Form and icon to unfav (remove mark as favourite) note *****/ - TL_Usr_FormFavSha (ActUnfTL_NotGbl, - ActUnfTL_NotUsr, - "NotCod=%ld",ParamCod, + TL_Frm_FormFavSha (TL_Frm_UNF_NOTE,"NotCod=%ld",ParamCod, TL_Fav_ICON_FAVED,Txt_TIMELINE_NOTE_Favourite); } @@ -136,9 +133,7 @@ static void TL_Fav_PutFormToFavComment (long ParamCod) extern const char *Txt_Mark_as_favourite; /***** Form and icon to mark comment as favourite *****/ - TL_Usr_FormFavSha (ActFavTL_ComGbl, - ActFavTL_ComUsr, - "PubCod=%ld",ParamCod, + TL_Frm_FormFavSha (TL_Frm_FAV_COMM,"PubCod=%ld",ParamCod, TL_Fav_ICON_FAV,Txt_Mark_as_favourite); } @@ -147,9 +142,7 @@ static void TL_Fav_PutFormToUnfComment (long ParamCod) extern const char *Txt_TIMELINE_NOTE_Favourite; /***** Form and icon to unfav (remove mark as favourite) comment *****/ - TL_Usr_FormFavSha (ActUnfTL_ComGbl, - ActUnfTL_ComUsr, - "PubCod=%ld",ParamCod, + TL_Frm_FormFavSha (TL_Frm_UNF_COMM,"PubCod=%ld",ParamCod, TL_Fav_ICON_FAVED,Txt_TIMELINE_NOTE_Favourite); } @@ -593,8 +586,7 @@ static void TL_Fav_ShowUsrsWhoHaveMarkedNoteAsFav (const struct TL_Not_Note *Not TL_Usr_ShowSharersOrFavers (&mysql_res,Not->NumFavs,NumFirstUsrs); if (NumFirstUsrs < Not->NumFavs) // Not all are shown /* Clickable ellipsis to show all users */ - TL_Usr_PutFormToSeeAllFaversSharers (ActAllFavTL_NotGbl, - ActAllFavTL_NotUsr, + TL_Frm_PutFormToSeeAllFaversSharers (TL_Frm_ALL_FAV_NOTE, "NotCod=%ld",Not->NotCod, HowManyUsrs); HTM_DIV_End (); @@ -641,8 +633,7 @@ static void TL_Fav_ShowUsrsWhoHaveMarkedCommAsFav (const struct TL_Com_Comment * TL_Usr_ShowSharersOrFavers (&mysql_res,Com->NumFavs,NumFirstUsrs); if (NumFirstUsrs < Com->NumFavs) /* Clickable ellipsis to show all users */ - TL_Usr_PutFormToSeeAllFaversSharers (ActAllFavTL_ComGbl, - ActAllFavTL_ComUsr, + TL_Frm_PutFormToSeeAllFaversSharers (TL_Frm_ALL_FAV_COMM, "PubCod=%ld",Com->PubCod, HowManyUsrs); HTM_DIV_End (); diff --git a/swad_timeline_form.c b/swad_timeline_form.c new file mode 100644 index 00000000..2fae640a --- /dev/null +++ b/swad_timeline_form.c @@ -0,0 +1,264 @@ +// swad_timeline_form.c: social timeline forms + +/* + SWAD (Shared Workspace At a Distance), + 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-2021 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 3 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 . +*/ + +/*****************************************************************************/ +/*********************************** Headers *********************************/ +/*****************************************************************************/ + +#define _GNU_SOURCE // For asprintf +#include // For asprintf + +#include "swad_action.h" +#include "swad_global.h" +#include "swad_timeline.h" +#include "swad_timeline_form.h" + +/*****************************************************************************/ +/****************************** Public constants *****************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/************************* Private constants and types ***********************/ +/*****************************************************************************/ + +#define TL_Frm_ICON_ELLIPSIS "ellipsis-h.svg" + +const Act_Action_t TL_Frm_ActionGbl[TL_Frm_NUM_ACTIONS] = + { + [TL_Frm_RECEIVE_POST] = ActRcvTL_PstGbl, + [TL_Frm_RECEIVE_COMM] = ActRcvTL_ComGbl, + [TL_Frm_REQ_REM_NOTE] = ActReqRemTL_PubGbl, + [TL_Frm_REQ_REM_COMM] = ActReqRemTL_ComGbl, + [TL_Frm_SHA_NOTE ] = ActShaTL_NotGbl, + [TL_Frm_UNS_NOTE ] = ActUnsTL_NotGbl, + [TL_Frm_FAV_NOTE ] = ActFavTL_NotGbl, + [TL_Frm_FAV_COMM ] = ActFavTL_ComGbl, + [TL_Frm_UNF_NOTE ] = ActUnfTL_NotGbl, + [TL_Frm_UNF_COMM ] = ActUnfTL_ComGbl, + [TL_Frm_ALL_SHA_NOTE] = ActAllShaTL_NotGbl, + [TL_Frm_ALL_FAV_NOTE] = ActAllFavTL_NotGbl, + [TL_Frm_ALL_FAV_COMM] = ActAllFavTL_ComGbl, + [TL_Frm_SHO_HID_COMM] = ActShoHidTL_ComGbl, + }; +const Act_Action_t TL_Frm_ActionUsr[TL_Frm_NUM_ACTIONS] = + { + [TL_Frm_RECEIVE_POST] = ActRcvTL_PstUsr, + [TL_Frm_RECEIVE_COMM] = ActRcvTL_ComUsr, + [TL_Frm_REQ_REM_NOTE] = ActReqRemTL_PubUsr, + [TL_Frm_REQ_REM_COMM] = ActReqRemTL_ComUsr, + [TL_Frm_SHA_NOTE ] = ActShaTL_NotUsr, + [TL_Frm_UNS_NOTE ] = ActUnsTL_NotUsr, + [TL_Frm_FAV_NOTE ] = ActFavTL_NotUsr, + [TL_Frm_FAV_COMM ] = ActFavTL_ComUsr, + [TL_Frm_UNF_NOTE ] = ActUnfTL_NotUsr, + [TL_Frm_UNF_COMM ] = ActUnfTL_ComUsr, + [TL_Frm_ALL_SHA_NOTE] = ActAllShaTL_NotUsr, + [TL_Frm_ALL_FAV_NOTE] = ActAllFavTL_NotUsr, + [TL_Frm_ALL_FAV_COMM] = ActAllFavTL_ComUsr, + [TL_Frm_SHO_HID_COMM] = ActShoHidTL_ComUsr, + }; + +/*****************************************************************************/ +/************** External global variables from others modules ****************/ +/*****************************************************************************/ + +extern struct Globals Gbl; + +/*****************************************************************************/ +/************************* Private global variables **************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/***************************** Private prototypes ****************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/***************** Start a form in global or user timeline *******************/ +/*****************************************************************************/ + +void TL_Frm_FormStart (const struct TL_Timeline *Timeline,TL_Frm_Action_t Action) + { + if (Gbl.Usrs.Other.UsrDat.UsrCod > 0) + { + /***** Start form in user timeline *****/ + Frm_StartFormAnchor (TL_Frm_ActionUsr[Action],"timeline"); + Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EnUsrCod); + } + else + { + /***** Start form in global timeline *****/ + Frm_StartForm (TL_Frm_ActionGbl[Action]); + Usr_PutHiddenParamWho (Timeline->Who); + } + } + +/*****************************************************************************/ +/********************* Form to show all favers/sharers ***********************/ +/*****************************************************************************/ + +void TL_Frm_PutFormToSeeAllFaversSharers (TL_Frm_Action_t Action, + const char *ParamFormat,long ParamCod, + TL_Usr_HowManyUsrs_t HowManyUsrs) + { + extern const char *Txt_View_all_USERS; + + switch (HowManyUsrs) + { + case TL_Usr_SHOW_FEW_USRS: + /***** Form and icon to mark note as favourite *****/ + TL_Frm_FormFavSha (Action,ParamFormat,ParamCod, + TL_Frm_ICON_ELLIPSIS,Txt_View_all_USERS); + break; + case TL_Usr_SHOW_ALL_USRS: + Ico_PutIconOff (TL_Frm_ICON_ELLIPSIS,Txt_View_all_USERS); + break; + } + } + +/*****************************************************************************/ +/******* Form to fav/unfav or share/unshare in global or user timeline *******/ +/*****************************************************************************/ + +void TL_Frm_FormFavSha (TL_Frm_Action_t Action, + const char *ParamFormat,long ParamCod, + const char *Icon,const char *Title) + { + char *OnSubmit; + char ParamStr[7 + Cns_MAX_DECIMAL_DIGITS_LONG + 1]; + + /***** Create parameter string *****/ + sprintf (ParamStr,ParamFormat,ParamCod); + + /* + +---------------------------------------------------------------------------+ + | div which content will be updated (parent of parent of form) | + | +---------------------+ +-------+ +-------------------------------------+ | + | | div (parent of form)| | div | | div for users | | + | | +-----------------+ | | for | | +------+ +------+ +------+ +------+ | | + | | | this form | | | num. | | | | | | | | | form | | | + | | | +-------------+ | | | of | | | user | | user | | user | | to | | | + | | | | fav icon | | | | users | | | 1 | | 2 | | 3 | | show | | | + | | | +-------------+ | | | | | | | | | | | | all | | | + | | +-----------------+ | | | | +------+ +------+ +------+ +------+ | | + | +---------------------+ +-------+ +-------------------------------------+ | + +---------------------------------------------------------------------------+ + */ + + /***** Form and icon to mark note as favourite *****/ + /* Form with icon */ + if (Gbl.Usrs.Other.UsrDat.UsrCod > 0) + { + if (asprintf (&OnSubmit,"updateDivFaversSharers(this," + "'act=%ld&ses=%s&%s&OtherUsrCod=%s');" + " return false;", // return false is necessary to not submit form + Act_GetActCod (TL_Frm_ActionUsr[Action]), + Gbl.Session.Id, + ParamStr, + Gbl.Usrs.Other.UsrDat.EnUsrCod) < 0) + Lay_NotEnoughMemoryExit (); + Frm_StartFormUniqueAnchorOnSubmit (ActUnk,"timeline",OnSubmit); + } + else + { + if (asprintf (&OnSubmit,"updateDivFaversSharers(this," + "'act=%ld&ses=%s&%s');" + " return false;", // return false is necessary to not submit form + Act_GetActCod (TL_Frm_ActionGbl[Action]), + Gbl.Session.Id, + ParamStr) < 0) + Lay_NotEnoughMemoryExit (); + Frm_StartFormUniqueAnchorOnSubmit (ActUnk,NULL,OnSubmit); + } + Ico_PutIconLink (Icon,Title); + Frm_EndForm (); + + /* Free allocated memory */ + free (OnSubmit); + } + +/*****************************************************************************/ +/********** Form to show hidden coments in global or user timeline ***********/ +/*****************************************************************************/ + +void TL_Frm_FormToShowHiddenComments (long NotCod, + char IdComments[Frm_MAX_BYTES_ID + 1], + unsigned NumInitialComments) + { + extern const char *The_ClassFormLinkInBox[The_NUM_THEMES]; + extern const char *Txt_See_the_previous_X_COMMENTS; + char *OnSubmit; + + HTM_DIV_Begin ("id=\"exp_%s\" class=\"TL_EXPAND_COM TL_RIGHT_WIDTH\"", + IdComments); + + /***** Form and icon-text to show hidden comments *****/ + /* Begin form */ + if (Gbl.Usrs.Other.UsrDat.UsrCod > 0) + { + if (asprintf (&OnSubmit,"toggleComments('%s');" + "updateDivHiddenComments(this," + "'act=%ld&ses=%s&NotCod=%ld&IdComments=%s&NumHidCom=%u&OtherUsrCod=%s');" + " return false;", // return false is necessary to not submit form + IdComments, + Act_GetActCod (TL_Frm_ActionUsr[TL_Frm_SHO_HID_COMM]), + Gbl.Session.Id, + NotCod, + IdComments, + NumInitialComments, + Gbl.Usrs.Other.UsrDat.EnUsrCod) < 0) + Lay_NotEnoughMemoryExit (); + Frm_StartFormUniqueAnchorOnSubmit (ActUnk,"timeline",OnSubmit); + } + else + { + if (asprintf (&OnSubmit,"toggleComments('%s');" + "updateDivHiddenComments(this," + "'act=%ld&ses=%s&NotCod=%ld&IdComments=%s&NumHidCom=%u');" + " return false;", // return false is necessary to not submit form + IdComments, + Act_GetActCod (TL_Frm_ActionGbl[TL_Frm_SHO_HID_COMM]), + Gbl.Session.Id, + NotCod, + IdComments, + NumInitialComments) < 0) + Lay_NotEnoughMemoryExit (); + Frm_StartFormUniqueAnchorOnSubmit (ActUnk,NULL,OnSubmit); + } + + /* Put icon and text with link to show the first hidden comments */ + HTM_BUTTON_SUBMIT_Begin (NULL,The_ClassFormLinkInBox[Gbl.Prefs.Theme],NULL); + Ico_PutIconTextLink ("angle-up.svg", + Str_BuildStringLong (Txt_See_the_previous_X_COMMENTS, + (long) NumInitialComments)); + Str_FreeString (); + HTM_BUTTON_End (); + + /* End form */ + Frm_EndForm (); + + /* Free allocated memory */ + free (OnSubmit); + + HTM_DIV_End (); + } diff --git a/swad_timeline_form.h b/swad_timeline_form.h new file mode 100644 index 00000000..f982e58e --- /dev/null +++ b/swad_timeline_form.h @@ -0,0 +1,80 @@ +// swad_timeline_form.h: social timeline forms + +#ifndef _SWAD_TL_FRM +#define _SWAD_TL_FRM +/* + 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-2021 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 . +*/ +/*****************************************************************************/ +/********************************** Headers **********************************/ +/*****************************************************************************/ + +// #include "swad_form.h" +// #include "swad_media.h" +// #include "swad_notification.h" +// #include "swad_user.h" +// #include "swad_timeline_user.h" + +/*****************************************************************************/ +/****************************** Public constants *****************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/******************************** Public types *******************************/ +/*****************************************************************************/ + +#define TL_Frm_NUM_ACTIONS 14 +typedef enum + { + TL_Frm_RECEIVE_POST, // Receive post + TL_Frm_RECEIVE_COMM, // Receive comment + TL_Frm_REQ_REM_NOTE, // Request removal note + TL_Frm_REQ_REM_COMM, // Request removal comment + TL_Frm_SHA_NOTE, // Share a note + TL_Frm_UNS_NOTE, // Unshare a note + TL_Frm_FAV_NOTE, // Favourite a note + TL_Frm_FAV_COMM, // Favourite a comment + TL_Frm_UNF_NOTE, // Unfavourite a note + TL_Frm_UNF_COMM, // Unfavourite a comment + TL_Frm_ALL_SHA_NOTE, // Show all sharers of note + TL_Frm_ALL_FAV_NOTE, // Show all favouriters of note + TL_Frm_ALL_FAV_COMM, // Show all favouriters of comment + TL_Frm_SHO_HID_COMM, // Show / hide comments + } TL_Frm_Action_t; + +/*****************************************************************************/ +/****************************** Public prototypes ****************************/ +/*****************************************************************************/ + +void TL_Frm_FormStart (const struct TL_Timeline *Timeline,TL_Frm_Action_t Action); + +void TL_Frm_PutFormToSeeAllFaversSharers (TL_Frm_Action_t Action, + const char *ParamFormat,long ParamCod, + TL_Usr_HowManyUsrs_t HowManyUsrs); +void TL_Frm_FormFavSha (TL_Frm_Action_t Action, + const char *ParamFormat,long ParamCod, + const char *Icon,const char *Title); + +void TL_Frm_FormToShowHiddenComments (long NotCod, + char IdComments[Frm_MAX_BYTES_ID + 1], + unsigned NumInitialComments); + +#endif diff --git a/swad_timeline_note.c b/swad_timeline_note.c index 6ba30650..1f28f794 100644 --- a/swad_timeline_note.c +++ b/swad_timeline_note.c @@ -42,6 +42,7 @@ #include "swad_profile.h" #include "swad_timeline.h" #include "swad_timeline_favourite.h" +#include "swad_timeline_form.h" #include "swad_timeline_publication.h" #include "swad_timeline_share.h" @@ -942,7 +943,7 @@ static void TL_Not_PutFormToRemoveNote (const struct TL_Timeline *Timeline, extern const char *Txt_Remove; /***** Form to remove publication *****/ - TL_FormStart (Timeline,TL_REQ_REM_NOTE); + TL_Frm_FormStart (Timeline,TL_Frm_REQ_REM_NOTE); TL_Not_PutHiddenParamNotCod (NotCod); Ico_PutIconLink ("trash.svg",Txt_Remove); Frm_EndForm (); diff --git a/swad_timeline_post.c b/swad_timeline_post.c index e49613a5..625eaa10 100644 --- a/swad_timeline_post.c +++ b/swad_timeline_post.c @@ -32,6 +32,7 @@ #include "swad_message.h" #include "swad_profile.h" #include "swad_timeline.h" +#include "swad_timeline_form.h" #include "swad_timeline_note.h" #include "swad_timeline_post.h" #include "swad_timeline_publication.h" @@ -149,7 +150,7 @@ void TL_Pst_PutFormToWriteNewPost (struct TL_Timeline *Timeline) /* Form to write the post */ HTM_DIV_Begin ("class=\"TL_FORM_NEW_PST TL_RIGHT_WIDTH\""); - TL_FormStart (Timeline,TL_RECEIVE_POST); + TL_Frm_FormStart (Timeline,TL_Frm_RECEIVE_POST); TL_Pst_PutTextarea (Txt_New_TIMELINE_post,"TL_PST_TEXTAREA TL_RIGHT_WIDTH"); Frm_EndForm (); HTM_DIV_End (); diff --git a/swad_timeline_share.c b/swad_timeline_share.c index 4c18dc18..5d2d6779 100644 --- a/swad_timeline_share.c +++ b/swad_timeline_share.c @@ -28,6 +28,7 @@ #include "swad_database.h" #include "swad_global.h" #include "swad_timeline.h" +#include "swad_timeline_form.h" #include "swad_timeline_notification.h" #include "swad_timeline_publication.h" #include "swad_timeline_share.h" @@ -101,8 +102,7 @@ static void TL_Sha_PutFormToShaNote (long ParamCod) extern const char *Txt_Share; /***** Form and icon to mark note as favourite *****/ - TL_Usr_FormFavSha (ActShaTL_NotGbl, - ActShaTL_NotUsr, + TL_Frm_FormFavSha (TL_Frm_SHA_NOTE, "NotCod=%ld",ParamCod, TL_Sha_ICON_SHARE,Txt_Share); } @@ -112,8 +112,7 @@ static void TL_Sha_PutFormToUnsNote (long ParamCod) extern const char *Txt_TIMELINE_NOTE_Shared; /***** Form and icon to mark note as favourite *****/ - TL_Usr_FormFavSha (ActUnsTL_NotGbl, - ActUnsTL_NotUsr, + TL_Frm_FormFavSha (TL_Frm_UNS_NOTE, "NotCod=%ld",ParamCod, TL_Sha_ICON_SHARED,Txt_TIMELINE_NOTE_Shared); } @@ -349,7 +348,7 @@ static void TL_Sha_ShowUsrsWhoHaveSharedNote (const struct TL_Not_Note *Not, Not->UsrCod, (unsigned) TL_Pub_SHARED_NOTE, HowManyUsrs == TL_Usr_SHOW_FEW_USRS ? TL_Usr_DEF_USRS_SHOWN : - TL_Usr_MAX_USRS_SHOWN); + TL_Usr_MAX_USRS_SHOWN); else NumFirstUsrs = 0; @@ -364,8 +363,7 @@ static void TL_Sha_ShowUsrsWhoHaveSharedNote (const struct TL_Not_Note *Not, TL_Usr_ShowSharersOrFavers (&mysql_res,Not->NumShared,NumFirstUsrs); if (NumFirstUsrs < Not->NumShared) /* Clickable ellipsis to show all users */ - TL_Usr_PutFormToSeeAllFaversSharers (ActAllShaTL_NotGbl, - ActAllShaTL_NotUsr, + TL_Frm_PutFormToSeeAllFaversSharers (TL_Frm_ALL_SHA_NOTE, "NotCod=%ld",Not->NotCod, HowManyUsrs); HTM_DIV_End (); diff --git a/swad_timeline_user.c b/swad_timeline_user.c index d7c3b3df..5336ef77 100644 --- a/swad_timeline_user.c +++ b/swad_timeline_user.c @@ -224,91 +224,3 @@ void TL_Usr_ShowSharersOrFavers (MYSQL_RES **mysql_res, } } } - -/*****************************************************************************/ -/********************* Form to show all favers/sharers ***********************/ -/*****************************************************************************/ - -void TL_Usr_PutFormToSeeAllFaversSharers (Act_Action_t ActionGbl, - Act_Action_t ActionUsr, - const char *ParamFormat,long ParamCod, - TL_Usr_HowManyUsrs_t HowManyUsrs) - { - extern const char *Txt_View_all_USERS; - - switch (HowManyUsrs) - { - case TL_Usr_SHOW_FEW_USRS: - /***** Form and icon to mark note as favourite *****/ - TL_Usr_FormFavSha (ActionGbl, - ActionUsr, - ParamFormat,ParamCod, - TL_Usr_ICON_ELLIPSIS,Txt_View_all_USERS); - break; - case TL_Usr_SHOW_ALL_USRS: - Ico_PutIconOff (TL_Usr_ICON_ELLIPSIS,Txt_View_all_USERS); - break; - } - } - -/*****************************************************************************/ -/******* Form to fav/unfav or share/unshare in global or user timeline *******/ -/*****************************************************************************/ - -void TL_Usr_FormFavSha (Act_Action_t ActionGbl, - Act_Action_t ActionUsr, - const char *ParamFormat,long ParamCod, - const char *Icon,const char *Title) - { - char *OnSubmit; - char ParamStr[7 + Cns_MAX_DECIMAL_DIGITS_LONG + 1]; - - /***** Create parameter string *****/ - sprintf (ParamStr,ParamFormat,ParamCod); - - /* - +---------------------------------------------------------------------------+ - | div which content will be updated (parent of parent of form) | - | +---------------------+ +-------+ +-------------------------------------+ | - | | div (parent of form)| | div | | div for users | | - | | +-----------------+ | | for | | +------+ +------+ +------+ +------+ | | - | | | this form | | | num. | | | | | | | | | form | | | - | | | +-------------+ | | | of | | | user | | user | | user | | to | | | - | | | | fav icon | | | | users | | | 1 | | 2 | | 3 | | show | | | - | | | +-------------+ | | | | | | | | | | | | all | | | - | | +-----------------+ | | | | +------+ +------+ +------+ +------+ | | - | +---------------------+ +-------+ +-------------------------------------+ | - +---------------------------------------------------------------------------+ - */ - - /***** Form and icon to mark note as favourite *****/ - /* Form with icon */ - if (Gbl.Usrs.Other.UsrDat.UsrCod > 0) - { - if (asprintf (&OnSubmit,"updateDivFaversSharers(this," - "'act=%ld&ses=%s&%s&OtherUsrCod=%s');" - " return false;", // return false is necessary to not submit form - Act_GetActCod (ActionUsr), - Gbl.Session.Id, - ParamStr, - Gbl.Usrs.Other.UsrDat.EnUsrCod) < 0) - Lay_NotEnoughMemoryExit (); - Frm_StartFormUniqueAnchorOnSubmit (ActUnk,"timeline",OnSubmit); - } - else - { - if (asprintf (&OnSubmit,"updateDivFaversSharers(this," - "'act=%ld&ses=%s&%s');" - " return false;", // return false is necessary to not submit form - Act_GetActCod (ActionGbl), - Gbl.Session.Id, - ParamStr) < 0) - Lay_NotEnoughMemoryExit (); - Frm_StartFormUniqueAnchorOnSubmit (ActUnk,NULL,OnSubmit); - } - Ico_PutIconLink (Icon,Title); - Frm_EndForm (); - - /* Free allocated memory */ - free (OnSubmit); - } diff --git a/swad_timeline_user.h b/swad_timeline_user.h index 3563f5ee..c620636c 100644 --- a/swad_timeline_user.h +++ b/swad_timeline_user.h @@ -36,8 +36,6 @@ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define TL_Usr_ICON_ELLIPSIS "ellipsis-h.svg" - #define TL_Usr_DEF_USRS_SHOWN 5 // Default maximum number of users shown who have share/fav a note #define TL_Usr_MAX_USRS_SHOWN 1000 // Top maximum number of users shown who have share/fav a note @@ -66,13 +64,5 @@ void TL_Usr_RemoveUsrContent (long UsrCod); void TL_Usr_ShowNumSharersOrFavers (unsigned NumUsrs); void TL_Usr_ShowSharersOrFavers (MYSQL_RES **mysql_res, unsigned NumUsrs,unsigned NumFirstUsrs); -void TL_Usr_PutFormToSeeAllFaversSharers (Act_Action_t ActionGbl, - Act_Action_t ActionUsr, - const char *ParamFormat,long ParamCod, - TL_Usr_HowManyUsrs_t HowManyUsrs); -void TL_Usr_FormFavSha (Act_Action_t ActionGbl, - Act_Action_t ActionUsr, - const char *ParamFormat,long ParamCod, - const char *Icon,const char *Title); #endif