From: zuber Date: Tue, 15 Sep 2009 15:33:16 +0000 (+0200) Subject: Zapisywanie ustawień paneli dla 5 ostatnio otwartych plików. X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/889882b4d84fb826afc834040b203dff2fb4a224?ds=sidebyside;hp=--cc Zapisywanie ustawień paneli dla 5 ostatnio otwartych plików. --- 889882b4d84fb826afc834040b203dff2fb4a224 diff --git a/apps/explorer/models.py b/apps/explorer/models.py index ace513d4..a1cb56cf 100644 --- a/apps/explorer/models.py +++ b/apps/explorer/models.py @@ -1,3 +1,4 @@ +# -*- encoding: utf-8 -*- import os from django.db import models @@ -10,6 +11,29 @@ import toolbar.models from explorer import fields class EditorSettings(models.Model): + """Ustawienia edytora dla użytkownika. + + Pole settings zawiera obiekt JSON o kluczach: + - panels - lista otwartych paneli i ich proporcje + - recentFiles - lista otwartych plików i ustawienia dla nich + + Przykład: + { + 'panels': [ + {'name': 'htmleditor', 'ratio': 0.5}, + {'name': 'gallery', 'ratio': 0.5} + ], + 'recentFiles': [ + { + 'fileId': 'mickiewicz_pan_tadeusz.xml', + 'panels': [ + {'name': 'htmleditor', 'ratio': 0.4}, + {'name': 'gallery', 'ratio': 0.6} + ] + } + ] + } + """ user = models.ForeignKey(User, unique=True) settings = fields.JSONField() diff --git a/project/static/js/editor.js b/project/static/js/editor.js index 8267097c..fa796dba 100644 --- a/project/static/js/editor.js +++ b/project/static/js/editor.js @@ -298,9 +298,21 @@ Editor.prototype.loadConfig = function() { } catch (e) { this.options = defaultOptions; } + + this.fileOptions = this.options; + var self = this; + $.each(this.options.recentFiles, function(index) { + if (fileId == self.options.recentFiles[index].fileId) { + $.log('Found options for', fileId); + self.fileOptions = self.options.recentFiles[index]; + } + }); + $.log(this.options); + $.log('fileOptions', this.fileOptions); this.loadPanelOptions(); + this.savePanelOptions(); }; Editor.prototype.loadPanelOptions = function() { @@ -308,7 +320,7 @@ Editor.prototype.loadPanelOptions = function() { var totalWidth = 0; $('.panel-wrap', self.rootDiv).each(function(index) { - var panelWidth = self.options.panels[index].ratio * self.rootDiv.width(); + var panelWidth = self.fileOptions.panels[index].ratio * self.rootDiv.width(); if ($(this).hasClass('last-panel')) { $(this).css({ left: totalWidth, @@ -323,7 +335,7 @@ Editor.prototype.loadPanelOptions = function() { } $.log('panel:', this, $(this).css('left')); $('.panel-toolbar option', this).each(function() { - if ($(this).attr('p:panel-name') == self.options.panels[index].name) { + if ($(this).attr('p:panel-name') == self.fileOptions.panels[index].name) { $(this).parent('select').val($(this).attr('value')); } }); @@ -340,8 +352,20 @@ Editor.prototype.savePanelOptions = function() { }); }); self.options.panels = panels; + + // Dodaj obecnie oglądany plik do listy recentFiles + var recentFiles = [{fileId: fileId, panels: panels}]; + var count = 1; + $.each(self.options.recentFiles, function(index) { + if (count < 5 && fileId != self.options.recentFiles[index].fileId) { + recentFiles.push(self.options.recentFiles[index]); + count++; + } + }); + self.options.recentFiles = recentFiles; + self.options.lastUpdate = new Date().getTime() / 1000; - $.log($.toJSON(self.options)); + $.log($.toJSON(self.options)); $.cookie('options', $.toJSON(self.options), { expires: 7, path: '/' diff --git a/project/templates/explorer/editor.html b/project/templates/explorer/editor.html index 6ee1cf85..4b08914b 100644 --- a/project/templates/explorer/editor.html +++ b/project/templates/explorer/editor.html @@ -1,6 +1,9 @@ {% extends "base.html" %} {% block extrahead %} + diff --git a/project/templates/explorer/file_list.html b/project/templates/explorer/file_list.html index 48be7f59..4e5a12ad 100644 --- a/project/templates/explorer/file_list.html +++ b/project/templates/explorer/file_list.html @@ -3,6 +3,8 @@ {% block extrahead %} + + {% endblock extrahead %} @@ -45,6 +79,12 @@ $(function() { +
+

Ostatnio oglądane pliki:

+ +
+ {% if perms.explorer.can_add_files %}

Dodaj nowy utwór