X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=js%2Futil.js;h=87a95c53138b93d6574da12b0b49dbf96a283c52;hb=cb183359e23ae7a5cfb483fa06c6c4b7a8b05fff;hp=966df4d93fbe085efcd47323e585b12dfacb269f;hpb=2bccd18d9a4f1ed2b74b854a7c1cffc707f961af;p=quix0rs-gnu-social.git diff --git a/js/util.js b/js/util.js index 966df4d93f..87a95c5313 100644 --- a/js/util.js +++ b/js/util.js @@ -236,10 +236,11 @@ var SN = { // StatusNet * @fixme can't submit file uploads * * @param {jQuery} form: jQuery object whose first element is a form + * @param function onSuccess: something extra to do on success * * @access public */ - FormXHR: function(form) { + FormXHR: function(form, onSuccess) { $.ajax({ type: 'POST', dataType: 'xml', @@ -253,15 +254,39 @@ var SN = { // StatusNet .attr(SN.C.S.Disabled, SN.C.S.Disabled); }, error: function (xhr, textStatus, errorThrown) { - alert(errorThrown || textStatus); + // If the server end reported an error from StatusNet, + // find it -- otherwise we'll see what was reported + // from the browser. + var errorReported = null; + if (xhr.responseXML) { + errorReported = $('#error', xhr.responseXML).text(); + } + alert(errorReported || errorThrown || textStatus); + + // Restore the form to original state. + // Hopefully. :D + form + .removeClass(SN.C.S.Processing) + .find('.submit') + .removeClass(SN.C.S.Disabled) + .removeAttr(SN.C.S.Disabled); }, success: function(data, textStatus) { if (typeof($('form', data)[0]) != 'undefined') { form_new = document._importNode($('form', data)[0], true); form.replaceWith(form_new); + if (onSuccess) { + onSuccess(); + } } - else { + else if (typeof($('p', data)[0]) != 'undefined') { form.replaceWith(document._importNode($('p', data)[0], true)); + if (onSuccess) { + onSuccess(); + } + } + else { + alert('Unknown error.'); } } }); @@ -394,16 +419,20 @@ var SN = { // StatusNet var replyItem = form.closest('li.notice-reply'); if (replyItem.length > 0) { - // If this is an inline reply, insert it in place. + // If this is an inline reply, remove the form... + var list = form.closest('.threaded-replies'); + var placeholder = list.find('.notice-reply-placeholder'); + replyItem.remove(); + var id = $(notice).attr('id'); if ($("#"+id).length == 0) { - var parentNotice = replyItem.closest('li.notice'); - replyItem.replaceWith(notice); - SN.U.NoticeInlineReplyPlaceholder(parentNotice); + $(notice).insertBefore(placeholder); } else { // Realtime came through before us... - replyItem.remove(); } + + // ...and show the placeholder form. + placeholder.show(); } else if (notices.length > 0 && SN.U.belongsOnTimeline(notice)) { // Not a reply. If on our timeline, show it at the top! @@ -454,6 +483,74 @@ var SN = { // StatusNet }); }, + FormProfileSearchXHR: function(form) { + $.ajax({ + type: 'POST', + dataType: 'xml', + url: form.attr('action'), + data: form.serialize() + '&ajax=1', + beforeSend: function(xhr) { + form + .addClass(SN.C.S.Processing) + .find('.submit') + .addClass(SN.C.S.Disabled) + .attr(SN.C.S.Disabled, SN.C.S.Disabled); + }, + error: function (xhr, textStatus, errorThrown) { + alert(errorThrown || textStatus); + }, + success: function(data, textStatus) { + var results_placeholder = $('#profile_search_results'); + if (typeof($('ul', data)[0]) != 'undefined') { + var list = document._importNode($('ul', data)[0], true); + results_placeholder.replaceWith(list); + } + else { + var _error = $('
  • ').append(document._importNode($('p', data)[0], true)); + results_placeholder.html(_error); + } + form + .removeClass(SN.C.S.Processing) + .find('.submit') + .removeClass(SN.C.S.Disabled) + .attr(SN.C.S.Disabled, false); + } + }); + }, + + FormPeopletagsXHR: function(form) { + $.ajax({ + type: 'POST', + dataType: 'xml', + url: form.attr('action'), + data: form.serialize() + '&ajax=1', + beforeSend: function(xhr) { + form.find('.submit') + .addClass(SN.C.S.Processing) + .addClass(SN.C.S.Disabled) + .attr(SN.C.S.Disabled, SN.C.S.Disabled); + }, + error: function (xhr, textStatus, errorThrown) { + alert(errorThrown || textStatus); + }, + success: function(data, textStatus) { + var results_placeholder = form.parents('.entity_tags'); + if (typeof($('.entity_tags', data)[0]) != 'undefined') { + var tags = document._importNode($('.entity_tags', data)[0], true); + $(tags).find('.editable').append($('