General Progress
This commit is contained in:
176
application/classes/Controller/Director/Child.php
Normal file
176
application/classes/Controller/Director/Child.php
Normal file
@@ -0,0 +1,176 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class provides the Directors ability to setup families
|
||||
*
|
||||
* @package Membership Database
|
||||
* @category Controllers/Director
|
||||
* @author Deon George
|
||||
* @copyright (c) 2014 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
class Controller_Director_Child extends Controller_Child {
|
||||
protected $secure_actions = array(
|
||||
'add'=>TRUE,
|
||||
'ajaxroomrow'=>FALSE,
|
||||
'edit'=>TRUE,
|
||||
'list'=>TRUE,
|
||||
);
|
||||
|
||||
/**
|
||||
* Add a Child
|
||||
*/
|
||||
public function action_add() {
|
||||
Block::factory()
|
||||
->type('form-horizontal')
|
||||
->title('Add/Edit Record')
|
||||
->title_icon('fa-wrench')
|
||||
->body($this->add_edit());
|
||||
}
|
||||
|
||||
public function action_ajaxroomrow() {
|
||||
$this->response->body(
|
||||
View::factory('child/director/add_roomrow')
|
||||
->set('o',ORM::factory('Child',$this->request->query('cid')))
|
||||
->set('so',Company::instance()->so())
|
||||
->set('rco',ORM::factory('Room_Children'))
|
||||
->set('row',$this->request->query('id'))
|
||||
->set('type',$this->request->query('type')));
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit a Child
|
||||
*/
|
||||
public function action_edit() {
|
||||
Block::factory()
|
||||
->type('form-horizontal')
|
||||
->title('Add/Edit Record')
|
||||
->title_icon('fa-wrench')
|
||||
->body($this->add_edit($this->request->param('id')));
|
||||
}
|
||||
|
||||
public function action_list() {
|
||||
Block::factory()
|
||||
->title('Children List')
|
||||
->title_icon('fa-list-ol')
|
||||
->body(Table::factory()
|
||||
->data(ORM::factory('Child')->find_all())
|
||||
->columns(array(
|
||||
'id'=>'ID',
|
||||
'name()'=>'Name',
|
||||
'age()'=>'Age',
|
||||
"days(NULL,".Site::DateStartOfWeek(time()).",7,'P',TRUE)"=>'Perm Days',
|
||||
"days(NULL,".Site::DateStartOfWeek(time()).",7,'w',TRUE)"=>'Wait Days',
|
||||
'date_orig'=>'Date Registered'
|
||||
))
|
||||
->prepend(array(
|
||||
'id'=>array('url'=>URL::link('director','child/edit/')),
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
private function add_edit($id=NULL) {
|
||||
$co = ORM::factory('Child',$id);
|
||||
|
||||
if ($this->request->post()) {
|
||||
foreach ($this->request->post('room') as $index=>$room) {
|
||||
$new = FALSE;
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
Style::factory()
|
||||
->type('file')
|
||||
->data('media/theme/bootstrap/css/bootstrap.datepicker.css');
|
||||
|
||||
Script::factory()
|
||||
->type('file')
|
||||
->data('media/theme/bootstrap/js/bootstrap.datepicker.js');
|
||||
|
||||
Script::factory()
|
||||
->type('stdin')
|
||||
->data('
|
||||
$(document).ready(function() {
|
||||
var x = '.count($co->subitems()).';
|
||||
|
||||
$("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);
|
||||
}
|
||||
});
|
||||
|
||||
// This code has been disabled as it pollutes datepicker.
|
||||
/*
|
||||
$.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",new Date(data*1000))});
|
||||
// $(".input-daterange input").each(function(){alert(new Date(data*1000));$(this).datepicker("setEndDate",new Date(data*1000))});
|
||||
$(".input-daterange").each(function(){alert(data);$(this).datepicker("setEndDate",data)});
|
||||
}
|
||||
});
|
||||
*/
|
||||
});
|
||||
});
|
||||
');
|
||||
|
||||
return View::factory('child/director/add_edit')
|
||||
->set('o',$co)
|
||||
->set('so',Company::instance()->so());
|
||||
}
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user