General Progress

This commit is contained in:
Deon George
2014-12-01 14:01:02 +11:00
parent 6eb0b2f8dd
commit fba5988d8d
18 changed files with 806 additions and 136 deletions

View File

@@ -35,7 +35,7 @@ class Controller_User_Child extends Controller_Child {
public function action_ajaxagemax() {
$x = ORM::factory('Child');
$x->dob = $this->request->query('date');
$this->template->content = $x->date_enrol_max();
$this->template->content = $x->date_enrol_max(TRUE);
}
public function action_edit() {
@@ -50,17 +50,27 @@ class Controller_User_Child extends Controller_Child {
$co = ORM::factory('Child',$id);
if ($this->request->post()) {
$co->values($this->request->post());
$co->account_id = (string)$this->ao;
foreach ($this->request->post('room') as $index=>$room) {
$new = FALSE;
if ($co->changed() AND (! $this->save($co)))
if (! $room['id'] OR ! $rco=$co->subitem_get('id',$room['id'])) {
$new = TRUE;
$rco = $co->room;
$rco->child_id = $co->id;
}
$rco->values($room);
if ($new)
$co->subitem_add($rco);
}
$co->values($this->request->post());
if (! $this->save($co))
$co->reload()->values($this->request->post());
}
// If there are no room records, we'll create a waitlist one that can be completed.
if (! $co->subitems())
$co->subitem_add($co->room->values(array('child_id'=>$co->id,'code'=>'W')));
Style::factory()
->type('file')
->data('media/theme/bootstrap/css/bootstrap.datepicker.css');
@@ -73,48 +83,62 @@ class Controller_User_Child extends Controller_Child {
Script::factory()
->type('stdin')
->data('
$(document).ready(function() {
'.($co->loaded() ? '
$("#date_stop").datepicker({
endDate: new Date('.($co->date_enrol_max()*1000).')
});
' : '').'
$(document).ready(function() {
var x = '.count($co->subitems()).';
$("#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));
}
});
$("button[name=add]").click(function() {
// Send the request and get a new room row
$.ajax({
type: "GET",
data: "cid='.$co->id.'&type="+$(this).val()+"&id="+x++,
dataType: "html",
cache: false,
url: "'.URL::link('director','child/ajaxroomrow',TRUE).'",
timeout: 2000,
error: function(x) {
alert("Failed to submit");
},
success: function(data) {
$("table[name=room] tr:last").after(data);
}
});
});
$("#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 input:not(#dob)").each(function(){$(this).datepicker("setEndDate",data)});
}
});
});
});
');
return View::factory('child/user/add_edit')