X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=js%2Futil.js;h=9d693160e2fbfb352131c91202acc85201e51d3c;hb=3187d6184fb957e7122b768808c6d7286e572b0a;hp=31e574a3a87859458c5a2ef2c5c8dbc9f4dded36;hpb=cd4b23aa399a51744787e580f8dfdb3886bfc8f5;p=quix0rs-gnu-social.git diff --git a/js/util.js b/js/util.js index 31e574a3a8..9d693160e2 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', @@ -261,7 +262,7 @@ var SN = { // StatusNet errorReported = $('#error', xhr.responseXML).text(); } alert(errorReported || errorThrown || textStatus); - + // Restore the form to original state. // Hopefully. :D form @@ -272,11 +273,17 @@ var SN = { // StatusNet }, success: function(data, textStatus) { if (typeof($('form', data)[0]) != 'undefined') { - form_new = document._importNode($('form', data)[0], true); + var form_new = document._importNode($('form', data)[0], true); form.replaceWith(form_new); + if (onSuccess) { + onSuccess(); + } } else if (typeof($('p', data)[0]) != 'undefined') { form.replaceWith(document._importNode($('p', data)[0], true)); + if (onSuccess) { + onSuccess(); + } } else { alert('Unknown error.'); @@ -412,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! @@ -472,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($('