-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathteacher.html
146 lines (118 loc) · 5.23 KB
/
teacher.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide">
<div class="row">
<div class="col-xs-6">
<table id="tblTeacher" class="table table-condensed table-bordered table-responsive table-hover table-striped">
<thead>
<tr>
<td>First Name</td>
<td>Last Name</td>
</tr>
</thead>
<!-- tbody will be created via ajax call -->
</table>
</div>
<div class="col-xs-6">
<form name="frmTeacher" id="frmTeacher" class="form-horizontal" role="form" method="POST">
<input type="hidden" name="hdnId" id="hdnId" value="0"/>
<div class="form-group" >
<label class="col-xs-2 control-label" for="teacherFirstName">First Name</label>
<div class="col-xs-4">
<input type="text" class="form-control" id="teacherFirstName" name="teacherFirstName" />
</div>
</div>
<div class="form-group" >
<label class="col-xs-2 control-label" for="teacherLastName">Last Name</label>
<div class="col-xs-4">
<input type="text" class="form-control" id="teacherLastName" name="teacherLastName" />
</div>
</div>
<div class="form-group" >
<label class="col-xs-2 control-label" for="teacherActive">Active</label>
<div class="col-xs-1 pull-left">
<input type="checkbox" class="form-control" id="teacherActive" name="teacherActive" checked="checked" />
</div>
</div>
<div class="form-group">
<div class="col-xs-offset-2 col-xs-4">
<button id="btnSave" class="btn btn-default btn-primary">Save</button>
<button id="btnClear" class="btn">Clear</button>
</div>
</div>
</form>
</div>
</div> <!-- div class=row -->
</div> <!-- div class=ui-tabs-panel -->
<script>
$(document).ready(function() {
var dtTeacher = $('#tblTeacher').DataTable({
"bJQueryUI": true,
"sScrollY": "450px",
"bPaginate": false,
"bScrollCollapse": true,
"bAutoWidth": true,
"ajax": 'backend/teacher/getTeacherList.php',
"columns": [
{"data": "first_name"},
{"data": "last_name"}
]
});
function dataTableReload() {
dtTeacher.ajax.reload();
}
$('#tblTeacher').on("click", "tbody tr", function() {
var teacherId = $(this).attr('id');
//console.log('row dbl-clicked id=' + teacherId);
$.ajax({
type: "GET",
url: "backend/teacher/getTeacherById.php",
data: {id: teacherId}
}).done(function(data) {
// parse returned data
var dataObj = $.parseJSON(data);
var rec = dataObj.data[0];
//populate form
$('#frmTeacher input#hdnId').val(rec.id);
$('#frmTeacher input#teacherFirstName').val(rec.first_name);
$('#frmTeacher input#teacherLastName').val(rec.last_name);
$('#frmTeacher input#teacherActive').prop('checked', function() {
return rec.active == 1;
});
});
return false;
});
$('#frmTeacher #btnClear').on('click', function() {
$('#frmTeacher input#hdnId').val(0);
$('#frmTeacher').trigger("reset");
// added Jan18/2015 (LCC)
$('#frmTeacher input#teacherFirstName').focus();
$('.error').remove();
return false;
});
$('#frmTeacher #btnSave').on('click', function() {
var hasError = false;
$('.error').remove();
//---------- start of validation checks
if ($('#frmTeacher input#teacherFirstName').val() === '') {
$('#frmTeacher input#teacherFirstName').after('<span class=\'error\' style=\'color:red;\'> Please fill in first name.</span>');
hasError = true;
}
//---------- end of validation checks
if (hasError === true) {
// nothing
} else {
$('.error').remove();
$.ajax({
type: "POST",
url: 'backend/teacher/saveTeacher.php',
data: $('#frmTeacher').serialize()
}).done(function(data) {
dataTableReload();
// added Jan18/2015 (LCC)
$.notify('Teacher record saved',{ className:'success', globalPosition:'top centre' });
$('#frmTeacher #btnClear').trigger( "click" );
});
}
return false;
});
});
</script>