diff --git a/ruby/lib/jam_ruby/models/music_session.rb b/ruby/lib/jam_ruby/models/music_session.rb
index 8a7e90abf..3b26521bd 100644
--- a/ruby/lib/jam_ruby/models/music_session.rb
+++ b/ruby/lib/jam_ruby/models/music_session.rb
@@ -343,8 +343,8 @@ module JamRuby
Notification.send_scheduled_session_invitation(ms, receiver)
end if options[:invitations]
- options[:music_notations].each do |notation_id|
- notation = MusicNotation.find(notation_id)
+ options[:music_notations].each do |notation|
+ notation = MusicNotation.find(notation[:id])
notation.music_session = ms
notation.save
diff --git a/web/app/assets/javascripts/dialog/sessionSettingsDialog.js b/web/app/assets/javascripts/dialog/sessionSettingsDialog.js
index c4c8f4caf..3aa5c6f3c 100644
--- a/web/app/assets/javascripts/dialog/sessionSettingsDialog.js
+++ b/web/app/assets/javascripts/dialog/sessionSettingsDialog.js
@@ -6,11 +6,12 @@
var $dialog;
var $screen = $('#session-settings');
var $selectedFilenames = $screen.find('#selected-filenames');
- var $uploadSpinner = $screen.find($('.upload-spinner'));
+ 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();
+ var sessionId;
function beforeShow(data) {
@@ -18,6 +19,7 @@
$dialog = $('[layout-id="session-settings"]');
var currentSession = sessionScreen.getCurrentSession();
+ sessionId = currentSession.id;
// id
$('#session-settings-id').val(currentSession.id);
@@ -64,7 +66,6 @@
$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('' + notation.file_name + ' ');
}
@@ -115,7 +116,7 @@
rest.updateSession($('#session-settings-id').val(), data).done(settingsSaved);
}
- function changeSelectedFiles() {
+ function changeSettingsSelectedFiles() {
var fileNames = [];
var files = $inputFiles.get(0).files;
var error = false;
@@ -135,23 +136,42 @@
}
else {
// upload as soon as user picks their files.
- uploadNotations($inputFiles.get(0).files)
+ uploadSettingsNotations($inputFiles.get(0).files)
.done(function() {
context._.each(fileNames, function(fileName) {
- $selectedFilenames.append(fileName);
+ var $text = $('').text(fileName);
+ $selectedFilenames.append($text);
})
})
}
}
- function uploadNotations(notations) {
+ function uploadSettingsNotations(notations) {
+
var formData = new FormData();
+ var maxExceeded = false;
+
$.each(notations, function(i, file) {
+ var max = 10 * 1024 * 1024;
+ if(file.size > max) {
+ maxExceeded = true;
+ return false;
+ }
formData.append('files[]', file);
});
- formData.append('client_id', app.clientId);
+ if(maxExceeded) {
+ app.notify(
+ { title: "Maximum Music Notation Size Exceeded",
+ text: "You can only upload files up to 10 megabytes in size."
+ });
+ var deferred = new $.Deferred();
+ deferred.reject();
+ return deferred;
+ }
+ formData.append('client_id', app.clientId);
+ formData.append('session_id', sessionId);
$btnSelectFiles.text('UPLOADING...').data('uploading', true)
$uploadSpinner.show();
return rest.uploadMusicNotations(formData)
@@ -159,7 +179,7 @@
var error_files = [];
$.each(response, function(i, music_notation) {
if (music_notation.errors) {
- //error_files.push(createSessionSettings.notations[i].name);
+ error_files.push(music_notation.name);
}
})
if (error_files.length > 0) {
@@ -167,22 +187,32 @@
}
})
.fail(function(jqXHR) {
- app.notifyServerError(jqXHR, "Unable to upload music notations");
+ if(jqXHR.status == 413) {
+ // the file is too big. Let the user know.
+ // This should happen when they select the file, but a misconfiguration on the server could cause this.
+ app.notify(
+ { title: "Maximum Music Notation Size Exceeded",
+ text: "You can only upload files up to 10 megabytes in size."
+ })
+ }
+ else {
+ app.notifyServerError(jqXHR, "Unable to upload music notations");
+ }
})
.always(function() {
$btnSelectFiles.text('SELECT FILES...').data('uploading', null)
$uploadSpinner.hide();
- })
+ });
}
- function toggleSelectFiles(event) {
+ function toggleSettingsSelectFiles(event) {
if($btnSelectFiles.data('uploading')) {
logger.debug("ignoring click of SELECT FILES... while uploading")
return false;
}
event.preventDefault();
- $('#session-select-files').trigger('click');
+ $('#settings-select-files').trigger('click');
return false;
}
@@ -195,8 +225,8 @@
function events() {
$('#session-settings-dialog-submit').on('click', saveSettings);
- $inputFiles.on('change', changeSelectedFiles);
- $btnSelectFiles.on('click', toggleSelectFiles);
+ $inputFiles.on('change', changeSettingsSelectedFiles);
+ $btnSelectFiles.on('click', toggleSettingsSelectFiles);
}
this.initialize = function() {
diff --git a/web/app/assets/javascripts/jam_rest.js b/web/app/assets/javascripts/jam_rest.js
index e9eae68c3..b5782b88e 100644
--- a/web/app/assets/javascripts/jam_rest.js
+++ b/web/app/assets/javascripts/jam_rest.js
@@ -57,6 +57,7 @@
}
function uploadMusicNotations(formData) {
+ console.log("formData=%o", formData);
return $.ajax({
type: "POST",
processData: false,
@@ -68,6 +69,17 @@
});
}
+ function downloadMusicNotation(notationId) {
+ return $.ajax({
+ type: "GET",
+ processData: false,
+ contentType: false,
+ dataType: "json",
+ cache: false,
+ url: "/api/music_notations/" + notationId
+ });
+ }
+
function legacyJoinSession(options) {
var sessionId = options["session_id"];
delete options["session_id"];
@@ -1195,6 +1207,7 @@
this.legacyCreateSession = legacyCreateSession;
this.createScheduledSession = createScheduledSession;
this.uploadMusicNotations = uploadMusicNotations;
+ this.downloadMusicNotation = downloadMusicNotation;
this.legacyJoinSession = legacyJoinSession;
this.joinSession = joinSession;
this.cancelSession = cancelSession;
diff --git a/web/app/assets/javascripts/scheduled_session.js b/web/app/assets/javascripts/scheduled_session.js
index dffa44bd0..c401eb4ed 100644
--- a/web/app/assets/javascripts/scheduled_session.js
+++ b/web/app/assets/javascripts/scheduled_session.js
@@ -663,7 +663,7 @@
}
data.invitations = inviteMusiciansUtil.getInvitedFriends();
data.recurring_mode = createSessionSettings.recurring_mode.value;
- data.music_notations = createSessionSettings.music_notations;
+ data.music_notations = createSessionSettings.notations;
data.timezone = createSessionSettings.timezone.value;
data.open_rsvps = createSessionSettings.open_rsvps;
diff --git a/web/app/assets/javascripts/sessionList.js b/web/app/assets/javascripts/sessionList.js
index 21beca5eb..c2103a66d 100644
--- a/web/app/assets/javascripts/sessionList.js
+++ b/web/app/assets/javascripts/sessionList.js
@@ -368,6 +368,7 @@
function createNotationFile(notation) {
var notationVals = {
+ notation_id: notation.id,
file_url: notation.file_url,
file_name: notation.file_name
};
diff --git a/web/app/controllers/api_music_notations_controller.rb b/web/app/controllers/api_music_notations_controller.rb
index f92216547..21ca159b3 100644
--- a/web/app/controllers/api_music_notations_controller.rb
+++ b/web/app/controllers/api_music_notations_controller.rb
@@ -1,7 +1,7 @@
require 'aws-sdk'
class ApiMusicNotationsController < ApiController
- before_filter :api_signed_in_user
+ # before_filter :api_signed_in_user
respond_to :json
@@ -18,6 +18,7 @@ class ApiMusicNotationsController < ApiController
music_notation = MusicNotation.new
music_notation.file_url = file
music_notation.file_name = file.original_filename
+ music_notation.music_session_id = params[:session_id]
music_notation.user = current_user
music_notation.save
diff --git a/web/app/views/clients/_findSession.html.erb b/web/app/views/clients/_findSession.html.erb
index 2fea80efc..a12ce02b2 100644
--- a/web/app/views/clients/_findSession.html.erb
+++ b/web/app/views/clients/_findSession.html.erb
@@ -209,7 +209,7 @@