Skip to content

Commit

Permalink
[-] FO : Fix bug #PSCSX-1930, could not delete banner in live edit
Browse files Browse the repository at this point in the history
  • Loading branch information
gRoussac committed Apr 28, 2014
1 parent 377fe5e commit fc7522d
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 34 deletions.
6 changes: 5 additions & 1 deletion classes/controller/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,10 @@ protected function smartyOutputContent($content)

if ($this->controller_type == 'front' && !empty($html) && $this->getLayout())
{
$live_edit_content = '';
if (!$this->useMobileTheme() && $this->checkLiveEditAccess())
$live_edit_content = $this->getLiveEditFooter();

$dom_available = extension_loaded('dom') ? true : false;
if ($dom_available)
$html = Media::deferInlineScripts($html);
Expand All @@ -415,7 +419,7 @@ protected function smartyOutputContent($content)
'js_inline' => $dom_available ? Media::getInlineScript() : array()
));
$javascript = $this->context->smarty->fetch(_PS_ALL_THEMES_DIR_.'javascript.tpl');
echo $html.$javascript."\t</body>\n</html>";
echo $html.$javascript.$live_edit_content."\t</body>\n</html>";
}
else
echo $html;
Expand Down
12 changes: 4 additions & 8 deletions classes/controller/FrontController.php
Original file line number Diff line number Diff line change
Expand Up @@ -540,25 +540,21 @@ public function display()
'display_header' => $this->display_header,
'display_footer' => $this->display_footer,
));

$live_edit_content = '';
// Don't use live edit if on mobile theme
if (!$this->useMobileTheme() && $this->checkLiveEditAccess())
$live_edit_content = $this->getLiveEditFooter();


$layout = $this->getLayout();
if ($layout)
{
if ($this->template)
$this->context->smarty->assign('template', $this->context->smarty->fetch($this->template).$live_edit_content);
$template = $this->context->smarty->fetch($this->template);
else // For retrocompatibility with 1.4 controller
{
ob_start();
$this->displayContent();
$template = ob_get_contents();
ob_clean();
$this->context->smarty->assign('template', $template.$live_edit_content);

}
$template = $this->context->smarty->assign('template', $template);
$this->smartyOutputContent($layout);
}
else
Expand Down
31 changes: 18 additions & 13 deletions controllers/admin/AdminModulesPositionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ public function initContent()
if (array_key_exists('addToHook', $_GET) || array_key_exists('editGraft', $_GET) || (Tools::isSubmit('submitAddToHook') && $this->errors))
{
$this->display = 'edit';

$this->content .= $this->renderForm();
}
else
Expand Down Expand Up @@ -566,33 +567,37 @@ public function ajaxProcessSaveHook()
$hookableList = array();
// $_POST['hook'] is an array of id_module
$hooks_list = Tools::getValue('hook');

foreach ($hooks_list as $id_hook => $modules)
{

// 1st, drop all previous hooked modules
$sql = 'DELETE FROM `'._DB_PREFIX_.'hook_module`
WHERE `id_hook` = '.(int)$id_hook.'
AND id_shop = '.(int)$id_shop;
$sql = 'DELETE FROM `'._DB_PREFIX_.'hook_module` WHERE `id_hook` = '.(int)$id_hook.' AND id_shop = '.(int)$id_shop;
$res &= Db::getInstance()->execute($sql);

$i = 1;
$value = '';
$ids = array();
// then prepare sql query to rehook all chosen modules(id_module, id_shop, id_hook, position)
// position is i (autoincremented)
foreach ($modules as $id_module)
if (is_array($modules) && count($modules))
{
if (!in_array($id_module, $ids))
foreach ($modules as $id_module)
{
$ids[] = (int)$id_module;
$value .= '('.(int)$id_module.', '.(int)$id_shop.', '.(int)$id_hook.', '.(int)$i.'),';
if ($id_module && !in_array($id_module, $ids))
{
$ids[] = (int)$id_module;
$value .= '('.(int)$id_module.', '.(int)$id_shop.', '.(int)$id_hook.', '.(int)$i.'),';
}
$i++;
}
$i++;
}
$value = rtrim($value, ',');
$res &= Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'hook_module`
(id_module, id_shop, id_hook, position)
VALUES '.$value);

if ($value)
{
$value = rtrim($value, ',');
$res &= Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'hook_module` (id_module, id_shop, id_hook, position) VALUES '.$value);
}
}
}
if ($res)
$hasError = true;
Expand Down
8 changes: 7 additions & 1 deletion install-dev/upgrade/sql/1.6.0.7.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@ SET NAMES 'utf8';

ALTER TABLE `PREFIX_customer_message` CHANGE `ip_address` `ip_address` VARCHAR( 16 ) NULL DEFAULT NULL;

UPDATE `PREFIX_theme` SET product_per_page = '12' WHERE `product_per_page` = 0;
UPDATE `PREFIX_theme` SET product_per_page = '12' WHERE `product_per_page` = 0;

UPDATE `PREFIX_hook` SET live_edit = '1' WHERE `name` IN('displayTop','displayAttributeForm','displayAttributeGroupForm','displayBeforeCarrier',
'displayBeforePayment','displayCarrierList','displayCustomerAccount','displayCustomerAccountForm','displayCustomerAccountFormTop','displayFeatureForm',
'displayFeatureValueForm','displayFooter','displayLeftColumnProduct','displayMyAccountBlock','displayMyAccountBlockfooter','displayOrderConfirmation',
'displayOrderDetail','displayPaymentReturn','displayPaymentTop','displayProductButtons','displayProductComparison','displayProductListFunctionalButtons',
'displayProductTab','displayProductTabContent','displayRightColumnProduct','displayShoppingCart','displayShoppingCartFooter');
28 changes: 17 additions & 11 deletions js/hookLiveEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ $(document).ready(function() {
getHookableList();
$('.unregisterHook').unbind('click').click(function()
{
id = $(this).attr('id');
ids = $(this).attr('id').split('_');
$(this).parent().parent().parent().fadeOut('slow', function() {
$(this).parent().data('id', + ids[0]);
$(this).remove();
});
return false;
Expand Down Expand Up @@ -208,26 +209,31 @@ function saveModulePosition()
$("#fancy").attr('href', '#live_edit_feedback');
$("#fancy").trigger("click");
var str = '';
for (var i = 0; i < hooks_list.length; i++) {
for (var i = 0; i < hooks_list.length; i++)
{
str += '&' + hooks_list[i] + '=';
$('#' + hooks_list[i] + ' > .dndModule').each(function() {
ids = $(this).attr('id').split('_');
$("#liveEdit-action-form")
.append('<input class="dynamic-input-save-position" type="hidden" name="hook['+ids[1]+'][]" value="'+ids[3]+'" />');
});

if ($('#' + hooks_list[i] + ' > .dndModule').length)
{
$('#' + hooks_list[i] + ' > .dndModule').each(function(){

ids = $(this).attr('id').split('_');
$("#liveEdit-action-form").append('<input class="dynamic-input-save-position" type="hidden" name="hook[' + ids[1] + '][]" value="' + ids[3] + '" />');
});
}
else if (typeof($('#' + hooks_list[i]).data('id')) !== 'undefined' && !$('input[name="hook[' + i + ']"]').length)
$("#liveEdit-action-form").append('<input class="dynamic-input-save-position" type="hidden" name="hook[' + parseInt($('#' + hooks_list[i]).data('id')) + '][0]" value="0" />');
}
$("#liveEdit-action-form")
.append('<input class="dynamic-input-save-position" type="hidden" name="saveHook" value="1" />');
datas = $("#liveEdit-action-form").serializeArray();
$("#liveEdit-action-form").append('<input class="dynamic-input-save-position" type="hidden" name="saveHook" value="1" />');
datas = $("#liveEdit-action-form").serializeArray();

$.ajax({
type: 'POST',
url: baseDir + ad + "/index.php",
async: true,
dataType: 'json',
data: datas,
success: function(jsonData) {
success: function(jsonData){
$('#live_edit_feedback_str').html('<div class="live_edit_feed_back_ok" style="text-align:center; padding-top: 33px;"><img src="' + baseDir + 'img/admin/ok2.png"><h3>' + saveOK + '</h3><a style="margin:auto" class="exclusive" href="#" onclick="closeFancybox();">' + close + '</a></div>');
timer = setTimeout("hideFeedback()", 3000);
has_been_moved = false;
Expand Down

0 comments on commit fc7522d

Please sign in to comment.