Skip to content

Commit

Permalink
direct file uploads now possible
Browse files Browse the repository at this point in the history
  • Loading branch information
phirschybar committed Jun 2, 2016
1 parent 88fac00 commit 248e909
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 14 deletions.
Binary file modified public/img/file.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/file.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 30 additions & 12 deletions public/js/base.form.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,12 @@ $(document).ready(function() {
if($type[0]=='edit')
{
// update upload button
$('.trigger_img_upload').html('Upload Different File');
$('.trigger_img_upload').html('Uploaded! Choose Different File?');

//display image
var $parts = $('#target-'+$elem_name).attr('src').split('/station_thumbs_sm/');
$('#station-fileupload-hud').html('<img src="'+$parts[0]+'/station_thumbs_lg/'+$parts[1]+'">');
var src = $('#target-'+$elem_name).hasClass('for-file') ? '/packages/lifeboy/station/img/file.png' : $parts[0] + '/station_thumbs_lg/' + $parts[1];
$('#station-fileupload-hud').html('<img src="' + src + '">');

// loading text for controls
$('.station-file-options').html('<h5><span class="label label-primary">Loading...</span></h5>').show();
Expand Down Expand Up @@ -163,9 +164,19 @@ $(document).ready(function() {
var $elem_name = $(this).attr('name');
//console.log($elem_name);
var $img_hidden_val = $(this).val();
if($img_hidden_val!='')

if ($('#target-'+$elem_name).hasClass('for-file')){

var src = '/packages/lifeboy/station/img/file.png';

} else {

var src = 'http://'+$('#target-'+$elem_name).attr('bucket')+'.s3.amazonaws.com/station_thumbs_sm/'+$img_hidden_val;
}

if($img_hidden_val != '')
{
$('#target-'+$elem_name).attr('src','http://'+$('#target-'+$elem_name).attr('bucket')+'.s3.amazonaws.com/station_thumbs_sm/'+$img_hidden_val);
$('#target-'+$elem_name).attr('src', src);
$('#edit_for_' + $elem_name + ', #remove_for_' + $elem_name).show();
}
});
Expand Down Expand Up @@ -197,11 +208,12 @@ $(document).ready(function() {
if(typeof $results.file_uri!='undefined')
{
// we display the thumb
$('#station-fileupload-hud').html('<img src="'+$results.file_uri_stub+'station_thumbs_lg/'+$results.file_name+'">');

//populate sidebar info
var $elem_name = $('#mediaModal [name="upload_element_name"]').val();

var src = $('#target-' + $elem_name).hasClass('for-file') ? '/packages/lifeboy/station/img/file.png' : $results.file_uri_stub+'station_thumbs_lg/'+$results.file_name
$('#station-fileupload-hud').html('<img src="'+ src +'">');

//populate sidebar info
create_media_side_controls($results.file_uri_stub,$results.file_name,$elem_name);
$(this).remove();

Expand Down Expand Up @@ -230,7 +242,8 @@ $(document).ready(function() {

// we need the img filename and the uri
var $parts = $('#station-fileupload-hud').children(':first').attr('src').split('/station_thumbs_lg/');
$('#target-'+$elem_name).attr('src',$parts[0]+'/station_thumbs_sm/'+$parts[1]).show();
var src = $('#target-'+$elem_name).hasClass('for-file') ? '/packages/lifeboy/station/img/file.png' : $parts[0]+'/station_thumbs_sm/' + $parts[1];
$('#target-'+$elem_name).attr('src', src).show();

if ($('[name='+$elem_name+']').is('textarea')){ // using the embedder tool

Expand Down Expand Up @@ -407,7 +420,7 @@ $(document).ready(function() {
* for url fetching
*/
function disperse_fetched_url_parts(parts, element_name){

eval('var mapping = ' + $('.parsed-results[data-element="' + element_name + '"]').attr('data-mapping'));

$.each(mapping, function(index, val) {
Expand All @@ -424,11 +437,16 @@ $(document).ready(function() {
if (index == 'image'){

var thumbnail = $('.station-element-group[data-element-name="' + element_name + '"] .station-img-thumbnail');
var for_file = thumbnail.hasClass('for-file');

if (typeof parts.graph != 'undefined' && typeof parts.graph[index] != 'undefined') {
if (typeof parts.graph != 'undefined' && typeof parts.graph[index] != 'undefined' && !for_file) {

var src = 'http://' + thumbnail.attr('bucket') + '.s3.amazonaws.com/station_thumbs_sm/' + parts.graph[index];


} else if (typeof parts.graph != 'undefined' && typeof parts.graph[index] != 'undefined' && for_file) {

var src = '/packages/lifeboy/station/img/file.png';

} else {

var src = '/packages/lifeboy/station/img/missing.gif';
Expand Down Expand Up @@ -613,7 +631,7 @@ $(document).ready(function() {
+ '</div>\n';
}

$('.station-file-options').html($button_html);
$('.station-file-options').html($('#target-' + $elem_name).hasClass('for-file') ? '' : $button_html);

$('.btn-group.w-no-size .station-crop-start').remove();
//console.log($this_img_sizes);
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/StationFileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public function upload()

$success = TRUE;
$message = 'File sent to S3';
$preview_uri = '/public/packages/lifeboy/station/img/file.gif';
$preview_uri = '/public/packages/lifeboy/station/img/file.png';
$final_file_name = $new_file_name;
}

Expand Down
3 changes: 2 additions & 1 deletion src/views/partials/uploader.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<div class="station-file-upload-wrap row {{ $is_embedder ? 'snapped-to-textarea' : '' }}">
<?php $for_file = $element_info['type'] == 'file'; ?>
<div class="col-sm-2">
<img width="100px" height="100px" src="/packages/lifeboy/station/img/missing.gif" bucket="{{ $bucket_name }}" class="img-thumbnail station-img-thumbnail" id="target-{{ $original_el_name }}" data-target="{{ $original_el_name }}">
<img width="100px" height="100px" src="/packages/lifeboy/station/img/missing.gif" bucket="{{ $bucket_name }}" class="img-thumbnail station-img-thumbnail {{ $for_file ? 'for-file' : '' }}" id="target-{{ $original_el_name }}" data-target="{{ $original_el_name }}">
</div>
@if (isset($element_info['fetch_url']))
{{-- Special element which can fetch URLs --}}
Expand Down

0 comments on commit 248e909

Please sign in to comment.