From 889882b4d84fb826afc834040b203dff2fb4a224 Mon Sep 17 00:00:00 2001 From: zuber <marek@stepniowski.com> Date: Tue, 15 Sep 2009 17:33:16 +0200 Subject: [PATCH] =?utf8?q?Zapisywanie=20ustawie=C5=84=20paneli=20dla=205?= =?utf8?q?=20ostatnio=20otwartych=20plik=C3=B3w.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- apps/explorer/models.py | 24 ++++++++++++++ project/static/js/editor.js | 30 +++++++++++++++-- project/templates/explorer/editor.html | 3 ++ project/templates/explorer/file_list.html | 40 +++++++++++++++++++++++ 4 files changed, 94 insertions(+), 3 deletions(-) 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 %} + <script type="text/javascript" charset="utf-8"> + var fileId = '{{ fileid }}'; + </script> <link rel="stylesheet" href="{{STATIC_URL}}css/toolbar.css" type="text/css" /> <link rel="stylesheet" href="{{STATIC_URL}}css/jquery.modal.css" type="text/css" /> <script src="{{STATIC_URL}}js/jquery.lazyload.js" type="text/javascript" charset="utf-8"></script> 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 %} <link rel="stylesheet" href="{{ STATIC_URL }}css/filelist.css" type="text/css" /> <script type="text/javascript" charset="utf-8" src="{{ STATIC_URL }}js/jquery.paginate.js"></script> + <script src="{{STATIC_URL}}js/jquery.json.js" type="text/javascript" charset="utf-8"></script> + <script src="{{STATIC_URL}}js/jquery.cookie.js" type="text/javascript" charset="utf-8"></script> <script type="text/javascript" charset="utf-8"> $(function() { $('#file-list').paginate({itemsPerPage: 15}); @@ -23,6 +25,38 @@ $(function() { $('#file-list').filterItems(); event.preventDefault(); }); + + var defaultOptions = { + panels: [ + { + name: 'htmleditor', + ratio: 0.5 + }, + + { + name: 'gallery', + ratio: 0.5 + } + ], + recentFiles: [], + lastUpdate: 0 + }; + + var options = null; + try { + var cookie = $.cookie('options'); + options = $.secureEvalJSON(cookie); + if (!options) { + options = defaultOptions; + } + } catch (e) { + options = defaultOptions; + } + + $.each(options.recentFiles, function(index) { + var fileId = options.recentFiles[index].fileId; + $('#recent-file-list ul').append('<li><a href="/editor/' + fileId + '/">' + fileId + '</a></li>'); + }); }); </script> {% endblock extrahead %} @@ -45,6 +79,12 @@ $(function() { </div> </div> +<div id="recent-file-list"> + <h2>Ostatnio oglÄ dane pliki:</h2> + <ul> + </ul> +</div> + {% if perms.explorer.can_add_files %} <div class="upload-file-widget"> <h2>Dodaj nowy utwór</h2> -- 2.20.1