diff options
author | Wojciech Polak <polak@gnu.org> | 2010-12-30 12:47:15 +0100 |
---|---|---|
committer | Wojciech Polak <polak@gnu.org> | 2010-12-30 12:47:15 +0100 |
commit | 3ea3bb6b86c6352615829199eefdfa3985d675ab (patch) | |
tree | baeef579075ba830f6c7ce6c961799b597cb3482 | |
parent | 295d7dc7967dd30c3d872ad527eb7d1cf542e9d2 (diff) | |
download | glifestream-3ea3bb6b86c6352615829199eefdfa3985d675ab.tar.gz glifestream-3ea3bb6b86c6352615829199eefdfa3985d675ab.tar.bz2 |
Add inline entry content editing.
-rw-r--r-- | static/js/glifestream.js | 38 | ||||
-rw-r--r-- | static/themes/default/style.css | 16 | ||||
-rw-r--r-- | stream/views.py | 17 | ||||
-rw-r--r-- | templates/stream-pure.html | 3 | ||||
-rw-r--r-- | templates/stream.html | 7 |
5 files changed, 79 insertions, 2 deletions
diff --git a/static/js/glifestream.js b/static/js/glifestream.js index 7db6f30..1bb8736 100644 --- a/static/js/glifestream.js +++ b/static/js/glifestream.js @@ -246,6 +246,40 @@ }); } + function edit_entry (e) { + if (e) e.preventDefault (); + var that = this; + var id = this.id.split ('-')[1]; + show_spinner ($M (this)); + $.post (baseurl + 'api/getcontent', {entry: id, raw: 1}, function (html) { + hide_spinner (); + var ec = $(that).closest ('article').find ('.entry-content'); + var editor = $('#entry-editor'); + $('#edited-content').val (html); + ec.after (editor); + editor.fadeIn ('normal', function () { + scroll_to_element (editor, 400); + }); + }); + } + + function editor_handler (e) { + var op = this.getAttribute ('name'); + if (op == 'cancel') + $('#entry-editor').fadeOut (); + else if (op == 'save') { + show_spinner (this); + var article = $(this).closest ('article').get (0); + var id = parse_id (article.id)[1]; + $.post (baseurl + 'api/putcontent', + { entry: id, content: $('#edited-content').val () }, + function (html) { + hide_spinner (); + $('#entry-'+ id +' .entry-content').html (html); + }); + } + } + function change_theme () { var cookie_name = 'glifestream_theme'; var cs = read_cookie (cookie_name); @@ -657,6 +691,7 @@ $('a.favorite-control', stream).live ('click', favorite_entry); $('a.hide-control', stream).live ('click', hide_entry); $('a.translate-control', stream).live ('click', translate_entry); + $('a.edit-control', stream).live ('click', edit_entry); $('a.shareit', stream).live ('click', shareit_entry); $('a.map', stream).each (render_map); $('a.show-map', stream).live ('click', show_map); @@ -669,6 +704,7 @@ if (this.value != '') window.location = baseurl + 'list/' + this.value + '/'; }); + $('#entry-editor input[type=button]').live ('click', editor_handler); gen_archive_calendar (); $('#calendar a.prev').live ('click', function () { @@ -692,7 +728,7 @@ this.title = _('Click and Listen'); }); - $('#status, form input[type=text]'). + $('#status, #edited-content, form input[type=search]'). focus (function () { document.onkeypress = null; }). blur (function () { document.onkeypress = kshortcuts; }); diff --git a/static/themes/default/style.css b/static/themes/default/style.css index 9f408f4..99ba784 100644 --- a/static/themes/default/style.css +++ b/static/themes/default/style.css @@ -295,6 +295,22 @@ p.subtitle a:hover { text-decoration: none; } margin-bottom: 3px; } +#entry-editor { + margin: 10px 0 0 60px; + line-height: 140%; + padding: 5px; + border: none; + background-color: whitesmoke; + border-radius: 4px; + -moz-border-radius: 4px; + -webkit-border-radius: 4px; +} +#entry-editor textarea { + font-size: smaller; + width: 95%; + height: 100px; +} + .services { padding: 0 0 1em 0; margin: 0 0 1em 0; diff --git a/stream/views.py b/stream/views.py index c7233dc..4dc67dd 100644 --- a/stream/views.py +++ b/stream/views.py @@ -552,6 +552,9 @@ def api (request, **args): else: entry = Entry.objects.get (id=int(entry)) if entry: + if request.POST.get('raw', False) and authed: + return HttpResponse (entry.content) + if authed or friend: entry.friends_only = False content = fix_ampersands (gls_content ('', entry)) @@ -559,6 +562,20 @@ def api (request, **args): except Exception: pass + elif cmd == 'putcontent': + try: + if entry and authed: + content = request.POST.get ('content', '') + if content: + Entry.objects.filter (id=int(entry)).update ( + content=content) + entry = Entry.objects.get (id=int(entry)) + if entry: + content = fix_ampersands (gls_content ('', entry)) + return HttpResponse (content) + except Exception: + pass + elif cmd == 'translate': try: if entry: diff --git a/templates/stream-pure.html b/templates/stream-pure.html index 939423b..d96c9a5 100644 --- a/templates/stream-pure.html +++ b/templates/stream-pure.html @@ -39,7 +39,8 @@ {% endif %} <li><a id="hide-{{ entry.id }}" class="hide-control" href="#">{% trans "Hide" %}</a></li> <li><a id="translate-{{ entry.id }}" class="translate-control" href="#">{% trans "Translate" %}</a></li> - <li><a href="{% url admin:index %}stream/entry/{{ entry.id }}">{% trans "Edit" %}</a></li> + <li><a id="edit-{{ entry.id }}" class="edit-control" href="#">{% trans "Edit" %}</a></li> + <li><a href="{% url admin:index %}stream/entry/{{ entry.id }}" target="_blank">{% trans "Admin" %}</a></li> </ul> {% endif %} {% if not entry.friends_only %}<a href="#" id="shareit-{{ entry.id }}" class="shareit{% if authed %} reshareit{% endif %}" title="{% trans "Share or bookmark this entry" %}"><span>{% trans "Share" %}</span></a>{% endif %} diff --git a/templates/stream.html b/templates/stream.html index 1adea0e..89616f0 100644 --- a/templates/stream.html +++ b/templates/stream.html @@ -69,6 +69,13 @@ </div> </form> </aside> +<aside id="entry-editor" style="display:none"> + <textarea id="edited-content" cols="50" rows="4"></textarea> + <div> + <input type="button" name="save" value="{% trans 'Save' %}" /> + <input type="button" name="cancel" value="{% trans 'Cancel' %}" /> + </div> +</aside> {% endif %} <section id="stream" class="hfeed"> {% if page.subtitle %} |