Merge branches 'dev_aliyun' and 'dev_new_shixunsrepository' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_new_shixunsrepository
Conflicts: public/react/src/modules/tpm/TPMIndex.jsdev_new_shixunsrepository
commit
f022a8139e
@ -1,31 +1,42 @@
|
||||
$(document).on('turbolinks:load', function() {
|
||||
$('.admin-modal-container').on('show.bs.modal', '.modal.admin-edit-discipline-modal', function(){
|
||||
var $modal = $('.modal.admin-edit-discipline-modal');
|
||||
var $form = $modal.find('form.admin-edit-discipline-form');
|
||||
$(document).on('turbolinks:load', function () {
|
||||
$('.admin-modal-container').on('show.bs.modal', '.modal.admin-edit-discipline-modal', function () {
|
||||
var $modal = $('.modal.admin-edit-discipline-modal');
|
||||
var $form = $modal.find('form.admin-edit-discipline-form');
|
||||
|
||||
$form.validate({
|
||||
errorElement: 'span',
|
||||
errorClass: 'danger text-danger',
|
||||
rules: {
|
||||
'discipline[name]': {
|
||||
required: true,
|
||||
maxlength: 20
|
||||
}
|
||||
}
|
||||
});
|
||||
$form.validate({
|
||||
errorElement: 'span',
|
||||
errorClass: 'danger text-danger',
|
||||
rules: {
|
||||
'discipline[name]': {
|
||||
required: true,
|
||||
maxlength: 20
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$modal.on('click', '.submit-btn', function(){
|
||||
$form.find('.error').html('');
|
||||
var url = $form.attr('action');
|
||||
$modal.on('click', '.submit-btn', submit_edit_form);
|
||||
|
||||
if ($form.valid()) {
|
||||
$.ajax({
|
||||
method: 'PATCH',
|
||||
dataType: 'script',
|
||||
url: url,
|
||||
data: $form.serialize()
|
||||
$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');
|
||||
|
||||
if ($form.valid()) {
|
||||
$.ajax({
|
||||
method: 'PATCH',
|
||||
dataType: 'script',
|
||||
url: url,
|
||||
data: $form.serialize()
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
@ -0,0 +1,31 @@
|
||||
$(document).on('turbolinks:load', function() {
|
||||
$('.admin-modal-container').on('show.bs.modal', '.modal.admin-edit-repertoire-modal', function(){
|
||||
var $modal = $('.modal.admin-edit-repertoire-modal');
|
||||
var $form = $modal.find('form.admin-edit-repertoire-form');
|
||||
|
||||
$form.validate({
|
||||
errorElement: 'span',
|
||||
errorClass: 'danger text-danger',
|
||||
rules: {
|
||||
'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()
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
@ -1,31 +1,43 @@
|
||||
$(document).on('turbolinks:load', function() {
|
||||
$('.admin-modal-container').on('show.bs.modal', '.modal.admin-edit-sub-discipline-modal', function(){
|
||||
var $modal = $('.modal.admin-edit-sub-discipline-modal');
|
||||
var $form = $modal.find('form.admin-edit-sub-discipline-form');
|
||||
$(document).on('turbolinks:load', function () {
|
||||
$('.admin-modal-container').on('show.bs.modal', '.modal.admin-edit-sub-discipline-modal', function () {
|
||||
var $modal = $('.modal.admin-edit-sub-discipline-modal');
|
||||
var $form = $modal.find('form.admin-edit-sub-discipline-form');
|
||||
|
||||
$form.validate({
|
||||
errorElement: 'span',
|
||||
errorClass: 'danger text-danger',
|
||||
rules: {
|
||||
'sub_discipline[name]': {
|
||||
required: true,
|
||||
maxlength: 20
|
||||
}
|
||||
}
|
||||
});
|
||||
$form.validate({
|
||||
errorElement: 'span',
|
||||
errorClass: 'danger text-danger',
|
||||
rules: {
|
||||
'sub_discipline[name]': {
|
||||
required: true,
|
||||
maxlength: 20
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$modal.on('click', '.submit-btn', function(){
|
||||
$form.find('.error').html('');
|
||||
var url = $form.attr('action');
|
||||
$modal.on('click', '.submit-btn', submit_edit_form);
|
||||
|
||||
if ($form.valid()) {
|
||||
$.ajax({
|
||||
method: 'PATCH',
|
||||
dataType: 'script',
|
||||
url: url,
|
||||
data: $form.serialize()
|
||||
$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');
|
||||
|
||||
if ($form.valid()) {
|
||||
$.ajax({
|
||||
method: 'PATCH',
|
||||
dataType: 'script',
|
||||
url: url,
|
||||
data: $form.serialize()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
});
|
@ -0,0 +1,31 @@
|
||||
$(document).on('turbolinks:load', function() {
|
||||
$('.admin-modal-container').on('show.bs.modal', '.modal.admin-edit-sub-repertoire-modal', function(){
|
||||
var $modal = $('.modal.admin-edit-sub-repertoire-modal');
|
||||
var $form = $modal.find('form.admin-edit-sub-repertoire-form');
|
||||
|
||||
$form.validate({
|
||||
errorElement: 'span',
|
||||
errorClass: 'danger text-danger',
|
||||
rules: {
|
||||
'sub_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()
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
@ -1,31 +1,42 @@
|
||||
$(document).on('turbolinks:load', function() {
|
||||
$('.admin-modal-container').on('show.bs.modal', '.modal.admin-edit-tag-discipline-modal', function(){
|
||||
var $modal = $('.modal.admin-edit-tag-discipline-modal');
|
||||
var $form = $modal.find('form.admin-edit-tag-discipline-form');
|
||||
$(document).on('turbolinks:load', function () {
|
||||
$('.admin-modal-container').on('show.bs.modal', '.modal.admin-edit-tag-discipline-modal', function () {
|
||||
var $modal = $('.modal.admin-edit-tag-discipline-modal');
|
||||
var $form = $modal.find('form.admin-edit-tag-discipline-form');
|
||||
|
||||
$form.validate({
|
||||
errorElement: 'span',
|
||||
errorClass: 'danger text-danger',
|
||||
rules: {
|
||||
'tag_discipline[name]': {
|
||||
required: true,
|
||||
maxlength: 20
|
||||
}
|
||||
}
|
||||
});
|
||||
$form.validate({
|
||||
errorElement: 'span',
|
||||
errorClass: 'danger text-danger',
|
||||
rules: {
|
||||
'tag_discipline[name]': {
|
||||
required: true,
|
||||
maxlength: 20
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$modal.on('click', '.submit-btn', function(){
|
||||
$form.find('.error').html('');
|
||||
var url = $form.attr('action');
|
||||
$modal.on('click', '.submit-btn', submit_edit_form);
|
||||
|
||||
if ($form.valid()) {
|
||||
$.ajax({
|
||||
method: 'PATCH',
|
||||
dataType: 'script',
|
||||
url: url,
|
||||
data: $form.serialize()
|
||||
$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');
|
||||
|
||||
if ($form.valid()) {
|
||||
$.ajax({
|
||||
method: 'PATCH',
|
||||
dataType: 'script',
|
||||
url: url,
|
||||
data: $form.serialize()
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
@ -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-repertoires-index-page').length > 0) {
|
||||
|
||||
// ============== 新建 ===============
|
||||
var $modal = $('.modal.admin-create-repertoire-modal');
|
||||
var $form = $modal.find('form.admin-create-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);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$(".repertoire-list-container").on("change", '.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/repertoires/" + s_id,
|
||||
type: "PUT",
|
||||
dataType:'script',
|
||||
data: json
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
@ -0,0 +1,119 @@
|
||||
$(document).on('turbolinks:load', function() {
|
||||
if ($('body.admins-salesman-channels-index-page').length > 0) {
|
||||
|
||||
// ============= 添加销售人员 ==============
|
||||
var $addMemberModal = $('.admin-add-salesman-channel-user-modal');
|
||||
var $addMemberForm = $addMemberModal.find('.admin-add-salesman-channel-user-form');
|
||||
var $memberSelect = $addMemberModal.find('.salesman-channel-user-select');
|
||||
var $form = $addMemberModal.find('form.admin-add-salesman-user-form');
|
||||
|
||||
// 搜索
|
||||
var searchscForm = $(".saleman-channel-list-form .search-form");
|
||||
|
||||
|
||||
$addMemberModal.on('show.bs.modal', function(event){
|
||||
$memberSelect.select2('val', ' ');
|
||||
});
|
||||
|
||||
$memberSelect.select2({
|
||||
theme: 'bootstrap4',
|
||||
placeholder: '请输入要添加的单位',
|
||||
multiple: true,
|
||||
minimumInputLength: 1,
|
||||
ajax: {
|
||||
delay: 500,
|
||||
url: '/admins/schools',
|
||||
dataType: 'json',
|
||||
data: function(params){
|
||||
return { keyword: params.term };
|
||||
},
|
||||
processResults: function(data){
|
||||
return { results: data.schools }
|
||||
}
|
||||
},
|
||||
templateResult: function (item) {
|
||||
if(!item.id || item.id === '') return '';
|
||||
return $("<span>" + item.name + "</span>");
|
||||
},
|
||||
templateSelection: function(item){
|
||||
if (item.id) {
|
||||
}
|
||||
return item.name || '';
|
||||
}
|
||||
});
|
||||
|
||||
$addMemberModal.on('click', '.submit-btn', function(){
|
||||
$addMemberForm.find('.error').html('');
|
||||
|
||||
// var salesmanId = $salesmanIdInput.val();
|
||||
var memberIds = $memberSelect.val();
|
||||
if (memberIds && memberIds.length > 0) {
|
||||
var url = $form.data('url');
|
||||
$.ajax({
|
||||
method: 'POST',
|
||||
dataType: 'json',
|
||||
url: url,
|
||||
data: $form.serialize(),
|
||||
success: function(){
|
||||
$.notify({ message: '创建成功' });
|
||||
$addMemberModal.modal('hide');
|
||||
searchscForm.find('input[name="keyword"]').val('');
|
||||
|
||||
setTimeout(function(){
|
||||
submitForm();
|
||||
}, 500);
|
||||
},
|
||||
error: function(res){
|
||||
var data = res.responseJSON;
|
||||
$addMemberForm.find('.error').html(data.message);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
$addMemberModal.modal('hide');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// 清空
|
||||
searchscForm.on('click', '.clear-btn', function () {
|
||||
searchscForm.find('.start_date').val('');
|
||||
searchscForm.find('.end_date').val('').trigger('change');
|
||||
searchscForm.find('input[name="keyword"]').val('');
|
||||
});
|
||||
|
||||
// 时间跨度
|
||||
var baseOptions = {
|
||||
autoclose: true,
|
||||
language: 'zh-CN',
|
||||
format: 'yyyy-mm-dd',
|
||||
startDate: '2017-04-01'
|
||||
};
|
||||
|
||||
var defineDateRangeSelect = function(element){
|
||||
var options = $.extend({inputs: $(element).find('.start-date, .end-date')}, baseOptions);
|
||||
$(element).datepicker(options);
|
||||
|
||||
$(element).find('.start-date').datepicker().on('changeDate', function(e){
|
||||
$(element).find('.end-date').datepicker('setStartDate', e.date);
|
||||
});
|
||||
};
|
||||
|
||||
defineDateRangeSelect('.grow-date-input-daterange');
|
||||
|
||||
|
||||
// 区间搜索
|
||||
searchscForm.on('click', ".search-btn", function(){
|
||||
submitForm();
|
||||
});
|
||||
|
||||
var submitForm = function(){
|
||||
var url = searchscForm.data('search-form-url');
|
||||
var form = searchscForm;
|
||||
$.ajax({
|
||||
url: url,
|
||||
data: form.serialize(),
|
||||
dataType: "script"
|
||||
})
|
||||
};
|
||||
}
|
||||
});
|
@ -0,0 +1,82 @@
|
||||
$(document).on('turbolinks:load', function() {
|
||||
if ($('body.admins-salesman-customers-index-page').length > 0) {
|
||||
|
||||
// ============= 添加销售人员 ==============
|
||||
var $addMemberModal = $('.admin-add-salesman-customer-user-modal');
|
||||
var $addMemberForm = $addMemberModal.find('.admin-add-salesman-customer-user-form');
|
||||
var $memberSelect = $addMemberModal.find('.salesman-customer-user-select');
|
||||
var $salesmanIdInput = $('.salesman-customer-list-form').find(".btn-primary");
|
||||
|
||||
$addMemberModal.on('show.bs.modal', function(event){
|
||||
var $link = $(event.relatedTarget);
|
||||
// var salesmanId = $link.data('salesman_id');
|
||||
// $salesmanIdInput.val(salesmanId);
|
||||
|
||||
$memberSelect.select2('val', ' ');
|
||||
});
|
||||
|
||||
$memberSelect.select2({
|
||||
theme: 'bootstrap4',
|
||||
placeholder: '请输入要添加的销售姓名',
|
||||
multiple: true,
|
||||
minimumInputLength: 1,
|
||||
ajax: {
|
||||
delay: 500,
|
||||
url: '/admins/users',
|
||||
dataType: 'json',
|
||||
data: function(params){
|
||||
return { name: params.term };
|
||||
},
|
||||
processResults: function(data){
|
||||
return { results: data.users }
|
||||
}
|
||||
},
|
||||
templateResult: function (item) {
|
||||
if(!item.id || item.id === '') return item.text;
|
||||
return $("<span>" + item.real_name + " <span class='font-12'>" + item.school_name + ' ' + item.hidden_phone + "</span></span>");
|
||||
},
|
||||
templateSelection: function(item){
|
||||
if (item.id) {
|
||||
}
|
||||
return item.real_name || item.text;
|
||||
}
|
||||
});
|
||||
|
||||
$addMemberModal.on('click', '.submit-btn', function(){
|
||||
$addMemberForm.find('.error').html('');
|
||||
|
||||
// var salesmanId = $salesmanIdInput.val();
|
||||
var memberIds = $memberSelect.val();
|
||||
if (memberIds && memberIds.length > 0) {
|
||||
$.ajax({
|
||||
method: 'POST',
|
||||
dataType: 'json',
|
||||
url: '/admins/salesman_customers/batch_add',
|
||||
data: { salesman_id: $salesmanIdInput.data("salesman-id"), user_ids: memberIds },
|
||||
success: function(){
|
||||
$.notify({ message: '创建成功' });
|
||||
$addMemberModal.modal('hide');
|
||||
|
||||
setTimeout(function(){
|
||||
listForm();
|
||||
}, 500);
|
||||
},
|
||||
error: function(res){
|
||||
var data = res.responseJSON;
|
||||
$form.find('.error').html(data.message);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
$addMemberModal.modal('hide');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
var listForm = function(){
|
||||
$.ajax({
|
||||
url: '/admins/salesman_customers?salesman_id='+ $salesmanIdInput.data("salesman-id"),
|
||||
dataType: "script"
|
||||
});
|
||||
};
|
||||
}
|
||||
});
|
@ -0,0 +1,99 @@
|
||||
$(document).on('turbolinks:load', function() {
|
||||
if ($('body.admins-salesmans-index-page').length > 0) {
|
||||
|
||||
// ============= 添加销售人员 ==============
|
||||
var $addMemberModal = $('.admin-add-salesman-user-modal');
|
||||
var $addMemberForm = $addMemberModal.find('.admin-add-salesman-user-form');
|
||||
var $memberSelect = $addMemberModal.find('.salesman-user-select');
|
||||
// var $salesmanIdInput = $addMemberForm.find('input[name="salesman_id"]')
|
||||
|
||||
$addMemberModal.on('show.bs.modal', function(event){
|
||||
var $link = $(event.relatedTarget);
|
||||
// var salesmanId = $link.data('salesman-id');
|
||||
// $salesmanIdInput.val(salesmanId);
|
||||
|
||||
$memberSelect.select2('val', ' ');
|
||||
});
|
||||
|
||||
$memberSelect.select2({
|
||||
theme: 'bootstrap4',
|
||||
placeholder: '请输入要添加的销售姓名',
|
||||
multiple: true,
|
||||
minimumInputLength: 1,
|
||||
ajax: {
|
||||
delay: 500,
|
||||
url: '/admins/users',
|
||||
dataType: 'json',
|
||||
data: function(params){
|
||||
return { name: params.term };
|
||||
},
|
||||
processResults: function(data){
|
||||
return { results: data.users }
|
||||
}
|
||||
},
|
||||
templateResult: function (item) {
|
||||
if(!item.id || item.id === '') return item.text;
|
||||
return $("<span>" + item.real_name + " <span class='font-12'>" + item.school_name + ' ' + item.hidden_phone + "</span></span>");
|
||||
},
|
||||
templateSelection: function(item){
|
||||
if (item.id) {
|
||||
}
|
||||
return item.real_name || item.text;
|
||||
}
|
||||
});
|
||||
|
||||
$addMemberModal.on('click', '.submit-btn', function(){
|
||||
$addMemberForm.find('.error').html('');
|
||||
|
||||
// var salesmanId = $salesmanIdInput.val();
|
||||
var memberIds = $memberSelect.val();
|
||||
if (memberIds && memberIds.length > 0) {
|
||||
$.ajax({
|
||||
method: 'POST',
|
||||
dataType: 'json',
|
||||
url: '/admins/salesmans/batch_add',
|
||||
data: { user_ids: memberIds },
|
||||
success: function(){
|
||||
$.notify({ message: '创建成功' });
|
||||
$addMemberModal.modal('hide');
|
||||
|
||||
setTimeout(function(){
|
||||
window.location.reload();
|
||||
}, 500);
|
||||
},
|
||||
error: function(res){
|
||||
var data = res.responseJSON;
|
||||
$form.find('.error').html(data.message);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
$addMemberModal.modal('hide');
|
||||
}
|
||||
});
|
||||
|
||||
$(".salesman-list-container").on("change", '.salesman-sync-course', function () {
|
||||
var s_id = $(this).attr("data-id");
|
||||
var json = {};
|
||||
$.ajax({
|
||||
url: "/admins/salesmans/" + s_id + "/update_sync_course",
|
||||
type: "POST",
|
||||
dataType:'script',
|
||||
data: json
|
||||
})
|
||||
});
|
||||
|
||||
$(".salesman-list-container").on("change", '.salesman-sync-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/salesmans/" + s_id,
|
||||
type: "PUT",
|
||||
dataType:'script',
|
||||
data: json
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
@ -1,65 +1,89 @@
|
||||
$(document).on('turbolinks:load', function() {
|
||||
if ($('body.admins-sub-disciplines-index-page').length > 0) {
|
||||
$(document).on('turbolinks:load', function () {
|
||||
if ($('body.admins-sub-disciplines-index-page').length > 0) {
|
||||
|
||||
// ============== 新建 ===============
|
||||
var $modal = $('.modal.admin-create-sub-discipline-modal');
|
||||
var $form = $modal.find('form.admin-create-sub-discipline-form');
|
||||
var $nameInput = $form.find('input[name="name"]');
|
||||
// ============== 新建 ===============
|
||||
var $modal = $('.modal.admin-create-sub-discipline-modal');
|
||||
var $form = $modal.find('form.admin-create-sub-discipline-form');
|
||||
var $nameInput = $form.find('input[name="name"]');
|
||||
|
||||
$form.validate({
|
||||
errorElement: 'span',
|
||||
errorClass: 'danger text-danger',
|
||||
rules: {
|
||||
name: {
|
||||
required: true
|
||||
}
|
||||
}
|
||||
});
|
||||
$form.validate({
|
||||
errorElement: 'span',
|
||||
errorClass: 'danger text-danger',
|
||||
rules: {
|
||||
name: {
|
||||
required: true
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// modal ready fire
|
||||
$modal.on('show.bs.modal', function () {
|
||||
$nameInput.val('');
|
||||
});
|
||||
// modal ready fire
|
||||
$modal.on('show.bs.modal', function () {
|
||||
$nameInput.val('');
|
||||
});
|
||||
|
||||
$modal.on('click', '.submit-btn', function(){
|
||||
$form.find('.error').html('');
|
||||
$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;
|
||||
}
|
||||
});
|
||||
|
||||
if ($form.valid()) {
|
||||
var url = $form.data('url');
|
||||
function submit_create_form() {
|
||||
$form.find('.error').html('');
|
||||
|
||||
$.ajax({
|
||||
method: 'POST',
|
||||
dataType: 'json',
|
||||
url: url,
|
||||
data: $form.serialize(),
|
||||
success: function(){
|
||||
$.notify({ message: '创建成功' });
|
||||
$modal.modal('hide');
|
||||
if ($form.valid()) {
|
||||
var url = $form.data('url');
|
||||
|
||||
setTimeout(function(){
|
||||
window.location.reload();
|
||||
}, 500);
|
||||
},
|
||||
error: function(res){
|
||||
var data = res.responseJSON;
|
||||
$form.find('.error').html(data.message);
|
||||
}
|
||||
$.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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
$(".sub-discipline-list-container").on("change", '.sub-discipline-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/sub_disciplines/" + s_id,
|
||||
type: "PUT",
|
||||
dataType: 'script',
|
||||
data: json
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
// ------------ 上移/下移 -------------
|
||||
$('.sub-discipline-list-container').on('click', ".move-action", function () {
|
||||
var $doAction = $(this);
|
||||
|
||||
$(".sub-discipline-list-container").on("change", '.sub-discipline-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/sub_disciplines/" + s_id,
|
||||
type: "PUT",
|
||||
dataType:'script',
|
||||
data: json
|
||||
});
|
||||
});
|
||||
}
|
||||
var objectId = $doAction.data('id');
|
||||
var opr = $doAction.data('opr');
|
||||
$.ajax({
|
||||
url: '/admins/sub_disciplines/' + objectId + '/adjust_position',
|
||||
method: 'POST',
|
||||
dataType: 'script',
|
||||
data: {opr: opr}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
@ -0,0 +1,65 @@
|
||||
$(document).on('turbolinks:load', function() {
|
||||
if ($('body.admins-sub-repertoires-index-page').length > 0) {
|
||||
|
||||
// ============== 新建 ===============
|
||||
var $modal = $('.modal.admin-create-sub-repertoire-modal');
|
||||
var $form = $modal.find('form.admin-create-sub-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);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$(".sub-repertoire-list-container").on("change", '.sub-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/sub_repertoires/" + s_id,
|
||||
type: "PUT",
|
||||
dataType:'script',
|
||||
data: json
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
@ -0,0 +1,72 @@
|
||||
$(document).on('turbolinks:load', function () {
|
||||
if ($('body.admins-subject-settings-index-page').length > 0) {
|
||||
var $form = $('.subject-setting-list-form');
|
||||
|
||||
// ************** 学校选择 *************
|
||||
$form.find('.school-select').select2({
|
||||
theme: 'bootstrap4',
|
||||
placeholder: '请选择创建者单位',
|
||||
minimumInputLength: 1,
|
||||
ajax: {
|
||||
delay: 500,
|
||||
url: '/api/schools/search.json',
|
||||
dataType: 'json',
|
||||
data: function (params) {
|
||||
return {keyword: params.term};
|
||||
},
|
||||
processResults: function (data) {
|
||||
return {results: data.schools}
|
||||
}
|
||||
},
|
||||
templateResult: function (item) {
|
||||
if (!item.id || item.id === '') return item.text;
|
||||
return item.name;
|
||||
},
|
||||
templateSelection: function (item) {
|
||||
if (item.id) {
|
||||
}
|
||||
return item.name || item.text;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
$(".subject-setting-list-container").on("change", '.subject-setting-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/subject_settings/" + s_id,
|
||||
type: "PUT",
|
||||
dataType:'script',
|
||||
data: json
|
||||
})
|
||||
});
|
||||
|
||||
// 清空
|
||||
$form.on('click', '.clear-btn', function () {
|
||||
$form.find('select[name="status"]').val('');
|
||||
$form.find('.school-select').val('').trigger('change');
|
||||
$form.find('input[name="keyword"]').val('');
|
||||
$form.find('#homepage_show').attr('checked', false);
|
||||
$form.find('#excellent').attr('checked', false);
|
||||
$form.find('input[type="submit"]').trigger('click');
|
||||
});
|
||||
|
||||
// 上传图片
|
||||
$('.modal.admin-upload-file-modal').on('upload:success', function (e, data) {
|
||||
if(data.suffix == '_qrcode'){
|
||||
var $imageElement = $('.subject-weapp-image-' + data.source_id);
|
||||
$imageElement.attr('src', data.url);
|
||||
$imageElement.show();
|
||||
$imageElement.next().html('重新上传');
|
||||
} else {
|
||||
var $imageElement = $('.subject-image-' + data.source_id);
|
||||
$imageElement.attr('src', data.url);
|
||||
$imageElement.show();
|
||||
$imageElement.next().html('重新上传');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
@ -1,65 +1,90 @@
|
||||
$(document).on('turbolinks:load', function() {
|
||||
if ($('body.admins-tag-disciplines-index-page').length > 0) {
|
||||
$(document).on('turbolinks:load', function () {
|
||||
if ($('body.admins-tag-disciplines-index-page').length > 0) {
|
||||
|
||||
// ============== 新建 ===============
|
||||
var $modal = $('.modal.admin-create-tag-discipline-modal');
|
||||
var $form = $modal.find('form.admin-create-tag-discipline-form');
|
||||
var $nameInput = $form.find('input[name="name"]');
|
||||
// ============== 新建 ===============
|
||||
var $modal = $('.modal.admin-create-tag-discipline-modal');
|
||||
var $form = $modal.find('form.admin-create-tag-discipline-form');
|
||||
var $nameInput = $form.find('input[name="name"]');
|
||||
|
||||
$form.validate({
|
||||
errorElement: 'span',
|
||||
errorClass: 'danger text-danger',
|
||||
rules: {
|
||||
name: {
|
||||
required: true
|
||||
}
|
||||
}
|
||||
});
|
||||
$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', submit_create_form);
|
||||
|
||||
// modal ready fire
|
||||
$modal.on('show.bs.modal', function () {
|
||||
$nameInput.val('');
|
||||
});
|
||||
$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('');
|
||||
|
||||
$modal.on('click', '.submit-btn', function(){
|
||||
$form.find('.error').html('');
|
||||
if ($form.valid()) {
|
||||
var url = $form.data('url');
|
||||
|
||||
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');
|
||||
|
||||
$.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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
setTimeout(function(){
|
||||
window.location.reload();
|
||||
}, 500);
|
||||
},
|
||||
error: function(res){
|
||||
var data = res.responseJSON;
|
||||
$form.find('.error').html(data.message);
|
||||
}
|
||||
$(".tag-discipline-list-container").on("change", '.tag-discipline-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_disciplines/" + s_id,
|
||||
type: "PUT",
|
||||
dataType: 'script',
|
||||
data: json
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$(".tag-discipline-list-container").on("change", '.tag-discipline-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_disciplines/" + s_id,
|
||||
type: "PUT",
|
||||
dataType:'script',
|
||||
data: json
|
||||
});
|
||||
});
|
||||
}
|
||||
// ------------ 上移/下移 -------------
|
||||
$('.tag-discipline-list-container').on('click', ".move-action", function () {
|
||||
var $doAction = $(this);
|
||||
|
||||
var objectId = $doAction.data('id');
|
||||
var opr = $doAction.data('opr');
|
||||
$.ajax({
|
||||
url: '/admins/tag_disciplines/' + objectId + '/adjust_position',
|
||||
method: 'POST',
|
||||
dataType: 'script',
|
||||
data: {opr: opr}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
@ -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,36 @@
|
||||
class Admins::RepertoiresController < Admins::BaseController
|
||||
|
||||
def index
|
||||
@repertoires = Repertoire.all
|
||||
end
|
||||
|
||||
def edit
|
||||
@repertoire = current_repertoire
|
||||
end
|
||||
|
||||
def update
|
||||
Rails.logger.info("#################--------")
|
||||
if params[:repertoire] && params[:repertoire][:name].present?
|
||||
name = params[:repertoire][:name].to_s.strip
|
||||
current_repertoire.update_attributes!(name: name)
|
||||
end
|
||||
@repertoires = Repertoire.all
|
||||
end
|
||||
|
||||
def create
|
||||
name = params[:name].to_s.strip
|
||||
return render_error('名称重复') if Repertoire.where(name: name).exists?
|
||||
Repertoire.create!(name: name)
|
||||
render_ok
|
||||
end
|
||||
|
||||
def destroy
|
||||
@repertoire_id = params[:id]
|
||||
current_repertoire.destroy!
|
||||
end
|
||||
|
||||
private
|
||||
def current_repertoire
|
||||
@_current_repertoire = Repertoire.find params[:id]
|
||||
end
|
||||
end
|
@ -0,0 +1,35 @@
|
||||
class Admins::SalesmanChannelsController < Admins::BaseController
|
||||
before_action :set_salesman
|
||||
|
||||
def index
|
||||
@channels = @salesman.salesman_channels
|
||||
if params[:keyword].present?
|
||||
@channels = @channels.joins(:school).where("schools.name like ?", "%#{params[:keyword]}%")
|
||||
end
|
||||
@start_time = params[:start_date]
|
||||
@end_time = params[:end_date].blank? ? Time.now : params[:end_date]
|
||||
end
|
||||
|
||||
def batch_add
|
||||
channel_ids = @salesman.salesman_channels.pluck(:school_id)
|
||||
school_ids = params[:school_ids] - channel_ids
|
||||
school_ids.each do |school_id|
|
||||
school = School.find_by(id: school_id)
|
||||
next if school.blank? || @salesman.salesman_channels.where(school_id: school.id).exists?
|
||||
@salesman.salesman_channels.create!(school_id: school.id)
|
||||
end
|
||||
render_ok
|
||||
rescue Exception => ex
|
||||
render_error(ex.message)
|
||||
end
|
||||
|
||||
def destroy
|
||||
@salesman.salesman_channels.find_by!(id: params[:id]).destroy
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_salesman
|
||||
@salesman = Salesman.find params[:salesman_id]
|
||||
end
|
||||
end
|
@ -0,0 +1,28 @@
|
||||
class Admins::SalesmanCustomersController < Admins::BaseController
|
||||
before_action :set_salesman
|
||||
|
||||
def index
|
||||
@customers = @salesman.salesman_customers.includes(:user, :school)
|
||||
end
|
||||
|
||||
def batch_add
|
||||
customer_ids = @salesman.salesman_customers.pluck(:user_id)
|
||||
user_ids = params[:user_ids] - customer_ids
|
||||
user_ids.each do |user_id|
|
||||
user = UserExtension.find_by(user_id: user_id)
|
||||
next if user.blank? || @salesman.salesman_customers.where(user_id: user.user_id).exists?
|
||||
@salesman.salesman_customers.create!(user_id: user.user_id, school_id: user.school_id)
|
||||
end
|
||||
render_ok
|
||||
end
|
||||
|
||||
def destroy
|
||||
@salesman.salesman_customers.find_by!(id: params[:id]).destroy
|
||||
end
|
||||
|
||||
private
|
||||
def set_salesman
|
||||
@salesman = Salesman.find params[:salesman_id]
|
||||
end
|
||||
|
||||
end
|
@ -0,0 +1,29 @@
|
||||
class Admins::SalesmansController < Admins::BaseController
|
||||
before_action :set_salesman, except: [:index, :batch_add]
|
||||
|
||||
def index
|
||||
@salesmans = Salesman.all
|
||||
end
|
||||
|
||||
def destroy
|
||||
@salesman.destroy!
|
||||
end
|
||||
|
||||
# 批量增加销售人员
|
||||
def batch_add
|
||||
salesman_user_ids = Salesman.where(id: params[:user_ids]).pluck(:user_id)
|
||||
user_ids = params[:user_ids] - salesman_user_ids
|
||||
user_ids.each do |user_id|
|
||||
user = User.find_by(id: user_id)
|
||||
next if user.blank?
|
||||
Salesman.create!(user_id: user.id, name: user.real_name)
|
||||
end
|
||||
render_ok
|
||||
end
|
||||
|
||||
private
|
||||
def set_salesman
|
||||
@salesman = Salesman.find params[:id]
|
||||
end
|
||||
|
||||
end
|
@ -0,0 +1,45 @@
|
||||
class Admins::SubRepertoiresController < Admins::BaseController
|
||||
|
||||
def index
|
||||
@repertoire = current_repertoire
|
||||
@sub_repertoires = current_repertoire.sub_repertoires
|
||||
end
|
||||
|
||||
def create
|
||||
name = params[:name].to_s.strip
|
||||
return render_error('名称重复') if current_repertoire.sub_repertoires.where(name: name).exists?
|
||||
SubRepertoire.create!(name: name, repertoire_id: current_repertoire.id)
|
||||
render_ok
|
||||
end
|
||||
|
||||
def edit
|
||||
@sub_repertoire = current_sub_repertoire
|
||||
end
|
||||
|
||||
def update
|
||||
if params[:sub_repertoire] && params[:sub_repertoire][:name].present?
|
||||
name = params[:sub_repertoire][:name].to_s.strip
|
||||
current_sub_repertoire.update_attributes!(name: name)
|
||||
end
|
||||
@sub_repertoires = current_sub_repertoire.repertoire&.sub_repertoires
|
||||
end
|
||||
|
||||
def destroy
|
||||
@sub_repertoire_id = params[:id]
|
||||
current_sub_repertoire.destroy!
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def current_sub_repertoire
|
||||
@_current_sub_repertoire = SubRepertoire.find params[:id]
|
||||
end
|
||||
|
||||
def current_repertoire
|
||||
@_current_repertoire = Repertoire.find params[:repertoire_id]
|
||||
end
|
||||
|
||||
def setting_params
|
||||
params.permit(:shixun, :subject, :question)
|
||||
end
|
||||
end
|
@ -0,0 +1,34 @@
|
||||
class Admins::SubjectSettingsController < Admins::BaseController
|
||||
def index
|
||||
default_sort('created_at', 'desc')
|
||||
|
||||
subjects = Admins::SubjectQuery.call(params)
|
||||
@sub_disciplines = SubDiscipline.where(subject: 1).pluck(:name,:id)
|
||||
@subjects = paginate subjects.includes(:repertoire, :subject_level_system, :sub_disciplines)
|
||||
end
|
||||
|
||||
def update
|
||||
sub_discipline_ids = params[:sub_disciplines] || []
|
||||
sub_ids = sub_discipline_ids.reject(&:blank?).map(&:to_i)
|
||||
old_sub_ids = current_subject.sub_discipline_containers.pluck(:sub_discipline_id)
|
||||
new_ids = sub_ids - old_sub_ids
|
||||
delete_ids = old_sub_ids - sub_ids
|
||||
sub_params = new_ids.map{|sub| {sub_discipline_id: sub}}
|
||||
ActiveRecord::Base.transaction do
|
||||
current_subject.sub_discipline_containers.where(sub_discipline_id: delete_ids).destroy_all
|
||||
current_subject.sub_discipline_containers.create!(sub_params)
|
||||
end
|
||||
end
|
||||
|
||||
def update_mobile_show
|
||||
subject = Subject.find(params[:subject_id])
|
||||
subject.update_attributes(:show_mobile => params[:show_mobile])
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def current_subject
|
||||
@_current_subject ||= Subject.find(params[:id])
|
||||
end
|
||||
|
||||
end
|
@ -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
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,69 @@
|
||||
class LiveLinksController < ApplicationController
|
||||
before_action :require_login
|
||||
before_action :find_course, only: [:index, :create]
|
||||
before_action :user_course_identity, :teacher_allowed, only: [:create]
|
||||
before_action :edit_auth, only: [:edit, :update]
|
||||
before_action :delete_auth, only: [:destroy]
|
||||
|
||||
def index
|
||||
lives = @course.live_links
|
||||
order_str = "on_status desc, live_time desc"
|
||||
@total_count = lives.size
|
||||
@my_live_id = @course.live_links.find_by(user_id: current_user.id)&.id
|
||||
# order_str = "live_links.id = #{@my_live_id} desc, #{order_str}" if @my_live_id.present?
|
||||
lives = lives.order("#{order_str}")
|
||||
@lives = paginate lives.includes(user: :user_extension)
|
||||
end
|
||||
|
||||
def create
|
||||
on_status = params[:live_time].present? && params[:live_time].to_time <= Time.now ? 1 : 0
|
||||
@course.live_links.create!(create_params.merge(user_id: current_user.id, on_status: on_status))
|
||||
render_ok
|
||||
end
|
||||
|
||||
def edit
|
||||
@live = current_live
|
||||
end
|
||||
|
||||
def update
|
||||
if params[:on_status]
|
||||
tip_exception("请勿重复开启") if current_live.on_status && params[:on_status].to_i == 1
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
current_live.update!(on_status: params[:on_status])
|
||||
|
||||
# 开启时发送消息,关闭直播时删除对应的消息
|
||||
if params[:on_status].to_i == 1
|
||||
LivePublishJob.perform_later(current_live.id)
|
||||
end
|
||||
end
|
||||
else
|
||||
on_status = params[:live_time].present? && params[:live_time].to_time <= Time.now ? 1 : 0
|
||||
current_live.update!(create_params.merge(on_status: on_status))
|
||||
end
|
||||
render_ok
|
||||
end
|
||||
|
||||
def destroy
|
||||
current_live.destroy!
|
||||
render_ok
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def create_params
|
||||
params.permit(:url, :description, :course_name, :platform, :live_time, :duration)
|
||||
end
|
||||
|
||||
def current_live
|
||||
@_current_live = LiveLink.find params[:id]
|
||||
end
|
||||
|
||||
def edit_auth
|
||||
tip_exception(403, "无权限操作") unless current_user.id == current_live.user_id || current_user.admin_or_business?
|
||||
end
|
||||
|
||||
def delete_auth
|
||||
tip_exception(403, "无权限操作") unless current_user.id == current_live.user_id || current_user.admin?
|
||||
end
|
||||
end
|
@ -0,0 +1,13 @@
|
||||
class Oauth::CasController < Oauth::BaseController
|
||||
def create
|
||||
user, is_new_user = Oauth::CreateORFindCasUserService.call(current_user, auth_hash)
|
||||
successful_authentication(user)
|
||||
|
||||
redirect_to root_url
|
||||
end
|
||||
|
||||
|
||||
def auth_hash
|
||||
JSON.parse(CGI.unescape(request.env['omniauth.auth'].extra.to_json))
|
||||
end
|
||||
end
|
@ -1,11 +1,32 @@
|
||||
class Oauth::WechatController < Oauth::BaseController
|
||||
def create
|
||||
user, new_user = Oauth::CreateOrFindWechatAccountService.call(current_user ,params)
|
||||
# user, new_user = Oauth::CreateOrFindWechatAccountService.call(current_user ,params)
|
||||
|
||||
successful_authentication(user)
|
||||
begin
|
||||
code = params['code'].to_s.strip
|
||||
tip_exception("code不能为空") if code.blank?
|
||||
new_user = false
|
||||
|
||||
render_ok(new_user: new_user)
|
||||
rescue Oauth::CreateOrFindWechatAccountService::Error => ex
|
||||
render_error(ex.message)
|
||||
result = WechatOauth::Service.access_token(code)
|
||||
result = WechatOauth::Service.user_info(result['access_token'], result['openid'])
|
||||
|
||||
# 存在该用户
|
||||
open_user = OpenUsers::Wechat.find_by(uid: result['unionid'])
|
||||
if open_user.present? && open_user.user.present?
|
||||
successful_authentication(open_user.user)
|
||||
else
|
||||
if current_user.blank? || !current_user.logged?
|
||||
new_user = true
|
||||
set_session_openid(result['openid'])
|
||||
set_session_unionid(result['unionid'])
|
||||
else
|
||||
OpenUsers::Wechat.create!(user: current_user, uid: result['unionid'])
|
||||
end
|
||||
end
|
||||
|
||||
render_ok(new_user: new_user)
|
||||
rescue WechatOauth::Error => ex
|
||||
render_error(ex.message)
|
||||
end
|
||||
end
|
||||
end
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,26 @@
|
||||
class Weapps::ChallengesController < Weapps::BaseController
|
||||
before_action :require_login
|
||||
before_action :set_challenge
|
||||
|
||||
def is_play
|
||||
# 关卡有展示效果 || 选择题 || jupyter实训 || vnc || 隐藏代码窗口 || html+css实训
|
||||
# @challenge.show_type != -1 || @challenge.st == 1 || @shixun.is_jupyter? || @shixun.vnc ||
|
||||
# @shixun.hide_code? || (@shixun.small_mirror_name & ["Css", "Html", "Web"]).present?
|
||||
play = @shixun.is_jupyter? || @shixun.vnc ||
|
||||
@shixun.hide_code? || (@shixun.small_mirror_name & ["Css", "Html", "Web"]).present?
|
||||
|
||||
if play
|
||||
normal_status(-5, "该关卡暂不支持小程序")
|
||||
else
|
||||
render_ok
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
def set_challenge
|
||||
@challenge = Challenge.find_by!(id: params[:id])
|
||||
@shixun = @challenge.shixun
|
||||
end
|
||||
|
||||
end
|
@ -0,0 +1,14 @@
|
||||
class Weapps::ShixunListsController < ApplicationController
|
||||
|
||||
def index
|
||||
results = Weapps::ShixunSearchService.call(search_params, current_laboratory)
|
||||
@total_count = results.size
|
||||
@results = paginate results
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def search_params
|
||||
params.permit(:keyword, :type, :page, :limit, :order, :status, :diff, :sort, :no_jupyter)
|
||||
end
|
||||
end
|
@ -0,0 +1,28 @@
|
||||
class Weapps::SubjectsController < Weapps::BaseController
|
||||
before_action :require_login, except: [:index, :show]
|
||||
before_action :find_subject, except: [:index]
|
||||
|
||||
# 首页
|
||||
def index
|
||||
subjects = Weapps::SubjectQuery.call(current_laboratory, params)
|
||||
@subject_count = subjects.map(&:id).size
|
||||
@subjects = paginate subjects
|
||||
end
|
||||
|
||||
# 详情
|
||||
def show
|
||||
# 合作团队
|
||||
Rails.logger.info("##########subject: #{@subject.id}")
|
||||
@members = @subject.subject_members.includes(:user)
|
||||
shixuns = @subject.shixuns.published.pluck(:id)
|
||||
challenge_ids = Challenge.where(shixun_id: shixuns).pluck(:id)
|
||||
# 实训路径中的所有实训标签
|
||||
@tags = ChallengeTag.where(challenge_id: challenge_ids).pluck(:name).uniq
|
||||
end
|
||||
|
||||
private
|
||||
def find_subject
|
||||
@subject = Subject.find(params[:id])
|
||||
end
|
||||
|
||||
end
|
@ -0,0 +1,16 @@
|
||||
class Weapps::UnbindAccountsController < Weapps::BaseController
|
||||
before_action :require_login
|
||||
|
||||
def show
|
||||
@user = current_user
|
||||
end
|
||||
|
||||
def destroy
|
||||
open_user = OpenUsers::Wechat.find_by!(user_id: current_user.id)
|
||||
session[:unionid] = open_user.uid
|
||||
open_user.destroy!
|
||||
UserAction.create(action_id: current_user.id, action_type: "UnbindWechat", user_id: current_user.id, :ip => request.remote_ip)
|
||||
logout_user
|
||||
render_ok
|
||||
end
|
||||
end
|
@ -1,11 +1,22 @@
|
||||
module Admins::SubjectsHelper
|
||||
def display_subject_status(subject)
|
||||
style =
|
||||
case subject.status
|
||||
case subject.public
|
||||
when 0 then 'text-secondary'
|
||||
when 1 then 'text-warning'
|
||||
when 2 then 'text-success'
|
||||
end
|
||||
raw content_tag(:span, t("subject.status.#{subject.status}"), class: style)
|
||||
|
||||
status =
|
||||
if subject.public == 2
|
||||
"publiced"
|
||||
elsif subject.public == 1
|
||||
"pending"
|
||||
elsif subject.status == 2
|
||||
"processed"
|
||||
else
|
||||
"editing"
|
||||
end
|
||||
raw content_tag(:span, t("subject.public.#{status}"), class: style)
|
||||
end
|
||||
end
|
@ -0,0 +1,13 @@
|
||||
# 删除课堂时将相应的课堂消息置为删除状态,并给老师发送删除消息
|
||||
class DeleteCourseNotifyJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
def perform(course_id, user_id)
|
||||
course = Course.find_by(id: course_id)
|
||||
return if course.blank?
|
||||
|
||||
Tiding.where(belong_container: course).update_all(is_delete: 1)
|
||||
Tiding.create!(user_id: user_id, trigger_user_id: user_id, container_id: course.id,
|
||||
container_type: 'DeleteCourse', tiding_type: 'System', belong_container: course, extra: course.name)
|
||||
end
|
||||
end
|
@ -0,0 +1,27 @@
|
||||
# 直播开启的消息通知
|
||||
class LivePublishJob < ApplicationJob
|
||||
queue_as :notify
|
||||
|
||||
def perform(live_id)
|
||||
live = LiveLink.find_by(id: live_id)
|
||||
return if live.blank? || live.course.blank?
|
||||
course = live.course
|
||||
|
||||
attrs = %i[
|
||||
user_id trigger_user_id container_id container_type parent_container_id parent_container_type
|
||||
belong_container_id belong_container_type viewed tiding_type created_at updated_at
|
||||
]
|
||||
|
||||
same_attrs = {
|
||||
trigger_user_id: live.user_id, container_id: live.id, container_type: 'LiveLink',
|
||||
parent_container_id: live.id, parent_container_type: 'LiveLink',
|
||||
belong_container_id: live.course_id, belong_container_type: 'Course',
|
||||
viewed: 0, tiding_type: 'LiveLink'
|
||||
}
|
||||
Tiding.bulk_insert(*attrs) do |worker|
|
||||
course.students.pluck(:user_id).each do |user_id|
|
||||
worker.add same_attrs.merge(user_id: user_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,4 @@
|
||||
class CourseVideo < ApplicationRecord
|
||||
belongs_to :course
|
||||
belongs_to :video
|
||||
end
|
@ -1,7 +1,12 @@
|
||||
class Discipline < ApplicationRecord
|
||||
has_many :sub_disciplines, dependent: :destroy
|
||||
default_scope { order(position: :asc) }
|
||||
|
||||
has_many :sub_disciplines, -> { order("sub_disciplines.position ASC") }, dependent: :destroy
|
||||
|
||||
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
|
||||
|
@ -1,3 +1,4 @@
|
||||
class HackCode < ApplicationRecord
|
||||
# 编程题代码相关
|
||||
belongs_to :hack
|
||||
end
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue