Skip to content

Commit

Permalink
[spalenque] - #10736 - share buttons on event detail
Browse files Browse the repository at this point in the history
  • Loading branch information
santipalenque committed Mar 29, 2016
1 parent 05efcbc commit 1d972d2
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 14 deletions.
3 changes: 3 additions & 0 deletions sample._ss_environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@
define('PARSE_REST_KEY','');
define('PARSE_MASTER_KEY','');

//SOCIAL MEDIA
define('FB_APP_ID','');

global $_FILE_TO_URL_MAPPING;
$_FILE_TO_URL_MAPPING[''] = '';

26 changes: 26 additions & 0 deletions summit/code/interfaces/restfull_api/SummitAppScheduleApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ protected function authenticate() {
'PUT $EventID!' => 'addToSchedule',
'DELETE $EventID!' => 'removeFromSchedule',
'POST $EventID!/feedback' => 'addFeedback',
'POST /shareEmail' => 'shareEmail',
);

static $allowed_actions = array(
Expand All @@ -107,6 +108,7 @@ protected function authenticate() {
'addToSchedule',
'removeFromSchedule',
'addFeedback',
'shareEmail',
);

protected function getCacheKey(SS_HTTPRequest $request){
Expand Down Expand Up @@ -629,4 +631,28 @@ public function addFeedback(){
return $this->serverError();
}
}

/**
* @return SS_HTTPResponse
*/
public function shareEmail(){
try {


$data = $this->getJsonRequest();

if (!$data) return $this->serverError();

$this->schedule_manager->sendEmail($data);

}
catch(EntityValidationException $ex1){
SS_Log::log($ex1,SS_Log::WARN);
return $this->validationError($ex1->getMessages());
}
catch(Exception $ex){
SS_Log::log($ex,SS_Log::ERR);
return $this->serverError();
}
}
}
18 changes: 18 additions & 0 deletions summit/code/models/managers/ScheduleManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,22 @@ public function addFeedback($data)
});
}

/**
* @param $data
* @return mixed
*/
public function sendEmail($data)
{
return $this->tx_manager->transaction(function () use ( $data ) {

if (!$data['from'] || !$data['to']) {
throw new EntityValidationException('Please enter From and To email addresses.');
}

$email = EmailFactory::getInstance()->buildEmail($data['from'], $data['to'], $data['subject'], $data['body']);

return $email->send();
});
}

}
5 changes: 4 additions & 1 deletion summit/code/pages/SummitAppSchedPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ public function ViewEvent()

return $this->renderWith(
array('SummitAppEventPage', 'SummitPage', 'Page'),
array('Event' => $event, 'goback' => $goback));
array(
'Event' => $event,
'FB_APP_ID' => FB_APP_ID,
'goback' => $goback));
}

public function ViewSpeakerProfile()
Expand Down
4 changes: 4 additions & 0 deletions summit/css/summitapp-event.css
Original file line number Diff line number Diff line change
Expand Up @@ -342,3 +342,7 @@ a.profile-pic-wrapper {
background-repeat: no-repeat;
background-color: #fff;
}

.error {
color: red;
}
74 changes: 69 additions & 5 deletions summit/javascript/schedule/share-buttons.tag
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
<raw>
<span></span>
this.root.innerHTML = opts.content
</raw>

<share-buttons>

Expand Down Expand Up @@ -31,6 +27,46 @@
</span>
</div>

<div id="email-modal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Email</h4>
</div>
<div class="modal-body">
<form id="email-form">
<div class="form-group">
<label for="email-from">From:</label>
<input type="email" class="form-control" id="email-from" required>
</div>
<div class="form-group">
<label for="email-to">To:</label>
<input type="email" class="form-control" id="email-to" required>
</div>
<div class="form-group">
<label for="email-subject">Subject:</label>
<input type="text" class="form-control" id="email-subject" value="Fwd: { share_info.title}" >
</div>
<div class="form-group">
<label for="email-body">Body:</label>
<textarea id="email-body" class="form-control">
{ share_info.title }
&#13;&#10;
{ share_info.description }
&#13;&#10;&#13;&#10;
Check it out: { share_info.url }
</textarea>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" onclick={ sendEmail }>Send</button>
</div>
</div>
</div>
</div>

<script>

this.share_info = opts.share_info;
Expand All @@ -49,7 +85,35 @@
}

shareMail(e) {
console.log("share mail");
console.log('email');
$('#email-modal').modal('show');

$('#email-form').validate();
}

sendEmail() {
var url = 'api/v1/summits/6/schedule/shareEmail';
var request = {
from:$('#email-from').val(),
to:$('#email-to').val(),
subject:$('#email-subject').val(),
body:$('#email-body').val()
}

if (!$('#email-form').valid()) {
return false;
}

$.ajax({
type: 'POST',
url: url,
data: JSON.stringify(request),
contentType: "application/json; charset=utf-8",
success: function () {
$('#email-modal').modal('hide');
swal('Success');
}
});
}

window.fbAsyncInit = function() {
Expand Down
16 changes: 8 additions & 8 deletions summit/templates/Layout/SummitAppEventPage.ss
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@
<% end_if %>
<div class="share">
<script type="application/javascript">
var share_info =
{
url: "{$AbsoluteLink}event/{$Event.ID}",
title : "{$Event.Title.JS}",
description: "{$Event.ShortDescription().JS}",
image: "",
fb_app_id : "227356147446887",
};
var share_info =
{
url: "{$AbsoluteLink}event/{$Event.ID}",
title : "{$Event.Title.JS}",
description: "{$Event.ShortDescription().JS}",
image: "/themes/openstack/images/openstack-logo-full.png",
fb_app_id : {$FB_APP_ID},
};
</script>
<share-buttons share_info="{ share_info }"></share-buttons>
</div>
Expand Down

0 comments on commit 1d972d2

Please sign in to comment.