From d4b467fd4217c8304038e1ddd4e0923b7feb41e2 Mon Sep 17 00:00:00 2001 From: Bert Owen Date: Sat, 14 Jun 2014 21:25:32 +0800 Subject: [PATCH] scheduled session - RSVP slot updated --- ruby/lib/jam_ruby/models/music_session.rb | 16 ++++++++++++++++ web/app/assets/javascripts/scheduled_session.js | 12 ++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/ruby/lib/jam_ruby/models/music_session.rb b/ruby/lib/jam_ruby/models/music_session.rb index 9024597b1..4b32114d7 100644 --- a/ruby/lib/jam_ruby/models/music_session.rb +++ b/ruby/lib/jam_ruby/models/music_session.rb @@ -255,6 +255,8 @@ module JamRuby unless ms.errors.any? ms.reload + rsvp_slot_ids = [] + self_rsvp_slot_ids = [] options[:rsvp_slots].each do |rs| rsvp = RsvpSlot.new rsvp.instrument = Instrument.find(rs[:instrument_id]) @@ -263,7 +265,21 @@ module JamRuby rsvp.save ms.rsvp_slots << rsvp + + if rs[:approved] + self_rsvp_slot_ids.push rsvp.id + else + rsvp_slot_ids.push rsvp.id + end end if options[:rsvp_slots] + RsvpRequest.create({session_id: ms.id, rsvp_slots: rsvp_slot_ids}, user) + rsvp_rq_ids = RsvpRequest.create({session_id: ms.id, rsvp_slots: self_rsvp_slot_ids}).map(&:id) + + self_rsvp_rq = [] + rsvp_rq_ids.each do |rsvp_rq| + self_rsvp_rq.push {request_slot_id: rsvp_rq, approved: true} + end + RsvpRequest.update({session_id: ms.id, rsvp_responses: self_rsvp_rq}) options[:invitations].each do |invite_id| invitation = Invitation.new diff --git a/web/app/assets/javascripts/scheduled_session.js b/web/app/assets/javascripts/scheduled_session.js index 87ea03731..e541d2b79 100644 --- a/web/app/assets/javascripts/scheduled_session.js +++ b/web/app/assets/javascripts/scheduled_session.js @@ -419,14 +419,14 @@ data.rsvp_slots = []; $.each(instrumentSelector.getSelectedInstruments(), function(index, instrument) { - data.rsvp_slots.push({instrument: instrument.id, proficiency_level: instrument.level}); + data.rsvp_slots.push({instrument: instrument.id, proficiency_level: instrument.level. approve: false}); }); - // var instruments_rsvp = []; - // $.each(instrumentRSVP.getSelectedInstruments(), function(index, instrument) { - // instruments_rsvp.push(instrument.name + ' (' + instrument.count + ') (' + instrument.level + ')'); - // }); - // $('#session-instruments-rsvp-disp').html(instruments_rsvp.join(', ')); + $.each(instrumentRSVP.getSelectedInstruments(), function(index, instrument) { + for (var i = 0; i < instrument.count; i++) { + data.rsvp_slots.push({instrument: instrument.id, proficiency_level: instruemnt.level, approve: true}); + } + }); } var tracks = context.JK.TrackHelpers.getUserTracks(context.jamClient);