Display request for comments button if we are working on a non binary submission. Introduced needed data attributes for that and assigned them to the frame (instead of the editor). Data Attributes get updated by the CreateSubmissionCallback. Adjusted comment checks to also use the attributes of the frame.

This commit is contained in:
Ralf Teusner
2015-07-09 12:03:03 +02:00
parent a49ffc978b
commit 81d2d69d11
3 changed files with 22 additions and 6 deletions

View File

@ -125,12 +125,16 @@ $(function() {
}; };
var createSubmissionCallback = function(data){ var createSubmissionCallback = function(data){
// set all frames context types to submission
$('.frame').each(function(index, element) {
$(element).data('context-type', 'Submission');
});
// update the ids of the editors and reload the annotations // update the ids of the editors and reload the annotations
for (var i = 0; i < editors.length; i++) { for (var i = 0; i < editors.length; i++) {
// set the data attribute to submission // set the data attribute to submission
$(editors[i].container).data('context-type', 'Submission'); //$(editors[i].container).data('context-type', 'Submission');
var file_id_old = $(editors[i].container).data('file-id'); var file_id_old = $(editors[i].container).data('file-id');
@ -150,6 +154,8 @@ $(function() {
} }
setAnnotations(editors[i], $(editors[i].container).data('id')); setAnnotations(editors[i], $(editors[i].container).data('id'));
} }
// toggle button states (it might be the case that the request for comments button has to be enabled
toggleButtonStates();
}; };
@ -373,7 +379,8 @@ $(function() {
var target = e.domEvent.target; var target = e.domEvent.target;
// only allow comments on submissions, not on the template // only allow comments on submissions, not on the template
if ($(editor.container).data('context-type') != 'Submission') return; if(active_frame.data('context-type') != 'Submission') return;
//if ($(editor.container).data('context-type') != 'Submission') return;
if (target.className.indexOf("ace_gutter-cell") == -1) return; if (target.className.indexOf("ace_gutter-cell") == -1) return;
if (!editor.isFocused()) return; if (!editor.isFocused()) return;
if (e.clientX > 25 + target.getBoundingClientRect().left) return; if (e.clientX > 25 + target.getBoundingClientRect().left) return;
@ -573,6 +580,10 @@ $(function() {
$('#start-over').on('click', confirmReset); $('#start-over').on('click', confirmReset);
}; };
var isActiveFileBinary = function() {
return 'binary' in active_frame.data();
};
var isActiveFileExecutable = function() { var isActiveFileExecutable = function() {
return 'executable' in active_frame.data(); return 'executable' in active_frame.data();
}; };
@ -596,6 +607,10 @@ $(function() {
return isActiveFileRunnable() && running; return isActiveFileRunnable() && running;
}; };
var isActiveFileSubmission = function() {
return ['Submission'].includes(active_frame.data('contextType'));
};
var isActiveFileTestable = function() { var isActiveFileTestable = function() {
return isActiveFileExecutable() && ['teacher_defined_test', 'user_defined_test'].includes(active_frame.data('role')); return isActiveFileExecutable() && ['teacher_defined_test', 'user_defined_test'].includes(active_frame.data('role'));
}; };
@ -960,6 +975,7 @@ $(function() {
$('#run').toggle(isActiveFileRunnable() && !running); $('#run').toggle(isActiveFileRunnable() && !running);
$('#stop').toggle(isActiveFileStoppable()); $('#stop').toggle(isActiveFileStoppable());
$('#test').toggle(isActiveFileTestable()); $('#test').toggle(isActiveFileTestable());
$('#request-for-comments').toggle(isActiveFileSubmission() && !isActiveFileBinary());
}; };
var requestComments = function(e) { var requestComments = function(e) {

View File

@ -5,6 +5,6 @@ hr
= render('editor_button', classes: 'btn-block btn-primary btn-xs', data: {:'data-cause' => 'file'}, icon: 'fa fa-plus', id: 'create-file', label: t('exercises.editor.create_file')) = render('editor_button', classes: 'btn-block btn-primary btn-xs', data: {:'data-cause' => 'file'}, icon: 'fa fa-plus', id: 'create-file', label: t('exercises.editor.create_file'))
= render('editor_button', classes: 'btn-block btn-warning btn-xs', data: {:'data-cause' => 'file', :'data-message-confirm' => t('shared.confirm_destroy')}, icon: 'fa fa-times', id: 'destroy-file', label: t('exercises.editor.destroy_file')) = render('editor_button', classes: 'btn-block btn-warning btn-xs', data: {:'data-cause' => 'file', :'data-message-confirm' => t('shared.confirm_destroy')}, icon: 'fa fa-times', id: 'destroy-file', label: t('exercises.editor.destroy_file'))
= render('editor_button', classes: 'btn-block btn-primary btn-xs', icon: 'fa fa-download', id: 'download', label: t('exercises.editor.download')) = render('editor_button', classes: 'btn-block btn-primary btn-xs', icon: 'fa fa-download', id: 'download', label: t('exercises.editor.download'))
/= render('editor_button', classes: 'btn-block btn-primary btn-xs', icon: 'fa fa-bullhorn', id: 'request-for-comments', label: 'Request comments') = render('editor_button', classes: 'btn-block btn-primary btn-xs', icon: 'fa fa-bullhorn', id: 'request-for-comments', label: 'Request comments')
= render('shared/modal', id: 'modal-file', template: 'code_ocean/files/_form', title: t('exercises.editor.create_file')) = render('shared/modal', id: 'modal-file', template: 'code_ocean/files/_form', title: t('exercises.editor.create_file'))

View File

@ -1,4 +1,4 @@
.frame data-executable=file.file_type.executable? data-filename=file.name_with_extension data-renderable=file.file_type.renderable? data-role=file.role .frame data-executable=file.file_type.executable? data-filename=file.name_with_extension data-renderable=file.file_type.renderable? data-role=file.role data-binary=file.file_type.binary? data-context-type=file.context_type
- if file.file_type.binary? - if file.file_type.binary?
.binary-file data-file-id=file.ancestor_id .binary-file data-file-id=file.ancestor_id
- if file.file_type.renderable? - if file.file_type.renderable?
@ -12,4 +12,4 @@
= link_to(file.native_file.file.name_with_extension, file.native_file.url) = link_to(file.native_file.file.name_with_extension, file.native_file.url)
- else - else
.editor-content.hidden data-file-id=file.ancestor_id = file.content .editor-content.hidden data-file-id=file.ancestor_id = file.content
.editor data-file-id=file.ancestor_id data-indent-size=file.file_type.indent_size data-mode=file.file_type.editor_mode data-read-only=file.read_only data-id=file.id data-context-type=file.context_type .editor data-file-id=file.ancestor_id data-indent-size=file.file_type.indent_size data-mode=file.file_type.editor_mode data-read-only=file.read_only data-id=file.id