/** * 高级检索 */ $(document).ready(function () { $('#sort-ul li:lt(6)').show(); $('#journal-ul li:lt(9)').show(); /** * 展开期刊分类 */ $('.show-more-sort').click(function () { var cls = $(this).prop('class'); if (cls == 'show-more-sort') { $('#sort-ul li').show(); $('.more-sort-txt').text('Fold '); $('.more-sort-open').css('transform', 'rotate(0deg)'); $(this).prop('class', 'hide-more-sort'); } else { $('#sort-ul li:gt(5)').hide(); $('.more-sort-txt').text('Expand '); $('.more-sort-open').css('transform', 'rotate(-90deg)'); $(this).prop('class', 'show-more-sort'); } }); /** * 展开期刊 */ $('.show-more-journal').click(function () { var cls = $(this).prop('class'); if (cls == 'show-more-journal') { $('#journal-ul li').show(); $('.more-journal-txt').text('Fold '); $('.more-journal-open').css('transform', 'rotate(0deg)'); $(this).prop('class', 'hide-more-journal'); } else { $('#journal-ul li:gt(8)').hide(); $('.more-journal-txt').text('Expand '); $('.more-journal-open').css('transform', 'rotate(-90deg)'); $(this).prop('class', 'show-more-journal'); } }); /** * 检索文章 */ $('#btn-search').click(function () { var searchSql = $('#text-sql').html(); // 1.获取 journalIds var journalIds = ''; var scope = $('#journal-scope').val(); if (scope > 0) { if ($('input[name="journalId"]:checked').length == 0) { alert('Please select a journal!'); return false; } $('input[name="journalId"]:checked').each(function () { journalIds += $(this).val() + 'J'; }); } else { journalIds = $('#current-jid').val(); } searchSql = '(' + searchSql + ' AND ' + journalIds + '[Journal])'; // 2.年, 卷, 期, 起始页, doi var year = $('#year').val(); if (year.trim() != '') { var regYear = new RegExp('^[1-9][0-9]{3}$'); if (!regYear.test(year)) { alert('Year input error!'); $('#year').focus(); return false; } searchSql = '(' + searchSql + ' AND ' + year + '[Year])'; } var volumn = $('#volumn').val(); if (volumn.trim() != '') { var regVolumn = new RegExp('^([a-zA-Z0-9])+$'); if (!regVolumn.test(volumn)) { alert('volumn input error!'); $('#volumn').focus(); return false; } searchSql = '(' + searchSql + ' AND ' + volumn + '[volumn])'; } var issue = $('#issue').val(); if (issue.trim() != '') { var regIssue = new RegExp('^([a-zA-Z0-9])+$'); if (!regIssue.test(issue)) { alert('issue input error!'); $('#issue').focus(); return false; } searchSql = '(' + searchSql + ' AND ' + issue + '[issue])'; } var startP = $('#startP').val(); if (startP.trim() != '') { var regStartP = new RegExp('^[0-9]{1,}$'); if (!regStartP.test(startP)) { alert('Start page input error!'); $('#startP').focus(); return false; } searchSql = '(' + searchSql + ' AND ' + startP + '[startP])'; } var doi = $('#doi').val(); if (doi.trim() != '') { searchSql = '(' + searchSql + ' AND ' + doi + '[DOI])'; } // 3.专题, var subject = $('#subject').val(); if (subject) { if (subject != '0') { searchSql = '(' + searchSql + ' AND ' + subject + '[SubjectArticle])'; } } //栏目 var channel = $('#channel').val(); if (channel) { if (channel != '0') { searchSql = '(' + searchSql + ' AND ' + channel + '[Channel])'; } } // 4.字段组合 // joinField(); // 5.出版年, 每页显示, 排序方式 var startYear = $('#startYear').val(); if (startYear.trim() != '') { searchSql = '(' + searchSql + ' AND ' + startYear + '[FromYear])'; } var endYear = $('#endYear').val(); if (endYear.trim() != '') { searchSql = '(' + searchSql + ' AND ' + endYear + '[ToYear])'; } var pageSize = $('#page-size').val(); if (pageSize.trim() != '') { var regSize = new RegExp('^[1-9][0-9]{0,4}$'); if (!regSize.test(pageSize)) { alert('Page input error!'); $('#page-size').focus(); return false; } searchSql = '((' + searchSql + ' AND ' + pageSize + '[PageSize])'; } var sort = $('input[name="sort"]:checked').val(); searchSql = '(' + searchSql + ' AND ' + sort + '[Order])'; $('#text-sql').html(searchSql); $('#inp-sql').val(searchSql); $('#search-form').submit(); }); }); /*************************************************************************************************************************** ****** 上面 jquery, 下面 javascript ****** ***************************************************************************************************************************/ /** * 动态加载指定专题 * @returns {boolean} */ function changeSubject() { var scope = $('#journal-scope').val(); if (scope > 0) { var journalIds = ''; $('input[name="journalId"]:checked').each(function () { journalIds += $(this).val() + ','; }); journalIds = journalIds.substring(0, journalIds.length - 1); $.ajax({ url: 'changeSubject.do', data: { journalIds: journalIds }, type: 'post', dataType: 'json', success: function (data) { $('#subject option:not(:first)').remove(); if (data != null) { $.each(data, function (i, item) { $('#subject').append(''); }); } }, error: function () { alert('Exception'); } }); } } /** * 期刊 change 事件 * @param obj */ function changeJournal(obj) { $.ajax({ url: 'changeJournal.do', data: { journalId: obj.value }, type: 'post', dataType: 'json', success: function (res) { if (res != null) { var journalSortId = ''; var boxLen = 0; $.each(res, function (i, item) { if (journalSortId == '') { journalSortId = item['journalSortId']; } var jbox = $('input[name="journalId"][value="' + item['journalId'] + '"]:checked').length; boxLen += jbox; }); if (boxLen == 0) { $('input[name="journalSortId"][value="' + journalSortId + '"]').removeProp('indeterminate'); $('input[name="journalSortId"][value="' + journalSortId + '"]').removeProp('checked'); } else if (res.length != boxLen) { $('input[name="journalSortId"][value="' + journalSortId + '"]').removeProp('checked'); $('input[name="journalSortId"][value="' + journalSortId + '"]').prop('indeterminate', true); } else if (res.length == boxLen) { $('input[name="journalSortId"][value="' + journalSortId + '"]').removeProp('indeterminate'); $('input[name="journalSortId"][value="' + journalSortId + '"]').prop('checked', true); } $('.show-more-sort').prop('class', 'hide-more-sort'); $('.more-sort-txt').text('Fold '); $('#sort-ul li').show(); changeSubject(); } }, error: function () { alert('Exception'); } }); } /** * 期刊分类 change 事件 * @returns {boolean} */ function changeJournalSort() { // 1.获取全选状态期刊分类 ids var checkedJournalSortIds = ''; $('input[name="journalSortId"]:checked').each(function () { checkedJournalSortIds += $(this).val() + ','; }); checkedJournalSortIds = checkedJournalSortIds.substring(0, checkedJournalSortIds.length - 1); // 2.获取半选状态期刊分类 ids var indeterminateJournalSortIds = ''; $('input[name="journalSortId"]:indeterminate').each(function () { indeterminateJournalSortIds += $(this).val() + ','; }); indeterminateJournalSortIds = indeterminateJournalSortIds.substring(0, indeterminateJournalSortIds.length - 1); var journalIds = ''; if (indeterminateJournalSortIds) { $('input[name="journalId"]:checked').each(function () { journalIds += $(this).val() + ','; }); journalIds = journalIds.substring(0, journalIds.length - 1); } if (!checkedJournalSortIds && !indeterminateJournalSortIds) { $('input[name="journalId"]').removeProp('checked'); return false; } $.ajax({ url: 'changeJournalSort.do', data: { checkedJournalSortIds: checkedJournalSortIds, indeterminateJournalSortIds: indeterminateJournalSortIds, journalIds: journalIds }, type: 'post', dataType: 'json', success: function (data) { if (data != null) { $('#journal-ul').html(''); $.each(data, function (i, item) { if (item['check'] == 't') { $('#journal-ul').append('
'); } else { $('#journal-ul').append(''); } }); $('.show-more-journal').prop('class', 'hide-more-journal'); $('.more-journal-txt').text('Fold '); $('#journal-ul li').show(); changeSubject(); } } }); } /** * 全选 * @param type */ function selectAll(type) { if (type == 'sort') { $('input[name="journalSortId"]').removeProp('indeterminate'); $('input[name="journalSortId"]').prop('checked', true); $('input[name="journalId"]').prop('checked', true); } if (type == 'journal') { $('input[name="journalSortId"]').removeProp('indeterminate'); $('input[name="journalId"]').prop('checked', true); $('input[name="journalSortId"]').prop('checked', true); } changeSubject(); } /** * 全不选 * @param type */ function cancelAll(type) { if (type == 'sort') { $('input[name="journalSortId"]').removeProp('indeterminate'); $('input[name="journalSortId"]').removeProp('checked'); $('input[name="journalId"]').removeProp('checked'); } if (type == 'journal') { $('input[name="journalSortId"]').removeProp('indeterminate'); $('input[name="journalId"]').removeProp('checked'); $('input[name="journalSortId"]').removeProp('checked'); } changeSubject(); } /** * 字段组合 */ function joinField() { // 获取字段组合最外层 table 容器 var fieldContainer = document.getElementById('field-container'); // 获取 table 容器里边所有 tr, 并遍历 var rows = fieldContainer.getElementsByTagName('tr'); var searchSql = ''; for (var r = 0; r < rows.length; r++) { // 获取每个 tr 的 id 属性 var trId = rows[r].id; trId = trId.replace('fields', ''); // value var value = document.getElementById('value' + trId).value; if (value.trim() != '') { // key var key = document.getElementById('key' + trId).value; if (trId == 1) { // 文题, 摘要, 关键词 if (key == 'tit-abs-key') { searchSql = '(((' + value + '[Title]) OR ' + value + '[Abstract]) OR ' + value + '[Keyword])'; } else { // 其它 searchSql = '(' + value + '[' + key + '])'; } } if (trId > 1) { var logic = document.getElementById('logic' + trId).value; // logic if (key == 'tit-abs-key') { searchSql = '(((' + searchSql + ' ' + logic + ' ' + value + '[Title] OR) + ' + value + '[Abstract]) OR ' + value + '[Keyword])'; } else { searchSql = '(' + searchSql + ' ' + logic + ' ' + value + '[' + key + '])'; } } } } document.getElementById('text-sql').innerHTML = searchSql; } /** * 添加字段组合 */ var id = 2; function addFieldItem() { $('#field-first').attr('class', 'field-first'); $('.joint-field').append('