From: Łukasz Rekucki Date: Sat, 5 Sep 2009 00:06:19 +0000 (+0200) Subject: Komunikat, ze zaczal zapisywac. X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/d798a69cb177ba4dabd2d917e1da6ab94707aa7d?ds=sidebyside Komunikat, ze zaczal zapisywac. Naprawiony bug z kodowaniem znakow. Przyciski autokorekty ustawiaja dobry stan. Bledy XML przy zapisywaniu sa traktowane jako ostrzezenia. --- diff --git a/apps/explorer/views.py b/apps/explorer/views.py index d6118acb..82c9d398 100644 --- a/apps/explorer/views.py +++ b/apps/explorer/views.py @@ -98,27 +98,37 @@ def file_upload(request, repo): def file_xml(request, repo, path): if request.method == 'POST': errors = None + warnings = None form = forms.BookForm(request.POST) if form.is_valid(): print 'Saving whole text.', request.user.username - def save_action(): - print 'In branch: ' + repo.repo[None].branch() - repo._add_file(path, form.cleaned_data['content']) - repo._commit(message=(form.cleaned_data['commit_message'] or 'Lokalny zapis platformy.'),\ - user=request.user.username) try: - # wczytaj dokument z ciągu znaków -> weryfikacja - document = parser.WLDocument.from_string(form.cleaned_data['content']) + # encode it back to UTF-8, so we can put it into repo + encoded_data = form.cleaned_data['content'].encode('utf-8') + + def save_action(): + repo._add_file(path, encoded_data) + repo._commit(message=(form.cleaned_data['commit_message'] or 'Lokalny zapis platformy.'),\ + user=request.user.username) + + try: + # wczytaj dokument z ciągu znaków -> weryfikacja + document = parser.WLDocument.from_string(form.cleaned_data['content']) + except (ParseError, ValidationError), e: + warnings = [u'Niepoprawny dokument XML: ' + unicode(e.message)] # save to user's branch repo.in_branch(save_action, models.user_branch(request.user) ); - except (ParseError, ValidationError), e: - errors = [e.message] + except UnicodeDecodeError, e: + errors = [u'Błąd kodowania danych przed zapisem: ' + unicode(e.message)] + except RepositoryException, e: + errors = [u'Błąd repozytorium: ' + unicode(e.message)] if not errors: errors = dict( (field[0], field[1].as_text()) for field in form.errors.iteritems() ) - return HttpResponse(json.dumps({'result': errors and 'error' or 'ok', 'errors': errors})); + return HttpResponse( json.dumps({'result': errors and 'error' or 'ok', + 'errors': errors, 'warnings': warnings}) ); form = forms.BookForm() data = repo.get_file(path, models.user_branch(request.user)) diff --git a/project/static/css/master.css b/project/static/css/master.css index 561ef50a..c321c782 100644 --- a/project/static/css/master.css +++ b/project/static/css/master.css @@ -294,7 +294,7 @@ div.isection p { width: 33%; } -.msg-error, .msg-success, .msg-warning { +.msg-error, .msg-success, .msg-warning, .msg-info { overflow: hidden; padding: 0.1em 0.5em; text-align: center; @@ -325,6 +325,11 @@ div.isection p { border-color: lightgreen; } +.msg-info { + background-color: lightblue; + border-color: lightblue; +} + .msg-warning { background-color: yellow; border-color: yellow; diff --git a/project/static/js/editor.js b/project/static/js/editor.js index 879762cd..13c70978 100644 --- a/project/static/js/editor.js +++ b/project/static/js/editor.js @@ -154,7 +154,7 @@ Panel.prototype.connectToolbar = function() var params = $.evalJSON(button.attr('ui:action-params')); var callback = function() { - editor.callScriptlet(button.attr('ui:action'), self, params); + editor.callScriptlet(button.attr('ui:action'), self, params); }; // connect button @@ -354,12 +354,15 @@ Editor.prototype.saveToBranch = function(msg) 'commit_message': msg }) + self.showPopup('save-waiting', '', -1); + $.ajax({ url: saveInfo.url, dataType: 'json', success: function(data, textStatus) { - if (data.result != 'ok') - self.showPopup('save-error', data.errors[0]); + if (data.result != 'ok') { + self.showPopup('save-error', (data.errors && data.errors[0]) || 'Nieznany błąd X_X.'); + } else { self.refreshPanels(changed_panel); $('#toolbar-button-save').attr('disabled', 'disabled'); @@ -367,11 +370,17 @@ Editor.prototype.saveToBranch = function(msg) if(self.autosaveTimer) clearTimeout(self.autosaveTimer); - self.showPopup('save-successful'); + if (data.warnings == null) + self.showPopup('save-successful'); + else + self.showPopup('save-warn', data.warnings[0]); } + + self.advancePopupQueue(); }, error: function(rq, tstat, err) { - self.showPopup('save-error'); + self.showPopup('save-error', '- bład wewnętrzny serwera.'); + self.advancePopupQueue(); }, type: 'POST', data: postData @@ -435,10 +444,11 @@ Editor.prototype.sendPullRequest = function () { }); */ } -Editor.prototype.showPopup = function(name, text) +Editor.prototype.showPopup = function(name, text, timeout) { + timeout = timeout || 4000; var self = this; - self.popupQueue.push( [name, text] ) + self.popupQueue.push( [name, text, timeout] ) if( self.popupQueue.length > 1) return; @@ -447,26 +457,31 @@ Editor.prototype.showPopup = function(name, text) $('*.data', box).html(text); box.fadeIn(); - self._nextPopup = function() { - var elem = self.popupQueue.pop() - if(elem) { - var box = $('#message-box > #' + elem[0]); + if(timeout > 0) + setTimeout( $.fbind(self, self.advancePopupQueue), timeout); +}; - box.fadeOut(300, function() { - $('*.data', box).html(); - - if( self.popupQueue.length > 0) { - box = $('#message-box > #' + self.popupQueue[0][0]); - $('*.data', box).html(self.popupQueue[0][1]); - box.fadeIn(); - setTimeout(self._nextPopup, 5000); - } - }); - } +Editor.prototype.advancePopupQueue = function() { + var self = this; + var elem = this.popupQueue.shift(); + if(elem) { + var box = $('#message-box > #' + elem[0]); + + box.fadeOut(200, function() + { + $('*.data', box).html(); + + if( self.popupQueue.length > 0) { + var ibox = $('#message-box > #' + self.popupQueue[0][0]); + $('*.data', ibox).html(self.popupQueue[0][1]); + ibox.fadeIn(); + if(self.popupQueue[0][2] > 0) + setTimeout( $.fbind(self, self.advancePopupQueue), self.popupQueue[0][2]); + } + }); } +}; - setTimeout(self._nextPopup, 5000); -} Editor.prototype.registerScriptlet = function(scriptlet_id, scriptlet_func) { @@ -485,7 +500,9 @@ Editor.prototype.callScriptlet = function(scriptlet_id, panel, params) { $(function() { $.fbind = function (self, func) { - return function() { return func.apply(self, arguments); }; + return function() { + return func.apply(self, arguments); + }; }; editor = new Editor(); diff --git a/project/templates/explorer/editor.html b/project/templates/explorer/editor.html index 6dce9047..b3a2e4c6 100644 --- a/project/templates/explorer/editor.html +++ b/project/templates/explorer/editor.html @@ -34,9 +34,11 @@ {% endblock %} {% block message-box %} +

Zapisuję dane na serwerze.

Zapisano :)

Błąd przy zapisie.

Tej funkcji jeszcze nie ma :(

+

Zapisano. Uwagi: (

{% endblock %} {% block maincontent %}