Quellcode durchsuchen

Remeber opened tab

Denis K vor 8 Jahren
Ursprung
Commit
221f6ea90e
2 geänderte Dateien mit 31 neuen und 13 gelöschten Zeilen
  1. 29 11
      jet/static/jet/js/main.js
  2. 2 2
      jet/templates/admin/change_form.html

+ 29 - 11
jet/static/jet/js/main.js

@@ -16,22 +16,40 @@
         };
 
         var initChangeformTabs = function() {
-            var $tabItems = $('.changeform-tabs-item');
-            var $modules = $('.module');
+            $('.changeform').each(function() {
+                var $changeform = $(this);
+                var $tabItems = $changeform.find('.changeform-tabs-item');
+                var $modules = $changeform.find('.module');
 
-            $('.changeform-tabs-item-link').click(function (e) {
-                var $tabItemLink = $(this);
-                var $tabItem = $tabItemLink.closest('.changeform-tabs-item');
-                var moduleId = $tabItemLink.data('module-id');
+                if ($tabItems.length == 0) {
+                    return;
+                }
+
+                var showTab = function(selector) {
+                    selector = selector.replace(/^#\/?/, '');
 
-                $tabItems.removeClass('selected');
-                $tabItem.addClass('selected');
+                    var $module = selector.length > 0 ? $modules.filter('#' + selector) : $();
 
-                var $module = $modules.removeClass('selected').filter('#' + moduleId).addClass('selected');
+                    if ($module && $module.length == 0) {
+                        selector = $tabItems.first().find('a').attr('href').replace(/^#\/?/, '');
+                    }
 
-                $module.find('select').trigger('select:init');
+                    var $tabItem = $tabItems.find('a[href="#/' + selector + '"]').closest('.changeform-tabs-item');
 
-                e.preventDefault();
+
+                    $tabItems.removeClass('selected');
+                    $tabItem.addClass('selected');
+                    $module = $modules.removeClass('selected').filter('#' + selector).addClass('selected');
+                    $module.find('select').trigger('select:init');
+                };
+
+                $('.changeform-tabs-item-link').click(function (e) {
+                    var moduleSelector = $(this).attr('href');
+
+                    showTab(moduleSelector);
+                });
+
+                showTab(location.hash);
             });
         };
 

+ 2 - 2
jet/templates/admin/change_form.html

@@ -77,7 +77,7 @@
                             {% is_fieldset_with_errors forloop.counter0 fieldsets_with_errors as fieldset_with_errors %}
 
                             <li class="changeform-tabs-item{% if selected %} selected{% endif %}{% if fieldset_with_errors %} errors{% endif %}">
-                                <a href="#" class="changeform-tabs-item-link" data-module-id="module_{{ forloop.counter0 }}">
+                                <a href="#/module_{{ forloop.counter0 }}" class="changeform-tabs-item-link" data-module-id="module_{{ forloop.counter0 }}">
                                     {% if fieldset.name %}
                                         {{ fieldset.name }}
                                     {% else %}
@@ -90,7 +90,7 @@
                             {% formset_has_errors inline_admin_formset.formset as errors %}
 
                             <li class="changeform-tabs-item{% if errors %} errors{% endif %}">
-                                <a href="#" class="changeform-tabs-item-link" data-module-id="inline_module_{{ forloop.counter0 }}">
+                                <a href="#/inline_module_{{ forloop.counter0 }}" class="changeform-tabs-item-link" data-module-id="inline_module_{{ forloop.counter0 }}">
                                     {{ inline_admin_formset.opts.verbose_name_plural|capfirst }}
                                 </a>
                             </li>