diff options
| author | Jules Laplace <jules@okfoc.us> | 2012-07-18 00:02:21 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2012-07-18 00:02:21 -0400 |
| commit | c4338d2ae878a167c409e91dea6d1783fc7e30ba (patch) | |
| tree | 1e54fac722ac3153f9180a5a8332f2b19e11c00c /static/js/src/profile.js | |
| parent | d891a7ae1b205716c086363fba17a3249a665deb (diff) | |
put away back
Diffstat (limited to 'static/js/src/profile.js')
| -rw-r--r-- | static/js/src/profile.js | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/static/js/src/profile.js b/static/js/src/profile.js new file mode 100644 index 0000000..1fa6610 --- /dev/null +++ b/static/js/src/profile.js @@ -0,0 +1,109 @@ + +function initProfile(recips) { + Search.initInpage(); + $(".linkify-text").each(function() { + var text = jQuery(this).text(); + jQuery(this).html(linkifyWithoutImage(text)); + }); + + $(".linkify-full").each(function() { + $(this).html(buildMsgContent($(this).text(), recips)); + }); + + $('#edit-toggle').click(enableProfileEdit); + activateProfileEditable(); + + $('.dash-dump .content').each(function() { + var t = $(this); + t.html(buildMsgContent(t.text())); + }); +}; + + +function enableProfileEdit() { + $('img#contact').replaceWith('<div id="contact" class="linkify"></div>'); + $('img#bio').replaceWith('<div id="bio" class="linkify"></div>'); + $('#contact, #bio, #avatar').addClass('editable'); + $('#avatar-editing').show(); + var resetPage = function() { location.reload() }; + $('#edit-toggle a').text('done editing').click(resetPage); + activateProfileEditable(); +} + + +function activateProfileEditable() { + var onSubmit = function(attr, newVal, oldVal) { + newVal = $.trim(newVal); + if (newVal == oldVal) { return oldVal }; + + $.ajax({ + type: "POST", + timeout: 5000, + url: "/update-profile", + data: { 'attr': attr, 'val': newVal } + }); + if (attr == 'avatar') { + if (newVal != "") { + var s = '<img id="avatarPic" src="' + newVal + '" width="150" />'; + $('#avatarPic').replaceWith(s).show(); + } else { + $('#avatarPic').hide(); + } + } + return escapeHtml(newVal); + }; + + if ($('#avatar-editing').length > 0) + setupUploadAvatar('uploadp'); + + var textareaOpts = { 'default_text': 'Enter here!', + 'callback': onSubmit, + 'field_type': 'textarea', + 'callbackShowErrors': false }; + $('#contact.editable, #bio.editable') + .editInPlace(textareaOpts) + .each(makePlainText); +} + + +function setupUploadAvatar(elementId) { + // NOTE: AjaxUpload responses aren't converted from JSON. + var onSubmit = function(file, error) { + $('#spinner').show(); + }; + var onComplete = function(file, resp) { + $('#spinner').hide(); + var r = $.trim(resp); + + if (r == 'INVALID_REQUEST') { + location.reload(); + } else if (r == 'NOT_LOGGED_IN') { + location.reload(); + } else if (r == 'INVALID_IMAGE') { + alert("Sorry, dump.fm can't deal with your image. Pick another :("); + return; + } else if (r.match(/FILE_TOO_BIG/)) { + var maxSize = r.split(" ")[1] / 1024; + alert("Sorry. Your avatar is just too fucking big. " + + maxSize + "KB or less please."); + return; + } else if (r.match(/INVALID_RESOLUTION/)) { + var maxWidth = r.split(" ")[1]; + var maxHeight = r.split(" ")[2]; + alert("Sorry, the maximum avatar resolution is " + + maxWidth + "x" + maxHeight); + return; + } + var s = '<img id="dashavatarPic" src="' + r + '" />'; + $('#dashavatar').html(s).show(); + $('#dashtotal').css('background-image', 'url(' + r + ')'); + }; + new AjaxUpload(elementId, { + action: '/upload/avatar', + autoSubmit: true, + name: 'image', + onSubmit: onSubmit, + onComplete: onComplete + }); +} + |
