Created
January 18, 2022 06:06
-
-
Save DariaUshaeva/13b13b695f627ca097a76e9077d9d226 to your computer and use it in GitHub Desktop.
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
diff --git a/app/controllers/backend/block_manager.post.php b/app/controllers/backend/block_manager.post.php | |
index 1ac68b310c..7119e0fe2a 100644 | |
--- a/app/controllers/backend/block_manager.post.php | |
+++ b/app/controllers/backend/block_manager.post.php | |
@@ -216,7 +216,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { | |
$block['content_data']['content']['items']['item_ids'] = Block::instance()->processItemIds($block['content_data']['content']['items']['item_ids']); | |
} | |
- $block_schema = SchemesManager::getBlockScheme($block['type'], []); | |
+ $block_schema = empty($block['type']) ? [] : SchemesManager::getBlockScheme($block['type'], []); | |
if (SchemesManager::isTemplateAvailable($block, $block_schema)) { | |
$block_id = Block::instance()->update($block, $description); |
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
diff --git a/design/backend/templates/views/tabs/update.tpl b/design/backend/templates/views/tabs/update.tpl | |
index e9c546f72d..64e3eed049 100644 | |
--- a/design/backend/templates/views/tabs/update.tpl | |
+++ b/design/backend/templates/views/tabs/update.tpl | |
@@ -1,87 +1,25 @@ | |
-{if $tab_data} | |
- {assign var="id" value=$tab_data.tab_id} | |
-{else} | |
- {assign var="id" value=0} | |
-{/if} | |
- | |
+{$id = ($tab_data) ? $tab_data.tab_id : 0} | |
{script src="js/tygh/tabs.js"} | |
+{script src="js/tygh/block_manager.js"} | |
-{assign var=html_id value="tab_`$id`"} | |
+{$html_id = "tab_`$id`"} | |
<script> | |
-var html_id = "{$html_id}"; | |
-{literal} | |
-(function(_, $) { | |
- $(document).ready(function() { | |
- $(_.doc).on('click', '.cm-remove-block', function(e) { | |
- if (confirm(_.tr('text_are_you_sure_to_proceed')) != false) { | |
- var parent = $(this).parent(); | |
- var block_id = parent.find('input[name="block_id"]').val(); | |
- | |
- $.ceAjax('request', fn_url('block_manager.block.delete'), { | |
- data: {block_id: block_id}, | |
- callback: function() { | |
- parent.remove(); | |
- }, | |
- method: 'post' | |
- }); | |
- } | |
- | |
- return false; | |
- }); | |
- | |
- $(_.doc).on('click', '.cm-add-block', function(e) { | |
- /* | |
- Adding new block functionality | |
- */ | |
- var action = $(this).prop('class').match(/bm-action-([a-zA-Z0-9-_]+)/)[1]; | |
- | |
- if (action == 'new-block') { | |
- var block_type = $(this).find('input[name="block_data[type]"]').val(); | |
- | |
- var href = 'block_manager.update_block?'; | |
- href += 'block_data[type]=' + block_type; | |
- href += '&ajax_update=1'; | |
- href += '&html_id=' + html_id; | |
- href += '&force_close=' + 1; | |
- href += '&assign_to=' + 'ajax_update_block_' + html_id; | |
- | |
- var prop_container = 'new_block_' + block_type; | |
- | |
- // Remove properties container if it exist | |
- if ($('#' + prop_container).length != 0) { | |
- $('#' + prop_container).remove(); | |
- } | |
- | |
- // Create properties container | |
- var container = $('<div id="' + prop_container + '"></div>').appendTo(_.body); | |
- | |
- $('#' + prop_container).ceDialog('open', {href: fn_url(href), title: Tygh.tr('add_block') + ': ' + $(this).find('strong').text()}); | |
- } else if (action == 'existing-block') { | |
- var block_id = $(this).find('input[name="block_id"]').val(); | |
- var block_title = $(this).find('.select-block-title').text(); | |
- | |
- data = { | |
- block_data: { | |
- block_id: $(this).find('input[name="block_id"]').val() | |
- }, | |
- assign_to: 'ajax_update_block_' + html_id, | |
- force_close: '1' | |
- }; | |
- | |
- $.ceAjax('request', fn_url('block_manager.update_block'), { | |
- data: data, | |
- method: 'post' | |
- }); | |
- } | |
- | |
- $.ceDialog('get_last').ceDialog('close'); | |
+ var html_id = "{$html_id}"; | |
+ var BlockManager = new BlockManager_Class(); | |
+ | |
+ {literal} | |
+ (function(_, $) { | |
+ $(document).ready(function() { | |
+ var is_manage_blocks = true; | |
+ var result_id = 'ajax_update_block_' + html_id; | |
+ | |
+ BlockManager.initBlockManagerActions(is_manage_blocks, result_id); | |
}); | |
- }); | |
-}(Tygh, Tygh.$)); | |
-{/literal} | |
+ }(Tygh, Tygh.$)); | |
+ {/literal} | |
</script> | |
<form action="{""|fn_url}" enctype="multipart/form-data" name="update_product_tab_form_{$id}" method="post" class=" form-horizontal"> |
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
diff --git a/js/tygh/block_manager.js b/js/tygh/block_manager.js | |
index 046a844e13..da8211515b 100644 | |
--- a/js/tygh/block_manager.js | |
+++ b/js/tygh/block_manager.js | |
@@ -447,7 +447,81 @@ function BlockManager_Class() | |
_init_params = params; | |
_init_params.containers = containers; | |
+ | |
+ _self.initBlockManagerActions(); | |
+ | |
+ // Update grid width select | |
+ $(Tygh.doc).on('change', 'select[name="offset"]', function() { | |
+ const $self = $(this), | |
+ gridId = $self.data('caGridId') ? +$self.data('caGridId') : 0; | |
+ | |
+ if (!gridId) { | |
+ return; | |
+ } | |
+ | |
+ const $gridElement = $(`#${_init_params.grid_class}_${gridId}`), | |
+ $widthGridSelect = $('#elm_grid_width_' + gridId), | |
+ minWidth = _self.getMinWidth($gridElement), | |
+ maxWidth = _self.getMaxWidth($gridElement), | |
+ currentWidth = $widthGridSelect.val() <= maxWidth && $widthGridSelect.val() >= minWidth? $widthGridSelect.val() : minWidth; | |
+ | |
+ $widthGridSelect.empty(); | |
+ | |
+ for (let i = minWidth; i <= maxWidth; i += 1) { | |
+ $widthGridSelect | |
+ .append($('<option></option>') | |
+ .attr('value', i).text(i)); | |
+ } | |
+ | |
+ $widthGridSelect.val(currentWidth); | |
+ }); | |
+ | |
+ // Update grid offset select | |
+ $(Tygh.doc).on('change', 'select[name="width"]', function() { | |
+ const $self = $(this), | |
+ gridId = $self.data('caGridId') ? +$self.data('caGridId') : 0; | |
+ | |
+ if (!gridId) { | |
+ return; | |
+ } | |
+ | |
+ const $gridElement = $(`#${_init_params.grid_class}_${gridId}`), | |
+ $offsetGridSelect = $('#elm_grid_offset_' + gridId), | |
+ maxOffset = _self.getMaxOffset($gridElement, +$self.val()), | |
+ currentOffset = $offsetGridSelect.val() < maxOffset ? $offsetGridSelect.val() : 0; | |
+ | |
+ $offsetGridSelect.empty(); | |
+ | |
+ for (let i = 0; i < maxOffset; i += 1) { | |
+ $offsetGridSelect | |
+ .append($('<option></option>') | |
+ .attr('value', i).text(i)); | |
+ } | |
+ | |
+ $offsetGridSelect.val(currentOffset); | |
+ }); | |
+ // Init sortable zones | |
+ _self.calculateLevels(); | |
+ | |
+ // Correct control menues | |
+ _self.checkMenuItems($('.' + params.grid_class, params.parent)); | |
+ | |
+ // Disable/Enable blocks in depends on the Grid statuses | |
+ $('.grid-off, .container-off ').each(function(){ | |
+ _self.recheckBlockStatuses($(this)); | |
+ }); | |
+ | |
+ if (params.device_availability_switcher) { | |
+ _self.initDeviceAvailabilitySwitcher(params.device_availability_switcher); | |
+ } | |
+ | |
+ if (params.edit_object_id && params.edit_object_type) { | |
+ _self.openObjectPropertiesForm(params.edit_object_id, params.edit_object_type); | |
+ } | |
+ }; | |
+ | |
+ this.initBlockManagerActions = function (is_manage_blocks, result_id) { | |
/* | |
We have 2 function to parse actions: | |
1) Block manager control elements, like "Add grid", "Properties", etc. | |
@@ -474,7 +548,7 @@ function BlockManager_Class() | |
if (confirm(Tygh.tr('text_are_you_sure_to_proceed')) != false) { | |
var block_id = $(this).parent().find('input[name="block_id"]').val(); | |
- _self.sendRequest('block', 'delete', {block_id: block_id}); | |
+ _self.sendRequest('block', 'delete', {block_id: block_id}, is_manage_blocks); | |
$(this).parent().remove(); | |
} | |
@@ -488,20 +562,20 @@ function BlockManager_Class() | |
*/ | |
var action = $(this).prop('class').match(/bm-action-([a-zA-Z0-9-_]+)/)[1]; | |
- if (action == 'new-block') { | |
- var is_manage = $(this).hasClass('bm-manage'); | |
- var block_type = $(this).find('input[name="block_data[type]"]').val(); | |
- | |
- if (is_manage) { | |
- var grid_id = 0; | |
+ if (action === 'new-block') { | |
+ var is_manage = $(this).hasClass('bm-manage'), | |
+ block_type = $(this).find('input[name="block_data[type]"]').val(), | |
+ grid_id = (is_manage || is_manage_blocks) ? 0 : _hover_element.prop('id').replace('grid_', ''), | |
+ href = 'block_manager.update_block?block_data[type]=' + block_type; | |
+ | |
+ if (is_manage_blocks) { | |
+ href += '&ajax_update=1'; | |
+ href += '&html_id=' + html_id; | |
+ href += '&assign_to=' + result_id; | |
} else { | |
- var grid_id = _hover_element.prop('id').replace('grid_', ''); | |
- } | |
- | |
- var href = 'block_manager.update_block?'; | |
- href += 'block_data[type]=' + block_type; | |
href += '&snapping_data[grid_id]=' + grid_id; | |
href += '&selected_location=' + (typeof(selected_location) == 'undefined' ? 0 : selected_location); | |
+ } | |
var prop_container = 'new_block_' + block_type + '_' + grid_id; | |
@@ -512,19 +586,14 @@ function BlockManager_Class() | |
$('#' + prop_container).ceDialog('open', {href: fn_url(href), title: Tygh.tr('add_block') + ': ' + $(this).find('strong').text(), destroyOnClose: true}); | |
- } else if (action == 'existing-block') { | |
- var is_manage = $(this).hasClass('bm-manage'); | |
- var block_id = $(this).find('input[name="block_id"]').val(); | |
- var block_type = $(this).find('input[name="type"]').val(); | |
- var grid_id = $(this).find('input[name="grid_id"]').val(); | |
- var block_title = $(this).find('.select-block-description > strong').text(); | |
- | |
- if (is_manage) { | |
- var href = 'block_manager.update_block?'; | |
- href += 'block_data[type]=' + block_type; | |
- href += '&block_data[block_id]=' + block_id; | |
- href += '&selected_location=' + (typeof(selected_location) == 'undefined' ? 0 : selected_location); | |
+ } else if (action === 'existing-block') { | |
+ var is_manage = $(this).hasClass('bm-manage'), | |
+ block_id = $(this).find('input[name="block_id"]').val(), | |
+ block_type = $(this).find('input[name="type"]').val(), | |
+ grid_id = $(this).find('input[name="grid_id"]').val(), | |
+ block_title = $(this).find('.select-block-description > strong').text(); | |
+ if (is_manage || is_manage_blocks) { | |
var prop_container = 'new_block_' + block_type + '_block_' + block_id; | |
if ($('#' + prop_container).length == 0) { | |
@@ -532,7 +601,24 @@ function BlockManager_Class() | |
var container = $('<div id="' + prop_container + '"></div>').appendTo('body'); | |
} | |
- $('#' + prop_container).ceDialog('open', {href: fn_url(href), title: $(this).find('strong').text()}); | |
+ if (is_manage_blocks) { | |
+ var data = { | |
+ block_data: { | |
+ block_id: block_id, | |
+ type: block_type | |
+ }, | |
+ assign_to: result_id, | |
+ } | |
+ | |
+ _self.sendRequest('', 'update_block', data, is_manage_blocks); | |
+ } else { | |
+ var href = 'block_manager.update_block?'; | |
+ href += 'block_data[type]=' + block_type; | |
+ href += '&block_data[block_id]=' + block_id; | |
+ href += '&selected_location=' + (typeof(selected_location) == 'undefined' ? 0 : selected_location); | |
+ | |
+ $('#' + prop_container).ceDialog('open', {href: fn_url(href), title: $(this).find('strong').text()}); | |
+ } | |
} else { | |
var elm = $('<div class="block base-block" data-block-id="' + block_id + '" id="block_' + block_id + '" title="' + block_title + '">' + $('.base-block').html() + '</div>'); | |
@@ -586,77 +672,11 @@ function BlockManager_Class() | |
} | |
} | |
} | |
- }); | |
- | |
- // Update grid width select | |
- $(Tygh.doc).on('change', 'select[name="offset"]', function() { | |
- const $self = $(this), | |
- gridId = $self.data('caGridId') ? +$self.data('caGridId') : 0; | |
- | |
- if (!gridId) { | |
- return; | |
- } | |
- | |
- const $gridElement = $(`#${_init_params.grid_class}_${gridId}`), | |
- $widthGridSelect = $('#elm_grid_width_' + gridId), | |
- minWidth = _self.getMinWidth($gridElement), | |
- maxWidth = _self.getMaxWidth($gridElement), | |
- currentWidth = $widthGridSelect.val() <= maxWidth && $widthGridSelect.val() >= minWidth? $widthGridSelect.val() : minWidth; | |
- | |
- $widthGridSelect.empty(); | |
- | |
- for (let i = minWidth; i <= maxWidth; i += 1) { | |
- $widthGridSelect | |
- .append($('<option></option>') | |
- .attr('value', i).text(i)); | |
- } | |
- | |
- $widthGridSelect.val(currentWidth); | |
- }); | |
- | |
- // Update grid offset select | |
- $(Tygh.doc).on('change', 'select[name="width"]', function() { | |
- const $self = $(this), | |
- gridId = $self.data('caGridId') ? +$self.data('caGridId') : 0; | |
- | |
- if (!gridId) { | |
- return; | |
- } | |
- const $gridElement = $(`#${_init_params.grid_class}_${gridId}`), | |
- $offsetGridSelect = $('#elm_grid_offset_' + gridId), | |
- maxOffset = _self.getMaxOffset($gridElement, +$self.val()), | |
- currentOffset = $offsetGridSelect.val() < maxOffset ? $offsetGridSelect.val() : 0; | |
- | |
- $offsetGridSelect.empty(); | |
- | |
- for (let i = 0; i < maxOffset; i += 1) { | |
- $offsetGridSelect | |
- .append($('<option></option>') | |
- .attr('value', i).text(i)); | |
+ if (is_manage_blocks) { | |
+ $.ceDialog('get_last').ceDialog('close'); | |
} | |
- | |
- $offsetGridSelect.val(currentOffset); | |
}); | |
- | |
- // Init sortable zones | |
- _self.calculateLevels(); | |
- | |
- // Correct control menues | |
- _self.checkMenuItems($('.' + params.grid_class, params.parent)); | |
- | |
- // Disable/Enable blocks in depends on the Grid statuses | |
- $('.grid-off, .container-off ').each(function(){ | |
- _self.recheckBlockStatuses($(this)); | |
- }); | |
- | |
- if (params.device_availability_switcher) { | |
- _self.initDeviceAvailabilitySwitcher(params.device_availability_switcher); | |
- } | |
- | |
- if (params.edit_object_id && params.edit_object_type) { | |
- _self.openObjectPropertiesForm(params.edit_object_id, params.edit_object_type); | |
- } | |
}; | |
this.hideControls = function () { | |
@@ -807,17 +827,18 @@ function BlockManager_Class() | |
return clears_data; | |
}; | |
- this.sendRequest = function(mode, action, data) | |
+ this.sendRequest = function(mode, action, data, is_manage_blocks) | |
{ | |
if (mode == 'grid') { | |
data.clears_data = _self.recalculateClearLines(); | |
} | |
- var controller = typeof(data['controller']) == 'undefined' ? 'block_manager.' : data['controller'] + '.'; | |
+ var controller = typeof(data['controller']) == 'undefined' ? 'block_manager' : data['controller'], | |
+ url = controller + (mode ? '.' + mode : '') + (action ? '.' + action : ''); | |
- $.ceAjax('request', fn_url(controller + mode + '.' + action), { | |
+ $.ceAjax('request', fn_url(url), { | |
data: data, | |
- callback: _parseResponse, | |
+ callback: (is_manage_blocks ? false : _parseResponse), | |
method: 'post' | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment