mirror of
https://github.com/viq/NewsBlur.git
synced 2025-09-18 21:43:31 +00:00
Using correct domain, not adding the same site twice, messaging, better styling.
This commit is contained in:
parent
ed3e34ea36
commit
6e19d4d88b
9 changed files with 74 additions and 21 deletions
|
@ -52,7 +52,12 @@ def add_site(request, token):
|
|||
except Profile.DoesNotExist:
|
||||
code = -1
|
||||
|
||||
print code, message, us
|
||||
if code > 0:
|
||||
folder_image_path = os.path.join(settings.MEDIA_ROOT, 'img/icons/silk/accept.png')
|
||||
folder_image = open(folder_image_path)
|
||||
folder_image = base64.b64encode(folder_image.read())
|
||||
message = folder_image
|
||||
|
||||
return HttpResponse(callback + '(' + json.encode({
|
||||
'code': code,
|
||||
'message': message,
|
||||
|
|
|
@ -79,7 +79,7 @@ class UserSubscription(models.Model):
|
|||
code = -1
|
||||
message = "That URL does not point to an RSS feed or a website that has an RSS feed."
|
||||
else:
|
||||
us, _ = cls.objects.get_or_create(
|
||||
us, subscription_created = cls.objects.get_or_create(
|
||||
feed=feed,
|
||||
user=user,
|
||||
defaults={
|
||||
|
@ -90,6 +90,10 @@ class UserSubscription(models.Model):
|
|||
code = 1
|
||||
message = ""
|
||||
|
||||
if us and not subscription_created:
|
||||
code = -3
|
||||
message = "You are already subscribed to this site."
|
||||
elif us:
|
||||
user_sub_folders_object, created = UserSubscriptionFolders.objects.get_or_create(
|
||||
user=user,
|
||||
defaults={'folders': '[]'}
|
||||
|
|
|
@ -14,6 +14,7 @@ from django.contrib.auth.models import User
|
|||
from django.http import HttpResponse, HttpResponseRedirect, HttpResponseForbidden, Http404
|
||||
from django.conf import settings
|
||||
from django.core.mail import mail_admins
|
||||
from django.contrib.sites.models import Site
|
||||
from collections import defaultdict
|
||||
from operator import itemgetter
|
||||
from mongoengine.queryset import OperationError
|
||||
|
|
|
@ -212,6 +212,7 @@
|
|||
.NB-bookmarklet {
|
||||
font-family: 'Lucida Sans', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif;
|
||||
font-size: 12px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.NB-bookmarklet .NB-modal-information {
|
||||
|
@ -222,7 +223,8 @@
|
|||
font-size: 10px;
|
||||
}
|
||||
.NB-bookmarklet .NB-bookmarklet-folder-container {
|
||||
margin: 24px 0;
|
||||
margin: 20px 0;
|
||||
float: right;
|
||||
}
|
||||
.NB-bookmarklet .NB-bookmarklet-folder-container .NB-bookmarklet-folder-label {
|
||||
float: left;
|
||||
|
@ -231,10 +233,19 @@
|
|||
.NB-bookmarklet .NB-bookmarklet-folder-container .NB-folders {
|
||||
font-size: 14px;
|
||||
}
|
||||
.NB-bookmarklet .NB-folders {
|
||||
width: 200px;
|
||||
}
|
||||
.NB-bookmarklet .NB-modal-submit-button {
|
||||
float: left;
|
||||
clear: both;
|
||||
padding: 6px 16px;
|
||||
width: 100px;
|
||||
padding: 0 16px;
|
||||
line-height: 24px;
|
||||
width: 200px;
|
||||
text-align: center;
|
||||
}
|
||||
.NB-bookmarklet .NB-modal-submit-button img {
|
||||
margin: 5px 6px 0 0;
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
vertical-align: top;
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
NEWSBLUR.generate_bookmarklet = function() {
|
||||
var href = "javascript:function newsblur_bookmarklet() { var d=document,z=d.createElement('scr'+'ipt'),b=d.body,l=d.location; try{ if(!b) { throw(0); } d.title = '(Adding...) ' + d.title; z.setAttribute('src',l.protocol+'//'+'nb.local.host:8000'+'/api/add_site_load_script/"+NEWSBLUR.Globals.secret_token+"?url='+encodeURIComponent(l.href)+'&time='+(new Date().getTime())); b.appendChild(z); } catch(e) {alert('Please wait until the page has loaded.');}}newsblur_bookmarklet();void(0)";
|
||||
var href = "javascript:function newsblur_bookmarklet() { var d=document,z=d.createElement('scr'+'ipt'),b=d.body,l=d.location; try{ if(!b) { throw(0); } d.title = '(Adding...) ' + d.title; z.setAttribute('src',l.protocol+'//"+NEWSBLUR.URLs['domain']+"/api/add_site_load_script/"+NEWSBLUR.Globals['secret_token']+"?url='+encodeURIComponent(l.href)+'&time='+(new Date().getTime())); b.appendChild(z); } catch(e) {alert('Please wait until the page has loaded.');}}newsblur_bookmarklet();void(0)";
|
||||
|
||||
var $bookmarklet = $.make('a', {
|
||||
className: 'NB-goodies-bookmarklet-button',
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{% load bookmarklet_includes %}
|
||||
{% load bookmarklet_includes utils_tags %}
|
||||
|
||||
(function() {
|
||||
|
||||
|
@ -7,12 +7,13 @@
|
|||
NEWSBLUR.BookmarkletModal = function(options) {
|
||||
var defaults = {};
|
||||
|
||||
this.token = "{{ token }}";
|
||||
this.active = true;
|
||||
this.token = "{{ token }}";
|
||||
this.active = true;
|
||||
this.username = '{{ user.username }}';
|
||||
this.folders = {{ folders|safe }};
|
||||
this.folders = {{ folders|safe }};
|
||||
this.domain = "{% current_domain %}";
|
||||
|
||||
this.options = $.extend({}, defaults, options);
|
||||
this.options = $.extend({}, defaults, options);
|
||||
this.runner();
|
||||
};
|
||||
|
||||
|
@ -55,8 +56,7 @@
|
|||
},
|
||||
|
||||
check_if_on_newsblur: function() {
|
||||
if (window.location.href.indexOf('newsblur.com/') != -1 ||
|
||||
window.location.href.indexOf('nb.local.host:8000/') != -1) {
|
||||
if (window.location.href.indexOf(this.domain) != -1) {
|
||||
return true;
|
||||
}
|
||||
},
|
||||
|
@ -153,17 +153,39 @@
|
|||
},
|
||||
|
||||
save: function() {
|
||||
var self = this;
|
||||
var $submit = $('.NB-modal-submit-button');
|
||||
var folder = $('.NB-folders').val();
|
||||
var add_site_url = "http://nb.local.host:8000{% url api-add-site token %}?callback=?";
|
||||
var add_site_url = "http://"+this.domain+"{% url api-add-site token %}?callback=?";
|
||||
|
||||
$submit.addClass('NB-disabled').text('Fetching and parsing...');
|
||||
|
||||
$.getJSON(add_site_url, {
|
||||
url: window.location.href,
|
||||
folder: folder
|
||||
}, function(resp) {
|
||||
console.log(['resp', resp]);
|
||||
self.post_save(resp);
|
||||
});
|
||||
},
|
||||
|
||||
post_save: function(resp) {
|
||||
var $submit = $('.NB-modal-submit-button');
|
||||
|
||||
$submit.addClass('NB-close');
|
||||
|
||||
if (resp.code == 1) {
|
||||
$submit.html($.make('div', [
|
||||
$.make('img', { src: 'data:image/png;charset=utf-8;base64,' + resp.message }),
|
||||
'Added!'
|
||||
]));
|
||||
setTimeout(function() {
|
||||
// $.modal.close();
|
||||
}, 1600);
|
||||
} else {
|
||||
$submit.text('Not working');
|
||||
}
|
||||
},
|
||||
|
||||
// ===========
|
||||
// = Actions =
|
||||
// ===========
|
||||
|
@ -173,8 +195,15 @@
|
|||
|
||||
$.targetIs(e, { tagSelector: '.NB-modal-submit-button' }, function($t, $p) {
|
||||
e.preventDefault();
|
||||
|
||||
self.save();
|
||||
|
||||
if (!$t.hasClass('NB-disabled')) {
|
||||
self.save();
|
||||
}
|
||||
});
|
||||
$.targetIs(e, { tagSelector: '.NB-close' }, function($t, $p) {
|
||||
e.preventDefault();
|
||||
|
||||
$.modal.close();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
};
|
||||
NEWSBLUR.URLs = {
|
||||
'google-reader-authorize': "{% url google-reader-authorize %}",
|
||||
'newsblur': "{% url index %}"
|
||||
'domain': "{% current_domain %}"
|
||||
};
|
||||
</script>
|
||||
|
||||
|
|
|
@ -72,6 +72,6 @@ def colorize(msg):
|
|||
msg = re.sub(r'(~[A-Z]{2})', r'%(\1)s', msg)
|
||||
try:
|
||||
msg = msg % colors
|
||||
except TypeError:
|
||||
except (TypeError, ValueError):
|
||||
pass
|
||||
return msg
|
|
@ -1,5 +1,8 @@
|
|||
from django.conf import settings
|
||||
from django.contrib.sites.models import Site
|
||||
from django import template
|
||||
|
||||
register = template.Library()
|
||||
|
||||
@register.simple_tag
|
||||
def current_domain():
|
||||
return Site.objects.get_current().domain
|
Loading…
Add table
Reference in a new issue