github.com/benoitkugler/goacve@v0.0.0-20201217100549-151ce6e55dc8/client/GUI/messages/contenus.go (about)

     1  package messages
     2  
     3  import (
     4  	"fmt"
     5  	"strconv"
     6  	"strings"
     7  
     8  	"github.com/benoitkugler/goACVE/client/GUI/basic"
     9  	dm "github.com/benoitkugler/goACVE/server/core/datamodel"
    10  	rd "github.com/benoitkugler/goACVE/server/core/rawdata"
    11  	"github.com/therecipe/qt/core"
    12  	"github.com/therecipe/qt/widgets"
    13  )
    14  
    15  type contenuPaiement struct {
    16  	*widgets.QFrame
    17  
    18  	onGoToPaiement func(id int64)
    19  }
    20  
    21  func newContenuPaiement(base *dm.BaseLocale, id int64) *contenuPaiement {
    22  	out := &contenuPaiement{QFrame: basic.Frame()}
    23  	out.SetContentsMargins(5, 0, 5, 0)
    24  
    25  	paiement := base.Paiements[id]
    26  	desc, montant := paiement.Description()
    27  
    28  	labelDesc := basic.Label(fmt.Sprintf(`<a href='%d'>%s</a>`, paiement.Id, desc))
    29  	labelDesc.ConnectLinkActivated(func(link string) {
    30  		if id, err := strconv.Atoi(link); err == nil {
    31  			out.onGoToPaiement(int64(id))
    32  		}
    33  	})
    34  
    35  	labelMontant := basic.Label(montant)
    36  	labelMontant.SetAlignment(core.Qt__AlignRight)
    37  
    38  	layout := widgets.NewQHBoxLayout2(out)
    39  	layout.SetContentsMargins(0, 0, 0, 0)
    40  	layout.AddWidget(labelDesc, 2, 0)
    41  	layout.AddStretch(1)
    42  	layout.AddWidget(labelMontant, 1, core.Qt__AlignRight)
    43  	return out
    44  }
    45  
    46  type contenuPerso struct {
    47  	*widgets.QLabel
    48  }
    49  
    50  func newContenuPerso(contenu dm.ContenuPerso) *contenuPerso {
    51  	label := basic.Label(strings.ReplaceAll(string(contenu), "\n", "<br/>"))
    52  	label.SetWordWrap(true)
    53  	label.SetTextFormat(core.Qt__RichText)
    54  	return &contenuPerso{QLabel: label}
    55  }
    56  
    57  type contenuDocument struct {
    58  	*widgets.QLabel
    59  
    60  	onGoToCamp func(id int64)
    61  }
    62  
    63  func newContenuDocument(base *dm.BaseLocale, contenu dm.ContenuDocument) *contenuDocument {
    64  	out := &contenuDocument{QLabel: basic.Label("")}
    65  
    66  	camp := base.Camps[contenu.IdCamp]
    67  	out.SetText(fmt.Sprintf(`Les <b>documents</b> du <a href='%d'>séjour %s</a> ont été envoyés.`, camp.Id, camp.Label()))
    68  	out.ConnectLinkActivated(func(link string) {
    69  		if id, err := strconv.Atoi(link); err == nil {
    70  			out.onGoToCamp(int64(id))
    71  		}
    72  	})
    73  	return out
    74  }
    75  
    76  type contenuSondage struct {
    77  	*widgets.QLabel
    78  
    79  	onGoToCamp func(id int64)
    80  }
    81  
    82  func newContenuSondage(base *dm.BaseLocale, contenu dm.ContenuSondage) *contenuSondage {
    83  	out := &contenuSondage{QLabel: basic.Label("")}
    84  
    85  	camp := base.Camps[contenu.IdCamp]
    86  	out.SetText(fmt.Sprintf(`Le <b>sondage</b> pour le <a href='%d'>séjour %s</a> a été envoyé`, camp.Id, camp.Label()))
    87  	out.ConnectLinkActivated(func(link string) {
    88  		if id, err := strconv.Atoi(link); err == nil {
    89  			out.onGoToCamp(int64(id))
    90  		}
    91  	})
    92  	return out
    93  }
    94  
    95  type contenuPlaceLiberee struct {
    96  	*widgets.QLabel
    97  
    98  	onGoToParticipant func(id int64)
    99  }
   100  
   101  func newContenuPlaceLiberee(base *dm.BaseLocale, contenu dm.ContenuPlaceLiberee) *contenuPlaceLiberee {
   102  	out := &contenuPlaceLiberee{QLabel: basic.Label("")}
   103  
   104  	participant := base.NewParticipant(contenu.IdParticipant)
   105  	camp := participant.GetCamp().RawData()
   106  	out.SetText(fmt.Sprintf(`Une place s'est libérée pour <a href='%d'>%s</a> sur le séjour %s.`,
   107  		participant.Id, participant.GetPersonne().RawData().NomPrenom(), camp.Label()))
   108  	out.ConnectLinkActivated(func(link string) {
   109  		if id, err := strconv.Atoi(link); err == nil {
   110  			out.onGoToParticipant(int64(id))
   111  		}
   112  	})
   113  	return out
   114  }
   115  
   116  type contenuFacture struct {
   117  	*widgets.QFrame
   118  
   119  	onShow func()
   120  }
   121  
   122  func newContenuFacture(isAcquitte, isRappel bool, downloaded rd.Time) *contenuFacture {
   123  	out := &contenuFacture{QFrame: basic.Frame()}
   124  
   125  	ac := ""
   126  	if isAcquitte {
   127  		ac = " <b>acquittée</b>"
   128  	}
   129  	sprintf := fmt.Sprintf("Une <a href='goto'>facture%s</a> a été envoyée.", ac)
   130  	if !isAcquitte && isRappel {
   131  		sprintf += " Il s'agit d'un <i>rappel</i>."
   132  	}
   133  	label := basic.Label(sprintf)
   134  	label.ConnectLinkActivated(func(_ string) { // un seul lien possible
   135  		out.onShow()
   136  	})
   137  
   138  	layout := widgets.NewQHBoxLayout2(out)
   139  	layout.SetContentsMargins(5, 0, 5, 0)
   140  	layout.AddWidget(label, 2, core.Qt__AlignLeft)
   141  	if !downloaded.Time().IsZero() {
   142  		layout.AddWidget(basic.Label(fmt.Sprintf("Téléchargée le %s", downloaded.String())), 2, core.Qt__AlignRight)
   143  	}
   144  	return out
   145  }
   146  
   147  type contenuAttestation struct {
   148  	*widgets.QFrame
   149  
   150  	onShow func()
   151  }
   152  
   153  func newContenuAttestation(downloaded rd.Time) *contenuAttestation {
   154  	out := &contenuAttestation{QFrame: basic.Frame()}
   155  
   156  	label := basic.Label(fmt.Sprintf("Une <a href='goto'>attestation de présence</a> a été envoyée."))
   157  	label.ConnectLinkActivated(func(_ string) { // un seul lien possible
   158  		out.onShow()
   159  	})
   160  
   161  	layout := widgets.NewQHBoxLayout2(out)
   162  	layout.SetContentsMargins(5, 0, 5, 0)
   163  	layout.AddWidget(label, 2, core.Qt__AlignLeft)
   164  	if !downloaded.Time().IsZero() {
   165  		layout.AddWidget(basic.Label(fmt.Sprintf("Téléchargée le %s", downloaded.String())), 2, core.Qt__AlignRight)
   166  	}
   167  	return out
   168  }