From: Łukasz Rekucki Date: Sun, 28 Mar 2010 18:38:34 +0000 (+0200) Subject: Javascript refactoring. History view now displays tags X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/02a98d2af6f1fabf567b575c5f2d818688af1594 Javascript refactoring. History view now displays tags --- diff --git a/apps/toolbar/templates/toolbar/button.html b/apps/toolbar/templates/toolbar/button.html index 8335918a..92c51a18 100644 --- a/apps/toolbar/templates/toolbar/button.html +++ b/apps/toolbar/templates/toolbar/button.html @@ -2,8 +2,8 @@ {% endif %}
    -
  1. - Historia -
  2. + +
  3. + {{ document_meta.title }} +
  4. - {{ document.name }} + Edytor +
  5. + +
  6. + Historia
  7. {% toolbar %} - + - {% include "wiki/history_panel.html" %} + {% include "wiki/history_view.html" %} + {% include "wiki/summary_view.html" %}
    - - +{% include "wiki/save_dialog.html" %} {% endblock %} \ No newline at end of file diff --git a/apps/wiki/templates/wiki/history_panel.html b/apps/wiki/templates/wiki/history_panel.html deleted file mode 100644 index 3edecdee..00000000 --- a/apps/wiki/templates/wiki/history_panel.html +++ /dev/null @@ -1,24 +0,0 @@ - diff --git a/apps/wiki/templates/wiki/history_view.html b/apps/wiki/templates/wiki/history_view.html new file mode 100644 index 00000000..c14cb4de --- /dev/null +++ b/apps/wiki/templates/wiki/history_view.html @@ -0,0 +1,20 @@ + diff --git a/apps/wiki/templates/wiki/save_dialog.html b/apps/wiki/templates/wiki/save_dialog.html new file mode 100644 index 00000000..f49db3f5 --- /dev/null +++ b/apps/wiki/templates/wiki/save_dialog.html @@ -0,0 +1,24 @@ +
    +

    {{ text_save_form.comment.label }}

    +

    {{text_save_form.comment.help_text}}

    + {{ text_save_form.comment }} + + {% if request.user.is_anonymous %} +

    + {{ text_save_form.author.label }}: + {{ text_save_form.author }} + {{ text_save_form.author.help_text }} +

    + {% else %} +

    + {{ text_save_form.stage_completed.label }}: + {{ text_save_form.stage_completed }} + {{ text_save_form.stage_completed.help_text }} +

    + {% endif %} + +

    + + +

    +
    diff --git a/apps/wiki/templates/wiki/summary_view.html b/apps/wiki/templates/wiki/summary_view.html new file mode 100644 index 00000000..3f52aae0 --- /dev/null +++ b/apps/wiki/templates/wiki/summary_view.html @@ -0,0 +1,31 @@ + \ No newline at end of file diff --git a/apps/wiki/urls.py b/apps/wiki/urls.py index 14cb81e4..0c6393cf 100644 --- a/apps/wiki/urls.py +++ b/apps/wiki/urls.py @@ -1,6 +1,7 @@ from django.conf.urls.defaults import * +from django.conf import settings -urlpatterns = patterns('wiki.views', +urlpatterns = patterns('wiki.views', url(r'^$', 'document_list', name='wiki_doclist'), url(r'^gallery/(?P[^/]+)$', @@ -14,7 +15,5 @@ urlpatterns = patterns('wiki.views', url(r'^(?P[^/]+)/diff/(?P\d+)/(?P\d+)$', 'document_diff', name="wiki_diff"), url(r'^(?P[^/]+)$', - 'document_detail', name="wiki_details"), - -) - + 'document_detail', name="wiki_details"), +) \ No newline at end of file diff --git a/apps/wiki/views.py b/apps/wiki/views.py index c3fd6e38..5bf3ce4d 100644 --- a/apps/wiki/views.py +++ b/apps/wiki/views.py @@ -6,7 +6,7 @@ from django.http import HttpResponse, Http404 from django.utils import simplejson as json from wiki.models import Document, DocumentNotFound, getstorage -from wiki.forms import DocumentForm +from wiki.forms import DocumentForm, DocumentTextSaveForm from datetime import datetime from django.utils.encoding import smart_unicode import wlapi @@ -57,7 +57,10 @@ def document_detail(request, name, template_name = 'wiki/document_details.html') request.session['wiki_last_docs'] = last_documents return direct_to_template(request, template_name, extra_context = { - 'document': document, + 'document': document, + 'document_info': document.info, + 'document_meta': document.meta, + 'text_save_form': DocumentTextSaveForm(), }) @never_cache @@ -73,7 +76,7 @@ def document_text(request, name): document = form.save(document_author = request.user.username) return HttpResponse(json.dumps({'text': document.plain_text, 'meta': document.meta(), 'revision': document.revision()})) else: - return HttpResponse(json.dumps({'errors': form.errors})) + return HttpResponse(json.dumps({'errors': list(form.errors)})) else: return HttpResponse(json.dumps({'text': document.plain_text, 'meta': document.meta(), 'revision': document.revision()})) @@ -143,4 +146,4 @@ def document_publish(request, name, version): except wlapi.APICallException, e: result = {"success": False, "reason": str(e)} - return HttpResponse( json.dumps(result), mimetype='application/json') \ No newline at end of file + return HttpResponse( json.dumps(result), mimetype='application/json') \ No newline at end of file diff --git a/lib/vstorage.py b/lib/vstorage.py index 2274a044..527a245d 100644 --- a/lib/vstorage.py +++ b/lib/vstorage.py @@ -354,7 +354,14 @@ class VersionedStorage(object): author = unicode(filectx.user(), "utf-8", 'replace').split('<')[0].strip() comment = unicode(filectx.description(), "utf-8", 'replace') - yield {"version": rev, "date": date, "author": author, "description": comment} + tags = filectx.changectx().tags() + yield { + "version": rev, + "date": date, + "author": author, + "description": comment, + "tag": tags[0] if tags else None, + } def page_revision(self, title, rev): """Get unicode contents of specified revision of the page.""" diff --git a/platforma/config/requirements.txt b/platforma/config/requirements.txt index 0014b59e..0d95ac8c 100644 --- a/platforma/config/requirements.txt +++ b/platforma/config/requirements.txt @@ -9,7 +9,7 @@ git+http://github.com/fnp/librarian.git@master#egg=librarian ## Django Django>=1.1.1,<1.2 sorl-thumbnail>=3.2 -django-maintanancemode>=0.9 +django-maintenancemode>=0.9 # migrations south>=0.6 diff --git a/platforma/settings.py b/platforma/settings.py index 5485b305..0290dd88 100644 --- a/platforma/settings.py +++ b/platforma/settings.py @@ -86,7 +86,7 @@ MIDDLEWARE_CLASSES = ( 'django.middleware.doc.XViewMiddleware', 'maintenancemode.middleware.MaintenanceModeMiddleware', - 'debug_toolbar.middleware.DebugToolbarMiddleware' + # 'debug_toolbar.middleware.DebugToolbarMiddleware' # ) AUTHENTICATION_BACKENDS = ( @@ -114,9 +114,12 @@ COMPRESS_CSS = { 'detail': { 'source_filenames': ( 'css/master.css', + 'css/gallery.css', 'css/history.css', + 'css/summary.css', 'css/html.css', 'css/jquery.autocomplete.css', + 'css/dialogs.css', ), 'output_filename': 'compressed/detail_styles_?.css', }, @@ -143,9 +146,11 @@ COMPRESS_JS = { 'js/wiki/wikiapi.js', 'js/wiki/base.js', 'js/wiki/xslt.js', - 'js/wiki/history.js', + 'js/wiki/history_view.js', + 'js/wiki/summary_view.js', 'js/wiki/source_editor.js', - 'js/wiki/wysiwyg_editor.js', + 'js/wiki/wysiwyg_editor.js', + 'js/wiki/scan_gallery.js', 'js/wiki/main.js', ), 'output_filename': 'compressed/detail_scripts_?.js', @@ -212,17 +217,6 @@ FILEBROWSER_DEFAULT_ORDER = "path_relative" # REPOSITORY_PATH = '/Users/zuber/Projekty/platforma/files/books' IMAGE_DIR = 'images' -# Python logging settings -import logging - -log = logging.getLogger('platforma') -log.setLevel(logging.DEBUG) -ch = logging.StreamHandler() -ch.setLevel(logging.DEBUG) -formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') -ch.setFormatter(formatter) -log.addHandler(ch) - # Import localsettings file, which may override settings defined here try: from localsettings import * @@ -232,16 +226,12 @@ except ImportError: try: LOGGING_CONFIG_FILE except NameError: - LOGGING_CONFIG_FILE = os.path.join(PROJECT_ROOT, + LOGGING_CONFIG_FILE = os.path.join(PROJECT_ROOT, 'config', ('logging.cfg' if not DEBUG else 'logging.cfg.dev')) - try: import logging import logging.config - + logging.config.fileConfig(LOGGING_CONFIG_FILE) except ImportError, exc: - import traceback - traceback.print_exc() - raise - + raise \ No newline at end of file diff --git a/platforma/static/css/dialogs.css b/platforma/static/css/dialogs.css new file mode 100644 index 00000000..026fc9dc --- /dev/null +++ b/platforma/static/css/dialogs.css @@ -0,0 +1,27 @@ +#save_dialog { + display: none; + padding: 5px; + text-align: left; + cursor: auto; + background-color: #E1E1E1; /* #e0ffb8; */ +} + +#save_dialog textarea { + width: 90%; + margin: 0.2em 4%; +} + +.dialog .help_text { + font-size: 11px; + color: #2e3536; +} + +.dialog .action_area { + padding: 1em 0.5em 0.5em; + border-top: 1px solid black; + margin-top: 0.5em; +} + +.dialog p { + margin: 0.5em; +} diff --git a/platforma/static/css/gallery.css b/platforma/static/css/gallery.css new file mode 100644 index 00000000..379abcce --- /dev/null +++ b/platforma/static/css/gallery.css @@ -0,0 +1,60 @@ +/* =========== */ +/* = Gallery = */ +/* =========== */ + +#side-gallery { + position: absolute; + /* overflow: hidden; */ + top: 0px; + right: 0px; + bottom: 0px; + width: 480px; + display: none; + background-color: #FFF; +} + +#side-gallery .error_message +{ + background-color: white; + color: black; + padding: 0.5em 1em; +} + +.change-gallery-panel { + width: 100%; + border-bottom: 1px solid #777; + background-color: #C1C1C1; + margin: 0; + padding: 2px; + z-index: 10; +} + +.gallery-image { + position: absolute; + top: 30px; + right: 0; + bottom: 0; + left: 0; + margin: 0; + border: none; + background-color: transparent; + overflow: hidden; +} + +.gallery-image img { + position: absolute; + -moz-drag: none; + user-select: none; + -webkit-user-select: none; + -khtml-user-select: none; + -moz-user-select: none; + cursor: pointer; + + background-color: white; + min-height: 100px; + min-width: 100px; +} + +.gallery-image img[src=''] { + background-color: red; +} diff --git a/platforma/static/css/history.css b/platforma/static/css/history.css index 26ab7f9e..5028e230 100644 --- a/platforma/static/css/history.css +++ b/platforma/static/css/history.css @@ -1,8 +1,86 @@ +#history-view { + overflow: auto; + position: absolute; + top: 30px; /* 0 for no toolbar, 30 for toolbar */ + bottom: 0px; + left: 0px; + right: 0px; + z-index: 1; +} + +/* + * File History + */ +#changes-list { + margin: 0.5em 0.2em; +} + +#changes-list div { + position: relative; + padding: 0.5em; + margin: 0.5em; +} + +#changes-list div:hover { + background-color: #f0f0f0; +} + +#changes-list div.selected { + background-color: #ffec63; +} + +#changes-list span.tag { + display: inline-block; + visibility: hidden; + width: 60px; + margin: 0 0.5em 0 0; + font-size: 11px; + padding: 3px 2px; + text-align: center; + color: black; + background: #add8e6; + cursor: pointer; + vertical-align: middle; + -moz-border-radius: 10px; + -webkit-border-radius: 10px; + border-radius: 10px; +} + +#changes-list div:hover span.tag { + visibility: visible; +} + +#changes-list span.tag:hover { + background: #bde8f6; +} + +#changes-list span[data-version-tag] { + visibility: visible; + border: 1px solid black; + + color: black; +} + +#changes-list span[data-stub-value='version'] { + font-weight: bold; +} + +#changes-list span[data-stub-value='date'], +#changes-list span[data-stub-value='author'] +{ + font-size: 11px; + color: gray; +} + + +/* + * Graphical DIFF view + * + */ #history-view .diff_table { width: 90%; } - -/* DIFFS */ + .diff_table { border-width: 1px; border-style: solid; diff --git a/platforma/static/css/master.css b/platforma/static/css/master.css index b1bcdf79..68d82190 100644 --- a/platforma/static/css/master.css +++ b/platforma/static/css/master.css @@ -21,34 +21,29 @@ body { position: absolute; top: 0px; bottom: 0; - right: 0;; - width: 13px; - background: #C1C1C1 url(../img/gallery.png) no-repeat scroll center center; - text- - border-left: 1px solid #999; - border-right: 1px solid #999; + right: 0; + width: 26px; + background: #C1C1C1 url(../img/gallery.png) no-repeat scroll center center; + border-left: 2px solid #999; + border-right: 2px solid #999; cursor: pointer; } .vsplitbar:hover { - background-color: #e6e6fa; -} - -.vsplitbar.active { - background- - + background-color: yellow; + border-color: orange; } -#source-editor, #simple-editor, #history-viewer { +.editor { position: absolute; top: 0px; bottom: 0; left: 0; - right: 15px; + right: 30px; overflow: hidden; } -#html-view, #history-view { +#html-view { overflow: auto; position: absolute; top: 30px; @@ -58,18 +53,6 @@ body { z-index: 1; } -#sidebar { - position: absolute; - overflow: hidden; - top: 0px; - right: 0; - bottom: 0; - width: 0; - display: none; - background-color: #FFF; -} - - #splitter { position: fixed; top: 31px; @@ -181,7 +164,7 @@ body { margin: 0; padding: 2px; z-index: 100; -/* height: 22px;*/ + height: 28px; } .toolbar button { @@ -235,41 +218,6 @@ button::-moz-focus-inner { p { margin: 0;} -/* =========== */ -/* = Gallery = */ -/* =========== */ -.change-gallery-panel { - width: 100%; - border-bottom: 1px solid #777; - background-color: #C1C1C1; - margin: 0; - padding: 2px; - z-index: 10; -} - -.gallery-image { - position: absolute; - top: 30px; - right: 0; - bottom: 0; - left: 0; - margin: 0; - border: none; - background-color: #000; - overflow: hidden; -} - -.gallery-image img { - position: absolute; - -moz-drag: none; - user-select: none; - -webkit-user-select: none; - -khtml-user-select: none; - -moz-user-select: none; - cursor: pointer; -} - - #body-wrap { height: 100%; width: 100%; @@ -307,9 +255,6 @@ p { margin: 0;} margin-top: -6px; } - - - /* * CodeMirror */ @@ -350,4 +295,9 @@ p { margin: 0;} background-color: #FAFAFA; border: 1px solid #DDD; /* -webkit-transition: all 1s linear;*/ -} \ No newline at end of file +} + +.blockOverlay { + background-color: black; + opacity: 0.4; +} diff --git a/platforma/static/css/summary.css b/platforma/static/css/summary.css new file mode 100644 index 00000000..9f8def02 --- /dev/null +++ b/platforma/static/css/summary.css @@ -0,0 +1,21 @@ +#summary-view-editor { + background: white; +} + +#summary-view { + padding: 1em; +} + +#summary-view .book-cover { + float: left; + margin: 1em; + max-height: 300px; +} + +#summary-view form p { + margin: 0.5em; +} + +#summary-view form label { + font-weight: bold; +} diff --git a/platforma/static/js/jquery.elastic.js b/platforma/static/js/jquery.elastic.js deleted file mode 100644 index a0d87199..00000000 --- a/platforma/static/js/jquery.elastic.js +++ /dev/null @@ -1,117 +0,0 @@ -/** -* @name Elastic -* @descripton Elastic is Jquery plugin that grow and shrink your textareas automaticliy -* @version 1.6.3 -* @requires Jquery 1.2.6+ -* -* @author Jan Jarfalk -* @author-email jan.jarfalk@unwrongest.com -* @author-website http://www.unwrongest.com -* -* @licens MIT License - http://www.opensource.org/licenses/mit-license.php -*/ - -(function(jQuery){ - jQuery.fn.extend({ - elastic: function() { - - // We will create a div clone of the textarea - // by copying these attributes from the textarea to the div. - var mimics = [ - 'paddingTop', - 'paddingRight', - 'paddingBottom', - 'paddingLeft', - 'fontSize', - 'lineHeight', - 'fontFamily', - 'width', - 'fontWeight']; - - return this.each( function() { - - // Elastic only works on textareas - if ( this.type != 'textarea' ) { - return false; - } - - var $textarea = jQuery(this), - $twin = jQuery('
    ').css({'position': 'absolute','display':'none','word-wrap':'break-word'}), - lineHeight = parseInt($textarea.css('line-height'),10) || parseInt($textarea.css('font-size'),'10'), - minheight = parseInt($textarea.css('height'),10) || lineHeight*3, - maxheight = parseInt($textarea.css('max-height'),10) || Number.MAX_VALUE, - goalheight = 0, - i = 0; - - // Opera returns max-height of -1 if not set - if (maxheight < 0) { maxheight = Number.MAX_VALUE; } - - // Append the twin to the DOM - // We are going to meassure the height of this, not the textarea. - $twin.appendTo($textarea.parent()); - - // Copy the essential styles (mimics) from the textarea to the twin - var i = mimics.length; - while(i--){ - $twin.css(mimics[i].toString(),$textarea.css(mimics[i].toString())); - } - - - // Sets a given height and overflow state on the textarea - function setHeightAndOverflow(height, overflow){ - curratedHeight = Math.floor(parseInt(height,10)); - if($textarea.height() != curratedHeight){ - $textarea.css({'height': curratedHeight + 'px','overflow':overflow}); - - } - } - - - // This function will update the height of the textarea if necessary - function update() { - - // Get curated content from the textarea. - var textareaContent = $textarea.val().replace(/&/g,'&').replace(/ /g, ' ').replace(/<|>/g, '>').replace(/\n/g, '
    '); - - var twinContent = $twin.html(); - - if(textareaContent+' ' != twinContent){ - - // Add an extra white space so new rows are added when you are at the end of a row. - $twin.html(textareaContent+' '); - - // Change textarea height if twin plus the height of one line differs more than 3 pixel from textarea height - if(Math.abs($twin.height()+lineHeight - $textarea.height()) > 3){ - - var goalheight = $twin.height()+lineHeight; - if(goalheight >= maxheight) { - setHeightAndOverflow(maxheight,'auto'); - } else if(goalheight <= minheight) { - setHeightAndOverflow(minheight,'hidden'); - } else { - setHeightAndOverflow(goalheight,'hidden'); - } - - } - - } - - } - - // Hide scrollbars - $textarea.css({'overflow':'hidden'}); - - // Update textarea size on keyup - $textarea.keyup(function(){ update(); }); - - // And this line is to catch the browser paste event - $textarea.live('input paste',function(e){ setTimeout( update, 250); }); - - // Run update once when elastic is initialized - update(); - - }); - - } - }); -})(jQuery); \ No newline at end of file diff --git a/platforma/static/js/wiki/base.js b/platforma/static/js/wiki/base.js index 8c626d98..535749c8 100644 --- a/platforma/static/js/wiki/base.js +++ b/platforma/static/js/wiki/base.js @@ -12,7 +12,10 @@ $.wiki.Perspective.prototype.onEnter = function () { // called when perspective in initialized - document.location.hash = '#' + this.perspective_id; + if (this.perspective_id) { + document.location.hash = '#' + this.perspective_id; + } + console.log(document.location.hash); }; diff --git a/platforma/static/js/wiki/history.js b/platforma/static/js/wiki/history.js deleted file mode 100644 index 87def8b9..00000000 --- a/platforma/static/js/wiki/history.js +++ /dev/null @@ -1,92 +0,0 @@ -(function($){ - - function fetchDiff(success, failed){ - var changelist = $('#changes-list'); - var rev_a = $("input[name='rev_from']:checked", changelist); - var rev_b = $("input[name='rev_to']:checked", changelist); - - if (rev_a.length != 1 || rev_b.length != 1) { - window.alert("Musisz zaznaczyć dwie wersje do porównania."); - failed(); - } - - if (rev_a.val() == rev_b.val()) { - window.alert("Musisz zaznaczyć dwie różne wersje do porównania."); - failed(); - } - - $.blockUI({ - message: 'Wczytywanie porównania...' - }); - - $.ajax({ - url: document.location.href + '/diff/' + rev_a.val() + '/' + rev_b.val(), - dataType: 'html', - error: function(){ - $.unblockUI(); - error(); - }, - success: function(data){ - var diffview = $('#diff-view'); - diffview.html(data); - diffview.show(); - $.unblockUI(); - success(); - } - }); - } - - function HistoryPerspective(doc, callback) { - this.perspective_id = 'HistoryPerspective'; - this.doc = doc; - - // first time page is rendered - $('#make-diff-button').click(fetchDiff); - callback.call(this); - }; - - HistoryPerspective.prototype = new $.wiki.Perspective(); - - HistoryPerspective.prototype.freezeState = function(){ - // must - }; - - HistoryPerspective.prototype.onEnter = function(success, failure) - { - $.wiki.Perspective.prototype.onEnter.call(this); - - $.blockUI({ - message: 'Odświeżanie historii...' - }); - - function _finalize(s) { - $.unblockUI(); - - if(s) { if(success) success(); } - else { if(failure) failure(); } - } - - function _failure(doc, message) { - $('#history-view .message-box').html('Nie udało się odświeżyć historii:' + message).show(); - _finalize(false); - }; - - function _success(doc, data) { - $('#history-view .message-box').hide(); - var changes_list = $('#changes-list'); - var $stub = $('#history-view .row-stub'); - changes_list.html(''); - - $.each(data, function(){ - $.wiki.renderStub(changes_list, $stub, this); - }); - - _finalize(true); - }; - - return this.doc.fetchHistory({success: _success, failure: _failure}); - }; - - $.wiki.HistoryPerspective = HistoryPerspective; - -})(jQuery); diff --git a/platforma/static/js/wiki/history_view.js b/platforma/static/js/wiki/history_view.js new file mode 100644 index 00000000..0f35ca3b --- /dev/null +++ b/platforma/static/js/wiki/history_view.js @@ -0,0 +1,106 @@ +(function($){ + + function fetchDiff(success, failed){ + var changelist = $('#changes-list'); + + var selected = $('div.selected', changelist); + + if (selected.length != 2) { + window.alert("Musisz zaznaczyć dokładnie dwie wersje do porównania."); + if(failed) failed(); + } + + $.blockUI({ + message: 'Wczytywanie porównania...' + }); + + $.ajax({ + method: "GET", + url: document.location.href + '/diff/' + rev_a.val() + '/' + rev_b.val(), + dataType: 'html', + error: function(){ + $.unblockUI(); + if(failed) failed('Nie udało się wczytać porównania z serwera.'); + }, + success: function(data){ + var diffview = $('#diff-view'); + diffview.html(data); + diffview.show(); + $.unblockUI(); + if(success) success(data); + } + }); + } + + function HistoryPerspective(doc, callback) { + this.perspective_id = 'HistoryPerspective'; + this.doc = doc; + + // first time page is rendered + $('#make-diff-button').click(fetchDiff); + + $('#changes-list div').live('click', function() { + var $this = $(this); + if($this.hasClass('selected')) + return $this.removeClass('selected'); + + if($("#changes-list div.selected").length < 2) + return $this.addClass('selected'); + }); + + $('#changes-list span.tag').live('click', function(event) { + return false; + }); + + callback.call(this); + }; + + HistoryPerspective.prototype = new $.wiki.Perspective(); + + HistoryPerspective.prototype.freezeState = function(){ + // must + }; + + HistoryPerspective.prototype.onEnter = function(success, failure) + { + $.wiki.Perspective.prototype.onEnter.call(this); + + $.blockUI({ + message: 'Odświeżanie historii...' + }); + + function _finalize(s) { + $.unblockUI(); + + if(s) { if(success) success(); } + else { if(failure) failure(); } + } + + function _failure(doc, message) { + $('#history-view .message-box').html('Nie udało się odświeżyć historii:' + message).show(); + _finalize(false); + }; + + function _success(doc, data) { + $('#history-view .message-box').hide(); + var changes_list = $('#changes-list'); + var $stub = $('#history-view .row-stub'); + changes_list.html(''); + + $.each(data, function(){ + $.wiki.renderStub(changes_list, $stub, this); + }); + + $('span[data-version-tag]', changes_list).each(function() { + $(this).text($(this).attr('data-version-tag')); + }); + + _finalize(true); + }; + + return this.doc.fetchHistory({success: _success, failure: _failure}); + }; + + $.wiki.HistoryPerspective = HistoryPerspective; + +})(jQuery); diff --git a/platforma/static/js/wiki/main.js b/platforma/static/js/wiki/main.js index 270bc7cc..802926c2 100644 --- a/platforma/static/js/wiki/main.js +++ b/platforma/static/js/wiki/main.js @@ -6,216 +6,16 @@ if (!window.console) { } } -THEMES = ['Alkohol', 'Ambicja', 'Anioł', 'Antysemityzm', 'Arkadia', 'Artysta', 'Bezdomność', 'Bezpieczeństwo', 'Bieda', 'Bijatyka', 'Błazen', 'Błądzenie', 'Błoto', 'Bogactwo', 'Bóg', 'Brat', 'Bunt', 'Buntownik', 'Burza', 'Car', 'Carpe diem', 'Ciemność', 'Cień', 'Cisza', 'Chciwość', 'Chleb', 'Chłop', 'Choroba', 'Chrystus', 'Chrzest', 'Ciało', 'Cierpienie', 'Cmentarz', 'Cnota', 'Córka', 'Cud', 'Czarownika', 'Czary', 'Czas', 'Czyn', 'Czyściec', 'Dama', 'Danse macabre', 'Deszcz', 'Diabeł', 'Dobro', 'Dom', 'Dorosłość', 'Drzewo', 'Duch', 'Dusza', 'Duma', 'Dworek', 'Dworzanin', 'Dwór', 'Dzieciństwo', 'Dziecko', 'Dziedzictwo', 'Dziewictwo', 'Dźwięk', 'Egzorcyzm', 'Elita', 'Emigrant', 'Fałsz', 'Filozof', 'Fircyk', 'Flirt', 'Głupiec', 'Głupota', 'Głód', 'Gospodarz', 'Gospodyni', 'Gość', 'Gotycyzm', 'Góra', 'Gra', 'Grób', 'Grzech', 'Grzeczność', 'Gwiazda', 'Handel', 'Hańba', 'Historia', 'Honor', 'Idealista', 'Imię', 'Interes', 'Jabłka', 'Jedzenie', 'Jesień', 'Kaleka', 'Kara', 'Karczma', 'Klęska', 'Kłamstwo', 'Kłótnia', 'Kobieta', 'Kobieta demoniczna', 'Kobieta "upadła"', 'Kochanek', 'Kochanek romantyczny', 'Kolonializm', 'Kondycja ludzka', 'Konflikt', 'Konflikt wewnętrzny', 'Koniec świata', 'Koń', 'Korzyść', 'Kot', 'Kradzież', 'Krew', 'Król', 'Krzywda', 'Ksiądz', 'Książka', 'Księżyc', 'Kuchnia', 'Kuszenie', 'Kwiaty', 'Labirynt', 'Las', 'Lato', 'Lekarz', 'Lenistwo', 'List', 'Liberat', 'Los', 'Lud', 'Lustro', 'Łzy', 'Małżeństwo', 'Marzenie', 'Maska', 'Maszyna', 'Matka', 'Matka Boska', 'Mądrość', 'Mąż', 'Melancholia', 'Mędrzec', 'Mężczyzna', 'Miasto', 'Mieszczanin', 'Miłosierdzie', 'Miłość', 'Miłość niespełniona', 'Miłość platoniczna', 'Miłość romantyczna', 'Miłość silniejsza niż śmierć', 'Miłość spełniona', 'Miłość tragiczna', 'Mizoginia', 'Młodość', 'Moda', 'Modlitwa', 'Morderstwo', 'Morze', 'Motyl', 'Mucha', 'Muzyka', 'Narodziny', 'Naród', 'Natura', 'Nauczyciel', 'Nauczycielka', 'Nauka', 'Niebezpieczeństwo', 'Niedziela', 'Niemiec', 'Nienawiść', 'Nieśmiertelność', 'Niewola', 'Noc', 'Nuda', 'Obcy', 'Obłok', 'Obowiązek', 'Obraz świata', 'Obrzędy', 'Obyczaje', 'Obywatel', 'Odrodzenie przez grób', 'Odwaga', 'Ofiara', 'Ogień', 'Ogród', 'Ojciec', 'Ojczyzna', 'Oko', 'Okręt', 'Okrucieństwo', 'Omen', 'Opieka', 'Organizm', 'Otchłań', 'Pająk', 'Pamięć', 'Pan', 'Panna młoda', 'Państwo', 'Patriota', 'Piekło', 'Pielgrzym', 'Pieniądz', 'Pies', 'Piętno', 'Pijaństwo', 'Piwnica', 'Plotka', 'Pobożność', 'Pocałunek', 'Pochlebstwo', 'Poeta', 'Poetka', 'Poezja', 'Podróż', 'Podstęp', 'Pogrzeb', 'Pojedynek', 'Pokora', 'Pokusa', 'Polak', 'Polityka', 'Polowanie', 'Polska', 'Portret', 'Porwanie', 'Poświęcenie', 'Potwór', 'Powstanie', 'Powstaniec', 'Pozory', 'Pozycja społeczna', 'Pożar', 'Pożądanie', 'Praca', 'Praca u podstaw', 'Praca organiczna', 'Prawda', 'Prawnik', 'Prometeusz', 'Proroctwo', 'Prorok', 'Próżność', 'Przebranie', 'Przeczucie', 'Przedmurze chrześcijaństwa', 'Przekleństwo', 'Przekupstwo', 'Przemiana', 'Przemijanie', 'Przemoc', 'Przestrzeń', 'Przyjaźń', 'Przyroda nieożywiona', 'Przysięga', 'Przywódca', 'Ptak', 'Pustynia', 'Pycha', 'Raj', 'Realista', 'Religia', 'Rewolucja', 'Robak', 'Robotnik', 'Rodzina', 'Rosja', 'Rosjanin', 'Rośliny', 'Rozczarowanie', 'Rozpacz', 'Rozstanie', 'Rozum', 'Ruiny', 'Rycerz', 'Rzeka', 'Salon', 'Samobójstwo', 'Samolubstwo', 'Samotnik', 'Samotność', 'Sarmata', 'Sąsiad', 'Sąd', 'Sąd Ostateczny', 'Sen', 'Serce', 'Sędzia', 'Sielanka', 'Sierota', 'Siła', 'Siostra', 'Sława', 'Słońce', 'Słowo', 'Sługa', 'Służalczość', 'Skąpiec', 'Sobowtór', 'Społecznik', 'Spowiedź', 'Sprawiedliwość', 'Starość', 'Strach', 'Strój', 'Stworzenie', 'Sumienie', 'Swaty', 'Syberia', 'Syn', 'Syn marnotrawny', 'Syzyf', 'Szaleniec', 'Szaleństwo', 'Szantaż', 'Szatan', 'Szczęście', 'Szkoła', 'Szlachcic', 'Szpieg', 'Sztuka', 'Ślub', 'Śmiech', 'Śmierć', 'Śmierć bohaterska', 'Śpiew', 'Światło', 'Świętoszek', 'Święty', 'Świt', 'Tajemnica', 'Taniec', 'Tchórzostwo', 'Teatr', 'Testament', 'Tęsknota', 'Theatrum mundi', 'Tłum', 'Trucizna', 'Trup', 'Twórczość', 'Uczeń', 'Uczta', 'Uroda', 'Umiarkowanie', 'Upadek', 'Upiór', 'Urzędnik', 'Vanitas', 'Walka', 'Walka klas', 'Wampir', 'Warszawa', 'Wąż', 'Wdowa', 'Wdowiec', 'Wesele', 'Wiatr', 'Wierność', 'Wierzenia', 'Wieś', 'Wiedza', 'Wieża Babel', 'Więzienie', 'Więzień', 'Wina', 'Wino', 'Wiosna', 'Wizja', 'Władza', 'Własność', 'Woda', 'Wojna', 'Wojna pokoleń', 'Wolność', 'Wróg', 'Wspomnienia', 'Współpraca', 'Wygnanie', 'Wyrzuty sumienia', 'Wyspa', 'Wzrok', 'Zabawa', 'Zabobony', 'Zamek', 'Zaręczyny', 'Zaświaty', 'Zazdrość', 'Zbawienie', 'Zbrodnia', 'Zbrodniarz', 'Zdrada', 'Zdrowie', 'Zemsta', 'Zesłaniec', 'Ziarno', 'Ziemia', 'Zima', 'Zło', 'Złodziej', 'Złoty wiek', 'Zmartwychwstanie', 'Zwątpienie', 'Zwierzęta', 'Zwycięstwo', 'Å»ałoba', 'Å»ebrak', 'Å»ołnierz', 'Å»ona', 'Å»ycie jako wędrówka', 'Å»ycie snem', 'Å»yd', 'Å»ywioły', 'Oświadczyny'] +THEMES = ['Alkohol', 'Ambicja', 'Anioł', 'Antysemityzm', 'Arkadia', 'Artysta', 'Bezdomność', 'Bezpieczeństwo', 'Bieda', 'Bijatyka', 'Błazen', 'Błądzenie', 'Błoto', 'Bogactwo', 'Bóg', 'Brat', 'Bunt', 'Buntownik', 'Burza', 'Car', 'Carpe diem', 'Ciemność', 'Cień', 'Cisza', 'Chciwość', 'Chleb', 'Chłop', 'Choroba', 'Chrystus', 'Chrzest', 'Ciało', 'Cierpienie', 'Cmentarz', 'Cnota', 'Córka', 'Cud', 'Czarownika', 'Czary', 'Czas', 'Czyn', 'Czyściec', 'Dama', 'Danse macabre', 'Deszcz', 'Diabeł', 'Dobro', 'Dom', 'Dorosłość', 'Drzewo', 'Duch', 'Dusza', 'Duma', 'Dworek', 'Dworzanin', 'Dwór', 'Dzieciństwo', 'Dziecko', 'Dziedzictwo', 'Dziewictwo', 'Dźwięk', 'Egzorcyzm', 'Elita', 'Emigrant', 'Fałsz', 'Filozof', 'Fircyk', 'Flirt', 'Głupiec', 'Głupota', 'Głód', 'Gospodarz', 'Gospodyni', 'Gość', 'Gotycyzm', 'Góra', 'Gra', 'Grób', 'Grzech', 'Grzeczność', 'Gwiazda', 'Handel', 'Hańba', 'Historia', 'Honor', 'Idealista', 'Imię', 'Interes', 'Jabłka', 'Jedzenie', 'Jesień', 'Kaleka', 'Kara', 'Karczma', 'Klęska', 'Kłamstwo', 'Kłótnia', 'Kobieta', 'Kobieta demoniczna', 'Kobieta "upadła"', 'Kochanek', 'Kochanek romantyczny', 'Kolonializm', 'Kondycja ludzka', 'Konflikt', 'Konflikt wewnętrzny', 'Koniec świata', 'Koń', 'Korzyść', 'Kot', 'Kradzież', 'Krew', 'Król', 'Krzywda', 'Ksiądz', 'Książka', 'Księżyc', 'Kuchnia', 'Kuszenie', 'Kwiaty', 'Labirynt', 'Las', 'Lato', 'Lekarz', 'Lenistwo', 'List', 'Liberat', 'Los', 'Lud', 'Lustro', 'Łzy', 'Małżeństwo', 'Marzenie', 'Maska', 'Maszyna', 'Matka', 'Matka Boska', 'Mądrość', 'Mąż', 'Melancholia', 'Mędrzec', 'Mężczyzna', 'Miasto', 'Mieszczanin', 'Miłosierdzie', 'Miłość', 'Miłość niespełniona', 'Miłość platoniczna', 'Miłość romantyczna', 'Miłość silniejsza niż śmierć', 'Miłość spełniona', 'Miłość tragiczna', 'Mizoginia', 'Młodość', 'Moda', 'Modlitwa', 'Morderstwo', 'Morze', 'Motyl', 'Mucha', 'Muzyka', 'Narodziny', 'Naród', 'Natura', 'Nauczyciel', 'Nauczycielka', 'Nauka', 'Niebezpieczeństwo', 'Niedziela', 'Niemiec', 'Nienawiść', 'Nieśmiertelność', 'Niewola', 'Noc', 'Nuda', 'Obcy', 'Obłok', 'Obowiązek', 'Obraz świata', 'Obrzędy', 'Obyczaje', 'Obywatel', 'Odrodzenie przez grób', 'Odwaga', 'Ofiara', 'Ogień', 'Ogród', 'Ojciec', 'Ojczyzna', 'Oko', 'Okręt', 'Okrucieństwo', 'Omen', 'Opieka', 'Organizm', 'Otchłań', 'Pająk', 'Pamięć', 'Pan', 'Panna młoda', 'Państwo', 'Patriota', 'Piekło', 'Pielgrzym', 'Pieniądz', 'Pies', 'Piętno', 'Pijaństwo', 'Piwnica', 'Plotka', 'Pobożność', 'Pocałunek', 'Pochlebstwo', 'Poeta', 'Poetka', 'Poezja', 'Podróż', 'Podstęp', 'Pogrzeb', 'Pojedynek', 'Pokora', 'Pokusa', 'Polak', 'Polityka', 'Polowanie', 'Polska', 'Portret', 'Porwanie', 'Poświęcenie', 'Potwór', 'Powstanie', 'Powstaniec', 'Pozory', 'Pozycja społeczna', 'Pożar', 'Pożądanie', 'Praca', 'Praca u podstaw', 'Praca organiczna', 'Prawda', 'Prawnik', 'Prometeusz', 'Proroctwo', 'Prorok', 'Próżność', 'Przebranie', 'Przeczucie', 'Przedmurze chrześcijaństwa', 'Przekleństwo', 'Przekupstwo', 'Przemiana', 'Przemijanie', 'Przemoc', 'Przestrzeń', 'Przyjaźń', 'Przyroda nieożywiona', 'Przysięga', 'Przywódca', 'Ptak', 'Pustynia', 'Pycha', 'Raj', 'Realista', 'Religia', 'Rewolucja', 'Robak', 'Robotnik', 'Rodzina', 'Rosja', 'Rosjanin', 'Rośliny', 'Rozczarowanie', 'Rozpacz', 'Rozstanie', 'Rozum', 'Ruiny', 'Rycerz', 'Rzeka', 'Salon', 'Samobójstwo', 'Samolubstwo', 'Samotnik', 'Samotność', 'Sarmata', 'Sąsiad', 'Sąd', 'Sąd Ostateczny', 'Sen', 'Serce', 'Sędzia', 'Sielanka', 'Sierota', 'Siła', 'Siostra', 'Sława', 'Słońce', 'Słowo', 'Sługa', 'Służalczość', 'Skąpiec', 'Sobowtór', 'Społecznik', 'Spowiedź', 'Sprawiedliwość', 'Starość', 'Strach', 'Strój', 'Stworzenie', 'Sumienie', 'Swaty', 'Syberia', 'Syn', 'Syn marnotrawny', 'Syzyf', 'Szaleniec', 'Szaleństwo', 'Szantaż', 'Szatan', 'Szczęście', 'Szkoła', 'Szlachcic', 'Szpieg', 'Sztuka', 'Ślub', 'Śmiech', 'Śmierć', 'Śmierć bohaterska', 'Śpiew', 'Światło', 'Świętoszek', 'Święty', 'Świt', 'Tajemnica', 'Taniec', 'Tchórzostwo', 'Teatr', 'Testament', 'Tęsknota', 'Theatrum mundi', 'Tłum', 'Trucizna', 'Trup', 'Twórczość', 'Uczeń', 'Uczta', 'Uroda', 'Umiarkowanie', 'Upadek', 'Upiór', 'Urzędnik', 'Vanitas', 'Walka', 'Walka klas', 'Wampir', 'Warszawa', 'Wąż', 'Wdowa', 'Wdowiec', 'Wesele', 'Wiatr', 'Wierność', 'Wierzenia', 'Wieś', 'Wiedza', 'Wieża Babel', 'Więzienie', 'Więzień', 'Wina', 'Wino', 'Wiosna', 'Wizja', 'Władza', 'Własność', 'Woda', 'Wojna', 'Wojna pokoleń', 'Wolność', 'Wróg', 'Wspomnienia', 'Współpraca', 'Wygnanie', 'Wyrzuty sumienia', 'Wyspa', 'Wzrok', 'Zabawa', 'Zabobony', 'Zamek', 'Zaręczyny', 'Zaświaty', 'Zazdrość', 'Zbawienie', 'Zbrodnia', 'Zbrodniarz', 'Zdrada', 'Zdrowie', 'Zemsta', 'Zesłaniec', 'Ziarno', 'Ziemia', 'Zima', 'Zło', 'Złodziej', 'Złoty wiek', 'Zmartwychwstanie', 'Zwątpienie', 'Zwierzęta', 'Zwycięstwo', 'Å»ałoba', 'Å»ebrak', 'Å»ołnierz', 'Å»ona', 'Å»ycie jako wędrówka', 'Å»ycie snem', 'Å»yd', 'Å»ywioły', 'Oświadczyny']; -function gallery(element, url){ - var element = $(element); - var imageDimensions = {}; - element.data('images', []); - - function changePage(pageNumber){ - $('.gallery-image img', element).attr('src', element.data('images')[pageNumber - 1]); - } - - function normalizeNumber(pageNumber){ - // Numer strony musi być pomiędzy 1 a najwyższym numerem - var pageCount = element.data('images').length; - pageNumber = parseInt(pageNumber, 10); - - if (!pageNumber || pageNumber == NaN || pageNumber == Infinity || pageNumber == -Infinity) { - return 1; - } - else - if (pageNumber < 1) { - return 1; - } - else - if (pageNumber > pageCount) { - return pageCount; - } - else { - return pageNumber; - } - } - - var pn = $('.page-number', element); - pn.change(function(event){ - event.preventDefault(); - var n = normalizeNumber(pn.val()); - pn.val(n); - changePage(n); - }); - $('.previous-page', element).click(function(){ - pn.val(normalizeNumber(pn.val()) - 1); - pn.change(); - }); - $('.next-page', element).click(function(){ - pn.val(normalizeNumber(pn.val()) + 1); - pn.change(); - }); - - - var image = $('.gallery-image img', element).attr('unselectable', 'on'); - var origin = {}; - var imageOrigin = {}; - var zoomFactor = 1; - - $('.zoom-in', element).click(function(){ - zoomFactor = Math.min(2, zoomFactor + 0.2); - zoom(); - }); - $('.zoom-out', element).click(function(){ - zoomFactor = Math.max(0.2, zoomFactor - 0.2); - zoom(); - }); - $('.change-gallery', element).click(function(){ - $('.chosen-gallery').val($('#document-meta .gallery').html() || '/platforma/gallery/'); - $('.gallery-image').animate({ - top: 60 - }, 200); - $('.chosen-gallery').focus(); - }); - $('.change-gallery-ok', element).click(function(){ - if ($('#document-meta .gallery').length == 0) { - $('').appendTo('#document-meta'); - } - $('#document-meta .gallery').html($('.chosen-gallery').val()); - updateGallery($('.chosen-gallery').val()); - $('.gallery-image').animate({ - top: 30 - }, 200); - }); - $('.change-gallery-cancel', element).click(function(){ - $('.gallery-image').animate({ - top: 30 - }, 200); - }); - - $('.gallery-image img', element).load(function(){ - image.css({ - width: null, - height: null - }); - imageDimensions = { - width: $(this).width() * zoomFactor, - height: $(this).height() * zoomFactor, - originWidth: $(this).width(), - originHeight: $(this).height(), - galleryWidth: $(this).parent().width(), - galleryHeight: $(this).parent().height() - }; - - if (!(imageDimensions.width && imageDimensions.height)) { - setTimeout(function(){ - $('.gallery-image img', element).load(); - }, 100); - } - var position = normalizePosition(image.position().left, image.position().top, imageDimensions.galleryWidth, imageDimensions.galleryHeight, imageDimensions.width, imageDimensions.height); - image.css({ - left: position.x, - top: position.y, - width: $(this).width() * zoomFactor, - height: $(this).height() * zoomFactor - }); - }); - - $(window).resize(function(){ - imageDimensions.galleryWidth = image.parent().width(); - imageDimensions.galleryHeight = image.parent().height(); - }); - - function bounds(galleryWidth, galleryHeight, imageWidth, imageHeight){ - return { - maxX: 0, - maxY: 0, - minX: galleryWidth - imageWidth, - minY: galleryHeight - imageHeight - } - } - - function normalizePosition(x, y, galleryWidth, galleryHeight, imageWidth, imageHeight){ - var b = bounds(galleryWidth, galleryHeight, imageWidth, imageHeight); - return { - x: Math.min(b.maxX, Math.max(b.minX, x)), - y: Math.min(b.maxY, Math.max(b.minY, y)) - } - } - - function onMouseMove(event){ - var position = normalizePosition(event.clientX - origin.x + imageOrigin.left, event.clientY - origin.y + imageOrigin.top, imageDimensions.galleryWidth, imageDimensions.galleryHeight, imageDimensions.width, imageDimensions.height); - image.css({ - position: 'absolute', - top: position.y, - left: position.x - }); - return false; - } - - function setZoom(factor){ - zoomFactor = factor; - } - - function zoom(){ - imageDimensions.width = imageDimensions.originWidth * zoomFactor; - imageDimensions.height = imageDimensions.originHeight * zoomFactor; - var position = normalizePosition(image.position().left, image.position().top, imageDimensions.galleryWidth, imageDimensions.galleryHeight, imageDimensions.width, imageDimensions.height); - image.css({ - width: imageDimensions.width, - height: imageDimensions.height, - left: position.x, - top: position.y - }); - - } - - function onMouseUp(event){ - $(document).unbind('mousemove.gallery').unbind('mouseup.gallery'); - return false; - } - - image.bind('mousedown', function(event){ - origin = { - x: event.clientX, - y: event.clientY - }; - imageOrigin = image.position(); - $(document).bind('mousemove.gallery', onMouseMove).bind('mouseup.gallery', onMouseUp); - return false; - }); - - function updateGallery(url){ - $.ajax({ - url: url, - type: 'GET', - dataType: 'json', - - success: function(data){ - element.data('images', data); - pn.val(1); - pn.change(); - $('.gallery-image img', element).show(); - }, - - error: function(data){ - element.data('images', []); - pn.val(1); - pn.change(); - $('.gallery-image img', element).hide(); - } - }); - } - - if (url) { - updateGallery(url); - } -} - -$(function() { - // gallery('#sidebar', $('#document-meta .gallery').html()); - +$(function() +{ var tabs = $('ol#tabs li'); var perspectives = {}; + var gallery = null; var wikidoc = new $.wikiapi.WikiDocument("document-meta"); + + $.blockUI.defaults.baseZ = 10000; function activePerspective() { return perspectives[$("#tabs " + document.location.hash + "-tab").attr('data-ui-jsclass')]; @@ -223,15 +23,22 @@ $(function() { function initialize() { + gallery = new $.wiki.ScanGalleryPerspective(wikidoc); + /* The save button */ $('#save-button').click(function(event){ event.preventDefault(); $.blockUI({ - message: $('#save-dialog') + message: $('#save_dialog'), + css: { + 'top': '25%', + 'left': '25%', + 'width': '50%' + } }); }); - $('#save-ok').click(function(){ + $('#save_dialog .ok-button').click(function(){ $.blockUI({ message: 'Zapisywanie...' }); @@ -246,19 +53,26 @@ $(function() { $.unblockUI(); }; - wikidoc.save( $("#komentarz").text(), - function(doc, changed) { - console.log("Saved."); - finalize(); - }, - function(doc, message) { - alert(message); - finalize(); + wikidoc.save({ + comment: $("#komentarz").text(), + success: function(doc, changed, info){ + console.log(info); + $.blockUI({ + message: info + }); + setTimeout(finalize, 2000); + }, + failure: function(doc, info) { + console.log(info); + $.blockUI({ + message: info + }); + setTimeout(finalize, 3000); } - ); + }); }); - $('#save-cancel').click(function(){ + $('#save_dialog .cancel-button').click(function(){ $.unblockUI(); }); @@ -290,41 +104,34 @@ $(function() { $(window).resize(); - $('.vsplitbar').click(function(){ - if ($('#sidebar').width() == 0) { - $('#sidebar').width(480).css({ - right: 0 - }).show(); - $('#editor .editor').css({ - right: 495 - }); - $('.vsplitbar').css({ - right: 480 - }).addClass('active'); - } - else { - $('#sidebar').width(0).hide(); - $('#editor .editor').css({ - right: 15 - }); - $('.vsplitbar').css({ - right: 0 - }).removeClass('active'); - } - $(window).resize(); - }); + $('.vsplitbar').toggle( + function() { + $('#side-gallery').show(); + $('.vsplitbar').css('right', 480).addClass('.active'); + $('#editor .editor').css('right', 510); + $(window).resize(); + gallery.onEnter(); + }, + function() { + $('#side-gallery').hide(); + $('.vsplitbar').css('right', 0).removeClass('active'); + $('#editor .editor').css('right', 30); + $(window).resize(); + gallery.onExit(); + } + ); $(window).bind('beforeunload', function(event){ - return "Na stronie mogą być zmiany."; + if(wikidoc.has_local_changes) return "Na stronie mogą być zmiany."; }); - console.log("prepare for fetch"); + console.log("Fetching document's text"); wikidoc.fetch({ success: function(){ console.log("Fetch success"); $('#loading-overlay').fadeOut(); - var active_tab = document.location.hash || "#VisualPerspective"; + var active_tab = document.location.hash || "#SummaryPerspective"; var $active = $("#tabs " + active_tab + "-tab"); $active.trigger("click"); diff --git a/platforma/static/js/wiki/scan_gallery.js b/platforma/static/js/wiki/scan_gallery.js new file mode 100644 index 00000000..1d496f1a --- /dev/null +++ b/platforma/static/js/wiki/scan_gallery.js @@ -0,0 +1,267 @@ +(function($){ + + function normalizeNumber(number, length){ + // Numer strony musi być pomiędzy 1 a najwyższym numerem + var pageCount = length; + pageNumber = parseInt(pageNumber, 10); + + if (!pageNumber || + pageNumber == NaN || + pageNumber == Infinity || + pageNumber == -Infinity || + pageNumber < 1) + return 1; + + if (pageNumber > pageCount) + return pageCount; + + return pageNumber; + } + + function bounds(galleryWidth, galleryHeight, imageWidth, imageHeight){ + return { + maxX: 0, + maxY: 0, + minX: galleryWidth - imageWidth, + minY: galleryHeight - imageHeight + } + }; + + function normalizePosition(x, y, galleryWidth, galleryHeight, imageWidth, imageHeight){ + var b = bounds(galleryWidth, galleryHeight, imageWidth, imageHeight); + return { + x: Math.min(b.maxX, Math.max(b.minX, x)), + y: Math.min(b.maxY, Math.max(b.minY, y)) + } + }; + + function fixImageSize(){ + + } + + /* + * Perspective + */ + function ScanGalleryPerspective(doc, callback){ + var self = this; + + this.perspective_id = ''; + this.doc = doc; + + this.dimensions = {}; + this.zoomFactor = 1; + this.$element = $("#side-gallery"); + this.$numberInput = $('.page-number', this.$element); + + // ... + var origin = {}; + var imageOrigin = {}; + + this.$image = $('.gallery-image img', this.$element).attr('unselectable', 'on'); + + // button handlers + this.$numberInput.change(function(event){ + event.preventDefault(); + self.setPage($(this).val()); + }); + + $('.previous-page', this.$element).click(function(){ + self.setPage(self.$numberInput.val() - 1); + }); + + $('.nexy-page', this.$element).click(function(){ + self.setPage(self.$numberInput.val() + 1); + }); + + $('.zoom-in', this.$element).click(function(){ + self.alterZoom(0.2); + }); + + $('.zoom-out', this.$element).click(function(){ + self.alterZoom(-0.2); + }); + + $(window).resize(function(){ + self.dimensions.galleryWidth = self.$image.parent().width(); + self.dimensions.galleryHeight = self.$image.parent().height(); + }); + + $('.gallery-image img', this.$element).load(function(){ + console.load("Image loaded.") + self._resizeImage(); + }); + }; + + ScanGalleryPerspective.prototype = new $.wiki.Perspective(); + + ScanGalleryPerspective.prototype._resizeImage = function(){ + var $img = this.$image; + + $img.css({ + width: null, + height: null + }); + + this.dimensions = { + width: $img.width() * this.zoomFactor, + height: $img.height() * this.zoomFactor, + originWidth: $img.width(), + originHeight: $img.height(), + galleryWidth: $img.parent().width(), + galleryHeight: $img.parent().height() + }; + + if (!(this.dimensions.width && this.dimensions.height)) { + setTimeout(function(){ + $img.load(); + }, 100); + } + + var position = normalizePosition($img.position().left, $img.position().top, this.dimensions.galleryWidth, this.dimensions.galleryHeight, this.dimensions.width, this.dimensions.height); + + $img.css({ + left: position.x, + top: position.y, + width: $img.width() * this.zoomFactor, + height: $img.height() * this.zoomFactor + }); + }; + + ScanGalleryPerspective.prototype.setPage = function(newPage){ + newPage = normalizeNumber(newPage, this.$image.length); + this.$numberInput.val(newPage); + $('.gallery-image img', this.$element).attr('src', this.doc.galleryImages[newPage - 1]); + }; + + ScanGalleryPerspective.prototype.alterZoom = function(delta){ + var zoomFactor = this.zoomFactor + delta; + if (zoomFactor < 0.2) + zoomFactor = 0.2; + if (zoomFactor > 2) + zoomFactor = 2; + this.setZoom(zoomFactor); + }; + + ScanGalleryPerspective.prototype.setZoom = function(factor){ + this.zoomFactor = factor; + + this.dimensions.width = this.dimensions.originWidth * this.zoomFactor; + this.dimensions.height = this.dimensions.originHeight * this.zoomFactor; + + var position = normalizePosition(this.$image.position().left, this.$image.position().top, this.dimensions.galleryWidth, this.dimensions.galleryHeight, this.dimensions.width, this.dimensions.height); + + this.$image.css({ + width: this.dimensions.width, + height: this.dimensions.height, + left: position.x, + top: position.y + }); + }; + + /* + * Loading gallery + */ + ScanGalleryPerspective.prototype.onEnter = function(success, failure){ + var self = this; + + $.wiki.Perspective.prototype.onEnter.call(this); + + this.doc.refreshGallery({ + success: function(doc, data) { + self.$image.show(); + $('.error_message', self.$element).hide(); + success(); + }, + failure: function(doc, message) { + self.$image.hide(); + $('.error_message', self.$element).show().html(message); + failure(); + } + }); + }; + + $.wiki.ScanGalleryPerspective = ScanGalleryPerspective; +})(jQuery); + + +/* + + + function onMouseMove(event){ + + + var position = normalizePosition(event.clientX - origin.x + imageOrigin.left, event.clientY - origin.y + imageOrigin.top, imageDimensions.galleryWidth, imageDimensions.galleryHeight, imageDimensions.width, imageDimensions.height); + + + image.css({ + + + position: 'absolute', + + + top: position.y, + + + left: position.x + + + }); + + + return false; + + + } + + + function onMouseUp(event){ + + + $(document).unbind('mousemove.gallery').unbind('mouseup.gallery'); + + + return false; + + + } + + + image.bind('mousedown', function(event){ + + + origin = { + + + x: event.clientX, + + + y: event.clientY + + + }; + + + imageOrigin = image.position(); + + + $(document).bind('mousemove.gallery', onMouseMove).bind('mouseup.gallery', onMouseUp); + + + return false; + + + }); + + + if (url) { + + + updateGallery(url); + + + } + + + }*/ + + diff --git a/platforma/static/js/wiki/source_editor.js b/platforma/static/js/wiki/source_editor.js index 6f7ed3d7..0f671103 100644 --- a/platforma/static/js/wiki/source_editor.js +++ b/platforma/static/js/wiki/source_editor.js @@ -4,26 +4,10 @@ function CodeMirrorPerspective(doc, callback) { this.perspective_id = 'CodeMirrorPerspective'; - this.doc = doc; + this.doc = doc; // document model var self = this; - $('#source-editor .toolbar button').click(function(event){ - event.preventDefault(); - var params = eval("(" + $(this).attr('ui:action-params') + ")"); - scriptletCenter.scriptlets[$(this).attr('ui:action')](editor, params); - }); - - $('.toolbar select').change(function(event){ - var slug = $(this).val(); - - $('.toolbar-buttons-container').hide().filter('[data-group=' + slug + ']').show(); - $(window).resize(); - }); - - $('.toolbar-buttons-container').hide(); - $('.toolbar select').change(); - this.codemirror = CodeMirror.fromTextArea('codemirror_placeholder', { parserfile: 'parsexml.js', path: STATIC_URL + "js/lib/codemirror/", @@ -38,7 +22,25 @@ tabMode: 'spaces', indentUnit: 0, initCallback: function() { + $('#source-editor .toolbar button').click(function(event){ + event.preventDefault(); + var params = eval("(" + $(this).attr('data-ui-action-params') + ")"); + scriptletCenter.scriptlets[$(this).attr('data-ui-action')](self.codemirror, params); + }); + + $('.toolbar select').change(function(event){ + var slug = $(this).val(); + + $('.toolbar-buttons-container').hide().filter('[data-group=' + slug + ']').show(); + $(window).resize(); + }); + + $('.toolbar-buttons-container').hide(); + $('.toolbar select').change(); + console.log("Initialized CodeMirror"); + // textarea is no longer needed + $('codemirror_placeholder').remove(); callback.call(self); } }); @@ -59,6 +61,14 @@ if(success) success(); } + CodeMirrorPerspective.prototype.onExit = function(success, failure) { + $.wiki.Perspective.prototype.onExit.call(this); + + console.log(this.doc); + this.doc.setText(this.codemirror.getCode()); + if(success) success(); + } + $.wiki.CodeMirrorPerspective = CodeMirrorPerspective; })(jQuery); diff --git a/platforma/static/js/wiki/summary_view.js b/platforma/static/js/wiki/summary_view.js new file mode 100644 index 00000000..bed8155c --- /dev/null +++ b/platforma/static/js/wiki/summary_view.js @@ -0,0 +1,25 @@ +(function($){ + + function SummaryPerspective(doc, callback) { + this.perspective_id = 'SummaryPerspective'; + this.doc = doc; + + callback.call(this); + }; + + SummaryPerspective.prototype = new $.wiki.Perspective(); + + SummaryPerspective.prototype.freezeState = function(){ + // must + }; + + SummaryPerspective.prototype.onEnter = function(success, failure){ + $.wiki.Perspective.prototype.onEnter.call(this); + + console.log("Entered summery view"); + }; + + $.wiki.SummaryPerspective = SummaryPerspective; + +})(jQuery); + diff --git a/platforma/static/js/wiki/wikiapi.js b/platforma/static/js/wiki/wikiapi.js index d151f9e5..ee444ca1 100644 --- a/platforma/static/js/wiki/wikiapi.js +++ b/platforma/static/js/wiki/wikiapi.js @@ -24,10 +24,14 @@ if (vname == "ajax_document_history") { return "/" + arguments[1] + "/history"; - } + } + + if (vname == "ajax_document_gallery") { + return "/gallery/" + arguments[1]; + } if(vname == "ajax_document_diff") - return "/" + arguments[1] + "/diff/" + arguments[2] + "/" + arguments[3] + return "/" + arguments[1] + "/diff"; console.log("Couldn't reverse match:", vname); return "/404.html"; @@ -41,8 +45,8 @@ this.id = meta.attr('data-document-name'); this.revision = $("*[data-key='revision']", meta).text(); - this.gallery = $("*[data-key='gallery']", meta).text(); - + this.galleryLink = $("*[data-key='gallery']", meta).text(); + this.galleryImages = []; this.text = null; this.has_local_changes = false; @@ -142,47 +146,100 @@ params['success'](self, data); }, error: function() { - params['failure'](self, "Nie udało się wczytać treści dokumentu."); + params['failure'](self, "Nie udało się wczytać historii dokumentu."); + } + }); + }; + + WikiDocument.prototype.fetchDiff = function(params) { + /* this doesn't modify anything, so no locks */ + params = $.extend({ + 'from': self.revision, + 'to': self.revision + }, noops, params); + + var self = this; + + $.ajax({ + method: "GET", + url: reverse("ajax_document_diff", self.id), + dataType: 'json', + data: {"from": params['from'], "to": params['to']}, + success: function(data) { + params['success'](self, data); + }, + error: function() { + params['failure'](self, "Nie udało się wczytać porównania wersji."); } }); }; + /* + * Fetch gallery + */ + WikiDocument.prototype.refreshGallery = function(params) { + params = $.extend({}, noops, params); + var self = this; + + $.ajax({ + method: "GET", + url: reverse("ajax_document_gallery", self.galleryLink), + dataType: 'json', + // data: {}, + success: function(data) { + this.galleryImages = data.images; + params['success'](self, data); + }, + error: function() { + this.galleryImages = []; + params['failure'](self, "

    Nie udało się wczytać gallerii pod nazwą: '" + + self.galleryLink + "'.

    "); + + } + }); + }; + /* * Set document's text */ - WikiDocument.prototype.setText = function(text) { - this.text = text; - this.has_local_changes = true; + WikiDocument.prototype.setText = function(text) { + if (this.text != text) { + this.text = text; + this.has_local_changes = true; + } }; /* * Set document's gallery link */ - WikiDocument.prototype.setGallery = function(gallery) { - this.gallery = gallery; + WikiDocument.prototype.setGalleryLink = function(gallery) { + this.galleryLink = gallery; this.has_local_changes = true; }; /* * Save text back to the server */ - WikiDocument.prototype.save = function(comment, success, failure){ + WikiDocument.prototype.save = function(params){ + params = $.extend({'comment': 'No comment.'}, noops, params); var self = this; + /* you can't set text while some is fetching it (or saving) */ + if (!self.has_local_changes) { - return success(self, "Nie ma zmian do zapisania."); - } + console.log("Abort: no changes."); + return params['success'](self, false, "Nie ma zmian do zapisania."); + }; - /* you can't set text while some is fetching it (or saving) */ var metaComment = '' + metaComment += '\n\tgallery:' + self.galleryLink; + metaComment += '\n-->\n' var data = { name: self.id, - text: self.text, + text: metaComment + self.text, parent_revision: self.revision, - comment: comment, + comment: params['comment'], }; $.ajax({ @@ -198,10 +255,10 @@ self.gallery = data.gallery; changed = true; } - success(self, changed); + params['success'](self, changed, "Zapisano"); }, - error: function(){ - failure(self, "Nie udało się zapisać."); + error: function() { + params['failure'](self, "Nie udało się zapisać."); } }); }; /* end of save() */ diff --git a/setup.py b/setup.py index fffdad3c..9c658b71 100644 --- a/setup.py +++ b/setup.py @@ -28,9 +28,7 @@ def files_from(*paths, **kwargs): base = kwargs.pop('base') def generator(): for path in paths: - path = os.path.join(base, path) - print path - + path = os.path.join(base, path) if not os.path.isdir(path) or is_package(path): continue for dir, _, files in os.walk(path): @@ -100,5 +98,9 @@ django_setup( 'toolbar', 'wiki', ], + requires = [ + "librarian (>=1.3)", + "Django (>=1.1.1,<1.2)", + ] # data_files=[ ('', ['LICENSE', 'NOTICE', 'README.rst', 'AUTHORS.md', 'requirements.txt'])], )