diff --git a/media/js/src/modules/snipt.js b/media/js/src/modules/snipt.js index 1f62f53..2a380d2 100644 --- a/media/js/src/modules/snipt.js +++ b/media/js/src/modules/snipt.js @@ -59,30 +59,51 @@ window.location = this.model.get('get_absolute_url'); }, edit: function() { + + var that = this; + window.editing = true; window.ui_halted = true; this.select(); var editPane = this.editTemplate({snipt: this.model.toJSON()}); - var JavaScriptMode = require('ace/mode/javascript').Mode; + //var JavaScriptMode = require('ace/mode/javascript').Mode; window.site.$main.hide(); window.site.$body.addClass('detail editing'); - window.site.$main_edit.html(editPane).show(); + window.site.$main_edit.html(editPane); + + $('option[value="' + this.model.get('lexer') + '"]').attr('selected', 'selected'); + + window.site.$main_edit.show(); $('div#editor', window.site.$main_edit).css('height', ($(window).height() - 187)); - window.editor = ace.edit('editor'); - window.editor.setTheme('ace/theme/tomorrow'); - window.editor.renderer.setShowGutter(false); - window.editor.getSession().setMode(new JavaScriptMode()); - window.editor.$textarea = $('textarea', window.editor.container); - window.editor.focus(); - window.editor.$textarea.bind('keydown', 'esc', function(e) { + var editor = ace.edit('editor'); + editor.setTheme('ace/theme/tomorrow'); + editor.renderer.setShowGutter(false); + //editor.getSession().setMode(new JavaScriptMode()); + editor.focus(); + $('textarea, input', window.site.$main_edit).bind('keydown', 'esc', function(e) { $(this).blur(); return false; }); + $('button.delete', window.site.$main_edit).on('click', function(e) { + if (confirm('Are you sure you want to delete this snipt?')) { + that.model.destroy(); + } + e.preventDefault(); + }); + $('button.cancel', window.site.$main_edit).on('click', function(e) { + window.site.snipt_list.escapeUI(); + return false; + }); + $('button.save', window.site.$main_edit).on('click', function(e) { + that.model.save(); + e.preventDefault(); + }); + window.scrollTo(0, 0); return false; @@ -150,8 +171,10 @@ } }, remove: function() { + console.log('remove() on view called'); }, render: function() { + console.log('render called'); this.$el.html(this.template({ snipt: this.model.toJSON() @@ -273,8 +296,37 @@ model: new Snipt.SniptModel(data) }); }, + escapeUI: function() { + if (window.editing) { + if (!window.site.$html.hasClass('detail')) { + window.site.$body.removeClass('detail'); + } + window.site.$main_edit.hide(); + window.site.$body.removeClass('editing'); + window.site.$main.show(); + + window.editing = true; + window.ui_halted = false; + + if (window.site.$snipts.index(window.$selected) === 0) { + window.scrollTo(0, 0); + } else { + window.site.$html_body.animate({ + scrollTop: window.$selected.offset().top - 50 + }, 0); + } + } else { + if (!window.ui_halted) { + if ($selected) { + $selected.trigger('deselect'); + } + } + } + }, keyboardShortcuts: function() { + var that = this; + $selected = window.selected; $document = $(document); @@ -314,31 +366,7 @@ } }); $document.bind('keydown', 'esc', function() { - if (window.editing) { - if (!window.site.$html.hasClass('detail')) { - window.site.$body.removeClass('detail'); - } - window.site.$main_edit.hide(); - window.site.$body.removeClass('editing'); - window.site.$main.show(); - - window.editing = true; - window.ui_halted = false; - - if (window.site.$snipts.index(window.$selected) === 0) { - window.scrollTo(0, 0); - } else { - window.site.$html_body.animate({ - scrollTop: window.$selected.offset().top - 50 - }, 0); - } - } else { - if (!window.ui_halted) { - if ($selected) { - $selected.trigger('deselect'); - } - } - } + that.escapeUI(); }); $document.bind('keydown', 'g', function() { if (!window.ui_halted) { diff --git a/snipts/templates/snipts/snipt-edit-js-template.html b/snipts/templates/snipts/snipt-edit-js-template.html index bcdc0d2..bb2d5d6 100644 --- a/snipts/templates/snipts/snipt-edit-js-template.html +++ b/snipts/templates/snipts/snipt-edit-js-template.html @@ -31,13 +31,17 @@
- +
diff --git a/snipts/views.py b/snipts/views.py index 9b0f557..1745597 100644 --- a/snipts/views.py +++ b/snipts/views.py @@ -1,6 +1,7 @@ from django.shortcuts import get_object_or_404, render_to_response from django.http import Http404, HttpResponseRedirect from django.contrib.auth.models import User +from pygments.lexers import get_all_lexers from django.template import RequestContext from annoying.decorators import render_to from snipts.models import Favorite, Snipt @@ -31,6 +32,7 @@ def list_public(request, tag_slug=None): return { 'has_snipts': True, + 'lexers': sorted(get_all_lexers()), 'public': True, 'snipts': snipts, 'tags': tags, @@ -68,6 +70,7 @@ def list_user(request, username, tag_slug=None): return { 'has_snipts': True, + 'lexers': sorted(get_all_lexers()), 'public': public, 'snipts': snipts, 'tags': tags, @@ -103,6 +106,7 @@ def detail(request, username, snipt_slug): return { 'has_snipts': True, + 'lexers': sorted(get_all_lexers()), 'public': public, 'snipt': snipt, 'tags': tags, diff --git a/templates/base.html b/templates/base.html index c983842..be5790c 100644 --- a/templates/base.html +++ b/templates/base.html @@ -33,7 +33,6 @@ -