1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
package user
import "encoding/base64"
import "encoding/json"
import "net/http"
import "time"
import "soko/pkg/app/utils"
import "soko/pkg/models"
templ useflags(preferences models.UseflagsPreferences) {
<form method="post" action="/user/preferences/useflags/edit">
<div class="row">
<div class="col-5 offset-1 mt-1">
<div class="card" style="background: transparent;">
<div class="card-body">
<img id="img1" alt="Popular USE flags (default)" src="/assets/pgo6.png" style="width: 100%;cursor: pointer;"/>
</div>
</div>
<div class="text-center mt-2">
<div class="form-check text-center form-check-inline" style="text-overflow: ellipsis;overflow: hidden;">
<input
type="radio"
id="BubbleUseflagDefaultPage"
name="useflag-default-page"
value="bubble"
checked?={ preferences.Layout == "bubble" }
/>
<label class="form-check-label ml-1" for="BubbleUseflagDefaultPage" style="overflow:hidden;text-overflow: ellipsis;" title="Popular USE flags (default)">Popular USE flags <i>(default)</i></label>
</div>
</div>
</div>
<div class="col-5 mt-1">
<div class="card" style="background: transparent;">
<div class="card-body">
<img id="img2" alt="USE flags search" src="/assets/pgo5.png" style="width: 100%;cursor: pointer;"/>
</div>
</div>
<div class="text-center mt-2">
<div class="form-check text-center form-check-inline" style="text-overflow: ellipsis;overflow: hidden;">
<input
type="radio"
id="SearchUseflagDefaultPage"
name="useflag-default-page"
value="search"
checked?={ preferences.Layout == "search" }
/>
<label class="form-check-label ml-1" for="SearchUseflagDefaultPage" style="overflow:hidden;text-overflow: ellipsis;" title="USE flags search">USE flags search</label>
</div>
</div>
</div>
<div class="col-10 offset-1 mt-4">
<button type="submit" class="float-right btn btn-sm btn-primary">Save</button>
<a class="float-right btn btn-sm btn-outline-danger mr-2" href="/user/preferences/useflags/reset">Reset to Defaults</a>
</div>
</div>
</form>
<div id="myModal" class="modal">
<span class="close">×</span>
<img class="modal-content" id="img01"/>
<div id="caption"></div>
</div>
}
func Useflags(w http.ResponseWriter, r *http.Request) {
userPreferences := utils.GetUserPreferences(r)
r.ParseForm()
// default use flag page
layout := r.Form.Get("useflag-default-page")
if layout == "bubble" || layout == "search" {
userPreferences.Useflags.Layout = layout
}
// store cookie
encodedUserPreferences, err := json.Marshal(&userPreferences.Useflags)
if err == nil {
sEnc := base64.StdEncoding.EncodeToString(encodedUserPreferences)
addCookie(w, "userpref_useflags", "/", sEnc, 365*24*time.Hour)
}
http.Redirect(w, r, "/user/preferences/useflags", http.StatusSeeOther)
}
func ResetUseflags(w http.ResponseWriter, r *http.Request) {
userPreferences := utils.GetDefaultUserPreferences()
encodedUserPreferences, err := json.Marshal(&userPreferences.Useflags)
if err == nil {
sEnc := base64.StdEncoding.EncodeToString(encodedUserPreferences)
addCookie(w, "userpref_useflags", "/", sEnc, 365*24*time.Hour)
}
http.Redirect(w, r, "/user/preferences/useflags", http.StatusSeeOther)
}
|