课程体系的新增和编辑弹框均支持回车提交、并增加提示信息

dev_video
cxt 5 years ago
parent 94a711d8e0
commit ff919bddae

@ -14,7 +14,18 @@ $(document).on('turbolinks:load', function() {
}
});
$modal.on('click', '.submit-btn', function(){
$modal.on('click', '.submit-btn', submit_edit_form);
$form.find("#discipline_name").keydown(function (e) {
var ev = e || event;
var keycode = ev.which || ev.keyCode;
if (keycode == 13) {
submit_edit_form();
return false;
}
});
function submit_edit_form() {
$form.find('.error').html('');
var url = $form.attr('action');
@ -26,6 +37,6 @@ $(document).on('turbolinks:load', function() {
data: $form.serialize()
});
}
});
}
});
});

@ -14,7 +14,18 @@ $(document).on('turbolinks:load', function() {
}
});
$modal.on('click', '.submit-btn', function(){
$modal.on('click', '.submit-btn', submit_edit_form);
$form.find("#sub_discipline_name").keydown(function (e) {
var ev = e || event;
var keycode = ev.which || ev.keyCode;
if (keycode == 13) {
submit_edit_form();
return false;
}
});
function submit_edit_form() {
$form.find('.error').html('');
var url = $form.attr('action');
@ -26,6 +37,7 @@ $(document).on('turbolinks:load', function() {
data: $form.serialize()
});
}
});
}
});
});

@ -14,7 +14,18 @@ $(document).on('turbolinks:load', function() {
}
});
$modal.on('click', '.submit-btn', function(){
$modal.on('click', '.submit-btn', submit_edit_form);
$form.find("#tag_discipline_name").keydown(function (e) {
var ev = e || event;
var keycode = ev.which || ev.keyCode;
if (keycode == 13) {
submit_edit_form();
return false;
}
});
function submit_edit_form() {
$form.find('.error').html('');
var url = $form.attr('action');
@ -26,6 +37,6 @@ $(document).on('turbolinks:load', function() {
data: $form.serialize()
});
}
});
}
});
});

@ -21,7 +21,18 @@ $(document).on('turbolinks:load', function() {
$nameInput.val('');
});
$modal.on('click', '.submit-btn', function(){
$modal.on('click', '.submit-btn', submit_create_form);
$nameInput.keydown(function (e) {
var ev = e || event;
var keycode = ev.which || ev.keyCode;
if (keycode == 13) {
submit_create_form();
return false;
}
});
function submit_create_form() {
$form.find('.error').html('');
if ($form.valid()) {
@ -46,7 +57,7 @@ $(document).on('turbolinks:load', function() {
}
});
}
});
}
$(".sub-discipline-list-container").on("change", '.sub-discipline-source-form', function () {
var s_id = $(this).attr("data-id");

@ -21,7 +21,18 @@ $(document).on('turbolinks:load', function() {
$nameInput.val('');
});
$modal.on('click', '.submit-btn', function(){
$modal.on('click', '.submit-btn', submit_create_form);
$nameInput.keydown(function (e) {
var ev = e || event;
var keycode = ev.which || ev.keyCode;
if (keycode == 13) {
submit_create_form();
return false;
}
});
function submit_create_form() {
$form.find('.error').html('');
if ($form.valid()) {
@ -46,7 +57,7 @@ $(document).on('turbolinks:load', function() {
}
});
}
});
}
$(".tag-discipline-list-container").on("change", '.tag-discipline-source-form', function () {
var s_id = $(this).attr("data-id");

@ -16,7 +16,8 @@ class Admins::DisciplinesController < Admins::BaseController
end
def update
if params[:discipline] && params[:discipline][:name].present?
begin
if params[:discipline] && params[:discipline][:name]
name = params[:discipline][:name].to_s.strip
current_discipline.update_attributes!(name: name)
else
@ -30,6 +31,9 @@ class Admins::DisciplinesController < Admins::BaseController
end
end
end
rescue Exception => e
@message = e.message
end
@disciplines = Discipline.all
end

@ -7,6 +7,7 @@ class Admins::SubDisciplinesController < Admins::BaseController
def create
name = params[:name].to_s.strip
return render_error('名称不能为空') if name.blank?
return render_error('名称重复') if current_discipline.sub_disciplines.where(name: name).exists?
SubDiscipline.create!(name: name, discipline_id: current_discipline.id)
render_ok
@ -17,7 +18,8 @@ class Admins::SubDisciplinesController < Admins::BaseController
end
def update
if params[:sub_discipline] && params[:sub_discipline][:name].present?
begin
if params[:sub_discipline] && params[:sub_discipline][:name]
name = params[:sub_discipline][:name].to_s.strip
current_sub_discipline.update_attributes!(name: name)
else
@ -28,6 +30,9 @@ class Admins::SubDisciplinesController < Admins::BaseController
end
end
end
rescue Exception => e
@message = e.message
end
@sub_disciplines = current_sub_discipline.discipline&.sub_disciplines
end

@ -17,12 +17,16 @@ class Admins::TagDisciplinesController < Admins::BaseController
end
def update
if params[:tag_discipline] && params[:tag_discipline][:name].present?
begin
if params[:tag_discipline] && params[:tag_discipline][:name]
name = params[:tag_discipline][:name].to_s.strip
current_tag_discipline.update_attributes!(name: name)
else
current_tag_discipline.update_attributes!(setting_params)
end
rescue Exception => e
@message = e.message
end
@tag_disciplines = current_tag_discipline.sub_discipline&.tag_disciplines
end

@ -2,8 +2,6 @@ class TagDisciplinesController < ApplicationController
before_action :require_login
def create
tip_exception("请输入知识点") if params[:name].blank?
tip_exception("输入字符长度限制在15个以内") if params[:name].length > 15
sub_discipline = SubDiscipline.find_by!(id: params[:sub_discipline_id])
tip_exception("重复的知识点") if sub_discipline.tag_disciplines.exists?(name: params[:name].to_s.strip)
tag_discipline = TagDiscipline.create!(name: params[:name].to_s.strip, sub_discipline: sub_discipline, user_id: current_user.id)

@ -4,4 +4,7 @@ class Discipline < ApplicationRecord
has_many :shixun_sub_disciplines, -> { where("shixun = 1") }, class_name: "SubDiscipline"
has_many :subject_sub_disciplines, -> { where("subject = 1") }, class_name: "SubDiscipline"
has_many :question_sub_disciplines, -> { where("question = 1") }, class_name: "SubDiscipline"
validates_presence_of :name
end

@ -7,4 +7,7 @@ class SubDiscipline < ApplicationRecord
has_many :shixun_tag_disciplines, -> { where("shixun = 1") }, class_name: "TagDiscipline"
has_many :subject_tag_disciplines, -> { where("subject = 1") }, class_name: "TagDiscipline"
has_many :question_tag_disciplines, -> { where("question = 1") }, class_name: "TagDiscipline"
validates_presence_of :name
end

@ -4,6 +4,7 @@ class TagDiscipline < ApplicationRecord
has_many :tag_discipline_containers, dependent: :destroy
validates_presence_of :name
validates :name, length: { maximum: 15, too_long: "不能超过15个字符" }
def discipline
sub_discipline&.discipline

@ -1,2 +1,6 @@
<% if @message.present? %>
$.notify({ message: "<%= @message %>" });
<% else %>
$('.modal.admin-edit-discipline-modal').modal("hide");
$(".discipline-list-container").html("<%= j(render :partial => 'admins/disciplines/shared/list') %>");
<% end %>

@ -1,2 +1,6 @@
<% if @message.present? %>
$.notify({ message: "<%= @message %>" });
<% else %>
$('.modal.admin-edit-sub-discipline-modal').modal("hide");
$(".sub-discipline-list-container").html("<%= j(render :partial => 'admins/sub_disciplines/shared/list') %>");
<% end %>

@ -1,2 +1,6 @@
<% if @message.present? %>
$.notify({ message: "<%= @message %>" });
<% else %>
$('.modal.admin-edit-tag-discipline-modal').modal("hide");
$(".tag-discipline-list-container").html("<%= j(render :partial => 'admins/tag_disciplines/shared/list') %>");
<% end %>

@ -164,6 +164,12 @@ zh-CN:
notes: '笔记'
trustie_hack:
description: '描述'
discipline:
name: '名称'
sub_discipline:
name: '名称'
tag_discipline:
name: '名称'

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save