Skip to content

Commit

Permalink
RGIMS template: homepage, fix PH locations import
Browse files Browse the repository at this point in the history
S3LocationSelectorWidget now loads JS separately from S3.min.js
Alphasort the Sites list on the frontpage (default & RGIMS)
  • Loading branch information
flavour committed Jun 25, 2012
1 parent ef62f27 commit 14bf678
Show file tree
Hide file tree
Showing 24 changed files with 2,598 additions and 2,306 deletions.
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
99ec853 (2012-06-25 08:23:18)
ef62f27 (2012-06-25 14:04:41)
75 changes: 26 additions & 49 deletions controllers/default.py
Expand Up @@ -243,7 +243,7 @@ def index():
)

div_arrow = DIV(IMG(_src = "/%s/static/img/arrow_blue_right.png" % \
appname),
appname),
_class = "div_arrow")
sit_dec_res_box = DIV(menu_divs["sit"],
div_arrow,
Expand All @@ -256,15 +256,17 @@ def index():
)
facility_box = menu_divs["facility"]
facility_box.append(A(IMG(_src = "/%s/static/img/map_icon_128.png" % \
appname),
appname),
_href = URL(c="gis", f="index"),
_title = T("Map")
)
)

datatable_ajax_source = ""

# Check logged in AND permissions
if AUTHENTICATED in session.s3.roles and \
roles = session.s3.roles
if AUTHENTICATED in roles and \
auth.s3_has_permission("read", db.org_organisation):
org_items = organisation()
datatable_ajax_source = "/%s/default/organisation.aaData" % \
Expand All @@ -278,6 +280,7 @@ def index():
if permitted_facilities:
facility_list = s3base.s3_represent_facilities(db, permitted_facilities,
link=False)
facility_list = sorted(facility_list, key=lambda fac: fac[1])
facility_opts = [OPTION(opt[1], _value = opt[0])
for opt in facility_list]
if facility_list:
Expand All @@ -295,10 +298,10 @@ def index():
),
_id = "manage_facility_box",
_class = "menu_box fleft")
s3.jquery_ready.append( """
$('#manage_facility_select').change(function() {
$('#manage_facility_btn').attr('href', S3.Ap.concat('/default/site/', $('#manage_facility_select').val()));
})""" )
s3.jquery_ready.append('''
$('#manage_facility_select').change(function(){
$('#manage_facility_btn').attr('href',S3.Ap.concat('/default/site/',$('#manage_facility_select').val()));
})''')
else:
manage_facility_box = DIV()

Expand All @@ -317,26 +320,14 @@ def index():
manage_facility_box = ""
org_box = ""

# @ToDo: Replace this with an easily-customisable section on the homepage
#settings = db(db.s3_setting.id == 1).select(limitby=(0, 1)).first()
#if settings:
# admin_name = settings.admin_name
# admin_email = settings.admin_email
# admin_tel = settings.admin_tel
#else:
# # db empty and prepopulate is false
# admin_name = T("Sahana Administrator").xml(),
# admin_email = "support@Not Set",
# admin_tel = T("Not Set").xml(),

# Login/Registration forms
self_registration = settings.get_security_self_registration()
registered = False
login_form = None
login_div = None
register_form = None
register_div = None
if AUTHENTICATED not in session.s3.roles:
if AUTHENTICATED not in roles:
# This user isn't yet logged-in
if request.cookies.has_key("registered"):
# This browser has logged-in before
Expand All @@ -362,32 +353,23 @@ def index():
else:
s3.scripts.append("/%s/static/scripts/jquery.validate.min.js" % appname)
if request.env.request_method == "POST":
post_script = """// Unhide register form
$('#register_form').removeClass('hide');
// Hide login form
$('#login_form').addClass('hide');"""
post_script = '''
$('#register_form').removeClass('hide');
$('#login_form').addClass('hide');'''
else:
post_script = ""
register_script = """
// Change register/login links to avoid page reload, make back button work.
$('#register-btn').attr('href', '#register');
$('#login-btn').attr('href', '#login');
%s
// Redirect Register Button to unhide
$('#register-btn').click(function() {
// Unhide register form
$('#register_form').removeClass('hide');
// Hide login form
$('#login_form').addClass('hide');
});
// Redirect Login Button to unhide
$('#login-btn').click(function() {
// Hide register form
$('#register_form').addClass('hide');
// Unhide login form
$('#login_form').removeClass('hide');
});""" % post_script
register_script = '''
$('#register-btn').attr('href','#register');
$('#login-btn').attr('href','#login');
%s
$('#register-btn').click(function() {
$('#register_form').removeClass('hide');
$('#login_form').addClass('hide');
});
$('#login-btn').click(function() {
$('#register_form').addClass('hide');
$('#login_form').removeClass('hide');
});''' % post_script
s3.jquery_ready.append(register_script)

# Provide a login box on front page
Expand Down Expand Up @@ -434,17 +416,12 @@ def index():

return dict(title = title,
item = item,

sit_dec_res_box = sit_dec_res_box,
facility_box = facility_box,
manage_facility_box = manage_facility_box,
org_box = org_box,

r = None, # Required for dataTable to work
datatable_ajax_source = datatable_ajax_source,
#admin_name=admin_name,
#admin_email=admin_email,
#admin_tel=admin_tel,
self_registration=self_registration,
registered=registered,
login_form=login_form,
Expand Down
59 changes: 44 additions & 15 deletions modules/eden/gis.py
Expand Up @@ -260,8 +260,12 @@ def model(self):
list_fields = ["id",
"name",
"level",
"parent",
"gis_feature_type",
#"parent",
"L0",
"L1",
"L2",
"L3",
"L4",
"lat",
"lon"
]
Expand Down Expand Up @@ -582,21 +586,18 @@ def gis_location_deduplicate(job):
# @ToDo: check the the lat and lon if they exist?
#lat = "lat" in data and data.lat
#lon = "lon" in data and data.lon
_duplicate = None

db = current.db

if not _duplicate:
# Try the Name
#query = (table.name.lower().like('%%%s%%' % name.lower()))
query = (table.name.lower() == name.lower())
if parent:
query = query & (table.parent == parent)
if level:
query = query & (table.level == level)
# Try the Name
# @ToDo: Hook for possible duplicates vs definite?
#query = (table.name.lower().like('%%%s%%' % name.lower()))
query = (table.name.lower() == name.lower())
if parent:
query = query & (table.parent == parent)
if level:
query = query & (table.level == level)

_duplicate = db(query).select(table.id,
limitby=(0, 1)).first()
_duplicate = current.db(query).select(table.id,
limitby=(0, 1)).first()
if _duplicate:
job.id = _duplicate.id
job.method = job.METHOD.UPDATE
Expand Down Expand Up @@ -702,12 +703,40 @@ def model(self):
s3_comments(),
*s3_meta_fields())

self.configure(tablename,
deduplicate=self.gis_location_tag_deduplicate)

# ---------------------------------------------------------------------
# Pass variables back to global scope (response.s3.*)
#
return Storage(
)

# -------------------------------------------------------------------------
@staticmethod
def gis_location_tag_deduplicate(job):
"""
If the record is a duplicate then it will set the job method to update
"""

if job.tablename == "gis_location_tag":
table = job.table
data = job.data
tag = "tag" in data and data.tag or None
location = "location_id" in data and data.location_id or None

if not tag or not location:
return

query = (table.tag.lower() == tag.lower()) & \
(table.location_id == location)

_duplicate = current.db(query).select(table.id,
limitby=(0, 1)).first()
if _duplicate:
job.id = _duplicate.id
job.method = job.METHOD.UPDATE

# =============================================================================
class S3LocationGroupModel(S3Model):
"""
Expand Down
8 changes: 4 additions & 4 deletions modules/eden/org.py
Expand Up @@ -267,10 +267,10 @@ def model(self):
tooltip=help),
ondelete = "SET NULL")

# Tags as component of Locations
add_component("gis_location_tag",
gis_location=dict(joinby="location_id",
name="tag"))
# Tags as component of Organisation Types
add_component("org_organisation_type_tag",
org_organisation_type=dict(joinby="organisation_type_id",
name="tag"))

# ---------------------------------------------------------------------
# Organisations
Expand Down
14 changes: 11 additions & 3 deletions modules/s3/s3widgets.py
Expand Up @@ -1241,7 +1241,7 @@ def __call__(self, field, value, **attributes):
settings = current.deployment_settings
response = current.response
s3 = current.response.s3
cache = s3.cache
appname = current.request.application

locations = s3db.gis_location
ctable = s3db.gis_config
Expand Down Expand Up @@ -1620,7 +1620,7 @@ def ac_help_widget(level):
_title="%s|%s|%s" % (label, AUTOCOMPLETE_HELP, NEW_HELP))

hidden = ""
throbber = "/%s/static/img/ajax-loader.gif" % current.request.application
throbber = "/%s/static/img/ajax-loader.gif" % appname
Lx_rows = DIV()
if value:
# Display Read-only Fields
Expand Down Expand Up @@ -1877,6 +1877,7 @@ def ac_help_widget(level):
COUNTRY_REQUIRED = T("Country is required!")

# Settings to be read by static/scripts/S3/s3.locationselector.widget.js
# Note: Currently we're limited to a single location selector per page
js_location_selector = '''
%s%s%s%s%s%s
S3.gis.location_id = '%s';
Expand All @@ -1898,6 +1899,14 @@ def ac_help_widget(level):
COUNTRY_REQUIRED
)

s3.js_global.append(js_location_selector)
if s3.debug:
script = "s3.locationselector.widget.js"
else:
script = "s3.locationselector.widget.min.js"

s3.scripts.append("/%s/static/scripts/S3/%s" % (appname, script))

# The overall layout of the components
return TAG[""](
TR(INPUT(**attr)), # Real input, which is hidden
Expand All @@ -1914,7 +1923,6 @@ def ac_help_widget(level):
latlon_rows,
divider,
TR(map_popup, TD(), _class="box_middle"),
SCRIPT(js_location_selector),
requires=requires
)

Expand Down
7 changes: 4 additions & 3 deletions private/templates/DRRPP/controllers.py
Expand Up @@ -23,11 +23,12 @@ def __call__(self):

T = current.T
request = current.request
response = current.response
appname = request.application
response = current.response

view = path.join(current.request.folder, "private", "templates",
response.s3.theme, "views", "index.html")
response.title = current.deployment_settings.get_system_name()
view = path.join(request.folder, "private", "templates",
"DRRPP", "views", "index.html")
try:
# Pass view as file not str to work in compiled mode
response.view = open(view, "rb")
Expand Down
13 changes: 6 additions & 7 deletions private/templates/IFRC/controllers.py
Expand Up @@ -14,11 +14,10 @@ def __call__(self):

T = current.T
response = current.response
s3 = response.s3

response.title = current.deployment_settings.get_system_name()
view = path.join(current.request.folder, "private", "templates",
s3.theme, "views", "index.html")
"IFRC", "views", "index.html")
try:
# Pass view as file not str to work in compiled mode
response.view = open(view, "rb")
Expand All @@ -27,13 +26,13 @@ def __call__(self):
raise HTTP("404", "Unable to open Custom View: %s" % view)

script = '''
$('.marker').mouseover(function() {
$(this).children('.marker-window').show();
$('.marker').mouseover(function(){
$(this).children('.marker-window').show();
})
$('.marker').mouseout(function() {
$(this).children('.marker-window').hide();
$('.marker').mouseout(function(){
$(this).children('.marker-window').hide();
})'''
s3.jquery_ready.append(script)
response.s3.jquery_ready.append(script)

markers = [
Storage(name = "Afghan Red Crescent Society",
Expand Down
3 changes: 3 additions & 0 deletions private/templates/IFRC/tasks.cfg
Expand Up @@ -38,6 +38,9 @@ gis,hierarchy,gis_hierarchy.csv,hierarchy.xsl
gis,location,TL_L1.csv,location.xsl
gis,location,TL_L2.csv,location.xsl
gis,location,TL_L3.csv,location.xsl
gis,location,RGIMS/PH_L1.csv,location.xsl
gis,location,RGIMS/PH_L2.csv,location.xsl
gis,location,RGIMS/PH_L3.csv,location.xsl
# Layers
gis,layer_config,gis_layer_feature.csv,layer_feature.xsl
gis,layer_symbology,gis_layer_feature.csv,layer_feature.xsl
Expand Down
1 change: 1 addition & 0 deletions private/templates/IFRC_Demo/tasks.cfg
Expand Up @@ -16,6 +16,7 @@
# Assumes that all of IFRC_Train has already been imported
# GIS
gis,location,IFRC/TL_L3.csv,location.xsl
gis,location,RGIMS/PH_L3.csv,location.xsl
gis,layer_config,gis_layer_theme.csv,layer_theme.xsl
gis,theme_data,gis_theme_data.csv,theme_data.xsl
# Human Resources
Expand Down
3 changes: 3 additions & 0 deletions private/templates/IFRC_Train/tasks.cfg
Expand Up @@ -42,6 +42,9 @@ gis,hierarchy,IFRC/gis_hierarchy.csv,hierarchy.xsl
gis,location,IFRC/TL_L1.csv,location.xsl
gis,location,IFRC/TL_L2.csv,location.xsl
#gis,location,IFRC/TL_L3.csv,location.xsl
gis,location,RGIMS/PH_L1.csv,location.xsl
gis,location,RGIMS/PH_L2.csv,location.xsl
#gis,location,RGIMS/PH_L3.csv,location.xsl
# Layers
gis,layer_config,IFRC/gis_layer_feature.csv,layer_feature.xsl
gis,layer_symbology,IFRC/gis_layer_feature.csv,layer_feature.xsl
Expand Down

0 comments on commit 14bf678

Please sign in to comment.