diff --git a/pinry/static/css/pinry.css b/pinry/static/css/pinry.css index 6a0fd71..279f41c 100644 --- a/pinry/static/css/pinry.css +++ b/pinry/static/css/pinry.css @@ -105,8 +105,10 @@ body { .pin p { margin-bottom: 0; - padding-top: 15px; - padding-bottom: 15px; + padding: 8px; + border-bottom: 1px solid #ddd; + font-family: "Georgia", "Times", "Times New Roman", Serif; + font-size: 12px; } .pin strong { diff --git a/pinry/static/js/pin-form.js b/pinry/static/js/pin-form.js index c21c9bb..6e98a06 100644 --- a/pinry/static/js/pin-form.js +++ b/pinry/static/js/pin-form.js @@ -1,25 +1,74 @@ $(window).load(function() { + var currentPin; + + function cleanTags() { + var tags = $('#pin-form-tags').val() + tags = tags.split(',') + for (var tag in tags) tags[tag] = tags[tag].trim(); + return tags + } + + function createPin() { + var template = Handlebars.compile($('#pins-template').html()); + var html = template({ + pins: [{ + submitter: currentUser, + image: { + standard: { + image: $('#pin-form-image-url').val() + }, + thumbnail: { + image: $('#pin-form-image-url').val() + } + }, + description: $('#pin-form-description').val(), + tags: cleanTags() + }] + }); + currentPin = html; + return html + } + + function createPreview() { + $('#pin-form-image-preview').html(createPin()); + $('#pin-form-image-preview .pin').css('width', '200px'); + $('#pin-form-image-preview .pin .text').css('width', '140px'); + var pinHeight = $('#pin-form-image-preview .pin').height(); + if (pinHeight > 305) + $('#pin-form .modal-body').css('height', String(pinHeight)+'px'); + } + function createPinForm() { var template = Handlebars.compile($('#pin-form-template').html()); var html = template(); $('body').append(html); $('#pin-form-image-url').bind('propertychange keyup input paste', function() { - $('#pin-form-image-preview').html(''); + createPreview(); + }); + $('#pin-form-description').bind('propertychange keyup input paste', function() { + createPreview(); + }); + $('#pin-form-tags').bind('propertychange keyup input paste', function() { + createPreview(); }); $('#pin-form-submit').click(function(e) { - var tags = $('#pin-form-tags').val() - tags = tags.split(',') - for (var tag in tags) tags[tag] = tags[tag].trim(); + var tags = cleanTags(); $.ajax({ type: "post", url: "/api/v1/pin/", contentType: 'application/json', data: JSON.stringify({ - submitter: '/api/v1/user/'+currentUser+'/', + submitter: '/api/v1/user/'+currentUser.id+'/', url: $('#pin-form-image-url').val(), description: $('#pin-form-description').val(), tags: tags - }) + }), + success: function() { + $('#pins').prepend(currentPin); + }, + error: function() { + alert("Something went wrong. :("); + } }); $('#pin-form-close').click(function() { @@ -34,7 +83,6 @@ $(window).load(function() { $('#pin-form-close').click(function() { $('#pin-form').remove(); }); - e.preventDefault(); } $('#call-pin-form').click(function() { diff --git a/pinry/static/js/pinry.js b/pinry/static/js/pinry.js index e25beb6..402d081 100644 --- a/pinry/static/js/pinry.js +++ b/pinry/static/js/pinry.js @@ -70,7 +70,7 @@ $(window).load(function() { $.get('/api/v1/pin/?format=json&ordering=-id&offset='+String(offset), function(pins) { // Set which items are editable by the current user for (var i=0; i < pins.objects.length; i++) - pins.objects[i].editable = (pins.objects[i].submitter.id == currentUser); + pins.objects[i].editable = (pins.objects[i].submitter.username == currentUser.username); // Use the fetched pins as our context for our pins template var template = Handlebars.compile($('#pins-template').html()); diff --git a/pinry/templates/base.html b/pinry/templates/base.html index 129454c..ec58c58 100644 --- a/pinry/templates/base.html +++ b/pinry/templates/base.html @@ -34,8 +34,8 @@ {{ SITE_NAME }}