Skip to content

Commit

Permalink
Merge pull request #5486 from vxsx/bugfix/aliased-plugin-double-init
Browse files Browse the repository at this point in the history
Fixed alias plugin preventing operations on the original plugin
  • Loading branch information
vxsx committed Jul 5, 2016
2 parents 6957537 + 17214e1 commit dbf8eb3
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.txt
Expand Up @@ -34,6 +34,8 @@
page tree dropdowns.
* Fixed a bug where Django Compressor could not be used on the sekizai ``js``
block.
* Fixed an issue when plugin that is aliased on the same page couldn't be
operated upon in the structure mode.


=== 3.3.0 (2016-05-26) ===
Expand Down
8 changes: 4 additions & 4 deletions cms/static/cms/js/dist/bundle.toolbar.min.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions cms/static/cms/js/modules/cms.plugins.js
Expand Up @@ -67,6 +67,9 @@ var Plugin = new Class({

// bind data element to the container
this.ui.container.data('settings', this.options);
if (Plugin.aliasPluginDuplicatesMap[this.options.plugin_id]) {
return;
}
Plugin._initializeDragItemsStates();

// determine type of plugin
Expand All @@ -76,6 +79,7 @@ var Plugin = new Class({
this._collapsables();
break;
case 'plugin': // handler for all plugins
Plugin.aliasPluginDuplicatesMap[this.options.plugin_id] = true;
this._setPlugin();
this._collapsables();
break;
Expand Down Expand Up @@ -1645,6 +1649,8 @@ Plugin._initializeDragItemsStates = Helpers.once(function _initializeDragItemsSt
});
});

Plugin.aliasPluginDuplicatesMap = {};

// shorthand for jQuery(document).ready();
$(Plugin._initializeGlobalHandlers);

Expand Down
31 changes: 31 additions & 0 deletions cms/tests/frontend/unit/cms.plugins.test.js
Expand Up @@ -39,6 +39,10 @@ describe('CMS.Plugin', function () {
});
});

afterEach(function () {
Plugin.aliasPluginDuplicatesMap = {};
});

describe('instance', function () {
var plugin1;
var plugin2;
Expand Down Expand Up @@ -244,8 +248,35 @@ describe('CMS.Plugin', function () {
expect(generic.ui.container.data('settings')).toEqual(generic.options);
});

it('doesnt reset the ui if the same plugin is initialized twice (alias case)', function () {
spyOn(Plugin.prototype, '_setPlugin');
spyOn(Plugin.prototype, '_setPlaceholder');
spyOn(Plugin.prototype, '_setGeneric');
expect(Plugin.aliasPluginDuplicatesMap[plugin1.options.plugin_id]).toEqual(true);

new CMS.Plugin('cms-plugin-1', {
type: 'plugin',
plugin_id: 1,
plugin_type: 'TextPlugin',
placeholder_id: 1,
urls: {
add_plugin: '/en/admin/cms/page/add-plugin/',
edit_plugin: '/en/admin/cms/page/edit-plugin/1/',
move_plugin: '/en/admin/cms/page/move-plugin/',
delete_plugin: '/en/admin/cms/page/delete-plugin/1/',
copy_plugin: '/en/admin/cms/page/copy-plugins/'
}
});

expect(Plugin.aliasPluginDuplicatesMap[plugin1.options.plugin_id]).toEqual(true);
expect(Plugin.prototype._setPlugin).not.toHaveBeenCalled();
expect(Plugin.prototype._setPlaceholder).not.toHaveBeenCalled();
expect(Plugin.prototype._setGeneric).not.toHaveBeenCalled();
});

it('checks if pasting into this plugin is allowed', function () {
spyOn(CMS.Plugin.prototype, '_checkIfPasteAllowed');
Plugin.aliasPluginDuplicatesMap = {};

plugin1 = new CMS.Plugin('cms-plugin-1', {
type: 'plugin',
Expand Down

0 comments on commit dbf8eb3

Please sign in to comment.