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 ($.isController('exercises')) {
|
||||||
if ($('table').isPresent()) {
|
if ($('table').isPresent()) {
|
||||||
enableBatchUpdate();
|
enableBatchUpdate();
|
||||||
@ -162,6 +178,10 @@ $(function() {
|
|||||||
inferFileAttributes();
|
inferFileAttributes();
|
||||||
observeFileRoleChanges();
|
observeFileRoleChanges();
|
||||||
overrideTextareaTabBehavior();
|
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();
|
toggleCodeHeight();
|
||||||
if (window.hljs) {
|
if (window.hljs) {
|
||||||
|
@ -6,6 +6,14 @@ class FileTemplatesController < ApplicationController
|
|||||||
end
|
end
|
||||||
private :authorize!
|
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
|
||||||
# GET /file_templates.json
|
# GET /file_templates.json
|
||||||
def index
|
def index
|
||||||
|
@ -4,4 +4,8 @@ class FileTemplatePolicy < AdminOnlyPolicy
|
|||||||
everyone
|
everyone
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def by_file_type?
|
||||||
|
everyone
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -12,4 +12,5 @@
|
|||||||
= f.label(:file_template_id, t('activerecord.attributes.file.file_template_id'))
|
= 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.collection_select(:file_template_id, FileTemplate.all.order(:name), :id, :name, {:include_blank => true}, class: 'form-control')
|
||||||
= f.hidden_field(:context_id)
|
= 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)
|
.actions = render('shared/submit_button', f: f, object: CodeOcean::File.new)
|
||||||
|
@ -432,3 +432,5 @@ de:
|
|||||||
next_label: 'Nächste Seite →'
|
next_label: 'Nächste Seite →'
|
||||||
page_gap: '…'
|
page_gap: '…'
|
||||||
previous_label: '← Vorherige Seite'
|
previous_label: '← Vorherige Seite'
|
||||||
|
file_template:
|
||||||
|
no_template_label: "Leere Datei"
|
||||||
|
@ -432,3 +432,5 @@ en:
|
|||||||
next_label: 'Next Page →'
|
next_label: 'Next Page →'
|
||||||
page_gap: '…'
|
page_gap: '…'
|
||||||
previous_label: '← Previous Page'
|
previous_label: '← Previous Page'
|
||||||
|
file_template:
|
||||||
|
no_template_label: "Empty File"
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
FILENAME_REGEXP = /[\w\.]+/ unless Kernel.const_defined?(:FILENAME_REGEXP)
|
FILENAME_REGEXP = /[\w\.]+/ unless Kernel.const_defined?(:FILENAME_REGEXP)
|
||||||
|
|
||||||
Rails.application.routes.draw do
|
Rails.application.routes.draw do
|
||||||
resources :file_templates
|
resources :file_templates do
|
||||||
|
collection do
|
||||||
|
get 'by_file_type/:file_type_id', as: :by_file_type, to: :by_file_type
|
||||||
|
end
|
||||||
|
end
|
||||||
resources :code_harbor_links
|
resources :code_harbor_links
|
||||||
resources :request_for_comments
|
resources :request_for_comments
|
||||||
get '/my_request_for_comments', as: 'my_request_for_comments', to: 'request_for_comments#get_my_comment_requests'
|
get '/my_request_for_comments', as: 'my_request_for_comments', to: 'request_for_comments#get_my_comment_requests'
|
||||||
|
Reference in New Issue
Block a user