liquid_feedback_frontend

view model/draft.lua @ 1800:b87997219042

Updated spanish translation
author bsw
date Thu Oct 21 15:22:29 2021 +0200 (2021-10-21)
parents 17e7082c377a
children
line source
1 Draft = mondelefant.new_class()
2 Draft.table = 'draft'
4 -- Many drafts belonging to an initiative
5 Draft:add_reference{
6 mode = 'm1',
7 to = "Initiative",
8 this_key = 'initiative_id',
9 that_key = 'id',
10 ref = 'initiative',
11 }
13 -- Many drafts are authored by a member
14 Draft:add_reference{
15 mode = 'm1',
16 to = "Member",
17 this_key = 'author_id',
18 that_key = 'id',
19 ref = 'author',
20 }
22 function Draft.object_get:author_name()
23 return self.author and self.author.name or _"Unknown author"
24 end
26 model.has_rendered_content(Draft, RenderedDraft, "content", "draft_id")
28 function Draft:update_content(member_id, initiative_id, p_formatting_engine, content, external_reference, preview)
29 local initiative = Initiative:by_id(initiative_id)
31 -- TODO important m1 selectors returning result _SET_!
32 local issue = initiative:get_reference_selector("issue"):for_share():single_object_mode():exec()
34 if issue.closed then
35 slot.put_into("error", _"This issue is already closed.")
36 return false
37 elseif issue.half_frozen then
38 slot.put_into("error", _"This issue is already frozen.")
39 return false
40 elseif issue.phase_finished then
41 slot.put_into("error", _"Current phase is already closed.")
42 return false
43 end
45 local initiator = Initiator:by_pk(initiative.id, member_id)
46 if not initiator or not initiator.accepted then
47 return false
48 end
50 local tmp = db:query({ "SELECT text_entries_left FROM member_contingent_left WHERE member_id = ? AND polling = ?", member_id, initiative.polling }, "opt_object")
51 if not tmp or tmp.text_entries_left < 1 then
52 slot.put_into("error", _"Sorry, you have reached your personal flood limit. Please be slower...")
53 return false
54 end
56 local formatting_engine
57 if config.enforce_formatting_engine then
58 formatting_engine = config.enforce_formatting_engine
59 else
60 formatting_engine = p_formatting_engine
62 local formatting_engine_valid = false
63 for i, fe in pairs(config.formatting_engines) do
64 if formatting_engine == fe.id then
65 formatting_engine_valid = true
66 end
67 end
68 if not formatting_engine_valid then
69 error("invalid formatting engine!")
70 end
71 end
73 if preview then
74 return false
75 end
77 local old_draft = initiative.current_draft
79 local draft = Draft:new()
80 draft.author_id = member_id
81 draft.initiative_id = initiative.id
82 draft.formatting_engine = formatting_engine or old_draft and old_draft.formatting_engine or nil
83 draft.content = content or old_draft and old_draft.content or nil
84 if external_reference == false then
85 draft.external_reference = nil
86 else
87 draft.external_reference = external_reference or old_draft and old_draft.external_reference or nil
88 end
89 draft:save()
91 local supporter = Supporter:by_pk(initiative.id, member_id)
93 if supporter then
94 supporter.draft_id = draft.id
95 supporter:save()
96 end
98 draft:render_content()
100 local draft_attachments = DraftAttachment:new_selector()
101 :add_where{ "draft_id = ?", old_draft.id }
102 :exec()
104 for i, draft_attachment in ipairs(draft_attachments) do
105 local new_draft_attachment = DraftAttachment:new()
106 new_draft_attachment.draft_id = draft.id
107 new_draft_attachment.file_id = draft_attachment.file_id
108 new_draft_attachment.title = draft_attachment.title
109 new_draft_attachment.description = draft_attachment.description
110 new_draft_attachment:save()
111 end
113 slot.put_into("notice", _"The initiative text has been updated")
114 return draft.id
115 end

Impressum / About Us