diff --git a/ruby/lib/jam_ruby/models/music_session.rb b/ruby/lib/jam_ruby/models/music_session.rb index 91f71075a..553486183 100644 --- a/ruby/lib/jam_ruby/models/music_session.rb +++ b/ruby/lib/jam_ruby/models/music_session.rb @@ -228,6 +228,7 @@ module JamRuby current_time = Time.now query = MusicSession.where("music_sessions.user_id = '#{user.id}'") query = query.where("music_sessions.scheduled_start IS NOT NULL AND music_sessions.scheduled_start < '#{current_time + 12.hours}'") + query = query.where("music_sessions.scheduled_start > '#{current_time - 12.hours}'") query = query.where("music_session_id IS NULL") query = query.order("music_sessions.scheduled_start ASC") @@ -248,8 +249,8 @@ module JamRuby ms.band = band ms.legal_policy = options[:legal_policy] ms.language = options[:language] - ms.scheduled_start = options[:start] if options[:start] - ms.timezone = options[:timezone] + ms.scheduled_start = options[:start] + ms.scheduled_duration = options[:duration].to_i * 1.minutes if options[:duration] ms.recurring_mode = options[:recurring_mode] if options[:recurring_mode] ms.legal_terms = true ms.creator = user @@ -259,33 +260,24 @@ 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]) - # rsvp.proficiency_level = rs[:proficiency_level] - # rsvp.music_session = ms - # rsvp.save + rsvp_slot_ids = [] + self_rsvp_slot_ids = [] + options[:rsvp_slots].each do |rs| + rsvp = RsvpSlot.new + rsvp.instrument = Instrument.find(rs[:instrument_id]) + rsvp.proficiency_level = rs[:proficiency_level] + rsvp.music_session = ms + rsvp.save - # ms.rsvp_slots << rsvp + ms.rsvp_slots << rsvp - # if !rs[:approve].nil? && rs[:approve] == true - # self_rsvp_slot_ids.push rsvp.id - # else - # rsvp_slot_ids.push rsvp.id - # end - # end if options[:rsvp_slots] - # rsvp_rq_ids = RsvpRequest.create({session_id: ms.id, rsvp_slots: self_rsvp_slot_ids}, user).map(&:id) - - # self_rsvp_rq = [] - # rsvp_rq_ids.each do |rsvp_rq| - # r = Hash.new - # r[:request_slot_id] = rsvp_rq - # r[:approved] = true - # self_rsvp_rq.push r - # end - # RsvpRequest.update({session_id: ms.id, rsvp_responses: self_rsvp_rq}) + if !rs[:approve].nil? && rs[:approve] == true + 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: self_rsvp_slot_ids, :autoapprove => true}, user).map(&:id) options[:invitations].each do |invite_id| invitation = Invitation.new @@ -297,7 +289,7 @@ module JamRuby ms.invitations << invitation - Notification.send_session_invitation(receiver, user, ms.id) + Notification.send_scheduled_session_invitation(ms, receiver) end if options[:invitations] options[:music_notations].each do |notation_id| @@ -417,6 +409,18 @@ module JamRuby end end + def get_timezone + tz = nil + if timezone.blank? + tz = ActiveSupport::TimeZone["Central Time (US & Canada)"] + self.timezone = tz.name + ',' + tz.tzinfo.name + else + tz = ActiveSupport::TimeZone[self.timezone.split(',')[0]] + end + + tz + end + def scheduled_start_time unless self.scheduled_start.nil? self.scheduled_start.to_s @@ -426,15 +430,7 @@ module JamRuby end def timezone_description - tz = nil - if timezone.blank? - tz = ActiveSupport::TimeZone["Central Time (US & Canada)"] - self.timezone = tz.name + ',' + tz.tzinfo.name - else - tz = ActiveSupport::TimeZone[self.timezone.split(',')[0]] - end - - tz.to_s + self.get_timezone.to_s end def musician_access_description diff --git a/web/app/assets/javascripts/confirm.js b/web/app/assets/javascripts/confirm.js index d032e803c..c643eb098 100644 --- a/web/app/assets/javascripts/confirm.js +++ b/web/app/assets/javascripts/confirm.js @@ -11,7 +11,6 @@ $('#btn-confirm-ok').unbind("click"); $('#btn-confirm-ok').click(function(evt) { if (callback) { - $.holdReady(true); callback(); } }); diff --git a/web/app/assets/javascripts/instrumentSelector.js b/web/app/assets/javascripts/instrumentSelector.js index f983ab20d..240218f59 100644 --- a/web/app/assets/javascripts/instrumentSelector.js +++ b/web/app/assets/javascripts/instrumentSelector.js @@ -41,7 +41,9 @@ }); } - function render(parentSelector) { + function render(parentSelector, userInstruments) { + userInstruments = typeof userInstruments !== 'undefined' ? userInstruments : []; + _parentSelector = parentSelector; $(parentSelector).empty(); var template = null; @@ -51,10 +53,36 @@ else { template = $('#template-instrument-option').html(); } - $.each(_instruments, function (index, value) { + + var userInstrumentList = []; + $.each(userInstruments, function(index) { + userInstrumentList.push({ + id: 'instrument-false-' + this.instrument_id.replace(' ', '-'), + value: this.instrument_id, + label: this.description, + level: this.level + }); + }); + + $.each(userInstrumentList, function (index, value) { var instrumentOptionHtml = context.JK.fillTemplate(template, value); $(_parentSelector).append(instrumentOptionHtml); }); + + setSelectedInstruments(userInstrumentList); + + $.each(_instruments, function(index, instrument) { + var isRendered = false; + $.each(userInstrumentList, function(index, userInstrument) { + if (instrument.value == userInstrument.value) { + isRendered = true; + } + }) + if (!isRendered) { + var instrumentOptionHtml = context.JK.fillTemplate(template, instrument); + $(_parentSelector).append(instrumentOptionHtml); + } + }) } function getSelectedInstruments() { @@ -82,7 +110,7 @@ } $.each(instrumentList, function (index, value) { - $('input[type=checkbox][session-instrument-id="' + value.id + '"]') + $('input[type=checkbox][id="' + value.id + '"]') .attr('checked', 'checked') .iCheck({ checkboxClass: 'icheckbox_minimal', @@ -90,11 +118,11 @@ inheritClass: true }); if (_rsvp) { - $('select[session-instrument-id="' + value.id + '"].rsvp-count', _parentSelector).val(value.count); - $('select[session-instrument-id="' + value.id + '"].rsvp-level', _parentSelector).val(value.level); + $('select[session-instrument-id="' + value.value + '"].rsvp-count', _parentSelector).val(value.count); + $('select[session-instrument-id="' + value.value + '"].rsvp-level', _parentSelector).val(value.level); } else { - $('select[session-instrument-id="' + value.id + '"]').val(value.level); + $('select[session-instrument-id="' + value.value + '"]').val(value.level); } }); } diff --git a/web/app/assets/javascripts/scheduled_session.js b/web/app/assets/javascripts/scheduled_session.js index 7f00141aa..2d0249e4c 100644 --- a/web/app/assets/javascripts/scheduled_session.js +++ b/web/app/assets/javascripts/scheduled_session.js @@ -48,6 +48,9 @@ var STEP_SELECT_POLICY = 3; var STEP_SELECT_CONFIRM = 4; + var ONE_HOUR = 3600 * 1000; + var ONE_MINUTE = 60 * 1000; + var defaultTimeArray = ["12:00 AM", "12:30 AM", "01:00 AM", "01:30 AM", "02:00 AM", "02:30 AM", "03:00 AM", "03:30 AM", "04:00 AM", "04:30 AM", "05:00 AM", "05:30 AM", "06:00 AM", "06:30 AM", "07:00 AM", "07:30 AM", "08:00 AM", "08:30 AM", "09:00 AM", "09:30 AM", "10:00 AM", "10:30 AM", @@ -56,6 +59,12 @@ "07:00 PM", "07:30 PM", "08:00 PM", "08:30 PM", "09:00 PM", "09:30 PM", "10:00 PM", "10:30 PM", "11:00 PM", "11:30 PM"]; + var proficiencyDescriptionMap = { + "1": "Beginner", + "2": "Intermediate", + "3": "Expert" + }; + function afterLoadScheduledSessions(sessionList) { $scheduledSessions.empty(); @@ -73,7 +82,7 @@ }); context._.each(sessionList, function (session) { - session.scheduled_start = (new Date(session.scheduled_start)).toDateString() + + session.scheduled_start = new Date(session.scheduled_start).toDateString() + ', ' + getFormattedTime(new Date(session.scheduled_start), false); var options = { id: session.id, @@ -114,11 +123,38 @@ $('#edit_scheduled_sessions').show(); } + function afterLoadUserDetail(userDetail) { + var userInstruments = []; + $.each(userDetail.instruments, function(index, userInstrument) { + userInstrument.level = proficiencyDescriptionMap[userInstrument.proficiency_level]; + userInstruments.push(userInstrument); + }) + + instrumentSelector.render('#instrument-select-list', userInstruments); + instrumentRSVP.render('#instrument-select-rsvp-list'); + + $("#instrument-select-list").iCheck({ + checkboxClass: 'icheckbox_minimal', + radioClass: 'iradio_minimal', + inheritClass: true + }); + + $("#instrument-select-rsvp-list").iCheck({ + checkboxClass: 'icheckbox_minimal', + radioClass: 'iradio_minimal', + inheritClass: true + }); + } + function beforeShowStep1() { rest.findScheduledSessions({}) .done(afterLoadScheduledSessions) .fail(app.ajaxError); + rest.getUserDetail() + .done(afterLoadUserDetail) + .fail(app.ajaxError); + createSessionSettings.startDate = createSessionSettings.startDate || (new Date().toDateString()); $("#session-start-date").val(createSessionSettings.startDate); @@ -192,17 +228,22 @@ } $('#session-invited-disp').html(sessionInvitedString); - var instruments_me = []; - $.each(instrumentSelector.getSelectedInstruments(), function(index, instrument) { - instruments_me.push(instrument.name); - }); - $('#session-instruments-me-disp').html(instruments_me.join(', ')); + if (createSessionSettings.createType == 'start-scheduled') { - 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(', ')); + } + else { + var instruments_me = []; + $.each(instrumentSelector.getSelectedInstruments(), function(index, instrument) { + instruments_me.push(instrument.name); + }); + $('#session-instruments-me-disp').html(instruments_me.join(', ')); + + 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(', ')); + } $('#session-musician-access-disp').html('Musicians: ' + createSessionSettings.musician_access.label); $('#session-fans-access-disp').html('Fans: ' + createSessionSettings.fans_access.label); @@ -213,21 +254,43 @@ function beforeMoveStep1() { if (createSessionSettings.createType == 'start-scheduled') { var session = scheduledSessions[createSessionSettings.selectedSessionId]; - createSessionSettings.startDate = new Date(session.scheduled_start_time).toDateString(); - createSessionSettings.startTime = getFormattedTime(new Date(session.scheduled_start), false); - createSessionSettings.genresValues = session.genres; - createSessionSettings.genres = [session.genre_id]; - createSessionSettings.timezone.label = session.timezone_description; - createSessionSettings.timezone.value = session.timezone; - createSessionSettings.name = session.name; - createSessionSettings.description = session.description; - createSessionSettings.notations = session.music_notations; - createSessionSettings.language.label = session.language_description; - createSessionSettings.language.value = session.language; - createSessionSettings.session_policy = session.legal_policy; - createSessionSettings.musician_access.label = session.musician_access_description; - createSessionSettings.fans_access.label = session.fan_access_description; - createSessionSettings.recurring_mode.value = session.recurring_mode; + + var moveToFinish = function() { + app.layout.closeDialog('confirm'); + createSessionSettings.startDate = new Date(session.scheduled_start).toDateString(); + createSessionSettings.startTime = getFormattedTime(new Date(session.scheduled_start), false); + createSessionSettings.genresValues = session.genres; + createSessionSettings.genres = [session.genre_id]; + createSessionSettings.timezone.label = session.timezone_description; + createSessionSettings.timezone.value = session.timezone; + createSessionSettings.name = session.name; + createSessionSettings.description = session.description; + createSessionSettings.notations = session.music_notations; + createSessionSettings.language.label = session.language_description; + createSessionSettings.language.value = session.language; + createSessionSettings.session_policy = session.legal_policy; + createSessionSettings.musician_access.label = session.musician_access_description; + createSessionSettings.fans_access.label = session.fan_access_description; + createSessionSettings.recurring_mode.value = session.recurring_mode; + + step = STEP_SELECT_CONFIRM; + moveToStep(); + } + + var currentTime = new Date(); + var startTime = new Date(session.scheduled_start_time); + var diffTime = startTime.getTime() - currentTime.getTime(); + if (diffTime > ONE_HOUR) { + var confirmDialog = new context.JK.ConfirmDialog(app, "Start Session Now", + "You are starting a session that is scheduled to begin more than one hour from now. Are you sure you want to do this?", + "Future Session", moveToFinish); + confirmDialog.initialize(); + context.JK.app.layout.showDialog('confirm'); + } + else { + moveToFinish(); + } + return false; } else if (createSessionSettings.createType == 'quick-start') { createSessionSettings.genresValues = ['Pop']; @@ -409,13 +472,20 @@ data.language = createSessionSettings.language.value; if (createSessionSettings.createType == 'quick-start' || createSessionSettings.createType == 'immediately') { data.start = new Date().toDateString() + ' ' + getFormattedTime(new Date(), false); + data.duration = "30"; + } + else if (createSessionSettings.createType == 'rsvp') { + data.start = ""; data.duration = "0"; } else { data.start = createSessionSettings.startDate + ' ' + createSessionSettings.startTime; + var endDate = new Date(createSessionSettings.startDate + ' ' + createSessionSettings.endTime); + data.duration = (endDate - new Date(data.start)) / ONE_MINUTE; } data.invitations = inviteMusiciansUtil.getInvitedFriends(); data.recurring_mode = createSessionSettings.recurring_mode.value; data.music_notations = createSessionSettings.music_notations; + data.timezone = createSessionSettings.timezone.value; data.rsvp_slots = []; $.each(instrumentSelector.getSelectedInstruments(), function(index, instrument) { @@ -426,15 +496,15 @@ data.rsvp_slots.push(slot); }); - // $.each(instrumentRSVP.getSelectedInstruments(), function(index, instrument) { - // for (var i = 0; i < instrument.count; i++) { - // var slot = {}; - // slot.instrument_id = instrument.id; - // slot.proficiency_level = instrument.level; - // slot.approve = true; - // data.rsvp_slots.push(slot); - // } - // }); + $.each(instrumentRSVP.getSelectedInstruments(), function(index, instrument) { + for (var i = 0; i < instrument.count; i++) { + var slot = {}; + slot.instrument_id = instrument.id; + slot.proficiency_level = instrument.level; + slot.approve = true; + data.rsvp_slots.push(slot); + } + }); } var tracks = context.JK.TrackHelpers.getUserTracks(context.jamClient); @@ -937,8 +1007,6 @@ instrumentSelector = instrumentSelectorInstance; instrumentRSVP = instrumentRSVPSelectorInstance; - instrumentSelector.render('#instrument-select-list'); - instrumentRSVP.render('#instrument-select-rsvp-list'); var screenBindings = {'beforeShow': beforeShow, 'afterShow': afterShow}; app.bindScreen('createSession', screenBindings); diff --git a/web/app/assets/stylesheets/client/createSession.css.scss b/web/app/assets/stylesheets/client/createSession.css.scss index c8d77960f..8fda6a729 100644 --- a/web/app/assets/stylesheets/client/createSession.css.scss +++ b/web/app/assets/stylesheets/client/createSession.css.scss @@ -124,7 +124,7 @@ height: 310px; .session-instrumentlist { padding: 10px; - height: 55px; + height: 65px; background-color: #c5c5c5; border: none; -webkit-box-shadow: inset 2px 2px 3px 0px #888; diff --git a/web/app/views/clients/_confirm.html.erb b/web/app/views/clients/_confirm.html.erb index 3212b293f..29f08a088 100644 --- a/web/app/views/clients/_confirm.html.erb +++ b/web/app/views/clients/_confirm.html.erb @@ -1,5 +1,5 @@ -