Skip to content

Commit

Permalink
Merge 6f49887 into ac41c3d
Browse files Browse the repository at this point in the history
  • Loading branch information
vxsx committed Nov 3, 2016
2 parents ac41c3d + 6f49887 commit 0fe25f6
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 39 deletions.
8 changes: 4 additions & 4 deletions cms/static/cms/js/dist/3.4.1/bundle.admin.base.min.js

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions cms/static/cms/js/dist/3.4.1/bundle.toolbar.min.js

Large diffs are not rendered by default.

15 changes: 14 additions & 1 deletion cms/static/cms/js/modules/cms.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -608,8 +608,21 @@ CMS.API.Helpers = {
*/
_getWindow: function () {
return window;
}
},

/**
* We need to update the url with cms_path param for undo/redo
*
* @function updateUrlWithPath
* @private
* @param {String} url url
* @returns {String} modified url
*/
updateUrlWithPath: function (url) {
var path = window.location.pathname;

return this.makeURL(url, ['cms_path=' + encodeURIComponent(path)]);
}
};

// shorthand for jQuery(document).ready();
Expand Down
2 changes: 1 addition & 1 deletion cms/static/cms/js/modules/cms.clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ var Clipboard = new Class({

// redirect to ajax
CMS.API.Toolbar.openAjax({
url: CMS.config.clipboard.url,
url: Helpers.updateUrlWithPath(CMS.config.clipboard.url),
post: post,
callback: callback
});
Expand Down
2 changes: 1 addition & 1 deletion cms/static/cms/js/modules/cms.modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ var Modal = new Class({

if (item.is('a')) {
that._loadIframe({
url: item.prop('href'),
url: Helpers.updateUrlWithPath(item.prop('href')),
name: title
});
}
Expand Down
26 changes: 18 additions & 8 deletions cms/static/cms/js/modules/cms.plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require('../polyfills/array.prototype.findindex');
var doc;
var clipboard;
var clipboardDraggable;
var path = window.location.pathname;

/**
* Class for handling Plugins / Placeholders or Generics.
Expand Down Expand Up @@ -223,7 +224,7 @@ var Plugin = new Class({
e.stopPropagation();

that.editPlugin(
that.options.urls.edit_plugin,
Helpers.updateUrlWithPath(that.options.urls.edit_plugin),
that.options.plugin_name,
that._getPluginBreadcrumbs()
);
Expand Down Expand Up @@ -315,7 +316,11 @@ var Plugin = new Class({
this.ui.container.on(this.doubleClick, function (e) {
e.preventDefault();
e.stopPropagation();
that.editPlugin(that.options.urls.edit_plugin, that.options.plugin_name, []);
that.editPlugin(
Helpers.updateUrlWithPath(that.options.urls.edit_plugin),
that.options.plugin_name,
[]
);
});

// adds edit tooltip
Expand Down Expand Up @@ -398,6 +403,7 @@ var Plugin = new Class({
var params = {
placeholder_id: this.options.placeholder_id,
plugin_type: type,
cms_path: path,
plugin_language: this.options.plugin_language
};

Expand Down Expand Up @@ -494,7 +500,7 @@ var Plugin = new Class({
};
var request = {
type: 'POST',
url: options.urls.copy_plugin,
url: Helpers.updateUrlWithPath(options.urls.copy_plugin),
data: data,
success: function () {
CMS.API.Messages.open({
Expand Down Expand Up @@ -560,7 +566,7 @@ var Plugin = new Class({
// move plugin
$.ajax({
type: 'POST',
url: that.options.urls.move_plugin,
url: Helpers.updateUrlWithPath(that.options.urls.move_plugin),
data: data,
success: function () {
CMS.API.Messages.open({
Expand Down Expand Up @@ -677,7 +683,7 @@ var Plugin = new Class({

$.ajax({
type: 'POST',
url: options.urls.move_plugin,
url: Helpers.updateUrlWithPath(options.urls.move_plugin),
data: data,
success: function (response) {
// if response is reload
Expand Down Expand Up @@ -958,7 +964,11 @@ var Plugin = new Class({
* @param {Object} response response from server
*/
editPluginPostAjax: function (toolbar, response) {
this.editPlugin(response.url, this.options.plugin_name, response.breadcrumb);
this.editPlugin(
Helpers.updateUrlWithPath(response.url),
this.options.plugin_name,
response.breadcrumb
);
},

/**
Expand Down Expand Up @@ -1294,7 +1304,7 @@ var Plugin = new Class({
break;
case 'edit':
that.editPlugin(
that.options.urls.edit_plugin,
Helpers.updateUrlWithPath(that.options.urls.edit_plugin),
that.options.plugin_name,
that._getPluginBreadcrumbs()
);
Expand All @@ -1321,7 +1331,7 @@ var Plugin = new Class({
break;
case 'delete':
that.deletePlugin(
that.options.urls.delete_plugin,
Helpers.updateUrlWithPath(that.options.urls.delete_plugin),
that.options.plugin_name,
that._getPluginBreadcrumbs()
);
Expand Down
2 changes: 1 addition & 1 deletion cms/static/cms/js/modules/cms.toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ var Toolbar = new Class({
});

modal.open({
url: el.attr('href'),
url: Helpers.updateUrlWithPath(el.attr('href')),
title: el.data('name')
});
break;
Expand Down
2 changes: 1 addition & 1 deletion cms/tests/frontend/unit/cms.base.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('cms.base.js', function () {
it('exists', function () {
expect(CMS.API.Helpers).toEqual(jasmine.any(Object));
// this expectation is here so no one ever forgets to add a test
expect(Object.keys(CMS.API.Helpers).length).toEqual(19);
expect(Object.keys(CMS.API.Helpers).length).toEqual(20);
});

describe('.reloadBrowser()', function () {
Expand Down
4 changes: 2 additions & 2 deletions cms/tests/frontend/unit/cms.clipboard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,14 @@ describe('CMS.Clipboard', function () {
it('makes a request to the API', function () {
clipboard.clear();
expect(CMS.API.Toolbar.openAjax).toHaveBeenCalledWith({
url: 'clear-clipboard',
url: 'clear-clipboard?cms_path=%2Fcontext.html',
post: '{ "csrfmiddlewaretoken": "test_csrf" }',
callback: undefined
});

clipboard.clear($.noop);
expect(CMS.API.Toolbar.openAjax).toHaveBeenCalledWith({
url: 'clear-clipboard',
url: 'clear-clipboard?cms_path=%2Fcontext.html',
post: '{ "csrfmiddlewaretoken": "test_csrf" }',
callback: $.noop
});
Expand Down
2 changes: 1 addition & 1 deletion cms/tests/frontend/unit/cms.modal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1631,7 +1631,7 @@ describe('CMS.Modal', function () {

modal.ui.modalButtons.find('.cms-modal-item-buttons:eq(2) a').trigger(modal.click);
expect(modal._loadIframe).toHaveBeenCalledWith({
url: jasmine.stringMatching(/#go$/),
url: jasmine.stringMatching(/#go\?cms_path/),
name: 'link'
});
expect(spy).not.toHaveBeenCalled();
Expand Down
24 changes: 15 additions & 9 deletions cms/tests/frontend/unit/cms.plugins.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,10 +494,16 @@ describe('CMS.Plugin', function () {
});

expect(fakeModal.open).toHaveBeenCalledWith({
url: '/en/admin/cms/page/add-plugin/' +
'?placeholder_id=1&plugin_type=TextPlugin&plugin_language=&plugin_parent=12',
url: jasmine.any(String),
title: 'Text plugin'
});

expect(fakeModal.open.calls.mostRecent().args[0].url).toMatch('/en/admin/cms/page/add-plugin?');
expect(fakeModal.open.calls.mostRecent().args[0].url).toMatch('placeholder_id=1');
expect(fakeModal.open.calls.mostRecent().args[0].url).toMatch('plugin_type=TextPlugin');
expect(fakeModal.open.calls.mostRecent().args[0].url).toMatch('plugin_language=');
expect(fakeModal.open.calls.mostRecent().args[0].url).toMatch('plugin_parent=12');
expect(fakeModal.open.calls.mostRecent().args[0].url).toMatch('cms_path=');
});

it('opens the modal with correct url', function () {
Expand All @@ -513,7 +519,7 @@ describe('CMS.Plugin', function () {

expect(fakeModal.open).toHaveBeenCalledWith({
url: '/en/admin/cms/page/add-plugin/' +
'?placeholder_id=1&plugin_type=TextPlugin&plugin_language=',
'?placeholder_id=1&plugin_type=TextPlugin&cms_path=%2Fcontext.html&plugin_language=',
title: 'Text plugin'
});
});
Expand Down Expand Up @@ -655,7 +661,7 @@ describe('CMS.Plugin', function () {
it('makes a request to the API', function () {
expect(plugin.copyPlugin(plugin.options)).toEqual(undefined);
var request = jasmine.Ajax.requests.mostRecent();
expect(request.url).toEqual('/en/admin/cms/page/copy-plugins/');
expect(request.url).toEqual('/en/admin/cms/page/copy-plugins/?cms_path=%2Fcontext.html');
expect(request.method).toEqual('POST');
expect(request.data()).toEqual({
source_placeholder_id: ['1'],
Expand Down Expand Up @@ -848,7 +854,7 @@ describe('CMS.Plugin', function () {
it('makes a request to the API', function () {
expect(plugin.cutPlugin()).toEqual(undefined);
var request = jasmine.Ajax.requests.mostRecent();
expect(request.url).toEqual('/en/admin/cms/page/move-plugin/');
expect(request.url).toEqual('/en/admin/cms/page/move-plugin/?cms_path=%2Fcontext.html');
expect(request.method).toEqual('POST');
expect(request.data()).toEqual({
'placeholder_id': ['clipboardId'],
Expand Down Expand Up @@ -1176,7 +1182,7 @@ describe('CMS.Plugin', function () {
CMS.API.locked = false;
expect(plugin.movePlugin()).toEqual(undefined);
var request = jasmine.Ajax.requests.mostRecent();
expect(request.url).toEqual('/en/admin/cms/page/move-plugin/');
expect(request.url).toEqual('/en/admin/cms/page/move-plugin/?cms_path=%2Fcontext.html');
expect(request.method).toEqual('POST');
expect(request.data()).toEqual({
'placeholder_id': ['1'],
Expand Down Expand Up @@ -1542,7 +1548,7 @@ describe('CMS.Plugin', function () {
spyOn(plugin, 'editPlugin');
plugin.editPluginPostAjax({}, { url: 'test-url', breadcrumb: 'whatever' });
expect(plugin.editPlugin).toHaveBeenCalledWith(
'test-url',
'test-url?cms_path=%2Fcontext.html',
'Test Text Plugin',
'whatever'
);
Expand Down Expand Up @@ -1746,7 +1752,7 @@ describe('CMS.Plugin', function () {
link.trigger(plugin.click);
expect(plugin.editPlugin).toHaveBeenCalledTimes(1);
expect(plugin.editPlugin).toHaveBeenCalledWith(
'edit_plugin_url',
'edit_plugin_url?cms_path=%2Fcontext.html',
'MockPlugin',
'MockBreadcrumb'
);
Expand Down Expand Up @@ -1829,7 +1835,7 @@ describe('CMS.Plugin', function () {

expect(plugin.deletePlugin).toHaveBeenCalledTimes(1);
expect(plugin.deletePlugin).toHaveBeenCalledWith(
'DELETE_URL',
'DELETE_URL?cms_path=%2Fcontext.html',
'MockPlugin',
'Breadcrumb'
);
Expand Down
2 changes: 1 addition & 1 deletion cms/tests/frontend/unit/cms.toolbar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ describe('CMS.Toolbar', function () {
toolbar._delegate($('<div href="href" data-name="modal" data-rel="modal" data-on-close="test"></div>'));

expect(modalOpen).toHaveBeenCalledWith({
url: 'href',
url: 'href?cms_path=%2Fcontext.html',
title: 'modal'
});
});
Expand Down

0 comments on commit 0fe25f6

Please sign in to comment.