consolidate error handling

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
Arthur Schiwon 2016-10-19 13:56:49 +02:00
parent bc18a2900e
commit 763a99ec30
No known key found for this signature in database
GPG Key ID: 7424F1874854DF23
1 changed files with 41 additions and 27 deletions

View File

@ -386,6 +386,15 @@
this.nextPage();
},
/**
* takes care of updating comment elements after submit (either new
* comment or edit).
*
* @param {OC.Backbone.Model} model
* @param {jQuery} $form
* @param {string|undefined} commentId
* @private
*/
_onSubmitSuccess: function(model, $form, commentId) {
var self = this;
var $submit = $form.find('.submit');
@ -396,32 +405,25 @@
success: function(model) {
$submit.removeClass('hidden');
$loading.addClass('hidden');
var $target;
if(!_.isUndefined(commentId)) {
var $row = $form.closest('.comment');
$row.data('commentEl')
.removeClass('hidden')
.find('.message')
.html(self._formatMessage(model.get('message'), model.get('mentions')))
.find('.avatar')
.each(function () { $(this).avatar(); });
$target = $row.data('commentEl');
$target.removeClass('hidden');
$row.remove();
} else {
var $row = $form.closest('.comments');
$('.commentsTabView .comments').find('li:first')
.find('.message')
.html(self._formatMessage(model.get('message'), model.get('mentions')))
.find('.avatar')
.each(function () { $(this).avatar(); });
$target = $('.commentsTabView .comments').find('li:first');
$textArea.val('').prop('disabled', false);
}
$target.find('.message')
.html(self._formatMessage(model.get('message'), model.get('mentions')))
.find('.avatar')
.each(function () { $(this).avatar(); });
},
error: function () {
$submit.removeClass('hidden');
$loading.addClass('hidden');
$textArea.prop('disabled', false);
OC.Notification.showTemporary(t('comments', 'Error occurred while updating comment with id {id}', {id: commentId}));
self._onSubmitError($form, commentId);
}
});
},
@ -455,11 +457,7 @@
self._onSubmitSuccess(model, $form, commentId);
},
error: function() {
$submit.removeClass('hidden');
$loading.addClass('hidden');
$textArea.prop('disabled', false);
OC.Notification.showTemporary(t('comments', 'Error occurred while updating comment with id {id}', {id: commentId}));
self._onSubmitError($form, commentId);
}
});
} else {
@ -478,11 +476,7 @@
self._onSubmitSuccess(model, $form);
},
error: function() {
$submit.removeClass('hidden');
$loading.addClass('hidden');
$textArea.prop('disabled', false);
OC.Notification.showTemporary(t('comments', 'Error occurred while posting comment'));
self._onSubmitError($form);
}
});
}
@ -490,6 +484,26 @@
return false;
},
/**
* takes care of updating the UI after an error on submit (either new
* comment or edit).
*
* @param {jQuery} $form
* @param {string|undefined} commentId
* @private
*/
_onSubmitError: function($form, commentId) {
$form.find('.submit').removeClass('hidden');
$form.find('.submitLoading').addClass('hidden');
$form.find('.message').prop('disabled', false);
if(!_.isUndefined(commentId)) {
OC.Notification.showTemporary(t('comments', 'Error occurred while updating comment with id {id}', {id: commentId}));
} else {
OC.Notification.showTemporary(t('comments', 'Error occurred while posting comment'));
}
},
/**
* Returns whether the given message is long and needs
* collapsing