Permalink
Browse files

Datepicker validation to ensure end_date not before start_date

  • Loading branch information...
1 parent f83dee2 commit 6c8ac2db040a87636726e00fded328fe82f3b393 @flavour flavour committed Jun 30, 2012
View
@@ -1 +1 @@
-ee3e4d3 (2012-06-30 16:17:20)
+f83dee2 (2012-06-30 19:51:37)
View
@@ -71,22 +71,25 @@ def prep(r):
if r.method == "form":
return True
if r.interactive:
- # Assume staff only between 16-81
- s3db.pr_person.date_of_birth.widget = S3DateWidget(past=972, future=-192)
-
- table = r.table
- table.site_id.comment = DIV(DIV(_class="tooltip",
- _title="%s|%s|%s" % (T("Facility"),
- T("The site where this position is based."),
- T("Enter some characters to bring up a list of possible matches."))))
- if r.method != "read":
- # Don't want to see in Create forms
- # inc list_create (list_fields over-rides)
- field = table.status
- field.writable = False
- field.readable = False
-
- if r.method == "create" and r.component is None:
+ if r.method == "create" and not r.component:
+ # Don't redirect
+ # Assume staff only between 16-81
+ s3db.pr_person.date_of_birth.widget = S3DateWidget(past=972, future=-192)
+
+ # Set the minimum end_date to the same as the start_date
+ s3.jquery_ready.append(
+'''S3.start_end_date('hrm_human_resource_start_date','hrm_human_resource_end_date')''')
+
+ table = r.table
+ table.site_id.comment = DIV(DIV(_class="tooltip",
+ _title="%s|%s|%s" % (T("Facility"),
+ T("The site where this position is based."),
+ T("Enter some characters to bring up a list of possible matches."))))
+ table.status.writable = False
+ table.status.readable = False
+
+ elif r.method == "delete":
+ # Don't redirect
pass
elif r.id:
# Redirect to person controller
@@ -165,24 +168,23 @@ def staff():
def prep(r):
if r.interactive:
- # Assume staff only between 16-81
- s3db.pr_person.date_of_birth.widget = S3DateWidget(past=972, future=-192)
-
- table = r.table
- table.site_id.comment = DIV(DIV(_class="tooltip",
- _title="%s|%s|%s" % (T("Facility"),
- T("The site where this position is based."),
- T("Enter some characters to bring up a list of possible matches."))))
- if r.method != "read":
- # Don't want to see in Create forms
- # inc list_create (list_fields over-rides)
- field = table.status
- field.writable = False
- field.readable = False
-
- if r.method == "create" and r.component is None:
+ if r.method == "create" and not r.component:
# Don't redirect
- pass
+ # Assume staff only between 16-81
+ s3db.pr_person.date_of_birth.widget = S3DateWidget(past=972, future=-192)
+
+ # Set the minimum end_date to the same as the start_date
+ s3.jquery_ready.append(
+'''S3.start_end_date('hrm_human_resource_start_date','hrm_human_resource_end_date')''')
+
+ table = r.table
+ table.site_id.comment = DIV(DIV(_class="tooltip",
+ _title="%s|%s|%s" % (T("Facility"),
+ T("The site where this position is based."),
+ T("Enter some characters to bring up a list of possible matches."))))
+ table.status.writable = False
+ table.status.readable = False
+
elif r.method == "delete":
# Don't redirect
pass
@@ -235,30 +237,6 @@ def person():
set_method("pr", resourcename,
method="contacts",
action=s3db.pr_contacts)
- # Custom Method for Identity
- set_method("pr", resourcename,
- method="identity")
- # Custom Method for Education
- set_method("pr", resourcename,
- method="education")
- # Custom Method for Description
- set_method("pr", resourcename,
- method="physical_description")
- # Hide all but those details that we want
- # Lock all the fields
- pr_desc_table = s3db.pr_physical_description
- for field in pr_desc_table.fields:
- pr_desc_table[field].writable = False
- pr_desc_table[field].readable = False
- # Now enable those that we want
- pr_desc_table.ethnicity.writable = True
- pr_desc_table.ethnicity.readable = True
- pr_desc_table.blood_type.writable = True
- pr_desc_table.blood_type.readable = True
- pr_desc_table.medical_conditions.writable = True
- pr_desc_table.medical_conditions.readable = True
- pr_desc_table.other_details.writable = True
- pr_desc_table.other_details.readable = True
# Plug-in role matrix for Admins/OrgAdmins
realms = auth.user is not None and auth.user.realms or []
@@ -334,11 +312,12 @@ def person():
list_fields=list_fields)
# Configure person table
- # - hide fields
tablename = "pr_person"
table = s3db[tablename]
- if settings.get_hrm_experience() == "programme":
+ if (group == "staff" and settings.get_hrm_staff_experience() == "programme") or \
+ (group == "volunteer" and settings.get_hrm_vol_experience() == "programme"):
table.virtualfields.append(s3db.hrm_programme_person_virtual_fields())
+ # Hide fields
table.pe_label.readable = False
table.pe_label.writable = False
table.missing.readable = False
@@ -420,13 +399,10 @@ def import_prep(data, group=group):
before processing a new data import, used for the import_prep
hook in s3mgr
"""
- request = current.request
-
resource, tree = data
xml = s3mgr.xml
tag = xml.TAG
att = xml.ATTRIBUTE
-
if s3.import_replace:
if tree is not None:
if group == "staff":
@@ -472,6 +448,30 @@ def prep(r):
insertable = False,
editable = False,
deletable = False)
+ elif r.component_name == "human_resource":
+ # Set the minimum end_date to the same as the start_date
+ s3.jquery_ready.append(
+'''S3.start_end_date('hrm_human_resource_start_date','hrm_human_resource_end_date')''')
+ elif r.component_name == "experience":
+ # Set the minimum end_date to the same as the start_date
+ s3.jquery_ready.append(
+'''S3.start_end_date('hrm_experience_start_date','hrm_experience_end_date')''')
+ elif r.component_name == "physical_description":
+ # Hide all but those details that we want
+ # Lock all the fields
+ pr_desc_table = s3db.pr_physical_description
+ for field in pr_desc_table.fields:
+ pr_desc_table[field].writable = False
+ pr_desc_table[field].readable = False
+ # Now enable those that we want
+ pr_desc_table.ethnicity.writable = True
+ pr_desc_table.ethnicity.readable = True
+ pr_desc_table.blood_type.writable = True
+ pr_desc_table.blood_type.readable = True
+ pr_desc_table.medical_conditions.writable = True
+ pr_desc_table.medical_conditions.readable = True
+ pr_desc_table.other_details.writable = True
+ pr_desc_table.other_details.readable = True
else:
# Assume volunteers only between 12-81
r.table.date_of_birth.widget = S3DateWidget(past=972, future=-144)
View
@@ -76,6 +76,12 @@ def prep(r):
# Redirect to person controller
vars = {"membership.id": r.id}
redirect(URL(f="person", vars=vars))
+ else:
+ # Assume members under 120
+ s3db.pr_person.date_of_birth.widget = S3DateWidget(past=1440)
+ # Set the minimum end_date to the same as the start_date
+ s3.jquery_ready.append(
+'''S3.start_end_date('member_membership_start_date','member_membership_end_date')''')
return True
s3.prep = prep
@@ -112,12 +118,10 @@ def import_prep(data):
before processing a new data import, used for the import_prep
hook in s3mgr
"""
-
resource, tree = data
xml = s3mgr.xml
tag = xml.TAG
att = xml.ATTRIBUTE
-
if s3.import_replace:
if tree is not None:
root = tree.getroot()
@@ -145,6 +149,13 @@ def import_prep(data):
# CRUD pre-process
def prep(r):
if r.interactive and r.method != "import":
+ if not r.component:
+ # Assume members under 120
+ s3db.pr_person.date_of_birth.widget = S3DateWidget(past=1440)
+ elif r.component_name == "membership":
+ # Set the minimum end_date to the same as the start_date
+ s3.jquery_ready.append(
+'''S3.start_end_date('member_membership_start_date','member_membership_end_date')''')
resource = r.resource
if resource.count() == 1:
resource.load()
@@ -23,7 +23,7 @@ def index():
redirect(URL(f="project", args="search"))
else:
# Bypass home page & go direct to list of Projects
- # - no good search options avaialble
+ # - no good search options available
redirect(URL(f="project"))
#module_name = deployment_settings.modules[module].name_nice
@@ -78,7 +78,17 @@ def postp(r, output):
# Pre-process
def prep(r):
if r.interactive:
- if r.component is not None:
+ if not r.component:
+ if not r.id and r.function == "index":
+ r.method = "search"
+ # If just a few Projects, then a List is sufficient
+ #r.method = "list"
+
+ # Set the minimum end_date to the same as the start_date
+ s3.jquery_ready.append(
+'''S3.start_end_date('project_project_start_date','project_project_end_date')''')
+
+ else:
if r.component_name == "organisation":
if r.method != "update":
host_role = 1
@@ -115,6 +125,9 @@ def prep(r):
filter = (r.component.table.status.belongs(statuses))
r.resource.add_component_filter("task", filter)
elif r.component_name == "beneficiary":
+ # Set the minimum end_date to the same as the start_date
+ s3.jquery_ready.append(
+'''S3.start_end_date('project_beneficiary_start_date','project_beneficiary_end_date')''')
db.project_beneficiary.project_location_id.requires = IS_NULL_OR(
IS_ONE_OF(db,
"project_location.id",
@@ -127,22 +140,23 @@ def prep(r):
from eden.hrm import hrm_human_resource_represent
# We can pass the human resource type filter in the URL
- group = r.vars.get('group', None)
+ group = r.vars.get("group", None)
# These values are defined in hrm_type_opts
if group:
+ crud_strings = s3.crud_strings
if group == "staff":
group = 1
db.project_human_resource.human_resource_id.label = T("Staff")
- s3.crud_strings["project_human_resource"] = s3.crud_strings["hrm_staff"]
- s3.crud_strings["project_human_resource"].update(
+ crud_strings["project_human_resource"] = crud_strings["hrm_staff"]
+ crud_strings["project_human_resource"].update(
subtitle_create = T("Add Staff Member to Project")
)
elif group == "volunteer":
group = 2
db.project_human_resource.human_resource_id.label = T("Volunteer")
- s3.crud_strings["project_human_resource"] = s3.crud_strings["hrm_volunteer"]
- s3.crud_strings["project_human_resource"].update(
+ crud_strings["project_human_resource"] = crud_strings["hrm_volunteer"]
+ crud_strings["project_human_resource"].update(
subtitle_create = T("Add Volunteer to Project")
)
@@ -161,72 +175,19 @@ def prep(r):
sort=True
)
- elif not r.id and r.function == "index":
- r.method = "search"
- # If just a few Projects, then a List is sufficient
- #r.method = "list"
-
return True
s3.prep = prep
# Post-process
def postp(r, output):
- if r.interactive:
- if not r.component:
- # Do extra client-side validation
- # This part needs to be able to support multiple L10n_date_format
- #var datePattern = /^(19|20)\d\d([-\/.])(0[1-9]|1[012])\2(0[1-9]|[12][0-9]|3[01])$/;
- #if ( (start_date && !(datePattern.test(start_date))) | (end_date && !(datePattern.test(end_date))) ) {
- # error_msg = '%s';
- # jQuery('#project_project_start_date__row > td').last().text(error_msg);
- # jQuery('#project_project_start_date__row > td').last().addClass('red');
- # return false;
- #}
- validate = True
- date_format = deployment_settings.get_L10n_date_format()
- if date_format == T("%Y-%m-%d"):
- # Default
- start_date_string = "start_date[0], start_date[1], start_date[2]"
- end_date_string = "end_date[0], end_date[1], end_date[2]"
- elif date_format == T("%m-%d-%Y"):
- # US Style
- start_date_string = "start_date[2], start_date[0], start_date[1]"
- end_date_string = "end_date[2], end_date[0], end_date[1]"
- elif date_format == T("%d-%b-%Y"):
- # Unsortable 'Pretty' style
- start_date_string = "start_date[0] + ' ' + start_date[1] + ' ' + start_date[2]"
- end_date_string = "end_date[0] + ' ' + end_date[1] + ' ' + end_date[2]"
- else:
- # Unknown format - don't add extra validation
- validate = False
- if validate:
- script = """$('.form-container > form').submit(function () {
- var start_date = this.start_date.value;
- var end_date = this.end_date.value;
- start_date = start_date.split('-');
- start_date = new Date(%s);
- end_date = end_date.split('-');
- end_date = new Date(%s);
- if (start_date > end_date) {
- var error_msg = '%s';
- jQuery('#project_project_end_date__row > td').last().text(error_msg);
- jQuery('#project_project_end_date__row > td').last().addClass('red');
- return false;
- } else {
- return true;
- }
-});""" % (start_date_string,
- end_date_string,
- T("End date should be after start date"))
- if validate:
- s3.jquery_ready.append(script)
-
- if mode_task:
- read_url = URL(args=["[id]", "task"])
- update_url = URL(args=["[id]", "task"])
- s3mgr.crud.action_buttons(r,
- read_url=read_url,
- update_url=update_url)
+ if r.interactive and \
+ mode_task and \
+ not r.component:
+ read_url = URL(args=["[id]", "task"])
+ update_url = URL(args=["[id]", "task"])
+ s3mgr.crud.action_buttons(r,
+ read_url=read_url,
+ update_url=update_url)
return output
s3.postp = postp
Oops, something went wrong.

0 comments on commit 6c8ac2d

Please sign in to comment.