bsw/jbe@0: local initiative = Initiative:new_selector():add_where{ "id = ?", param.get_id()}:single_object_mode():exec()
bsw/jbe@0: 
bsw/jbe@5: slot.select("actions", function()
bsw/jbe@5:   ui.link{
bsw/jbe@5:     content = function()
bsw/jbe@5:       ui.image{ static = "icons/16/script.png" }
bsw/jbe@5:       slot.put(_"Show all initiatives")
bsw/jbe@5:     end,
bsw/jbe@5:     module = "issue",
bsw/jbe@5:     view = "show",
bsw/jbe@5:     id = initiative.issue.id
bsw/jbe@5:   }
bsw/jbe@5: end)
bsw/jbe@4: 
bsw/jbe@4: execute.view{
bsw/jbe@4:   module = "issue",
bsw/jbe@4:   view = "_show_head",
bsw/jbe@4:   params = { issue = initiative.issue }
bsw/jbe@4: }
bsw/jbe@4: 
bsw/jbe@4: local initiator = Initiator:by_pk(initiative.id, app.session.member.id)
bsw/jbe@4: 
bsw@3: --slot.put_into("html_head", '')
bsw/jbe@0: 
bsw/jbe@0: execute.view{
bsw/jbe@0:   module = "supporter",
bsw/jbe@0:   view = "_show_box",
bsw/jbe@0:   params = { initiative = initiative }
bsw/jbe@0: }
bsw/jbe@0: 
bsw/jbe@4: slot.put_into("sub_title", encode.html(_"Initiative: '#{name}'":gsub("#{name}", initiative.shortened_name) ))
bsw/jbe@0: 
bsw/jbe@0: slot.select("actions", function()
bsw/jbe@4:   if not initiative.issue.fully_frozen and not initiative.issue.closed then
bsw@2:     ui.link{
bsw@3:       attr = { class = "action" },
bsw@3:       content = function()
bsw@3:         ui.image{ static = "icons/16/script_add.png" }
bsw/jbe@4:         slot.put(_"Create alternative initiative")
bsw@3:       end,
bsw@3:       module = "initiative",
bsw@3:       view = "new",
bsw@3:       params = { issue_id = initiative.issue.id }
bsw@3:     }
bsw@3:   end
bsw/jbe@4: end)
bsw/jbe@4: 
bsw/jbe@4: 
bsw/jbe@4: util.help("initiative.show")
bsw/jbe@4: 
bsw/jbe@4: 
bsw/jbe@4: ui.container{
bsw/jbe@4:   attr = { class = "vertical" },
bsw/jbe@4:   content = function()
bsw/jbe@4:     ui.container{
bsw/jbe@4:       attr = { class = "ui_field_label" },
bsw/jbe@4:       content = _"Discussion URL"
bsw/jbe@4:     }
bsw/jbe@4:     ui.tag{
bsw/jbe@4:       tag = "span",
bsw@3:       content = function()
bsw/jbe@4:         if initiative.discussion_url and #initiative.discussion_url > 0 then
bsw/jbe@4:           ui.link{
bsw/jbe@4:             attr = {
bsw/jbe@4:               class = "actions",
bsw/jbe@5:               target = "_blank",
bsw/jbe@4:               title = initiative.discussion_url
bsw/jbe@4:             },
bsw/jbe@4:             content = function()
bsw/jbe@4:               slot.put(encode.html(initiative.discussion_url))
bsw/jbe@4:             end,
bsw/jbe@4:             external = initiative.discussion_url
bsw/jbe@4:           }
bsw/jbe@4:         end
bsw/jbe@4:         slot.put(" ")
bsw/jbe@4:         if initiator then
bsw/jbe@4:           ui.link{
bsw/jbe@4:             attr = { class = "actions" },
bsw/jbe@4:             content = _"(change URL)",
bsw/jbe@4:             module = "initiative",
bsw/jbe@4:             view = "edit",
bsw/jbe@4:             id = initiative.id
bsw/jbe@4:           }
bsw/jbe@4:         end
bsw/jbe@4:       end
bsw@3:     }
bsw@3:   end
bsw/jbe@4: }
bsw/jbe@4: 
bsw/jbe@0: 
bsw/jbe@0: 
bsw/jbe@0: ui.container{
bsw/jbe@0:   attr = {  id = "add_suggestion_form", class = "hidden_inline_form" },
bsw/jbe@0:   content = function()
bsw/jbe@0: 
bsw/jbe@0:     ui.link{
bsw/jbe@0:       content = _"Close",
bsw/jbe@0:       attr = {
bsw/jbe@0:         onclick = "document.getElementById('add_suggestion_form').style.display='none';return(false)",
bsw/jbe@0:         style = "float: right;"
bsw/jbe@0:       }
bsw/jbe@0:     }
bsw/jbe@0: 
bsw/jbe@0:     ui.field.text{ attr = { class = "head" }, value = _"Add new suggestion" }
bsw/jbe@0: 
bsw/jbe@0: 
bsw/jbe@0:     ui.form{
bsw/jbe@0:       module = "suggestion",
bsw/jbe@0:       action = "add",
bsw/jbe@0:       params = { initiative_id = initiative.id },
bsw/jbe@0:       routing = {
bsw/jbe@0:         default = {
bsw/jbe@0:           mode = "redirect",
bsw/jbe@0:           module = "initiative",
bsw/jbe@0:           view = "show",
bsw/jbe@0:           id = initiative.id,
bsw/jbe@0:           params = { tab = "suggestion" }
bsw/jbe@0:         }
bsw/jbe@0:       },
bsw/jbe@0:       attr = { class = "vertical" },
bsw/jbe@0:       content = function()
bsw/jbe@4:         local supported = Supporter:by_pk(initiative.id, app.session.member.id) and true or false
bsw/jbe@4:         if not supported then
bsw/jbe@4:           ui.field.text{
bsw/jbe@4:             attr = { class = "warning" },
bsw/jbe@4:             value = _"You are currently not supporting this initiative. By adding suggestions to this initiative you will automatically become a potential supporter."
bsw/jbe@4:           }
bsw/jbe@4:         end
bsw/jbe@4:         ui.field.text{ label = _"Title (80 chars max)",        name = "name" }
bsw/jbe@0:         ui.field.text{ label = _"Description", name = "description", multiline = true }
bsw/jbe@0:         ui.field.select{ 
bsw/jbe@0:           label = _"Degree", 
bsw/jbe@0:           name = "degree",
bsw/jbe@0:           foreign_records = { 
bsw/jbe@0:             { id =  1, name = _"should"},
bsw/jbe@0:             { id =  2, name = _"must"},
bsw/jbe@0:           },
bsw/jbe@0:           foreign_id = "id",
bsw/jbe@0:           foreign_name = "name"
bsw/jbe@0:         }
bsw/jbe@0:         ui.submit{ text = _"Commit suggestion" }
bsw/jbe@0:       end
bsw/jbe@0:     }
bsw/jbe@0:   end
bsw/jbe@0: }
bsw/jbe@0: 
bsw@2: local supporter = app.session.member:get_reference_selector("supporters")
bsw@2:   :add_where{ "initiative_id = ?", initiative.id }
bsw@2:   :optional_object_mode()
bsw@2:   :exec()
bsw@2: 
bsw@2: if supporter then
bsw@2:   local old_draft_id = supporter.draft_id
bsw@2:   local new_draft_id = initiative.current_draft.id
bsw@2:   if old_draft_id ~= new_draft_id then
bsw@2:     ui.container{
bsw@2:       attr = { class = "draft_updated_info" },
bsw@2:       content = function()
bsw@2:         slot.put("The draft of this initiative has been updated!")
bsw@2:         slot.put(" ")
bsw@2:         ui.link{
bsw@2:           content = _"Show diff",
bsw@2:           module = "draft",
bsw@2:           view = "diff",
bsw@2:           params = {
bsw@2:             old_draft_id = old_draft_id,
bsw@2:             new_draft_id = new_draft_id
bsw@2:           }
bsw@2:         }
bsw@2:         slot.put(" ")
bsw@2:         ui.link{
bsw@2:           content = _"Refresh support to current draft",
bsw@2:           module = "initiative",
bsw@2:           action = "add_support",
bsw@2:           id = initiative.id,
bsw@2:           routing = {
bsw@2:             default = {
bsw@2:               mode = "redirect",
bsw@2:               module = "initiative",
bsw@2:               view = "show",
bsw@2:               id = initiative.id
bsw@2:             }
bsw@2:           }
bsw@2:         }
bsw@2:       end
bsw@2:     }
bsw@2:   end
bsw@2: end
bsw/jbe@0: 
bsw/jbe@4: 
bsw/jbe@0: ui.tabs{
bsw/jbe@0:   {
bsw/jbe@0:     name = "current_draft",
bsw/jbe@0:     label = _"Current draft",
bsw/jbe@0:     content = function()
bsw/jbe@4:       if initiator then
bsw/jbe@4:         ui.link{
bsw/jbe@4:           content = function()
bsw/jbe@4:             ui.image{ static = "icons/16/script_add.png" }
bsw/jbe@4:             slot.put(_"Edit draft")
bsw/jbe@4:           end,
bsw/jbe@4:           module = "draft",
bsw/jbe@4:           view = "new",
bsw/jbe@4:           params = { initiative_id = initiative.id }
bsw/jbe@4:         }
bsw/jbe@4:       end
bsw/jbe@0:       execute.view{ module = "draft", view = "_show", params = { draft = initiative.current_draft } }
bsw/jbe@0:     end
bsw/jbe@0:   },
bsw/jbe@0:   {
bsw/jbe@0:     name = "suggestion",
bsw/jbe@0:     label = _"Suggestions",
bsw/jbe@0:     content = function()
bsw/jbe@4:       execute.view{
bsw/jbe@4:         module = "suggestion",
bsw/jbe@4:         view = "_list",
bsw/jbe@4:         params = {
bsw/jbe@4:           initiative = initiative,
bsw/jbe@4:           suggestions_selector = initiative:get_reference_selector("suggestions")
bsw/jbe@4:         }
bsw/jbe@4:       }
bsw/jbe@0:       slot.put("
")
bsw/jbe@5:       if not initiative.issue.fully_frozen and not initiative.issue.closed then
bsw/jbe@0:         ui.link{
bsw/jbe@0:           content = function()
bsw/jbe@0:             ui.image{ static = "icons/16/comment_add.png" }
bsw/jbe@0:             slot.put(_"Add new suggestion")
bsw/jbe@0:           end,
bsw/jbe@0:           attr = { onclick = "document.getElementById('add_suggestion_form').style.display='block';return(false)" },
bsw/jbe@0:           static = "#"
bsw/jbe@0:         }
bsw/jbe@0:       end
bsw/jbe@0:     end
bsw/jbe@0:   },
bsw/jbe@0:   {
bsw/jbe@5:     name = "satisfied_supporter",
bsw/jbe@0:     label = _"Supporter",
bsw/jbe@0:     content = function()
bsw@3:       execute.view{
bsw@3:         module = "member",
bsw@3:         view = "_list",
bsw@3:         params = {
bsw@3:           initiative = initiative,
bsw@3:           members_selector =  initiative:get_reference_selector("supporting_members_snapshot")
bsw@3:             :join("issue", nil, "issue.id = direct_supporter_snapshot.issue_id")
bsw/jbe@4:             :join("direct_interest_snapshot", nil, "direct_interest_snapshot.event = issue.latest_snapshot_event AND direct_interest_snapshot.issue_id = issue.id AND direct_interest_snapshot.member_id = member.id")
bsw/jbe@4:             :add_field("direct_interest_snapshot.weight")
bsw@3:             :add_where("direct_supporter_snapshot.event = issue.latest_snapshot_event")
bsw/jbe@5:             :add_where("direct_supporter_snapshot.satisfied")
bsw/jbe@5:         }
bsw/jbe@5:       }
bsw/jbe@5:     end
bsw/jbe@5:   },
bsw/jbe@5:   {
bsw/jbe@5:     name = "supporter",
bsw/jbe@5:     label = _"Potential supporter",
bsw/jbe@5:     content = function()
bsw/jbe@5:       execute.view{
bsw/jbe@5:         module = "member",
bsw/jbe@5:         view = "_list",
bsw/jbe@5:         params = {
bsw/jbe@5:           initiative = initiative,
bsw/jbe@5:           members_selector =  initiative:get_reference_selector("supporting_members_snapshot")
bsw/jbe@5:             :join("issue", nil, "issue.id = direct_supporter_snapshot.issue_id")
bsw/jbe@5:             :join("direct_interest_snapshot", nil, "direct_interest_snapshot.event = issue.latest_snapshot_event AND direct_interest_snapshot.issue_id = issue.id AND direct_interest_snapshot.member_id = member.id")
bsw/jbe@5:             :add_field("direct_interest_snapshot.weight")
bsw/jbe@5:             :add_where("direct_supporter_snapshot.event = issue.latest_snapshot_event")
bsw/jbe@5:             :add_where("NOT direct_supporter_snapshot.satisfied")
bsw@3:         }
bsw@3:       }
bsw/jbe@0:     end
bsw/jbe@0:   },
bsw/jbe@0:   {
bsw/jbe@0:     name = "initiators",
bsw/jbe@0:     label = _"Initiators",
bsw/jbe@0:     content = function()
bsw/jbe@0:       execute.view{ module = "member", view = "_list", params = { members_selector = initiative:get_reference_selector("initiating_members") } }
bsw/jbe@0:     end
bsw/jbe@0:   },
bsw/jbe@0:   {
bsw/jbe@0:     name = "drafts",
bsw/jbe@0:     label = _"Old drafts",
bsw/jbe@0:     content = function()
bsw/jbe@0:       execute.view{ module = "draft", view = "_list", params = { drafts = initiative.drafts } }
bsw/jbe@0:     end
bsw/jbe@0:   },
bsw@2:   {
bsw@2:     name = "details",
bsw@2:     label = _"Details",
bsw@2:     content = function()
bsw@2:       ui.form{
bsw@2:         attr = { class = "vertical" },
bsw@2:         record = initiative,
bsw@2:         readonly = true,
bsw@2:         content = function()
bsw@2:           ui.field.text{ label = _"Issue policy", value = initiative.issue.policy.name }
bsw@2:           ui.field.text{
bsw@2:             label = _"Created at",
bsw@2:             value = tostring(initiative.created)
bsw@2:           }
bsw@2:           ui.field.text{
bsw@2:             label = _"Created at",
bsw@2:             value = format.timestamp(initiative.created)
bsw@2:           }
bsw@2:           ui.field.date{ label = _"Revoked at", name = "revoked" }
bsw@2:           ui.field.boolean{ label = _"Admitted", name = "admitted" }
bsw@2:         end
bsw@2:       }
bsw@2:     end
bsw@2:   },
bsw/jbe@0: }
bsw/jbe@0: 
bsw/jbe@0: