Repository: mozmeao/snippets-service

Issue:
Job editing page - show popup to prevent data loss when leaving page



Discussion:

Resolving patch:
diff --git a/snippets/base/forms.py b/snippets/base/forms.py
--- a/snippets/base/forms.py
+++ b/snippets/base/forms.py
@@ -200,7 +200,6 @@ class Media:
             'all': ('css/templateDataWidget.css',)
         }
         js = [
-            'js/lib/jquery-3.3.1.min.js',
             'js/lib/nunjucks.min.js',
             'js/templateDataWidget.js'
         ]
@@ -209,32 +208,10 @@ class Media:
 class TemplateChooserWidget(forms.Select):
     class Media:
         js = [
-            'js/lib/jquery-3.3.1.min.js',
             'js/templateChooserWidget.js',
         ]
 
 
-class IconWidget(forms.TextInput):
-    def render(self, name, value, attrs=None, renderer=None):
-        if not attrs:
-            attrs = {}
-        attrs['style'] = 'display:none'
-        original_widget_code = super(IconWidget, self).render(name, value, attrs)
-        widget_code = """
-        <div id="{name}-container">
-          <img src="{value}">
-          <input type="file" class="image-input">
-          {original_widget_code}
-        </div>
-        """.format(name=name, value=value,
-                   original_widget_code=original_widget_code)
-        return mark_safe(widget_code)
-
-    class Media:
-        js = ('js/lib/jquery-3.3.1.min.js',
-              'js/iconWidget.js')
-
-
 class PublishPermissionFormMixIn:
     def _publish_permission_check(self, cleaned_data):
         """If Snippet is Published or the current form sets it to Published verify that
@@ -562,7 +539,6 @@ def create_option(self, name, value, label, selected, index, subindex=None, attr
 
     class Media:
         js = [
-            'js/lib/jquery-3.3.1.min.js',
             'js/autoTranslatorWidget.js',
         ]
 
@@ -640,7 +616,6 @@ class Meta:
 
     class Media:
         js = [
-            'js/lib/jquery-3.3.1.min.js',
             'js/admin/inlineMover.js',
         ]
 


Test patch:
diff --git a/snippets/base/tests/test_forms.py b/snippets/base/tests/test_forms.py
--- a/snippets/base/tests/test_forms.py
+++ b/snippets/base/tests/test_forms.py
@@ -5,25 +5,13 @@
 from unittest.mock import Mock, patch
 from pyquery import PyQuery as pq
 
-from snippets.base.forms import (IconWidget, SnippetAdminForm, TargetAdminForm,
+from snippets.base.forms import (SnippetAdminForm, TargetAdminForm,
                                  TemplateDataWidget, TemplateSelect)
 from snippets.base.tests import (SnippetFactory, SnippetTemplateFactory,
                                  SnippetTemplateVariableFactory, TestCase,
                                  TargetFactory)
 
 
-class IconWidgetTests(TestCase):
-    def test_basic(self):
-        with patch('snippets.base.forms.forms.TextInput.render') as render_mock:
-            render_mock.return_value = 'original widget code'
-            widget = IconWidget()
-            rendered_widget = widget.render('iconname', 'iconvalue')
-        self.assertTrue('original widget code' in rendered_widget)
-        d = pq(rendered_widget)
-        self.assertEqual(d.find('img').attr('src'), 'iconvalue')
-        self.assertTrue(d.attr('id'), 'iconname')
-
-
 class TemplateSelectTests(TestCase):
     def test_basic(self):
         variable1 = SnippetTemplateVariableFactory()