+# -*- encoding: utf-8 -*-
import os
from django.db import 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()
} 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() {
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,
}
$.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'));
}
});
});
});
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: '/'
{% 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>
{% 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});
$('#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 %}
</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>