ability to edit title, publish and lock articles on web frontend page

This commit is contained in:
Sanj 2011-07-09 01:18:30 +05:30
parent 7789c667b1
commit c4a8957161
5 changed files with 185 additions and 2 deletions

View File

@ -29,6 +29,11 @@ urlpatterns = patterns('',
(r'^print_article/$', views.article_pdf), (r'^print_article/$', views.article_pdf),
(r'^article_frontend/(?P<product_id>\d+)/(?P<article_order>\d+)/$', views.article_frontend), (r'^article_frontend/(?P<product_id>\d+)/(?P<article_order>\d+)/$', views.article_frontend),
(r'^article_web/(?P<article_id>\d+)/', views.article_webalone), (r'^article_web/(?P<article_id>\d+)/', views.article_webalone),
(r'^articleTitle/$', views.articleTitle),
(r'^lockArticle/$', views.lockArticle),
(r'^publishArticle/$', views.publishArticle),
(r'^issue/(?P<id>\d+)/$', views.edit_issue), (r'^issue/(?P<id>\d+)/$', views.edit_issue),
(r'^product/(?P<id>\d+)/$', views.edit_product), (r'^product/(?P<id>\d+)/$', views.edit_product),
(r'^new_issue/', views.new_issue), (r'^new_issue/', views.new_issue),

View File

@ -527,6 +527,55 @@ def view_article(request, id):
return render_to_response("view_article.html", {'pages': d, 'm': m, 'width': addPx(page_width), 'height': addPx(page_height)}) return render_to_response("view_article.html", {'pages': d, 'm': m, 'width': addPx(page_width), 'height': addPx(page_height)})
@login_required
def articleTitle(request):
user = request.user
id = request.POST.get("id", "0")
article = Article.objects.get(pk=id)
if not article.is_owner(user):
return HttpResponse("sorry, you do not have permission to do that.")
oldTitle = article.name
title = request.POST.get("title", oldTitle)
article.name = title
article.save()
return HttpResponse("title edited. thanks.")
@login_required
def lockArticle(request):
user = request.user
id = request.POST.get("id", "0")
article = Article.objects.get(pk=id)
if not article.is_owner(user):
return HttpResponse("sorry, you do not have permission to do that.")
locked = request.POST.get("locked", "false")
if locked == "true":
article.locked = True
msg = "article locked. it will no longer be editable on the tool page."
else:
article.locked = False
msg = "article unlocked."
article.save()
return HttpResponse(msg)
@login_required
def publishArticle(request):
user = request.user
id = request.POST.get("id", "0")
article = Article.objects.get(pk=id)
if not article.is_owner(user):
return HttpResponse("sorry, you do not have permission to do that.")
published = request.POST.get("published", "false")
if published == "true":
article.published = True
msg = "article published. it will now be browsable on public pages."
else:
article.published = False
msg = "article unpublished. it will no longer be browsable on public pages."
article.save()
return HttpResponse(msg)
@login_required @login_required
def create_article(request): def create_article(request):
if request.POST: if request.POST:
@ -571,6 +620,9 @@ def article_frontend(request, product_id, article_order):
def article_webalone(request, article_id): def article_webalone(request, article_id):
article = Article.objects.get(pk=article_id) article = Article.objects.get(pk=article_id)
user = request.user
if not article.can_view(user):
return HttpResponse("sorry, you do not have the permissions to view this article")
width = article.view_size()[0] width = article.view_size()[0]
height = article.view_size()[1] height = article.view_size()[1]
pages = article.get_dict() pages = article.get_dict()
@ -581,6 +633,9 @@ def article_webalone(request, article_id):
'height': height, 'height': height,
'width': width, 'width': width,
'm': 1, 'm': 1,
'locked': article.locked,
'published': article.published,
'is_owner': article.is_owner(user),
'article': article, 'article': article,
'articles_before': [], 'articles_before': [],
'articles_after': [] 'articles_after': []

View File

@ -28,6 +28,10 @@ text-decoration:none;}
top: 50px; top: 50px;
} }
#articleEditWrapper {
margin-bottom: 20px;
}
#header ul li { #header ul li {
float: left; float: left;
margin-right: 30px; margin-right: 30px;
@ -301,8 +305,42 @@ a img
display: none; display: none;
} }
.pdfLink {
margin-left: 8px;
color: #393939;
text-decoration: none;
font-family: "DejaVu Sans", Arial, sans-serif;
}
.pdfLink a {
text-decoration: none;
}
.pdfLink a:hover {
color: #fff;
}
h5 {
margin: 0;
padding: 0;
}
#articleAdminH {
cursor: pointer;
margin: 4px;
}
#articleAdminH:hover {
color: #fff;
}
#articleFormToggle {
display: none;
}
#scrollDots { #scrollDots {
margin-top: -10px; margin-top: 0px;
} }
.dotDiv { .dotDiv {

View File

@ -65,7 +65,57 @@ $(document).ready(function() {
$('.english').show(); $('.english').show();
$('.arabic').hide(); $('.arabic').hide();
$('#scrollDots').css("direction", "ltr"); $('#scrollDots').css("direction", "ltr");
});
$('#articleAdminH').toggle(function() {
$('#articleFormToggle').slideDown();
}, function() {
$('#articleFormToggle').slideUp();
});
$('#titleForm').submit(function(e) {
e.preventDefault();
var $this = $(this);
var id = $('#articleId').val();
var title = $('#articleTitle').val();
//alert(title);
$this.attr("disabled", "disabled");
$this.val("Submitting...");
$('#articleName').text(title);
$.post("/edit/articleTitle/", {
'title': title,
'id': id
}, function(response) {
$this.removeAttr("disabled");
$this.val("Change Title");
alert(response);
}); });
});
$('#lockArticle').change(function() {
var $this = $(this);
var id = $('#articleId').val();
var checked = $(this).is(":checked");
$.post("/edit/lockArticle/", {
'id': id,
'locked': checked
}, function(response) {
alert(response);
});
});
$('#publishArticle').change(function() {
var checked = $(this).is(":checked");
$.post("/edit/publishArticle/", {
'id': $('#articleId').val(),
'published': checked
}, function(response) {
alert(response);
});
});
}); });
function scrollPages() { function scrollPages() {

View File

@ -220,7 +220,42 @@ p {
<p>&nbsp;</p> <p>&nbsp;</p>
<div id="contents"> <div id="contents">
<div class="english"> <div class="english">
<p>{{ article.name }} (<a target="_blank" href="/edit/print_article/?id={{article.id}}" title="Download PDF">get pdf</a>)<br /><br /> <div id="dotsHeader">
<p><span id="articleName">{{ article.name }}</span>
<span class="pdfLink">
&lt;&lt;
<a target="_blank" href="/edit/print_article/?id={{article.id}}" title="Download PDF">
get pdf
</a>
&gt;&gt;
</span>
</p>
{% if is_owner %}
<div id="articleEditWrapper">
<h5 id="articleAdminH">Article Admin</h5>
<div id="articleFormToggle">
<p>
<form id="titleForm" method="post" action="">
<input type="hidden" id="articleId" value="{{ article.id }}" />
<input type="text" id="articleTitle" value="{{ article.name }}" />
<input type="submit" id="submitTitleBtn" value="Change Title" />
</form>
</p>
<p>
Lock Article: <input type="checkbox" id="lockArticle" {% if locked %} checked="checked" {% endif %}>
</p>
<p>
Publish Article: <input type="checkbox" id="publishArticle" {% if published %} checked="checked" {% endif %}>
</p>
<p>
</p>
</div>
</div>
{% endif %}
</div>
{% for a_b in articles_before %} {% for a_b in articles_before %}
<a href="../../{{a_b.product.id}}/{{a_b.order}}/">{{a_b.order}}</a>. {{a_b.name}}<br /> <a href="../../{{a_b.product.id}}/{{a_b.order}}/">{{a_b.order}}</a>. {{a_b.name}}<br />
{% endfor %} {% endfor %}