liquid_feedback_frontend
view app/main/initiative/show.lua @ 4:80c215dbf076
Version alpha5
Many optical changes and improved usability
Support for different wiki-formatting-engines
Help system
Many optical changes and improved usability
Support for different wiki-formatting-engines
Help system
| author | bsw/jbe | 
|---|---|
| date | Thu Dec 10 12:00:00 2009 +0100 (2009-12-10) | 
| parents | 768faea1096d | 
| children | afd9f769c7ae | 
 line source
     1 local initiative = Initiative:new_selector():add_where{ "id = ?", param.get_id()}:single_object_mode():exec()
     5 execute.view{
     6   module = "issue",
     7   view = "_show_head",
     8   params = { issue = initiative.issue }
     9 }
    11 local initiator = Initiator:by_pk(initiative.id, app.session.member.id)
    13 --slot.put_into("html_head", '<link rel="alternate" type="application/rss+xml" title="RSS" href="../show/' .. tostring(initiative.id) .. '.rss" />')
    15 execute.view{
    16   module = "supporter",
    17   view = "_show_box",
    18   params = { initiative = initiative }
    19 }
    21 --[[
    23 execute.view{
    24   module = "delegation",
    25   view = "_show_box",
    26   params = { issue_id = initiative.issue_id }
    27 }
    29 execute.view{
    30   module = "issue",
    31   view = "_show_box",
    32   params = { issue = initiative.issue }
    33 }
    36 slot.select("path", function()
    37   ui.link{
    38     content = _"Area '#{name}'":gsub("#{name}", initiative.issue.area.name),
    39     module = "area",
    40     view = "show",
    41     id = initiative.issue.area.id
    42   }
    43   ui.container{ content = "::" }
    44   ui.link{
    45     content = _"Issue ##{id}":gsub("#{id}", initiative.issue.id),
    46     module = "issue",
    47     view = "show",
    48     id = initiative.issue.id
    49   }
    50 end)
    52 slot.put_into("title", encode.html(_"Initiative: '#{name}'":gsub("#{name}", initiative.shortened_name) ))
    53 --]]
    55 slot.put_into("sub_title", encode.html(_"Initiative: '#{name}'":gsub("#{name}", initiative.shortened_name) ))
    57 slot.select("actions", function()
    59   if not initiative.issue.fully_frozen and not initiative.issue.closed then
    60     ui.link{
    61       content = function()
    62         ui.image{ static = "icons/16/script.png" }
    63         slot.put(_"Show other initiatives")
    64       end,
    65       module = "issue",
    66       view = "show",
    67       id = initiative.issue.id
    68     }
    69     ui.link{
    70       attr = { class = "action" },
    71       content = function()
    72         ui.image{ static = "icons/16/script_add.png" }
    73         slot.put(_"Create alternative initiative")
    74       end,
    75       module = "initiative",
    76       view = "new",
    77       params = { issue_id = initiative.issue.id }
    78     }
    79   end
    80 --  ui.twitter("http://example.com/i" .. tostring(initiative.id) .. " " .. initiative.name)
    82 end)
    85 util.help("initiative.show")
    88 ui.container{
    89   attr = { class = "vertical" },
    90   content = function()
    91     ui.container{
    92       attr = { class = "ui_field_label" },
    93       content = _"Discussion URL"
    94     }
    95     ui.tag{
    96       tag = "span",
    97       content = function()
    98         if initiative.discussion_url and #initiative.discussion_url > 0 then
    99           ui.link{
   100             attr = {
   101               class = "actions",
   102               target = _"blank",
   103               title = initiative.discussion_url
   104             },
   105             content = function()
   106               slot.put(encode.html(initiative.discussion_url))
   107             end,
   108             external = initiative.discussion_url
   109           }
   110         end
   111         slot.put(" ")
   112         if initiator then
   113           ui.link{
   114             attr = { class = "actions" },
   115             content = _"(change URL)",
   116             module = "initiative",
   117             view = "edit",
   118             id = initiative.id
   119           }
   120         end
   121       end
   122     }
   123   end
   124 }
   128 ui.container{
   129   attr = {  id = "add_suggestion_form", class = "hidden_inline_form" },
   130   content = function()
   132     ui.link{
   133       content = _"Close",
   134       attr = {
   135         onclick = "document.getElementById('add_suggestion_form').style.display='none';return(false)",
   136         style = "float: right;"
   137       }
   138     }
   140     ui.field.text{ attr = { class = "head" }, value = _"Add new suggestion" }
   143     ui.form{
   144       module = "suggestion",
   145       action = "add",
   146       params = { initiative_id = initiative.id },
   147       routing = {
   148         default = {
   149           mode = "redirect",
   150           module = "initiative",
   151           view = "show",
   152           id = initiative.id,
   153           params = { tab = "suggestion" }
   154         }
   155       },
   156       attr = { class = "vertical" },
   157       content = function()
   158         local supported = Supporter:by_pk(initiative.id, app.session.member.id) and true or false
   159         if not supported then
   160           ui.field.text{
   161             attr = { class = "warning" },
   162             value = _"You are currently not supporting this initiative. By adding suggestions to this initiative you will automatically become a potential supporter."
   163           }
   164         end
   165         ui.field.text{ label = _"Title (80 chars max)",        name = "name" }
   166         ui.field.text{ label = _"Description", name = "description", multiline = true }
   167         ui.field.select{ 
   168           label = _"Degree", 
   169           name = "degree",
   170           foreign_records = { 
   171             { id =  1, name = _"should"},
   172             { id =  2, name = _"must"},
   173           },
   174           foreign_id = "id",
   175           foreign_name = "name"
   176         }
   177         ui.submit{ text = _"Commit suggestion" }
   178       end
   179     }
   180   end
   181 }
   183 local supporter = app.session.member:get_reference_selector("supporters")
   184   :add_where{ "initiative_id = ?", initiative.id }
   185   :optional_object_mode()
   186   :exec()
   188 if supporter then
   189   local old_draft_id = supporter.draft_id
   190   local new_draft_id = initiative.current_draft.id
   191   if old_draft_id ~= new_draft_id then
   192     ui.container{
   193       attr = { class = "draft_updated_info" },
   194       content = function()
   195         slot.put("The draft of this initiative has been updated!")
   196         slot.put(" ")
   197         ui.link{
   198           content = _"Show diff",
   199           module = "draft",
   200           view = "diff",
   201           params = {
   202             old_draft_id = old_draft_id,
   203             new_draft_id = new_draft_id
   204           }
   205         }
   206         slot.put(" ")
   207         ui.link{
   208           content = _"Refresh support to current draft",
   209           module = "initiative",
   210           action = "add_support",
   211           id = initiative.id,
   212           routing = {
   213             default = {
   214               mode = "redirect",
   215               module = "initiative",
   216               view = "show",
   217               id = initiative.id
   218             }
   219           }
   220         }
   221       end
   222     }
   223   end
   224 end
   227 ui.tabs{
   228   {
   229     name = "current_draft",
   230     label = _"Current draft",
   231     content = function()
   232       if initiator then
   233         ui.link{
   234           content = function()
   235             ui.image{ static = "icons/16/script_add.png" }
   236             slot.put(_"Edit draft")
   237           end,
   238           module = "draft",
   239           view = "new",
   240           params = { initiative_id = initiative.id }
   241         }
   242       end
   243       execute.view{ module = "draft", view = "_show", params = { draft = initiative.current_draft } }
   244     end
   245   },
   246   {
   247     name = "suggestion",
   248     label = _"Suggestions",
   249     content = function()
   250       execute.view{
   251         module = "suggestion",
   252         view = "_list",
   253         params = {
   254           initiative = initiative,
   255           suggestions_selector = initiative:get_reference_selector("suggestions")
   256         }
   257       }
   258       slot.put("<br />")
   259       if not initiative.issue.frozen and not initiative.issue.closed then
   260         ui.link{
   261           content = function()
   262             ui.image{ static = "icons/16/comment_add.png" }
   263             slot.put(_"Add new suggestion")
   264           end,
   265           attr = { onclick = "document.getElementById('add_suggestion_form').style.display='block';return(false)" },
   266           static = "#"
   267         }
   268       end
   269     end
   270   },
   271   {
   272     name = "supporter",
   273     label = _"Supporter",
   274     content = function()
   275       execute.view{
   276         module = "member",
   277         view = "_list",
   278         params = {
   279           initiative = initiative,
   280           members_selector =  initiative:get_reference_selector("supporting_members_snapshot")
   281             :join("issue", nil, "issue.id = direct_supporter_snapshot.issue_id")
   282             :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")
   283             :add_field("direct_interest_snapshot.weight")
   284             :add_where("direct_supporter_snapshot.event = issue.latest_snapshot_event")
   285         }
   286       }
   287     end
   288   },
   289   {
   290     name = "initiators",
   291     label = _"Initiators",
   292     content = function()
   293       execute.view{ module = "member", view = "_list", params = { members_selector = initiative:get_reference_selector("initiating_members") } }
   294     end
   295   },
   296   {
   297     name = "drafts",
   298     label = _"Old drafts",
   299     content = function()
   300       execute.view{ module = "draft", view = "_list", params = { drafts = initiative.drafts } }
   301     end
   302   },
   303   {
   304     name = "details",
   305     label = _"Details",
   306     content = function()
   307       ui.form{
   308         attr = { class = "vertical" },
   309         record = initiative,
   310         readonly = true,
   311         content = function()
   312           ui.field.text{ label = _"Issue policy", value = initiative.issue.policy.name }
   313           ui.field.text{
   314             label = _"Created at",
   315             value = tostring(initiative.created)
   316           }
   317           ui.field.text{
   318             label = _"Created at",
   319             value = format.timestamp(initiative.created)
   320           }
   321           ui.field.date{ label = _"Revoked at", name = "revoked" }
   322           ui.field.boolean{ label = _"Admitted", name = "admitted" }
   323         end
   324       }
   325     end
   326   },
   327 }
