Issue#1124 2.2.1 #1205

Closed
wants to merge 1 commit into
from
Jump to file or symbol
Failed to load files and symbols.
+72 −3
Split
View
@@ -1235,6 +1235,26 @@ def edit_plugin(self, request, plugin_id):
context = RequestContext(request)
return render_to_response(plugin_admin.render_template, plugin_admin.render(context, instance, plugin_admin.placeholder))
+ if request.POST.get("_cancel", False):
+ # cancel buton was clicked
+ context = {
+ 'CMS_MEDIA_URL': settings.CMS_MEDIA_URL,
+ 'plugin': cms_plugin,
+ 'is_popup': True,
+ 'name': unicode(cms_plugin),
+ "type": cms_plugin.get_plugin_name(),
+ 'plugin_id': plugin_id,
+ 'icon': force_escape(escapejs(cms_plugin.get_instance_icon_src())),
+ 'alt': force_escape(escapejs(cms_plugin.get_instance_icon_alt())),
+ 'cancel': True,
+ }
+ if not instance:
+ # cancelled before any content was added to plugin
+ cms_plugin.delete()
+ context.update({
+ "deleted":True,
+ })
+ return render_to_response('admin/cms/page/plugin_forms_ok.html', context, RequestContext(request))
if not instance:
# instance doesn't exist, call add view
@@ -179,5 +179,9 @@ function loadPluginForm(target, id){
$('#plugin_'+id+" span.text").html(html);
$('#iframe_'+id).parent().html("<p>"+msg+"</p>");
}
+
+ removed_cancelled_plugin = function(plugin_id) {
+ $('#plugin_'+plugin_id).remove();
+ }
})(jQuery);
@@ -110,8 +110,8 @@
</div>
<span class="plugin-submit-row"{% if is_popup %} style="overflow: auto;"{% endif %}>
- <input type="submit" name="_save" class="default" value="{% trans "Save" %}" {{ onclick_attrib }}/>
- <input type="submit" style="margin-left: 8px;" value="{% trans "Cancel" %}" name="_cancel">
+ <input type="submit" style="float:none;" name="_save" class="default" value="{% trans "Save" %}" {{ onclick_attrib }}/>
+ <input type="submit" style="margin-left: 8px;" value="{% trans "Cancel" %}" name="_cancel" class="cancel-btn">
</span>
</form>
@@ -18,7 +18,14 @@
if(window.parent != self) {
if (typeof window.parent.CMS === 'undefined'){
// backend admin
- parent.hide_iframe({{ plugin.pk }}, {% javascript_string %}{{ type }}{% end_javascript_string %}, {% javascript_string %}{{ name }}{% end_javascript_string %}, {% javascript_string %}{% trans "Plugin saved successfully." %}{% end_javascript_string %});
+ {% if deleted %}
+ // delete plugin selector if cancelled before adding content
+ window.parent.removed_cancelled_plugin({{ plugin_id }});
+ {% endif %}
+ parent.hide_iframe({{ plugin_id }}, {% javascript_string %}{{ type }}{% end_javascript_string %}, {% javascript_string %}{{ name }}{% end_javascript_string %}, {% javascript_string %}
+ {% if cancel %}{% trans "Plugin editing has been cancelled." %}{% else %}{% trans "Plugin saved successfully." %}{% endif %}
+ {% end_javascript_string %});
+
} else {
// frontend edit
setTimeout(function () { window.parent.CMS.API.Helpers.reloadBrowser(); }, 1000);
View
@@ -102,6 +102,44 @@ def test_add_edit_plugin(self):
self.assertEquals(response.status_code, 200)
txt = Text.objects.all()[0]
self.assertEquals("Hello World", txt.body)
+ # edit body, but click cancel button
+ data = {
+ "body":"Hello World!!",
+ "_cancel":True,
+ }
+ response = self.client.post(edit_url, data)
+ self.assertEquals(response.status_code, 200)
+ txt = Text.objects.all()[0]
+ self.assertEquals("Hello World", txt.body)
+
+ def test_add_cancel_plugin(self):
+ """
+ Test that you can cancel a new plugin before editing and
+ that the plugin is removed.
+ """
+ # add a new text plugin
+ page_data = self.get_new_page_data()
+ response = self.client.post(URL_CMS_PAGE_ADD, page_data)
+ page = Page.objects.all()[0]
+ plugin_data = {
+ 'plugin_type':"TextPlugin",
+ 'language':settings.LANGUAGES[0][0],
+ 'placeholder':page.placeholders.get(slot="body").pk,
+ }
+ response = self.client.post(URL_CMS_PLUGIN_ADD, plugin_data)
+ self.assertEquals(response.status_code, 200)
+ self.assertEquals(int(response.content), CMSPlugin.objects.all()[0].pk)
+ # now click cancel instead of editing
+ edit_url = URL_CMS_PLUGIN_EDIT + response.content + "/"
+ response = self.client.get(edit_url)
+ self.assertEquals(response.status_code, 200)
+ data = {
+ "body":"Hello World",
+ "_cancel":True,
+ }
+ response = self.client.post(edit_url, data)
+ self.assertEquals(response.status_code, 200)
+ self.assertEquals(0, Text.objects.count())
def test_copy_plugins(self):
"""