liquid_feedback_frontend
view app/main/initiative/_action/create.lua @ 1042:e2875fedb3f4
Fixed syntax error in translations.el.lua
| author | jbe | 
|---|---|
| date | Wed Oct 09 20:16:30 2013 +0200 (2013-10-09) | 
| parents | c23a25f38c44 | 
| children | 701a5cf6b067 | 
 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}:for_share():single_object_mode():exec()
     7   if issue.closed then
     8     slot.put_into("error", _"This issue is already closed.")
     9     return false
    10   elseif issue.fully_frozen then 
    11     slot.put_into("error", _"Voting for this issue has already begun.")
    12     return false
    13   elseif issue.phase_finished then
    14     slot.put_into("error", _"Current phase is already closed.")
    15     return false
    16   end
    17   area = issue.area
    18 else
    19   local area_id = param.get("area_id", atom.integer)
    20   area = Area:new_selector():add_where{"id=?",area_id}:single_object_mode():exec()
    21   if not area.active then
    22     slot.put_into("error", "Invalid area.")
    23     return false
    24   end
    25 end
    27 if not app.session.member:has_voting_right_for_unit_id(area.unit_id) then
    28   error("access denied")
    29 end
    31 local policy_id = param.get("policy_id", atom.integer)
    32 local policy
    33 if policy_id then
    34   policy = Policy:by_id(policy_id)
    35 end
    37 if not issue then
    38   if policy_id == -1 then
    39     slot.put_into("error", _"Please choose a policy")
    40     return false
    41   end
    42   if not policy.active then
    43     slot.put_into("error", "Invalid policy.")
    44     return false
    45   end
    46   if policy.polling and not app.session.member:has_polling_right_for_unit_id(area.unit_id) then
    47     error("no polling right for this unit")
    48   end
    50   if not area:get_reference_selector("allowed_policies")
    51     :add_where{ "policy.id = ?", policy_id }
    52     :optional_object_mode()
    53     :exec()
    54   then
    55     error("policy not allowed")
    56   end
    57 end
    59 local is_polling = (issue and param.get("polling", atom.boolean)) or (policy and policy.polling) or false
    61 local tmp = db:query({ "SELECT text_entries_left, initiatives_left FROM member_contingent_left WHERE member_id = ? AND polling = ?", app.session.member.id, is_polling }, "opt_object")
    62 if not tmp or tmp.initiatives_left < 1 then
    63   slot.put_into("error", _"Sorry, your contingent for creating initiatives has been used up. Please try again later.")
    64   return false
    65 end
    66 if tmp and tmp.text_entries_left < 1 then
    67   slot.put_into("error", _"Sorry, you have reached your personal flood limit. Please be slower...")
    68   return false
    69 end
    71 local name = param.get("name")
    73 local name = util.trim(name)
    75 if #name < 3 then
    76   slot.put_into("error", _"This name is really too short!")
    77   return false
    78 end
    80 local formatting_engine = param.get("formatting_engine")
    82 local formatting_engine_valid = false
    83 for fe, dummy in pairs(config.formatting_engine_executeables) do
    84   if formatting_engine == fe then
    85     formatting_engine_valid = true
    86   end
    87 end
    88 if not formatting_engine_valid then
    89   error("invalid formatting engine!")
    90 end
    92 if param.get("preview") then
    93   return
    94 end
    97 local initiative = Initiative:new()
    99 if not issue then
   100   issue = Issue:new()
   101   issue.area_id = area.id
   102   issue.policy_id = policy_id
   104   if policy.polling then
   105     issue.accepted = 'now'
   106     issue.state = 'discussion'
   107     initiative.polling = true
   109     if policy.free_timeable then
   110       local free_timing_string = util.trim(param.get("free_timing"))
   111       local available_timings
   112       if config.free_timing and config.free_timing.available_func then
   113         available_timings = config.free_timing.available_func(policy)
   114         if available_timings == false then
   115           error("error in free timing config")
   116         end
   117       end
   118       if available_timings then
   119         local timing_available = false
   120         for i, available_timing in ipairs(available_timings) do
   121           if available_timing.id == free_timing_string then
   122             timing_available = true
   123           end
   124         end
   125         if not timing_available then
   126           error('Invalid timing')
   127         end
   128       end
   129       local timing = config.free_timing.calculate_func(policy, free_timing_string)
   130       if not timing then
   131         error("error in free timing config")
   132       end
   133       issue.discussion_time = timing.discussion
   134       issue.verification_time = timing.verification
   135       issue.voting_time = timing.voting
   136     end
   138   end
   140   issue:save()
   142   if config.etherpad then
   143     local result = net.curl(
   144       config.etherpad.api_base 
   145       .. "api/1/createGroupPad?apikey=" .. config.etherpad.api_key
   146       .. "&groupID=" .. config.etherpad.group_id
   147       .. "&padName=Issue" .. tostring(issue.id)
   148       .. "&text=" .. request.get_absolute_baseurl() .. "issue/show/" .. tostring(issue.id) .. ".html"
   149     )
   150   end
   151 end
   153 if param.get("polling", atom.boolean) and app.session.member:has_polling_right_for_unit_id(area.unit_id) then
   154   initiative.polling = true
   155 end
   156 initiative.issue_id = issue.id
   157 initiative.name = name
   158 param.update(initiative, "discussion_url")
   159 initiative:save()
   161 local draft = Draft:new()
   162 draft.initiative_id = initiative.id
   163 draft.formatting_engine = formatting_engine
   164 draft.content = param.get("draft")
   165 draft.author_id = app.session.member.id
   166 draft:save()
   168 local initiator = Initiator:new()
   169 initiator.initiative_id = initiative.id
   170 initiator.member_id = app.session.member.id
   171 initiator.accepted = true
   172 initiator:save()
   174 if not is_polling then
   175   local supporter = Supporter:new()
   176   supporter.initiative_id = initiative.id
   177   supporter.member_id = app.session.member.id
   178   supporter.draft_id = draft.id
   179   supporter:save()
   180 end
   182 slot.put_into("notice", _"Initiative successfully created")
   184 request.redirect{
   185   module = "initiative",
   186   view = "show",
   187   id = initiative.id
   188 }
