瀏覽代碼

ImageChooser now sets a default title based on filename. Fix #2844 (#4385)

Coen van der Kamp 7 年之前
父節點
當前提交
7841f54fe8
共有 4 個文件被更改,包括 21 次插入0 次删除
  1. 1 0
      CHANGELOG.txt
  2. 1 0
      CONTRIBUTORS.rst
  3. 1 0
      docs/releases/2.1.rst
  4. 18 0
      wagtail/images/templates/wagtailimages/chooser/chooser.js

+ 1 - 0
CHANGELOG.txt

@@ -18,6 +18,7 @@ Changelog
  * Added hook `register_account_menu_item` to add new account preference items (Michael van Tellingen)
  * Added change email functionality from the account settings (Alejandro Garza, Alexs Mathilda)
  * Add request parameter to edit handlers (Rajeev J Sebastian)
+ * ImageChooser now sets a default title based on filename (Coen van der Kamp)
  * Fix: Status button on 'edit page' now links to the correct URL when live and draft slug differ (LB (Ben Johnston))
  * Fix: Image title text in the gallery and in the chooser now wraps for long filenames (LB (Ben Johnston), Luiz Boaretto)
  * Fix: Move image editor action buttons to the bottom of the form on mobile (Julian Gallo)

+ 1 - 0
CONTRIBUTORS.rst

@@ -290,6 +290,7 @@ Contributors
 * Arthur Holzner
 * Alejandro Garza
 * Rajeev J Sebastian
+* Coen van der Kamp
 
 Translators
 ===========

+ 1 - 0
docs/releases/2.1.rst

@@ -32,6 +32,7 @@ Other features
  * Added hook `register_account_menu_item` to add new account preference items (Michael van Tellingen)
  * Added change email functionality from the account settings (Alejandro Garza, Alexs Mathilda)
  * Add request parameter to edit handlers (Rajeev J Sebastian)
+ * ImageChooser now sets a default title based on filename (Coen van der Kamp)
 
 Bug fixes
 ~~~~~~~~~

+ 18 - 0
wagtail/images/templates/wagtailimages/chooser/chooser.js

@@ -109,6 +109,24 @@ function(modal) {
         return false;
     });
 
+    function populateTitle(context) {
+        // Note: There are two inputs with `#id_title` on the page.
+        // The page title and image title. Select the input inside the modal body.
+        var fileWidget = $('#id_file', context);
+        fileWidget.on('change', function () {
+            var titleWidget = $('#id_title', context);
+            var title = titleWidget.val();
+            if (title === '') {
+                // The file widget value example: `C:\fakepath\image.jpg`
+                var parts = fileWidget.val().split('\\');
+                var fileName = parts[parts.length - 1];
+                titleWidget.val(fileName);
+            }
+        });
+    }
+
+    populateTitle(modal.body);
+
     {% url 'wagtailadmin_tag_autocomplete' as autocomplete_url %}
 
     /* Add tag entry interface (with autocompletion) to the tag field of the image upload form */