David Jean Louis avatar David Jean Louis committed 15a6d99

avoid conflicts between different dashboards

Comments (0)

Files changed (4)

admin_tools/dashboard/models.py

 from django.contrib import admin
 from django.contrib.contenttypes.models import ContentType
 from django.core.urlresolvers import reverse
+from django.template.defaultfilters import slugify
 from django.utils.importlib import import_module
 from django.utils.text import capfirst
 from django.utils.translation import ugettext_lazy as _
         """
         pass
 
+    def get_id(self):
+        """
+        Internal method used to distinguish different dashboards in js code.
+        """
+        return 'dashboard'
+
 
 class AppIndexDashboard(Dashboard):
     """
         return [ContentType.objects.get_for_model(c) for c \
                 in self.get_app_model_classes()]
 
+    def get_id(self):
+        """
+        Internal method used to distinguish different dashboards in js code.
+        """
+        return '%s-dashboard' % slugify(unicode(self.app_title))
+
 
 class DashboardModule(object):
     """

admin_tools/dashboard/templates/dashboard/dashboard.html

 <script type="text/javascript">
 // <![CDATA[
 $(document).ready(function() {
-    $('#dashboard').dashboard({
+    $('#{{ dashboard.get_id }}').dashboard({
         'columns': {{ dashboard.columns }}
     });
 });
         {% endspaceless %}
     </ul>
 </div>
-<div id="dashboard">
+<div id="{{ dashboard.get_id }}" class="dashboard-container">
     {% for module in dashboard %}
 {% render_dashboard_module module forloop.counter %}{% endfor %}
 </div>

admin_tools/media/admin_tools/css/dashboard.css

     width: auto; !important;
 }
 
-#dashboard {
+.dashboard-container {
     clear: both;
 }
 

admin_tools/media/admin_tools/js/jquery/jquery.dashboard.js

             //Set the default values, use comma to separate the settings, example:
             var defaults = {
                 panel_id: 'dashboard-panel',
+                dashboard_id: this.attr('id'),
                 dashboard_module_class: 'dashboard-module',
                 columns: 2
             }    
         }
     });
 
-    var json_str = $.cookie('admin-tools.dashboard');
-    var preferences = json_str ? JSON.parse(json_str) : {};
 
     var _set_ids = function(elt, options) {
         elt.children('div[id!=' + options.panel_id +']').each(function(index) {
         }
     };
 
+    var preferences = false;
+
     var _restore_preferences = function(elt, options) {
+        if (preferences === false) {
+            var json_str = $.cookie('admin-tools.' + options.dashboard_id);
+            preferences = json_str ? JSON.parse(json_str) : {};
+        }
         elt.children().children('.disabled').each(function() {
             _delete_element($(this), options);
         });
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.