define(['jquery', 'bootstrap', 'frontend', 'form', 'template'], function ($, undefined, Frontend, Form, Template) { var validatoroptions = { invalid: function (form, errors) { $.each(errors, function (i, j) { Layer.msg(j); }); } }; var Controller = { login: function () { //本地验证未通过时提示 $("#login-form").data("validator-options", validatoroptions); //为表单绑定事件 Form.api.bindevent($("#login-form"), function (data, ret) { setTimeout(function () { location.href = ret.url ? ret.url : "/"; }, 1000); }); //忘记密码 $(document).on("click", ".btn-forgot", function () { var id = "resetpwdtpl"; var content = Template(id, {}); Layer.open({ type: 1, title: __('Reset password'), area: ["450px", "355px"], content: content, success: function (layero) { var rule = $("#resetpwd-form input[name='captcha']").data("rule"); Form.api.bindevent($("#resetpwd-form", layero), function (data) { Layer.closeAll(); }); $(layero).on("change", "input[name=type]", function () { var type = $(this).val(); $("div.form-group[data-type]").addClass("hide"); $("div.form-group[data-type='" + type + "']").removeClass("hide"); $('#resetpwd-form').validator("setField", { captcha: rule.replace(/remote\((.*)\)/, "remote(" + $(this).data("check-url") + ", event=resetpwd, " + type + ":#" + type + ")") }); $(".btn-captcha").data("url", $(this).data("send-url")).data("type", type); }); } }); }); }, register: function () { //本地验证未通过时提示 $("#register-form").data("validator-options", validatoroptions); //为表单绑定事件 Form.api.bindevent($("#register-form"), function (data, ret) { setTimeout(function () { location.href = ret.url ? ret.url : "/"; }, 6000); }, function (data) { $("input[name=captcha]").next(".input-group-btn").find("img").trigger("click"); }); }, changepwd: function () { //本地验证未通过时提示 $("#changepwd-form").data("validator-options", validatoroptions); //为表单绑定事件 Form.api.bindevent($("#changepwd-form"), function (data, ret) { setTimeout(function () { location.href = ret.url ? ret.url : "/"; }, 1000); }); }, profile: function () { // 给上传按钮添加上传成功事件 $("#faupload-avatar").data("upload-success", function (data) { var url = Fast.api.cdnurl(data.url); $(".profile-user-img").prop("src", url); Toastr.success('Uploaded successful'); }); Form.api.bindevent($("#profile-form")); $(document).on("click", ".btn-change", function () { var that = this; var id = $(this).data("type") + "tpl"; var content = Template(id, {}); Layer.open({ type: 1, title: "修改", area: ["400px", "250px"], content: content, success: function (layero) { var form = $("form", layero); Form.api.bindevent(form, function (data) { location.reload(); Layer.closeAll(); }); } }); }); }, attachment: function () { require(['table'], function (Table) { // 初始化表格参数配置 Table.api.init({ extend: { index_url: 'user/attachment', } }); var urlArr = []; var multiple = Fast.api.query('multiple'); multiple = multiple == 'true' ? true : false; var table = $("#table"); table.on('check.bs.table uncheck.bs.table check-all.bs.table uncheck-all.bs.table', function (e, row) { if (e.type == 'check' || e.type == 'uncheck') { row = [row]; } else { urlArr = []; } $.each(row, function (i, j) { if (e.type.indexOf("uncheck") > -1) { var index = urlArr.indexOf(j.url); if (index > -1) { urlArr.splice(index, 1); } } else { urlArr.indexOf(j.url) == -1 && urlArr.push(j.url); } }); }); // 初始化表格 table.bootstrapTable({ url: $.fn.bootstrapTable.defaults.extend.index_url, sortName: 'id', showToggle: false, showExport: false, fixedColumns: true, fixedRightNumber: 1, columns: [ [ {field: 'state', checkbox: multiple, visible: multiple, operate: false}, {field: 'id', title: __('Id'), operate: false}, { field: 'url', title: __('Preview'), formatter: function (value, row, index) { var html = ''; if (row.mimetype.indexOf("image") > -1) { html = ''; } else { html = ''; } return '
' + html + '
'; } }, { field: 'filename', title: __('Filename'), formatter: function (value, row, index) { return '
' + Table.api.formatter.search.call(this, value, row, index) + '
'; }, operate: 'like' }, {field: 'imagewidth', title: __('Imagewidth'), operate: false}, {field: 'imageheight', title: __('Imageheight'), operate: false}, {field: 'mimetype', title: __('Mimetype'), formatter: Table.api.formatter.search}, { field: 'createtime', title: __('Createtime'), width: 120, formatter: Table.api.formatter.datetime, datetimeFormat: 'YYYY-MM-DD', operate: 'RANGE', addclass: 'datetimerange', sortable: true }, { field: 'operate', title: __('Operate'), width: 85, events: { 'click .btn-chooseone': function (e, value, row, index) { Fast.api.close({url: row.url, multiple: multiple}); }, }, formatter: function () { return ' ' + __('Choose') + ''; } } ] ] }); // 选中多个 $(document).on("click", ".btn-choose-multi", function () { Fast.api.close({url: urlArr.join(","), multiple: multiple}); }); // 为表格绑定事件 Table.api.bindevent(table); require(['upload'], function (Upload) { Upload.api.upload($("#toolbar .faupload"), function () { $(".btn-refresh").trigger("click"); }); }); }); }, inbox: function () { $(document).ready(function () { $(document).on('click', '#read-button', function () { let email_id = $(this).attr('data-id'); $.ajax({ url: '/api/user/read_email', // 后台处理数据请求的接口地址 type: 'POST', dataType: 'json', data: { email_id: email_id, }, success: function(res) { if (res.code === 1) { layer.msg(res.msg, { icon: 1, time: 2000, }, function () { location.reload(); }); } }, error: function(xhr, status, error) { console.error(error); } }); }); }); }, unread: function () { $(document).ready(function () { $(document).on('click', '#read-button', function () { let email_id = $(this).attr('data-id'); $.ajax({ url: '/api/user/read_email', // 后台处理数据请求的接口地址 type: 'POST', dataType: 'json', data: { email_id: email_id, }, success: function(res) { if (res.code === 1) { layer.msg(res.msg, { icon: 1, time: 2000, }, function () { location.reload(); }); } }, error: function(xhr, status, error) { console.error(error); } }); }); }); }, submit_manuscript: function () { // 初始化分页参数 var currentPage = 1; var pageSize = 10; var index = 0; var is_next = false; var button_next = false; var manuscript_id = $("#c-manuscript_id").val(); var custom_mousemove_x = 490; var custom_mousemove_y = 350; $(document).ready(function () { // 下一步按钮 $('.next-button').on('click', function () { // 陈述内容可点击下一步按钮 if ($('.statement-content').css('display') == 'block') { is_next = true; } // 推荐内容可点击下一步按钮 if ($('.recommended-content').css('display') == 'block') { is_next = true; } // 判断当前页面的必填项是否都填写 if (index == 0) { $("#c-manuscript-zip").trigger("validate"); let manuscript_zip = $("#c-manuscript-zip").isValid(); if(!manuscript_zip) { return true; } } // 手稿信息 if (index == 1) { $("#c-image").trigger("validate"); $('#c-journal').trigger("validate"); $('#c-article-type').trigger("validate"); $('#c-title').trigger("validate"); $('#c-abstract').trigger("validate"); $("#c-keywords").trigger("validate"); $("#c-number_page").trigger("validate"); let image = $("#c-image").isValid(); let journal = $('#c-journal').isValid(); let article_type = $('#c-article-type').isValid(); let title = $('#c-title').isValid(); let abstract = $("#c-abstract").isValid(); let keywords = $('#c-keywords').isValid(); let number_page = $('#c-number_page').isValid(); if (!image) { return true; } if (!journal) { return true; } if (!article_type) { return true; } if (!title) { return true; } if (!abstract) { return true; } if (!keywords) { return true; } if (!number_page) { return true; } is_next = true; } // 作者信息 if (index == 2) {; for (let i = 0; i < $('.add-author-item').length; i++) { $("[name='row[author]["+ i +"][email]']").trigger("validate"); $("[name='row[author]["+ i +"][first_name]']").trigger("validate"); $("[name='row[author]["+ i +"][author_affiliation]']").trigger("validate"); $("[name='row[author]["+ i +"][author_country]']").trigger("validate"); let email = $("[name='row[author]["+ i +"][email]']").isValid(); let first_name = $("[name='row[author]["+ i +"][first_name]']").isValid(); let author_affiliation = $("[name='row[author]["+ i +"][author_affiliation]']").isValid(); let author_country = $("[name='row[author]["+ i +"][author_country]']").isValid(); if (!email) { return true; } if (!first_name) { return true; } if (!author_affiliation) { return true; } if (!author_country) { return true; } } is_next = true; } if (is_next || index == 0) { index++; $("ul.nav-justified li").removeClass("active"); $("ul.nav-justified .nav-item .nav-content .nav-li-desc").removeClass("finish"); $("ul.nav-justified li:eq(" + index + ")").addClass("active"); $("ul.nav-justified .nav-item:eq(" + index + ") .nav-content .nav-li-desc").addClass('finish'); if (index == 5) { button_next = true; // 如果是最后一页操作时显示提交按钮,隐藏下一步按钮 $('.next-button').css('display', 'none'); $('.submit-button').css('display', 'block'); $(".manuscript-content").show(); $(".journal-content").show(); $(".add-author-content").show(); $('.recommended-button').hide(); // 最后一步设置鼠标移动时div的x与y轴的减少距离 custom_mousemove_x = 500; custom_mousemove_y = 2000; } else if (index == 4) { $('.recommended-button').show(); $(".form-item").hide(); $(".form-item:eq(" + index + ")").show(); } else if (index == 2) { $(".author-button").show(); $(".form-item").hide(); $(".form-item:eq(" + index + ")").show(); $(".recommended-button").hide(); } else { $('.recommended-button').hide(); $(".author-item").hide(); $('.author-button').hide(); $(".form-item").hide(); $(".form-item:eq(" + index + ")").show(); } is_next = false; } }); // 隐藏所有表单内容 $(".form-item").hide(); // 显示第一个表单内容 $(".form-item:first").show(); // 点击步骤条切换表单 $("ul.nav-justified .nav-item").click(function () { if (manuscript_id) { let li_index = $(this).index(); $("ul.nav-justified li").removeClass("active"); $("ul.nav-justified .nav-item .nav-content .nav-li-desc").removeClass("finish"); $("ul.nav-justified li:eq(" + li_index + ")").addClass("active"); $("ul.nav-justified .nav-item:eq(" + li_index + ") .nav-content .nav-li-desc").addClass('finish'); index = li_index; if (li_index == 5) { $('.next-button').css('display', 'none'); $('.submit-button').css('display', 'block'); $(".manuscript-content").show(); $(".journal-content").show(); $(".add-author-content").show(); $('.recommended-button').hide(); // 最后一步设置鼠标移动时div的x与y轴的减少距离 custom_mousemove_x = 500; custom_mousemove_y = 2000; } else if (li_index == 4) { $('.recommended-button').show(); $(".form-item").hide(); $(".form-item:eq(" + li_index + ")").show(); $(".author-button").hide(); } else if (li_index == 2) { $(".author-button").show(); $(".form-item").hide(); $(".form-item:eq(" + li_index + ")").show(); $('.recommended-button').hide(); } else { $('.recommended-button').hide(); $(".author-item").hide(); $('.author-button').hide(); $(".form-item").hide(); $(".form-item:eq(" + li_index + ")").show(); } if (li_index != 5) { $('.next-button').css('display', 'block'); $('.submit-button').css('display', 'none'); } } else { if (button_next) { index = 5; } if ($(this).index() <= index) { let li_index = $(this).index(); $("ul.nav-justified li").removeClass("active"); $("ul.nav-justified .nav-item .nav-content .nav-li-desc").removeClass("finish"); $("ul.nav-justified li:eq(" + li_index + ")").addClass("active"); $("ul.nav-justified .nav-item:eq(" + li_index + ") .nav-content .nav-li-desc").addClass('finish'); index = li_index; if (li_index == 5) { $('.next-button').css('display', 'none'); $('.submit-button').css('display', 'block'); $(".manuscript-content").show(); $(".journal-content").show(); $(".add-author-content").show(); $('.recommended-button').hide(); // 最后一步设置鼠标移动时div的x与y轴的减少距离 custom_mousemove_x = 500; custom_mousemove_y = 2000; } else if (li_index == 4) { $('.recommended-button').show(); $(".form-item").hide(); $(".form-item:eq(" + li_index + ")").show(); $(".author-button").hide(); } else if (li_index == 2) { $(".author-button").show(); $(".form-item").hide(); $(".form-item:eq(" + li_index + ")").show(); $('.recommended-button').hide(); } else { $('.recommended-button').hide(); $(".author-item").hide(); $('.author-button').hide(); $(".form-item").hide(); $(".form-item:eq(" + li_index + ")").show(); } if (li_index != 5) { $('.next-button').css('display', 'block'); $('.submit-button').css('display', 'none'); } } } }); // 删除对应作者信息 $(document).on('click', '.author-delete-button', function () { let author_content_length = $('.add-author-content').children('.add-author-item').length; if (author_content_length > 1) { $(this).parent().parent().remove(); // 删除后更新 input 的 name 值 updateInputNames(); } }); // 审稿人列表按钮 $(document).on('click', '.reviewer-list-button', function () { let selected_id = []; $('.recommended-del').each(function () { let id = $(this).data('id'); selected_id.push(id); }) // 清空表格内容和分页区域 $('#modal-table tbody').html(''); $('#modal-pagination').html(''); // 发送 Ajax 请求获取数据并填充表格和分页 $.ajax({ url: 'user/getReviewerList', // 后台处理数据请求的接口地址 type: 'GET', dataType: 'json', data: { page: currentPage, limit: pageSize }, success: function(data) { if (data.code === 1) { var tableData = data.data.data; for (var i = 0; i < tableData.length; i++) { var rowData = tableData[i]; let is_disabled = ''; if (selected_id.includes(rowData.id)) { is_disabled = 'disabled'; } var rowHtml = '' + '' + '' + rowData.user.nickname + '' + '' + rowData.user.email + '' + '' + rowData.user.first_name + '' + '' + rowData.user.last_name + '' + '' + rowData.affiliation + '' + '' + rowData.field + '' + ''; $('#modal-table tbody').append(rowHtml); } // 计算总页数 var totalPage = Math.ceil(data.data.total / pageSize); // 动态生成分页按钮,使用省略号表示更多页码 var pageHtml = ''; if (totalPage <= 7) { // 当总页数小于等于7时,显示所有页码按钮 for (var i = 1; i <= totalPage; i++) { if (i === currentPage) { pageHtml += '' + i + ''; } else { pageHtml += '' + i + ''; } } } else { // 当总页数大于7时,进行分段显示 if (currentPage <= 4) { pageHtml += generatePagination(1, 5); pageHtml += '...'; pageHtml += '' + totalPage + ''; } else if (currentPage >= totalPage - 3) { pageHtml += '1'; pageHtml += '...'; pageHtml += generatePagination(totalPage - 4, totalPage); } else { pageHtml += '1'; pageHtml += '...'; //只需要更改这一行的逻辑即可 var startPage = currentPage - 2; var endPage = currentPage + 2; pageHtml += generatePagination(startPage, endPage); //只需要更改这一行的逻辑即可 } } $('#modal-pagination').html(pageHtml); // 绑定分页按钮点击事件 $('.pagination-link').click(function(e) { $('.pagination-link').removeClass('active'); $(this).addClass('active'); e.preventDefault(); var page = parseInt($(this).text()); currentPage = page; // 发送 Ajax 请求获取对应页的数据并填充表格 $.ajax({ url: 'user/getReviewerList', type: 'GET', dataType: 'json', data: { page: currentPage, limit: pageSize }, success: function(data) { if (data.code === 1) { var tableData = data.data.data; $('#modal-table tbody').html(''); for (var i = 0; i < tableData.length; i++) { var rowData = tableData[i]; let is_disabled = ''; if (selected_id.includes(rowData.id)) { is_disabled = 'disabled'; } var rowHtml = '' + '' + '' + rowData.user.nickname + '' + '' + rowData.user.email + '' + '' + rowData.user.first_name + '' + '' + rowData.user.last_name + '' + '' + rowData.affiliation + '' + '' + rowData.field + '' + ''; $('#modal-table tbody').append(rowHtml); } } }, error: function(xhr, status, error) { console.error(error); } }); }); } }, error: function(xhr, status, error) { console.error(error); } }); }); // 选择审稿人后确定选择 $(document).on('click', '.add-review-button', function () { let tr_length = $('#recommended-table tbody tr').length; var selectedValues = []; // 使用 jQuery 的 each 函数遍历所有 name 为 option 的复选框 $('input[type=checkbox]:checked').each(function() { let obj = {}; obj['id'] = $(this).data('id'); obj['name'] = $(this).data('name'); obj['email'] = $(this).data('email'); obj['first_name'] = $(this).data('first'); obj['last_name'] = $(this).data('last'); obj['affiliation'] = $(this).data('affiliation'); obj['field'] = $(this).data('field'); selectedValues.push(obj); // 将选中的值添加到数组中 }); for (var i = 0; i < selectedValues.length; i++) { var rowData = selectedValues[i]; if (selectedValues.length > 1) { if (i > 0) { tr_length++; } } let html = '\n' + ' \n' + ' \n' + ' \n' + ' \n' + ' '; var rowHtml = '' + '' + rowData.name + '' + '' + rowData.email + '' + '' + rowData.first_name + '' + '' + rowData.last_name + '' + '' + rowData.affiliation + '' + '' + rowData.field + '' + '删除' + ''; $('#recommended-table tbody').append(rowHtml); $('.reviewer-hidden-content').append(html); } $('#myModal').modal('hide'); }); // 自定义添加审稿人按钮 $(document).on('click', '.add-reviewer-button', function () { let input_index = $('.custom-reviewer-content').children('.custom-reviewer-item').length; let str = '
\n' + '
\n' + ' \n' + '
\n' + ' Delete\n' + '
\n' + '
\n' + '
\n' + ' \n' + '
\n' + ' \n' + '
\n' + ' \n' + '
\n' + '
\n' + '
\n' + '
\n' + ' \n' + '
\n' + ' \n' + '
\n' + ' \n' + '
\n' + '
\n' + '
\n' + '\n' + '
\n' + ' \n' + '
\n' + ' \n' + '
\n' + ' \n' + '
\n' + '
\n' + '
\n' + '\n' + '
\n' + ' \n' + '
\n' + ' \n' + '
\n' + ' \n' + '
\n' + '
\n' + '
\n' + '\n' + '
\n' + ' \n' + '
\n' + ' \n' + '
\n' + ' \n' + '
\n' + '
\n' + '
\n' + '\n' + '
\n' + ' \n' + '
\n' + ' \n' + '
\n' + ' \n' + '
\n' + '
\n' + '
\n' + '
'; $('.custom-reviewer-content').append(str); updateReviewerInputNames(); }); // 排序input 的 name 值 var updateReviewerInputNames = function () { // 遍历所有的div元素 $(".custom-reviewer-item").each(function (index) { var name_input = $(this).find('input[id="c-add-review-name"]'); var email_input = $(this).find('input[id="c-add-review-email"]'); var first_name_input = $(this).find('input[id="c-add-review-first-name"]'); var last_name_input = $(this).find('input[id="c-add-review-last-name"]'); var affiliation_input = $(this).find('input[id="c-add-review-affiliation"]'); var field_input = $(this).find('input[id="c-add-review-field"]'); name_input.attr('name', "row[reviewer]["+ index +"][reviewer-name]"); email_input.attr('name', "row[reviewer]["+ index +"][reviewer-email]"); first_name_input.attr('name', "row[reviewer]["+ index +"][reviewer-first-name]"); last_name_input.attr('name', "row[reviewer]["+ index +"][reviewer-last-name]"); affiliation_input.attr('name', "row[reviewer]["+ index +"][reviewer-affiliation]"); field_input.attr('name', "row[reviewer]["+ index +"][reviewer-field]"); }); }; // 删除对应的审稿人信息 $(document).on('click', '.reviewer-delete-button', function () { let reviewer_content_length = $('.custom-reviewer-content').children('.custom-reviewer-item').length; if (reviewer_content_length > 1) { $(this).parent().parent().remove(); // 删除后更新 input 的 name 值 updateReviewerInputNames(); } }); // 自定义审稿人信息提交按钮操作 $(document).on('click', '.add-reviewer-submit', function () { let tr_length = $('#recommended-table tbody tr').length; let key = $(".custom-reviewer-item").length; let addReviewerInputValue = []; for (let i = 0; i < key; i++) { let obj = {}; obj['name'] = $(this).parent().parent().find("input[name='row[reviewer]["+ i +"][reviewer-name]']").val(); obj['email'] = $(this).parent().parent().find("input[name='row[reviewer]["+ i +"][reviewer-email]']").val(); obj['first_name'] = $(this).parent().parent().find("input[name='row[reviewer]["+ i +"][reviewer-first-name]']").val(); obj['last_name'] = $(this).parent().parent().find("input[name='row[reviewer]["+ i +"][reviewer-last-name]']").val(); obj['affiliation'] = $(this).parent().parent().find("input[name='row[reviewer]["+ i +"][reviewer-affiliation]']").val(); obj['field'] = $(this).parent().parent().find("input[name='row[reviewer]["+ i +"][reviewer-field]']").val(); addReviewerInputValue.push(obj); } for (var i = 0; i < addReviewerInputValue.length; i++) { var rowData = addReviewerInputValue[i]; if (addReviewerInputValue.length > 1) { if (i > 0) { tr_length++; } } let html = '\n' + ' \n' + ' \n' + ' \n' + ' \n' + ' '; var rowHtml = '' + '' + rowData.name + '' + '' + rowData.email + '' + '' + rowData.first_name + '' + '' + rowData.last_name + '' + '' + rowData.affiliation + '' + '' + rowData.field + '' + '删除' + ''; $('#recommended-table tbody').append(rowHtml); $('.reviewer-hidden-content').append(html); } // 清空已填内容 $('.custom-reviewer-content').html(''); $('.custom-reviewer-content').append('
\n' + '
\n' + ' \n' + '
\n' + ' Delete\n' + '
\n' + '
\n' + '
\n' + ' \n' + '
\n' + ' \n' + '
\n' + ' \n' + '
\n' + '
\n' + '
\n' + '
\n' + ' \n' + '
\n' + ' \n' + '
\n' + ' \n' + '
\n' + '
\n' + '
\n' + '\n' + '
\n' + ' \n' + '
\n' + ' \n' + '
\n' + ' \n' + '
\n' + '
\n' + '
\n' + '\n' + '
\n' + ' \n' + '
\n' + ' \n' + '
\n' + ' \n' + '
\n' + '
\n' + '
\n' + '\n' + '
\n' + ' \n' + '
\n' + ' \n' + '
\n' + ' \n' + '
\n' + '
\n' + '
\n' + '\n' + '
\n' + ' \n' + '
\n' + ' \n' + '
\n' + ' \n' + '
\n' + '
\n' + '
\n' + '
'); $('#addReviewModal').modal('hide'); }); // 删除已选中的审稿人 $(document).on('click', '.recommended-del', function () { let index = $(this).data('index'); $('.reviewer-hidden-content').find('input[name="row[reviewer]\\['+ index +'\\]\\[reviewer-name\\]"]').remove(); $('.reviewer-hidden-content').find('input[name="row[reviewer]\\['+ index +'\\]\\[reviewer-email\\]"]').remove(); $('.reviewer-hidden-content').find('input[name="row[reviewer]\\['+ index +'\\]\\[reviewer-first-name\\]"]').remove(); $('.reviewer-hidden-content').find('input[name="row[reviewer]\\['+ index +'\\]\\[reviewer-last-name\\]"]').remove(); $('.reviewer-hidden-content').find('input[name="row[reviewer]\\['+ index +'\\]\\[reviewer-affiliation\\]"]').remove(); $('.reviewer-hidden-content').find('input[name="row[reviewer]\\['+ index +'\\]\\[reviewer-field\\]"]').remove(); $(this).parent().remove(); // 重新排列键值 }); // 辅助函数:生成指定起始页码和结束页码的分页按钮HTML代码 function generatePagination(startPage, endPage) { var pageHtml = ''; for (var i = startPage; i <= endPage; i++) { if (i === currentPage) { pageHtml += '' + i + ''; } else { pageHtml += '' + i + ''; } } return pageHtml; } }); // 添加作者 $('.author-button').click(function () { let input_index = $('.add-author-content').children('.add-author-item').length; // let input_index = author_content_length - 1; // 克隆作者信息 let str = `

Delete
`; $('.add-author-content').append(str); // 更新 name 值为按顺序增加的索引值 updateInputNames(); }); // 排序input 的 name 值 function updateInputNames () { drags('add-author-item', 'div-dash', 'dash'); // 遍历所有的div元素 $(".add-author-item").each(function (index) { var email_input = $(this).find('input[id="c-email"]'); var first_name_input = $(this).find('input[id="c-first-name"]'); var middle_name_input = $(this).find('input[id="c-middle-name"]'); var last_name_input = $(this).find('input[id="c-last-name"]'); var author_affiliation_input = $(this).find('input[id="c-author-affiliation"]'); var display_email_yes_radio = $(this).find("input[type=radio][id=c-display-e-mail-yes]"); var display_email_no_radio = $(this).find("input[type=radio][id=c-display-e-mail-no]"); var correspondsing_author_yes_radio = $(this).find("input[type=radio][id=c-correspondsing-author-yes]"); var correspondsing_author_no_radio = $(this).find("input[type=radio][id=c-correspondsing-author-no]"); var select = $(this).find("select"); email_input.attr('name', "row[author]["+ index +"][email]"); first_name_input.attr('name', "row[author]["+ index +"][first_name]"); middle_name_input.attr('name', "row[author]["+ index +"][middle_name]"); last_name_input.attr('name', "row[author]["+ index +"][last_name]"); author_affiliation_input.attr('name', "row[author]["+ index +"][author_affiliation]"); display_email_yes_radio.attr('name', "row[author]["+ index +"][display_email]"); display_email_no_radio.attr('name', "row[author]["+ index +"][display_email]"); correspondsing_author_yes_radio.attr('name', "row[author]["+ index +"][correspondsing_author]"); correspondsing_author_no_radio.attr('name', "row[author]["+ index +"][correspondsing_author]"); select.attr('name', "row[author]["+ index +"][author_country]"); }); }; // 拖拽初始化 drags('add-author-item', 'div-dash', 'dash'); // 拖拽方法 function drags(name, name2, name3) { var range = {x: 0, y: 0}; // 鼠标元素偏移量 var lastPos = {x: 0, y: 0, x1: 0, y1: 0}; // 拖拽对象的四个坐标 var tarPos = {x: 0, y: 0, x1: 0, y1: 0}; // 目标元素对象的坐标初始化 var thidDiv = null, move = false, choose = false; // 拖拽对象 拖拽状态 选中状态 //拖拽对象的索引、高度、的初始化。 var thidDivWidth = 0, thidDivHeight = 0, thidDivHalfW = 0, thidDivHalfH = 0, tarFirstX = 0, tarFirstY = 0; var tarDiv = null, tarFirst, tempDiv; // 要插入的目标元素的对象, 临时的虚线对象 var initPos = {x: 0, y: 0}; // 记录拖拽元素初始鼠标元素偏移量 // 当鼠标按下时 $('.' + name).on('mousedown', function (event) { console.log(event.target.tagName); // 判断是否点击了 input 元素 if (event.target.tagName === 'INPUT') { return; } if (event.target.tagName === 'SELECT') { return; } if (event.target.tagName === 'LABEL') { return; } // 判断如果鼠标是删除按钮则终止拖拽 let class_name = event.target.className.split(" "); if (class_name[0] == 'author-delete-button') { return; } choose = true; // 拖拽对象 thidDiv = $(this); // 记录拖拽元素初始位置 initPos.x = thidDiv.offset().left; initPos.y = thidDiv.offset().top; // 鼠标元素相对偏移量 range.x = event.pageX - thidDiv.offset().left; range.y = event.pageY - thidDiv.offset().top; thidDivWidth = thidDiv.width(); thidDivHeight = thidDiv.height(); thidDivHalfW = thidDivWidth / 2; thidDivHalfH = thidDivHeight / 2; thidDiv.attr("class", name2); thidDiv.css({ left: (event.pageX + range.x) + 'px', top: (event.pageY + range.y) + 'px', }); // 创建新元素 插入拖拽元素之前的位置(虚线框) $("
").insertBefore(thidDiv); tempDiv = $("." + name3); }); // 当鼠标抬起时 $(document).on('mouseup', function (event) { if (!choose) { return false; } if (!move) { thidDiv.attr("class", name); tempDiv.remove(); // 删除新建的虚线div choose = false; return false; } thidDiv.insertBefore(tempDiv); // 拖拽元素插入到 虚线div的位置上 thidDiv.attr("class", name); //恢复对象的初始样式 tempDiv.remove(); // 删除新建的虚线div move = false; choose = false; // 当鼠标移动时 }).on('mousemove', function (event) { if (!choose) return false; move = true; lastPos.x = event.pageX - range.x; lastPos.y = event.pageY - range.y; lastPos.x1 = lastPos.x + thidDivWidth; lastPos.y1 = lastPos.y + thidDivHeight; // 拖拽元素随鼠标移动 thidDiv.css({ left: lastPos.x - custom_mousemove_x + 'px', top: lastPos.y - custom_mousemove_y + 'px' }); // 拖拽元素随鼠标移动 查找插入目标元素 var $main = $('.' + name); // 局部变量:按照重新排列过的顺序 再次获取 各个元素的坐标, $main.each(function () { tarDiv = $(this); tarPos.x = tarDiv.offset().left; tarPos.y = tarDiv.offset().top; tarPos.x1 = tarPos.x + tarDiv.width() / 2; tarPos.y1 = tarPos.y + tarDiv.height() / 2; tarFirst = $main.eq(0); // 获得第一个元素 tarFirstX = tarFirst.offset().left + thidDivHalfW; // 第一个元素对象的中心纵坐标 tarFirstY = tarFirst.offset().top + thidDivHalfH; // 第一个元素对象的中心横坐标 // 根据 拖拽对象x坐标 与 目标元素对象x坐标 对比,来显示 虚线div 在节点前、后出现的位置 if (lastPos.x > tarPos.x) { // 判断要插入目标元素的 坐标后, 直接插入 if (lastPos.x >= tarPos.x - thidDivHalfW && lastPos.x1 >= tarPos.x1 && lastPos.y >= tarPos.y - thidDivHalfH && lastPos.y1 >= tarPos.y1) { tempDiv.insertAfter(tarDiv); } //拖拽对象 移动到第一个位置 if (lastPos.x <= tarFirstX && lastPos.y <= tarFirstY) { tempDiv.insertBefore(tarFirst); } } else { //拖拽对象 移动到第一个位置 if (lastPos.x <= tarFirstX && lastPos.y <= tarFirstY) { tempDiv.insertBefore(tarFirst); } // 判断要插入目标元素的 坐标后, 直接插入 if (lastPos.x >= tarPos.x - thidDivHalfW && lastPos.x1 >= tarPos.x1 && lastPos.y >= tarPos.y - thidDivHalfH && lastPos.y1 >= tarPos.y1) { tempDiv.insertAfter(tarDiv); } } }); }); } $.fn.serializeObject = function() { var obj = {}; var arrayTmp = this.serializeArray(); $.each(arrayTmp, function() { if (obj[this.name]) { if (!obj[this.name].push) { obj[this.name] = [ obj[this.name] ]; } obj[this.name].push(this.value || ''); } else { obj[this.name] = this.value || ''; } }); return obj; }; $(document).on('mouseup', function () { let values = $('#submit-manuscript-form').serializeObject(); $.ajax({ url: '/api/user/incomplete_submit', type: 'POST', dataType: 'json', data: values, success: function(res) { // 如果保存了就代表接下来都是修改,所以记录返回的id if (res.code == 1) { $('#c-manuscript_id').val(res.data); } }, error: function(xhr, status, error) { top.window.Toastr.error('Save failed'); } }); }) Form.api.bindevent($("#submit-manuscript-form"), function () { setTimeout(function () { location.href = "/index/user/display_submitted"; }, 2000); }); }, invite_reviewers: function () { updateHidden(); // 全选 $('#reviewer-table').on('click', '.chk', function () { var checkedStatus = this.checked; $('#reviewer-table .son-chk').prop('checked', checkedStatus); updateHidden() }); $('#reviewer-table').on('click', '.son-chk', function () { updateHidden(); }) function updateHidden(){ var checkedVals = []; $('.son-chk:checked').each(function(){ let obj = {}; obj['id'] = $(this).data('id'); obj['user_id'] = $(this).data('user-id'); obj['name'] = $(this).data('name'); obj['education'] = $(this).data('education'); obj['affiliation'] = $(this).data('affiliation'); obj['field'] = $(this).data('field'); checkedVals.push(obj); }); $('#submit-invite-reviewers-form .reviewer-content').empty(); console.log(checkedVals); $.each(checkedVals, function(i, val){ var str = '\n' + '\n' + ' \n' + ' \n' + ' \n' + ' '; ' '; $('#submit-invite-reviewers-form .reviewer-content').append(str); }); } // 点击按钮后获取选择 Form.api.bindevent($("#submit-invite-reviewers-form"), function () { // 清理缓存 localStorage.removeItem('selectedTableVals'); // setTimeout(function () { // location.href = "index/user/reviewer_information"; // }, 2000); }); }, handing_suggestions: function () { Form.api.bindevent($("#submit-comments-form"), function () { setTimeout(function () { location.href = "index/user/reviewer_information"; }, 2000); }); }, display_submitted: function () { // 初始化分页参数 var currentPage = 1; var pageSize = 10; $('#c-search').on("keyup", function (e) { if (e.keyCode === 13) { let keyword = $(this).val(); // 点击回车后进行搜索 $.ajax({ url: 'user/display_submitted', type: 'GET', dataType: 'json', data: { page: currentPage, limit: pageSize, keyword: keyword, }, success: function(res) { if (res.code === 1) { if (res.data.total > 0) { $('.article-list').html(''); var tableData = res.data.data; for (var i = 0; i < tableData.length; i++) { let rowData = tableData[i]; let html = '
\n' + '
\n' + ' \n' + '
\n' + '

\n' + ' '+ rowData.title +'\n' + '
\n' + ' ID:'+ rowData.id +'\n' + '
\n' + '

\n' + '
\n' + ' Open Access\n' + ' Feature Paper\n' + ' Review\n' + '
\n' + ' \n' + '
\n' + '
\n' + '
'; $('.article-list').append(html); } } } }, error: function(xhr, status, error) { console.error(error); } }); } }); }, editing_manuscripts: function () { // 初始化分页参数 var currentPage = 1; var pageSize = 10; var status = $('#editor_manuscripts_status').val(); $('#c-search').on("keyup", function (e) { if (e.keyCode === 13) { let keyword = $(this).val(); // 点击回车后进行搜索 $.ajax({ url: 'user/editing_manuscripts', type: 'GET', dataType: 'json', data: { page: currentPage, limit: pageSize, keyword: keyword, status: status, }, success: function(res) { if (res.code === 1) { if (res.data.total > 0) { $('.article-list').html(''); var tableData = res.data.data; for (var i = 0; i < tableData.length; i++) { let rowData = tableData[i]; let html = `

${rowData.title}

Open Access Feature Paper Review
`; $('.article-list').append(html); } } } }, error: function(xhr, status, error) { console.error(error); } }); } }); }, show_reviewed_manuscripts: function () { // 初始化分页参数 var currentPage = 1; var pageSize = 10; var status = $('#reviewed_manuscripts_status').val(); $('#c-search').on("keyup", function (e) { if (e.keyCode === 13) { let keyword = $(this).val(); // 点击回车后进行搜索 $.ajax({ url: 'user/show_reviewed_manuscripts', type: 'GET', dataType: 'json', data: { status: status, page: currentPage, limit: pageSize, keyword: keyword, }, success: function(res) { console.log(res); if (res.code === 1) { // if (res.data.total > 0) { $('.article-list').html(''); var tableData = res.data.data; for (var i = 0; i < tableData.length; i++) { let rowData = tableData[i]; let html = '
\n' + '
\n' + ' \n' + '
\n' + '

\n' + ' '+ rowData.title +'\n' + '
\n' + ' ID:'+ rowData.id +'\n' + '
\n' + '

\n' + '
\n' + ' Open Access\n' + ' Feature Paper\n' + ' Review\n' + '
\n' + ' \n' + '
\n' + '
\n' + '
'; $('.article-list').append(html); } // } } }, error: function(xhr, status, error) { console.error(error); } }); } }); }, special_issue: function () { // 自定义添加作者按钮 $(document).on('click', '.add-editor-button', function () { let input_index = $('.custom-editor-content').children('.custom-editor-item').length; let str = '
\n' + '
\n' + ' \n' + '
\n' + ' Delete\n' + '
\n' + '
\n' + '
\n' + ' \n' + '
\n' + ' \n' + '
\n' + ' \n' + '
\n' + '
\n' + '
\n' + '\n' + '
\n' + ' \n' + '
\n' + ' \n' + '
\n' + ' \n' + '
\n' + '
\n' + '
\n' + '\n' + '
\n' + ' \n' + '
\n' + ' \n' + '
\n' + ' \n' + '
\n' + '
\n' + '
\n' + '\n' + '
\n' + ' \n' + '
\n' + ' \n' + '
\n' + ' \n' + '
\n' + '
\n' + '
\n' + '\n' + '
\n' + ' \n' + '
\n' + ' \n' + '
\n' + ' \n' + '
\n' + '
\n' + '
\n' + '
'; $('.custom-editor-content').append(str); updateEditorInputNames(); }); // 排序input 的 name 值 var updateEditorInputNames = function () { // 遍历所有的div元素 $(".custom-editor-item").each(function (index) { var email_input = $(this).find('input[id="c-add-editor-email"]'); var first_name_input = $(this).find('input[id="c-add-editor-first-name"]'); var last_name_input = $(this).find('input[id="c-add-editor-last-name"]'); var affiliation_input = $(this).find('input[id="c-add-editor-affiliation"]'); var record_link_input = $(this).find('input[id="c-add-editor-record_link"]'); email_input.attr('name', "row[editor]["+ index +"][email]"); first_name_input.attr('name', "row[editor]["+ index +"][first_name]"); last_name_input.attr('name', "row[editor]["+ index +"][last_name]"); affiliation_input.attr('name', "row[editor]["+ index +"][affiliation]"); record_link_input.attr('name', "row[editor]["+ index +"][record_link]"); }); }; // 删除对应的作者信息 $(document).on('click', '.editor-delete-button', function () { let editor_content_length = $('.custom-editor-content').children('.custom-editor-item').length; if (editor_content_length > 1) { $(this).parent().parent().remove(); // 删除后更新 input 的 name 值 updateEditorInputNames(); } }); // 自定义作者信息提交按钮操作 $(document).on('click', '.add-editor-submit', function () { let tr_length = $('#recommended-table tbody tr').length; let key = $(".custom-editor-item").length; let addEditorInputValue = []; for (let i = 0; i < key; i++) { let obj = {}; obj['email'] = $(this).parent().parent().find("input[name='row[editor]["+ i +"][email]']").val(); obj['first_name'] = $(this).parent().parent().find("input[name='row[editor]["+ i +"][first_name]']").val(); obj['last_name'] = $(this).parent().parent().find("input[name='row[editor]["+ i +"][last_name]']").val(); obj['affiliation'] = $(this).parent().parent().find("input[name='row[editor]["+ i +"][affiliation]']").val(); obj['record_link'] = $(this).parent().parent().find("input[name='row[editor]["+ i +"][record_link]']").val(); addEditorInputValue.push(obj); } for (var i = 0; i < addEditorInputValue.length; i++) { var rowData = addEditorInputValue[i]; if (addEditorInputValue.length > 1) { if (i > 0) { tr_length++; } } let html = ' \n' + ' \n' + ' \n' + ' \n' + ' '; var rowHtml = '' + '' + rowData.email + '' + '' + rowData.first_name + '' + '' + rowData.last_name + '' + '' + rowData.affiliation + '' + '' + rowData.record_link + '' + '删除' + ''; $('#recommended-table tbody').append(rowHtml); $('.editor-hidden-content').append(html); } // 清空已填内容 $('.custom-editor-content').html(''); $('.custom-editor-content').append('
\n' + '
\n' + ' \n' + '
\n' + ' Delete\n' + '
\n' + '
\n' + '
\n' + ' \n' + '
\n' + ' \n' + '
\n' + ' \n' + '
\n' + '
\n' + '
\n' + '\n' + '
\n' + ' \n' + '
\n' + ' \n' + '
\n' + ' \n' + '
\n' + '
\n' + '
\n' + '\n' + '
\n' + ' \n' + '
\n' + ' \n' + '
\n' + ' \n' + '
\n' + '
\n' + '
\n' + '\n' + '
\n' + ' \n' + '
\n' + ' \n' + '
\n' + ' \n' + '
\n' + '
\n' + '
\n' + '\n' + '
\n' + ' \n' + '
\n' + ' \n' + '
\n' + ' \n' + '
\n' + '
\n' + '
\n' + '
'); $('#addEditorModal').modal('hide'); }); // 删除已选中的作者 $(document).on('click', '.recommended-del', function () { let index = $(this).data('index'); $('.editor-hidden-content').find('input[name="row[editor]\\['+ index +'\\]\\[email\\]"]').remove(); $('.editor-hidden-content').find('input[name="row[editor]\\['+ index +'\\]\\[first_name\\]"]').remove(); $('.editor-hidden-content').find('input[name="row[editor]\\['+ index +'\\]\\[last_name\\]"]').remove(); $('.editor-hidden-content').find('input[name="row[editor]\\['+ index +'\\]\\[affiliation\\]"]').remove(); $('.editor-hidden-content').find('input[name="row[editor]\\['+ index +'\\]\\[record_link\\]"]').remove(); $(this).parent().remove(); // 重新排列键值 }); // 辅助函数:生成指定起始页码和结束页码的分页按钮HTML代码 function generatePagination(startPage, endPage) { var pageHtml = ''; for (var i = startPage; i <= endPage; i++) { if (i === currentPage) { pageHtml += '' + i + ''; } else { pageHtml += '' + i + ''; } } return pageHtml; } Form.api.bindevent($("#submit-issue-form"), function () { setTimeout(function () { location.reload(); }, 2000); }); }, article_details: function () { setTimeout(function () { $('.btn-delete').remove(); $('.input-group-addon').remove(); }, 300); Form.api.bindevent($("#article-details-form"), function () { setTimeout(function () { location.href = "index/user/reviewer_information"; }, 2000); }); }, conduct_review: function () { Form.api.bindevent($("#submit-comments-form"), function () { setTimeout(function () { location.href = "index/user/reviewer_information"; }, 2000); }); }, submit_conference: function () { Form.api.bindevent($("#conference-form"), function () { setTimeout(function () { location.href = "/p/conference"; }, 2000); }, function (data) { $("input[name=captcha]").next(".input-group-addon").find("img").trigger("click"); }); }, conference_participate: function () { Form.api.bindevent($("#conference-participate-form"), function () { setTimeout(function () { location.href = "/p/conference"; }, 2000); }); }, reviewer_information: function () { //为表单绑定事件 Form.api.bindevent($("#reviewer-information-form"), function (data, ret) { // setTimeout(function () { // location.href = ret.url ? ret.url : "/"; // }, 6000); }, function (data) { // $("input[name=captcha]").next(".input-group-btn").find("img").trigger("click"); }); }, become_an_editor: function () { //为表单绑定事件 Form.api.bindevent($("#become-an-editor-form"), function (data, ret) { // setTimeout(function () { // location.href = ret.url ? ret.url : "/"; // }, 6000); }, function (data) { // $("input[name=captcha]").next(".input-group-btn").find("img").trigger("click"); }); }, special_issue_list: function () { // 初始化分页参数 var currentPage = 1; var pageSize = 10; $('#c-search').on("keyup", function (e) { if (e.keyCode === 13) { let keyword = $(this).val(); // 点击回车后进行搜索 $.ajax({ url: 'user/special_issue_list', type: 'GET', dataType: 'json', data: { page: currentPage, limit: pageSize, keyword: keyword, }, success: function(res) { if (res.code === 1) { $('.article-list').html(''); var tableData = res.data.data; for (var i = 0; i < tableData.length; i++) { let rowData = tableData[i]; let html = '
\n' + '
\n' + ' \n' + '
\n' + '

\n' + ' '+ rowData.issue_name +'\n' + '
\n' + ' ID:'+ rowData.id +'\n' + '
\n' + '

\n' + '
\n' + ' '+ rowData.journal +'\n' + '
\n' + ' \n' + ' \n' + '
\n' + '
\n' + '
'; $('.article-list').append(html); } } }, error: function(xhr, status, error) { console.error(error); } }); } }); }, }; return Controller; });