diff --git a/js/swad18.51.js b/js/swad18.56.js similarity index 97% rename from js/swad18.51.js rename to js/swad18.56.js index f7b4dc46..8937a2df 100644 --- a/js/swad18.51.js +++ b/js/swad18.56.js @@ -1373,7 +1373,7 @@ function ExpandChildren (idParent) { } function ContractFolder (idParent) { - var parent = document.getElementById(idParent); + var parent = document.getElementById(idParent); var iconToExpand = document.getElementById('expand_' + idParent); var iconToContract = document.getElementById('contract_' + idParent); var iconFolderClosed = document.getElementById('folder_closed_' + idParent); @@ -1403,3 +1403,31 @@ function ContractChildren (idParent) { row.style.display = 'none'; // hide } } + +/*****************************************************************************/ +/**************** Animate icon "recycle" when click on a link ****************/ +/*****************************************************************************/ + +function FavSocial (idParent) { + var parent = document.getElementById(idParent); + var iconToFav = document.getElementById('fav_' + idParent); + var iconToUnfav = document.getElementById('unfav_' + idParent); + + if (parent.dataset.status == 'unfaved') { + parent.dataset.status = 'faved'; + iconToFav.style.display = 'none'; + iconToUnfav.style.display = ''; + } +} + +function UnfavSocial (idParent) { + var parent = document.getElementById(idParent); + var iconToFav = document.getElementById('fav_' + idParent); + var iconToUnfav = document.getElementById('unfav_' + idParent); + + if (parent.dataset.status == 'faved') { + parent.dataset.status = 'unfaved'; + iconToUnfav.style.display = 'none'; + iconToFav.style.display = ''; + } +} diff --git a/swad_action.c b/swad_action.c index 3d9b1144..282a35ba 100644 --- a/swad_action.c +++ b/swad_action.c @@ -1615,8 +1615,10 @@ struct Act_Actions Act_Actions[Act_NUM_ACTIONS] = /* ActRcvSocComGbl */{1503,-1,TabUnk,ActSeeSocTmlGbl ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_DATA,Act_BRW_1ST_TAB,Soc_ShowTimelineGbl1 ,Soc_ReceiveCommentGbl ,NULL}, /* ActShaSocNotGbl */{1495,-1,TabUnk,ActSeeSocTmlGbl ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_NORM,Act_BRW_1ST_TAB,Soc_ShowTimelineGbl1 ,Soc_ShareSocialNoteGbl ,NULL}, /* ActUnsSocNotGbl */{1496,-1,TabUnk,ActSeeSocTmlGbl ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_NORM,Act_BRW_1ST_TAB,Soc_ShowTimelineGbl1 ,Soc_UnshareSocialNoteGbl ,NULL}, - /* ActFavSocNotGbl */{1512,-1,TabUnk,ActSeeSocTmlGbl ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_NORM,Act_BRW_1ST_TAB,Soc_ShowTimelineGbl1 ,Soc_FavSocialNoteGbl ,NULL}, - /* ActUnfSocNotGbl */{1513,-1,TabUnk,ActSeeSocTmlGbl ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_NORM,Act_BRW_1ST_TAB,Soc_ShowTimelineGbl1 ,Soc_UnfavSocialNoteGbl ,NULL}, +// /* ActFavSocNotGbl */{1512,-1,TabUnk,ActSeeSocTmlGbl ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_NORM,Act_BRW_1ST_TAB,Soc_ShowTimelineGbl1 ,Soc_FavSocialNoteGbl ,NULL}, + /* ActFavSocNotGbl */{1512,-1,TabUnk,ActSeeSocTmlGbl ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_NORM,Act_204_NO_CONT,Soc_FavSocialNoteGbl_new ,NULL ,NULL}, +// /* ActUnfSocNotGbl */{1513,-1,TabUnk,ActSeeSocTmlGbl ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_NORM,Act_BRW_1ST_TAB,Soc_ShowTimelineGbl1 ,Soc_UnfavSocialNoteGbl ,NULL}, + /* ActUnfSocNotGbl */{1513,-1,TabUnk,ActSeeSocTmlGbl ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_NORM,Act_204_NO_CONT,Soc_UnfavSocialNoteGbl_new ,NULL ,NULL}, /* ActFavSocComGbl */{1516,-1,TabUnk,ActSeeSocTmlGbl ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_NORM,Act_BRW_1ST_TAB,Soc_ShowTimelineGbl1 ,Soc_FavSocialCommentGbl ,NULL}, /* ActUnfSocComGbl */{1517,-1,TabUnk,ActSeeSocTmlGbl ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_NORM,Act_BRW_1ST_TAB,Soc_ShowTimelineGbl1 ,Soc_UnfavSocialCommentGbl ,NULL}, /* ActReqRemSocPubGbl*/{1494,-1,TabUnk,ActSeeSocTmlGbl ,0x3F8,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,0x3C6,Act_CONT_NORM,Act_BRW_1ST_TAB,Soc_ShowTimelineGbl1 ,Soc_RequestRemSocialNoteGbl ,NULL}, diff --git a/swad_changelog.h b/swad_changelog.h index 1dbd8ded..e46fca6b 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -429,10 +429,11 @@ En OpenSWAD: ps2pdf source.ps destination.pdf */ -#define Log_PLATFORM_VERSION "SWAD 18.55 (2019-02-21)" +#define Log_PLATFORM_VERSION "SWAD 18.56 (2019-02-23)" #define CSS_FILE "swad18.55.css" -#define JS_FILE "swad18.51.js" +#define JS_FILE "swad18.56.js" /* + Version 18.56: Feb 23, 2019 Favourite is made in Javascript without reloading page. (237787 lines) Version 18.55: Feb 22, 2019 Changes in CSS styles related to forms. (237585 lines) Version 18.54.1: Feb 22, 2019 Following and followers shown in photo zoom. (237586 lines) Version 18.54: Feb 21, 2019 Selection of users scope in timeline is made with icons. (237534 lines) diff --git a/swad_form.c b/swad_form.c index 6976369e..a1ddedde 100644 --- a/swad_form.c +++ b/swad_form.c @@ -97,6 +97,15 @@ void Frm_StartFormUniqueAnchor (Act_Action_t NextAction,const char *Anchor) Frm_StartFormInternal (NextAction,true,Gbl.Form.UniqueId,Anchor,NULL); // Do put now parameter location (if no open session) } +void Frm_StartFormUniqueAnchorOnSubmit (Act_Action_t NextAction,const char *Anchor,const char *OnSubmit) + { + Gbl.Form.Num++; // Initialized to -1. The first time it is incremented, it will be equal to 0 + snprintf (Gbl.Form.UniqueId,sizeof (Gbl.Form.UniqueId), + "form_%s_%d", + Gbl.UniqueNameEncrypted,Gbl.Form.Num); + Frm_StartFormInternal (NextAction,true,Gbl.Form.UniqueId,Anchor,OnSubmit); // Do put now parameter location (if no open session) + } + void Frm_StartFormId (Act_Action_t NextAction,const char *Id) { Gbl.Form.Num++; // Initialized to -1. The first time it is incremented, it will be equal to 0 diff --git a/swad_form.h b/swad_form.h index dbdaba59..47731908 100644 --- a/swad_form.h +++ b/swad_form.h @@ -57,6 +57,7 @@ void Frm_StartFormAnchorOnSubmit (Act_Action_t NextAction,const char *Anchor,con void Frm_StartFormUnique (Act_Action_t NextAction); void Frm_StartFormAnchor (Act_Action_t NextAction,const char *Anchor); void Frm_StartFormUniqueAnchor (Act_Action_t NextAction,const char *Anchor); +void Frm_StartFormUniqueAnchorOnSubmit (Act_Action_t NextAction,const char *Anchor,const char *OnSubmit); void Frm_StartFormId (Act_Action_t NextAction,const char *Id); void Frm_SetParamsForm (char ParamsStr[Frm_MAX_BYTES_PARAMS_STR],Act_Action_t NextAction, bool PutParameterLocationIfNoSesion); diff --git a/swad_profile.c b/swad_profile.c index 8aa20cdc..a412e403 100644 --- a/swad_profile.c +++ b/swad_profile.c @@ -745,7 +745,7 @@ static unsigned long Prf_GetNumUsrsWithNumClicksPerDay (void) static void Prf_ShowRanking (unsigned long Rank,unsigned long NumUsrs) { - extern const char *The_ClassFormInBox[The_NUM_THEMES]; + extern const char *The_ClassFormOutBox[The_NUM_THEMES]; extern const char *Txt_of_PART_OF_A_TOTAL; /***** Part of a total and end container *****/ @@ -757,7 +757,7 @@ static void Prf_ShowRanking (unsigned long Rank,unsigned long NumUsrs) Frm_StartForm (ActSeeUseGbl); Sco_PutParamScope ("ScopeSta",Sco_SCOPE_SYS); Par_PutHiddenParamUnsigned ("FigureType",(unsigned) Fig_USERS_RANKING); - Frm_LinkFormSubmit (Gbl.Title,The_ClassFormInBox[Gbl.Prefs.Theme],NULL); + Frm_LinkFormSubmit (Gbl.Title,The_ClassFormOutBox[Gbl.Prefs.Theme],NULL); fprintf (Gbl.F.Out,"#%lu",Rank); Frm_EndForm (); } diff --git a/swad_social.c b/swad_social.c index 0a239456..d9c7eb6a 100644 --- a/swad_social.c +++ b/swad_social.c @@ -198,6 +198,8 @@ static void Soc_PutDisabledIconShare (unsigned NumShared); static void Soc_PutDisabledIconFav (unsigned NumFavs); static void Soc_PutFormToShareSocialNote (long NotCod); +static void Soc_PutFormToFavSocialNote_new (long NotCod,const char *FavId,bool Hidden); +static void Soc_PutFormToUnfavSocialNote_new (long NotCod,const char *FavId,bool Hidden); static void Soc_PutFormToFavSocialNote (long NotCod); static void Soc_PutFormToUnshareSocialNote (long NotCod); @@ -213,12 +215,14 @@ static long Soc_GetParamPubCod (void); static long Soc_ReceiveComment (void); static long Soc_ShareSocialNote (void); +static long Soc_FavSocialNote_new (void); static long Soc_FavSocialNote (void); static long Soc_FavSocialComment (void); static void Soc_CreateNotifToAuthor (long AuthorCod,long PubCod, Ntf_NotifyEvent_t NotifyEvent); static long Soc_UnshareSocialNote (void); +static long Soc_UnfavSocialNote_new (void); static long Soc_UnfavSocialNote (void); static long Soc_UnfavSocialComment (void); @@ -1373,6 +1377,8 @@ static void Soc_WriteSocialNote (const struct SocialNote *SocNot, char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1]; unsigned NumComments; char IdNewComment[Frm_MAX_BYTES_ID + 1]; + static unsigned Num = 0; + char FavId[Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64 + 1 + 10 + 1]; /***** Start box ****/ if (ShowNoteAlone) @@ -1563,18 +1569,37 @@ static void Soc_WriteSocialNote (const struct SocialNote *SocNot, "
"); /* Put icon to mark this social note as favourite */ + Num++; + sprintf (FavId,"%s_%u",Gbl.UniqueNameEncrypted,Num); + if (IAmTheAuthor) // I am the author Soc_PutDisabledIconFav (SocNot->NumFavs); else if (IAmAFaverOfThisSocNot) // I have favourited this social note + { /* Put icon to unfav this publishing */ - Soc_PutFormToUnfavSocialNote (SocNot->NotCod); + fprintf (Gbl.F.Out,"
", + FavId); + Soc_PutFormToFavSocialNote_new (SocNot->NotCod,FavId,true); + Soc_PutFormToUnfavSocialNote_new (SocNot->NotCod,FavId,false); + // Soc_PutFormToUnfavSocialNote (SocNot->NotCod); + fprintf (Gbl.F.Out,"
"); + } else // I am not the author and I am not a sharer { if (SocNot->Unavailable) // Unavailable social notes can not be favourited Soc_PutDisabledIconFav (SocNot->NumFavs); else - /* Put icon to share this publishing */ - Soc_PutFormToFavSocialNote (SocNot->NotCod); + { + /* Put icon to fav this publishing */ + fprintf (Gbl.F.Out,"
", + FavId); + Soc_PutFormToFavSocialNote_new (SocNot->NotCod,FavId,false); + Soc_PutFormToUnfavSocialNote_new (SocNot->NotCod,FavId,true); + // Soc_PutFormToFavSocialNote (SocNot->NotCod); + fprintf (Gbl.F.Out,"
"); + } } /* Show who have marked this social note as favourite */ @@ -2842,6 +2867,76 @@ static void Soc_PutFormToShareSocialNote (long NotCod) /*****************************************************************************/ // All forms in this function and nested functions must have unique identifiers +static void Soc_PutFormToFavSocialNote_new (long NotCod,const char *FavId,bool Hidden) + { + extern const char *Txt_Mark_as_favourite; + char JavaScriptFunc[256 + Brw_MAX_ROW_ID]; + + /***** Start container *****/ + fprintf (Gbl.F.Out,"
"); + + /***** Form and icon to mark social note as favourite *****/ + snprintf (JavaScriptFunc,sizeof (JavaScriptFunc), + "FavSocial('%s')", + FavId); + if (Gbl.Usrs.Other.UsrDat.UsrCod > 0) + { + Frm_StartFormUniqueAnchorOnSubmit (ActFavSocNotUsr,"timeline", + JavaScriptFunc); // JavaScript function to fav social note + Usr_PutParamOtherUsrCodEncrypted (); + } + else + { + Frm_StartFormUniqueAnchorOnSubmit (ActFavSocNotGbl,NULL, + JavaScriptFunc); // JavaScript function to fav social note + Soc_PutParamWhichUsrs (); + } + Soc_PutHiddenParamNotCod (NotCod); + Ico_PutIconLink ("heart.svg",Txt_Mark_as_favourite); + Frm_EndForm (); + + /***** End container *****/ + fprintf (Gbl.F.Out,"
"); + } + +static void Soc_PutFormToUnfavSocialNote_new (long NotCod,const char *FavId,bool Hidden) + { + extern const char *Txt_SOCIAL_NOTE_Favourite; + char JavaScriptFunc[256 + Brw_MAX_ROW_ID]; + + /***** Start container *****/ + fprintf (Gbl.F.Out,"
"); + + /***** Form and icon to mark social note as favourite *****/ + snprintf (JavaScriptFunc,sizeof (JavaScriptFunc), + "UnfavSocial('%s')", + FavId); + if (Gbl.Usrs.Other.UsrDat.UsrCod > 0) + { + Frm_StartFormUniqueAnchorOnSubmit (ActUnfSocNotUsr,"timeline", + JavaScriptFunc); // JavaScript function to unfav social note + Usr_PutParamOtherUsrCodEncrypted (); + } + else + { + Frm_StartFormUniqueAnchorOnSubmit (ActUnfSocNotGbl,NULL, + JavaScriptFunc); // JavaScript function to unfav social note + Soc_PutParamWhichUsrs (); + } + Soc_PutHiddenParamNotCod (NotCod); + Ico_PutIconLink ("heart-red.svg",Txt_SOCIAL_NOTE_Favourite); + Frm_EndForm (); + + /***** End container *****/ + fprintf (Gbl.F.Out,"
"); + } + static void Soc_PutFormToFavSocialNote (long NotCod) { extern const char *Txt_Mark_as_favourite; @@ -3159,6 +3254,14 @@ static long Soc_ShareSocialNote (void) /********************** Mark a social note as favourite **********************/ /*****************************************************************************/ +void Soc_FavSocialNoteGbl_new (void) + { + long NotCod; + + /***** Mark social note as favourite *****/ + NotCod = Soc_FavSocialNote_new (); + } + void Soc_FavSocialNoteGbl (void) { long NotCod; @@ -3193,6 +3296,47 @@ void Soc_FavSocialNoteUsr (void) Lay_EndSection (); } +static long Soc_FavSocialNote_new (void) + { + extern const char *Txt_The_original_post_no_longer_exists; + struct SocialNote SocNot; + bool ItsMe; + long OriginalPubCod; + + /***** Get data of social note *****/ + SocNot.NotCod = Soc_GetParamNotCod (); + Soc_GetDataOfSocialNotByCod (&SocNot); + + if (SocNot.NotCod > 0) + { + ItsMe = Usr_ItsMe (SocNot.UsrCod); + if (Gbl.Usrs.Me.Logged && !ItsMe) // I am not the author + if (!Soc_CheckIfNoteIsFavedByUsr (SocNot.NotCod, + Gbl.Usrs.Me.UsrDat.UsrCod)) // I have not yet favourited the note + { + /***** Mark as favourite in database *****/ + DB_QueryINSERT ("can not favourite social note", + "INSERT IGNORE INTO social_notes_fav" + " (NotCod,UsrCod,TimeFav)" + " VALUES" + " (%ld,%ld,NOW())", + SocNot.NotCod, + Gbl.Usrs.Me.UsrDat.UsrCod); + + /* Update number of times this social note is favourited */ + SocNot.NumFavs = Soc_GetNumTimesANoteHasBeenFav (&SocNot); + + /**** Create notification about favourite post + for the author of the post ***/ + OriginalPubCod = Soc_GetPubCodOfOriginalSocialNote (SocNot.NotCod); + if (OriginalPubCod > 0) + Soc_CreateNotifToAuthor (SocNot.UsrCod,OriginalPubCod,Ntf_EVENT_TIMELINE_FAV); + } + } + + return SocNot.NotCod; + } + static long Soc_FavSocialNote (void) { extern const char *Txt_The_original_post_no_longer_exists; @@ -3457,6 +3601,14 @@ static long Soc_UnshareSocialNote (void) /******* Stop marking as favourite a previously favourited social note *******/ /*****************************************************************************/ +void Soc_UnfavSocialNoteGbl_new (void) + { + long NotCod; + + /***** Stop marking as favourite a previously favourited social note *****/ + NotCod = Soc_UnfavSocialNote_new (); + } + void Soc_UnfavSocialNoteGbl (void) { long NotCod; @@ -3491,6 +3643,44 @@ void Soc_UnfavSocialNoteUsr (void) Lay_EndSection (); } +static long Soc_UnfavSocialNote_new (void) + { + struct SocialNote SocNot; + long OriginalPubCod; + bool ItsMe; + + /***** Get data of social note *****/ + SocNot.NotCod = Soc_GetParamNotCod (); + Soc_GetDataOfSocialNotByCod (&SocNot); + + if (SocNot.NotCod > 0) + { + ItsMe = Usr_ItsMe (SocNot.UsrCod); + if (SocNot.NumFavs && + Gbl.Usrs.Me.Logged && !ItsMe) // I am not the author + if (Soc_CheckIfNoteIsFavedByUsr (SocNot.NotCod, + Gbl.Usrs.Me.UsrDat.UsrCod)) // I have favourited the note + { + /***** Delete the mark as favourite from database *****/ + DB_QueryDELETE ("can not unfavourite social note", + "DELETE FROM social_notes_fav" + " WHERE NotCod=%ld AND UsrCod=%ld", + SocNot.NotCod, + Gbl.Usrs.Me.UsrDat.UsrCod); + + /***** Update number of times this social note is favourited *****/ + SocNot.NumFavs = Soc_GetNumTimesANoteHasBeenFav (&SocNot); + + /***** Mark possible notifications on this social note as removed *****/ + OriginalPubCod = Soc_GetPubCodOfOriginalSocialNote (SocNot.NotCod); + if (OriginalPubCod > 0) + Ntf_MarkNotifAsRemoved (Ntf_EVENT_TIMELINE_FAV,OriginalPubCod); + } + } + + return SocNot.NotCod; + } + static long Soc_UnfavSocialNote (void) { extern const char *Txt_The_original_post_no_longer_exists; diff --git a/swad_social.h b/swad_social.h index 7b93f093..874ad37e 100644 --- a/swad_social.h +++ b/swad_social.h @@ -157,6 +157,7 @@ void Soc_ReceiveCommentUsr (void); void Soc_ShareSocialNoteGbl (void); void Soc_ShareSocialNoteUsr (void); +void Soc_FavSocialNoteGbl_new (void); void Soc_FavSocialNoteGbl (void); void Soc_FavSocialNoteUsr (void); void Soc_FavSocialCommentGbl (void); @@ -164,6 +165,7 @@ void Soc_FavSocialCommentUsr (void); void Soc_UnshareSocialNoteGbl (void); void Soc_UnshareSocialNoteUsr (void); +void Soc_UnfavSocialNoteGbl_new (void); void Soc_UnfavSocialNoteGbl (void); void Soc_UnfavSocialNoteUsr (void); void Soc_UnfavSocialCommentGbl (void);