PrayerTracker/src/PrayerTracker.UI/SmallGroup.fs

521 lines
23 KiB
Forth
Raw Normal View History

2019-02-18 01:25:07 +00:00
module PrayerTracker.Views.SmallGroup
open Giraffe.GiraffeViewEngine
open Microsoft.Extensions.Localization
open PrayerTracker
open PrayerTracker.Entities
open PrayerTracker.ViewModels
open System.IO
/// View for the announcement page
let announcement isAdmin ctx vi =
let s = I18N.localizer.Force ()
let reqTypes = ReferenceList.requestTypeList s
[ form [ _action "/small-group/announcement/send"; _method "post"; _class "pt-center-columns" ] [
yield csrfToken ctx
yield div [ _class "pt-field-row" ] [
div [ _class "pt-field pt-editor" ] [
label [ _for "text" ] [ encLocText s.["Announcement Text"] ]
textarea [ _name "text"; _id "text"; _autofocus ] []
]
]
match isAdmin with
| true ->
2019-02-18 01:25:07 +00:00
yield div [ _class "pt-field-row" ] [
div [ _class "pt-field" ] [
label [] [ encLocText s.["Send Announcement to"]; rawText ":" ]
div [ _class "pt-center-text" ] [
radio "sendToClass" "sendY" "Y" "Y"
label [ _for "sendY" ] [ encLocText s.["This Group"]; rawText "     " ]
radio "sendToClass" "sendN" "N" "Y"
label [ _for "sendN" ] [ encLocText s.["All {0} Users", s.["PrayerTracker"]] ]
]
]
]
| false ->
yield input [ _type "hidden"; _name "sendToClass"; _value "Y" ]
yield div [ _class "pt-field-row pt-fadeable pt-shown"; _id "divAddToList" ] [
div [ _class "pt-checkbox-field" ] [
input [ _type "checkbox"; _name "addToRequestList"; _id "addToRequestList"; _value "True" ]
label [ _for "addToRequestList" ] [ encLocText s.["Add to Request List"] ]
]
]
yield div [ _class "pt-field-row pt-fadeable"; _id "divCategory" ] [
div [ _class "pt-field" ] [
label [ _for "requestType" ] [ encLocText s.["Request Type"] ]
reqTypes
|> Seq.ofList
|> Seq.map (fun item -> fst item, (snd item).Value)
|> selectList "requestType" "Announcement" []
]
]
yield div [ _class "pt-field-row" ] [ submit [] "send" s.["Send Announcement"] ]
]
script [] [ rawText "PT.onLoad(PT.smallGroup.announcement.onPageLoad)" ]
]
|> Layout.Content.standard
|> Layout.standard vi "Send Announcement"
/// View for once an announcement has been sent
let announcementSent (m : Announcement) vi =
let s = I18N.localizer.Force ()
[ span [ _class "pt-email-heading" ] [ encLocText s.["HTML Format"]; rawText ":" ]
div [ _class "pt-email-canvas" ] [ rawText m.text ]
br []
br []
span [ _class "pt-email-heading" ] [ encLocText s.["Plain-Text Format"]; rawText ":" ]
div [ _class "pt-email-canvas" ] [ pre [] [ encodedText (m.plainText ()) ] ]
]
|> Layout.Content.standard
|> Layout.standard vi "Announcement Sent"
/// View for the small group add/edit page
let edit (m : EditSmallGroup) (churches : Church list) ctx vi =
let s = I18N.localizer.Force ()
let pageTitle = match m.isNew () with true -> "Add a New Group" | false -> "Edit Group"
form [ _action "/small-group/save"; _method "post"; _class "pt-center-columns" ] [
csrfToken ctx
input [ _type "hidden"; _name "smallGroupId"; _value (flatGuid m.smallGroupId) ]
2019-02-18 01:25:07 +00:00
div [ _class "pt-field-row" ] [
div [ _class "pt-field" ] [
label [ _for "name" ] [ encLocText s.["Group Name"] ]
input [ _type "text"; _name "name"; _id "name"; _value m.name; _required; _autofocus ]
]
]
div [ _class "pt-field-row" ] [
div [ _class "pt-field" ] [
label [ _for "churchId" ] [ encLocText s.["Church"] ]
seq {
yield "", selectDefault s.["Select Church"].Value
yield! churches |> List.map (fun c -> flatGuid c.churchId, c.name)
2019-02-18 01:25:07 +00:00
}
|> selectList "churchId" (flatGuid m.churchId) [ _required ]
2019-02-18 01:25:07 +00:00
]
]
div [ _class "pt-field-row" ] [ submit [] "save" s.["Save Group"] ]
]
|> List.singleton
|> Layout.Content.standard
|> Layout.standard vi pageTitle
/// View for the member edit page
let editMember (m : EditMember) (typs : (string * LocalizedString) seq) ctx vi =
let s = I18N.localizer.Force ()
let pageTitle = match m.isNew () with true -> "Add a New Group Member" | false -> "Edit Group Member"
form [ _action "/small-group/member/save"; _method "post"; _class "pt-center-columns" ] [
style [ _scoped ] [ rawText "#memberName { width: 15rem; } #emailAddress { width: 20rem; }" ]
csrfToken ctx
input [ _type "hidden"; _name "memberId"; _value (flatGuid m.memberId) ]
2019-02-18 01:25:07 +00:00
div [ _class "pt-field-row" ] [
div [ _class "pt-field" ] [
label [ _for "memberName" ] [ encLocText s.["Member Name"] ]
input [ _type "text"; _name "memberName"; _id "memberName"; _required; _autofocus; _value m.memberName ]
]
div [ _class "pt-field" ] [
label [ _for "emailAddress" ] [ encLocText s.["E-mail Address"] ]
input [ _type "email"; _name "emailAddress"; _id "emailAddress"; _required; _value m.emailAddress ]
]
]
div [ _class "pt-field-row" ] [
div [ _class "pt-field" ] [
label [ _for "emailType" ] [ encLocText s.["E-mail Format"] ]
typs
|> Seq.map (fun typ -> fst typ, (snd typ).Value)
|> selectList "emailType" m.emailType []
]
]
div [ _class "pt-field-row" ] [ submit [] "save" s.["Save"] ]
]
|> List.singleton
|> Layout.Content.standard
|> Layout.standard vi pageTitle
/// View for the small group log on page
let logOn (grps : SmallGroup list) grpId ctx vi =
let s = I18N.localizer.Force ()
[ form [ _action "/small-group/log-on/submit"; _method "post"; _class "pt-center-columns" ] [
csrfToken ctx
div [ _class "pt-field-row" ] [
div [ _class "pt-field" ] [
label [ _for "smallGroupId" ] [ encLocText s.["Group"] ]
seq {
match grps.Length with
| 0 -> yield "", s.["There are no classes with passwords defined"].Value
| _ ->
yield "", selectDefault s.["Select Group"].Value
yield! grps
|> List.map (fun grp -> flatGuid grp.smallGroupId, sprintf "%s | %s" grp.church.name grp.name)
2019-02-18 01:25:07 +00:00
}
|> selectList "smallGroupId" grpId [ _required ]
]
div [ _class "pt-field" ] [
label [ _for "password" ] [ encLocText s.["Password"] ]
input [ _type "password"; _name "password"; _id "password"; _required;
_placeholder (s.["Case-Sensitive"].Value.ToLower ()) ]
]
]
div [ _class "pt-checkbox-field" ] [
input [ _type "checkbox"; _name "rememberMe"; _id "rememberMe"; _value "True" ]
label [ _for "rememberMe" ] [ encLocText s.["Remember Me"] ]
br []
small [] [ em [] [ encodedText (s.["Requires Cookies"].Value.ToLower ()) ] ]
]
div [ _class "pt-field-row" ] [ submit [] "account_circle" s.["Log On"] ]
]
script [] [ rawText "PT.onLoad(PT.smallGroup.logOn.onPageLoad)" ]
]
|> Layout.Content.standard
|> Layout.standard vi "Group Log On"
/// View for the small group maintenance page
let maintain (grps : SmallGroup list) ctx vi =
let s = I18N.localizer.Force ()
[ div [ _class "pt-center-text" ] [
br []
a [ _href (sprintf "/small-group/%s/edit" emptyGuid); _title s.["Add a New Group"].Value ] [
icon "add_circle"
rawText "  "
encLocText s.["Add a New Group"]
]
br []
br []
]
tableSummary grps.Length s
table [ _class "pt-table pt-action-table" ] [
thead [] [
tr [] [
th [] [ encLocText s.["Actions"] ]
th [] [ encLocText s.["Name"] ]
th [] [ encLocText s.["Church"] ]
th [] [ encLocText s.["Time Zone"] ]
]
]
grps
|> List.map (fun g ->
let grpId = flatGuid g.smallGroupId
2019-02-18 01:25:07 +00:00
let delAction = sprintf "/small-group/%s/delete" grpId
let delPrompt = s.["Are you want to delete this {0}? This action cannot be undone.",
sprintf "%s (%s)" (s.["Small Group"].Value.ToLower ()) g.name].Value
tr [] [
td [] [
a [ _href (sprintf "/small-group/%s/edit" grpId); _title s.["Edit This Group"].Value ] [ icon "edit" ]
a [ _href delAction
_title s.["Delete This Group"].Value
_onclick (sprintf "return PT.confirmDelete('%s','%s')" delAction delPrompt) ]
[ icon "delete_forever" ]
]
td [] [ encodedText g.name ]
td [] [ encodedText g.church.name ]
td [] [ encLocText (TimeZones.name g.preferences.timeZoneId s) ]
])
|> tbody []
]
form [ _id "DeleteForm"; _action ""; _method "post" ] [ csrfToken ctx ]
]
|> Layout.Content.standard
|> Layout.standard vi "Maintain Groups"
/// View for the member maintenance page
let members (mbrs : Member list) (emailTyps : Map<string, LocalizedString>) ctx vi =
let s = I18N.localizer.Force ()
[ div [ _class"pt-center-text" ] [
br []
a [ _href (sprintf "/small-group/member/%s/edit" emptyGuid); _title s.["Add a New Group Member"].Value ]
[ icon "add_circle"; rawText " &nbsp;"; encLocText s.["Add a New Group Member"] ]
br []
br []
]
tableSummary mbrs.Length s
table [ _class "pt-table pt-action-table" ] [
thead [] [
tr [] [
th [] [ encLocText s.["Actions"] ]
th [] [ encLocText s.["Name"] ]
th [] [ encLocText s.["E-mail Address"] ]
th [] [ encLocText s.["Format"] ]
]
]
mbrs
|> List.map (fun mbr ->
let mbrId = flatGuid mbr.memberId
2019-02-18 01:25:07 +00:00
let delAction = sprintf "/small-group/member/%s/delete" mbrId
let delPrompt = s.["Are you want to delete this {0} ({1})? This action cannot be undone.",
s.["group member"], mbr.memberName].Value
tr [] [
td [] [
a [ _href (sprintf "/small-group/member/%s/edit" mbrId); _title s.["Edit This Group Member"].Value ]
[ icon "edit" ]
a [ _href delAction
_title s.["Delete This Group Member"].Value
_onclick (sprintf "return PT.confirmDelete('%s','%s')" delAction delPrompt) ]
[ icon "delete_forever" ]
]
td [] [ encodedText mbr.memberName ]
td [] [ encodedText mbr.email ]
td [] [ encLocText emailTyps.[defaultArg mbr.format ""] ]
])
|> tbody []
]
form [ _id "DeleteForm"; _action ""; _method "post" ] [ csrfToken ctx ]
]
|> Layout.Content.standard
|> Layout.standard vi "Maintain Group Members"
/// View for the small group overview page
let overview m vi =
let s = I18N.localizer.Force ()
let linkSpacer = rawText "&nbsp; "
let typs = ReferenceList.requestTypeList s |> Map.ofList
article [ _class "pt-overview" ] [
section [] [
header [ _role "heading" ] [
iconSized 72 "bookmark_border"
encLocText s.["Quick Actions"]
]
div [] [
a [ _href "/prayer-requests/view" ] [ icon "list"; linkSpacer; encLocText s.["View Prayer Request List"] ]
hr []
a [ _href "/small-group/announcement" ] [ icon "send"; linkSpacer; encLocText s.["Send Announcement"] ]
hr []
a [ _href "/small-group/preferences" ] [ icon "build"; linkSpacer; encLocText s.["Change Preferences"] ]
]
]
section [] [
header [ _role "heading" ] [
iconSized 72 "question_answer"
encLocText s.["Prayer Requests"]
]
div [] [
yield p [ _class "pt-center-text" ] [
strong [] [ encodedText (m.totalActiveReqs.ToString "N0"); space; encLocText s.["Active Requests"] ]
]
yield hr []
for cat in m.activeReqsByCat do
yield encodedText (cat.Value.ToString "N0")
yield space
yield encLocText typs.[cat.Key]
yield br []
yield br []
yield encodedText (m.allReqs.ToString "N0")
yield space
yield encLocText s.["Total Requests"]
yield hr []
yield a [ _href "/prayer-requests/maintain" ] [
icon "compare_arrows"
linkSpacer
encLocText s.["Maintain Prayer Requests"]
]
]
]
section [] [
header [ _role "heading" ] [
iconSized 72 "people_outline"
encLocText s.["Group Members"]
]
div [ _class "pt-center-text" ] [
strong [] [ encodedText (m.totalMbrs.ToString "N0"); space; encLocText s.["Members"] ]
hr []
a [ _href "/small-group/members" ] [ icon "email"; linkSpacer; encLocText s.["Maintain Group Members"] ]
]
]
]
|> List.singleton
|> Layout.Content.wide
|> Layout.standard vi "Small Group Overview"
/// View for the small group preferences page
let preferences (m : EditPreferences) (tzs : TimeZone list) ctx vi =
let s = I18N.localizer.Force ()
let l = I18N.forView "SmallGroup/Preferences"
use sw = new StringWriter ()
let raw = rawLocText sw
[ form [ _action "/small-group/preferences/save"; _method "post"; _class "pt-center-columns" ] [
style [ _scoped ] [ rawText "#expireDays, #daysToKeepNew, #longTermUpdateWeeks, #headingFontSize, #listFontSize { width: 3rem; } #emailFromAddress { width: 20rem; } #listFonts { width: 40rem; } @media screen and (max-width: 40rem) { #listFonts { width: 100%; } }" ]
csrfToken ctx
fieldset [] [
legend [] [ strong [] [ icon "date_range"; rawText " &nbsp;"; encLocText s.["Dates"] ] ]
div [ _class "pt-field-row" ] [
div [ _class "pt-field" ] [
label [ _for "expireDays" ] [ encLocText s.["Requests Expire After"] ]
span [] [
input [ _type "number"; _name "expireDays"; _id "expireDays"; _min "1"; _max "30"; _required; _autofocus
_value (string m.expireDays) ]
space; encodedText (s.["Days"].Value.ToLower ())
]
]
div [ _class "pt-field" ] [
label [ _for "daysToKeepNew" ] [ encLocText s.["Requests “New” For"] ]
span [] [
input [ _type "number"; _name "daysToKeepNew"; _id "daysToKeepNew"; _min "1"; _max "30"; _required
_value (string m.daysToKeepNew) ]
space; encodedText (s.["Days"].Value.ToLower ())
]
]
div [ _class "pt-field" ] [
label [ _for "longTermUpdateWeeks" ] [ encLocText s.["Long-Term Requests Alerted for Update"] ]
span [] [
input [ _type "number"; _name "longTermUpdateWeeks"; _id "longTermUpdateWeeks"; _min "1"; _max "30"
_required; _value (string m.longTermUpdateWeeks) ]
space; encodedText (s.["Weeks"].Value.ToLower ())
]
]
]
]
fieldset [] [
legend [] [ strong [] [ icon "sort"; rawText " &nbsp;"; encLocText s.["Request Sorting"] ] ]
radio "requestSort" "requestSort_D" "D" m.requestSort
label [ _for "requestSort_D" ] [ encLocText s.["Sort by Last Updated Date"] ]
rawText " &nbsp; "
radio "requestSort" "requestSort_R" "R" m.requestSort
label [ _for "requestSort_R" ] [ encLocText s.["Sort by Requestor Name"] ]
]
fieldset [] [
legend [] [ strong [] [ icon "mail_outline"; rawText " &nbsp;"; encLocText s.["E-mail"] ] ]
div [ _class "pt-field-row" ] [
div [ _class "pt-field" ] [
label [ _for "emailFromName" ] [ encLocText s.["From Name"] ]
input [ _type "text"; _name "emailFromName"; _id "emailFromName"; _required; _value m.emailFromName ]
]
div [ _class "pt-field" ] [
label [ _for "emailFromAddress" ] [ encLocText s.["From Address"] ]
input [ _type "email"; _name "emailFromAddress"; _id "emailFromAddress"; _required
_value m.emailFromAddress ]
]
]
div [ _class "pt-field-row" ] [
div [ _class "pt-field" ] [
label [ _for "defaultEmailType" ] [ encLocText s.["E-mail Format"] ]
seq {
yield "", selectDefault s.["Select"].Value
yield! ReferenceList.emailTypeList "" s |> Seq.skip 1 |> Seq.map (fun typ -> fst typ, (snd typ).Value)
}
|> selectList "defaultEmailType" m.defaultEmailType [ _required ]
]
]
]
fieldset [] [
legend [] [ strong [] [ icon "color_lens"; rawText " &nbsp;"; encLocText s.["Colors"] ]; rawText " ***" ]
div [ _class "pt-field-row" ] [
div [ _class "pt-field" ] [
label [ _class "pt-center-text" ] [ encLocText s.["Color of Heading Lines"] ]
span [] [
radio "headingLineType" "headingLineType_Name" "Name" m.headingLineType
label [ _for "headingLineType_Name" ] [ encLocText s.["Named Color"] ]
namedColorList "headingLineColor" m.headingLineColor
[ yield _id "headingLineColor_Select"
match m.headingLineColor.StartsWith "#" with true -> yield _disabled | false -> () ] s
rawText "&nbsp; &nbsp; "; encodedText (s.["or"].Value.ToUpper ())
radio "headingLineType" "headingLineType_RGB" "RGB" m.headingLineType
label [ _for "headingLineType_RGB" ] [ encLocText s.["Custom Color"] ]
input [ yield _type "color"
yield _name "headingLineColor"
yield _id "headingLineColor_Color"
yield _value m.headingLineColor
match m.headingLineColor.StartsWith "#" with true -> () | false -> yield _disabled ]
]
]
]
div [ _class "pt-field-row" ] [
div [ _class "pt-field" ] [
label [ _class "pt-center-text" ] [ encLocText s.["Color of Heading Text"] ]
span [] [
radio "headingTextType" "headingTextType_Name" "Name" m.headingTextType
label [ _for "headingTextType_Name" ] [ encLocText s.["Named Color"] ]
namedColorList "headingTextColor" m.headingTextColor
[ yield _id "headingTextColor_Select"
match m.headingTextColor.StartsWith "#" with true -> yield _disabled | false -> () ] s
rawText "&nbsp; &nbsp; "; encodedText (s.["or"].Value.ToUpper ())
radio "headingTextType" "headingTextType_RGB" "RGB" m.headingTextType
label [ _for "headingTextType_RGB" ] [ encLocText s.["Custom Color"] ]
input [ yield _type "color"
yield _name "headingTextColor"
yield _id "headingTextColor_Color"
yield _value m.headingTextColor
match m.headingTextColor.StartsWith "#" with true -> () | false -> yield _disabled ]
]
]
]
]
fieldset [] [
legend [] [ strong [] [ icon "font_download"; rawText " &nbsp;"; encLocText s.["Fonts"] ] ]
div [ _class "pt-field" ] [
label [ _for "listFonts" ] [ encLocText s.["Fonts** for List"] ]
input [ _type "text"; _name "listFonts"; _id "listFonts"; _required; _value m.listFonts ]
]
div [ _class "pt-field-row" ] [
div [ _class "pt-field" ] [
label [ _for "headingFontSize" ] [ encLocText s.["Heading Text Size"] ]
input [ _type "number"; _name "headingFontSize"; _id "headingFontSize"; _min "8"; _max "24"; _required
_value (string m.headingFontSize) ]
]
div [ _class "pt-field" ] [
label [ _for "listFontSize" ] [ encLocText s.["List Text Size"] ]
input [ _type "number"; _name "listFontSize"; _id "listFontSize"; _min "8"; _max "24"; _required
_value (string m.listFontSize) ]
]
]
]
fieldset [] [
legend [] [ strong [] [ icon "settings"; rawText " &nbsp;"; encLocText s.["Other Settings"] ] ]
div [ _class "pt-field-row" ] [
div [ _class "pt-field" ] [
label [ _for "TimeZone" ] [ encLocText s.["Time Zone"] ]
seq {
yield "", selectDefault s.["Select"].Value
yield! tzs |> List.map (fun tz -> tz.timeZoneId, (TimeZones.name tz.timeZoneId s).Value)
}
|> selectList "timeZone" m.timeZone [ _required ]
]
]
div [ _class "pt-field" ] [
label [] [ encLocText s.["Request List Visibility"] ]
span [] [
radio "listVisibility" "viz_Public" (string RequestVisibility.``public``) (string m.listVisibility)
label [ _for "viz_Public" ] [ encLocText s.["Public"] ]
rawText " &nbsp;"
radio "listVisibility" "viz_Private" (string RequestVisibility.``private``) (string m.listVisibility)
label [ _for "viz_Private" ] [ encLocText s.["Private"] ]
rawText " &nbsp;"
radio "listVisibility" "viz_Password" (string RequestVisibility.passwordProtected) (string m.listVisibility)
label [ _for "viz_Password" ] [ encLocText s.["Password Protected"] ]
]
]
div [ yield _id "divClassPassword"
match m.listVisibility = RequestVisibility.passwordProtected with
| true -> yield _class "pt-field-row pt-fadeable pt-show"
| false -> yield _class "pt-field-row pt-fadeable"
] [
div [ _class "pt-field" ] [
label [ _for "groupPassword" ] [ encLocText s.["Group Password (Used to Read Online)"] ]
input [ _type "text"; _name "groupPassword"; _id "groupPassword";
_value (match m.groupPassword with Some x -> x | None -> "") ]
]
]
div [ _class "pt-field-row" ] [ submit [] "save" s.["Save Preferences"] ]
]
]
p [] [
rawText "** "
raw l.["List font names, separated by commas."]
space
raw l.["The first font that is matched is the one that is used."]
space
raw l.["Ending with either “serif” or “sans-serif” will cause the user's browser to use the default “serif” font (“Times New Roman” on Windows) or “sans-serif” font (“Arial” on Windows) if no other fonts in the list are found."]
]
p [] [
rawText "*** "
raw l.["If you want a custom color, you may be able to get some ideas (and a list of RGB values for those colors) from the W3 School's <a href=\"http://www.w3schools.com/html/html_colornames.asp\" title=\"HTML Color List - W3 School\">HTML color name list</a>."]
]
script [] [ rawText "PT.onLoad(PT.smallGroup.preferences.onPageLoad)" ]
]
|> Layout.Content.standard
|> Layout.standard vi "Group Preferences"