liquid_feedback_frontend
view app/main/initiative/new.lua @ 1363:4664e021473f
Fixed code order
| author | bsw | 
|---|---|
| date | Mon Aug 06 14:13:05 2018 +0200 (2018-08-06) | 
| parents | 32cc544d5a5b | 
| children | 
 line source
     1 local issue
     2 local area
     4 local issue_id = param.get("issue_id", atom.integer)
     5 if issue_id then
     6   issue = Issue:new_selector():add_where{"id=?",issue_id}:single_object_mode():exec()
     7   issue:load_everything_for_member_id(app.session.member_id)
     8   area = issue.area
    10 else
    11   local area_id = param.get("area_id", atom.integer)
    12   area = Area:new_selector():add_where{"id=?",area_id}:single_object_mode():exec()
    13   area:load_delegation_info_once_for_member_id(app.session.member_id)
    14 end
    16 local polling = param.get("polling", atom.boolean)
    18 local policy_id = param.get("policy_id", atom.integer)
    19 local policy
    21 local preview = param.get("preview")
    23 if #(slot.get_content("error")) > 0 then
    24   preview = false
    25 end
    27 if policy_id then
    28   policy = Policy:by_id(policy_id)
    29 end
    31 if issue_id then
    32   execute.view {
    33     module = "issue", view = "_head", 
    34     params = { issue = issue, member = app.session.member }
    35   }
    36 else
    37   --[[
    38   execute.view {
    39     module = "area", view = "_head", 
    40     params = { area = area, member = app.session.member }
    41   }
    42   --]]
    43   --[[
    44   execute.view { 
    45     module = "initiative", view = "_sidebar_policies", 
    46     params = {
    47       area = area,
    48     }
    49   }
    50   --]]
    51 end
    53 ui.form{
    54   module = "initiative",
    55   action = "create",
    56   params = {
    57     area_id = area.id,
    58     issue_id = issue and issue.id or nil
    59   },
    60   attr = { class = "vertical" },
    61   content = function()
    62     ui.grid{ content = function()
    63       ui.cell_main{ content = function()
    64         ui.container{ attr = { class = "mdl-card mdl-shadow--2dp mdl-card__fullwidth" }, content = function()
    65           ui.container{ attr = { class = "mdl-card__title mdl-card--border" }, content = function()
    66             if preview then
    67               ui.heading { attr = { class = "mdl-card__title-text" }, level = 2, content = _"Preview" }
    68             elseif issue_id then
    69               ui.heading { attr = { class = "mdl-card__title-text" }, level = 2, content = _"New competing initiative" }
    70             else
    71               ui.heading { attr = { class = "mdl-card__title-text" }, level = 2, content = _"Create a new issue" }
    72             end
    73           end }
    75           ui.container{ attr = { class = "mdl-card__content mdl-card--border" }, content = function()
    78             if preview then
    80               ui.section( function()
    81                 ui.sectionHead( function()
    82                   ui.heading{ level = 1, content = encode.html(param.get("name")) }
    83                   if not issue then
    84                     ui.container { content = policy.name }
    85                   end
    86                   if param.get("free_timing") then
    87                     ui.container { content = param.get("free_timing") }
    88                   end
    89                   slot.put("<br />")
    91                   local draft_text = param.get("draft")
    92                   local draft_text = util.wysihtml_preproc(draft_text)
    94                   ui.field.hidden{ name = "policy_id", value = param.get("policy_id") }
    95                   ui.field.hidden{ name = "name", value = param.get("name") }
    96                   if config.initiative_abstract then
    97                     ui.field.hidden{ name = "abstract", value = param.get("abstract") }
    98                     ui.container{
    99                       attr = { class = "abstract" },
   100                       content = param.get("abstract")
   101                     }
   102                     slot.put("<br />")
   103                   end
   104                   ui.field.hidden{ name = "draft", value = draft_text }
   105                   ui.field.hidden{ name = "free_timing", value = param.get("free_timing") }
   106                   ui.field.hidden{ name = "polling", value = param.get("polling", atom.boolean) }
   107                   ui.field.hidden{ name = "location", value = param.get("location") }
   108                   local formatting_engine
   109                   if config.enforce_formatting_engine then
   110                     formatting_engine = config.enforce_formatting_engine
   111                   else
   112                     formatting_engine = param.get("formatting_engine")
   113                   end
   114                   ui.container{
   115                     attr = { class = "draft" },
   116                     content = function()
   117                       slot.put(draft_text)
   118                     end
   119                   }
   120                   slot.put("<br />")
   122                   ui.tag{
   123                     tag = "input",
   124                     attr = {
   125                       type = "submit",
   126                       class = "mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--colored",
   127                       value = _'Publish now'
   128                     },
   129                     content = ""
   130                   }
   131                   slot.put("   ")
   132                   ui.tag{
   133                     tag = "input",
   134                     attr = {
   135                       type = "submit",
   136                       name = "edit",
   137                       class = "mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect",
   138                       value = _'Edit again'
   139                     },
   140                     content = ""
   141                   }
   142                   slot.put("   ")
   143                   local class = "mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect"
   144                   if issue then
   145                     ui.link{ content = _"Cancel", module = "issue", view = "show", id = issue.id, attr = { class = class } }
   146                   else
   147                     ui.link{ content = _"Cancel", module = "index", view = "index", params = { unit = area.unit_id, area = area.id }, attr = { class = class } }
   148                   end
   149                 end )
   150               end )
   151             else
   153               ui.sectionRow( function()
   154               --[[
   155                 if not preview and not issue_id then
   156                   ui.container { attr = { class = "section" }, content = _"Before creating a new issue, please check any existant issues before, if the topic is already in discussion." }
   157                   slot.put("<br />")
   158                 end
   159               --]]
   160                 if not issue_id then
   161                   local tmp = { { id = -1, name = "" } }
   162                   for i, allowed_policy in ipairs(area.allowed_policies) do
   163                     if not allowed_policy.polling or app.session.member:has_polling_right_for_unit_id(area.unit_id) then
   164                       tmp[#tmp+1] = allowed_policy
   165                     end
   166                   end
   167                   ui.container{ content = _"Please choose a policy for the new issue:" }
   168                   ui.field.select{
   169                     name = "policy_id",
   170                     foreign_records = tmp,
   171                     foreign_id = "id",
   172                     foreign_name = "name",
   173                     value = param.get("policy_id", atom.integer) or area.default_policy and area.default_policy.id
   174                   }
   175                   if policy and policy.free_timeable then
   176                     local available_timings
   177                     if config.free_timing and config.free_timing.available_func then
   178                       available_timings = config.free_timing.available_func(policy)
   179                       if available_timings == false then
   180                         slot.put_into("error", "error in free timing config")
   181                         return false
   182                       end
   183                     end
   184                     ui.heading{ level = 4, content = _"Free timing:" }
   185                     if available_timings then
   186                       ui.field.select{
   187                         name = "free_timing",
   188                         foreign_records = available_timings,
   189                         foreign_id = "id",
   190                         foreign_name = "name",
   191                         value = param.get("free_timing")
   192                       }
   193                     else
   194                       ui.field.text{
   195                         name = "free_timing",
   196                         value = param.get("free_timing")
   197                       }
   198                     end
   199                   end
   200                 end
   202                 if issue and issue.policy.polling and app.session.member:has_polling_right_for_unit_id(area.unit_id) then
   203                   slot.put("<br />")
   204                   ui.field.boolean{ name = "polling", label = _"No admission needed", value = polling }
   205                 end
   207                 ui.container{ attr = { class = "mdl-textfield mdl-js-textfield mdl-textfield--floating-label mdl-card__fullwidth" }, content = function ()
   208                   ui.field.text{
   209                     attr = { id = "lf-initiative__name", class = "mdl-textfield__input" },
   210                     label_attr = { class = "mdl-textfield__label", ["for"] = "lf-initiative__name" },
   211                     label = _"Title",
   212                     name  = "name",
   213                     value = param.get("name")
   214                   }
   215                 end }
   217                 if config.initiative_abstract then
   218                   ui.container { content = _"Enter abstract:" }
   219                   ui.container{ attr = { class = "mdl-textfield mdl-js-textfield mdl-textfield--expandable mdl-textfield__fullwidth" }, content = function()
   220                     ui.field.text{
   221                       name = "abstract",
   222                       multiline = true, 
   223                       attr = { id = "abstract", style = "height: 20ex; width: 100%;" },
   224                       value = param.get("abstract")
   225                     }
   226                   end }
   227                 end
   229                 ui.container { content = _"Enter your proposal and/or reasons:" }
   230                 ui.container{ attr = { class = "mdl-textfield mdl-js-textfield mdl-textfield--expandable mdl-textfield__fullwidth" }, content = function()
   231                   ui.field.wysihtml{
   232                     name = "draft",
   233                     multiline = true, 
   234                     attr = { id = "draft", style = "height: 50ex; width: 100%;" },
   235                     value = param.get("draft") or config.draft_template
   236                   }
   237                 end }
   238                 if not issue or issue.state == "admission" or issue.state == "discussion" then
   239                   ui.container { content = _"You can change your text again anytime during admission and discussion phase" }
   240                 else
   241                   ui.container { content = _"You cannot change your text again later, because this issue is already in verfication phase!" }
   242                 end
   243                 slot.put("<br />")
   245                 slot.put("<br />")
   246                 ui.tag{
   247                   tag = "input",
   248                   attr = {
   249                     type = "submit",
   250                     name = "preview",
   251                     class = "mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--colored",
   252                     value = _'Preview'
   253                   },
   254                   content = ""
   255                 }
   256                 slot.put("   ")
   258                 local class = "mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect"
   259                 if issue then
   261                   ui.link{ content = _"Cancel", module = "issue", view = "show", id = issue.id, attr = { class = class } }
   262                 else
   263                   ui.link{ content = _"Cancel", module = "index", view = "index", params = { unit = area.unit_id, area = area.id }, attr = { class = class } }
   264                 end
   265               end )
   266             end
   267           end }
   268         end }
   269       end }
   270       if config.map or config.firstlife then
   271         ui.cell_sidebar{ content = function()
   272           ui.container{ attr = { class = "mdl-special-card map mdl-shadow--2dp" }, content = function()
   273             ui.field.location{ name = "location", value = param.get("location") }
   274           end }
   275         end }
   276       end
   277     end }
   278   end
   279 }
