Permalink
Browse files

delete a pin

  • Loading branch information...
1 parent ba440f2 commit 12cca5c71602e5600b2b40ea3e684ab66d87f615 @danieleguido committed Mar 22, 2013
Showing with 127 additions and 36 deletions.
  1. +1 −1 glue/api.py
  2. +1 −0 static/js/oo.js
  3. +24 −0 static/js/oo/glue.js
  4. +81 −31 templates/walt/index.html
  5. +20 −4 templates/walt/middle.html
View
@@ -293,7 +293,7 @@ def pin( request, pin_id ):
elif response.method=='DELETE':
try:
- Pin.objects.filter(slug=Pin.objects.get(id=pin_id).slug).delete()
+ Pin.objects.filter(slug=Pin.objects.get(id=pin_id).slug, authors=request.user ).delete()
except Pin.DoesNotExist, e:
return response.throw_error( error="%s" % e, code=API_EXCEPTION_DOESNOTEXIST).json()
return response.json()
View
@@ -130,6 +130,7 @@ oo.api.Builder = function( model ){
}
this.remove = function( params ){
+ params['method'] = 'DELETE'
instance.ajax( 'delete', 'remove', params, oo.api.urlfactory( oo.urls[ 'remove_' + instance.model ], params.id ) );
}
View
@@ -30,7 +30,12 @@ oo.magic.pin.get = function( result ){
oo.log("[oo.magic.pin.get]", result);
// window.location.reload();
}
+oo.magic.pin.remove = function( result ){
+ oo.log("[oo.magic.pin.remove]", result);
+ window.location.reload();
+ // remove item
+}
/*
@@ -110,6 +115,16 @@ oo.glue.pin.listeners.update = function(event){ event.preventDefault();
oo.api.pin.edit( params );
}
+oo.glue.pin.listeners.remove = function(event){ event.preventDefault();
+ var el = $(this);
+
+
+ var pin_id = el.attr("data-id");
+ oo.log("[oo.glue.init:$('.remove-pin'):click] with id 'pin_id' : ", pin_id);
+
+ oo.api.pin.remove({id:pin_id});
+}
+
oo.glue.pin.listeners.add = function(event){ event.preventDefault();
var el = $(this);
@@ -124,6 +139,7 @@ oo.glue.pin.listeners.add = function(event){ event.preventDefault();
var pin_slug = el.attr("data-pin-slug"); // pin parent slug. It could be undefined.
var content = $("#" + auto_id + "_content").val();
+ var abstract = $("#" + auto_id + "_abstract").val();
var mimetype = $("#" + auto_id + "_mimetype").val();
@@ -146,6 +162,10 @@ oo.glue.pin.listeners.add = function(event){ event.preventDefault();
$.extend(params,{content:content});
}
+ if ( typeof abstract != "undefined" && abstract.length ){
+ $.extend(params,{abstract:abstract});
+ }
+
if ( typeof mimetype != "undefined" && mimetype.length ){
$.extend(params,{mimetype:mimetype});
}
@@ -195,6 +215,10 @@ oo.glue.init = function(){ oo.log("[oo.glue.init]");
// save edited pin
$(".update-pin").on("click", oo.glue.pin.listeners.update );
+ // remove pin with the same slug as pin given (remove from all languages)
+ // user should be the object author, an the object shound.nt be used into frames
+ $(".remove-pin").on("click", oo.glue.pin.listeners.remove );
+
// generic pin adder to walt page, with error control
$(".add-walt-pin").on("click", oo.glue.pin.listeners.add );
@@ -17,7 +17,7 @@
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 %}";
-
+ oo.urls.remove_pin = "{% url glue_api_pin 0 %}";
{% endif %}
{% endblock %}
@@ -149,7 +149,11 @@ <h2 style="text-align: center"><a href="{% url walt_login %}">&rarr; {% trans "p
<div class="grid_3 alpha">
+ <!--
+ WANDER
+
+ -->
<div class="items">
{% for pin in walt.wander.pins.all|slice:":10" %}
<div class="item">
@@ -193,7 +197,7 @@ <h2 style="text-align: center"><a href="{% url walt_login %}">&rarr; {% trans "p
{% endif %}
{% if user in authors %}
- <a class="external action warning" href="{{ pin.permalink}}">{% trans "delete" %}</a>
+ <a class="remove-pin action warning" data-id="{{ pin.id }}">{% trans "delete" %}</a>
{% endif %}
</div>
@@ -216,7 +220,11 @@ <h2 style="text-align: center"><a href="{% url walt_login %}">&rarr; {% trans "p
</div>
<div class="grid_3">
+ <!--
+ AUGMENT
+
+ -->
<div class="items">
{% for pin in walt.augment.pins %}
<div class="item">
@@ -250,7 +258,7 @@ <h2 style="text-align: center"><a href="{% url walt_login %}">&rarr; {% trans "p
<a class="external action" href="{{ pin.permalink}}">{% trans "link" %}</a>
{% if user in authors %}
- <a class="external action warning" href="{{ pin.permalink}}">{% trans "delete" %}</a>
+ <a class="remove-pin action warning" data-id="{{ pin.id }}">{% trans "delete" %}</a>
{% endif %}
</div>
{% endwith %}
@@ -269,6 +277,11 @@ <h2 style="text-align: center"><a href="{% url walt_login %}">&rarr; {% trans "p
</div>
<div class="grid_3">
+ <!--
+
+ LEARN
+
+ -->
<div class="items">
{% for pin in walt.learn.pins.all|slice:":10" %}
@@ -283,17 +296,7 @@ <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 %}
- <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 %}
- </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 %}
@@ -302,6 +305,34 @@ <h2 style="text-align: center"><a href="{% url walt_login %}">&rarr; {% trans "p
</blockquote>
+ {% with authors=pin.authors.all %}
+
+ <span class="authors">
+ {%trans "posted by" %}
+ {% for u in authors %}
+ <a href="{% url walt_spiff u.username %}">{{ u.username }}</a>
+ {% if not forloop.last %}, {% endif %}
+ {% endfor %}
+ </span>
+
+ <div class="actions">
+ <a href="#{% url admin:glue_pin_change pin.id %}" class="edit-pin action" data-id="{{ pin.id }}" title="{% trans "edit" %}">{% trans "modify" %}</a>
+
+ {% if pin.permalink %}
+ <a class="external action" href="{{ pin.permalink}}">{% trans "link" %}</a>
+ {% endif %}
+
+ {% if workon_serie %}
+ <a href="#{% url admin:glue_pin_change pin.id %}"
+ class="append-frame action" data-slug="{{ pin.slug }}" data-title="{{ pin.title }}" data-page-slug="wander" data-id="{{ pin.id }}" >{% trans "use in serie" %}</a>
+ {% endif %}
+
+ {% if user in authors %}
+ <a class="remove-pin action warning" data-id="{{ pin.id }}">{% trans "delete" %}</a>
+ {% endif %}
+ </div>
+
+ {% endwith %}
</div>
{% endwith %}
{% endifequal %}
@@ -319,29 +350,48 @@ <h2 style="text-align: center"><a href="{% url walt_login %}">&rarr; {% trans "p
<div class="item">
<h3><a href="{% url walt_pin pin.slug %}"><!-- #{{ pin.id }} -->{{ pin.title }} </a></h3>
- <div class="metadata"><span class="date">{% if pin.date %}{{ pin.date }}{% else %}{{ pin.date_last_modified }}{% endif %}</span>
+ <div class="metadata"><!-- span class="date">{% if pin.date %}{{ pin.date }}{% else %}{{ pin.date_last_modified }}{% endif %}</span -->
{% for tag in pin.tags.all %}
<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 %}
- <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 %}
- </span>
- <span>
- <a href="#{% url admin:glue_pin_change pin.id %}" class="edit-pin" data-id="{{ pin.id }}">&rarr; {% trans "edit" %}</a>
-
- </span>
+
+ </div>
+ <div class="content">
+ {{ pin.abstract|safe }}
</div>
- <blockquote>
- {{ pin.abstract }}
- </blockquote>
- {{ pin.content|safe }}
- <a class="external" href="{{ pin.permalink}}">&rarr; {{ pin.permalink}}</a>
+ <!-- tools does not manifest their content in index page. -->
+
+ {% with authors=pin.authors.all %}
+
+ <span class="authors">
+ {%trans "posted by" %}
+ {% for u in authors %}
+ <a href="{% url walt_spiff u.username %}">{{ u.username }}</a>
+ {% if not forloop.last %}, {% endif %}
+ {% endfor %}
+ </span>
+
+ <div class="actions">
+ <a href="#{% url admin:glue_pin_change pin.id %}" class="edit-pin action" data-id="{{ pin.id }}" title="{% trans "edit" %}">{% trans "modify" %}</a>
+
+ {% if pin.permalink %}
+ <a class="external action" href="{{ pin.permalink}}">{% trans "link" %}</a>
+ {% endif %}
+
+ {% if workon_serie %}
+ <a href="#{% url admin:glue_pin_change pin.id %}"
+ class="append-frame action" data-slug="{{ pin.slug }}" data-title="{{ pin.title }}" data-page-slug="wander" data-id="{{ pin.id }}" >{% trans "use in serie" %}</a>
+ {% endif %}
+
+ {% if user in authors %}
+ <a class="remove-pin action warning" data-id="{{ pin.id }}">{% trans "delete" %}</a>
+ {% endif %}
+ </div>
+
+ {% endwith %}
+
{% for child in pin.children.all|slice:":10" %}
<div class="comment">
@@ -261,17 +261,27 @@ <h1 style="float: left; margin:0; margin-right:24px"><a href="{% url walt_home %
<!-- TRY -->
+ {% if user.is_staff %}
<div id="add-walt-t-modal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h2>{% trans "add a tool" %}</h2>
</div>
<div class="modal-body">
- <p>A short description of your tool
- Each object should have at least a <b>slug</b> and a <b>title</b>.</p>
+ <p>Please provide a short description of your tool, its <b>title</b> and its <b>slug</b>(the url representation of the title).
+
+ </p>
<p>
- <label for='id_add_pin_content'>{% trans "description" %}</label>
+ <label for='id_add_walt_t_abstract'>{% trans "short description" %}</label>
+ <textarea class="span6" id="id_add_walt_t_abstract">
+
+
+ </textarea>
+ <input type='hidden' id="id_add_walt_t_mimetype" value="text/html"/>
+ </p>
+ <p>
+ <label for='id_add_walt_t_content'>{% trans "long description" %}</label>
<textarea class="span6" id="id_add_walt_t_content">
@@ -287,12 +297,18 @@ <h1 style="float: left; margin:0; margin-right:24px"><a href="{% url walt_home %
<label for='id_add_walt_t_slug'>{% trans "slug" %}</label>
<input type='text' class="span6" id="id_add_walt_t_slug" placeholder="slug"/>
</p>
+
+ <p>
+ <label for='id_add_walt_t_permalink'>{% trans "code source location (e.g github url)" %}</label>
+ <input type='text' class="span6" id="id_add_walt_t_permalink" placeholder="http://"/>
+ </p>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">{% trans "close" %}</button>
- <button class="btn btn-primary add-walt-pin" data-page-slug="learn" data-auto-id="id_add_walt_t">{% trans "add publication" %}</button>
+ <button class="btn btn-primary add-walt-pin" data-page-slug="try" data-auto-id="id_add_walt_t">{% trans "add tool" %}</button>
</div>
</div>
+ {% endif %}
{% endif %}
{% endblock %}

0 comments on commit 12cca5c

Please sign in to comment.