liquid_feedback_frontend
view app/main/issue/_sidebar_whatcanido.lua @ 1305:fd50bdd36a4b
Set name for To: field of notification mails, added missing translation function call
| author | bsw | 
|---|---|
| date | Sat May 07 19:27:58 2016 +0200 (2016-05-07) | 
| parents | 904f6807f7fa | 
| children | 32cc544d5a5b | 
 line source
     1 local issue = param.get("issue", "table")
     2 local initiative = param.get("initiative", "table")
     3 local member = param.get("member", "table") or app.session.member
     5 if initiative then
     6   issue = initiative.issue
     7 end
     9 local privileged_to_vote = app.session.member and app.session.member:has_voting_right_for_unit_id(issue.area.unit_id)
    11 local active_trustee_id
    12 if member then
    13   if not issue.member_info.own_participation then
    14     if issue.member_info.first_trustee_participation then
    15       active_trustee_id = issue.member_info.first_trustee_id
    16     elseif issue.member_info.other_trustee_participation then
    17       active_trustee_id = issue.member_info.other_trustee_id
    18     end
    19   end
    20 end
    22 ui.sidebar ( "tab-whatcanido", function ()
    24   ui.sidebarHeadWhatCanIDo()
    26   local supporter
    28   if initiative and app.session.member_id then
    29     supporter = app.session.member:get_reference_selector("supporters")
    30       :add_where{ "initiative_id = ?", initiative.id }
    31       :optional_object_mode()
    32       :exec()
    33   end
    35   local view_module
    36   local view_id
    38   if initiative then
    39     issue = issue
    40     view_module = "initiative"
    41     view_id = initiative.id
    42   else
    43     view_module = "issue"
    44     view_id = issue.id
    45   end
    47   local initiator
    48   if initiative and app.session.member_id then
    49     initiator = Initiator:by_pk(initiative.id, app.session.member.id)
    50   end
    52   local initiators 
    54   if initiative then
    55     local initiators_members_selector = initiative:get_reference_selector("initiating_members")
    56       :add_field("initiator.accepted", "accepted")
    57       :add_order_by("member.name")
    58     if initiator and initiator.accepted then
    59       initiators_members_selector:add_where("initiator.accepted ISNULL OR initiator.accepted")
    60     else
    61       initiators_members_selector:add_where("initiator.accepted")
    62     end
    64     initiators = initiators_members_selector:exec()
    65   end
    67   if initiator and 
    68     initiator.accepted and 
    69     not issue.fully_frozen and 
    70     not issue.closed and 
    71     not initiative.revoked 
    72   then
    74     ui.container { attr = { class = "sidebarRow" }, content = function ()
    75       ui.heading { level = 3, content = function()
    76         ui.tag { content = _"You are initiator of this initiative" }
    77       end }
    78       ui.tag { tag = "ul", attr = { class = "ul" }, content = function ()
    79         if issue.half_frozen then
    80           ui.tag { tag = "li", content = _"this issue is in verification phase, therefore the initiative text cannot be updated anymore" }
    81         else
    82           ui.tag { tag = "li", content = function ()
    83             ui.link{
    84               module = "draft", view = "new",
    85               params = { initiative_id = initiative.id },
    86               content = _"edit proposal and/or reasons"
    87             }
    88           end }
    89           ui.tag { tag = "li", content = function ()
    90             ui.link{
    91               attr = { class = "action" },
    92               module = "initiative", view = "add_initiator",
    93               params = { initiative_id = initiative.id },
    94               content = _"invite another initiator"
    95             }
    96           end }
    97           if #initiative.initiators > 1 then
    98             ui.tag { tag = "li", content = function ()
    99               ui.link{
   100                 module = "initiative", view = "remove_initiator",
   101                 params = { initiative_id = initiative.id },
   102                 content = _"remove an initiator"
   103               }
   104             end }
   105           end
   106           ui.tag { tag = "li", content = function ()
   107             ui.link{
   108               module = "initiative", view = "revoke", id = initiative.id,
   109               content = _"revoke initiative"
   110             }
   111           end }
   112         end
   113       end }
   114     end }
   115   end
   117   -- invited as initiator
   118   if initiator and initiator.accepted == nil and not initiative.issue.half_frozen and not initiative.issue.closed then
   119     ui.container { attr = { class = "sidebarRow highlighted" }, content = function ()
   120       ui.heading { level = 3, content = function()
   121         ui.tag { content = _"You are invited to become initiator of this initiative" }
   122       end }
   123       ui.tag { tag = "ul", attr = { class = "ul" }, content = function ()
   124         ui.tag{ tag = "li", content = function ()
   125           ui.link{
   126             content = _"accept invitation",
   127             module = "initiative",
   128             action = "accept_invitation",
   129             id     = initiative.id,
   130             routing = {
   131               default = {
   132                 mode = "redirect",
   133                 module = request.get_module(),
   134                 view = request.get_view(),
   135                 id = request.get_id_string(),
   136                 params = request.get_param_strings()
   137               }
   138             }
   139           }
   140         end }
   142         ui.tag{ tag = "li", content = function ()
   143           ui.link{
   144             content = _"refuse invitation",
   145             module = "initiative",
   146             action = "reject_initiator_invitation",
   147             params = {
   148               initiative_id = initiative.id,
   149               member_id = app.session.member.id
   150             },
   151             routing = {
   152               default = {
   153                 mode = "redirect",
   154                 module = request.get_module(),
   155                 view = request.get_view(),
   156                 id = request.get_id_string(),
   157                 params = request.get_param_strings()
   158               }
   159             }
   160           }
   161         end }
   162       end }
   163     end }
   164   end
   167   if privileged_to_vote and issue.member_info.first_trustee_id then
   168     local member = Member:by_id(issue.member_info.first_trustee_id)
   169     ui.sidebarSection( function ()
   170       ui.container { attr = { class = "right" }, content = function()
   171         execute.view{
   172           module = "member_image",
   173           view = "_show",
   174           params = {
   175             member = member,
   176             image_type = "avatar",
   177             show_dummy = true
   178           }
   179         }
   180       end }
   181       if issue.member_info.own_delegation_scope == "unit" then
   182         ui.heading{ level = 3, content = _"You delegated this organizational unit" }
   183       elseif issue.member_info.own_delegation_scope == "area" then
   184         ui.heading{ level = 3, content = _"You delegated this subject area" }
   185       elseif issue.member_info.own_delegation_scope == "issue" then
   186         ui.heading{ level = 3, content = _"You delegated this issue" }
   187       end
   189       ui.tag { tag = "ul", attr = { class = "ul" }, content = function ()
   190         if issue.member_info.own_delegation_scope == "area" or
   191            issue.member_info.own_delegation_scope == "unit" then
   192           ui.tag { tag = "li", content = function ()
   193             ui.link {
   194               module = "delegation", view = "show", params = {
   195                 issue_id = issue.id,
   196                 initiative_id = initiative and initiative.id or nil
   197               },
   198               content = _"change/revoke delegation only for this issue" 
   199             }
   200           end }
   201         end
   202         if issue.member_info.own_delegation_scope == "unit" then
   203           ui.tag { tag = "li", content = function ()
   204             ui.link {
   205               module = "delegation", view = "show", params = {
   206                 unit_id = issue.area.unit_id,
   207               },
   208               content = _("change/revoke delegation of organizational unit", {
   209                 unit_name = issue.area.unit.name
   210               })
   211             }
   212           end }
   213         elseif issue.member_info.own_delegation_scope == "area" then
   214           ui.tag { tag = "li", content = function ()
   215             ui.link {
   216               module = "delegation", view = "show", params = {
   217                 area_id = issue.area_id,
   218               },
   219               content = _"change/revoke delegation of subject area" 
   220             }
   221           end }
   222         end
   223         if issue.member_info.own_delegation_scope == nil then
   224           ui.tag { tag = "li", content = function ()
   225             ui.link {
   226               module = "delegation", view = "show", params = {
   227                 issue_id = issue.id,
   228                 initiative_id = initiative and initiative.id or nil
   229               },
   230               content = _"choose issue delegatee" 
   231             }
   232           end }
   233         elseif issue.member_info.own_delegation_scope == "issue" then
   234           ui.tag { tag = "li", content = function ()
   235             ui.link {
   236               module = "delegation", view = "show", params = {
   237                 issue_id = issue.id,
   238                 initiative_id = initiative and initiative.id or nil
   239               },
   240               content = _"change/revoke issue delegation" 
   241             }
   242           end }
   243         end
   244       end }
   246       if issue.member_info.first_trustee_id and issue.member_info.own_participation then
   247         local text = _"As long as you are interested in this issue yourself, the delegation is suspended for this issue, but it will be applied again in the voting phase unless you vote yourself."
   248         if issue.state == "voting" then
   249           text = _"This delegation is suspended, because you voted yourself."
   250         end
   251         ui.container { content = text }
   252       end
   253     end )
   254   end
   256   if privileged_to_vote and not issue.closed and not issue.fully_frozen then
   257     if issue.member_info.own_participation then
   258       ui.sidebarSection( function ()
   259         ui.container{ attr = { class = "right" }, content = function()
   260           ui.image{ attr = { class = "right" }, static = "icons/48/eye.png" }
   261           if issue.member_info.weight and issue.member_info.weight > 1 then
   262             slot.put("<br />")
   263             ui.tag{ 
   264               attr = { class = "right" },
   265               content = "+" .. issue.member_info.weight - 1
   266            }
   267           end
   268         end }
   269         ui.heading{ level = 3, content = _("You are interested in this issue", { id = issue.id }) }
   270         ui.tag { tag = "ul", attr = { class = "ul" }, content = function ()
   271           if issue.member_info.weight and issue.member_info.weight > 1 then
   272             ui.tag { tag = "li", content = function ()
   273               ui.link {
   274                 module = "delegation", view = "show_incoming",
   275                 params = { issue_id = issue.id, member_id = app.session.member_id },
   276                 content = _("you have #{count} incoming delegations", {
   277                   count = issue.member_info.weight - 1
   278                 })
   279               }
   280             end }
   281           end
   282           ui.tag { tag = "li", content = function ()
   283             ui.link {
   284               module = "interest", action = "update",
   285               routing = { default = {
   286                 mode = "redirect", module = view_module, view = "show", id = view_id
   287               } },
   288               params = { issue_id = issue.id, delete = true },
   289               text = _"remove my interest"
   290             }
   291           end }
   292         end }
   293       end )
   294     else
   295       ui.sidebarSection( function ()
   296         ui.heading{ level = 3, content = _("I want to participate in this issue", { id = issue.id }) }
   297         ui.tag { tag = "ul", attr = { class = "ul" }, content = function ()
   298           ui.tag { tag = "li", content = function ()
   299             ui.link {
   300               module = "interest", action = "update", 
   301               params = { issue_id = issue.id },
   302               routing = { default = {
   303                 mode = "redirect", module = view_module, view = "show", id = view_id
   304               } },
   305               text = _"add my interest"
   306             }
   307           end }
   308           ui.tag { tag = "li", content = _"browse through the competing initiatives" }
   309         end }
   310       end )
   311     end
   313     if initiative then
   315       if not initiative.member_info.supported or active_trustee_id then
   316         ui.container { attr = { class = "sidebarRow" }, content = function ()
   317           ui.heading { level = 3, content = function()
   318             ui.tag { content = _"I like this initiative and I want to support it" }
   319           end }
   320           ui.tag { tag = "ul", attr = { class = "ul" }, content = function ()
   321             ui.tag { tag = "li", content = function ()
   322               ui.link {
   323                 module = "initiative", action = "add_support", 
   324                 routing = { default = {
   325                   mode = "redirect", module = "initiative", view = "show", id = initiative.id
   326                 } },
   327                 id = initiative.id,
   328                 text = _"add my support"
   329               }
   330             end }
   331           end }
   332         end }
   334       else -- if not supported
   335         ui.container { attr = { class = "sidebarRow" }, content = function ()
   336           if initiative.member_info.satisfied then
   337             ui.image{ attr = { class = "right icon48" }, static = "icons/32/support_satisfied.png" }
   338           else
   339             ui.image{ attr = { class = "right icon48" }, static = "icons/32/support_unsatisfied.png" }
   340           end
   341           ui.heading { level = 3, content = _"You are supporting this initiative" }
   342           ui.tag { tag = "ul", attr = { class = "ul" }, content = function ()
   343             if not initiative.member_info.satisfied then
   344               ui.tag { tag = "li", content = function ()
   345                 ui.tag { content = function ()
   346                   ui.link {
   347                     external = "#suggestions",
   348                     content = _"you restricted your support by rating suggestions as must or must not"
   349                   }
   350                 end }
   351               end }
   352             end
   353             ui.tag { tag = "li", content = function ()
   354               ui.tag { content = function ()
   355                 ui.link {
   356                   xattr = { class = "btn btn-remove" },
   357                   module = "initiative", action = "remove_support", 
   358                   routing = { default = {
   359                     mode = "redirect", module = "initiative", view = "show", id = initiative.id
   360                   } },
   361                   id = initiative.id,
   362                   text = _"remove my support"
   363                 }
   364               end }
   365             end }
   366           end }
   367         end }
   369       end -- not supported
   371       ui.container { attr = { class = "sidebarRow" }, content = function ()
   372         ui.heading { level = 3, content = _"I want to improve this initiative" }
   373         ui.tag { tag = "ul", attr = { class = "ul" }, content = function ()
   374           if issue.state == "verification" then
   375             ui.tag { tag = "li", content = _"this issue is in verification phase, therefore the initiative text cannot be updated anymore" }
   376           elseif issue.state == "voting" then
   377             ui.tag { tag = "li", content = _"this issue is in voting phase, therefore the initiative text cannot be updated anymore" }
   378           else
   380             if initiative.member_info.initiated then
   381               ui.tag { tag = "li", content =_"take a look at the suggestions of your supporters" }
   382               ui.tag { tag = "li", content =_"if you like to implement a suggestion in your proposal and/or reasons, update your initiative draft" }
   383               ui.tag { tag = "li", content =_"to argue about suggestions, just add your arguments to your reasons in the initiative draft, so your supporters can learn about your opinion" }
   384             end
   386             if not initiative.member_info.supported or active_trustee_id then
   387               ui.tag { tag = "li", content =_"add your support (see above) and rate or write new suggestions (and thereby restrict your support to certain conditions if necessary)" }
   388             else
   389               ui.tag { tag = "li", content = _"take a look at the suggestions (see left) and rate them" }
   390               ui.tag { tag = "li", content = function ()
   391                 ui.link {
   392                   module = "suggestion", view = "new", params = {
   393                     initiative_id = initiative.id
   394                   },
   395                   content = _"write a new suggestion" 
   396                 }
   397               end }
   398             end
   399           end
   400         end }
   401       end }
   403     end
   405     if 
   406       (issue.state == "admission" or 
   407       issue.state == "discussion" or
   408       issue.state == "verification")
   409     then
   410       ui.sidebarSection( function ()
   411         if initiative then
   412           ui.heading{ level = 3, content = _"I don't like this initiative and I want to add my opinion or counter proposal" }
   413         else
   414           ui.heading{ level = 3, content = _"I don't like any of the initiative in this issue and I want to add my opinion or counter proposal" }
   415         end
   416         ui.tag { tag = "ul", attr = { class = "ul" }, content = function ()
   417           ui.tag { tag = "li", content = function ()
   418             ui.link {
   419               module = "issue", view = "show", id = issue.id,
   420               content = _"take a look at the competing initiatives"
   421             }
   422           end }
   423           ui.tag { tag = "li", content = function ()
   424             ui.link {
   425               module = "initiative", view = "new", 
   426               params = { issue_id = issue.id },
   427               content = _"start a new competing initiative"
   428             }
   429           end }
   430         end }
   431       end )
   432     end 
   434   end
   436   if privileged_to_vote and not issue.closed then
   438     if not issue.member_info.first_trustee_id then
   439       ui.sidebarSection( function ()
   440         ui.heading{ level = 3, content = _"I want to delegate this issue" }
   442         ui.tag { tag = "ul", attr = { class = "ul" }, content = function ()
   443           ui.tag { tag = "li", content = function ()
   444             ui.link {
   445               module = "delegation", view = "show", params = {
   446                 issue_id = issue.id,
   447                 initiative_id = initiative and initiative.id or nil
   448               },
   449               content = _"choose issue delegatee" 
   450             }
   451           end }
   452         end }
   453       end )
   454     end
   456   end
   458   if initiator and initiator.accepted == false then
   459     ui.container { attr = { class = "sidebarRow" }, content = function ()
   460       ui.heading { level = 3, content = function()
   461         ui.tag { content = _"You refused to become initiator of this initiative" }
   462       end }
   463       ui.tag { tag = "ul", attr = { class = "ul" }, content = function ()
   464         ui.tag{ tag = "li", content = function ()
   465           ui.link{
   466             text   = _"allow invitation again",
   467             module = "initiative",
   468             action = "remove_initiator",
   469             params = {
   470               initiative_id = initiative.id,
   471               member_id = app.session.member.id
   472             },
   473             routing = {
   474               ok = {
   475                 mode = "redirect",
   476                 module = "initiative",
   477                 view = "show",
   478                 id = initiative.id
   479               }
   480             }
   481           }
   482         end }
   483       end }
   484     end }
   485   end
   489   if privileged_to_vote then
   491     if initiative and
   492       (issue.state == "admission" or 
   493       issue.state == "discussion" or
   494       issue.state == "verification")
   495     then
   497     elseif issue.state == "verification" then
   499     elseif issue.state == "voting" then
   500       if not issue.member_info.direct_voted then
   501         if not issue.member_info.non_voter then
   502           ui.container { attr = { class = "sidebarRow" }, content = function ()
   503             ui.heading { level = 3, content = _"I like to vote on this issue:" }
   504             ui.tag { tag = "ul", attr = { class = "ul" }, content = function ()
   505               ui.tag { tag = "li", content = function ()
   506                 ui.tag { content = function ()
   507                   if not issue.closed then
   508                     ui.link {
   509                       xattr = { class = "btn btn-vote" },
   510                       module = "vote", view = "list", 
   511                       params = { issue_id = issue.id },
   512                       text = _"vote now"
   513                     }
   514                   end
   515                 end }
   516               end }
   517             end }
   518           end }
   519         end
   520         ui.container { attr = { class = "sidebarRow" }, content = function ()
   521           if not issue.member_info.non_voter then
   522             ui.heading { level = 3, content = _"I don't like to vote this issue (myself):" }
   523             ui.tag { tag = "ul", attr = { class = "ul" }, content = function ()
   524               ui.tag { tag = "li", content = function ()
   525                 ui.link{
   526                   content = _"do not notify me about this voting anymore",
   527                   module = "vote",
   528                   action = "non_voter",
   529                   params = { issue_id = issue.id },
   530                   routing = {
   531                     default = {
   532                       mode = "redirect",
   533                       module = request.get_module(),
   534                       view = request.get_view(),
   535                       id = request.get_id_string(),
   536                       params = request.get_param_strings()
   537                     }
   538                   }
   539                 }
   540               end }
   541             end }
   542           else
   543             ui.heading { level = 3, content = _"You do not like to vote this issue (yourself)" }
   544             ui.tag { tag = "ul", attr = { class = "ul" }, content = function ()
   545               ui.tag { tag = "li", content = function ()
   546                 ui.link{
   547                   in_brackets = true,
   548                   content = _"discard",
   549                   module = "vote",
   550                   action = "non_voter",
   551                   params = { issue_id = issue.id, delete = true },
   552                   routing = {
   553                     default = {
   554                       mode = "redirect",
   555                       module = request.get_module(),
   556                       view = request.get_view(),
   557                       id = request.get_id_string(),
   558                       params = request.get_param_strings()
   559                     }
   560                   }
   561                 }
   562               end }
   563             end }
   564           end
   565         end }
   566       else
   567         ui.container { attr = { class = "sidebarRow" }, content = function ()
   568           ui.heading { level = 3, content = _"I like to change/revoke my vote:" }
   569           ui.tag { tag = "ul", attr = { class = "ul" }, content = function ()
   570             ui.tag { tag = "li", content = function ()
   571               ui.tag { content = function ()
   572                 if not issue.closed then
   573                   ui.link {
   574                     xattr = { class = "btn btn-vote" },
   575                     module = "vote", view = "list", 
   576                     params = { issue_id = issue.id },
   577                     text = _"change my vote"
   578                   }
   579                 end
   580               end }
   581             end }
   582             ui.tag { tag = "li", content = function ()
   583               ui.tag { content = function ()
   584                 if not issue.closed then
   585                   ui.link {
   586                     module = "vote", action = "update",
   587                     params = {
   588                       issue_id = issue.id,
   589                       discard = true
   590                     },
   591                     routing = {
   592                       default = {
   593                         mode = "redirect",
   594                         module = "issue",
   595                         view = "show",
   596                         id = issue.id
   597                       }
   598                     },
   599                     text = _"discard my vote"
   600                   }
   601                 end
   602               end }
   603             end }
   604           end } 
   606         end } 
   608       end
   609     end
   610   end
   612   if app.session.member and not privileged_to_vote then
   613     ui.sidebarSection( _"You are not entitled to vote in this unit" )
   614   end
   616   if issue.closed then
   617     ui.container { attr = { class = "sidebarRow" }, content = function ()
   618       ui.heading { level = 3, content = _"This issue is closed" }
   619     end }
   620   end
   622   if initiative and config.tell_others and config.tell_others.initiative then
   623     ui.container { attr = { class = "sidebarRow" }, content = function ()
   625       ui.heading { level = 3, content = _"Tell others about this initiative:" }
   626       ui.tag { tag = "ul", attr = { class = "ul" }, content = function ()
   628         for i, link in ipairs (config.tell_others.initiative(initiative)) do
   629           ui.tag { tag = "li", content = function ()
   630             ui.link ( link )
   631           end }
   632         end
   634       end }
   635     end }
   636   end
   639 end )
