VRFS-1672 music notation file upload work

This commit is contained in:
Brian Smith 2014-06-26 23:07:48 -04:00
parent 09364fc25b
commit eb30ee3391
5 changed files with 145 additions and 4 deletions

View File

@ -681,6 +681,10 @@ module JamRuby
music_session.approval_required
end
def music_notations
music_session.music_notations
end
def tick_track_changes
self.track_changes_counter += 1
self.save!(:validate => false)

View File

@ -4,6 +4,12 @@
context.JK.SessionSettingsDialog = function(app, sessionScreen) {
var logger = context.JK.logger;
var $dialog;
var $screen = $('#session-settings');
var $selectedFilenames = $screen.find('#selected-filenames');
var $uploadSpinner = $screen.find($('.upload-spinner'));
var $selectedFilenames = $('#settings-selected-filenames');
var $inputFiles = $('#settings-select-files');
var $btnSelectFiles = $screen.find('.btn-select-files');
var rest = new JK.Rest();
function beforeShow(data) {
@ -19,7 +25,6 @@
// genre
context.JK.GenreSelectorHelper.setSelectedGenres('#session-settings-genre', currentSession.genres);
// name
$('#session-settings-name').val(currentSession.name);
@ -56,7 +61,12 @@
}
// notation files
$selectedFilenames.empty();
for (var i=0; i < currentSession.music_notations.length; i++) {
var notation = currentSession.music_notations[i];
console.log('notation.file_name %o', notation.file_name);
$selectedFilenames.append('<a href="' + notation.file_url + '" rel="external">' + notation.file_name + '</a>&nbsp;');
}
context.JK.dropdown($('#session-settings-language'));
context.JK.dropdown($('#session-settings-musician-access'));
@ -105,6 +115,78 @@
rest.updateSession($('#session-settings-id').val(), data).done(settingsSaved);
}
function changeSelectedFiles() {
var fileNames = [];
var files = $inputFiles.get(0).files;
var error = false;
for (var i = 0; i < files.length; ++i) {
var name = files.item(i).name;
var ext = name.split('.').pop();
if ($.inArray(ext, ["pdf", "png", "jpg", "jpeg", "gif", "xml", "mxl", "txt"]) == -1) {
error = true;
break;
}
fileNames.push(name);
}
if (error) {
app.notifyAlert("Error", "We're sorry, but we do not allow upload of that file type. Please upload only the file types listed in the Upload dialog box.");
$inputFiles.replaceWith($inputFiles.clone(true));
}
else {
}
// upload as soon as user picks their files.
uploadNotations($inputFiles.get(0).files)
.done(function() {
context._.each(fileNames, function(fileName) {
$selectedFilenames.append(fileName);
})
})
}
function uploadNotations(notations) {
var formData = new FormData();
$.each(notations, function(i, file) {
formData.append('files[]', file);
});
formData.append('client_id', app.clientId);
$btnSelectFiles.text('UPLOADING...').data('uploading', true)
$uploadSpinner.show();
return rest.uploadMusicNotations(formData)
.done(function(response) {
var error_files = [];
$.each(response, function(i, music_notation) {
if (music_notation.errors) {
//error_files.push(createSessionSettings.notations[i].name);
}
})
if (error_files.length > 0) {
app.notifyAlert("Failed to upload notations.", error_files.join(', '));
}
})
.fail(function(jqXHR) {
app.notifyServerError(jqXHR, "Unable to upload music notations");
})
.always(function() {
$btnSelectFiles.text('SELECT FILES...').data('uploading', null)
$uploadSpinner.hide();
})
}
function toggleSelectFiles(event) {
if($btnSelectFiles.data('uploading')) {
logger.debug("ignoring click of SELECT FILES... while uploading")
return false;
}
event.preventDefault();
$('#session-select-files').trigger('click');
return false;
}
function settingsSaved(response) {
// No response returned from this call. 204.
sessionScreen.refreshCurrentSession(true);
@ -113,6 +195,9 @@
function events() {
$('#session-settings-dialog-submit').on('click', saveSettings);
$inputFiles.on('change', changeSelectedFiles);
$btnSelectFiles.on('click', toggleSelectFiles);
}
this.initialize = function() {

View File

@ -340,6 +340,41 @@ a.arrow-down {
width:200px;
}
.btn-select-files {
margin-top: 10px;
margin-left:0;
width:110px;
@include border_box_sizing;
}
.spinner-small.upload-spinner {
display:none;
position: absolute;
left: 0px;
margin-top: 4px;
}
.select-files-section {
position:absolute;
}
#settings-selected-filenames {
font-size:12px;
span {
white-space:nowrap;
text-overflow:ellipsis;
overflow:hidden;
display:block;
}
}
.selected-files-section {
overflow: hidden;
width: 100%;
@include border_box_sizing;
}
#session-controls {
width:100%;
padding:6px 0px 11px 0px;

View File

@ -19,6 +19,16 @@ else
[item.genre.description] # XXX: need to return single genre; not array
end
child(:music_notations => :music_notations) {
attributes :id, :file_name
node do |music_notation|
{ file_url: music_notation["file_url"] }
end
}
if :is_recording?
node do |music_session|
{ :recording => partial("api_recordings/show", :object => music_session.recording) }
@ -44,7 +54,6 @@ else
}
}
child({:invitations => :invitations}) {
attributes :id, :sender_id, :receiver_id
}

View File

@ -54,12 +54,20 @@
.clearall.left.w25.ib.mb10
Notation Files:
.right.w75.ib.mb10
List of existing notation files goes here
.w40.left
.selected-files-section
%div{:id => "settings-selected-filenames"}
.right.ib.mb10
%a.button-orange.btn-select-files SELECT FILES...
%input.hidden{:type => "file", :id => "settings-select-files", :value => "Select Files...", :accept => ".pdf, .png, .jpg, .jpeg, .gif, .xml, .mxl, .txt"}
.spinner-small.upload-spinner
.clearall.right.mt10
%a.button-orange{:href => 'TBD', :rel => 'external'} HELP
%a.button-grey{'layout-action' => "close"} CANCEL
%a.button-orange{:id => "session-settings-dialog-submit"} UPDATE SETTINGS
.clearall
%br/
%br{:clear => 'all'}/