Only show file templates which are available for the selected file type
This commit is contained in:
@ -148,6 +148,22 @@ $(function() {
|
||||
});
|
||||
};
|
||||
|
||||
var updateFileTemplates = function(fileType) {
|
||||
var jqxhr = $.ajax({
|
||||
url: '/file_templates/by_file_type/' + fileType + '.json',
|
||||
dataType: 'json'
|
||||
});
|
||||
jqxhr.done(function(response) {
|
||||
var noTemplateLabel = $('#noTemplateLabel').data('text');
|
||||
var options = "<option value>" + noTemplateLabel + "</option>";
|
||||
for (var i = 0; i < response.length; i++) {
|
||||
options += "<option value='" + response[i].id + "'>" + response[i].name + "</option>"
|
||||
}
|
||||
$("#code_ocean_file_file_template_id").find('option').remove().end().append($(options));
|
||||
});
|
||||
jqxhr.fail(ajaxError);
|
||||
}
|
||||
|
||||
if ($.isController('exercises')) {
|
||||
if ($('table').isPresent()) {
|
||||
enableBatchUpdate();
|
||||
@ -162,6 +178,10 @@ $(function() {
|
||||
inferFileAttributes();
|
||||
observeFileRoleChanges();
|
||||
overrideTextareaTabBehavior();
|
||||
} else if ($('#files.jstree').isPresent()) {
|
||||
var fileTypeSelect = $('#code_ocean_file_file_type_id');
|
||||
fileTypeSelect.on("change", function() {updateFileTemplates(fileTypeSelect.val())});
|
||||
updateFileTemplates(fileTypeSelect.val());
|
||||
}
|
||||
toggleCodeHeight();
|
||||
if (window.hljs) {
|
||||
|
@ -6,6 +6,14 @@ class FileTemplatesController < ApplicationController
|
||||
end
|
||||
private :authorize!
|
||||
|
||||
def by_file_type
|
||||
@file_templates = FileTemplate.where(:file_type_id => params[:file_type_id])
|
||||
authorize!
|
||||
respond_to do |format|
|
||||
format.json { render :show, status: :ok, json: @file_templates.to_json }
|
||||
end
|
||||
end
|
||||
|
||||
# GET /file_templates
|
||||
# GET /file_templates.json
|
||||
def index
|
||||
|
@ -4,4 +4,8 @@ class FileTemplatePolicy < AdminOnlyPolicy
|
||||
everyone
|
||||
end
|
||||
|
||||
def by_file_type?
|
||||
everyone
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -12,4 +12,5 @@
|
||||
= f.label(:file_template_id, t('activerecord.attributes.file.file_template_id'))
|
||||
= f.collection_select(:file_template_id, FileTemplate.all.order(:name), :id, :name, {:include_blank => true}, class: 'form-control')
|
||||
= f.hidden_field(:context_id)
|
||||
.hidden#noTemplateLabel data-text=t('file_template.no_template_label')
|
||||
.actions = render('shared/submit_button', f: f, object: CodeOcean::File.new)
|
||||
|
Reference in New Issue
Block a user