From c4a8957161b47dd10d9fcaf4e5baf23e3b3e1efc Mon Sep 17 00:00:00 2001 From: Sanj Date: Sat, 9 Jul 2011 01:18:30 +0530 Subject: [PATCH] ability to edit title, publish and lock articles on web frontend page --- edgware/editor/urls.py | 5 +++ edgware/editor/views.py | 55 +++++++++++++++++++++++++ edgware/static/css/articleDemo.css | 40 +++++++++++++++++- edgware/static/js/articleMockup.js | 50 ++++++++++++++++++++++ edgware/templates/article_frontend.html | 37 ++++++++++++++++- 5 files changed, 185 insertions(+), 2 deletions(-) diff --git a/edgware/editor/urls.py b/edgware/editor/urls.py index 55b66cd..a4ba4dc 100644 --- a/edgware/editor/urls.py +++ b/edgware/editor/urls.py @@ -29,6 +29,11 @@ urlpatterns = patterns('', (r'^print_article/$', views.article_pdf), (r'^article_frontend/(?P\d+)/(?P\d+)/$', views.article_frontend), (r'^article_web/(?P\d+)/', views.article_webalone), + + (r'^articleTitle/$', views.articleTitle), + (r'^lockArticle/$', views.lockArticle), + (r'^publishArticle/$', views.publishArticle), + (r'^issue/(?P\d+)/$', views.edit_issue), (r'^product/(?P\d+)/$', views.edit_product), (r'^new_issue/', views.new_issue), diff --git a/edgware/editor/views.py b/edgware/editor/views.py index cad291c..f99e40f 100644 --- a/edgware/editor/views.py +++ b/edgware/editor/views.py @@ -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)}) +@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 def create_article(request): if request.POST: @@ -571,6 +620,9 @@ def article_frontend(request, product_id, article_order): def article_webalone(request, 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] height = article.view_size()[1] pages = article.get_dict() @@ -581,6 +633,9 @@ def article_webalone(request, article_id): 'height': height, 'width': width, 'm': 1, + 'locked': article.locked, + 'published': article.published, + 'is_owner': article.is_owner(user), 'article': article, 'articles_before': [], 'articles_after': [] diff --git a/edgware/static/css/articleDemo.css b/edgware/static/css/articleDemo.css index f49cfbc..6c118c6 100644 --- a/edgware/static/css/articleDemo.css +++ b/edgware/static/css/articleDemo.css @@ -28,6 +28,10 @@ text-decoration:none;} top: 50px; } +#articleEditWrapper { + margin-bottom: 20px; +} + #header ul li { float: left; margin-right: 30px; @@ -301,8 +305,42 @@ a img 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 { - margin-top: -10px; + margin-top: 0px; } .dotDiv { diff --git a/edgware/static/js/articleMockup.js b/edgware/static/js/articleMockup.js index a1ecb48..7754c3e 100644 --- a/edgware/static/js/articleMockup.js +++ b/edgware/static/js/articleMockup.js @@ -65,7 +65,57 @@ $(document).ready(function() { $('.english').show(); $('.arabic').hide(); $('#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() { diff --git a/edgware/templates/article_frontend.html b/edgware/templates/article_frontend.html index 325a5f1..465ba0a 100644 --- a/edgware/templates/article_frontend.html +++ b/edgware/templates/article_frontend.html @@ -220,7 +220,42 @@ p {

 

-

{{ article.name }} (get pdf)

+

+

{{ article.name }} + + << + + get pdf + + >> + +

+ {% if is_owner %} +
+
Article Admin
+
+

+

+ + + +
+

+ +

+ Lock Article: +

+

+ Publish Article: +

+ +

+ +

+
+
+ {% endif %} +
{% for a_b in articles_before %} {{a_b.order}}. {{a_b.name}}
{% endfor %}