| 1 |
<?php if (! defined('ABSPATH')) exit; // Exit if accessed directly |
| 2 |
#[AllowDynamicProperties] |
| 3 |
class SH4_Employees_Html_Admin_View_New |
| 4 |
{ |
| 5 |
public function __construct( |
| 6 |
HC3_Hooks $hooks, |
| 7 |
HC3_Ui $ui, |
| 8 |
|
| 9 |
SH4_Calendars_Query $calendarsQuery, |
| 10 |
SH4_Calendars_Presenter $calendarsPresenter, |
| 11 |
|
| 12 |
HC3_Ui_Layout1 $layout |
| 13 |
) |
| 14 |
{ |
| 15 |
$this->ui = $ui; |
| 16 |
$this->layout = $layout; |
| 17 |
|
| 18 |
$this->calendarsQuery = $hooks->wrap( $calendarsQuery ); |
| 19 |
$this->calendarsPresenter = $hooks->wrap( $calendarsPresenter ); |
| 20 |
|
| 21 |
$this->self = $hooks->wrap($this); |
| 22 |
} |
| 23 |
|
| 24 |
public function render() |
| 25 |
{ |
| 26 |
$form = $this->ui->makeForm( |
| 27 |
'admin/employees/new', |
| 28 |
$this->self->form() |
| 29 |
); |
| 30 |
|
| 31 |
$this->layout |
| 32 |
->setContent( $form ) |
| 33 |
->setBreadcrumb( $this->self->breadcrumb() ) |
| 34 |
->setHeader( $this->self->header() ) |
| 35 |
; |
| 36 |
|
| 37 |
$out = $this->layout->render(); |
| 38 |
return $out; |
| 39 |
} |
| 40 |
|
| 41 |
public function header() |
| 42 |
{ |
| 43 |
$out = '__Add New Employee__'; |
| 44 |
return $out; |
| 45 |
} |
| 46 |
|
| 47 |
public function breadcrumb() |
| 48 |
{ |
| 49 |
$return = array(); |
| 50 |
$return['admin'] = array( 'admin', '__Administration__' ); |
| 51 |
$return['employees'] = array( 'admin/employees', '__Employees__' ); |
| 52 |
return $return; |
| 53 |
} |
| 54 |
|
| 55 |
public function form() |
| 56 |
{ |
| 57 |
$inputs = array(); |
| 58 |
|
| 59 |
$inputs['title'] = $this->ui->makeInputText( 'title', '__Title__' )->bold(); |
| 60 |
$inputs['description'] = $this->ui->makeInputRichTextarea( 'description', '__Description__' )->setRows(6); |
| 61 |
|
| 62 |
$calendars = $this->calendarsQuery->findActive(); |
| 63 |
$calendarsView = array(); |
| 64 |
foreach( $calendars as $calendar ){ |
| 65 |
$calendarId = $calendar->getId(); |
| 66 |
$checked = FALSE; |
| 67 |
|
| 68 |
$title = $this->calendarsPresenter->presentTitle( $calendar ); |
| 69 |
// $thisView = $this->ui->makeInputCheckbox( 'calendar[]', $thisView, $calendarId, $checked ); |
| 70 |
$thisView = $this->ui->makeInputCheckbox( 'calendar[]', NULL, $calendarId, $checked ); |
| 71 |
$thisView = $this->ui->makeListInline( array($thisView, $title) ); |
| 72 |
|
| 73 |
$thisView = $this->ui->makeBlock( $thisView ) |
| 74 |
->tag('border') |
| 75 |
->tag('padding', 1) |
| 76 |
; |
| 77 |
if( $checked ){ |
| 78 |
$thisView |
| 79 |
->tag('border-color', 'olive') |
| 80 |
; |
| 81 |
} |
| 82 |
|
| 83 |
$calendarsView[] = $thisView; |
| 84 |
} |
| 85 |
|
| 86 |
$outCalendars = $this->ui->makeGrid(); |
| 87 |
foreach( $calendarsView as $v ){ |
| 88 |
$outCalendars->add( $v, 3, 12 ); |
| 89 |
} |
| 90 |
|
| 91 |
$outCalendars = $this->ui->makeBlock( $outCalendars ) |
| 92 |
->addAttr( 'id', 'sh4-calendars-employees' ) |
| 93 |
; |
| 94 |
$toggleAll = $this->ui->makeInputCheckbox( 'toggle_all', '__Toggle All__' ) |
| 95 |
->addAttr( 'class', 'sh4-calendars-employees-select-all' ) |
| 96 |
; |
| 97 |
$outCalendars = $this->ui->makeList( array($toggleAll, $outCalendars) ); |
| 98 |
$outCalendars = $this->ui->makeLabelled( '__Calendars__', $outCalendars ); |
| 99 |
|
| 100 |
// add check all |
| 101 |
$js = $this->renderJs(); |
| 102 |
$outCalendars = $this->ui->makeCollection( array($js, $outCalendars) ); |
| 103 |
$inputs['calendars'] = $outCalendars; |
| 104 |
|
| 105 |
$inputs = $this->ui->makeList( $inputs ); |
| 106 |
|
| 107 |
$buttons = $this->ui->makeInputSubmit( '__Add New Employee__') |
| 108 |
->tag('primary') |
| 109 |
; |
| 110 |
|
| 111 |
$out = $this->ui->makeList() |
| 112 |
->add( $inputs ) |
| 113 |
->add( $buttons ) |
| 114 |
; |
| 115 |
|
| 116 |
return $out; |
| 117 |
} |
| 118 |
|
| 119 |
public function renderJs() |
| 120 |
{ |
| 121 |
ob_start(); |
| 122 |
?> |
| 123 |
|
| 124 |
<script language="JavaScript"> |
| 125 |
( function(){ |
| 126 |
|
| 127 |
document.addEventListener('DOMContentLoaded', function() |
| 128 |
{ |
| 129 |
var self = this; |
| 130 |
var el = document.getElementById( 'sh4-calendars-employees' ); |
| 131 |
|
| 132 |
this.toggleAll = function( e ){ |
| 133 |
var checkers = el.getElementsByTagName( 'input' ); |
| 134 |
for( ii = 0; ii < checkers.length; ii++ ){ |
| 135 |
checkers[ii].checked = ! checkers[ii].checked; |
| 136 |
} |
| 137 |
}; |
| 138 |
|
| 139 |
var togglers = document.getElementsByClassName( 'sh4-calendars-employees-select-all' ); |
| 140 |
for( ii = 0; ii < togglers.length; ii++ ){ |
| 141 |
togglers[ii].addEventListener( 'change', self.toggleAll ); |
| 142 |
} |
| 143 |
}); |
| 144 |
|
| 145 |
})(); |
| 146 |
|
| 147 |
</script> |
| 148 |
|
| 149 |
<?php |
| 150 |
return ob_get_clean(); |
| 151 |
} |
| 152 |
} |
| 153 |
|