Skip to content
Snippets Groups Projects
Commit 08d21988 authored by xamgore's avatar xamgore
Browse files

Reduced handler `Search`

* Renamed AdmStudents -> Students
* New func Students::search()
parent 4fae796d
Branches
Tags
No related merge requests found
Showing
with 61 additions and 251 deletions
...@@ -10,7 +10,7 @@ $(function() ...@@ -10,7 +10,7 @@ $(function()
radioValue = this.value; radioValue = this.value;
$("#facultySelect [value='0']").attr('selected', 'selected'); $("#facultySelect [value='0']").attr('selected', 'selected');
$("#gradeSelect [value='0']").attr('selected', 'selected'); $("#gradeSelect [value='0']").attr('selected', 'selected');
$("#departmentSelect [value='0']").attr('selected', 'selected'); $("#departmentSelect [value='0']").attr('selected', 'selected');
$('#SecondStep').css('display', 'block'); $('#SecondStep').css('display', 'block');
$('#ThirdStep_Student').css('display', 'none'); $('#ThirdStep_Student').css('display', 'none');
$('#ThirdStep_Teacher').css('display', 'none'); $('#ThirdStep_Teacher').css('display', 'none');
...@@ -25,7 +25,7 @@ $(function() ...@@ -25,7 +25,7 @@ $(function()
{ {
$('#departmentSelect').attr('disabled', 'disabled'); $('#departmentSelect').attr('disabled', 'disabled');
$("#departmentSelect").html('<option value="0">--- Кафедра ---</option>'); $("#departmentSelect").html('<option value="0">--- Кафедра ---</option>');
$.post(URLdir + 'handler/admTeachers/getDepartmentsList', {'facultyID': $('#facultySelect option:selected').val()}, function(data){ $.post(URLdir + 'handler/teachers/getDepartmentsList', {'facultyID': $('#facultySelect option:selected').val()}, function(data){
$.each(data, function(i){ $.each(data, function(i){
var dep = data[i]; var dep = data[i];
if (!dep.Name) dep.Name = 'Служебная кафедра'; if (!dep.Name) dep.Name = 'Служебная кафедра';
...@@ -45,15 +45,15 @@ $(function() ...@@ -45,15 +45,15 @@ $(function()
$('#gradeSelect').change(function(){ $('#gradeSelect').change(function(){
if (($('#gradeSelect option:selected').val()!= '0')) { if (($('#gradeSelect option:selected').val()!= '0')) {
$('#FourthStep_'+radioValue).css('display', 'block'); $('#FourthStep_'+radioValue).css('display', 'block');
} }
}); });
$('body').on('click', '#downloadTeacherPDF', function(){ $('body').on('click', '#downloadTeacherPDF', function(){
$('#downloadTeacherPDF').attr('disabled', 'disabled'); $('#downloadTeacherPDF').attr('disabled', 'disabled');
$.fileDownload(URLdir + 'handler/admAccounts/getActivationForTeachers', { $.fileDownload(URLdir + 'handler/admAccounts/getActivationForTeachers', {
httpMethod: "POST", httpMethod: "POST",
data: data:
{ {
'facultyID': $('#facultySelect option:selected').val() 'facultyID': $('#facultySelect option:selected').val()
}, },
...@@ -65,13 +65,13 @@ $(function() ...@@ -65,13 +65,13 @@ $(function()
EventInspector_ShowMsg("Отсутствуют неактивированные аккаунты!", "success"); EventInspector_ShowMsg("Отсутствуют неактивированные аккаунты!", "success");
} }
}); });
}); });
$('body').on('click', '#downloadStudentPDF', function(e){ $('body').on('click', '#downloadStudentPDF', function(e){
$('#downloadStudentPDF').attr('disabled', 'disabled'); $('#downloadStudentPDF').attr('disabled', 'disabled');
$.fileDownload(URLdir + 'handler/admAccounts/getActivationForStudents', { $.fileDownload(URLdir + 'handler/admAccounts/getActivationForStudents', {
httpMethod: "POST", httpMethod: "POST",
data: data:
{ {
'facultyID': $('#facultySelect option:selected').val(), 'facultyID': $('#facultySelect option:selected').val(),
'gradeID': $('#gradeSelect option:selected').val() 'gradeID': $('#gradeSelect option:selected').val()
...@@ -84,5 +84,5 @@ $(function() ...@@ -84,5 +84,5 @@ $(function()
EventInspector_ShowMsg("Отсутствуют неактивированные аккаунты!", "success"); EventInspector_ShowMsg("Отсутствуют неактивированные аккаунты!", "success");
} }
}); });
}); });
}); });
\ No newline at end of file
...@@ -32,7 +32,7 @@ $(function () { ...@@ -32,7 +32,7 @@ $(function () {
$groupSelect.html('<option value="0">— Учебная группа —</option>'); $groupSelect.html('<option value="0">— Учебная группа —</option>');
if (($gradeSelect.find('option:selected').val() != '0')) { if (($gradeSelect.find('option:selected').val() != '0')) {
$.post(URLdir + 'handler/admStudents/getGroups', { $.post(URLdir + 'handler/students/getGroups', {
'facultyID': $facultySelect.find('option:selected').val(), 'facultyID': $facultySelect.find('option:selected').val(),
'gradeNum': $gradeSelect.find('option:selected').val() 'gradeNum': $gradeSelect.find('option:selected').val()
}, function (data) { }, function (data) {
...@@ -58,7 +58,7 @@ $(function () { ...@@ -58,7 +58,7 @@ $(function () {
$inputGroupSubmit.click(function () { $inputGroupSubmit.click(function () {
$inputGroupSubmit.attr('disabled', 'disabled'); $inputGroupSubmit.attr('disabled', 'disabled');
$.post(URLdir + 'handler/admStudents/create', { $.post(URLdir + 'handler/students/create', {
'firstName': $('#firstName').val(), 'firstName': $('#firstName').val(),
'secondName': $('#secondName').val(), 'secondName': $('#secondName').val(),
'lastName': $('#lastName').val(), 'lastName': $('#lastName').val(),
......
$(function()
{
var jFaculty = $('#facultySelect');
var jGrade = $('#gradeSelect');
var jGroup = $('#groupSelect');
jFaculty.find("[value='0']").attr('selected', 'selected');
jGrade.find("[value='0']").attr('selected', 'selected');
jGroup.find("[value='0']").attr('selected', 'selected');
jGrade.attr('disabled', 'disabled');
jGroup.attr('disabled', 'disabled');
// Переключение страниц
$('body').on('click', '.paginatorLink', function() {
$('.paginatorPage').addClass('hiddenPage');
$('.paginator_item').removeClass('selectedPageNum');
$('#' + this.id).removeClass('hiddenPage');
$(this).children('.paginator_item').addClass('selectedPageNum');
});
// Выбор факультета
jFaculty.change(function() {
if ((jFaculty.find('option:selected').val() != '0')) {
jGrade.removeAttr('disabled');
} else {
jGrade.attr('disabled', 'disabled');
}
jGroup.attr('disabled', 'disabled');
$("#studyGroupSelect").html('<option value="0">— Учебная группа —</option>');
}).change(searchStudents);
// Выбор курса
jGrade.change(function() {
jGroup.attr('disabled', 'disabled');
jGroup.empty();
jGroup.html('<option value="0">— Учебная группа —</option>');
if ((jGrade.find('option:selected').val() != '0')) {
$.post(URLdir + 'handler/admStudents/getGroups', {
'facultyID': jFaculty.find('option:selected').val(),
'gradeNum': jGrade.find('option:selected').val()
}, updateGroupsList, "json");
}
}).change(searchStudents);
function updateGroupsList(data) {
$.each(data, function(i) {
//jGroup.append('<optgroup label="'+data[i].SpecName+'">');
$.each(data[i].Groups, function(j) {
var group = data[i].Groups[j];
jGroup.append('<option value="' + group.ID + '">' + group.Num + ' группа</option>');
});
jGroup.append('</optgroup>');
});
jGroup.removeAttr("disabled");
}
// Выбор группы
jGroup.change(searchStudents);
// Search by name
var jStudentName = $("#studentName");
var prevNameValue = '';
var typewatch = (function() {
var timer = 0;
return function(callback, ms) {
clearTimeout(timer);
timer = setTimeout(callback, ms);
};
})();
var updateList = function(e) {
typewatch(function() {
if (prevNameValue != jStudentName.val())
searchStudents();
prevNameValue = jStudentName.val();
$(this).blur();
}, 700);
};
jStudentName
.keyup(updateList)
.bind("paste", updateList);
function searchStudents() {
var arr = {
'facultyID' : +jFaculty.find('option:selected').val(),
'gradeID' : +jGrade.find('option:selected').val(),
'groupID' : +jGroup.find('option:selected').val(),
'name' : jStudentName.val()
};
if (!arr.facultyID || !arr.gradeID)
return;
if (arr.name.length >= 3)
updateStudentsList('admStudents/getStudentsByName', arr);
else if (arr.groupID)
updateStudentsList('admStudents/getStudentsList', arr);
}
function updateStudentsList(method, params) {
$("#search_results").html('<div class="search_load"><img src="' + URLdir + 'media/img/load.gif"/></div>');
$.post(URLdir + 'handler/' + method, params, function(data) {
$("#search_results").html(data);
});
}
});
\ No newline at end of file
...@@ -4,7 +4,7 @@ $(function () { ...@@ -4,7 +4,7 @@ $(function () {
$grade.change(function () { $grade.change(function () {
$grade.html(''); $grade.html('');
$grade.attr('disabled', 'disabled'); $grade.attr('disabled', 'disabled');
$.post(URLdir + 'handler/admStudents/getGroups', { $.post(URLdir + 'handler/students/getGroups', {
'facultyID': facultyID, 'facultyID': facultyID,
'gradeNum': $grade.find('option:selected').val() 'gradeNum': $grade.find('option:selected').val()
}, },
......
...@@ -13,7 +13,7 @@ $(function () { ...@@ -13,7 +13,7 @@ $(function () {
if (($faculty.find('option:selected').val() != '0')) { if (($faculty.find('option:selected').val() != '0')) {
$department.html('<option value="0">— Кафедра —</option>'); $department.html('<option value="0">— Кафедра —</option>');
$department.attr('disabled', 'disabled'); $department.attr('disabled', 'disabled');
$.post(URLdir + 'handler/admTeachers/getDepartmentsList', { $.post(URLdir + 'handler/teachers/getDepartmentsList', {
'facultyID': $faculty.find('option:selected').val() 'facultyID': $faculty.find('option:selected').val()
}, function (data) { }, function (data) {
$.each(data, function (i) { $.each(data, function (i) {
...@@ -36,7 +36,7 @@ $(function () { ...@@ -36,7 +36,7 @@ $(function () {
$('#inputGroupSubmit').click(function () { $('#inputGroupSubmit').click(function () {
$('#inputGroupSubmit').attr('disabled', 'disabled'); $('#inputGroupSubmit').attr('disabled', 'disabled');
$.post(URLdir + 'handler/admTeachers/create', { $.post(URLdir + 'handler/teachers/create', {
'firstName': $('#firstName').val(), 'firstName': $('#firstName').val(),
'secondName': $('#secondName').val(), 'secondName': $('#secondName').val(),
'lastName': $('#lastName').val(), 'lastName': $('#lastName').val(),
......
$(function()
{
$("#facultySelect [value='0']").attr('selected', 'selected');
$('#departmentSelect').attr('disabled', 'disabled');
$("#departmentSelect [value='0']").attr('selected', 'selected');
// Переключение страниц
$('body').on('click', '.paginatorLink', function(){
$('.paginatorPage').addClass('hiddenPage');
$('.paginator_item').removeClass('selectedPageNum');
$('#'+this.id).removeClass('hiddenPage');
$(this).children('.paginator_item').addClass('selectedPageNum');
});
// Выбор факультета
$('#facultySelect').change(function(){
if (($('#facultySelect option:selected').val()!= '0')) {
$("#search_results").html('<div class="search_load"><img src="' + URLdir + 'media/img/load.gif"/></div>');
$("#departmentSelect").html('<option value="0">--- Кафедра ---</option>');
$('#departmentSelect').attr('disabled', 'disabled');
$.post(URLdir + 'handler/admTeachers/getTeachersList', {'facultyID': $('#facultySelect option:selected').val(), 'departmentID': '0'}, function(data){
$("#search_results").html(data);
});
$.post(URLdir + 'handler/admTeachers/getDepartmentsList', {'facultyID': $('#facultySelect option:selected').val()}, function(data){
$.each(data, function(i){
var dep = data[i];
if (!dep.Name) dep.Name = 'Служебная кафедра';
$("#departmentSelect").append('<option value="'+dep.ID+'">'+dep.Name+'</option>');
});
$("#departmentSelect").removeAttr("disabled");
}, "json");
}
else
{
$('#departmentSelect').attr('disabled', 'disabled');
}
});
// Выбор кафедры
$('#departmentSelect').change(function(){
$("#search_results").html('<div class="search_load"><img src="' + URLdir + 'media/img/load.gif"/></div>');
if (($('#departmentSelect option:selected').val()!= '0')) {
$.post(URLdir + 'handler/admTeachers/getTeachersList', {'facultyID': '0', 'departmentID': $('#departmentSelect option:selected').val()}, function(data){
$("#search_results").html(data);
});
}
});
});
\ No newline at end of file
...@@ -35,3 +35,11 @@ var Auth = (function () { ...@@ -35,3 +35,11 @@ var Auth = (function () {
onDeprecate: function () { } onDeprecate: function () { }
} }
})(); })();
var Watcher = (function() {
var timer = 0;
return function(ms, callback) {
clearTimeout(timer);
timer = setTimeout(callback, ms);
};
})();
...@@ -70,7 +70,16 @@ function SearchStudent(jName, jFacultySelect, jGradeSelect, jGroupSelect) { ...@@ -70,7 +70,16 @@ function SearchStudent(jName, jFacultySelect, jGradeSelect, jGroupSelect) {
}; };
this.EventsLinker = function () { this.EventsLinker = function () {
jName.change(self.Search); var typeWatcher = function(e) {
Watcher(700, function() {
if (prevNameValue != jName.val())
self.Search();
var prevNameValue = jName.val();
$(this).blur();
});
};
jName.keyup(typeWatcher).bind("paste", typeWatcher);
jFacultySelect.change(function (){ jFacultySelect.change(function (){
jGradeSelect.find('option[value=0]').attr("selected", "selected"); jGradeSelect.find('option[value=0]').attr("selected", "selected");
jGroupSelect.html("").attr("disabled", "disabled").append('<option>-- Фильтр по группе --</option>'); jGroupSelect.html("").attr("disabled", "disabled").append('<option>-- Фильтр по группе --</option>');
......
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Handler_Search extends Controller_Handler
{
public function before() {
parent::before();
}
public function action_getTeachersByName() {
$facultyID = (int) ($this->post['FacultyID'] ? $this->post['FacultyID'] : $this->user->FacultyID);
$departmentID = (int) $this->post['DepartmentID'];
$name = $this->post['Name'];
$arr = [];
// if (strlen($name) >= 3) {
$arr = Model_Teachers::search($facultyID, $departmentID, $name, 0);
// }
$this->response->body(json_encode($arr));
}
public function action_getStudentsByName() {
$facultyID = (int) ($this->post['FacultyID'] ? $this->post['FacultyID'] : $this->user->FacultyID);
$gradeID = (int) $this->post['GradeID'];
$groupID = (int) $this->post['GroupID'];
$name = $this->post['Name'];
$arr = [];
// if (strlen($name) >= 3) {
$arr = Model_Students::searchStudentsByName($name, $facultyID, $gradeID, $groupID);
// }
$this->response->body(json_encode($arr));
}
}
<?php defined('SYSPATH') or die('No direct script access.'); <?php defined('SYSPATH') or die('No direct script access.');
class Controller_Handler_AdmStudents extends Controller_Handler class Controller_Handler_Students extends Controller_Handler
{ {
const STUDENTS_LIST = '/handler/listStudents';
public function before() { public function before() {
parent::before(); parent::before();
...@@ -26,6 +24,20 @@ class Controller_Handler_AdmStudents extends Controller_Handler ...@@ -26,6 +24,20 @@ class Controller_Handler_AdmStudents extends Controller_Handler
$this->response->body(json_encode($response)); $this->response->body(json_encode($response));
} }
public function action_search() {
$this->user->checkAccess(User::RIGHTS_ADMIN | User::RIGHTS_DEAN);
$facultyID = $this->post['FacultyID'] ? $this->post['FacultyID'] : $this->user->Faculty->ID;
$gradeID = $this->post['GradeID'];
$groupID = $this->post['GroupID'];
$name = $this->post['Name'];
$list = (strlen($name) >= 3)
? Model_Students::searchStudentsByName($name, $facultyID, $gradeID, $groupID) : [];
$this->response->body(json_encode($list));
}
public function action_getGroups() { public function action_getGroups() {
$facultyID = $this->post['facultyID']; $facultyID = $this->post['facultyID'];
$gradeID = $this->post['gradeNum']; $gradeID = $this->post['gradeNum'];
...@@ -50,29 +62,4 @@ class Controller_Handler_AdmStudents extends Controller_Handler ...@@ -50,29 +62,4 @@ class Controller_Handler_AdmStudents extends Controller_Handler
$this->response->body(json_encode($groupsHandled)); $this->response->body(json_encode($groupsHandled));
} }
} }
public function action_getStudentsList() {
$faculty = Model_Faculty::with($this->post['facultyID']);
$twig = Twig::factory(self::STUDENTS_LIST, [
'List' => $faculty->getStudents($this->post['gradeID'], $this->post['groupID'])
]);
$this->response->body($twig);
}
public function action_getStudentsByName() {
$twig = Twig::factory(self::STUDENTS_LIST);
$facultyID = (int) $this->post['facultyID'];
$gradeID = (int) $this->post['gradeID'];
$groupID = (int) $this->post['groupID'];
$name = $this->post['name'];
if (strlen($name) >= 3) {
$twig->List = Model_Students::searchStudentsByName($name, $facultyID, $gradeID, $groupID);
}
$this->response->body($twig);
}
} }
<?php defined('SYSPATH') or die('No direct script access.'); <?php defined('SYSPATH') or die('No direct script access.');
class Controller_Handler_AdmTeachers extends Controller_Handler { class Controller_Handler_Teachers extends Controller_Handler
{
public function before() { public function before() {
parent::before(); parent::before();
...@@ -21,17 +21,15 @@ class Controller_Handler_AdmTeachers extends Controller_Handler { ...@@ -21,17 +21,15 @@ class Controller_Handler_AdmTeachers extends Controller_Handler {
$this->request->body(json_encode($request)); $this->request->body(json_encode($request));
} }
public function action_getTeachersList() public function action_search() {
{ $facultyID = $this->post['FacultyID'] ? $this->post['FacultyID'] : $this->user->Faculty->ID;
$departmentID = $this->post['departmentID']; $departmentID = $this->post['DepartmentID'];
$facultyID = $this->post['facultyID']; $name = $this->post['Name'];
if($departmentID != 0)
$teachers = Model_Teachers::ofDepartment($departmentID); $list = (strlen($name) >= 3)
elseif($facultyID != 0) ? Model_Teachers::search($facultyID, $departmentID, $name, 0) : [];
$teachers = Model_Teachers::ofFaculty($facultyID);
$twig = Twig::factory('admin/teachers/handler/listOutput'); $this->response->body(json_encode($list));
$twig->List = $teachers;
$this->response->body($twig);
} }
public function action_getDepartmentsList() { public function action_getDepartmentsList() {
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
{% block title %}Поиск студентов{% endblock %} {% block title %}Поиск студентов{% endblock %}
{% block office_media %} {% block office_media %}
{{ search.head("URLdir + 'handler/search/GetStudentsByName'") }} {# todo: this is not a good sign #} {{ search.head("URLdir + 'handler/students/search'") }} {# todo: this is not a good sign #}
{% endblock %} {% endblock %}
{% block _ResultPrototype %} {% block _ResultPrototype %}
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
{% block title %}Поиск преподавателей{% endblock %} {% block title %}Поиск преподавателей{% endblock %}
{% block office_media %} {% block office_media %}
{{ search.head("URLdir + 'handler/search/GetTeachersByName'") }} {{ search.head("URLdir + 'handler/teachers/search'") }}
{% endblock %} {% endblock %}
{% block main_top_title %}Преподаватели{% endblock %} {% block main_top_title %}Преподаватели{% endblock %}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment