Skip to content

Commit

Permalink
more ajax improvements, especially for gallery
Browse files Browse the repository at this point in the history
  • Loading branch information
Yim Hyun authored and Yim Hyun committed Oct 23, 2016
1 parent 4e9082f commit d3186d9
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 115 deletions.
98 changes: 66 additions & 32 deletions public/assets/js/lasso.js
Original file line number Diff line number Diff line change
Expand Up @@ -12685,21 +12685,11 @@ function EditusFormatAJAXErrorMessage(jqXHR, exception) {
});

function editus_gallery_swap(galleryID){
var data = {
action: 'process_gallery_swap',
gallery_id: galleryID,
nonce: lasso_editor.swapGallNonce
}

$.post( lasso_editor.ajaxurl, data, function(response) {
if( true == response.success ) {
// window.component is the current component being edited
window.component.replaceWith( response.data.gallery );
}
}).fail(function(xhr, err) {
var responseTitle= $(xhr.responseText).filter('title').get(0);
alert($(responseTitle).text() + "\n" + EditusFormatAJAXErrorMessage(xhr, err) );
});
var data3 = {
componentType: 'gallery',
id: galleryID
};
window.get_aesop_component_ajax(data3);
}

///////////
Expand All @@ -12723,8 +12713,11 @@ function EditusFormatAJAXErrorMessage(jqXHR, exception) {
}

function ase_encode_gallery_items(){
var imageArray = gallery.sortable('toArray');
$('#ase_gallery_ids').val( imageArray );
gallery = $('#lasso--gallery__images #ase-gallery-images');
if (gallery.length) {
var imageArray = gallery.sortable('toArray');
$('#ase_gallery_ids').val( imageArray );
}
}

// inserting gallery items
Expand Down Expand Up @@ -13182,6 +13175,53 @@ function EditusFormatAJAXErrorMessage(jqXHR, exception) {
(function( $ ) {

var form;
// get updated aesop componets through ajax calls (global function)
window.get_aesop_component_ajax = function(cdata)
{
var data = {
action: 'get_aesop_component',
code: 'aesop_'+cdata['componentType']
};
for ( var index in cdata ) {
// Don't accept componentType as a param
if ( !cdata.hasOwnProperty(index) || index == 'componentType' || index =='sortableItem') {
continue;
}
data[index] = cdata[index];
}

jQuery.post(lasso_editor.ajaxurl2, data, function(response) {
if( response ){
var $a = $(response);
window.component.replaceWith($a);
window.component = $a;
$('.aesop-component').each(function(){

// if there's no toolbar present
if ( !$('.lasso-component--toolbar').length > 0 ) {

// if this is a map then we need to first wrap it so that we can drag the map around
if ( $(this).hasClass('aesop-map-component') ) {

var $this = $(this)

// so wrap it with a aesop-compoentn aesop-map-component div
// @todo - note once a map is inserted it can't be edited after saving again. a user has to delete the existin map and add a new map
// to
//$this.wrap('<form id="lasso--map-form" class="aesop-component aesop-map-component lasso--map-drag-holder" data-component-type="map" >').before( lassoDragHandle ).after( lassoMapForm );
$this.wrap('<div id="lasso--map-form" class="aesop-component aesop-map-component lasso--map-drag-holder" data-component-type="map" >').before( lassoDragHandle );

} else {

$(this).append( lasso_editor.handle );
}
}
});
} else {
alert("error");
}
});
}

//$('#lasso--component-settings-form').live('submit', function(e) {
jQuery(document).on('submit', '#lasso--component-settings-form', function(e){
Expand Down Expand Up @@ -13216,6 +13256,7 @@ function EditusFormatAJAXErrorMessage(jqXHR, exception) {
delete cdata['sortableItem'];
return cdata;
}


/**
*
Expand Down Expand Up @@ -13283,7 +13324,8 @@ function EditusFormatAJAXErrorMessage(jqXHR, exception) {
if ( 'gallery-created' == response.data.message ) {

saveSequence( false, 1000, true );
editus_gallery_swap(response.data.id);
// load the new gallery
cdata['id'] = response.data.id;

} else if ( 'gallery-updated' == response.data.message ) {

Expand All @@ -13295,6 +13337,7 @@ function EditusFormatAJAXErrorMessage(jqXHR, exception) {
alert( 'error' );

}
window.get_aesop_component_ajax(cdata);

}).fail(function(xhr, err) {
var responseTitle= $(xhr.responseText).filter('title').get(0);
Expand All @@ -13306,22 +13349,13 @@ function EditusFormatAJAXErrorMessage(jqXHR, exception) {
saveSequence( true, 1200 );

}

});
function editus_gallery_swap(galleryID){
var data = {
action: 'process_gallery_swap',
gallery_id: galleryID,
nonce: lasso_editor.swapGallNonce

if ( 'image' == cdata['componentType'] || 'quote' == cdata['componentType'] || 'parallax' == cdata['componentType'] || 'chapter' == cdata['componentType'] ||
'character' == cdata['componentType'] || 'collection' == cdata['componentType']) {
window.get_aesop_component_ajax(cdata);
}

$.post( lasso_editor.ajaxurl, data, function(response) {
if( true == response.success ) {
// window.component is the current component being edited
window.component.replaceWith( response.data.gallery );
}
});
}
});

})( jQuery );

Expand Down
2 changes: 1 addition & 1 deletion public/assets/js/lasso.min.js

Large diffs are not rendered by default.

27 changes: 10 additions & 17 deletions public/assets/js/source/process-gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,21 +137,11 @@
});

function editus_gallery_swap(galleryID){
var data = {
action: 'process_gallery_swap',
gallery_id: galleryID,
nonce: lasso_editor.swapGallNonce
}

$.post( lasso_editor.ajaxurl, data, function(response) {
if( true == response.success ) {
// window.component is the current component being edited
window.component.replaceWith( response.data.gallery );
}
}).fail(function(xhr, err) {
var responseTitle= $(xhr.responseText).filter('title').get(0);
alert($(responseTitle).text() + "\n" + EditusFormatAJAXErrorMessage(xhr, err) );
});
var data = {
componentType: 'gallery',
id: galleryID
};
window.get_aesop_component_ajax(data);
}

///////////
Expand All @@ -175,8 +165,11 @@
}

function ase_encode_gallery_items(){
var imageArray = gallery.sortable('toArray');
$('#ase_gallery_ids').val( imageArray );
gallery = $('#lasso--gallery__images #ase-gallery-images');
if (gallery.length) {
var imageArray = gallery.sortable('toArray');
$('#ase_gallery_ids').val( imageArray );
}
}

// inserting gallery items
Expand Down
116 changes: 52 additions & 64 deletions public/assets/js/source/process-save-component.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,53 @@
(function( $ ) {

var form;
// get updated aesop componets through ajax calls (global function)
window.get_aesop_component_ajax = function(cdata)
{
var data = {
action: 'get_aesop_component',
code: 'aesop_'+cdata['componentType']
};
for ( var index in cdata ) {
// Don't accept componentType as a param
if ( !cdata.hasOwnProperty(index) || index == 'componentType' || index =='sortableItem') {
continue;
}
data[index] = cdata[index];
}

jQuery.post(lasso_editor.ajaxurl2, data, function(response) {
if( response ){
var $a = $(response);
window.component.replaceWith($a);
window.component = $a;
$('.aesop-component').each(function(){

// if there's no toolbar present
if ( !$('.lasso-component--toolbar').length > 0 ) {

// if this is a map then we need to first wrap it so that we can drag the map around
if ( $(this).hasClass('aesop-map-component') ) {

var $this = $(this)

// so wrap it with a aesop-compoentn aesop-map-component div
// @todo - note once a map is inserted it can't be edited after saving again. a user has to delete the existin map and add a new map
// to
//$this.wrap('<form id="lasso--map-form" class="aesop-component aesop-map-component lasso--map-drag-holder" data-component-type="map" >').before( lassoDragHandle ).after( lassoMapForm );
$this.wrap('<div id="lasso--map-form" class="aesop-component aesop-map-component lasso--map-drag-holder" data-component-type="map" >').before( lassoDragHandle );

} else {

$(this).append( lasso_editor.handle );
}
}
});
} else {
alert("error");
}
});
}

//$('#lasso--component-settings-form').live('submit', function(e) {
jQuery(document).on('submit', '#lasso--component-settings-form', function(e){
Expand Down Expand Up @@ -36,53 +83,6 @@
return cdata;
}


// get updated aesop componets through ajax calls
var get_aesop_component_ajax = function(cdata)
{
var data = {
action: 'get_aesop_component',
code: 'aesop_'+cdata['componentType']
};
for ( var index in cdata ) {
// Don't accept componentType as a param
if ( !cdata.hasOwnProperty(index) || index == 'componentType' || index =='sortableItem') {
continue;
}
data[index] = cdata[index];
}

jQuery.post(lasso_editor.ajaxurl2, data, function(response) {
if( response ){
debugger;
$component.replaceWith(response);
$('.aesop-component').each(function(){

// if there's no toolbar present
if ( !$('.lasso-component--toolbar').length > 0 ) {

// if this is a map then we need to first wrap it so that we can drag the map around
if ( $(this).hasClass('aesop-map-component') ) {

var $this = $(this)

// so wrap it with a aesop-compoentn aesop-map-component div
// @todo - note once a map is inserted it can't be edited after saving again. a user has to delete the existin map and add a new map
// to
//$this.wrap('<form id="lasso--map-form" class="aesop-component aesop-map-component lasso--map-drag-holder" data-component-type="map" >').before( lassoDragHandle ).after( lassoMapForm );
$this.wrap('<div id="lasso--map-form" class="aesop-component aesop-map-component lasso--map-drag-holder" data-component-type="map" >').before( lassoDragHandle );

} else {

$(this).append( lasso_editor.handle );
}
}
});
} else {
alert("error");
}
});
}

/**
*
Expand Down Expand Up @@ -150,7 +150,8 @@
if ( 'gallery-created' == response.data.message ) {

saveSequence( false, 1000, true );
editus_gallery_swap(response.data.id);
// load the new gallery
cdata['id'] = response.data.id;

} else if ( 'gallery-updated' == response.data.message ) {

Expand All @@ -162,6 +163,7 @@
alert( 'error' );

}
window.get_aesop_component_ajax(cdata);

}).fail(function(xhr, err) {
var responseTitle= $(xhr.responseText).filter('title').get(0);
Expand All @@ -175,24 +177,10 @@
}

if ( 'image' == cdata['componentType'] || 'quote' == cdata['componentType'] || 'parallax' == cdata['componentType'] || 'chapter' == cdata['componentType'] ||
'character' == cdata['componentType']) {
get_aesop_component_ajax(cdata);
'character' == cdata['componentType'] || 'collection' == cdata['componentType']) {
window.get_aesop_component_ajax(cdata);
}

});
function editus_gallery_swap(galleryID){
var data = {
action: 'process_gallery_swap',
gallery_id: galleryID,
nonce: lasso_editor.swapGallNonce
}

$.post( lasso_editor.ajaxurl, data, function(response) {
if( true == response.success ) {
// window.component is the current component being edited
window.component.replaceWith( response.data.gallery );
}
});
}

})( jQuery );
7 changes: 6 additions & 1 deletion public/includes/lasso.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,14 +292,19 @@ public function get_aesop_component()
echo aesop_character_shortcode($atts);
}

if ($code == "aesop_collection") {
require_once( ABSPATH . '/wp-content/plugins/aesop-story-engine/public/includes/components/component-collections.php');
echo aesop_collection_shortcode($atts);
}

if ($code == "aesop_chapter") {
require_once( ABSPATH . '/wp-content/plugins/aesop-story-engine/public/includes/components/component-heading.php');
echo aesop_chapter_shortcode($atts);
}

if ($code == "aesop_gallery") {
require_once( ABSPATH . '/wp-content/plugins/aesop-story-engine/public/includes/components/component-gallery.php');
echo do_shortcode( '[aesop_gallery id="'.$atts["id"]."]");
echo do_shortcode( '[aesop_gallery id="'.$atts["id"].'"]');
}

exit;
Expand Down

0 comments on commit d3186d9

Please sign in to comment.