liquid_feedback_frontend
view app/main/initiative/_action/create.lua @ 64:3ec1dea6eefb
Bug when creating alternative initiatives fixed; Policy list link only shown when creating new issue
| author | bsw | 
|---|---|
| date | Thu Apr 22 17:05:18 2010 +0200 (2010-04-22) | 
| parents | 88ac7798b562 | 
| children | 134fce4bede3 | 
 line source
     1 local tmp = db:query({ "SELECT text_entries_left, initiatives_left FROM member_contingent_left WHERE member_id = ?", app.session.member.id }, "opt_object")
     2 if tmp then
     3   if tmp.initiatives_left and tmp.initiatives_left < 1 then
     4     slot.put_into("error", _"Sorry, your contingent for creating initiatives has been used up. Please try again later.")
     5     return false
     6   end
     7   if tmp.text_entries_left and tmp.text_entries_left < 1 then
     8     slot.put_into("error", _"Sorry, you have reached your personal flood limit. Please be slower...")
     9     return false
    10   end
    11 end
    13 local issue
    14 local area
    16 local issue_id = param.get("issue_id", atom.integer)
    17 if issue_id then
    18   issue = Issue:new_selector():add_where{"id=?",issue_id}:single_object_mode():exec()
    19   if issue.closed then
    20     slot.put_into("error", _"This issue is already closed.")
    21     return false
    22   elseif issue.fully_frozen then 
    23     slot.put_into("error", _"Voting for this issue has already begun.")
    24     return false
    25   end
    26   area = issue.area
    27 else
    28   local area_id = param.get("area_id", atom.integer)
    29   area = Area:new_selector():add_where{"id=?",area_id}:single_object_mode():exec()
    30   if not area.active then
    31     slot.put_into("error", "Invalid area.")
    32     return false
    33   end
    34 end
    38 local name = param.get("name")
    40 local name = util.trim(name)
    42 if #name < 3 then
    43   slot.put_into("error", _"This name is really too short!")
    44   return false
    45 end
    47 local initiative = Initiative:new()
    49 if not issue then
    50   local policy_id = param.get("policy_id", atom.integer)
    51   if policy_id == -1 then
    52     slot.put_into("error", _"Please choose a policy")
    53     return false
    54   end
    55   local policy = Policy:by_id(policy_id)
    56   if not policy.active then
    57     slot.put_into("error", "Invalid policy.")
    58     return false
    59   end
    60   if not area:get_reference_selector("allowed_policies")
    61     :add_where{ "policy.id = ?", policy_id }
    62     :optional_object_mode()
    63     :exec()
    64   then
    65     error("policy not allowed")
    66   end
    67   issue = Issue:new()
    68   issue.area_id = area.id
    69   issue.policy_id = policy_id
    70   issue:save()
    71 end
    73 initiative.issue_id = issue.id
    74 initiative.name = name
    75 param.update(initiative, "discussion_url")
    76 initiative:save()
    78 local draft = Draft:new()
    79 draft.initiative_id = initiative.id
    80 local formatting_engine = param.get("formatting_engine")
    81 local formatting_engine_valid = false
    82 for fe, dummy in pairs(config.formatting_engine_executeables) do
    83   if formatting_engine == fe then
    84     formatting_engine_valid = true
    85   end
    86 end
    87 if not formatting_engine_valid then
    88   error("invalid formatting engine!")
    89 end
    90 draft.formatting_engine = formatting_engine
    91 draft.content = param.get("draft")
    92 draft.author_id = app.session.member.id
    93 draft:save()
    95 local initiator = Initiator:new()
    96 initiator.initiative_id = initiative.id
    97 initiator.member_id = app.session.member.id
    98 initiator.accepted = true
    99 initiator:save()
   101 local supporter = Supporter:new()
   102 supporter.initiative_id = initiative.id
   103 supporter.member_id = app.session.member.id
   104 supporter.draft_id = draft.id
   105 supporter:save()
   107 slot.put_into("notice", _"Initiative successfully created")
   109 request.redirect{
   110   module = "initiative",
   111   view = "show",
   112   id = initiative.id
   113 }
