Commit 66c08ce0 authored by Cecilia Vela Gurovic's avatar Cecilia Vela Gurovic Committed by Robert Lyon
Browse files

Bug 1813987: Making magic block work with gridstack layout

In view edit mode, dragging the button '+' on the
right top menu, will add a block in the page
with dimensions height=3 and width=4

behatnotneeded

Change-Id: I5f4334886f6685bd047cb5bfbf0d59dd3880109a
parent 15bca1e7
Loading
Loading
Loading
Loading
+54 −30
Original line number Diff line number Diff line
@@ -311,6 +311,8 @@
        };

        $('.grid-stack').on('change', function(event, items) {
            event.stopPropagation();
            event.preventDefault();
            serializeWidgetMap(items);
        })

@@ -445,6 +447,8 @@

        $('.blocktype-drag').draggable({
            start: function(event, ui) {
                $(this).attr('data-gs-width', 4);
                $(this).attr('data-gs-height', 3);
            },
            helper: function(event) {
              var original = $(this),
@@ -455,12 +459,24 @@
                  $(this).css('min-width', '200px');
              });

              // show dotted line with correct dimensions when dragging placeholder block
              var node = {width: 4, height: 3};
              $(this).data('_gridstack_node', node);

              return helper;
            },
            connectToSortable: '.js-col-row .column .column-content',
            connectToSortable: '.grid-stack',
            stop: function(event, ui) {
                var placeholder = $('.grid-stack').children().last(),
                    x = placeholder.attr('data-gs-x'),
                    y = placeholder.attr('data-gs-y');

                $(placeholder).remove();

                $('.grid-stack .blocktype-drag').removeClass('btn btn-primary');
                addNewBlock({'positionx': x, 'positiony': y}, 'placeholder');
            },
            appendTo: 'body'
            appendTo: 'body',
        });

        $('.blocktype-drag').off('click keydown'); // remove old event handlers
@@ -516,8 +532,16 @@
            var grid = $('.grid-stack').data('gridstack');
            pd['positiony'] = grid.grid.getGridHeight();
        }
        else {
            if (typeof(whereTo['positionx']) !== 'undefined') {
                pd['positionx'] = whereTo['positionx'];
            }
            if (typeof(whereTo['positiony']) !== 'undefined') {
                pd['positiony'] = whereTo['positiony'];
            }
        }

        pd['action_addblocktype_positionx_' + pd['positionx'] + '_positiony_' + pd['positiony'] + '_width_' + '3'+ '_height_' + '3'] = true;
        pd['action_addblocktype_positionx_' + pd['positionx'] + '_positiony_' + pd['positiony'] + '_width_' + '4'+ '_height_' + '3'] = true;
        sendjsonrequest(config['wwwroot'] + 'view/blocks.json.php', pd, 'POST', function(data) {
            var div = $('<div>').html(data.data.display.html),
                blockinstance = div.find('div.grid-stack-item'),
@@ -531,7 +555,7 @@
            addBlockCss(data.css);

            var grid = $('.grid-stack').data('gridstack');
            dimensions.width = 3;
            dimensions.width = 4;
            dimensions.height = 3;
            addNewWidget(blockinstance, blockId, dimensions, grid, null);

+0 −6
Original line number Diff line number Diff line
@@ -2584,9 +2584,6 @@ class View {
                'title'      => $newtitle,
                'view'       => $this->get('id'),
                'view_obj'   => $this,
                'row'        => $currentblock->row,
                'column'     => $currentblock->column,
                'order'      => $currentblock->order,
            )
        );
        $result = array('blockid' => $currentblock->id,
@@ -2651,9 +2648,6 @@ class View {
                'title'      => $oldtitle,
                'view'       => $this->get('id'),
                'view_obj'   => $this,
                'row'        => $currentblock->row,
                'column'     => $currentblock->column,
                'order'      => $currentblock->order,
            )
        );
        $result = array('blockid' => $currentblock->id,
+4 −4
Original line number Diff line number Diff line
@@ -1629,7 +1629,7 @@ JS;
    public function i_should_see_images_block($blocktitle) {
        // Find the block.
        $blocktitleliteral = $this->escaper->escapeLiteral($blocktitle);
        $xpath = "//div[contains(concat(' ', normalize-space(@class), ' '), ' column-content ')]" .
        $xpath = "//div[contains(concat(' ', normalize-space(@class), ' '), ' grid-stack-item-content ')]" .
                     "/div[contains(@id,'blockinstance_')" .
                         " and contains(h3, " . $blocktitleliteral . ")]//img";
        // Wait until it finds the text inside the block title.
@@ -1689,7 +1689,7 @@ JS;
        // Find the block.
        $blocktitleliteral = $this->escaper->escapeLiteral($blocktitle);
        $textliteral = $this->escaper->escapeLiteral($text);
        $xpath = "//div[contains(concat(' ', normalize-space(@class), ' '), ' column-content ')]" .
        $xpath = "//div[contains(concat(' ', normalize-space(@class), ' '), ' grid-stack-item-content ')]" .
                     "/div[contains(@id,'blockinstance_')" .
                         " and contains(h3, " . $blocktitleliteral . ")]" .
                     "//div[contains(normalize-space(.), " . $textliteral . ")]";
@@ -1732,7 +1732,7 @@ JS;
    public function i_should_not_see_images_block($blocktitle) {
        // Find the block.
        $blocktitleliteral = $this->escaper->escapeLiteral($blocktitle);
        $xpath = "//div[contains(concat(' ', normalize-space(@class), ' '), ' column-content ')]" .
        $xpath = "//div[contains(concat(' ', normalize-space(@class), ' '), ' grid-stack-item-content ')]" .
                     "/div[contains(@id,'blockinstance_')" .
                         " and contains(h3, " . $blocktitleliteral . ")]" .
                         "[count(descendant::img) = 0]";
@@ -1776,7 +1776,7 @@ JS;
        // Find the block.
        $blocktitleliteral = $this->escaper->escapeLiteral($blocktitle);
        $textliteral = $this->escaper->escapeLiteral($text);
        $xpath = "//div[contains(concat(' ', normalize-space(@class), ' '), ' column-content ')]" .
        $xpath = "//div[contains(concat(' ', normalize-space(@class), ' '), ' grid-stack-item-content ')]" .
                     "/div[contains(@id,'blockinstance_')" .
                         " and contains(h3, " . $blocktitleliteral . ")]" .
                     "//div[count(descendant::*[contains(normalize-space(.), " . $textliteral . ")]) = 0]";
+1 −0
Original line number Diff line number Diff line
@@ -171,6 +171,7 @@ if ($newlayout = $view->uses_new_layout()) {
            verticalMargin: 10,
            float: true, //to place a block in any part of the page and the position will remain fixed
            resizable: false,
            acceptWidgets: '.blocktype-drag',
        };
        var grid = $('.grid-stack');
        grid.gridstack(options);
+3 −0
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ Background:
    And I press "Add"
    And I click on "Show more"
    And I click on "Show more"
    And I click on "Show more"
    And I click on "Sign-off" in the "Content types" property
    And I enable the switch "Verify"
    And I press "Save"
@@ -71,6 +72,7 @@ Background:
    And I press "Add"
    And I click on "Show more"
    And I click on "Show more"
    And I click on "Show more"
    And I click on "Sign-off" in the "Content types" property
    And I enable the switch "Verify"
    And I press "Save"
@@ -84,6 +86,7 @@ Background:
    And I press "Add"
    And I click on "Show more"
    And I click on "Show more"
    And I click on "Show more"
    And I click on "Sign-off" in the "Content types" property
    And I enable the switch "Verify"
    And I press "Save"
Loading