Permalink
Browse files

adding edit pin

  • Loading branch information...
1 parent 74dc75a commit d6355ad4c444ab84d019b157641582339935c9a4 @danieleguido committed Mar 15, 2013
Showing with 225 additions and 100 deletions.
  1. +2 −1 glue/api.py
  2. +3 −2 glue/forms.py
  3. +5 −0 static/js/oo.js
  4. +105 −54 static/js/oo/glue.js
  5. +15 −1 static/less/style.less
  6. +35 −26 templates/walt/index.html
  7. +60 −16 templates/walt/middle.html
View
@@ -280,10 +280,11 @@ def pin( request, pin_id ):
form = EditPinForm( request.REQUEST )
if form.is_valid():
try:
- pin = Pin.objects.get( id=pin_id )
+ pin = Pin.objects.get( id=pin_id, authors=request.user )
pin.title = form.cleaned_data['title']
pin.abstract = form.cleaned_data['abstract']
pin.content = form.cleaned_data['content']
+ pin.permalink = form.cleaned_data['permalink']
pin.save()
except Pin.DoesNotExist, e:
return response.throw_error( error="%s" % e, code=API_EXCEPTION_DOESNOTEXIST).json()
View
@@ -59,8 +59,9 @@ def __init__(self, *args, **kwargs):
class EditPinForm(forms.Form):
title = forms.CharField( label=_("title"),required=True )
- abstract = forms.CharField( label=_("abstract"), required=True, widget=forms.Textarea )
- content = forms.CharField( label=_("content"), required=True, widget=forms.Textarea )
+ abstract = forms.CharField( label=_("abstract"), required=False, widget=forms.Textarea )
+ content = forms.CharField( label=_("content"), required=False, widget=forms.Textarea )
+ permalink = forms.URLField( required=False )
class UploadPinForm(forms.Form): # an upload form without file :D (upload via ajax)
page_slug = forms.SlugField( required=False, widget=forms.HiddenInput )
View
@@ -118,6 +118,11 @@ oo.api.Builder = function( model ){
instance.ajax( 'get', 'get', params, oo.api.urlfactory( oo.urls[ 'get_' + instance.model ], params.id ), callback );
}
+ this.edit = function( params, callback ){
+
+ instance.ajax( 'post', 'edit', params, oo.api.urlfactory( oo.urls[ 'edit_' + instance.model ], params.id ), callback );
+ }
+
this.list = function( params ){
instance.ajax( 'get', 'list', params, oo.urls[ 'list_' + instance.model ] );
}
View
@@ -43,6 +43,9 @@ oo.magic.pin.get = function( result ){
*/
oo.glue = {};
+oo.glue.pin = {};
+oo.glue.pin.listeners = {};
+
oo.glue.resize = function(){
var h = $(window).height();
@@ -62,86 +65,134 @@ oo.glue.resize = function(){
// h - hh - fh
//);
}
-oo.glue.init = function(){ oo.log("[oo.glue.init]");
-
- // compile pin api
- oo.api.compile( 'pin' );
- // bib text parser init
- oo.glue.bibtex.init();
+oo.glue.pin.listeners.edit = function( event ){
+ var pin_id = $(this).attr("data-id");
+ oo.log("[oo.glue.pin.listeners.edit] pin id :", pin_id);
+
+ // get pin and activate modal
+ oo.api.pin.get({id:pin_id}, function( result ){
+ oo.log("[oo.api.pin.get:callback]", result);
+ $("#id_edit_pin_id").val( pin_id );
+ $("#id_edit_pin_title").val( result.object.title );
+ $("#id_edit_pin_permalink").val( result.object.permalink );
+ $("#id_edit_pin_abstract").val( result.object.abstract );
+ $("#id_edit_pin_content").val( result.object.content );
+ $("#edit-pin-modal").modal({show:true});
+
+ });
- // input.repeatable: copy $.val() to targeted data-target element
- $(document).on('keyup', 'input.repeatable', function(event){ var $this = $(this); $( '#' + $this.attr('data-target') ).val( oo.fn.slug( $this.val() ) );});
+ // load and callback to oo.glue.pin.edit
+};
- $(document).on('keyup', 'textarea.embeddable', oo.glue.embed.keyup );
-
+oo.glue.pin.listeners.update = function(event){ event.preventDefault();
+ var el = $(this);
+ // get django form auto_id
+ var auto_id = el.attr("data-auto-id");
+ oo.log("[oo.glue.init:$('.update-pin'):click] form namespace 'auto_id' : ", auto_id);
+
+
+ var params = {
+ id:$("#" + auto_id + "_id").val(),
+ title:$("#" + auto_id + "_title").val(),
+ content:$("#" + auto_id + "_content").val(),
+ abstract:$("#" + auto_id + "_abstract").val(),
+ permalink:$("#" + auto_id + "_permalink").val(),
+ auto_id: auto_id
+ }
+ oo.log("[oo.glue.init:$('.update-pin'):click] edit pin : ", params.id );
+ oo.api.pin.edit( params );
+}
- // remove invalid elements
- $(document).click( function(event){ $(".invalid").removeClass('invalid');});
+oo.glue.pin.listeners.add = function(event){ event.preventDefault();
+ var el = $(this);
- // modal max height
- oo.on('resize', function(){ oo.fn.wait( oo.glue.resize, 100 );});
- oo.glue.resize()
+ // get django form auto_id
+ var auto_id = el.attr("data-auto-id"); // eg "id_add_walt_w" or "id_add_walt_l"
- // generic pin adder to walt page, with error control
- $(".add-walt-pin").on("click", function(event){ event.preventDefault();
- var el = $(this);
+ oo.log("[oo.glue.init:$('.add-walt-pin'):click] form namespace 'auto_id' : ", auto_id)
- // get django form auto_id
- var auto_id = el.attr("data-auto-id"); // eg "id_add_walt_w" or "id_add_walt_l"
+ // build stuff
+ var permalink = $("#" + auto_id + "_permalink").val();
+ var page_slug = el.attr("data-page-slug"); // page parent slug. It could be undefined
+ var pin_slug = el.attr("data-pin-slug"); // pin parent slug. It could be undefined.
- oo.log("[oo.glue.init:$('.add-walt-pin'):click] form namespace 'auto_id' : ", auto_id)
+ var content = $("#" + auto_id + "_content").val();
+ var mimetype = $("#" + auto_id + "_mimetype").val();
+
- // build stuff
- var permalink = $("#" + auto_id + "_permalink").val();
- var page_slug = el.attr("data-page-slug"); // page parent slug. It could be undefined
- var pin_slug = el.attr("data-pin-slug"); // pin parent slug. It could be undefined.
+ oo.log("[oo.glue.init:click] #add-pin, page-slug:", page_slug, ", parent-pin-slug:", pin_slug );
- var content = $("#" + auto_id + "_content").val();
- var mimetype = $("#" + auto_id + "_mimetype").val();
-
+ var params = {
+ title_en:$("#" + auto_id + "_title_en").val(),
+ title_fr:$("#" + auto_id + "_title_en").val(),
+ title_it:$("#" + auto_id + "_title_en").val(),
+ slug:$("#" + auto_id + "_slug").val(),
+ auto_id: auto_id
+ }
- oo.log("[oo.glue.init:click] #add-pin, page-slug:", page_slug, ", parent-pin-slug:", pin_slug );
- var params = {
- title_en:$("#" + auto_id + "_title_en").val(),
- title_fr:$("#" + auto_id + "_title_en").val(),
- title_it:$("#" + auto_id + "_title_en").val(),
- slug:$("#" + auto_id + "_slug").val(),
- auto_id: auto_id
- }
+ if ( typeof permalink != "undefined" && permalink.length ){
+ $.extend(params,{permalink:permalink});
+ }
+ if ( typeof content != "undefined" && content.length ){
+ $.extend(params,{content:content});
+ }
- if ( typeof permalink != "undefined" && permalink.length ){
- $.extend(params,{permalink:permalink});
- }
+ if ( typeof mimetype != "undefined" && mimetype.length ){
+ $.extend(params,{mimetype:mimetype});
+ }
- if ( typeof content != "undefined" && content.length ){
- $.extend(params,{content:content});
- }
+ if ( typeof page_slug != "undefined" && page_slug.length ){
+ $.extend(params,{page_slug:page_slug});
+ }
- if ( typeof mimetype != "undefined" && mimetype.length ){
- $.extend(params,{mimetype:mimetype});
- }
+ if ( typeof pin_slug != "undefined" && pin_slug.length ){
+ $.extend(params,{parent_pin_slug:pin_slug});
+ }
- if ( typeof page_slug != "undefined" && page_slug.length ){
- $.extend(params,{page_slug:page_slug});
- }
+ // procede to api
+ oo.api.pin.add( params );
+}
- if ( typeof pin_slug != "undefined" && pin_slug.length ){
- $.extend(params,{parent_pin_slug:pin_slug});
- }
+oo.glue.init = function(){ oo.log("[oo.glue.init]");
+
+ // compile pin api
+ oo.api.compile( 'pin' );
- // procede to api
- oo.api.pin.add( params );
- });
+ // bib text parser init
+ oo.glue.bibtex.init();
+ // input.repeatable: copy $.val() to targeted data-target element
+ $(document).on('keyup', 'input.repeatable', function(event){ var $this = $(this); $( '#' + $this.attr('data-target') ).val( oo.fn.slug( $this.val() ) );});
+ $(document).on('keyup', 'textarea.embeddable', oo.glue.embed.keyup );
+ // remove invalid elements
+ $(document).click( function(event){ $(".invalid").removeClass('invalid');});
+
+ $(document).on('shown', function () {
+ oo.log( "ehi" );
+ $('input:text:visible:first', this).focus();
+ });
+ // modal max height
+ oo.on('resize', function(){ oo.fn.wait( oo.glue.resize, 100 );});
+ oo.glue.resize();
+
+
+ // open generic pin editor (ajax load the pin)
+ $(".edit-pin").on("click", oo.glue.pin.listeners.edit );
+
+ // save edited pin
+ $(".update-pin").on("click", oo.glue.pin.listeners.update );
+
+ // generic pin adder to walt page, with error control
+ $(".add-walt-pin").on("click", oo.glue.pin.listeners.add );
};
@@ -369,7 +369,7 @@ p.invalid{
.border-radius(2px);
}
-input.invalid{
+input.invalid, textarea.invalid{
border: 1px solid #cc1400;
}
@@ -417,8 +417,22 @@ input.invalid{
.modal{
width: 492px;
margin-left: -246px;
+ margin-top: 2px;
.border-radius(0);
&.fade.in {
top: 0;
}
+
+ &.fade{
+ top: -100%;
+ opacity: 1;
+ }
+}
+.modal-backdrop{
+ &.fade.in{
+ opacity: .12;
+ }
+}
+.modal-body{
+ max-height: 600px;
}
@@ -6,11 +6,19 @@
{% block urls %}
{{ block.super }}
+ {% if user.is_authenticated %}
oo.urls.get_serie = "{% url glue_api_serie_frames 0 %}";
oo.urls.list_serie = "{% url glue_api_series %}";
oo.urls.remove_serie = "{% url glue_api_serie 0 %}";
oo.urls.add_serie = "{% url glue_api_series %}";
oo.urls.edit_serie = "{% url glue_api_serie 0 %}";
+
+
+ oo.urls.get_pin = "{% url glue_api_pin 0 %}";
+ oo.urls.list_pin = "{% url glue_api_pins %}";
+ oo.urls.edit_pin = "{% url glue_api_pin 0 %}";
+
+ {% endif %}
{% endblock %}
{% block navbar %}
@@ -191,19 +199,17 @@ <h2 style="text-align: center"><a href="{% url walt_login %}">&rarr; {% trans "p
<a href="{% url walt_tag tag.type|lower tag.slug %}" class="tag" alt="{{ tag.name }} ( {{ tag.type }} )">{{ tag.name }}</a>
{% if not forloop.last %},{%endif %}
{% endfor %}
- <p class="authors">
- {%trans "posted by" %}
+ <span class="authors">
+ &middot; {%trans "posted by" %}
{% for u in pin.authors.all %}
<a href="{% url walt_spiff u.username %}">{{ u.username }}</a>
{% if not forloop.last %}, {% endif %}
{% endfor %}
- </p>
- <p>
- <a href="{% url admin:glue_pin_change pin.id %}">&rarr; {% trans "edit" %}</a>
- <ul>
- <li style="float:left" class="drag-to-serie draggable" data-slug="{{ pin.slug }}" data-mimetype="{{ pin.mimetype }}" data-id="{{ pin.id }}">{% trans "drag" %}</li>
- </ul>
- </p>
+ </span>
+ <span>
+ <a href="#{% url admin:glue_pin_change pin.id %}" class="edit-pin" data-id="{{ pin.id }}">&rarr; {% trans "edit" %}</a>
+
+ </span>
</div>
<blockquote>
{{ pin.abstract }}
@@ -238,17 +244,16 @@ <h2 style="text-align: center"><a href="{% url walt_login %}">&rarr; {% trans "p
<a href="{% url walt_tag tag.type|lower tag.slug %}" class="tag" alt="{{ tag.name }} ( {{ tag.type }} )">{{ tag.name }}</a>
{% if not forloop.last %},{%endif %}
{% endfor %}
- <p class="authors">
- {%trans "posted by" %}
+ <span class="authors">
+ &middot; {%trans "posted by" %}
{% for u in pin.authors.all %}
<a href="{% url walt_spiff u.username %}">{{ u.username }}</a>
{% if not forloop.last %}, {% endif %}
{% endfor %}
- </p>
- <p>
- <a href="{% url admin:glue_pin_change pin.id %}">&rarr; {% trans "edit" %}</a>,
- <a href="#" class="drag-to-serie" data-slug="{{ pin.slug }}" data-mimetype="{{ pin.mimetype }}" data-id="{{ pin.id }}">{% trans "add to serie" %}</a>
- </p>
+ </span>
+ <span>
+ <a href="#{% url admin:glue_pin_change pin.id %}" class="edit-pin" data-id="{{ pin.id }}">&rarr; {% trans "edit" %}</a>
+ </span>
</div>
<blockquote>
{{ pin.abstract }}
@@ -286,15 +291,17 @@ <h2 style="text-align: center"><a href="{% url walt_login %}">&rarr; {% trans "p
<a href="#" class="tag" alt="{{ tag }}">{{ tag }}</a>
{% if not forloop.last %},{%endif %}
{% endfor %}
- <p class="authors">
- {%trans "posted by" %}
+ <span class="authors">
+ &middot; {%trans "posted by" %}
{% for u in pin.authors.all %}
<a href="{% url walt_spiff u.username %}">{{ u.username }}</a>
{% if not forloop.last %}, {% endif %}
{% endfor %}
- </p>
- <p><a href="{% url admin:glue_pin_change pin.id %}">&rarr; {% trans "edit" %}</a>,
- <a href="#" class="drag-to-serie" data-slug="{{ pin.slug }}" data-mimetype="{{ pin.mimetype }}" data-id="{{ pin.id }}">{% trans "add to serie" %}</a></p>
+ </span>
+ <span>
+ <a href="#{% url admin:glue_pin_change pin.id %}" class="edit-pin" data-id="{{ pin.id }}">&rarr; {% trans "edit" %}</a>
+
+ </span>
</div>
<blockquote>
{% if bibtex.abstract %} {{ bibtex.abstract }} {% endif %}
@@ -325,15 +332,17 @@ <h2 style="text-align: center"><a href="{% url walt_login %}">&rarr; {% trans "p
<a href="{% url walt_tag tag.type|lower tag.slug %}" class="tag" alt="{{ tag.name }} ( {{ tag.type }} )">{{ tag.name }}</a>
{% if not forloop.last %},{%endif %}
{% endfor %}
- <p class="authors">
- {%trans "posted by" %}
+ <span class="authors">
+ &middot; {%trans "posted by" %}
{% for u in pin.authors.all %}
<a href="{% url walt_spiff u.username %}">{{ u.username }}</a>
{% if not forloop.last %}, {% endif %}
{% endfor %}
- </p>
- <p><a href="{% url admin:glue_pin_change pin.id %}">&rarr; {% trans "edit" %}</a>,
- <a href="#" class="drag-to-serie" data-slug="{{ pin.slug }}" data-mimetype="{{ pin.mimetype }}" data-id="{{ pin.id }}">{% trans "add to serie" %}</a></p>
+ </span>
+ <span>
+ <a href="#{% url admin:glue_pin_change pin.id %}" class="edit-pin" data-id="{{ pin.id }}">&rarr; {% trans "edit" %}</a>
+
+ </span>
</div>
<blockquote>
{{ pin.abstract }}
Oops, something went wrong.

0 comments on commit d6355ad

Please sign in to comment.