-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from luizpicolo/issue#17
Adding gallery
- Loading branch information
Showing
20 changed files
with
290 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
app/assets/javascripts/rails_admin/helpers/action_sortable.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// sortable to relational | ||
function activeSortable() { | ||
$('.cb-relational__list').sortable({ | ||
revert: true, | ||
placeholder: 'ui-sortable-placeholder', | ||
handle: '.cb-relational__btn--move', | ||
cursor: 'move', | ||
}); | ||
|
||
$('.cb-gallery').sortable({ | ||
revert: true, | ||
placeholder: 'ui-sortable-placeholder--gallery', | ||
handle: '.cb-gallery__btn--move', | ||
cursor: 'move', | ||
}); | ||
} |
9 changes: 9 additions & 0 deletions
9
app/assets/javascripts/rails_admin/helpers/add_event_to_input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// add event on input file | ||
function addEventToInputFile(id) { | ||
$('#' + id).on('change', fileSelectAndUpload); | ||
} | ||
|
||
// add event on input file | ||
function addEventToInputFileGallery(id) { | ||
$('#' + id).on('change', fileSelectAndUploadGallery); | ||
} |
28 changes: 28 additions & 0 deletions
28
app/assets/javascripts/rails_admin/helpers/autocomplete.js.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
function autocomplete(id) { | ||
$('#' + id + ' input:text').autocomplete({ | ||
source: "search_content", | ||
minLength: 5, | ||
select: function(event, ui) { | ||
section_id = generateID(); | ||
|
||
element = '<li id="'+ section_id +'" class="cb-relational__item">'; | ||
element += '<a href="/noticias/' + ui.item.content_builder_category.slug + '/' + ui.item.slug + '" class="cb-relational__link" target="blank"></a>'; | ||
element += '<h2 class="cb-relational__caption cb-editable">'+ ui.item.title +'</h2>'; | ||
element += '<div class="cb-tools">'; | ||
element += '<a class="cb-tools__btn cb-tools__btn--small cb-relational__btn--move fa fa-arrows" href="#"></a>'; | ||
element += '<a class="cb-tools__btn cb-tools__btn--small cb-tools__btn--delete fa fa-trash" href="#'+ section_id +'"></a>'; | ||
element += '</div>'; | ||
element += '</li>'; | ||
|
||
$("#" + id + ' ol').append(element); | ||
activeMediumEditor(); | ||
activeSortable(); | ||
|
||
return false; | ||
} | ||
}).autocomplete("instance")._renderItem = function(ul, item) { | ||
return $( "<li>" ) | ||
.append( "<a>" + item.title + "</a>" ) | ||
.appendTo( ul ); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
app/assets/javascripts/rails_admin/helpers/file_select_and_upload.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// upload file via ajax | ||
function fileSelectAndUpload(evt) { | ||
//console.log(evt); | ||
var file = evt.target.files[0]; | ||
|
||
if(file) { | ||
var formData = new FormData(); | ||
formData.append('content_builder_image', file); | ||
|
||
$.ajax({ | ||
url: 'create_images', | ||
data: formData, | ||
cache: false, | ||
contentType: false, | ||
processData: false, | ||
type: 'PUT', | ||
beforeSend: function() { | ||
$('#' + evt.target.id).find('figure').append('<div class="cb-loading"></div>'); | ||
$('.cb-tools--center').addClass('cb-tools--disabled'); | ||
}, | ||
complete: function(){ | ||
$('.cb-loading').remove(); | ||
$('.cb-tools--center').removeClass('cb-tools--disabled'); | ||
} | ||
}).done(function(e) { | ||
var p = evt.target.getAttribute('data-position'); | ||
$('#' + evt.target.id).find('img').attr('src', getImageOfPosition(p, e)); | ||
}).fail(function(e) { | ||
alert('error: ' + e); | ||
}); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
app/assets/javascripts/rails_admin/helpers/file_select_and_upload_gallery.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Upload Gallery | ||
function fileSelectAndUploadGallery(evt) { | ||
//console.log(evt); | ||
var files = evt.target.files; | ||
|
||
for (i = 0; i < files.length; ++i) { | ||
var formData = new FormData(); | ||
formData.append('content_builder_image', files[i]); | ||
|
||
$.ajax({ | ||
url: 'create_images', | ||
data: formData, | ||
cache: false, | ||
contentType: false, | ||
processData: false, | ||
type: 'PUT', | ||
beforeSend: function() { | ||
$('#' + evt.target.id).find('figure').append('<div class="cb-loading"></div>'); | ||
$('.cb-tools--center').addClass('cb-tools--disabled'); | ||
}, | ||
complete: function(){ | ||
$('.cb-loading').remove(); | ||
$('.cb-tools--center').removeClass('cb-tools--disabled'); | ||
} | ||
}).done(function(e) { | ||
var p = evt.target.getAttribute('data-position'); | ||
id = generateID(); | ||
|
||
element = '<div class="cb-gallery__item" id="'+ id + '">'; | ||
element += '<div class="cb-tools cb-tools--center">'; | ||
element += '<a class="cb-tools__btn cb-gallery__btn--move fa fa-arrows" href="#"></a>'; | ||
element += '<a class="cb-tools__btn cb-tools__btn--delete fa fa-trash" href="#'+ id + '"></a>'; | ||
element += '</div>'; | ||
element += '<figure class="cb-gallery__figure">'; | ||
element += '<img class="cb-tools__image" src="'+ getImageOfPosition(p, e) +'">'; | ||
element += '</figure>'; | ||
element += '</div>'; | ||
|
||
$('#' + evt.target.id + ' .cb-gallery').append(element); | ||
}).fail(function(e) { | ||
alert('error: ' + e); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// generate random id | ||
function generateID() { | ||
return '_' + Math.random().toString(36).substr(2, 9); | ||
} |
11 changes: 11 additions & 0 deletions
11
app/assets/javascripts/rails_admin/helpers/get_image_of_position.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// get image of position | ||
function getImageOfPosition(position, e) { | ||
switch(position) { | ||
case 'left': | ||
case 'right': | ||
return e.image.left_or_right.url; | ||
|
||
case 'center': | ||
return e.image.center.url; | ||
} | ||
} |
Oops, something went wrong.