Created
May 18, 2017 12:34
-
-
Save amoretspero/a8c30e0cac082b7ad9c05c35d876b8bb to your computer and use it in GitHub Desktop.
Sample code for client-side code in JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
========== | |
File name: examsearch-index.js | |
This javascript file contains javascript codes that should be used only at /ExamSearch/Index.cshtml | |
Codes that are used at other files or codes that can also be used at some other files should not go here. | |
Codes that can also be used at some other files should go to: | |
1) site.js -> When That code is used over the entire site. | |
2) ***.js -> When code is not used over the entire site, but shared by plural files. | |
In case of 2, create javascript file that can contain common codes that have common characteristics. | |
========== | |
*/ | |
/** | |
* Changes list of months that exam was held for selected school year. | |
* If none is selected, list of months will be empty. | |
*/ | |
function ChangeMonthList() { | |
var selectedSchoolYear = document.getElementById('schoolyear-selected').value; | |
var selectedYear = document.getElementById('year-selected').value; | |
if (selectedSchoolYear == "고등학교3학년" || selectedSchoolYear == "고등학교2학년" || selectedSchoolYear == "고등학교1학년") { | |
$.ajax({ | |
url: '/api/v1/Storage/AvailableMonths?Year=' + selectedYear + '&SchoolYear=' + selectedSchoolYear, | |
dataType: 'json', | |
type: 'GET', | |
contentType: 'application/x-www-form-urlencoded; charset=utf-8', | |
success: function (data) { | |
if (data.availability) { | |
document.getElementById('month-selection').innerHTML = ""; | |
document.getElementById('month-selection-select').innerHTML = ""; | |
document.getElementById('month-selection-region').removeAttribute('hidden'); | |
data.months.forEach(function (val, idx, arr) { | |
document.getElementById('month-selection').appendChild(GenerateElementWithAttributes('button', { | |
'id': 'month-selection-button-' + data.monthsId[idx].value, 'type': 'button', 'class': 'btn btn-default', 'onclick': FunctionStringBuilder('CheckMonth', [{ arg: val, isString: true }]) + '; ' + FunctionStringBuilder('ResetFormError', [{ arg: 'month', isString: true }, { arg: 'csat', isString: true }]) | |
}, [document.createTextNode(val)])); | |
document.getElementById('month-selection-select').appendChild(GenerateElementWithAttributes('input', { 'type': 'checkbox', 'hidden': '', 'id': 'month-selection-select-' + data.monthsId[idx].value, }, [])); | |
}); | |
} | |
else { | |
document.getElementById('month-selection').innerHTML = ""; | |
document.getElementById('month-selection-select').innerHTML = ""; | |
document.getElementById('month-selection-region').removeAttribute('hidden'); | |
document.getElementById('month-selection').innerHTML = ""; | |
document.getElementById('month-selection').appendChild(GenerateElementWithAttributes('button', { 'id': 'month-selection-button-na', 'type': 'button', 'class': 'btn btn-default', 'disabled': '' }, [document.createTextNode('정보 없음')])); | |
} | |
} | |
}); | |
} | |
else { | |
document.getElementById('month-selection').innerHTML = ""; | |
document.getElementById('month-selection-select').innerHTML = ""; | |
document.getElementById('month-selection-region').setAttribute('hidden', ''); | |
} | |
} | |
/** | |
* Checkes hidden checkbox for month selection button. | |
* @param { string } month Month of selection. | |
*/ | |
function CheckMonth(month) { | |
var monthIds = { '전체': 'all', '3월': 'mar', '4월': 'apr', '6월': 'jun', '7월': 'jul', '9월': 'sep', '10월': 'oct', '11월': 'nov' }; | |
var months = ['전체', '3월', '4월', '6월', '7월', '9월', '10월', '11월']; | |
if (months.find(function (val, idx, obj) { if (val == month) { return true; } else { return false; } }) != undefined) { | |
var monthId = monthIds[month]; | |
if (month == '전체') { | |
if (!document.getElementById('month-selection-select-' + monthId).checked) { | |
months.forEach(function (val, idx, arr) { | |
if (val != '전체') { | |
var targetButton = document.getElementById('month-selection-button-' + monthIds[val]); | |
var targetCheckbox = document.getElementById('month-selection-select-' + monthIds[val]); | |
if (targetButton != undefined) { | |
targetButton.attributes['class'].nodeValue = 'btn btn-danger bgcolor border-color'; | |
targetButton.setAttribute('disabled', 'true'); | |
targetCheckbox.checked = true; | |
} | |
} | |
else { | |
var targetButton = document.getElementById('month-selection-button-' + monthIds[val]); | |
var targetCheckbox = document.getElementById('month-selection-select-' + monthIds[val]); | |
targetButton.attributes['class'].nodeValue = 'btn btn-danger bgcolor border-color'; | |
targetCheckbox.checked = true; | |
} | |
}) | |
} | |
else { | |
months.forEach(function (val, idx, arr) { | |
if (val != '전체') { | |
var targetButton = document.getElementById('month-selection-button-' + monthIds[val]); | |
var targetCheckbox = document.getElementById('month-selection-select-' + monthIds[val]); | |
if (targetButton != undefined) { | |
targetButton.attributes['class'].nodeValue = 'btn btn-default'; | |
targetButton.removeAttribute('disabled'); | |
targetCheckbox.checked = false; | |
} | |
} | |
else { | |
var targetButton = document.getElementById('month-selection-button-' + monthIds[val]); | |
var targetCheckbox = document.getElementById('month-selection-select-' + monthIds[val]); | |
targetButton.attributes['class'].nodeValue = 'btn btn-default'; | |
targetCheckbox.checked = false; | |
} | |
}) | |
} | |
} | |
else { | |
if (!document.getElementById('month-selection-select-' + monthId).checked) { | |
var targetButton = document.getElementById('month-selection-button-' + monthIds[month]); | |
var targetCheckbox = document.getElementById('month-selection-select-' + monthIds[month]); | |
targetButton.attributes['class'].nodeValue = 'btn btn-danger bgcolor border-color'; | |
targetCheckbox.checked = true; | |
} | |
else { | |
var targetButton = document.getElementById('month-selection-button-' + monthIds[month]); | |
var targetCheckbox = document.getElementById('month-selection-select-' + monthIds[month]); | |
targetButton.attributes['class'].nodeValue = 'btn btn-default'; | |
targetCheckbox.checked = false; | |
} | |
} | |
} | |
} | |
/** | |
* Check hidden checkbox with appropriate value for 'include solution', and change button color appropriately. | |
* @param {string} isCheck Whether solution inclusion select is checked as 'YES' or 'NO'. | |
*/ | |
function CheckSolution(isCheck) { | |
if (isCheck == 'no') { | |
document.getElementById('solution-selection-check').checked = false; | |
document.getElementById('solution-selection-select-no').setAttribute('class', 'btn btn-danger bgcolor border-color'); | |
document.getElementById('solution-selection-select-yes').setAttribute('class', 'btn btn-default'); | |
} | |
if (isCheck == 'yes') { | |
document.getElementById('solution-selection-check').checked = true; | |
document.getElementById('solution-selection-select-yes').setAttribute('class', 'btn btn-danger bgcolor border-color'); | |
document.getElementById('solution-selection-select-no').setAttribute('class', 'btn btn-default'); | |
} | |
} | |
/** | |
* Sets error message. | |
* @param {string} input Prefix for span element. | |
* @param {string} msg Error message. | |
*/ | |
function SetFormError(input, examType, msg) { | |
document.getElementById(input + '-error' + '-' + examType).innerText = msg; | |
} | |
/** | |
* Removes error message. | |
* @param {string} input Prefix for span element. | |
*/ | |
function ResetFormError(input, examType) { | |
document.getElementById(input + '-error' + '-' + examType).innerText = ""; | |
} | |
/** | |
* Resets school year selection. | |
*/ | |
function ResetSchoolYear() { | |
document.getElementById('schoolyear-selected').selectedIndex = 0; | |
document.getElementById('month-selection').innerHTML = ""; | |
document.getElementById('month-selection-select').innerHTML = ""; | |
document.getElementById('month-selection-region').setAttribute('hidden', ''); | |
} | |
/** | |
* Shows waiting message. Message will change with interval. | |
* @param {string} type Type of exam search. | |
* @param {number} interval Interval to display, in milliseconds. | |
*/ | |
function ShowWaitingMessage(type, interval) { | |
var text = [ | |
"지금 찾고있어요! 조금만 기다려주세요 ㅠㅠ", | |
"여러분의 후원이 겁나 빠른 서버를 만듭니다.", | |
"일해라 서버!", | |
"기다리느라 힘드시죠? 거의 다 찾았어요, 거의...", | |
"문제 풀 준비는 되셨나요?" | |
]; | |
var count = 0; | |
var intervalTracker = setInterval(function () { | |
document.getElementById('waiting-message-' + type).innerHTML = ""; | |
document.getElementById('waiting-message-' + type).appendChild(GenerateElementWithAttributes('p', { 'style': 'font-size:16px;' }, [document.createTextNode(text[count])])); | |
//document.getElementById('waiting-message-' + type).innerText = text[count]; | |
SEMICOLON.widget.animations(); | |
count++; | |
if (count == text.length) { | |
count = 0; | |
} | |
}, interval); | |
return intervalTracker | |
} | |
/** | |
* (ONLY when ES6 is fully supported.) Sleeps to given duration. | |
* @param {number} ms Duration to sleep, in milliseconds. | |
*/ | |
/*function sleep(ms) { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
}*/ | |
/** | |
* Gets exam paper and solution if exists and wanted. | |
* @param {string} type Type of previous exam papers. Currently 'csat' is the only supported one. | |
*/ | |
function GetExamPapers(type) { | |
if (type == "csat") { | |
//await sleep(1000); | |
var querySuccess = true; | |
var monthNumbers = { 'mar': 3, 'apr': 4, 'jun': 6, 'jul': 7, 'sep': 9, 'oct': 10, 'nov': 11 }; | |
var subjectTranslationDict = { | |
'국어영역': 'korean', | |
'언어영역': 'korean', | |
'수학영역': 'math', | |
'수리영역': 'math', | |
'영어영역': 'english', | |
'외국어영역': 'english', | |
'한국사영역': 'koreanhistory', | |
'사회탐구영역': 'socialstudies', | |
'과학탐구영역': 'science' | |
}; | |
var typeTranslationDict = { | |
'수능기출문제': 'csat', | |
'사관학교기출문제': 'militaryacademy', | |
'경찰대학기출문제': 'policeacademy' | |
}; | |
var year = document.getElementById('year-selected').value; | |
if (year == "") { | |
querySuccess = false; | |
SetFormError('year', 'csat', '연도는 꼭 선택해야 합니다.'); | |
} | |
var schoolyear = document.getElementById('schoolyear-selected').value; | |
if (schoolyear == "") { | |
querySuccess = false; | |
SetFormError('schoolyear', 'csat', '학년은 꼭 선택해야 합니다.'); | |
} | |
var urlEncodedSchoolYear = encodeURIComponent(schoolyear); | |
var months = []; | |
var childNodes = document.getElementById('month-selection-select').childNodes; | |
for (i = 0; i < childNodes.length; i++) { | |
var idx = i | |
var val = childNodes[i]; | |
if (val.nodeType == 1) { | |
var monthId = val.getAttribute('id').substring(23, 26); | |
if (monthId != 'all') { | |
if (val.checked) { | |
months.push(monthNumbers[monthId]); | |
} | |
} | |
} | |
} | |
if (months.length <= 0) { | |
querySuccess = false; | |
SetFormError('month', 'csat', '월은 최소한 하나 이상 선택해야 합니다.'); | |
} | |
var includeSolution = true; | |
if (querySuccess) { | |
document.getElementById('waiting-message-' + type).innerHTML = ""; | |
document.getElementById('waiting-message-' + type).appendChild(GenerateElementWithAttributes('p', { 'style': 'font-size:16px;' }, [document.createTextNode('찾을 준비를 하고 있어요.')])); | |
document.getElementById('button-get-exam-papers-' + type).innerText = "곧 찾아드릴게요!"; | |
document.getElementById('button-get-exam-papers-' + type).setAttribute('disabled', ''); | |
var intervalTracker = ShowWaitingMessage(type, 2000); | |
var queryString = ""; | |
queryString += 'Type=' + type + "&"; | |
queryString += 'Year=' + year + "&"; | |
queryString += 'SchoolYear=' + urlEncodedSchoolYear + "&"; | |
for (i = 0; i < months.length; i++) { | |
queryString += 'Months=' + months[i].toString() + "&"; | |
} | |
queryString += 'IncludeSolution=' + includeSolution; | |
var formData = new FormData(); | |
formData.append('Type', type); | |
formData.append('Year', year); | |
formData.append('SchoolYear', schoolyear); | |
formData.append('Months', months); | |
formData.append('IncludeSolution', includeSolution); | |
months.forEach(function (val, idx, arr) { | |
}); | |
$.ajax({ | |
url: '/api/v1/Storage/PastCsatFiles' + "?" + queryString, | |
type: 'GET', | |
datatype: 'json', | |
contentType: 'application/x-www-form-urlencoded; charset=utf-8', | |
beforeSend: function () { | |
document.getElementById('year-selected').setAttribute('disabled', ''); | |
document.getElementById('schoolyear-selected').setAttribute('disabled', ''); | |
for (i = 0; i < document.getElementById('month-selection').childNodes.length; i++) { | |
document.getElementById('month-selection').childNodes[i].setAttribute('disabled', ''); | |
} | |
}, | |
success: function (data) { | |
if (data.errorMessage == null && data.results.length > 0) { | |
document.getElementById('exam-search-result-header').innerHTML = ""; | |
document.getElementById('exam-search-result-header').appendChild(GenerateElementWithAttributes('h2', {}, [document.createTextNode('당신이 찾은 기출문제, 바로 여기에 있습니다.')])); | |
document.getElementById('exam-search-result-header').appendChild(GenerateElementWithAttributes('span', {}, [document.createTextNode('언제 어디서나, 원하는대로 다운받으세요!')])); | |
document.getElementById('exam-search-result').innerHTML = ""; | |
document.getElementById('exam-search-result-subject-filter').innerHTML = ""; | |
var subjects = []; | |
data.results.forEach(function (val, idx, arr) { | |
var type = val.type; | |
var examType = val.examType; | |
var problemType = val.problemType; | |
var schoolYear = val.schoolYear; | |
var year = val.year; | |
var heldYear = year - 1; | |
var month = val.month; | |
var subject = val.subject; | |
var link = val.link; | |
var includeSolutionResult = val.includeSolution; | |
var solutionLink = val.solutionLink; | |
var displayName = ""; | |
var examPaperDownloadCount = val.examPaperDownloadCount; | |
var solutionDownloadCount = val.solutionDownloadCount | |
var downloadCountPostfix = "명이 다운로드 하였습니다."; | |
var imageSrc = '/images/examsearch-thumbnails/' + typeTranslationDict[type] + '-' + subjectTranslationDict[subject] + '-thumbnail.png'; | |
var examPreparer = val.examPreparer; | |
var problemCount = val.problemCount; | |
var examTimeLimit = val.examTimeLimit; | |
var difficulty = val.difficulty; | |
var examCode = val.examCode; | |
var difficultyMin = 0; | |
var difficultyMax = 5; | |
if (schoolYear == "고등학교3학년") { | |
if (month == 11 || month == 9 || month == 6) { | |
displayName = year + "학년도" + " "; | |
} | |
else { | |
displayName = heldYear + "년도" + " " | |
} | |
if (month == 11) { | |
displayName += examType + " " + subject; | |
if (problemType != null) { | |
displayName += " " + problemType; | |
} | |
} | |
else { | |
displayName += month + "월" + " " + examType + " " + subject; | |
if (problemType != null) { | |
displayName += " " + problemType; | |
} | |
} | |
} | |
else { | |
displayName = heldYear + "년도" + " " + month + "월" + " " + examType + " " + subject; | |
if (problemType != null) { | |
displayName += " " + problemType; | |
} | |
} | |
var displayYearAndMonth = ""; | |
if (schoolYear == "고등학교3학년") { | |
displayYearAndMonth = heldYear + "년" + " " + month + "월"; | |
} | |
else { | |
displayYearAndMonth = heldYear + "년" + " " + month + "월"; | |
} | |
if (subjects.filter(function (val, idx, arr) { return val == subject; }) == 0) { | |
subjects.push(subject); | |
} | |
var solutionButton = null; | |
if (includeSolution && includeSolutionResult) { | |
solutionButton = GenerateElementWithAttributes('a', { 'class': 'button button-rounded button-white button-light blockdisplay margincenter', 'href': solutionLink, 'target': '_blank', 'onclick': FunctionStringBuilder('IncreaseSolutionDownloadCount', [{ arg: examCode, isString: true }]) }, [ | |
GenerateElementWithAttributes('i', { 'class': 'icon-testcloud-solution' }, []), | |
document.createTextNode('해설보기') | |
]); | |
} | |
else { | |
solutionButton = GenerateElementWithAttributes('button', { 'class': 'button button-rounded button-white button-light blockdisplay margincenter', 'disabled': '' }, [ | |
GenerateElementWithAttributes('i', { 'class': 'icon-testcloud-solution' }, []), | |
document.createTextNode('해설없음') | |
]); | |
} | |
var difficultyElem = [GenerateElementWithAttributes('b', {}, [document.createTextNode('난이도')]), document.createTextNode(' ')]; | |
for (i = 0; i < difficultyMax; i++) { | |
if (i < difficulty) { | |
difficultyElem.push(GenerateElementWithAttributes('i', { 'class': 'icon-testcloud-fire-on' }, [])); | |
} | |
else { | |
difficultyElem.push(GenerateElementWithAttributes('i', { 'class': 'icon-testcloud-fire-off' }, [])); | |
} | |
} | |
var newResultElem = GenerateElementWithAttributes('div', { 'class': 'search-result-full nobottommargin' }, [ | |
GenerateElementWithAttributes('div', { 'class': 'panel panel-default' }, [ | |
GenerateElementWithAttributes('div', { 'class': 'panel-heading' }, [ | |
GenerateElementWithAttributes('h3', { 'class': 'panel-title', 'style': 'margin:initial' }, [ | |
GenerateElementWithAttributes('a', { 'href': '/ExamSearch/Detail/' + val.examCode, 'target': '_blank' }, [ | |
document.createTextNode(displayName) | |
]) | |
]), | |
GenerateElementWithAttributes('h5', { 'class': 'exam-search-result-title-info', 'id': 'downloadcount-exampaper-' + examCode }, [ | |
GenerateElementWithAttributes('span', { 'class': 'color' }, [document.createTextNode(examPaperDownloadCount)]), | |
document.createTextNode(downloadCountPostfix) | |
]) | |
]), | |
GenerateElementWithAttributes('div', { 'class': 'panel-body' }, [ | |
GenerateElementWithAttributes('div', { 'class': 'author-image' }, [ | |
GenerateElementWithAttributes('img', { 'class': 'img-circle', 'alt': subject+' - 썸네일', 'src': imageSrc }) | |
]), | |
GenerateElementWithAttributes('div', { 'class': 'exam-search-result-control' }, [ | |
GenerateElementWithAttributes('a', { 'class': 'button button-rounded button-dirtygreen blockdisplay margincenter', 'href': link, 'target': '_blank', 'onclick': FunctionStringBuilder('IncreaseExamPaperDownloadCount', [{ arg: examCode, isString: true }, { arg: true, isString: false }]) }, [ | |
GenerateElementWithAttributes('i', { 'class': 'icon-testcloud-download' }, []), | |
document.createTextNode('다운로드') | |
]), | |
solutionButton | |
]), | |
GenerateElementWithAttributes('div', { 'class': 'exam-search-result-info' }, [ | |
GenerateElementWithAttributes('h4', { 'class': 'exam-search-result-title' }, [ | |
GenerateElementWithAttributes('span', { 'class': 'exam-search-result-title-text nocolor' }, [document.createTextNode('기출문제 정보')]) | |
]), | |
GenerateElementWithAttributes('div', { 'class': 'exam-search-result-info-sub' }, [ | |
GenerateElementWithAttributes('span', { 'class': 'exam-search-result-info-sub-title' }, [ | |
GenerateElementWithAttributes('b', {}, [document.createTextNode('출제년도')]), | |
document.createTextNode(' ' + displayYearAndMonth) | |
]), | |
document.createTextNode(' | '), | |
GenerateElementWithAttributes('span', { 'class': 'exam-search-result-info-sub-title' }, [ | |
GenerateElementWithAttributes('b', {}, [document.createTextNode('대상학년')]), | |
document.createTextNode(' ' + schoolYear) | |
]), | |
document.createTextNode(' | '), | |
GenerateElementWithAttributes('span', { 'class': 'exam-search-result-info-sub-title' }, [ | |
GenerateElementWithAttributes('b', {}, [document.createTextNode('출제기관')]), | |
document.createTextNode(' ' + examPreparer) | |
]), | |
GenerateElementWithAttributes('br', {}, []) | |
]), | |
GenerateElementWithAttributes('div', { 'class': 'exam-search-result-info-sub' }, [ | |
GenerateElementWithAttributes('span', { 'class': 'exam-search-result-info-sub-title' }, [ | |
GenerateElementWithAttributes('b', {}, [document.createTextNode('문항수')]), | |
document.createTextNode(' ' + problemCount + '문제') | |
]), | |
document.createTextNode(' | '), | |
GenerateElementWithAttributes('span', { 'class': 'exam-search-result-info-sub-title' }, [ | |
GenerateElementWithAttributes('b', {}, [document.createTextNode('시험시간')]), | |
document.createTextNode(' ' + examTimeLimit + '분') | |
]), | |
document.createTextNode(' | '), | |
GenerateElementWithAttributes('span', { 'class': 'exam-search-result-info-sub-title' }, difficultyElem) | |
]) | |
]), | |
]) | |
]) | |
]); | |
document.getElementById('exam-search-result').appendChild(newResultElem); | |
if (idx == data.results.length - 1) { | |
document.getElementById('exam-search-result').appendChild(GenerateElementWithAttributes('div', { 'class': 'center' }, [ | |
GenerateElementWithAttributes('button', { 'class': 'button button-xlarge', 'onclick': FunctionStringBuilder('RefreshSearchForm', []) }, [ | |
GenerateElementWithAttributes('i', { 'class': 'icon-refresh' }, []), | |
document.createTextNode('다시 검색하시겠어요?') | |
]) | |
])); | |
if (months.filter(function (val, idx, arr) { return (val == 6 || val == 9 || val == 11) }).length > 0 && schoolyear == "고등학교3학년") { | |
document.getElementById('exam-search-result').appendChild(GenerateElementWithAttributes('div', { 'class': 'center topmargin-sm' }, [ | |
GenerateElementWithAttributes('h4', {}, [document.createTextNode('한국교육과정평가원에서 시행하는 고등학교 3학년 대상의 6월, 9월 모의평가와 대학수학능력시험은 별도의 해설지를 제공하지 않습니다.')]) | |
])); | |
} | |
document.getElementById('exam-search-result-subject-filter').appendChild(GenerateElementWithAttributes('button', { 'class': 'button button-large', 'onclick': FunctionStringBuilder('FilterSubject', [{ arg: '전과목', isString: true }]) }, [document.createTextNode('전과목')])) | |
subjects.forEach(function (val, idx, arr) { | |
document.getElementById('exam-search-result-subject-filter').appendChild(GenerateElementWithAttributes('button', { 'class': 'button button-large button-white button-light', 'onclick': FunctionStringBuilder('FilterSubject', [{ arg: val, isString: true }]) }, [document.createTextNode(val)])); | |
}); | |
clearInterval(intervalTracker); | |
document.getElementById('waiting-message-csat').innerHTML = ""; | |
document.getElementById('button-get-exam-papers-' + typeTranslationDict[type]).removeAttribute('disabled'); | |
document.getElementById('button-get-exam-papers-' + typeTranslationDict[type]).innerText = "시험지를 찾아주세요!"; | |
document.getElementById('year-selected').removeAttribute('disabled'); | |
document.getElementById('schoolyear-selected').removeAttribute('disabled'); | |
for (i = 0; i < document.getElementById('month-selection').childNodes.length; i++) { | |
document.getElementById('month-selection').childNodes[i].removeAttribute('disabled'); | |
} | |
$('#content').scrollToElement(); | |
} | |
}); | |
} | |
else { | |
document.getElementById('exam-search-result-header').innerHTML = ""; | |
document.getElementById('exam-search-result-header').appendChild(GenerateElementWithAttributes('h2', {}, [document.createTextNode('앗...! 찾으시는 기출문제가 없습니다. ㅠㅠ')])); | |
document.getElementById('exam-search-result-header').appendChild(GenerateElementWithAttributes('span', {}, [document.createTextNode('Contact 페이지에서 연락해주시면 빠르게 업로드 해드리겠습니다!')])); | |
document.getElementById('exam-search-result').innerHTML = ""; | |
document.getElementById('exam-search-result').appendChild(GenerateElementWithAttributes('div', { 'class': 'center' }, [ | |
GenerateElementWithAttributes('button', { 'class': 'button button-xlarge', 'onclick': FunctionStringBuilder('RefreshSearchForm', []) }, [ | |
GenerateElementWithAttributes('i', { 'class': 'icon-refresh' }, []), | |
document.createTextNode('다시 검색하시겠어요?') | |
]) | |
])); | |
clearInterval(intervalTracker); | |
document.getElementById('waiting-message-csat').innerHTML = ""; | |
document.getElementById('button-get-exam-papers-' + type).removeAttribute('disabled'); | |
document.getElementById('button-get-exam-papers-' + type).innerText = "시험지를 찾아주세요!"; | |
document.getElementById('year-selected').removeAttribute('disabled'); | |
document.getElementById('schoolyear-selected').removeAttribute('disabled'); | |
for (i = 0; i < document.getElementById('month-selection').childNodes.length; i++) { | |
document.getElementById('month-selection').childNodes[i].removeAttribute('disabled'); | |
} | |
$('#content').scrollToElement(); | |
} | |
} | |
}); | |
} | |
} | |
else if (type == "militaryacademy" || type == "policeacademy") { | |
var querySuccess = true; | |
var monthNumbers = { 'mar': 3, 'apr': 4, 'jun': 6, 'jul': 7, 'sep': 9, 'oct': 10, 'nov': 11 }; | |
var subjectTranslationDict = { | |
'국어영역': 'korean', | |
'언어영역': 'korean', | |
'수학영역': 'math', | |
'수리영역': 'math', | |
'영어영역': 'english', | |
'외국어영역': 'english' | |
}; | |
var typeTranslationDict = { | |
'수능기출문제': 'csat', | |
'사관학교기출문제': 'militaryacademy', | |
'경찰대학기출문제': 'policeacademy' | |
}; | |
var year = document.getElementById('year-selected-'+type).value; | |
if (year == "") { | |
querySuccess = false; | |
SetFormError('year', type, '연도는 꼭 선택해야 합니다.'); | |
} | |
var schoolYear = "공통"; | |
var urlEncodedSchoolYear = encodeURIComponent(schoolYear); | |
var months = []; | |
var includeSolution = true; | |
if (querySuccess) { | |
document.getElementById('waiting-message-' + type).innerHTML = ""; | |
document.getElementById('waiting-message-' + type).appendChild(GenerateElementWithAttributes('p', { 'style': 'font-size:16px;' }, [document.createTextNode('찾을 준비를 하고 있어요.')])); | |
document.getElementById('button-get-exam-papers-' + type).innerText = "곧 찾아드릴게요!"; | |
document.getElementById('button-get-exam-papers-' + type).setAttribute('disabled', ''); | |
var intervalTracker = ShowWaitingMessage(type, 2000); | |
var queryString = ""; | |
queryString += 'Type=' + type + "&"; | |
queryString += 'Year=' + year + "&"; | |
queryString += 'SchoolYear=' + urlEncodedSchoolYear + "&"; | |
for (i = 0; i < months.length; i++) { | |
queryString += 'Months=' + months[i].toString() + "&"; | |
} | |
queryString += 'IncludeSolution=' + includeSolution; | |
$.ajax({ | |
url: '/api/v1/Storage/PastCsatFiles' + "?" + queryString, | |
type: 'GET', | |
datatype: 'json', | |
contentType: 'application/x-www-form-urlencoded; charset=utf-8', | |
beforeSend: function () { | |
document.getElementById('year-selected-' + type).setAttribute('disabled', ''); | |
}, | |
success: function (data) { | |
if (data.errorMessage == null && data.results.length > 0) { | |
document.getElementById('exam-search-result-header').innerHTML = ""; | |
document.getElementById('exam-search-result-header').appendChild(GenerateElementWithAttributes('h2', {}, [document.createTextNode('당신이 찾은 기출문제, 바로 여기에 있습니다.')])); | |
document.getElementById('exam-search-result-header').appendChild(GenerateElementWithAttributes('span', {}, [document.createTextNode('언제 어디서나, 원하는대로 다운받으세요!')])); | |
document.getElementById('exam-search-result').innerHTML = ""; | |
var subjects = []; | |
data.results.forEach(function (val, idx, arr) { | |
var type = val.type; | |
var examType = val.examType; | |
var problemType = val.problemType; | |
var schoolYear = val.schoolYear; | |
var year = val.year; | |
var heldYear = year - 1; | |
var month = val.month; | |
var subject = val.subject; | |
var link = val.link; | |
var includeSolutionResult = val.includeSolution; | |
var solutionLink = val.solutionLink; | |
var displayName = ""; | |
var examPaperDownloadCount = val.examPaperDownloadCount; | |
var solutionDownloadCount = val.solutionDownloadCount; | |
var downloadCountPostfix = "명이 다운로드 하였습니다."; | |
var imageSrc = '/images/examsearch-thumbnails/' + typeTranslationDict[type] + '-' + subjectTranslationDict[subject] + '-thumbnail.png'; | |
var examPreparer = val.examPreparer; | |
var problemCount = val.problemCount; | |
var examTimeLimit = val.examTimeLimit; | |
var difficulty = val.difficulty; | |
var examCode = val.examCode; | |
var difficultyMin = 0; | |
var difficultyMax = 5; | |
displayName += heldYear.toString() + "년도" + " "; | |
displayName += examType + " " + subject; | |
if (problemType != null) { | |
displayName += " " + problemType; | |
} | |
displayYearAndMonth = heldYear + "년"; | |
if (subjects.filter(function (val, idx, arr) { return val == subject; }) == 0) { | |
subjects.push(subject); | |
} | |
var solutionButton = null; | |
if (includeSolution && includeSolutionResult) { | |
solutionButton = GenerateElementWithAttributes('a', { 'class': 'button button-rounded button-white button-light blockdisplay margincenter', 'href': solutionLink, 'target': '_blank', 'onclick': FunctionStringBuilder('IncreaseSolutionDownloadCount', [{ arg: examCode, isString: true }, { arg: true, isString: false }]) }, [ | |
GenerateElementWithAttributes('i', { 'class': 'icon-testcloud-solution' }, []), | |
document.createTextNode('해설보기') | |
]); | |
} | |
else { | |
solutionButton = GenerateElementWithAttributes('button', { 'class': 'button button-rounded button-white button-light blockdisplay margincenter', 'disabled': '' }, [ | |
GenerateElementWithAttributes('i', { 'class': 'icon-testcloud-solution' }, []), | |
document.createTextNode('해설없음') | |
]); | |
} | |
var difficultyElem = [GenerateElementWithAttributes('b', {}, [document.createTextNode('난이도')]), document.createTextNode(' ')]; | |
for (i = 0; i < difficultyMax; i++) { | |
if (i < difficulty) { | |
difficultyElem.push(GenerateElementWithAttributes('i', { 'class': 'icon-testcloud-fire-on' }, [])); | |
} | |
else { | |
difficultyElem.push(GenerateElementWithAttributes('i', { 'class': 'icon-testcloud-fire-off' }, [])); | |
} | |
} | |
var newResultElem = GenerateElementWithAttributes('div', { 'class': 'search-result-full nobottommargin' }, [ | |
GenerateElementWithAttributes('div', { 'class': 'panel panel-default' }, [ | |
GenerateElementWithAttributes('div', { 'class': 'panel-heading' }, [ | |
GenerateElementWithAttributes('h3', { 'class': 'panel-title', 'style': 'margin:initial' }, [ | |
GenerateElementWithAttributes('a', { 'href': '/ExamSearch/Detail/' + val.examCode, 'target': '_blank' }, [ | |
document.createTextNode(displayName) | |
]) | |
]), | |
GenerateElementWithAttributes('h5', { 'class': 'exam-search-result-title-info', 'id': 'downloadcount-exampaper-' + examPaperDownloadCount }, [ | |
GenerateElementWithAttributes('span', { 'class': 'color' }, [document.createTextNode(examPaperDownloadCount)]), | |
document.createTextNode(downloadCountPostfix) | |
]) | |
]), | |
GenerateElementWithAttributes('div', { 'class': 'panel-body' }, [ | |
GenerateElementWithAttributes('div', { 'class': 'author-image' }, [ | |
GenerateElementWithAttributes('img', { 'class': 'img-circle', 'alt': subject + ' - 썸네일', 'src': imageSrc }) | |
]), | |
GenerateElementWithAttributes('div', { 'class': 'exam-search-result-control' }, [ | |
GenerateElementWithAttributes('a', { | |
'class': 'button button-rounded button-dirtygreen blockdisplay margincenter', 'href': link, 'target': '_blank', 'onclick': FunctionStringBuilder('IncreaseExamPaperDownloadCount', [{ arg: examCode, isString: true }])}, [ | |
GenerateElementWithAttributes('i', { 'class': 'icon-testcloud-download' }, []), | |
document.createTextNode('다운로드') | |
]), | |
solutionButton | |
]), | |
GenerateElementWithAttributes('div', { 'class': 'exam-search-result-info' }, [ | |
GenerateElementWithAttributes('h4', { 'class': 'exam-search-result-title' }, [ | |
GenerateElementWithAttributes('span', { 'class': 'exam-search-result-title-text nocolor' }, [document.createTextNode('기출문제 정보')]) | |
]), | |
GenerateElementWithAttributes('div', { 'class': 'exam-search-result-info-sub' }, [ | |
GenerateElementWithAttributes('span', { 'class': 'exam-search-result-info-sub-title' }, [ | |
GenerateElementWithAttributes('b', {}, [document.createTextNode('출제년도')]), | |
document.createTextNode(' ' + displayYearAndMonth) | |
]), | |
document.createTextNode(' | '), | |
GenerateElementWithAttributes('span', { 'class': 'exam-search-result-info-sub-title' }, [ | |
GenerateElementWithAttributes('b', {}, [document.createTextNode('대상학년')]), | |
document.createTextNode(' ' + schoolYear) | |
]), | |
document.createTextNode(' | '), | |
GenerateElementWithAttributes('span', { 'class': 'exam-search-result-info-sub-title' }, [ | |
GenerateElementWithAttributes('b', {}, [document.createTextNode('출제기관')]), | |
document.createTextNode(' ' + examPreparer) | |
]), | |
GenerateElementWithAttributes('br', {}, []) | |
]), | |
GenerateElementWithAttributes('div', { 'class': 'exam-search-result-info-sub' }, [ | |
GenerateElementWithAttributes('span', { 'class': 'exam-search-result-info-sub-title' }, [ | |
GenerateElementWithAttributes('b', {}, [document.createTextNode('문항수')]), | |
document.createTextNode(' ' + problemCount + '문제') | |
]), | |
document.createTextNode(' | '), | |
GenerateElementWithAttributes('span', { 'class': 'exam-search-result-info-sub-title' }, [ | |
GenerateElementWithAttributes('b', {}, [document.createTextNode('시험시간')]), | |
document.createTextNode(' ' + examTimeLimit + '분') | |
]), | |
document.createTextNode(' | '), | |
GenerateElementWithAttributes('span', { 'class': 'exam-search-result-info-sub-title' }, difficultyElem) | |
]) | |
]), | |
]) | |
]) | |
]); | |
document.getElementById('exam-search-result').appendChild(newResultElem); | |
if (idx == data.results.length - 1) { | |
document.getElementById('exam-search-result').appendChild(GenerateElementWithAttributes('div', { 'class': 'center' }, [ | |
GenerateElementWithAttributes('button', { 'class': 'button button-xlarge', 'onclick': FunctionStringBuilder('RefreshSearchForm', []) }, [ | |
GenerateElementWithAttributes('i', { 'class': 'icon-refresh' }, []), | |
document.createTextNode('다시 검색하시겠어요?') | |
]) | |
])); | |
document.getElementById('exam-search-result-subject-filter').appendChild(GenerateElementWithAttributes('button', { 'class': 'button button-large', 'onclick': FunctionStringBuilder('FilterSubject', [{ arg: '전과목', isString: true }]) }, [document.createTextNode('전과목')])) | |
subjects.forEach(function (val, idx, arr) { | |
document.getElementById('exam-search-result-subject-filter').appendChild(GenerateElementWithAttributes('button', { 'class': 'button button-large button-white button-light', 'onclick': FunctionStringBuilder('FilterSubject', [{ arg: val, isString: true }]) }, [document.createTextNode(val)])); | |
}); | |
clearInterval(intervalTracker); | |
document.getElementById('waiting-message-' + typeTranslationDict[type]).innerHTML = ""; | |
document.getElementById('button-get-exam-papers-' + typeTranslationDict[type]).removeAttribute('disabled'); | |
document.getElementById('year-selected-' + typeTranslationDict[type]).removeAttribute('disabled'); | |
$('#content').scrollToElement(); | |
} | |
}); | |
} | |
else { | |
document.getElementById('exam-search-result-header').innerHTML = ""; | |
document.getElementById('exam-search-result-header').appendChild(GenerateElementWithAttributes('h2', {}, [document.createTextNode('앗...! 찾으시는 기출문제가 없습니다. ㅠㅠ')])); | |
document.getElementById('exam-search-result-header').appendChild(GenerateElementWithAttributes('span', {}, [document.createTextNode('Contact 페이지에서 연락해주시면 빠르게 업로드 해드리겠습니다!')])); | |
document.getElementById('exam-search-result').innerHTML = ""; | |
document.getElementById('exam-search-result').appendChild(GenerateElementWithAttributes('div', { 'class': 'center' }, [ | |
GenerateElementWithAttributes('button', { 'class': 'button button-xlarge', 'onclick': FunctionStringBuilder('RefreshSearchForm', []) }, [ | |
GenerateElementWithAttributes('i', { 'class': 'icon-refresh' }, []), | |
document.createTextNode('다시 검색하시겠어요?') | |
]) | |
])); | |
clearInterval(intervalTracker); | |
document.getElementById('waiting-message-' + type).innerHTML = ""; | |
document.getElementById('button-get-exam-papers-' + type).removeAttribute('disabled'); | |
document.getElementById('year-selected-'+type).removeAttribute('disabled'); | |
$('#content').scrollToElement(); | |
} | |
} | |
}); | |
} | |
} | |
} | |
function FilterSubject(subject) { | |
var subjectButtons = document.getElementById('exam-search-result-subject-filter').childNodes; | |
for (i=0; i < subjectButtons.length; i++) { | |
var subjectButton = subjectButtons[i]; | |
if (subjectButton.nodeType != 3) { | |
if (subjectButton.innerText == subject) { | |
subjectButton.setAttribute('class', 'button button-large'); | |
} | |
else { | |
subjectButton.setAttribute('class', 'button button-large button-white button-light'); | |
} | |
if (i == subjectButtons.length - 1) { | |
var searchResults = document.getElementById('exam-search-result').childNodes; | |
for (j=0; i < searchResults.length; j++) { | |
var searchResult = searchResults[j]; | |
if (searchResult.nodeType != 3) { | |
if (subject == '전과목') { | |
searchResult.removeAttribute('hidden'); | |
} | |
else { | |
if (searchResult.getElementsByClassName('panel-title')[0].textContent.includes(subject)) { | |
searchResult.removeAttribute('hidden'); | |
} | |
else { | |
searchResult.setAttribute('hidden', ''); | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
/** | |
* Refreshes exam paper search form and result region. | |
* @param type {string} | |
*/ | |
function RefreshSearchForm(type) { | |
document.getElementById('year-selected').selectedIndex = 0; | |
document.getElementById('year-selected-militaryacademy').selectedIndex = 0; | |
document.getElementById('year-selected-policeacademy').selectedIndex = 0; | |
document.getElementById('schoolyear-selected').selectedIndex = 0; | |
document.getElementById('month-selection').innerHTML = ""; | |
document.getElementById('month-selection-select').innerHTML = ""; | |
document.getElementById('month-selection-region').setAttribute('hidden', ''); | |
document.getElementById('exam-search-result-subject-filter').innerHTML = ""; | |
$('#wrapper').scrollToElement(function () { | |
document.getElementById('exam-search-result').innerHTML = ""; | |
document.getElementById('exam-search-result-header').innerHTML = ""; | |
var newResultHeader = GenerateElementWithAttributes('div', { 'id': 'exam-search-result-header', 'class': 'heading-block center', 'data-animate': 'fadeIn' }, [ | |
GenerateElementWithAttributes('h2', {}, [document.createTextNode('기출문제를 먼저 검색해주세요!')]), | |
GenerateElementWithAttributes('span', {}, [document.createTextNode('바로 위에 간단한 정보를 입력하는 곳이 있습니다.')]) | |
]); | |
var newResult = GenerateElementWithAttributes('div', { 'id': 'exam-search-result', 'class': 'grid-2', 'data-animate': 'fadeIn' }, []); | |
var newFilter = GenerateElementWithAttributes('div', { 'id': 'exam-search-result-subject-filter', 'class': 'center bottommargin', 'data-animate': 'fadeIn'}, []); | |
ReplaceElement(newResultHeader, document.getElementById('exam-search-result-header')); | |
ReplaceElement(newResult, document.getElementById('exam-search-result')); | |
ReplaceElement(newFilter, document.getElementById('exam-search-result-subject-filter')); | |
SEMICOLON.widget.animations(); | |
}); | |
} | |
/** | |
* Toggles detail selection for given type of default category. | |
* @param {string} type Type of default category. | |
*/ | |
function ToggleDefaultCategory(type) { | |
var targetRegion = document.getElementById('exam-search-default-category-detail-' + type); | |
if (targetRegion.hasAttribute('hidden')) { | |
targetRegion.removeAttribute('hidden'); | |
} | |
else { | |
targetRegion.setAttribute('hidden', ''); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment