Merge branch 'dev_aliyun' of http://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun
commit
58ed01395e
@ -0,0 +1,31 @@
|
||||
$(document).on('turbolinks:load', function() {
|
||||
$('.admin-modal-container').on('show.bs.modal', '.modal.admin-edit-tag-repertoire-modal', function(){
|
||||
var $modal = $('.modal.admin-edit-tag-repertoire-modal');
|
||||
var $form = $modal.find('form.admin-edit-tag-repertoire-form');
|
||||
|
||||
$form.validate({
|
||||
errorElement: 'span',
|
||||
errorClass: 'danger text-danger',
|
||||
rules: {
|
||||
'tag_repertoire[name]': {
|
||||
required: true,
|
||||
maxlength: 20
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$modal.on('click', '.submit-btn', function(){
|
||||
$form.find('.error').html('');
|
||||
var url = $form.attr('action');
|
||||
|
||||
if ($form.valid()) {
|
||||
$.ajax({
|
||||
method: 'PATCH',
|
||||
dataType: 'script',
|
||||
url: url,
|
||||
data: $form.serialize()
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
@ -0,0 +1,65 @@
|
||||
$(document).on('turbolinks:load', function() {
|
||||
if ($('body.admins-tag-repertoires-index-page').length > 0) {
|
||||
|
||||
// ============== 新建 ===============
|
||||
var $modal = $('.modal.admin-create-tag-repertoire-modal');
|
||||
var $form = $modal.find('form.admin-create-tag-repertoire-form');
|
||||
var $nameInput = $form.find('input[name="name"]');
|
||||
|
||||
$form.validate({
|
||||
errorElement: 'span',
|
||||
errorClass: 'danger text-danger',
|
||||
rules: {
|
||||
name: {
|
||||
required: true
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// modal ready fire
|
||||
$modal.on('show.bs.modal', function () {
|
||||
$nameInput.val('');
|
||||
});
|
||||
|
||||
$modal.on('click', '.submit-btn', function(){
|
||||
$form.find('.error').html('');
|
||||
|
||||
if ($form.valid()) {
|
||||
var url = $form.data('url');
|
||||
|
||||
$.ajax({
|
||||
method: 'POST',
|
||||
dataType: 'json',
|
||||
url: url,
|
||||
data: $form.serialize(),
|
||||
success: function(){
|
||||
$.notify({ message: '创建成功' });
|
||||
$modal.modal('hide');
|
||||
|
||||
setTimeout(function(){
|
||||
window.location.reload();
|
||||
}, 500);
|
||||
},
|
||||
error: function(res){
|
||||
var data = res.responseJSON;
|
||||
$form.find('.error').html(data.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$(".tag-repertoire-list-container").on("change", '.tag-repertoire-source-form', function () {
|
||||
var s_id = $(this).attr("data-id");
|
||||
var s_value = $(this).val();
|
||||
var s_name = $(this).attr("name");
|
||||
var json = {};
|
||||
json[s_name] = s_value;
|
||||
$.ajax({
|
||||
url: "/admins/tag_repertoires/" + s_id,
|
||||
type: "PUT",
|
||||
dataType:'script',
|
||||
data: json
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
@ -0,0 +1,43 @@
|
||||
class Admins::TagRepertoiresController < Admins::BaseController
|
||||
|
||||
def index
|
||||
@sub_repertoire = current_sub_repertoire
|
||||
@tag_repertoires = current_sub_repertoire.tag_repertoires
|
||||
end
|
||||
|
||||
def create
|
||||
name = params[:name].to_s.strip
|
||||
return render_error('名称重复') if current_sub_repertoire.tag_repertoires.where(name: name).exists?
|
||||
TagRepertoire.create!(name: name, sub_repertoire_id: current_sub_repertoire.id)
|
||||
render_ok
|
||||
end
|
||||
|
||||
def edit
|
||||
@tag_repertoire = current_tag_repertoire
|
||||
end
|
||||
|
||||
def update
|
||||
if params[:tag_repertoire] && params[:tag_repertoire][:name].present?
|
||||
name = params[:tag_repertoire][:name].to_s.strip
|
||||
current_tag_repertoire.update_attributes!(name: name)
|
||||
end
|
||||
@tag_repertoires = current_tag_repertoire.sub_repertoire&.tag_repertoires
|
||||
end
|
||||
|
||||
def destroy
|
||||
@tag_repertoire_id = params[:id]
|
||||
current_tag_repertoire.destroy!
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def current_sub_repertoire
|
||||
@_current_sub_repertoire = SubRepertoire.find params[:sub_repertoire_id]
|
||||
end
|
||||
|
||||
def current_tag_repertoire
|
||||
@_current_tag_repertoire = TagRepertoire.find params[:id]
|
||||
end
|
||||
|
||||
|
||||
end
|
@ -0,0 +1,2 @@
|
||||
$.notify({ message: '删除成功' });
|
||||
$(".tag-repertoire-item-<%= @tag_repertoire_id %>").remove();
|
@ -0,0 +1,2 @@
|
||||
$('.admin-modal-container').html("<%= j( render partial: 'admins/tag_repertoires/shared/edit_tag_repertoire_modal', locals: { tag_repertoire: @tag_repertoire } ) %>");
|
||||
$('.modal.admin-edit-tag-repertoire-modal').modal('show');
|
@ -0,0 +1,15 @@
|
||||
<% define_admin_breadcrumbs do %>
|
||||
<% add_admin_breadcrumb('技术体系', admins_repertoires_path) %>
|
||||
<% add_admin_breadcrumb(@sub_repertoire&.repertoire&.name, admins_sub_repertoires_path(repertoire_id: @sub_repertoire&.repertoire_id)) %>
|
||||
<% add_admin_breadcrumb(@sub_repertoire.name) %>
|
||||
<% end %>
|
||||
|
||||
<div class="box search-form-container tag-repertoire-list-form">
|
||||
<%= javascript_void_link '新增', class: 'btn btn-primary', data: { toggle: 'modal', target: '.admin-create-tag-repertoire-modal' } %>
|
||||
</div>
|
||||
|
||||
<div class="box admin-list-container tag-repertoire-list-container">
|
||||
<%= render(partial: 'admins/tag_repertoires/shared/list') %>
|
||||
</div>
|
||||
|
||||
<%= render 'admins/tag_repertoires/shared/create_tag_repertoire_modal' %>
|
@ -0,0 +1,28 @@
|
||||
<div class="modal fade admin-create-tag-repertoire-modal" tabindex="-1" role="dialog" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">新建知识标签</h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form class="admin-create-tag-repertoire-form" data-url="<%= admins_tag_repertoires_path(sub_repertoire_id: @sub_repertoire) %>">
|
||||
<div class="form-group d-flex">
|
||||
<label for="new_mirror_id" class="col-form-label">名称:</label>
|
||||
<div class="w-75 d-flex flex-column">
|
||||
<%= text_field_tag(:name, nil, class: 'form-control', placeholder: '请输入名称') %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="error text-danger"></div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
|
||||
<button type="button" class="btn btn-primary submit-btn">确认</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
@ -0,0 +1,23 @@
|
||||
<div class="modal fade admin-edit-tag-repertoire-modal" tabindex="-1" role="dialog" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">编辑知识点</h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<%= simple_form_for([:admins, tag_repertoire], html: { class: 'admin-edit-tag-repertoire-form' }, defaults: { wrapper_html: { class: 'offset-md-1 col-md-10' } }) do |f| %>
|
||||
<%= f.input :name, as: :string, label: '名称' %>
|
||||
|
||||
<div class="error text-danger"></div>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
|
||||
<button type="button" class="btn btn-primary submit-btn">确认</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
@ -0,0 +1,25 @@
|
||||
<table class="table table-hover text-center tag-repertoire-list-table">
|
||||
<thead class="thead-light">
|
||||
<tr>
|
||||
<th width="6%">序号</th>
|
||||
<th width="42%" class="text-left">知识标签</th>
|
||||
<th width="16%">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% if @tag_repertoires.present? %>
|
||||
<% @tag_repertoires.each_with_index do |tag, index| %>
|
||||
<tr class="tag-repertoire-item tag-repertoire-item-<%= tag.id %>">
|
||||
<td><%= index + 1 %></td>
|
||||
<td class="text-left"><%= tag.name %></td>
|
||||
<td>
|
||||
<%= link_to '编辑', edit_admins_tag_repertoire_path(tag), remote: true, class: 'action' %>
|
||||
<%= delete_link '删除', admins_tag_repertoire_path(tag, element: ".tag-repertoire-item-#{tag.id}"), class: 'delete-tag-repertoire-action' %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= render 'admins/shared/no_data_for_table' %>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
@ -0,0 +1,2 @@
|
||||
$('.modal.admin-edit-tag-repertoire-modal').modal("hide");
|
||||
$(".tag-repertoire-list-container").html("<%= j(render :partial => 'admins/tag_repertoires/shared/list') %>");
|
Loading…
Reference in new issue