# HG changeset patch
# User bsw
# Date 1340144573 -7200
# Node ID 5650f8163a29e21e0d876d5a5130319b58c766ed
# Parent e7baf2713987c9db0864f0883a732421b6d3ab4e
Fixed errors from delegation dialog
diff -r e7baf2713987 -r 5650f8163a29 app/main/delegation/_action/update.lua
--- a/app/main/delegation/_action/update.lua Tue Jun 19 23:42:13 2012 +0200
+++ b/app/main/delegation/_action/update.lua Wed Jun 20 00:22:53 2012 +0200
@@ -8,6 +8,8 @@
local issue_id = param.get("issue_id", atom.integer)
+local initiative_id = param.get("initiative_id", atom.integer)
+
if issue_id then
area_id = nil
end
@@ -16,7 +18,7 @@
if preview == "1" then
request.redirect{ module = "delegation", view = "show", params = {
- unit_id = unit_id, area_id = area_id, issue_id = issue_id, preview_trustee_id = trustee_id
+ unit_id = unit_id, area_id = area_id, issue_id = issue_id, initiative_id = initiative_id, preview_trustee_id = trustee_id
} }
return
end
diff -r e7baf2713987 -r 5650f8163a29 app/main/delegation/show.lua
--- a/app/main/delegation/show.lua Tue Jun 19 23:42:13 2012 +0200
+++ b/app/main/delegation/show.lua Wed Jun 20 00:22:53 2012 +0200
@@ -38,7 +38,62 @@
util.help("delegation.new.issue")
end
-local initiative = Initiative:by_id(param.get("initiative_id", atom.integer))
+
+local delegation
+local unit_id
+local area_id
+local issue_id
+local initiative_id
+local initiative
+
+local scope = "unit"
+
+unit_id = param.get("unit_id", atom.integer)
+
+local inline = param.get("inline", atom.boolean)
+
+if param.get("initiative_id", atom.integer) then
+ initiative_id = param.get("initiative_id", atom.integer)
+ initiative = Initiative:by_id(initiative_id)
+ issue_id = initiative.issue_id
+ scope = "issue"
+end
+
+if param.get("issue_id", atom.integer) then
+ issue_id = param.get("issue_id", atom.integer)
+ scope = "issue"
+end
+
+if param.get("area_id", atom.integer) then
+ area_id = param.get("area_id", atom.integer)
+ scope = "area"
+end
+
+
+
+local delegation
+local issue
+
+if issue_id then
+ issue = Issue:by_id(issue_id)
+ delegation = Delegation:by_pk(app.session.member.id, nil, nil, issue_id)
+ if not delegation then
+ delegation = Delegation:by_pk(app.session.member.id, nil, issue.area_id)
+ end
+ if not delegation then
+ delegation = Delegation:by_pk(app.session.member.id, issue.area.unit_id)
+ end
+elseif area_id then
+ delegation = Delegation:by_pk(app.session.member.id, nil, area_id)
+ if not delegation then
+ local area = Area:by_id(area_id)
+ delegation = Delegation:by_pk(app.session.member.id, area.unit_id)
+ end
+end
+
+if not delegation then
+ delegation = Delegation:by_pk(app.session.member.id, unit_id)
+end
local contact_members = Member:build_selector{
is_contact_of_member_id = app.session.member_id,
@@ -93,13 +148,14 @@
unit_id = unit and unit.id or nil,
area_id = area and area.id or nil,
issue_id = issue and issue.id or nil,
+ initiative_id = initiative_id
},
routing = {
default = {
mode = "redirect",
module = area and "area" or initiative and "initiative" or issue and "issue" or "unit",
view = "show",
- id = area and area.id or initiative and initiative.id or issue and issue.id or unit.id
+ id = area and area.id or initiative and initiative.id or issue and issue.id or unit.id,
}
},
content = function()
@@ -182,15 +238,25 @@
end
end
-- add saved members
- records[#records+1] = {id="_", name= "--- " .. _"Saved contacts" .. " ---"}
- for i, record in ipairs(contact_members) do
- records[#records+1] = record
+ if #contact_members > 0 then
+ records[#records+1] = {id="_", name= "--- " .. _"Saved contacts" .. " ---"}
+ for i, record in ipairs(contact_members) do
+ records[#records+1] = record
+ end
end
disabled_records = {}
disabled_records["_"] = true
disabled_records[app.session.member_id] = true
+ local value = current_trustee_id
+ if preview_trustee_id then
+ value = preview_trustee_id
+ end
+ if preview_trustee_id == nil and delegation and not delegation.trustee_id then
+ value = 0
+ end
+
ui.field.select{
attr = { onchange = "updateDelegationInfo();" },
label = _"Trustee",
@@ -199,7 +265,7 @@
foreign_id = "id",
foreign_name = "name",
disabled_records = disabled_records,
- value = preview_trustee_id or current_trustee_id
+ value = value
}
ui.field.hidden{ name = "preview" }
@@ -210,134 +276,72 @@
}
-
-- ------------------------
-
-
-local delegation
-local unit_id
-local area_id
-local issue_id
-local initiative_id
-
-local scope = "unit"
-
-unit_id = param.get("unit_id", atom.integer)
+local delegation_chain = Member:new_selector()
+ :add_field("delegation_chain.*")
+ :join({ "delegation_chain(?,?,?,?,?)", app.session.member.id, unit_id, area_id, issue_id, preview_trustee_id }, "delegation_chain", "member.id = delegation_chain.member_id")
+ :add_order_by("index")
+ :exec()
-local inline = param.get("inline", atom.boolean)
-
-if param.get("initiative_id", atom.integer) then
- initiative_id = param.get("initiative_id", atom.integer)
- issue_id = Initiative:by_id(initiative_id).issue_id
- scope = "issue"
-end
-
-if param.get("issue_id", atom.integer) then
- issue_id = param.get("issue_id", atom.integer)
- scope = "issue"
+for i, record in ipairs(delegation_chain) do
+ local style
+ local overridden = (not issue or issue.state ~= 'voting') and record.overridden
+ if record.scope_in then
+ if not overridden then
+ ui.image{
+ attr = { class = "delegation_arrow" },
+ static = "delegation_arrow_24_vertical.png"
+ }
+ else
+ ui.image{
+ attr = { class = "delegation_arrow delegation_arrow_overridden" },
+ static = "delegation_arrow_24_vertical.png"
+ }
+ end
+ ui.tag{
+ attr = { class = "delegation_scope" .. (overridden and " delegation_scope_overridden" or "") },
+ content = function()
+ if record.scope_in == "unit" then
+ slot.put(config.single_object_mode and _"Global delegation" or _"Unit delegation")
+ elseif record.scope_in == "area" then
+ slot.put(_"Area delegation")
+ elseif record.scope_in == "issue" then
+ slot.put(_"Issue delegation")
+ end
+ end
+ }
+ end
+ ui.container{
+ attr = { class = overridden and "delegation_overridden" or "" },
+ content = function()
+ execute.view{
+ module = "member",
+ view = "_show_thumb",
+ params = { member = record }
+ }
+ end
+ }
+ if (not issue or issue.state ~= 'voting') and record.participation and not record.overridden then
+ ui.container{
+ attr = { class = "delegation_participation" },
+ content = function()
+ slot.put(_"This member is participating, the rest of delegation chain is suspended while discussing")
+ end
+ }
+ end
+ slot.put("
")
end
-if param.get("area_id", atom.integer) then
- area_id = param.get("area_id", atom.integer)
- scope = "area"
-end
-
-
-
-local delegation
-local issue
-
-if issue_id then
- issue = Issue:by_id(issue_id)
- delegation = Delegation:by_pk(app.session.member.id, nil, nil, issue_id)
- if not delegation then
- delegation = Delegation:by_pk(app.session.member.id, nil, issue.area_id)
- end
- if not delegation then
- delegation = Delegation:by_pk(app.session.member.id, issue.area.unit_id)
- end
-elseif area_id then
- delegation = Delegation:by_pk(app.session.member.id, nil, area_id)
- if not delegation then
- local area = Area:by_id(area_id)
- delegation = Delegation:by_pk(app.session.member.id, area.unit_id)
+if preview_trustee_id == 0 or not preview_trustee_id ==null and delegation and not delegation.trustee_id then
+ ui.image{
+ static = "icons/16/table_go_crossed.png"
+ }
+ if delegation.issue_id then
+ slot.put(_"Delegation turned off for issue")
+ elseif delegation.area_id then
+ slot.put(_"Delegation turned off for area")
end
end
-if not delegation then
- delegation = Delegation:by_pk(app.session.member.id, unit_id)
-end
-
-local slot_name = "actions"
-
-if inline then
- slot_name = "default"
-end
-
- if delegation and not delegation.trustee_id then
- ui.image{
- static = "icons/16/table_go_crossed.png"
- }
- if delegation.issue_id then
- slot.put(_"Delegation turned off for issue")
- elseif delegation.area_id then
- slot.put(_"Delegation turned off for area")
- end
- end
-
- local delegation_chain = Member:new_selector()
- :add_field("delegation_chain.*")
- :join({ "delegation_chain(?,?,?,?,?)", app.session.member.id, unit_id, area_id, issue_id, preview_trustee_id }, "delegation_chain", "member.id = delegation_chain.member_id")
- :add_order_by("index")
- :exec()
-
- for i, record in ipairs(delegation_chain) do
- local style
- local overridden = (not issue or issue.state ~= 'voting') and record.overridden
- if record.scope_in then
- if not overridden then
- ui.image{
- attr = { class = "delegation_arrow" },
- static = "delegation_arrow_24_vertical.png"
- }
- else
- ui.image{
- attr = { class = "delegation_arrow delegation_arrow_overridden" },
- static = "delegation_arrow_24_vertical.png"
- }
- end
- ui.tag{
- attr = { class = "delegation_scope" .. (overridden and " delegation_scope_overridden" or "") },
- content = function()
- if record.scope_in == "unit" then
- slot.put(config.single_object_mode and _"Global delegation" or _"Unit delegation")
- elseif record.scope_in == "area" then
- slot.put(_"Area delegation")
- elseif record.scope_in == "issue" then
- slot.put(_"Issue delegation")
- end
- end
- }
- end
- ui.container{
- attr = { class = overridden and "delegation_overridden" or "" },
- content = function()
- execute.view{
- module = "member",
- view = "_show_thumb",
- params = { member = record }
- }
- end
- }
- if (not issue or issue.state ~= 'voting') and record.participation and not record.overridden then
- ui.container{
- attr = { class = "delegation_participation" },
- content = function()
- slot.put(_"This member is participating, the rest of delegation chain is suspended while discussing")
- end
- }
- end
- slot.put("
")
- end