X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=js%2Futil.js;h=5c12ab111db536d221a22d841c2db013f4e0e346;hb=76ea9384a3c6185a27d690e4247efe3a755be7b2;hp=9c074fdaa85746cf9bc372ae935c3169331e4f92;hpb=c1a27922ba738f71b100a520e5db6f32985a307b;p=quix0rs-gnu-social.git diff --git a/js/util.js b/js/util.js index 9c074fdaa8..5c12ab111d 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 @@ -274,9 +275,15 @@ var SN = { // StatusNet if (typeof($('form', data)[0]) != 'undefined') { 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.'); @@ -476,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($('