# HG changeset patch # User cavaliet # Date 1408541810 -7200 # Node ID 05c9f6551fde32cd10baf76dfbefbb681d312457 # Parent c949cb4316136b9ad003992d5368b34e2325ad35 ajax login and save diff -r c949cb431613 -r 05c9f6551fde src/hdalab/static/hdalab/css/additionnal_renkan.css --- a/src/hdalab/static/hdalab/css/additionnal_renkan.css Tue Aug 19 18:33:53 2014 +0200 +++ b/src/hdalab/static/hdalab/css/additionnal_renkan.css Wed Aug 20 15:36:50 2014 +0200 @@ -1,3 +1,6 @@ #container { overflow: hidden; +} +.hand{ + cursor: pointer; } \ No newline at end of file diff -r c949cb431613 -r 05c9f6551fde src/hdalab/static/hdalab/js/renkan-manual-save.js --- a/src/hdalab/static/hdalab/js/renkan-manual-save.js Tue Aug 19 18:33:53 2014 +0200 +++ b/src/hdalab/static/hdalab/js/renkan-manual-save.js Wed Aug 20 15:36:50 2014 +0200 @@ -22,6 +22,10 @@ success: function(_data) { _proj.set(_data, {validate: true}); _renkan.renderer.autoScale(); + // Green color when user is authenticated + if(_opts.user_authenticated==true){ + $(".Rk-Save-Button").addClass("Rk-Save-Online"); + } } }); }; @@ -34,11 +38,12 @@ contentType: "application/json", data: JSON.stringify(_data), success: function(data, textStatus, jqXHR) { - console.log("RMS success !"); + console.log("RMS success !", data); $(window).off("beforeunload", _onLeave); _saveWarn = false; - //document.location.hash = "#id=" + data.id; - //$(".Rk-Notifications").text("Saved as "+document.location.href).fadeIn().delay(2000).fadeOut(); + if(data.substr(0,6)=="rk_id="){ + _opts.url = _opts.url.split("?")[0] + "?" + data; + } } }); }; diff -r c949cb431613 -r 05c9f6551fde src/hdalab/templates/ajax_identification/ajax_login_ok.html --- a/src/hdalab/templates/ajax_identification/ajax_login_ok.html Tue Aug 19 18:33:53 2014 +0200 +++ b/src/hdalab/templates/ajax_identification/ajax_login_ok.html Wed Aug 20 15:36:50 2014 +0200 @@ -1,5 +1,8 @@ -
OK
-
+{% load i18n %} +
+

OK

{% trans "Close window" %}

+
\ No newline at end of file diff -r c949cb431613 -r 05c9f6551fde src/hdalab/templates/renkan_edit.html --- a/src/hdalab/templates/renkan_edit.html Tue Aug 19 18:33:53 2014 +0200 +++ b/src/hdalab/templates/renkan_edit.html Wed Aug 20 15:36:50 2014 +0200 @@ -87,7 +87,7 @@ language: "fr" }); - io_options = { url: "{% url 'renkan_get_put' %}" + window.location.search, user_authenticated: {% if request.user.is_authenticated %}true{% else %}false{% endif %} }; + io_options = { url: "{% url 'renkan_get_put' %}" + window.location.search, user_authenticated: {% if user.is_authenticated %}true{% else %}false{% endif %} }; Rkns.jsonIOSaveOnClick(_renkan, io_options); }; @@ -109,6 +109,20 @@ url: f.attr("action"), data: f.serialize(), success: function(data, textStatus, jqXHR) { + var d = $(data); + if($(".ok",d).length==1){ + $("#dialog-form").html($(".ok",d)[0]); + $(".hello-user").remove(); + $("#nav").append($(".username",d).children()); + //$("#dialog-form .close").click(function(){ + // dialog.dialog( "close" ); + //}); + io_options.user_authenticated = true; + $(".Rk-Save-Button").addClass("Rk-Save-Online"); + dialog.dialog( "close" ); + $(".Rk-Save-Button").click(); + return true; + } $("#dialog-form").html(data); // in case, login failed, we reassign the behaviour form = dialog.find( "form" ).on( "submit", function( event ) { diff -r c949cb431613 -r 05c9f6551fde src/hdalab/views/profile.py --- a/src/hdalab/views/profile.py Tue Aug 19 18:33:53 2014 +0200 +++ b/src/hdalab/views/profile.py Wed Aug 20 15:36:50 2014 +0200 @@ -13,7 +13,7 @@ from django.contrib.sites.models import get_current_site from django.core.urlresolvers import reverse from django.db.models import Q -from django.http import HttpResponse +from django.http import HttpResponse, HttpResponseBadRequest from django.http import HttpResponseRedirect from django.shortcuts import get_object_or_404, redirect from django.shortcuts import resolve_url @@ -230,19 +230,72 @@ response = json.dumps(content) - if request.user.is_authenticated(): - rk = Renkan() - rk.rk_id = unicode(uuid.uuid1()) - rk.title = title - rk.content = response - rk.owner = request.user - rk.save() - hr = HdalabRenkan() - hr.renkan = rk - hr.state = HdalabRenkan.EDITION - hr.save() +# if request.user.is_authenticated(): +# rk = Renkan() +# rk.rk_id = unicode(uuid.uuid1()) +# rk.title = title +# rk.content = response +# rk.owner = request.user +# rk.save() +# hr = HdalabRenkan() +# hr.renkan = rk +# hr.state = HdalabRenkan.EDITION +# hr.save() return HttpResponse(response, content_type="application/json") + + + def post(self, request): + + rk_id = request.GET.get("rk_id", "") + #data = json.loads(request.body) + logger.debug("YEAH !") + #logger.debug(data["edges"]) + #logger.debug(data["nodes"]) + #logger.debug(request.user.is_authenticated()) + #logger.debug(request.user.is_anonymous()) + if rk_id!="": + rk = get_object_or_404(Renkan, rk_id=rk_id) + if rk.owner!=request.user: + return HttpResponseBadRequest("You are not allowed to edit this renkan") + rk.content = request.body + data = json.loads(request.body) + if "title" in data: + rk.title = data["title"] + rk.save() + return HttpResponse("SAVED") + else: + logger.debug("1") + # if rk_id was not a get parameter AND if it is set in json data AND if user is authenticated + # Then we can save the renkan + data = json.loads(request.body) + logger.debug("2") + if "id" in data: + logger.debug("3") + rk_id = data["id"] + logger.debug("4") + logger.debug(rk_id) + logger.debug(Renkan.objects.filter(rk_id=rk_id)) + logger.debug(Renkan.objects.filter(rk_id=rk_id).count()) + logger.debug(request.user.is_authenticated()) + logger.debug(request.user) + if rk_id != "" and Renkan.objects.filter(rk_id=rk_id).count()==0 and request.user.is_authenticated(): + logger.debug("5") + rk = Renkan() + rk.rk_id = rk_id + rk.title = data["title"] if "title" in data else "" + rk.content = data + rk.owner = request.user + rk.save() + hr = HdalabRenkan() + hr.renkan = rk + hr.state = HdalabRenkan.EDITION + hr.save() + logger.debug("6") + return HttpResponse("rk_id=" + rk_id) + + + return HttpResponse("NOT SAVED")