Skip to content

Commit

Permalink
[spalenque] - #14328 * allow only one moderator per event
Browse files Browse the repository at this point in the history
  • Loading branch information
santipalenque committed Sep 6, 2018
1 parent ee863e3 commit d1a9eb2
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 50 deletions.
32 changes: 20 additions & 12 deletions summit/code/forms/AddSpeakerForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,24 @@ public function __construct($controller, $name, $presentation, $summit) {
protected function getFormFields() {
$presentation_type = $this->presentation->getTypeName();
$max_speakers_reached = $this->presentation->maxSpeakersReached();
$use_speakers = $this->presentation->Type()->UseSpeakers;
$speakers_exists = $this->presentation->Speakers()->exists();
$max_moderators_reached = $this->presentation->maxModeratorsReached();
$speaker_type = (!$max_moderators_reached) ? 'Moderator' : 'Speaker';
$use_moderator = $this->presentation->Type()->UseModerator;
$moderator_exists = $this->presentation->Moderator()->exists();
$speaker_type = ($use_moderator && (!$max_moderators_reached || !$use_speakers)) ? 'moderator' : 'speaker';

$fields = FieldList::create(
LiteralField::create('SpeakerNote',
'<p class="at-least-one">Each '.$presentation_type.' needs at least one speaker. You cannot submit your '.$presentation_type.' without a speaker. If you are speaking AND you are the '.$presentation_type.' owner, you still must add yourself as a speaker.</p>'),
'<p class="at-least-one">Each '.$presentation_type.' needs at least one '.$speaker_type.'. You cannot submit your '.$presentation_type.' without a '.$speaker_type.'. If you are speaking AND you are the '.$presentation_type.' owner, you still must add yourself as a '.$speaker_type.'.</p>'),
OptionsetField::create('SpeakerType', '', array(
'Me' => 'Add yourself as a '.$speaker_type.' to this '.$presentation_type,
'Else' => 'Add someone else'
))->setValue('Me'),
LiteralField::create('LegalMe', sprintf('
<div id="legal-me" style="display: none;">
<label>
'.$speaker_type.'s agree that OpenStack Foundation may record and publish their talks presented during the %s OpenStack Summit. If you submit a proposal on behalf of a speaker, you represent to OpenStack Foundation that you have the authority to submit the proposal on the speaker’s behalf and agree to the recording and publication of their presentation.
'.ucfirst($speaker_type).'s agree that OpenStack Foundation may record and publish their talks presented during the %s OpenStack Summit. If you submit a proposal on behalf of a '.$speaker_type.', you represent to OpenStack Foundation that you have the authority to submit the proposal on the '.$speaker_type.'’s behalf and agree to the recording and publication of their presentation.
</label>
</div>', $this->summit->Title)),
TextField::create('EmailAddress',
Expand All @@ -70,7 +74,7 @@ protected function getFormFields() {
LiteralField::create('LegalOther', sprintf('
<div id="legal-other" style="display: none;">
<label>
'.$speaker_type.'s agree that OpenStack Foundation may record and publish their talks presented during the %s OpenStack Summit. If you submit a proposal on behalf of a speaker, you represent to OpenStack Foundation that you have the authority to submit the proposal on the speaker’s behalf and agree to the recording and publication of their presentation.
'.ucfirst($speaker_type).'s agree that OpenStack Foundation may record and publish their talks presented during the %s OpenStack Summit. If you submit a proposal on behalf of a '.$speaker_type.', you represent to OpenStack Foundation that you have the authority to submit the proposal on the '.$speaker_type.'’s behalf and agree to the recording and publication of their presentation.
</label>
</div>', $this->summit->Title)
)
Expand All @@ -84,16 +88,16 @@ protected function getFormFields() {
->setDisplayLogicCriteria(null);
}

if ($this->presentation->Speakers()->exists() && $max_moderators_reached) {
if (!$max_speakers_reached) {
if ( (!$use_speakers || $speakers_exists) && (!$use_moderator || $moderator_exists) ) {
if ( ($use_speakers && !$max_speakers_reached) || ($use_moderator && !$max_moderators_reached) ) {
$fields->insertBefore(
LiteralField::create('MoreSpeakers', '<h3 class="more-speakers">Any more speakers to add?</h3>'),
LiteralField::create('MoreSpeakers', '<h3 class="more-speakers">Any more '.$speaker_type.'s to add?</h3>'),
'SpeakerNote'
);
$fields->removeField('SpeakerNote');
} else {
$fields->insertBefore(
LiteralField::create('LimitSpeakers', '<h3 class="limit-speakers">You have reached the maximum of speakers.</h3>'),
LiteralField::create('LimitSpeakers', '<h3 class="limit-speakers">You have reached the maximum of '.$speaker_type.'s.</h3>'),
'SpeakerNote'
);
$fields->removeField('SpeakerNote');
Expand All @@ -110,13 +114,17 @@ protected function getFormFields() {

protected function getFormActions($controller) {
$max_speakers_reached = $this->presentation->maxSpeakersReached();
$use_speakers = $this->presentation->Type()->UseSpeakers;
$speakers_exists = $this->presentation->Speakers()->exists();
$max_moderators_reached = $this->presentation->maxModeratorsReached();
$speaker_type = (!$max_moderators_reached) ? 'Moderator' : 'Speaker';
$use_moderator = $this->presentation->Type()->UseModerator;
$moderator_exists = $this->presentation->Moderator()->exists();
$speaker_type = ($use_moderator && (!$max_moderators_reached || !$use_speakers)) ? 'moderator' : 'speaker';
$actions = array();

if ($this->presentation->Speakers()->exists() && $max_moderators_reached) {
if (!$max_speakers_reached) {
$actions[] = FormAction::create('doAddSpeaker', '<i class="fa fa-plus fa-start"></i> Add another speaker');
if ( (!$use_speakers || $speakers_exists) && (!$use_moderator || $moderator_exists) ) {
if (($use_speakers && !$max_speakers_reached) || ($use_moderator && !$max_moderators_reached)) {
$actions[] = FormAction::create('doAddSpeaker', '<i class="fa fa-plus fa-start"></i> Add another '.$speaker_type);
}

$default_actions = $controller->createSaveActions('doFinishSpeaker', 3);
Expand Down
3 changes: 1 addition & 2 deletions summit/code/models/managers/PresentationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,7 @@ public function registerPresentationOn(ISummit $summit, Member $creator, array $
$presentation->SelectionPlanID = $selectionPlan->ID;
$presentation->CreatorID = $creator->ID;
$presentation->Progress = Presentation::PHASE_SUMMARY;
// add creator as speaker
$presentation->Speakers()->Add($speaker);

$presentation->write();

if(isset($data["PresentationLink"]))
Expand Down
76 changes: 40 additions & 36 deletions summit/javascript/AddSpeakerForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,47 @@
(function($) {
$(document).ready(function() {
var cache = {};
$( "#AddSpeakerForm_AddSpeakerForm_EmailAddress" ).autocomplete({
minLength: 2,
source: function( request, response ) {
var term = request.term;
if ( term in cache ) {
response( cache[ term ] );
return;

if ($( "#AddSpeakerForm_AddSpeakerForm_EmailAddress" ).length) {
$( "#AddSpeakerForm_AddSpeakerForm_EmailAddress" ).autocomplete({
minLength: 2,
source: function( request, response ) {
var term = request.term;
if ( term in cache ) {
response( cache[ term ] );
return;
}

$.getJSON(speaker_search_url, request, function( data, status, xhr ) {
cache[ term ] = data;
response( data );
});
},
select: function( event, ui ) {
$( "#AddSpeakerForm_AddSpeakerForm_EmailAddress" ).val(ui.item.name);
$( "#AddSpeakerForm_AddSpeakerForm_MemberId" ).val(ui.item.member_id );
$( "#AddSpeakerForm_AddSpeakerForm_SpeakerId" ).val(ui.item.speaker_id);
return false;
}

$.getJSON(speaker_search_url, request, function( data, status, xhr ) {
cache[ term ] = data;
response( data );
});
},
select: function( event, ui ) {
$( "#AddSpeakerForm_AddSpeakerForm_EmailAddress" ).val(ui.item.name);
$( "#AddSpeakerForm_AddSpeakerForm_MemberId" ).val(ui.item.member_id );
$( "#AddSpeakerForm_AddSpeakerForm_SpeakerId" ).val(ui.item.speaker_id);
return false;
}

}).data("ui-autocomplete")._renderItem = function(ul, item) {
// ul is the unordered suggestion list
// item is a object in the data object that was send to the response function
// after the JSON request
// We append a custom formatted list item to the suggestion list
var html = '<span><img width="50" height="50" src="'+item.pic+'"/>&nbsp;';

if( item.title != '')
html+= item.title +'&nbsp;-&nbsp;';

html += item.name +'&nbsp;('+item.email+')';

if(item.company != '')
html += '&nbsp;-&nbsp;' + item.company + '</span>';

return $("<li></li>").data("item.autocomplete", item).append(html).appendTo(ul);
};;
}).data("ui-autocomplete")._renderItem = function(ul, item) {
// ul is the unordered suggestion list
// item is a object in the data object that was send to the response function
// after the JSON request
// We append a custom formatted list item to the suggestion list
var html = '<span><img width="50" height="50" src="'+item.pic+'"/>&nbsp;';

if( item.title != '')
html+= item.title +'&nbsp;-&nbsp;';

html += item.name +'&nbsp;('+item.email+')';

if(item.company != '')
html += '&nbsp;-&nbsp;' + item.company + '</span>';

return $("<li></li>").data("item.autocomplete", item).append(html).appendTo(ul);
};
}

});
})(jQuery);

0 comments on commit d1a9eb2

Please sign in to comment.