From: zuber Date: Fri, 16 Oct 2009 09:06:23 +0000 (+0200) Subject: Merge branch 'master' of stigma.nowoczesnapolska.org.pl:platforma X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/cf265108541da0a0f54e2b4517ce9441e8ccf795?hp=a3face505cc1462d8d8cae3102666890608eacb6 Merge branch 'master' of stigma.nowoczesnapolska.org.pl:platforma --- diff --git a/apps/api/handlers/library_handlers.py b/apps/api/handlers/library_handlers.py index be504e90..f7d57849 100644 --- a/apps/api/handlers/library_handlers.py +++ b/apps/api/handlers/library_handlers.py @@ -261,8 +261,8 @@ class DocumentHandler(BaseHandler): # 'dc_url': reverse('docdc_view', args=[doc.id]), 'gallery_url': reverse('docgallery_view', args=[doc.id]), 'merge_url': reverse('docmerge_view', args=[doc.id]), - 'user_revision': doc.revision, - 'user_timestamp': doc.revision.timestamp, + 'revision': doc.revision, + 'timestamp': doc.revision.timestamp, # 'public_revision': doc.revision, # 'public_timestamp': doc.revision.timestamp, } @@ -628,6 +628,8 @@ class MergeHandler(BaseHandler): # update user document if changed: user_doc_new = user_doc.latest() + else: + user_doc_new = user_doc # shared document is the same doc_new = doc @@ -680,6 +682,8 @@ class MergeHandler(BaseHandler): # update shared version if needed if changed: doc_new = doc.latest() + else: + doc_new = doc # the user wersion is the same user_doc_new = base_doc @@ -691,9 +695,16 @@ class MergeHandler(BaseHandler): return response.SuccessAllOk().django_response({ "name": user_doc_new.id, "user": user_doc_new.owner, - "parent_revision": user_doc_new.revision, - "parent_shared_revision": doc.revision, + "revision": user_doc_new.revision, - "shared_revision": doc_new.revision, 'timestamp': user_doc_new.revision.timestamp, + + "parent_revision": user_doc_new.revision, + "parent_timestamp": user_doc_new.revision.timestamp, + + "shared_revision": doc_new.revision, + "shared_timestamp": doc_new.revision.timestamp, + + "shared_parent_revision": doc.revision, + "shared_parent_timestamp": doc.revision.timestamp, }) \ No newline at end of file diff --git a/apps/explorer/admin.py b/apps/explorer/admin.py index 1c91b963..10c3e79a 100644 --- a/apps/explorer/admin.py +++ b/apps/explorer/admin.py @@ -1,5 +1,4 @@ from django.contrib import admin -from django.utils.translation import ugettext_lazy as _ import explorer.models diff --git a/platforma/static/js/app.js b/platforma/static/js/app.js index e8b439df..8dae56e4 100644 --- a/platforma/static/js/app.js +++ b/platforma/static/js/app.js @@ -188,13 +188,16 @@ function parseXHRError(response) var json = $.evalJSON(response.responseText); if(json.reason == 'xml-parse-error') { - message = json_response.message.replace(/(line\s+)(\d+)(\s+)/i, + message = json.message.replace(/(line\s+)(\d+)(\s+)/i, "$1$2$3"); message = message.replace(/(line\s+)(\d+)(\,\s*column\s+)(\d+)/i, "$1$2$3$4"); } - message = json_response.message || json_response.reason || "Nieznany błąd :(("; + else { + message = json.message || json.reason || "Nieznany błąd :(("; + } + } catch(e) { // not a valid JSON response message = response.statusText; diff --git a/platforma/static/js/models.js b/platforma/static/js/models.js index 6399c037..fe42e895 100644 --- a/platforma/static/js/models.js +++ b/platforma/static/js/models.js @@ -393,7 +393,7 @@ Editor.ImageGalleryModel = Editor.Model.extend({ Editor.DocumentModel = Editor.Model.extend({ _className: 'Editor.DocumentModel', - data: null, // name, text_url, user_revision, latest_shared_rev, parts_url, dc_url, size, merge_url + data: null, // name, text_url, revision, latest_shared_rev, parts_url, dc_url, size, merge_url contentModels: {}, state: 'empty', errors: '', @@ -423,7 +423,7 @@ Editor.DocumentModel = Editor.Model.extend({ this.set('data', data); this.set('state', 'synced'); - this.set('revision', data.user_revision); + this.set('revision', data.revision); this.set('user', data.user); this.contentModels = { @@ -464,12 +464,13 @@ Editor.DocumentModel = Editor.Model.extend({ for (key in this.contentModels) { if (this.contentModels[key].guid() == contentModel.guid()) { this.contentModels[key].set('state', 'synced'); - this.data.user_revision = this.contentModels[key].get('revision'); + this.revision = this.contentModels[key].get('revision'); + } } for (key in this.contentModels) { if (this.contentModels[key].guid() != contentModel.guid()) { - this.contentModels[key].set('revision', this.data.user_revision); + this.contentModels[key].set('revision', this.revision); this.contentModels[key].set('state', 'empty'); } } @@ -487,60 +488,76 @@ Editor.DocumentModel = Editor.Model.extend({ update: function() { this.set('state', 'loading'); - messageCenter.addMessage('info', 'Uaktualniam dokument...'); + + messageCenter.addMessage('info', 'doc_update', + 'Uaktualniam dokument...'); + $.ajax({ url: this.data.merge_url, dataType: 'json', type: 'post', data: { type: 'update', - revision: this.revision, - user: this.user + revision: this.get('revision'), + user: this.get('user') }, complete: this.updateCompleted.bind(this), success: function(data) { this.set('updateData', data); + console.log("new data:", data) }.bind(this) }); }, updateCompleted: function(xhr, textStatus) { console.log(xhr.status, textStatus); - if (xhr.status == 200) { // Sukces - this.data = this.get('updateData'); - this.revision = this.data.user_revision; - this.user = this.data.user; - - messageCenter.addMessage('info', null, 'Uaktualnienie dokumentu do wersji ' + this.get('updateData').revision, - 'Uaktualnienie dokumentu do wersji ' + this.get('updateData').revision); - for (var key in this.contentModels) { - this.contentModels[key].set('revision', this.data.user_revision); - this.contentModels[key].set('state', 'empty'); + + if (xhr.status == 200) + { + var udata = this.get('updateData'); + if(udata.timestamp == udata.parent_timestamp) + { + // no change + messageCenter.addMessage('info', 'doc_update', + 'Nic się nie zmieniło od ostatniej aktualizacji. Po co mam uaktualniać?'); + } - messageCenter.addMessage('success', null, 'Uaktualniłem dokument do najnowszej wersji :-)'); - } else if (xhr.status == 202) { // Wygenerowano PullRequest (tutaj?) - } else if (xhr.status == 204) { // Nic nie zmieniono - messageCenter.addMessage('info', null, 'Nic się nie zmieniło od ostatniej aktualizacji. Po co mam uaktualniać?'); + else { + this.set('revision', udata.revision); + this.set('user', udata.user); + messageCenter.addMessage('info', 'doc_update', + 'Uaktualnienie dokumentu do wersji ' + udata.revision); + + for (var key in this.contentModels) { + this.contentModels[key].set('revision', this.get('revision') ); + this.contentModels[key].set('state', 'empty'); + } + } } else if (xhr.status == 409) { // Konflikt podczas operacji - messageCenter.addMessage('error', null, 'Wystąpił konflikt podczas aktualizacji. Pędź po programistów! :-('); - } else if (xhr.status == 500) { - messageCenter.addMessage('critical', null, 'Błąd serwera. Pędź po programistów! :-('); + messageCenter.addMessage('error', 'doc_update', + 'Wystąpił konflikt podczas aktualizacji. Pędź po programistów! :-('); + } else { + messageCenter.addMessage('critical', 'doc_update', + 'Nieoczekiwany błąd. Pędź po programistów! :-('); } + this.set('state', 'synced'); this.set('updateData', null); }, merge: function(message) { this.set('state', 'loading'); - messageCenter.addMessage('info', null, 'Scalam dokument z głównym repozytorium...'); + messageCenter.addMessage('info', null, + 'Scalam dokument z głównym repozytorium...'); + $.ajax({ url: this.data.merge_url, type: 'post', dataType: 'json', data: { type: 'share', - revision: this.revision, - user: this.user, + revision: this.get('revision'), + user: this.get('user'), message: message }, complete: this.mergeCompleted.bind(this), @@ -553,12 +570,11 @@ Editor.DocumentModel = Editor.Model.extend({ mergeCompleted: function(xhr, textStatus) { console.log(xhr.status, textStatus); if (xhr.status == 200) { // Sukces - this.data = this.get('updateData'); - this.revision = this.data.user_revision; - this.user = this.data.user; + this.set('revision', this.get('updateData').revision); + this.set('user', this.get('updateData').user); for (var key in this.contentModels) { - this.contentModels[key].set('revision', this.revision); + this.contentModels[key].set('revision', this.get('revision')); this.contentModels[key].set('state', 'empty'); } diff --git a/platforma/templates/explorer/editor.html b/platforma/templates/explorer/editor.html index daa1b9e8..f55f4ecd 100644 --- a/platforma/templates/explorer/editor.html +++ b/platforma/templates/explorer/editor.html @@ -1,4 +1,5 @@ {% extends "base.html" %} +{% load i18n %} {% block extrahead %} @@ -49,7 +50,7 @@ <% for (panel in panels) { %> <% }; %> -

+

@@ -63,7 +64,7 @@