diff --git a/app/assets/javascripts/admins/competition_settings/index.js b/app/assets/javascripts/admins/competition_settings/index.js index 4804ae16e..03c940b88 100644 --- a/app/assets/javascripts/admins/competition_settings/index.js +++ b/app/assets/javascripts/admins/competition_settings/index.js @@ -9,7 +9,7 @@ $(document).on('turbolinks:load', function(){ }; var timeOptions = { - // autoclose: true, + autoclose: 1, language: 'zh-CN', format: 'yyyy-mm-dd hh:ii:ss', minuteStep: 30 @@ -23,18 +23,9 @@ $(document).on('turbolinks:load', function(){ $(element).find('.end-date').datepicker('setStartDate', e.date); }); }; + $(".competition-start-end-date .start-date").datetimepicker(timeOptions); - var defineTimeRangeSelect = function (element) { - // var options = $.extend({inputs: $(element).find('.start-date, .end-date')}, timeOptions); - $(".start-date").datetimepicker(timeOptions); - - $(element).find('.start-date').datetimepicker().on('changeDate', function (e) { - $(element).find('.end-date').datetimepicker('setStartDate', e.date); - }); - }; - $(".competition-start-end-date .start-date").datetimepicker(); - - $(".competition-start-end-date .end-date").datetimepicker(); + $(".competition-start-end-date .end-date").datetimepicker(timeOptions); defineDateRangeSelect('.teaching-mode-date'); // defineTimeRangeSelect('.competition-start-end-date'); @@ -62,13 +53,13 @@ $(document).on('turbolinks:load', function(){ if ($("input[name='mode']:checked").val() == 2) { var $courseId = $("input[name='course_id'"); - if ($courseId.val() === undefined || $course_id.val().length === 0) { + if ($courseId.val() === undefined || $courseId.val().length === 0) { $courseId.addClass('danger text-danger'); valid = false; } else { $courseId.removeClass('danger text-danger'); } - } else if ($("input[name='mode']:checked").val() == 4) { + } else if ($("input[name='mode']:checked").val() == 3) { var $techStartTime = $("input[name='teach_start_time'"); var $techEndTime = $("input[name='teach_end_time'"); if ($techStartTime.val() === undefined || $techStartTime.val().length === 0) { @@ -84,6 +75,10 @@ $(document).on('turbolinks:load', function(){ } else { $techEndTime.removeClass('danger text-danger'); } + } else { + $("input[name='course_id'").removeClass('danger text-danger'); + $("input[name='teach_start_time'").removeClass('danger text-danger'); + $("input[name='teach_end_time'").removeClass('danger text-danger'); } if (!valid) return; @@ -113,81 +108,80 @@ $(document).on('turbolinks:load', function(){ $(function () { //MD编辑 - $("#MD_typeFrom").on("click",".add_MD_type",function () { - - var length=$(".MD_type").find(".add_MD_type").length + 1; - var html='
\n' + - '
\n' + - ' \n' + - '
\n' + - '
\n' + - '
\n' + - ' \n' + - ' \n' + - '
'; - $("#MD_typeFrom").append(html); - }) - $("#MD_typeFrom").on("click",".del_MD_type",function () { - $(this).parents(".MD_type").remove(); - }) - + // $("#MD_typeFrom").on("click",".add_MD_type",function () { + // + // var length=$(".MD_type").find(".add_MD_type").length + 1; + // var html='
\n' + + // '
\n' + + // ' \n' + + // '
\n' + + // '
\n' + + // '
\n' + + // ' \n' + + // ' \n' + + // '
'; + // $("#MD_typeFrom").append(html); + // }) + // $("#MD_typeFrom").on("click",".del_MD_type",function () { + // $(this).parents(".MD_type").remove(); + // }) //链接 $(".nav-setting-form").on("click",".add_linkBtn",function () { var length=$(".nav-setting-form").find(".linkFormItem").length + 1; - var html='
\n' + + var html='
\n' + '
\n' + ' \n' + '
\n' + - '
\n' + - '
\n' + - '
\n' + - ' \n' + - ' \n' + + '
\n' + + '
\n' + + '
\n' + + '
\n' + + ' +\n' + + ' ×\n' + '
'; - $(this).parents(".lineFromItem").insertAfter(html); + $(this).parents(".linkFormItem").after(html); }); - $(".nav-setting-form").on("click",".del_linkBtn",function () { - $(this).parents(".lineFromItem").remove(); + $(".nav-setting-form").on("click", ".del_linkBtn", function () { + $(this).parents(".linkFormItem").remove(); }); //有关报名要求 - $("#addRequireBtn").on("click",function () { + $(".addRequireBtn").on("click",function () { var length=$("#requireForm").find(".requireForm_item").length + 1; var html='
\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' + @@ -209,5 +203,33 @@ $(function () { } else { radio.parent().parent().siblings().find('.mutiple-limited-radio').attr('checked', true) } - }) + }); + + var $navForm = $('form.nav-setting-form'); + $navForm.on('click', ".submit-btn", function () { + $navForm.find('.submit-btn').attr('disabled', 'disabled'); + $navForm.find('.error').html(''); + var valid = $navForm.valid(); + + if (!valid) return; + $.ajax({ + method: 'POST', + dataType: 'json', + url: $navForm.attr('action'), + data: new FormData($navForm[0]), + processData: false, + contentType: false, + success: function (data) { + $.notify({message: '保存成功'}); + // window.location.reload(); + }, + error: function (res) { + var data = res.responseJSON; + $navForm.find('.error').html(data.message); + }, + complete: function () { + $navForm.find('.submit-btn').attr('disabled', false); + } + }); + }); }); \ No newline at end of file diff --git a/app/services/admins/competition_basic_setting_service.rb b/app/services/admins/competition_basic_setting_service.rb index e5a7dd6be..d943b1cb0 100644 --- a/app/services/admins/competition_basic_setting_service.rb +++ b/app/services/admins/competition_basic_setting_service.rb @@ -21,7 +21,7 @@ class Admins::CompetitionBasicSettingService < ApplicationService competition.save! if competition.mode == 1 || competition.mode == 4 - competition.competition_mode_setting.destroy + competition.competition_mode_setting&.destroy else setting = competition.competition_mode_setting || CompetitionModeSetting.create!(competition_id: competition.id) if competition.mode == 2 diff --git a/app/services/admins/competition_nav_setting_service.rb b/app/services/admins/competition_nav_setting_service.rb index 9b68450f7..4254dd060 100644 --- a/app/services/admins/competition_nav_setting_service.rb +++ b/app/services/admins/competition_nav_setting_service.rb @@ -20,7 +20,7 @@ class Admins::CompetitionNavSettingService < ApplicationService else com_module = CompetitionModule.create!(competition_id: competition.id, module_type: 'md') end - com_module.update_attributes!(hidden: nav["hidden"] ? 0 : 1, position: nav["position"], name: nav["name"], url: nav["url"]) + com_module.update_attributes!(hidden: nav["hidden"] ? 0 : 1, position: nav["position"] ? nav["position"] : com_module.position, name: nav["name"], url: nav["url"]) end competition.update_attributes!(enroll_end_time: params[:enroll_end_time]) diff --git a/app/views/admins/competition_settings/index.html.erb b/app/views/admins/competition_settings/index.html.erb index c2fdabbad..57c6f2fda 100644 --- a/app/views/admins/competition_settings/index.html.erb +++ b/app/views/admins/competition_settings/index.html.erb @@ -160,7 +160,8 @@
@@ -200,7 +201,7 @@ 报名要求
- + <%= javascript_void_link '+', class: 'btn btn-primary waves-effect waves-light btn-xs setBtn_s addRequireBtn' %>
@@ -213,7 +214,7 @@
~
- +
@@ -244,7 +245,7 @@
<% when 'inform', 'chart', 'resource' %> -
+
<% else %> @@ -282,8 +283,8 @@
<%= text_field_tag('navbar[][url]', com_module.url, id: nil, class: 'form-control', placeholder: '请输入资料下载地址') %>
- - + <%= javascript_void_link '+', class: 'mt-1 btn btn-primary waves-effect waves-light btn-xs setBtn_s add_linkBtn' %> + <%= javascript_void_link '×', class: 'mt-1 btn btn-icon waves-effect btn-default waves-light setBtn_s ml10 del_linkBtn' %>
<% end %> <% end %> @@ -298,12 +299,13 @@ +
+
<%= javascript_void_link '保存', class: 'btn btn-primary submit-btn' %>
-
<% end %>
diff --git a/db/migrate/20191024075134_migrate_competition_module_manual.rb b/db/migrate/20191024075134_migrate_competition_module_manual.rb new file mode 100644 index 000000000..3a2f16cff --- /dev/null +++ b/db/migrate/20191024075134_migrate_competition_module_manual.rb @@ -0,0 +1,5 @@ +class MigrateCompetitionModuleManual < ActiveRecord::Migration[5.2] + def change + CompetitionModule.where(module_type: "manual").update_all(module_type: "md") + end +end