Improving UI in attendance see BT#5419

skala
Julio Montoya 12 years ago
parent 7038bba9e5
commit 85a2ef6a2a
  1. 20
      main/attendance/attendance_controller.php
  2. 127
      main/attendance/attendance_sheet.php
  3. 14
      main/attendance/index.php
  4. 24
      main/inc/lib/attendance.lib.php

@ -222,6 +222,8 @@
$attendance = new Attendance();
$data = array();
$data['attendance_id'] = $attendance_id;
$data['attendance_obj'] = $attendance;
$data['attendance_states'] = $attendance->get_attendance_states();
$data['users_in_course'] = $attendance->get_users_rel_course($attendance_id);
$filter_type = 'today';
@ -256,7 +258,9 @@
if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") {
if (isset($_POST['hidden_input'])) {
foreach ($_POST['hidden_input'] as $cal_id) {
$columns_to_update = $_POST['hidden_input'];
$columns_to_update = array_unique(array_filter($columns_to_update));
foreach ($columns_to_update as $cal_id) {
$users_result = array();
if (isset($_POST['check_presence'][$cal_id])) {
$users_result = $_POST['check_presence'][$cal_id];
@ -266,16 +270,18 @@
if (!empty($users_result)) {
foreach ($users_result as $result) {
$user_status = explode('_', $result);
if (isset($user_status[2]) && isset($user_status[1])) {
$user_final_results[$user_status[2]] = $user_status[1];
if (isset($user_status[0]) && $user_status[0] == 'state' && isset($user_status[4]) && isset($user_status[1])) {
$user_final_results[$user_status[4]] = $user_status[1];
}
}
}
$affected_rows = $attendance->attendance_sheet_add($cal_id, $user_final_results, $attendance_id);
if (!empty($user_final_results)) {
$affected_rows = $attendance->attendance_sheet_add($cal_id, $user_final_results, $attendance_id);
}
}
}
$data['users_in_course'] = $attendance->get_users_rel_course($attendance_id);
$data['users_in_course'] = $attendance->get_users_rel_course($attendance_id);
$my_calendar_id = null;
if (is_numeric($filter_type)) {
$my_calendar_id = $filter_type;
@ -490,7 +496,7 @@
}
$max_cols_per_page = 12; //10 dates + 2 name and number
$max_dates_per_page = $max_dates_per_page_original = $max_cols_per_page - 2;//10
//var_dump($cols);exit;
$rows = count($data_table);
if ($cols > $max_cols_per_page) {

@ -11,13 +11,6 @@
// protect a course script
api_protect_course_script(true);
$attendance_states = array(
'1' => get_lang('Present'),
'0' => get_lang('Absent'),
'2' => get_lang('VeryLate'),
'3' => get_lang('Late'),
);
if (api_is_allowed_to_edit(null, true) || api_is_coach(api_get_session_id(), api_get_course_id())) {
$param_gradebook = '';
@ -91,9 +84,12 @@ if (api_is_allowed_to_edit(null, true) || api_is_coach(api_get_session_id(), api
$param_filter = '&filter='.Security::remove_XSS($default_filter);
if (count($users_in_course) > 0) {
foreach ($attendance_states as $id => $state) {
echo $attendance_obj->get_attendance_state_button($id, true).' ';
}
?>
<script>
?>
<script>
var original_url = '';
$("#filter_id").on('change', function() {
filter = $(this).val();
@ -144,30 +140,81 @@ if (api_is_allowed_to_edit(null, true) || api_is_coach(api_get_session_id(), api
});
}
function save_checkboxes() {
$('#form_attendance_sheet').submit();
}
$(document).ready(function() {
$("table.tableWithFloatingHeader").each(function() {
$(this).wrap("<div class=\"divTableWithFloatingHeader\" style=\"position:relative\"></div>");
var originalHeaderRow = $("tr:first", this)
originalHeaderRow.before(originalHeaderRow.clone());
var clonedHeaderRow = $("tr:first", this)
$('.switch').click(function() {
var state = 0;
var my_class = 'btn-info';
var current_class = '';
var my_button = $(this);
clonedHeaderRow.addClass("tableFloatingHeader");
clonedHeaderRow.css("position", "absolute");
clonedHeaderRow.css("top", "0px");
clonedHeaderRow.css("left", $(this).css("margin-left"));
clonedHeaderRow.css("visibility", "hidden");
if (my_button.is('.btn-warning')) {
current_class = 'btn-warning';
state = 1;
my_class = 'btn-success';
}
originalHeaderRow.addClass("tableFloatingHeaderOriginal");
});
if (my_button.is('.btn-info')) {
current_class = 'btn-info';
state = 2;
my_class = 'btn-warning';
}
if (my_button.is('.btn-danger')) {
current_class = 'btn-danger';
state =3;
my_class = 'btn-info';
}
/*
if (my_button.is('.btn-primary')) {
current_class = 'btn-primary';
state = 3;
my_class = 'btn-info';
}*/
if (my_button.is('.btn-success')) {
current_class = 'btn-success';
state = 0;
my_class = 'btn-danger';
}
var id = my_button.attr('id');
$('#hidden_'+id).attr('value', 'state_'+state+'_'+id);
my_button.attr('data-state', state);
my_button.removeClass(current_class);
UpdateTableHeaders();
$(window).scroll(UpdateTableHeaders);
$(window).resize(UpdateTableHeaders);
my_button.addClass('btn b1');
my_button.addClass(my_class);
});
</script>
<form method="post" action="index.php?action=attendance_sheet_add&<?php echo api_get_cidreq().$param_gradebook.$param_filter ?>&attendance_id=<?php echo $attendance_id?>" >
$("table.tableWithFloatingHeader").each(function() {
$(this).wrap("<div class=\"divTableWithFloatingHeader\" style=\"position:relative\"></div>");
var originalHeaderRow = $("tr:first", this)
originalHeaderRow.before(originalHeaderRow.clone());
var clonedHeaderRow = $("tr:first", this)
clonedHeaderRow.addClass("tableFloatingHeader");
clonedHeaderRow.css("position", "absolute");
clonedHeaderRow.css("top", "0px");
clonedHeaderRow.css("left", $(this).css("margin-left"));
clonedHeaderRow.css("visibility", "hidden");
originalHeaderRow.addClass("tableFloatingHeaderOriginal");
});
UpdateTableHeaders();
$(window).scroll(UpdateTableHeaders);
$(window).resize(UpdateTableHeaders);
});
</script>
<form id="form_attendance_sheet" method="post" action="index.php?action=attendance_sheet_add&<?php echo api_get_cidreq().$param_gradebook.$param_filter ?>&attendance_id=<?php echo $attendance_id?>" >
<div class="attendance-sheet-content" style="width:100%;background-color:#E1E1E1;margin-top:20px;">
<div class="divTableWithFloatingHeader attendance-users-table" style="width:45%;float:left;margin:0px;padding:0px;">
@ -230,19 +277,23 @@ if (api_is_allowed_to_edit(null, true) || api_is_coach(api_get_session_id(), api
foreach ($attendant_calendar as $calendar) {
$date = $calendar['date'];
$time = $calendar['time'];
$datetime = $date.'<br />'.$time;
$datetime = api_format_date($calendar['date_time'], DATE_FORMAT_NUMBER_NO_YEAR);
$img_lock = Display::return_icon('lock.gif',get_lang('DateUnLock'),array('class'=>'img_lock','id'=>'datetime_column_'.$calendar['id']));
if (!empty($calendar['done_attendance'])){
$datetime = '<font color="blue">'.$date.'<br />'.$time.'</font>';
$datetime = '<font color="blue">'.$datetime.'</font>';
}
$disabled_check = 'disabled = "true"';
$input_hidden = '<input type="hidden" id="hidden_input_'.$calendar['id'].'" name="hidden_input[]" value="" disabled />';
if ($next_attendance_calendar_id == $calendar['id']) {
$input_hidden = '<input type="hidden" id="hidden_input_'.$calendar['id'].'" name="hidden_input[]" value="'.$calendar['id'].'" />';
$disabled_check = '';
$img_lock = Display::return_icon('unlock.gif',get_lang('DateLock'),array('class'=>'img_unlock','id'=>'datetime_column_'.$calendar['id']));
} else {
$input_hidden = '<input type="hidden" id="hidden_input_'.$calendar['id'].'" name="hidden_input[]" value="" />';
}
$result .= '<th width="800px">';
@ -254,7 +305,6 @@ if (api_is_allowed_to_edit(null, true) || api_is_coach(api_get_session_id(), api
if ($is_locked_attendance == false) {
if (api_is_allowed_to_edit(null, true)) {
//$result .= '<br /><input type="checkbox" class="checkbox_head_'.$calendar['id'].'" id="checkbox_head_'.$calendar['id'].'" '.$disabled_check.' checked="checked" />';
$result .= $input_hidden.'</div></center></th>';
}
}
@ -311,19 +361,22 @@ if (api_is_allowed_to_edit(null, true) || api_is_coach(api_get_session_id(), api
}
echo '<td style="'.$style_td.'" class="checkboxes_col_'.$calendar['id'].'">';
echo '<div style="height:20px">';
echo '<center>';
echo '<div style="text-align:center; height:20px">';
if (api_is_allowed_to_edit(null, true)) {
if (!$is_locked_attendance || api_is_platform_admin()) {
//echo '<input type="checkbox" name="check_presence['.$calendar['id'].'][]" value="'.$user['user_id'].'" '.$disabled.' '.$checked.' />';
foreach ($attendance_states as $key => $state) {
$input_checked = null;
if ($key == $presence) {
$input_checked = " checked=checked";
}
echo Display::tag('label', '<input type="checkbox" name="check_presence['.$calendar['id'].'][]" value = "state_'.$key.'_'.$user['user_id'].'" '.$disabled.' '.$input_checked.' />&nbsp;'.$state, array('class'=> 'checkbox'));
//echo Display::tag('label', '<input type="checkbox" name="check_presence['.$calendar['id'].'][]" value = "state_'.$key.'_'.$user['user_id'].'" '.$disabled.' '.$input_checked.' />&nbsp;'.$state, array('class'=> 'checkbox'));
}
$link_id = 'link_'.$key.'_'.$user['user_id'].'_'.$calendar['id'];
$attributes = array('id' => $link_id, 'class' => 'switch '.$disabled);
echo $attendance_obj->get_attendance_state_button($presence, false, $attributes);
echo '<input id = "hidden_'.$link_id.'" type="hidden" name="check_presence['.$calendar['id'].'][]" '.$input_checked.' value="'.$presence.'" />';
echo '<span class="anchor_'.$calendar['id'].'"></span>';
} else {
@ -342,7 +395,7 @@ if (api_is_allowed_to_edit(null, true) || api_is_coach(api_get_session_id(), api
break;
}
}
echo '</center>';
echo '</div>';
echo '</td>';
}
@ -364,7 +417,7 @@ if (api_is_allowed_to_edit(null, true) || api_is_coach(api_get_session_id(), api
<?php if (!$is_locked_attendance || api_is_platform_admin()) {
if (api_is_allowed_to_edit(null, true)) {
?>
<button type="submit" class="save"><?php echo get_lang('Save') ?></button>
<button onclick="save_checkboxes();" type="button" class="save"><?php echo get_lang('Save') ?></button>
<?php }
}
?>
@ -409,7 +462,7 @@ if (api_is_allowed_to_edit(null, true) || api_is_coach(api_get_session_id(), api
<tr class="<?php echo $class ?>">
<td>
<?php
echo $attendance_states[$presence['presence']];
echo $attendance_obj->get_attendance_state_button($presence['presence']);
//echo $presence['presence']?Display::return_icon('checkbox_on.gif',get_lang('Presence')):Display::return_icon('checkbox_off.gif',get_lang('Presence'))
echo "&nbsp; ".$presence['date_time'] ?>
</td>
@ -422,4 +475,4 @@ if (api_is_allowed_to_edit(null, true) || api_is_coach(api_get_session_id(), api
<?php }
?>
</table>
<?php } ?>
<?php } ?>

@ -95,7 +95,7 @@ $(function() {
var col_split = col_id.split("_");
var calendar_id = col_split[2];
var class_img = $(this).attr("class");
if (class_img == "img_unlock") {
//lock
$(".checkbox_head_"+calendar_id).attr("disabled", true);
@ -109,6 +109,10 @@ $(function() {
$(this).attr("class","img_lock");
$("#hidden_input_"+calendar_id).attr("value","");
$("#hidden_input_"+calendar_id).attr("disabled",true);
$(".checkboxes_col_"+calendar_id).find(".switch").each(function(index) {
$(this).addClass("disabled");
});
return false;
} else {
@ -116,6 +120,7 @@ $(function() {
$(".checkbox_head_"+calendar_id).attr("disabled", false);
$(".checkbox_head_"+calendar_id).removeAttr("disabled");
$(".row_odd td.checkboxes_col_"+calendar_id).css({"opacity":"1","background-color":"#dcdcdc", "border-left":"1px #bbb solid", "border-right":"1px #bbb solid", "z-index":"1" });
$(".row_even td.checkboxes_col_"+calendar_id).css({"opacity":"1","background-color":"#eee", "border-left":"1px #bbb solid", "border-right":"1px #bbb solid", "z-index":"1" });
@ -130,12 +135,17 @@ $(function() {
// $("row_odd td.checkboxes_col_"+calendar_id).css({"opacity":"1","background-color":"#FFF", "border-left":"1px #EEEE00 solid", "border-right":"1px #EEEE00 solid" , "border-bottom":"1px #ccc solid" });
});
$(".checkboxes_col_"+calendar_id+" input:checkbox").attr("disabled",false);
$(".checkboxes_col_"+calendar_id).find(".switch").each(function(index) {
$(this).removeClass("disabled");
});
$(this).attr("src","'.api_get_path(WEB_CODE_PATH).'img/unlock.gif");
$(this).attr("title","'.get_lang('DateLock').'");
$(this).attr("alt","'.get_lang('DateLock').'");
$(this).attr("class","img_unlock");
$("#hidden_input_"+calendar_id).attr("disabled",false);
console.log(calendar_id);
$("#hidden_input_"+calendar_id).attr("value",calendar_id);
return false;
}

@ -1418,5 +1418,27 @@ class Attendance
public function set_course_int_id($course_id) {
$this->course_int_id = intval($course_id);
}
public function get_attendance_states() {
$attendance_states = array(
'1' => array('label' => get_lang('Present'), 'class' => 'btn-success') ,
'0' => array('label' => get_lang('Absent'), 'class' => 'btn-danger') ,
'3' => array('label' => get_lang('Late'), 'class' => 'btn-info') ,
'2' => array('label' => get_lang('VeryLate'), 'class' => 'btn-warning') ,
);
return $attendance_states;
}
public function get_attendance_state_button($state_id, $add_label = false, $extra_attributes = array()) {
$state_list = $this->get_attendance_states();
if (isset($state_list[$state_id])) {
$label = '&nbsp;';
if ($add_label) {
$label = $state_list[$state_id]['label'];
}
$extra_attributes['class'] = $extra_attributes['class']." btn ".$state_list[$state_id]['class'];
return Display::url($label, '', $extra_attributes);
}
return null;
}
}
Loading…
Cancel
Save