bsw@1045: local return_to = param.get("return_to")
bsw@1250: local return_to_area_id param.get("return_to_area_id", atom.integer)
bsw@1045: 
bsw@1126: ui.titleMember(_"notification settings")
bsw@286: 
bsw@1045: execute.view {
bsw@1045:   module = "member", view = "_sidebar_whatcanido", params = {
bsw@1045:     member = app.session.member
bsw@1045:   }
bsw@1045: }
bsw@286: 
bsw@286: ui.form{
bsw@286:   attr = { class = "vertical" },
bsw@286:   module = "member",
bsw@348:   action = "update_notify_level",
bsw@286:   routing = {
bsw@286:     ok = {
bsw@286:       mode = "redirect",
bsw@1250:       module = return_to == "area" and "area" or return_to == "home" and "index" or "member",
bsw@1250:       view = return_to == "area" and "show" or return_to == "home" and "index" or "show",
bsw@1250:       id = return_to == "area" and return_to_area_id or return_to ~= "home" and app.session.member_id or nil
bsw@286:     }
bsw@286:   },
bsw@286:   content = function()
bsw@1045: 
bsw@1045:     ui.section( function()
bsw@1045: 
bsw@1045:       ui.sectionHead( function()
bsw@1250:         ui.heading { level = 1, content = _"Do you like to receive updates by email?" }
bsw@1045:       end )
bsw@1045: 
bsw@474:     
bsw@1045:       ui.sectionRow( function()
bsw@1045:       
bsw@1045:         ui.container{ content = function()
bsw@1045:           ui.tag{
bsw@1045:             tag = "input", 
bsw@1045:             attr = {
bsw@1045:               id = "notify_level_all",
bsw@1248:               type = "radio", name = "disable_notifications", value = "false",
bsw@1248:               checked = not app.session.member.disable_notifications and "checked" or nil
bsw@1281:               onchange = [[ $(".view_on_notify_level_all_false")[this.checked ? "show" : "hide"](400) ]]
bsw@1045:             }
bsw@1045:           }
bsw@1045:           ui.tag{
bsw@1045:             tag = "label", attr = { ['for'] = "notify_level_all" },
bsw@1045:             content = _"I like to receive notifications"
bsw@1045:           }
bsw@1045:         end }
bsw@1045:         
bsw@1045:         slot.put("
")
bsw@1255:         
bsw@1281:         ui.container{ attr = { class = "view_on_notify_level_all_false", style = "margin-left: 3em;" }, content = function()
bsw@1277:         
bsw@1277:           ui.container{ content = _"You will receive status update notification on issue phase changes. Additionally you can subscribe for a regular digest including updates on initiative drafts and new suggestions." }
bsw@1279:           slot.put("
")
bsw@1261:           ui.container{ content = function()
bsw@1261:             ui.tag{
bsw@1261:               tag = "input", 
bsw@1261:               attr = {
bsw@1261:                 id = "digest_on",
bsw@1261:                 type = "radio", name = "digest", value = "true",
bsw@1266:                 checked = app.session.member.notification_hour ~= nil and "checked" or nil
bsw@1281:                 onchange = [[ $(".view_on_digest_true")[this.checked ? "show" : "hide"](400) ]]
bsw@1261:               }
bsw@1261:             }
bsw@1261:             ui.tag{
bsw@1261:               tag = "label", attr = { ['for'] = "digest_on" },
bsw@1277:               content = _"I want to receive a regular digest. Send the digest at:"
bsw@1261:             }
bsw@1262:           end }
bsw@1261:             
bsw@1281:           ui.container{ attr = { class = "view_on_digest_true", style = "margin-left: 4em;" }, content = function()
bsw@1261:             ui.tag{ content = _"Day:" }
bsw@1261:             slot.put(" ")
bsw@1261:             ui.field.select{
bsw@1273:               container_attr = { style = "display: inline-block; vertical-align: middle;" },
bsw@1274:               attr = { style = "width: 10em;" },
bsw@1261:               name = "notification_dow",
bsw@1261:               foreign_records = {
bsw@1261:                 { id = "daily", name = _"daily" },
bsw@1271:                 { id = 0, name = _"Sunday" },
bsw@1271:                 { id = 1, name = _"Monday" },
bsw@1271:                 { id = 2, name = _"Tuesday" },
bsw@1271:                 { id = 3, name = _"Wednesday" },
bsw@1271:                 { id = 4, name = _"Thursday" },
bsw@1271:                 { id = 5, name = _"Friday" },
bsw@1271:                 { id = 6, name = _"Saturday" }
bsw@1261:               },
bsw@1261:               foreign_id = "id",
bsw@1272:               foreign_name = "name",
bsw@1272:               value = app.session.member.notification_dow
bsw@1255:             }
bsw@1261:             
bsw@1261:             slot.put(" ")
bsw@1261: 
bsw@1261:             ui.tag{ content = _"Hour:" }
bsw@1261:             slot.put(" ")
bsw@1261:             local foreign_records = {}
bsw@1261:             for i = 0, 23 do
bsw@1261:               foreign_records[#foreign_records+1] = {
bsw@1261:                 id = i,
bsw@1277:                 name = string.format("%02d:00 - %02d:59", i, i),
bsw@1261:               }
bsw@1261:             end
bsw@1261:             ui.field.select{
bsw@1273:               container_attr = { style = "display: inline-block; vertical-align: middle;" },
bsw@1280:               attr = { style = "width: 10em;" },
bsw@1261:               name = "notification_hour",
bsw@1261:               foreign_records = foreign_records,
bsw@1261:               foreign_id = "id",
bsw@1268:               foreign_name = "name",
bsw@1272:               value = app.session.member.notification_hour
bsw@1261:             }
bsw@1261:           end }
bsw@1261:           
bsw@1261:           ui.container{ content = function()
bsw@1261:             ui.tag{
bsw@1261:               tag = "input", 
bsw@1261:               attr = {
bsw@1261:                 id = "digest_off",
bsw@1261:                 type = "radio", name = "digest", value = "false",
bsw@1276:                 checked = app.session.member.notification_dow == nil and app.session.member.notification_hour == nil and "checked" or nil
bsw@1281:                 onchange = [[ $(".view_on_digest_true")[this.checked ? "hide" : "show"](400) ]]
bsw@1261:               }
bsw@1261:             }
bsw@1261:             ui.tag{
bsw@1261:               tag = "label", attr = { ['for'] = "digest_off" },
bsw@1279:               content = _"Don't send me a digest"
bsw@1261:             }
bsw@1261:           end }
bsw@1255:         end }
bsw@1255:         
bsw@1263:         slot.put("
")
bsw@1255:         
bsw@1045:         ui.container{ content = function()
bsw@1045:           ui.tag{
bsw@1045:             tag = "input", 
bsw@1045:             attr = {
bsw@1045:               id = "notify_level_none",
bsw@1248:               type = "radio", name = "disable_notifications", value = "true",
bsw@1281:               checked = app.session.member.disable_notifications and "checked" or nil,
bsw@1281:               onchange = [[ $(".view_on_notify_level_all_false")[this.checked ? "hide" : "show"](400) ]]
bsw@1045:             }
bsw@1045:           }
bsw@1045:           ui.tag{
bsw@1045:             tag = "label", attr = { ['for'] = "notify_level_none" },
bsw@1279:             content = _"Don't send me notifications by email"
bsw@1045:           }
bsw@1045:         end }
bsw@1045:         
bsw@1045:         slot.put("
")
bsw@1045:       
bsw@1045:         ui.tag{
bsw@1045:           tag = "input",
bsw@1045:           attr = {
bsw@1045:             type = "submit",
bsw@1045:             class = "btn btn-default",
bsw@1045:             value = _"Save"
bsw@1045:           },
bsw@1045:           content = ""
bsw@348:         }
bsw@1045:         slot.put("
")
bsw@1045:         
bsw@1045:         slot.put(" ")
bsw@1045:         if return_to == "home" then
bsw@1045:           ui.link {
bsw@1045:             module = "index", view = "index",
bsw@1045:             content = _"cancel"
bsw@1045:           }
bsw@1045:         else
bsw@1045:           ui.link {
bsw@1045:             module = "member", view = "show", id = app.session.member_id, 
bsw@1045:             content = _"cancel"
bsw@1045:           }
bsw@1045:         end
bsw@1045:       end ) 
bsw@1045:     end )
bsw@474:     
bsw@286:   end
bsw@286: }
bsw@287: