diff --git a/pinry/api/api.py b/pinry/api/api.py index 5fb9f92..dc4ce98 100644 --- a/pinry/api/api.py +++ b/pinry/api/api.py @@ -84,3 +84,4 @@ class PinResource(ModelResource): resource_name = 'pin' include_resource_uri = False authorization = DjangoAuthorization() + ordering = '-published' diff --git a/pinry/static/js/bookmarklet.js b/pinry/static/js/bookmarklet.js index 12e91a0..fadece9 100644 --- a/pinry/static/js/bookmarklet.js +++ b/pinry/static/js/bookmarklet.js @@ -37,7 +37,14 @@ $(document).ready(function() { 'cursor': 'pointer' }); wrapper.click(function() { - alert('Added'); + $.ajax({ + type: "post", + url: "http://nebula.bythewood.me/api/v1/pin/", + contentType: 'application/json', + data: JSON.stringify({ + url: imageUrl + }) + }); $('.pinry-images').remove(); }); return wrapper; diff --git a/pinry/static/js/pin-form.js b/pinry/static/js/pin-form.js new file mode 100644 index 0000000..c21c9bb --- /dev/null +++ b/pinry/static/js/pin-form.js @@ -0,0 +1,43 @@ +$(window).load(function() { + 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(''); + }); + $('#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(); + $.ajax({ + type: "post", + url: "/api/v1/pin/", + contentType: 'application/json', + data: JSON.stringify({ + submitter: '/api/v1/user/'+currentUser+'/', + url: $('#pin-form-image-url').val(), + description: $('#pin-form-description').val(), + tags: tags + }) + }); + + $('#pin-form-close').click(function() { + $('#pin-form').remove(); + }); + + $('#pin-form').remove(); + + e.preventDefault(); + }); + + $('#pin-form-close').click(function() { + $('#pin-form').remove(); + }); + e.preventDefault(); + } + + $('#call-pin-form').click(function() { + createPinForm(); + }); +}); diff --git a/pinry/static/js/pinry.js b/pinry/static/js/pinry.js index ab660ff..e25beb6 100644 --- a/pinry/static/js/pinry.js +++ b/pinry/static/js/pinry.js @@ -67,10 +67,10 @@ $(window).load(function() { $('.spinner').css('display', 'block'); // Fetch our pins from the api using our current offset - $.get('/api/v1/pin/?format=json&offset='+String(offset), function(pins) { + $.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.username == currentUser); + pins.objects[i].editable = (pins.objects[i].submitter.id == currentUser); // Use the fetched pins as our context for our pins template var template = Handlebars.compile($('#pins-template').html()); diff --git a/pinry/templates/core/base.html b/pinry/templates/core/base.html index a10c4ad..34eab0a 100644 --- a/pinry/templates/core/base.html +++ b/pinry/templates/core/base.html @@ -24,7 +24,7 @@