You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.6 KiB
50 lines
1.6 KiB
5 years ago
|
$(document).on('turbolinks:load', function() {
|
||
|
if ($('body.admins-subjects-index-page').length > 0) {
|
||
|
var $form = $('.subject-list-form');
|
||
|
|
||
|
// ************** 学校选择 *************
|
||
|
$form.find('.school-select').select2({
|
||
|
theme: 'bootstrap4',
|
||
|
placeholder: '请选择创建者单位',
|
||
|
minimumInputLength: 1,
|
||
|
ajax: {
|
||
|
delay: 500,
|
||
|
url: '/api/schools/for_option.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;
|
||
|
}
|
||
|
});
|
||
|
|
||
|
// 清空
|
||
|
$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){
|
||
|
var $imageElement = $('.subject-image-' + data.source_id);
|
||
|
$imageElement.attr('src', data.url);
|
||
|
$imageElement.show();
|
||
|
$imageElement.next().html('重新上传');
|
||
|
})
|
||
|
}
|
||
|
});
|