def distribution_rheader(r): if r.representation == "html": distribution = r.record if distribution: T = current.T tabs = [ (T("Edit Details"), None), (T("Beneficiaries"), "person"), ] from s3 import s3_rheader_tabs rheader_tabs = s3_rheader_tabs(r, tabs) table = r.table rheader = DIV( TABLE( TR( TH("%s: " % table.parameter_id.label), table.parameter_id.represent( distribution.parameter_id), ), TR( TH("%s: " % table.date.label), table.date.represent(distribution.date), ), #TR(TH("%s: " % table.location_id.label), # table.location_id.represent(distribution.location_id), # ), #TR(TH("%s: " % table.organisation_id.label), # table.organisation_id.represent(distribution.organisation_id), # ), ), rheader_tabs) return rheader return None
def fire_rheader(r, tabs=[]): """ Resource headers for component views """ rheader = None if r.representation == "html": if r.name == "station": station = r.record if station: tabs = [ (T("Station Details"), None), (T("Staff"), "human_resource"), (T("Shifts"), "shift"), # @ToDo: #(T("Roster"), "shift_staff"), (T("Vehicles"), "vehicle"), (T("Vehicle Deployments"), "vehicle_report"), (T("Assets"), "asset"), ] from s3 import s3_rheader_tabs rheader_tabs = s3_rheader_tabs(r, tabs) rheader = DIV(rheader_tabs) return rheader
def mavc_rheader(r, tabs=None): """ Custom rheaders """ if r.representation != "html": return None from s3 import s3_rheader_resource, s3_rheader_tabs from gluon import A, DIV, H1, H2, TAG tablename, record = s3_rheader_resource(r) if record is None: return None T = current.T s3db = current.s3db if tablename != r.tablename: resource = s3db.resource(tablename, id=record.id if record else None) else: resource = r.resource rheader = "" if tablename == "org_organisation": # Tabs if not tabs: INDIVIDUALS = current.deployment_settings.get_hrm_staff_label() tabs = [ (T("About"), None), (INDIVIDUALS, "human_resource"), (T("Service Locations"), "service_location"), # @todo: activities ] # Use OrganisationRepresent for title to get L10n name if available represent = s3db.org_OrganisationRepresent(acronym=False, parent=False) title = represent(record.id) # Retrieve other details for the rheader data = resource.select(["organisation_organisation_type.organisation_type_id", "website"], represent=True) row = data.rows[0] subtitle = row["org_organisation_organisation_type.organisation_type_id"] website = row["org_organisation.website"] # Compile the rheader rheader = DIV(DIV(H1(title), H2(subtitle), website if record.website else "", _class="rheader-details")) if tabs: rheader_tabs = s3_rheader_tabs(r, tabs) rheader.append(rheader_tabs) return rheader
def patient_rheader(r, tabs=[]): """ Resource Page Header """ if r.representation == "html": if r.record is None: # List or Create form: rheader makes no sense here return None table = db.patient_patient from s3 import s3_rheader_tabs rheader_tabs = s3_rheader_tabs(r, tabs) patient = r.record if patient.person_id: from s3 import s3_fullname name = s3_fullname(patient.person_id) else: name = None if patient.country: country = table.country.represent(patient.country) else: country = None if patient.hospital_id: hospital = table.hospital_id.represent(patient.hospital_id) else: hospital = None rheader = DIV( TABLE( TR(TH("%s: " % T("Patient")), name, TH("%s: " % COUNTRY), country), TR( TH(), TH(), TH("%s: " % T("Hospital")), hospital, )), rheader_tabs) return rheader return None
def nzseel2_rheader(r, tabs=[]): """ Resource Headers """ if r.representation == "html": if r.name == "nzseel2": assess = r.record if assess: table = r.table from s3 import s3_rheader_tabs rheader_tabs = s3_rheader_tabs(r, tabs) location = assess.location_id if location: location = table.location_id.represent(location) person = assess.person_id if person: query = (db.pr_person.id == person) pe_id = db(query).select(db.pr_person.pe_id, limitby=(0, 1)).first().pe_id query = (db.pr_contact.pe_id == pe_id) & \ (db.pr_contact.contact_method == "SMS") mobile = db(query).select(db.pr_contact.value, limitby=(0, 1)).first() if mobile: mobile = mobile.value from s3 import s3_fullname person = s3_fullname(person) rheader = DIV(TABLE( TR( TH("%s: " % T("Person")), person, TH("%s: " % T("Mobile")), mobile, ), TR( TH("%s: " % T("Location")), location, TH("%s: " % T("Date")), table.date.represent(assess.date) ), TR( TH(""), "", TH("%s: " % T("Ticket ID")), r.table.ticket_id.represent(assess.ticket_id), ), ), rheader_tabs) return rheader return None
def group_rheader(r, tabs=[]): """ Group rheader """ if r.representation == "html": if r.record is None: # List or Create form: rheader makes no sense here return None tabs = [ (T("Basic Details"), None), (T("Problems"), "problem"), ] group = r.record # Get this User's permissions for this Group duser = s3db.delphi_DelphiUser(group.id) if duser.authorised: tabs.append((T("Membership"), "membership")) from s3 import s3_rheader_tabs rheader_tabs = s3_rheader_tabs(r, tabs) rheader = DIV( TABLE( TR( TH("%s: " % T("Group")), group.name, ), TR( TH("%s: " % T("Description")), group.description, ), TR( TH("%s: " % T("Active")), group.active, ), ), rheader_tabs) return rheader
def drk_org_rheader(r, tabs=None): """ ORG custom resource headers """ if r.representation != "html": # Resource headers only used in interactive views return None from s3 import s3_rheader_resource, s3_rheader_tabs, S3ResourceHeader from .uioptions import get_ui_options s3db = current.s3db tablename, record = s3_rheader_resource(r) if tablename != r.tablename: resource = s3db.resource(tablename, id=record.id) else: resource = r.resource rheader = None rheader_fields = [] if record: T = current.T record_id = record.id ui_options = get_ui_options() is_admin = current.auth.s3_has_role("ADMIN") if tablename == "org_organisation": table = resource.table if record.root_organisation == record_id: branch = False else: branch = True # Custom tabs tabs = [(T("Basic Details"), None), (T("Branches"), "branch"), (T("Facilities"), "facility"), (T("Staff & Volunteers"), "human_resource"), #(T("Projects"), "project"), (T("Counseling Themes"), "response_theme"), ] if is_admin or ui_options.get("response_themes_needs"): # Ability to manage org-specific need types # as they are used in themes: tabs.append((T("Counseling Reasons"), "need")) if not branch and \ (is_admin or \ ui_options.get("case_document_templates") and \ current.auth.s3_has_role("ORG_ADMIN")): tabs.append((T("Document Templates"), "document")) rheader_tabs = s3_rheader_tabs(r, tabs) # Custom header from gluon import TABLE, TR, TH, TD rheader = DIV() # Name record_data = TABLE(TR(TH("%s: " % table.name.label), record.name, ), ) # Parent Organisation if branch: btable = s3db.org_organisation_branch query = (btable.branch_id == record_id) & \ (btable.organisation_id == table.id) row = current.db(query).select(table.id, table.name, limitby = (0, 1), ).first() if row: record_data.append(TR(TH("%s: " % T("Branch of")), A(row.name, _href=URL(args=[row.id, "read"])), )) # Website as link if record.website: record_data.append(TR(TH("%s: " % table.website.label), A(record.website, _href=record.website))) logo = s3db.org_organisation_logo(record) if logo: rheader.append(TABLE(TR(TD(logo), TD(record_data), ))) else: rheader.append(record_data) rheader.append(rheader_tabs) return rheader elif tablename == "org_facility": if not tabs: tabs = [(T("Basic Details"), None), ] rheader_fields = [["name", "email"], ["organisation_id", "phone1"], ["location_id", "phone2"], ] rheader = S3ResourceHeader(rheader_fields, tabs)(r, table=resource.table, record=record, ) return rheader
def event_rheader(r): rheader = None record = r.record if record and r.representation == "html": from gluon import A, DIV, TABLE, TR, TH from s3 import s3_rheader_tabs name = r.name if name == "incident": tabs = [ (T("Incident Details"), None), #(T("Tasks"), "task"), #(T("Human Resources"), "human_resource"), #(T("Equipment"), "asset"), (T("Action Plan"), "plan"), (T("Incident Reports"), "incident_report"), (T("Logs"), "log"), (T("Expenses"), "expense"), (T("Situation Reports"), "sitrep"), ] rheader_tabs = s3_rheader_tabs(r, tabs) record_id = r.id incident_type_id = record.incident_type_id # Dropdown of Scenarios to select stable = current.s3db.event_scenario query = (stable.incident_type_id == incident_type_id) & \ (stable.deleted == False) scenarios = current.db(query).select( stable.id, stable.name, ) if len(scenarios) and r.method != "event": from gluon import SELECT, OPTION dropdown = SELECT(_id="scenarios") dropdown["_data-incident_id"] = record_id dappend = dropdown.append dappend(OPTION(T("Select Scenario"))) for s in scenarios: dappend(OPTION(s.name, _value=s.id)) scenarios = TR( TH("%s: " % T("Scenario")), dropdown, ) s3 = current.response.s3 script = "/%s/static/themes/SAFIRE/js/incident_profile.js" % r.application if script not in s3.scripts: s3.scripts.append(script) s3.js_global.append('''i18n.scenarioConfirm="%s"''' % T( "Populate Incident with Tasks, Organizations, Positions and Equipment from the Scenario?" )) else: scenarios = "" if record.exercise: exercise = TH(T("EXERCISE")) else: exercise = TH() if record.closed: closed = TH(T("CLOSED")) else: closed = TH() if record.event_id or r.method == "event": event = "" else: event = A(T("Assign to Event"), _href=URL( c="event", f="incident", args=[record_id, "event"], ), _class="action-btn") table = r.table rheader = DIV( TABLE( TR(exercise), TR( TH("%s: " % table.name.label), record.name, ), TR( TH("%s: " % table.incident_type_id.label), table.incident_type_id.represent(incident_type_id), ), TR( TH("%s: " % table.location_id.label), table.location_id.represent(record.location_id), ), # @ToDo: Add Zone TR( TH("%s: " % table.severity.label), table.severity.represent(record.severity), ), TR( TH("%s: " % table.level.label), table.level.represent(record.level), ), TR( TH("%s: " % table.organisation_id.label), table.organisation_id.represent( record.organisation_id), ), TR( TH("%s: " % table.person_id.label), table.person_id.represent(record.person_id), ), scenarios, TR( TH("%s: " % table.comments.label), record.comments, ), TR( TH("%s: " % table.date.label), table.date.represent(record.date), ), TR(closed), event, ), rheader_tabs) elif name == "incident_report": record_id = r.id ltable = current.s3db.event_incident_report_incident query = (ltable.incident_report_id == record_id) link = current.db(query).select(ltable.incident_id, limitby=(0, 1)).first() if link: from s3 import S3Represent represent = S3Represent(lookup="event_incident", show_link=True) rheader = DIV( TABLE( TR( TH("%s: " % ltable.incident_id.label), represent(link.incident_id), ), )) else: rheader = DIV( A(T("Assign to Incident"), _href=URL( c="event", f="incident_report", args=[record_id, "assign"], ), _class="action-btn")) elif name == "event": tabs = [ (T("Event Details"), None), (T("Incidents"), "incident"), (T("Documents"), "document"), (T("Photos"), "image"), ] rheader_tabs = s3_rheader_tabs(r, tabs) table = r.table rheader = DIV( TABLE( TR( TH("%s: " % table.event_type_id.label), table.event_type_id.represent( record.event_type_id), ), TR( TH("%s: " % table.name.label), record.name, ), TR( TH("%s: " % table.start_date.label), table.start_date.represent(record.start_date), ), TR( TH("%s: " % table.comments.label), record.comments, ), ), rheader_tabs) elif name == "scenario": tabs = [ (T("Scenario Details"), None), #(T("Tasks"), "task"), #(T("Human Resources"), "human_resource"), #(T("Equipment"), "asset"), (T("Action Plan"), "plan"), (T("Incident Reports"), "incident_report"), ] rheader_tabs = s3_rheader_tabs(r, tabs) table = r.table rheader = DIV( TABLE( TR( TH("%s: " % table.incident_type_id.label), table.incident_type_id.represent( record.incident_type_id), ), TR( TH("%s: " % table.organisation_id.label), table.organisation_id.represent( record.organisation_id), ), TR( TH("%s: " % table.location_id.label), table.location_id.represent(record.location_id), ), TR( TH("%s: " % table.name.label), record.name, ), TR( TH("%s: " % table.comments.label), record.comments, ), ), rheader_tabs) return rheader
def mavc_rheader(r, tabs=None): """ Custom rheaders """ if r.representation != "html": return None from s3 import s3_rheader_resource, s3_rheader_tabs from gluon import A, DIV, H1, H2, TAG tablename, record = s3_rheader_resource(r) if record is None: return None T = current.T s3db = current.s3db if tablename != r.tablename: resource = s3db.resource(tablename, id = record.id if record else None, ) else: resource = r.resource rheader = "" if tablename == "org_organisation": # Tabs if not tabs: INDIVIDUALS = current.deployment_settings.get_hrm_staff_label() tabs = [(T("About"), None), (INDIVIDUALS, "human_resource"), (T("Services"), "service_location"), (T("Facilities"), "facility"), (T("Projects"), "project"), (T("Attachments"), "document"), ] # Use OrganisationRepresent for title to get L10n name if available represent = s3db.org_OrganisationRepresent(acronym=False, parent=False, ) title = represent(record.id) # Retrieve details for the rheader data = resource.select(["organisation_organisation_type.organisation_type_id", "country", "website", ], raw_data = True, represent = True, ) row = data.rows[0] raw = row["_row"] # Construct subtitle subtitle_fields = ("org_organisation_organisation_type.organisation_type_id", "org_organisation.country", ) items = [] for fname in subtitle_fields: if raw[fname]: items.append(s3_unicode(row[fname])) subtitle = ", ".join(items) # Website website = row["org_organisation.website"] # Compose the rheader rheader = DIV(DIV(H1(title), H2(subtitle), website if record.website else "", _class="rheader-details", ), ) elif tablename == "project_project": if not tabs: tabs = [(T("About"), None), (T("Locations"), "location"), (T("Attachments"), "document"), ] # Retrieve details for the rheader data = resource.select(["name", "organisation_id", ], represent = True, ) row = data.rows[0] # Title and Subtitle title = row["project_project.name"] subtitle = row["project_project.organisation_id"] # Compose the rheader rheader = DIV(DIV(H1(title), H2(subtitle), _class="rheader-details", ), ) elif tablename == "pr_person": if not tabs: tabs = [(T("Person Details"), None), ] from s3 import s3_fullname title = s3_fullname(record) # Link organisation_id representation to staff tab linkto = URL(c = "org", f = "organisation", args = ["[id]", "human_resource"], ) htable = s3db.hrm_human_resource field = htable.organisation_id field.represent = s3db.org_OrganisationRepresent(show_link = True, linkto = linkto, ) # Retrieve details for the rheader data = resource.select(["human_resource.job_title_id", "human_resource.organisation_id", ], raw_data = True, represent = True, ) row = data.rows[0] raw = row["_row"] # Construct subtitle organisation_id = raw["hrm_human_resource.organisation_id"] if organisation_id: subtitle = row["hrm_human_resource.organisation_id"] job_title_id = raw["hrm_human_resource.job_title_id"] if job_title_id: subtitle = TAG[""]("%s, " % row["hrm_human_resource.job_title_id"], subtitle, ) # Compose the rheader rheader = DIV(DIV(H1(title), H2(subtitle), _class="rheader-details", ), ) if tabs: rheader_tabs = s3_rheader_tabs(r, tabs) rheader.append(rheader_tabs) return rheader
def event_rheader(r): rheader = None record = r.record if record and r.representation == "html": from gluon import DIV, TABLE, TR, TH from s3 import s3_rheader_tabs name = r.name if name == "incident": # Incident Controller tabs = [ (T("Incident Details"), None), #(T("Tasks"), "task"), #(T("Human Resources"), "human_resource"), #(T("Equipment"), "asset"), (T("Action Plan"), "plan"), (T("Incident Reports"), "incident_report"), ] rheader_tabs = s3_rheader_tabs(r, tabs) incident_type_id = record.incident_type_id # Dropdown of Scenarios to select stable = current.s3db.event_scenario query = (stable.incident_type_id == incident_type_id) & \ (stable.deleted == False) scenarios = current.db(query).select( stable.id, stable.name, ) if len(scenarios): from gluon import SELECT, OPTION dropdown = SELECT(_id="scenarios") dropdown["_data-incident_id"] = r.id dappend = dropdown.append dappend(OPTION(T("Select Scenario"))) for s in scenarios: dappend(OPTION(s.name, _value=s.id)) scenarios = TR( TH("%s: " % T("Scenario")), dropdown, ) s3 = current.response.s3 script = "/%s/static/themes/SAFIRE/js/incident_profile.js" % r.application if script not in s3.scripts: s3.scripts.append(script) s3.js_global.append('''i18n.scenarioConfirm="%s"''' % T( "Populate Incident with Tasks, Positions and Equipment from the Scenario?" )) else: scenarios = "" if record.exercise: exercise = TH(T("EXERCISE")) else: exercise = TH() if record.closed: closed = TH(T("CLOSED")) else: closed = TH() table = r.table rheader = DIV( TABLE( TR(exercise), TR( TH("%s: " % table.name.label), record.name, ), TR( TH("%s: " % table.incident_type_id.label), table.incident_type_id.represent(incident_type_id), ), TR( TH("%s: " % table.person_id.label), table.person_id.represent(record.person_id), ), scenarios, TR( TH("%s: " % table.location_id.label), table.location_id.represent(record.location_id), ), TR( TH("%s: " % table.comments.label), record.comments, ), TR( TH("%s: " % table.date.label), table.date.represent(record.date), ), TR(closed), ), rheader_tabs) elif name == "scenario": # Scenarios Controller tabs = [ (T("Scenario Details"), None), #(T("Tasks"), "task"), #(T("Human Resources"), "human_resource"), #(T("Equipment"), "asset"), (T("Action Plan"), "plan"), (T("Incident Reports"), "incident_report"), ] rheader_tabs = s3_rheader_tabs(r, tabs) table = r.table rheader = DIV( TABLE( TR( TH("%s: " % table.incident_type_id.label), table.incident_type_id.represent( record.incident_type_id), ), TR( TH("%s: " % table.name.label), record.name, ), TR( TH("%s: " % table.comments.label), record.comments, ), ), rheader_tabs) return rheader
def event_rheader(r): rheader = None record = r.record if record and r.representation == "html": from gluon import A, DIV, TABLE, TR, TH from s3 import s3_rheader_tabs name = r.name if name == "incident": # Incident Controller tabs = [(T("Incident Details"), None), #(T("Tasks"), "task"), #(T("Human Resources"), "human_resource"), #(T("Equipment"), "asset"), (T("Action Plan"), "plan"), (T("Incident Reports"), "incident_report"), (T("Situation Reports"), "sitrep"), ] rheader_tabs = s3_rheader_tabs(r, tabs) record_id = r.id incident_type_id = record.incident_type_id # Dropdown of Scenarios to select stable = current.s3db.event_scenario query = (stable.incident_type_id == incident_type_id) & \ (stable.deleted == False) scenarios = current.db(query).select(stable.id, stable.name, ) if len(scenarios) and r.method != "event": from gluon import SELECT, OPTION dropdown = SELECT(_id="scenarios") dropdown["_data-incident_id"] = record_id dappend = dropdown.append dappend(OPTION(T("Select Scenario"))) for s in scenarios: dappend(OPTION(s.name, _value=s.id)) scenarios = TR(TH("%s: " % T("Scenario")), dropdown, ) s3 = current.response.s3 script = "/%s/static/themes/SAFIRE/js/incident_profile.js" % r.application if script not in s3.scripts: s3.scripts.append(script) s3.js_global.append('''i18n.scenarioConfirm="%s"''' % T("Populate Incident with Tasks, Positions and Equipment from the Scenario?")) else: scenarios = "" if record.exercise: exercise = TH(T("EXERCISE")) else: exercise = TH() if record.closed: closed = TH(T("CLOSED")) else: closed = TH() if record.event_id or r.method == "event": event = "" else: event = A(T("Assign to Event"), _href = URL(c = "event", f = "incident", args = [record_id, "event"], ), _class = "action-btn" ) table = r.table rheader = DIV(TABLE(TR(exercise), TR(TH("%s: " % table.name.label), record.name, ), TR(TH("%s: " % table.incident_type_id.label), table.incident_type_id.represent(incident_type_id), ), TR(TH("%s: " % table.person_id.label), table.person_id.represent(record.person_id), ), scenarios, TR(TH("%s: " % table.location_id.label), table.location_id.represent(record.location_id), ), TR(TH("%s: " % table.comments.label), record.comments, ), TR(TH("%s: " % table.date.label), table.date.represent(record.date), ), TR(closed), event, ), rheader_tabs) elif name == "event": # Events Controller tabs = [(T("Event Details"), None), (T("Incidents"), "incident"), (T("Documents"), "document"), (T("Photos"), "image"), ] rheader_tabs = s3_rheader_tabs(r, tabs) table = r.table rheader = DIV(TABLE(TR(TH("%s: " % table.event_type_id.label), table.event_type_id.represent(record.event_type_id), ), TR(TH("%s: " % table.name.label), record.name, ), TR(TH("%s: " % table.start_date.label), table.start_date.represent(record.start_date), ), TR(TH("%s: " % table.comments.label), record.comments, ), ), rheader_tabs) elif name == "scenario": # Scenarios Controller tabs = [(T("Scenario Details"), None), #(T("Tasks"), "task"), #(T("Human Resources"), "human_resource"), #(T("Equipment"), "asset"), (T("Action Plan"), "plan"), (T("Incident Reports"), "incident_report"), ] rheader_tabs = s3_rheader_tabs(r, tabs) table = r.table rheader = DIV(TABLE(TR(TH("%s: " % table.incident_type_id.label), table.incident_type_id.represent(record.incident_type_id), ), TR(TH("%s: " % table.name.label), record.name, ), TR(TH("%s: " % table.comments.label), record.comments, ), ), rheader_tabs) return rheader
def mavc_rheader(r, tabs=None): """ Custom rheaders """ if r.representation != "html": return None from s3 import s3_rheader_resource, s3_rheader_tabs from gluon import A, DIV, H1, H2, TAG tablename, record = s3_rheader_resource(r) if record is None: return None T = current.T s3db = current.s3db if tablename != r.tablename: resource = s3db.resource( tablename, id=record.id if record else None, ) else: resource = r.resource rheader = "" if tablename == "org_organisation": # Tabs if not tabs: INDIVIDUALS = current.deployment_settings.get_hrm_staff_label() tabs = [ (T("About"), None), (INDIVIDUALS, "human_resource"), (T("Services"), "service_location"), (T("Facilities"), "facility"), (T("Projects"), "project"), ] # Use OrganisationRepresent for title to get L10n name if available represent = s3db.org_OrganisationRepresent( acronym=False, parent=False, ) title = represent(record.id) # Retrieve details for the rheader data = resource.select( [ "organisation_organisation_type.organisation_type_id", "country", "website", ], raw_data=True, represent=True, ) row = data.rows[0] raw = row["_row"] # Construct subtitle subtitle_fields = ( "org_organisation_organisation_type.organisation_type_id", "org_organisation.country", ) items = [] for fname in subtitle_fields: if raw[fname]: items.append(s3_unicode(row[fname])) subtitle = ", ".join(items) # Website website = row["org_organisation.website"] # Compile the rheader rheader = DIV( DIV( H1(title), H2(subtitle), website if record.website else "", _class="rheader-details", ), ) if tabs: rheader_tabs = s3_rheader_tabs(r, tabs) rheader.append(rheader_tabs) return rheader
def mavc_rheader(r, tabs=None): """ Custom rheaders """ if r.representation != "html": return None from s3 import s3_rheader_resource, s3_rheader_tabs from gluon import A, DIV, H1, H2, TAG tablename, record = s3_rheader_resource(r) if record is None: return None T = current.T s3db = current.s3db if tablename != r.tablename: resource = s3db.resource( tablename, id=record.id if record else None, ) else: resource = r.resource rheader = "" if tablename == "org_organisation": # Tabs if not tabs: INDIVIDUALS = current.deployment_settings.get_hrm_staff_label() tabs = [ (T("About"), None), (INDIVIDUALS, "human_resource"), (T("Services"), "service_location"), (T("Facilities"), "facility"), (T("Projects"), "project"), (T("Attachments"), "document"), ] # Use OrganisationRepresent for title to get L10n name if available represent = s3db.org_OrganisationRepresent( acronym=False, parent=False, ) title = represent(record.id) # Retrieve details for the rheader data = resource.select( [ "organisation_organisation_type.organisation_type_id", "country", "website", ], raw_data=True, represent=True, ) row = data.rows[0] raw = row["_row"] # Construct subtitle subtitle_fields = ( "org_organisation_organisation_type.organisation_type_id", "org_organisation.country", ) items = [] for fname in subtitle_fields: if raw[fname]: items.append(s3_unicode(row[fname])) subtitle = ", ".join(items) # Website website = row["org_organisation.website"] # Compose the rheader rheader = DIV( DIV( H1(title), H2(subtitle), website if record.website else "", _class="rheader-details", ), ) elif tablename == "project_project": if not tabs: tabs = [ (T("About"), None), (T("Locations"), "location"), (T("Attachments"), "document"), ] # Retrieve details for the rheader data = resource.select( [ "name", "organisation_id", ], represent=True, ) row = data.rows[0] # Title and Subtitle title = row["project_project.name"] subtitle = row["project_project.organisation_id"] # Compose the rheader rheader = DIV(DIV( H1(title), H2(subtitle), _class="rheader-details", ), ) elif tablename == "pr_person": if not tabs: tabs = [ (T("Person Details"), None), ] from s3 import s3_fullname title = s3_fullname(record) # Link organisation_id representation to staff tab linkto = URL( c="org", f="organisation", args=["[id]", "human_resource"], ) htable = s3db.hrm_human_resource field = htable.organisation_id field.represent = s3db.org_OrganisationRepresent( show_link=True, linkto=linkto, ) # Retrieve details for the rheader data = resource.select( [ "human_resource.job_title_id", "human_resource.organisation_id", ], raw_data=True, represent=True, ) row = data.rows[0] raw = row["_row"] # Construct subtitle organisation_id = raw["hrm_human_resource.organisation_id"] if organisation_id: subtitle = row["hrm_human_resource.organisation_id"] job_title_id = raw["hrm_human_resource.job_title_id"] if job_title_id: subtitle = TAG[""]( "%s, " % row["hrm_human_resource.job_title_id"], subtitle, ) # Compose the rheader rheader = DIV(DIV( H1(title), H2(subtitle), _class="rheader-details", ), ) if tabs: rheader_tabs = s3_rheader_tabs(r, tabs) rheader.append(rheader_tabs) return rheader
def event_rheader(r): rheader = None record = r.record if record and r.representation == "html": from gluon import A, DIV, TABLE, TR, TH from s3 import s3_rheader_tabs name = r.name if name == "incident": if settings.get_incident_label(): # == "Ticket" label = T("Ticket Details") else: label = T("Incident Details") tabs = [ (label, None), #(T("Tasks"), "task"), #(T("Human Resources"), "human_resource"), #(T("Equipment"), "asset"), (T("Action Plan"), "plan"), (T("Incident Reports"), "incident_report"), (T("Logs"), "log"), (T("Expenses"), "expense"), (T("Situation Reports"), "sitrep"), ] rheader_tabs = s3_rheader_tabs(r, tabs) record_id = r.id incident_type_id = record.incident_type_id editable = current.auth.s3_has_permission( "UPDATE", "event_incident", record_id) if editable and r.method == "plan": # Dropdown of Scenarios to select # @ToDo: Move this to a Popup behind an Action Button, to make it clearer that this isn't a maintained link # @ToDo: Also add 'Clear' button to clear all elements & start from a blank slate stable = current.s3db.event_scenario query = (stable.incident_type_id == incident_type_id) & \ (stable.deleted == False) scenarios = current.db(query).select( stable.id, stable.name, ) if len(scenarios) and r.method != "event": from gluon import SELECT, OPTION dropdown = SELECT(_id="scenarios") dropdown["_data-incident_id"] = record_id dappend = dropdown.append dappend(OPTION(T("Select Scenario"))) for s in scenarios: dappend(OPTION(s.name, _value=s.id)) scenarios = TR( TH("%s: " % T("Apply Scenario")), dropdown, ) s3 = current.response.s3 script = "/%s/static/themes/SAFIRE/js/incident_profile.js" % r.application if script not in s3.scripts: s3.scripts.append(script) s3.js_global.append( '''i18n.scenarioConfirm="%s"''' % T("Populate Incident with Tasks, Organizations, Positions and Equipment from the Scenario?" )) else: scenarios = "" else: scenarios = "" if record.exercise: exercise = TH(T("EXERCISE")) else: exercise = TH() if record.closed: closed = TH(T("CLOSED")) else: closed = TH() if record.event_id or r.method == "event" or not editable: event = "" else: if settings.get_event_label(): # == "Disaster" label = T("Assign to Disaster") else: label = T("Assign to Event") event = A(label, _href=URL( c="event", f="incident", args=[record_id, "event"], ), _class="action-btn") table = r.table rheader = DIV( TABLE( TR(exercise), TR( TH("%s: " % table.name.label), record.name, ), TR( TH("%s: " % table.incident_type_id.label), table.incident_type_id.represent(incident_type_id), ), TR( TH("%s: " % table.location_id.label), table.location_id.represent(record.location_id), ), # @ToDo: Add Zone TR( TH("%s: " % table.severity.label), table.severity.represent(record.severity), ), TR( TH("%s: " % table.level.label), table.level.represent(record.level), ), TR( TH("%s: " % table.organisation_id.label), table.organisation_id.represent( record.organisation_id), ), TR( TH("%s: " % table.person_id.label), table.person_id.represent(record.person_id), ), scenarios, TR( TH("%s: " % table.comments.label), record.comments, ), TR( TH("%s: " % table.date.label), table.date.represent(record.date), ), TR(closed), event, ), rheader_tabs) return rheader
def problem_rheader(r, tabs=[]): """ Problem rheader """ if r.representation == "html": if r.record is None: # List or Create form: rheader makes no sense here return None problem = r.record tabs = [ # Components & Custom Methods (T("Problems"), "problems"), (T("Solutions"), "solution"), (T("Discuss"), "discuss"), (T("Vote"), "vote"), (T("Scale of Results"), "results"), ] # Get this User's permissions for this Group duser = s3db.delphi_DelphiUser(problem.group_id) if duser.authorised: tabs.append((T("Edit"), None)) from s3 import s3_rheader_tabs rheader_tabs = s3_rheader_tabs(r, tabs) rtable = TABLE( TR( TH("%s: " % T("Problem")), problem.name, TH("%s: " % T("Active")), problem.active, ), TR( TH("%s: " % T("Description")), problem.description, ), TR( TH("%s: " % T("Criteria")), problem.criteria, ), ) if r.component and \ r.component_name == "solution" and \ r.component_id: stable = s3db.delphi_solution query = (stable.id == r.component_id) solution = db(query).select(stable.name, stable.description, limitby=(0, 1)).first() rtable.append( DIV( TR( TH("%s: " % T("Solution")), solution.name, ), TR( TH("%s: " % T("Description")), solution.description, ), )) rheader = DIV(rtable, rheader_tabs) return rheader
def event_rheader(r): rheader = None record = r.record if record and r.representation == "html": from gluon import A, DIV, TABLE, TR, TH from s3 import s3_rheader_tabs name = r.name if name == "incident": # Over-ride base SAFIRE template to add Notification Tab tabs = [(T("Incident Details"), None), #(T("Tasks"), "task"), #(T("Human Resources"), "human_resource"), #(T("Equipment"), "asset"), (T("Action Plan"), "plan"), (T("Incident Reports"), "incident_report"), (T("Logs"), "log"), (T("Expenses"), "expense"), (T("Situation Reports"), "sitrep"), (T("Send Notification"), "dispatch"), ] rheader_tabs = s3_rheader_tabs(r, tabs) record_id = r.id incident_type_id = record.incident_type_id editable = current.auth.s3_has_permission("UPDATE", "event_incident", record_id) if editable: # Dropdown of Scenarios to select stable = current.s3db.event_scenario query = (stable.incident_type_id == incident_type_id) & \ (stable.deleted == False) scenarios = current.db(query).select(stable.id, stable.name, ) if len(scenarios) and r.method != "event": from gluon import SELECT, OPTION dropdown = SELECT(_id="scenarios") dropdown["_data-incident_id"] = record_id dappend = dropdown.append dappend(OPTION(T("Select Scenario"))) for s in scenarios: dappend(OPTION(s.name, _value=s.id)) scenarios = TR(TH("%s: " % T("Scenario")), dropdown, ) s3 = current.response.s3 script = "/%s/static/themes/SAFIRE/js/incident_profile.js" % r.application if script not in s3.scripts: s3.scripts.append(script) s3.js_global.append('''i18n.scenarioConfirm="%s"''' % T("Populate Incident with Tasks, Organizations, Positions and Equipment from the Scenario?")) else: scenarios = "" else: scenarios = "" if record.exercise: exercise = TH(T("EXERCISE")) else: exercise = TH() if record.closed: closed = TH(T("CLOSED")) else: closed = TH() if record.event_id or r.method == "event" or not editable: event = "" else: event = A(T("Assign to Event"), _href = URL(c = "event", f = "incident", args = [record_id, "event"], ), _class = "action-btn" ) table = r.table rheader = DIV(TABLE(TR(exercise), TR(TH("%s: " % table.name.label), record.name, ), TR(TH("%s: " % table.incident_type_id.label), table.incident_type_id.represent(incident_type_id), ), TR(TH("%s: " % table.location_id.label), table.location_id.represent(record.location_id), ), # @ToDo: Add Zone TR(TH("%s: " % table.severity.label), table.severity.represent(record.severity), ), TR(TH("%s: " % table.level.label), table.level.represent(record.level), ), TR(TH("%s: " % table.organisation_id.label), table.organisation_id.represent(record.organisation_id), ), TR(TH("%s: " % table.person_id.label), table.person_id.represent(record.person_id), ), scenarios, TR(TH("%s: " % table.comments.label), record.comments, ), TR(TH("%s: " % table.date.label), table.date.represent(record.date), ), TR(closed), event, ), rheader_tabs) elif name == "incident_report": # Currently unused copy from base SAFIRE template record_id = r.id ltable = current.s3db.event_incident_report_incident query = (ltable.incident_report_id == record_id) link = current.db(query).select(ltable.incident_id, limitby = (0, 1) ).first() if link: from s3 import S3Represent represent = S3Represent(lookup="event_incident", show_link=True) rheader = DIV(TABLE(TR(TH("%s: " % ltable.incident_id.label), represent(link.incident_id), ), )) else: rheader = DIV(A(T("Assign to Incident"), _href = URL(c = "event", f = "incident_report", args = [record_id, "assign"], ), _class = "action-btn" )) elif name == "event": # Currently unused copy from base SAFIRE template tabs = [(T("Event Details"), None), (T("Incidents"), "incident"), (T("Documents"), "document"), (T("Photos"), "image"), ] rheader_tabs = s3_rheader_tabs(r, tabs) table = r.table rheader = DIV(TABLE(TR(TH("%s: " % table.event_type_id.label), table.event_type_id.represent(record.event_type_id), ), TR(TH("%s: " % table.name.label), record.name, ), TR(TH("%s: " % table.start_date.label), table.start_date.represent(record.start_date), ), TR(TH("%s: " % table.comments.label), record.comments, ), ), rheader_tabs) elif name == "scenario": # Currently unused copy from base SAFIRE template tabs = [(T("Scenario Details"), None), #(T("Tasks"), "task"), #(T("Human Resources"), "human_resource"), #(T("Equipment"), "asset"), (T("Action Plan"), "plan"), (T("Incident Reports"), "incident_report"), ] rheader_tabs = s3_rheader_tabs(r, tabs) table = r.table rheader = DIV(TABLE(TR(TH("%s: " % table.incident_type_id.label), table.incident_type_id.represent(record.incident_type_id), ), TR(TH("%s: " % table.organisation_id.label), table.organisation_id.represent(record.organisation_id), ), TR(TH("%s: " % table.location_id.label), table.location_id.represent(record.location_id), ), TR(TH("%s: " % table.name.label), record.name, ), TR(TH("%s: " % table.comments.label), record.comments, ), ), rheader_tabs) return rheader