Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
курc.docx
Скачиваний:
0
Добавлен:
01.07.2025
Размер:
606.17 Кб
Скачать

If(checkNullUndefined(studentId))

{

student = this.StudentModel.getStudentById(studentId);

this.View.renderStudentInfoBox(student);

}

};

this.editUserShowBox = (studentRow) =>

{

var studentId = parseInt(studentRow.parentNode.parentNode.getAttribute('data-studentid')),

student = {},

allGroups = [];

If(checkNullUndefined(studentId))

{

allGroups = this.GroupModel.getAllGroupsArr();

student = this.StudentModel.getStudentById(studentId);

this.View.renderEditStudentBox(student, allGroups);

}

};

this.deleteUserShowBox = (studentRow) =>

{

var studentId = parseInt(studentRow.parentNode.parentNode.getAttribute('data-studentid'));

If(checkNullUndefined(studentId))

{

this.View.renderDeleteUserShowBox(studentId);

}

};

this.render = () =>

{

var allStudents = this.StudentModel.getAllStudents(),

allGroups = this.GroupModel.getAllGroupsArr();

this.View.renderStudentTable(allStudents, allGroups);

};

this.createStudent = () =>

{

var inputsBox = document.getElementById('createStudents').querySelectorAll('input, select'),

groupsIdArr = this.GroupModel.getAllGroupsIdArr(),

studentObj = {},

studentInfo = {};

studentInfo = this.studentBoxGetInputParams(inputsBox, groupsIdArr);

studentObj = studentInfo.data;

If(!studentInfo.CheckError)

{

this.StudentModel.createStudent(

studentObj,

() => this.render()

);

}

};

this.editStudent = () =>

{

var inputsBox = document.getElementById('editStudent').querySelectorAll('input, select'),

studentId = parseInt(document.getElementById('editStudent').getAttribute('data-studentid')),

groupsIdArr = this.GroupModel.getAllGroupsIdArr(),

studentObj = {},

studentInfo = {};

studentInfo = this.studentBoxGetInputParams(inputsBox, groupsIdArr);

studentObj = studentInfo.data;

If(!studentInfo.CheckError)

{

studentObj.studentId = studentId;

this.StudentModel.editStudent(

studentObj,

() => () => this.render()

);

}

};

this.deleteStudent = () =>

{

var studentId = parseInt(document.getElementById('deleteStudent').getAttribute('data-studentid'));

If(checkNullUndefined(studentId))

{

this.StudentModel.deleteStudent(

{studentId},

() => this.render()

);

}

};

}

/assets/js/model/CommonModel .js

function CommonModel()

{

this.basicErrorHandler = (code) =>

{

c('ERROR: ' + code);

};

}

/assets/js/models/GroupModel .js

function GroupModel()

{

this.groupsArr = [];

this.specialityKeys = {};

this.addNewGroup = (group) =>

{

this.groupsArr.push(group);

};

this.updateGroup = (group) =>

{

var groupId = group.id;

this.groupsArr.some((item, i) =>

{

if(item.id === groupId)

{

this.groupsArr[i] = group;

return true;

}

});

};

this.geleteGroup = (groupId) =>

{

this.groupsArr.forEach((item, i) =>

{

if(item.id === groupId)

{

this.groupsArr.splice(i, 1);

}

});

};

this.getAllGroupsStudentsRequest = (callbackFunc) =>

{

AjaxController('getAllGroupsStudents',

'groupController',

{},

({data: {groupsArr}, data: {studentsArr}, data: {specialityKeys}}) =>

{

this.groupsArr = groupsArr;

for(let key in specialityKeys)

{

this.specialityKeys[specialityKeys[key].id] = specialityKeys[key].name;

}

callbackFunc(groupsArr, studentsArr, this.specialityKeys);

},

this.basicErrorHandler

);

};

this.deleteGroup = ({groupId}, callbackFunc) =>

{

AjaxController('deleteGroup',

'groupController',

{groupId},

() =>

{

this.geleteGroup(groupId);

callbackFunc();

},

this.basicErrorHandler

);

};

this.createGroup = ({name, curatorNameLast, speciality}, callbackFunc) =>

{

AjaxController('createGroup',

'groupController',

{name, curatorNameLast, speciality},

({data: {group}}) =>

{