Better handling of dates when registering children

This commit is contained in:
Deon George
2014-10-23 10:05:32 +11:00
parent 48debfbd6c
commit 6eb0b2f8dd
3 changed files with 63 additions and 8 deletions

View File

@@ -13,6 +13,8 @@ class Controller_User_Child extends Controller_Child {
protected $auth_required = TRUE;
protected $secure_actions = array(
'add'=>TRUE,
'ajaxage'=>FALSE,
'ajaxagemax'=>FALSE,
'edit'=>TRUE,
);
@@ -24,6 +26,18 @@ class Controller_User_Child extends Controller_Child {
->body($this->add_edit());
}
public function action_ajaxage() {
$x = ORM::factory('Child');
$x->dob = $this->request->query('date');
$this->template->content = $x->age();
}
public function action_ajaxagemax() {
$x = ORM::factory('Child');
$x->dob = $this->request->query('date');
$this->template->content = $x->date_enrol_max();
}
public function action_edit() {
Block::factory()
->type('form-horizontal')
@@ -59,11 +73,48 @@ class Controller_User_Child extends Controller_Child {
Script::factory()
->type('stdin')
->data('
$(document).ready(function() {
$("#date_stop").datepicker({
endDate: new Date('.($co->date_enrol_max()*1000).')
});
})
$(document).ready(function() {
'.($co->loaded() ? '
$("#date_stop").datepicker({
endDate: new Date('.($co->date_enrol_max()*1000).')
});
' : '').'
$("#dob").datepicker().on("hide",function(e) {
var x = $("#dob").datepicker("getDate").getTime()/1000;
// Send the request and update sub category dropdown
$.ajax({
type: "GET",
data: "date="+x,
dataType: "html",
cache: false,
url: "'.URL::link('user','child/ajaxage',TRUE).'",
timeout: 2000,
error: function(x) {
alert("Failed to submit");
},
success: function(data) {
$("div[id=age]").empty().append(data);
}
});
$.ajax({
type: "GET",
data: "date="+x,
dataType: "html",
cache: false,
url: "'.URL::link('user','child/ajaxagemax',TRUE).'",
timeout: 2000,
error: function(x) {
alert("Failed to submit");
},
success: function(data) {
$("#date_stop").datepicker("setEndDate",new Date(data*1000));
}
});
});
});
');
return View::factory('child/user/add_edit')