liquid_feedback_frontend
view app/main/initiative/new.lua @ 1300:5aecbbb04a42
Added missing conditions to events for notification selector
| author | bsw | 
|---|---|
| date | Wed May 04 21:38:02 2016 +0200 (2016-05-04) | 
| parents | 9fed7af9263f | 
| children | 32cc544d5a5b | 
 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   execute.view { 
    37     module = "issue", view = "_sidebar_state", 
    38     params = {
    39       issue = issue
    40     }
    41   }
    42   execute.view { 
    43     module = "issue", view = "_sidebar_issue", 
    44     params = {
    45       issue = issue
    46     }
    47   }
    48 else
    49   execute.view {
    50     module = "area", view = "_head", 
    51     params = { area = area, member = app.session.member }
    52   }
    53   execute.view { 
    54     module = "initiative", view = "_sidebar_policies", 
    55     params = {
    56       area = area,
    57     }
    58   }
    59 end
    61 ui.form{
    62   module = "initiative",
    63   action = "create",
    64   params = {
    65     area_id = area.id,
    66     issue_id = issue and issue.id or nil
    67   },
    68   attr = { class = "vertical" },
    69   content = function()
    71     if preview then
    72       ui.section( function()
    73         ui.sectionHead( function()
    74           ui.heading{ level = 1, content = encode.html(param.get("name")) }
    75           if not issue then
    76             ui.container { content = policy.name }
    77           end
    78 	  if param.get("free_timing") then
    79 	    ui.container { content = param.get("free_timing") }
    80 	  end
    81           slot.put("<br />")
    83           ui.field.hidden{ name = "formatting_engine", value = param.get("formatting_engine") }
    84           ui.field.hidden{ name = "policy_id", value = param.get("policy_id") }
    85           ui.field.hidden{ name = "name", value = param.get("name") }
    86           ui.field.hidden{ name = "draft", value = param.get("draft") }
    87           ui.field.hidden{ name = "free_timing", value = param.get("free_timing") }
    88           ui.field.hidden{ name = "polling", value = param.get("polling", atom.boolean) }
    89           local formatting_engine
    90           if config.enforce_formatting_engine then
    91             formatting_engine = config.enforce_formatting_engine
    92           else
    93             formatting_engine = param.get("formatting_engine")
    94           end
    95           ui.container{
    96             attr = { class = "draft" },
    97             content = function()
    98               slot.put(format.wiki_text(param.get("draft"), formatting_engine))
    99             end
   100           }
   101           slot.put("<br />")
   103           ui.tag{
   104             tag = "input",
   105             attr = {
   106               type = "submit",
   107               class = "btn btn-default",
   108               value = _'Publish now'
   109             },
   110             content = ""
   111           }
   112           slot.put("<br />")
   113           slot.put("<br />")
   114           ui.tag{
   115             tag = "input",
   116             attr = {
   117               type = "submit",
   118               name = "edit",
   119               class = "btn-link",
   120               value = _'Edit again'
   121             },
   122             content = ""
   123           }
   124           slot.put(" | ")
   125           if issue then
   126             ui.link{ content = _"Cancel", module = "issue", view = "show", id = issue.id }
   127           else
   128             ui.link{ content = _"Cancel", module = "area", view = "show", id = area.id }
   129           end
   130         end )
   131       end )
   132     else
   135       execute.view{ module = "initiative", view = "_sidebar_wikisyntax" }
   137       ui.section( function()
   138         if preview then
   139           ui.sectionHead( function()
   140             ui.heading { level = 1, content = _"Edit again" }
   141           end )
   142         elseif issue_id then
   143           ui.sectionHead( function()
   144             ui.heading { level = 1, content = _"Add a new competing initiative to issue" }
   145           end )
   146         else
   147           ui.sectionHead( function()
   148             ui.heading { level = 1, content = _"Create a new issue" }
   149           end )
   150         end
   152         ui.sectionRow( function()
   153           if not preview and not issue_id then
   154             ui.container { attr = { class = "section" }, content = _"Before creating a new issue, please check any existant issues before, if the topic is already in discussion." }
   155             slot.put("<br />")
   156           end
   157           if not issue_id then
   158             local tmp = { { id = -1, name = "" } }
   159             for i, allowed_policy in ipairs(area.allowed_policies) do
   160               if not allowed_policy.polling or app.session.member:has_polling_right_for_unit_id(area.unit_id) then
   161                 tmp[#tmp+1] = allowed_policy
   162               end
   163             end
   164             ui.heading{ level = 2, content = _"Please choose a policy for the new issue:" }
   165             ui.field.select{
   166               name = "policy_id",
   167               foreign_records = tmp,
   168               foreign_id = "id",
   169               foreign_name = "name",
   170               value = param.get("policy_id", atom.integer) or area.default_policy and area.default_policy.id
   171             }
   172             if policy and policy.free_timeable then
   173 	      local available_timings
   174 	      if config.free_timing and config.free_timing.available_func then
   175 		available_timings = config.free_timing.available_func(policy)
   176 		if available_timings == false then
   177 		  error("error in free timing config")
   178 		end
   179 	      end
   180 	      ui.heading{ level = 4, content = _"Free timing:" }
   181 	      if available_timings then
   182 		ui.field.select{
   183 		  name = "free_timing",
   184 		  foreign_records = available_timings,
   185 		  foreign_id = "id",
   186 		  foreign_name = "name",
   187 		  value = param.get("free_timing")
   188 		}
   189 	      else
   190 		ui.field.text{
   191 		  name = "free_timing",
   192 		  value = param.get("free_timing")
   193 		}
   194 	      end
   195             end
   196           end
   198           if issue and issue.policy.polling and app.session.member:has_polling_right_for_unit_id(area.unit_id) then
   199             slot.put("<br />")
   200             ui.field.boolean{ name = "polling", label = _"No admission needed", value = polling }
   201           end
   203           slot.put("<br />")
   204           ui.heading { level = 2, content = _"Enter a title for your initiative (max. 140 chars):" }
   205           ui.field.text{
   206             attr = { style = "width: 100%;" },
   207             name  = "name",
   208             value = param.get("name")
   209           }
   210           ui.container { content = _"The title is the figurehead of your iniative. It should be short but meaningful! As others identifies your initiative by this title, you cannot change it later!" }
   212           if not config.enforce_formatting_engine then
   213             slot.put("<br />")
   214             ui.heading { level = 4, content = _"Choose a formatting engine:" }
   215             ui.field.select{
   216               name = "formatting_engine",
   217               foreign_records = config.formatting_engines,
   218               attr = {id = "formatting_engine"},
   219               foreign_id = "id",
   220               foreign_name = "name",
   221               value = param.get("formatting_engine")
   222             }
   223           end
   224           slot.put("<br />")
   226           ui.heading { level = 2, content = _"Enter your proposal and/or reasons:" }
   227           ui.field.text{
   228             name = "draft",
   229             multiline = true, 
   230             attr = { style = "height: 50ex; width: 100%;" },
   231             value = param.get("draft") or config.draft_template or [[
   232 Proposal
   233 ======
   235 Replace me with your proposal.
   238 Reasons
   239 ======
   241 Argument 1
   242 ------
   244 Replace me with your first argument
   247 Argument 2
   248 ------
   250 Replace me with your second argument
   252 ]]
   253           }
   254           if not issue or issue.state == "admission" or issue.state == "discussion" then
   255             ui.container { content = _"You can change your text again anytime during admission and discussion phase" }
   256           else
   257             ui.container { content = _"You cannot change your text again later, because this issue is already in verfication phase!" }
   258           end
   259           slot.put("<br />")
   260           ui.tag{
   261             tag = "input",
   262             attr = {
   263               type = "submit",
   264               name = "preview",
   265               class = "btn btn-default",
   266               value = _'Preview'
   267             },
   268             content = ""
   269           }
   270           slot.put("<br />")
   271           slot.put("<br />")
   273           if issue then
   274             ui.link{ content = _"Cancel", module = "issue", view = "show", id = issue.id }
   275           else
   276             ui.link{ content = _"Cancel", module = "area", view = "show", id = area.id }
   277           end
   278         end )
   279       end )
   280     end
   281   end
   282 }
