liquid_feedback_frontend
view app/main/suggestion/_list.lua @ 311:b3506522d043
Fixed a translation
| author | bsw | 
|---|---|
| date | Mon Feb 27 16:18:56 2012 +0100 (2012-02-27) | 
| parents | 6c88b4bfb56c | 
| children | 1e7ce3fafc26 | 
 line source
     2 local initiative = param.get("initiative", "table")
     3 local suggestions_selector = param.get("suggestions_selector", "table")
     4 local tab_id = param.get("tab_id")
     5 local show_name = param.get("show_name", atom.boolean)
     6 if show_name == nil then
     7   show_name = true
     8 end
     9 local show_filter = param.get("show_filter", atom.boolean)
    10 if show_filter == nil then
    11   show_filter = true
    12 end
    14 local partial = {
    15   routing = {
    16     default = {
    17       mode = "redirect",
    18       module = "initiative",
    19       view = "show_tab",
    20       params = {
    21         initiative_id = initiative.id,
    22         tab = "suggestions",
    23         tab_id = tab_id
    24       },
    25     }
    26   }
    27 }
    29 local ui_filters = ui.filters
    30 if not show_filter then
    31   ui_filters = function(args) args.content() end
    32 end
    34 ui_filters{
    35   selector = suggestions_selector,
    36   {
    37     {
    38       name = "plus_unfulfilled",
    39       label = _"most requested",
    40       selector_modifier = function(selector) selector:add_order_by("plus2_unfulfilled_count + plus1_unfulfilled_count DESC, id") end
    41     },
    42     {
    43       name = "plus2",
    44       label = _"must",
    45       selector_modifier = function(selector) selector:add_order_by("plus2_unfulfilled_count + plus2_fulfilled_count DESC, id") end
    46     },
    47     {
    48       name = "plus",
    49       label = _"must/should",
    50       selector_modifier = function(selector) selector:add_order_by("plus2_unfulfilled_count + plus1_unfulfilled_count + plus2_fulfilled_count + plus1_fulfilled_count DESC, id") end
    51     },
    52     {
    53       name = "minus",
    54       label = _"must/should not",
    55       selector_modifier = function(selector) selector:add_order_by("minus2_unfulfilled_count + minus1_unfulfilled_count + minus2_fulfilled_count + minus1_fulfilled_count DESC, id") end
    56     },
    57     {
    58       name = "minus2",
    59       label = _"must not",
    60       selector_modifier = function(selector) selector:add_order_by("minus2_unfulfilled_count + minus2_fulfilled_count DESC, id") end
    61     }
    62   },
    63   content = function()
    64     ui.paginate{
    65       selector = suggestions_selector,
    66       content = function()
    67         ui.list{
    68           attr = { style = "table-layout: fixed;" },
    69           records = suggestions_selector:exec(),
    70           columns = {
    71             {
    72               label = show_name and _"Suggestion" or nil,
    73               content = function(record)
    74                 if show_name then
    75                   ui.link{
    76                     text = record.name,
    77                     module = "suggestion",
    78                     view = "show",
    79                     id = record.id
    80                   }
    81                 end
    82               end
    83             },
    84             {
    85               label = _"Collective opinion of supporters",
    86               label_attr = { style = "width: 101px;" },
    87               content = function(record)
    88                 if record.minus2_unfulfilled_count then
    89                   local max_value = record.initiative.supporter_count
    90                   ui.bargraph{
    91                     max_value = max_value,
    92                     width = 100,
    93                     bars = {
    94                       { color = "#0a0", value = record.plus2_unfulfilled_count + record.plus2_fulfilled_count },
    95                       { color = "#8f8", value = record.plus1_unfulfilled_count + record.plus1_fulfilled_count },
    96                       { color = "#eee", value = max_value - record.minus2_unfulfilled_count - record.minus1_unfulfilled_count - record.minus2_fulfilled_count - record.minus1_fulfilled_count - record.plus1_unfulfilled_count - record.plus2_unfulfilled_count - record.plus1_fulfilled_count - record.plus2_fulfilled_count},
    97                       { color = "#f88", value = record.minus1_unfulfilled_count + record.minus1_fulfilled_count },
    98                       { color = "#a00", value = record.minus2_unfulfilled_count + record.minus2_fulfilled_count },
    99                     }
   100                   }
   101                 end
   102               end
   103             },
   104             {
   105               label = _"My opinion",
   106               label_attr = { style = "width: 130px; font-style: italic;" },
   107               content = function(record)
   108                 local degree
   109                 local opinion
   110                 if app.session.member_id then
   111                   opinion = Opinion:by_pk(app.session.member.id, record.id)
   112                 end
   113                 if opinion then
   114                   degree = opinion.degree
   115                 end
   116                 ui.container{
   117                   attr = { class = "suggestion_my_opinion" },
   118                   content = function()
   119                     local has_voting_right = app.session.member and app.session.member:has_voting_right_for_unit_id(initiative.issue.area.unit_id)
   120                     if app.session.member_id and has_voting_right then
   121                       if initiative.issue.state == "voting" or initiative.issue.state == "closed" then
   122                         if degree == -2 then
   123                           ui.tag{
   124                             tag = "span",
   125                             attr = {
   126                               class = "action" .. (degree == -2 and " active_red2" or "")
   127                             },
   128                             content = _"must not"
   129                           }
   130                         end
   131                         if degree == -1 then
   132                           ui.tag{
   133                             tag = "span",
   134                             attr = { class = "action" .. (degree == -1 and " active_red1" or "") },
   135                             content = _"should not"
   136                           }
   137                         end
   138                         if degree == nil then
   139                           ui.tag{
   140                             tag = "span",
   141                             attr = { class = "action" .. (degree == nil and " active" or "") },
   142                             content = _"neutral"
   143                           }
   144                         end
   145                         if degree == 1 then
   146                           ui.tag{
   147                             tag = "span",
   148                             attr = { class = "action" .. (degree == 1 and " active_green1" or "") },
   149                             content = _"should"
   150                           }
   151                         end
   152                         if degree == 2 then
   153                           ui.tag{
   154                             tag = "span",
   155                             attr = { class = "action" .. (degree == 2 and " active_green2" or "") },
   156                             content = _"must"
   157                           }
   158                         end
   159                       else
   160                         -- we need to put initiative_id into the parameters to have a redirect target in case the suggestion is gone after the action
   161                         params = param.get_all_cgi()
   162                         params['initiative_id'] = initiative.id
   164                         ui.link{
   165                           attr = { class = "action" .. (degree == 2 and " active_green2" or "") },
   166                           text = _"must",
   167                           module = "opinion",
   168                           action = "update",
   169                           routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = params } },
   170                           params = {
   171                             suggestion_id = record.id,
   172                             degree = 2
   173                           },
   174                           partial = partial
   175                         }
   176                         slot.put(" ")
   177                         ui.link{
   178                           attr = { class = "action" .. (degree == 1 and " active_green1" or "") },
   179                           text = _"should",
   180                           module = "opinion",
   181                           action = "update",
   182                           routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = params} },
   183                           params = {
   184                             suggestion_id = record.id,
   185                             degree = 1
   186                           },
   187                           partial = partial
   188                         }
   189                         slot.put(" ")
   190                         ui.link{
   191                           attr = { class = "action" .. (degree == nil and " active" or "") },
   192                           text = _"neutral",
   193                           module = "opinion",
   194                           action = "update",
   195                           routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = params } },
   196                           params = {
   197                             suggestion_id = record.id,
   198                             delete = true
   199                           },
   200                           partial = partial
   201                         }
   202                         slot.put(" ")
   203                         ui.link{
   204                           attr = { class = "action" .. (degree == -1 and " active_red1" or "") },
   205                           text = _"should not",
   206                           module = "opinion",
   207                           action = "update",
   208                           routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = params } },
   209                           params = {
   210                             suggestion_id = record.id,
   211                             degree = -1
   212                           },
   213                           partial = partial
   214                         }
   215                         slot.put(" ")
   216                         ui.link{
   217                           attr = { class = "action" .. (degree == -2 and " active_red2" or "") },
   218                           text = _"must not",
   219                           module = "opinion",
   220                           action = "update",
   221                           routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = params } },
   222                           params = {
   223                             suggestion_id = record.id,
   224                             degree = -2
   225                           },
   226                           partial = partial
   227                         }
   228                       end
   229                     elseif app.session.member_id then
   230                       ui.field.text{ value = _"[No voting privilege]" }
   231                     else
   232                       ui.field.text{ value = _"[Registered members only]" }
   233                     end
   234                   end
   235                 }
   236               end
   237             },
   238             {
   239               label = _"Suggestion currently not implemented",
   240               label_attr = { style = "width: 101px;" },
   241               content = function(record)
   242                 if record.minus2_unfulfilled_count then
   243                   local max_value = record.initiative.supporter_count
   244                   ui.bargraph{
   245                     max_value = max_value,
   246                     width = 100,
   247                     bars = {
   248                       { color = "#0a0", value = record.plus2_unfulfilled_count },
   249                       { color = "#8f8", value = record.plus1_unfulfilled_count },
   250                       { color = "#eee", value = max_value - record.minus2_unfulfilled_count - record.minus1_unfulfilled_count - record.plus1_unfulfilled_count - record.plus2_unfulfilled_count },
   251                       { color = "#f88", value = record.minus1_unfulfilled_count },
   252                       { color = "#a00", value = record.minus2_unfulfilled_count },
   253                     }
   254                   }
   255                 end
   256               end
   257             },
   258             {
   259               label = _"Suggestion currently implemented",
   260               label_attr = { style = "width: 101px;" },
   261               content = function(record)
   262                 if record.minus2_fulfilled_count then
   263                   local max_value = record.initiative.supporter_count
   264                   ui.bargraph{
   265                     max_value = max_value,
   266                     width = 100,
   267                     bars = {
   268                       { color = "#0a0", value = record.plus2_fulfilled_count },
   269                       { color = "#8f8", value = record.plus1_fulfilled_count },
   270                       { color = "#eee", value = max_value - record.minus2_fulfilled_count - record.minus1_fulfilled_count - record.plus1_fulfilled_count - record.plus2_fulfilled_count},
   271                       { color = "#f88", value = record.minus1_fulfilled_count },
   272                       { color = "#a00", value = record.minus2_fulfilled_count },
   273                     }
   274                   }
   275                 end
   276               end
   277             },
   278             {
   279               label = app.session.member_id and _"I consider suggestion as" or nil,
   280               label_attr = { style = "width: 100px; font-style: italic;" },
   281               content = function(record)
   282                 local degree
   283                 local opinion
   284                 if app.session.member_id then
   285                   opinion = Opinion:by_pk(app.session.member.id, record.id)
   286                 end
   287                 if opinion then
   288                   degree = opinion.degree
   289                 end
   290                 if opinion then
   292                   ui.link{
   293                     attr = { class = opinion.fulfilled and "action active" or "action" },
   294                     text = _"implemented",
   295                     module = "opinion",
   296                     action = "update",
   297                     routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = param.get_all_cgi() } },
   298                     params = {
   299                       suggestion_id = record.id,
   300                       fulfilled = true
   301                     },
   302                     partial = partial
   303                   }
   304                   slot.put("<br />")
   305                   ui.link{
   306                     attr = { class = not opinion.fulfilled and "action active" or "action" },
   307                     text = _"not implemented",
   308                     module = "opinion",
   309                     action = "update",
   310                     routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = param.get_all_cgi() } },
   311                     params = {
   312                       suggestion_id = record.id,
   313                       fulfilled = false
   314                     },
   315                     partial = partial
   316                   }
   318                 end
   319               end
   320             },
   321             {
   322               label = app.session.member_id and _"So I'm" or nil,
   323               content = function(record)
   324                 local opinion
   325                 if app.session.member_id then
   326                   opinion = Opinion:by_pk(app.session.member.id, record.id)
   327                 end
   328                 if opinion then
   329                   if (opinion.fulfilled and opinion.degree > 0) or (not opinion.fulfilled and opinion.degree < 0) then
   330                     local title = _"satisfied"
   331                     ui.image{ attr = { alt = title, title = title }, static = "icons/emoticon_happy.png" }
   332                   elseif opinion.degree == 1 or opinion.degree == -1 then
   333                     local title = _"a bit unsatisfied"
   334                     ui.image{ attr = { alt = title, title = title }, static = "icons/emoticon_unhappy.png" }
   335                   else
   336                     local title = _"more unsatisfied"
   337                     ui.image{ attr = { alt = title, title = title }, static = "icons/emoticon_unhappy_red.png" }
   338                   end
   339                 end
   340               end
   341             },
   342           }
   343         }
   344       end
   345     }
   346   end
   347 }
