Show More
@@ -21,28 +21,14 b' function($,' | |||
|
21 | 21 | |
|
22 | 22 | this.codemirror = CodeMirror($(this.selector)[0]); |
|
23 | 23 | |
|
24 |
this.save_enabled = |
|
|
25 | }; | |
|
26 | ||
|
27 | // TODO: Remove this once the contents API is refactored to just use paths | |
|
28 | Editor.prototype._split_path = function() { | |
|
29 | var ix = this.file_path.lastIndexOf("/"); | |
|
30 | if (ix === -1) { | |
|
31 | return ['', this.file_path]; | |
|
32 | } else { | |
|
33 | return [ | |
|
34 | this.file_path.substring(0, ix), | |
|
35 | this.file_path.substring(ix+1) | |
|
36 | ]; | |
|
37 | } | |
|
24 | this.save_enabled = false; | |
|
38 | 25 | }; |
|
39 | 26 | |
|
40 | 27 | Editor.prototype.load = function() { |
|
41 |
var |
|
|
28 | var that = this; | |
|
42 | 29 | var cm = this.codemirror; |
|
43 | this.contents.load(split_path[0], split_path[1], { | |
|
44 |
|
|
|
45 | if (model.type === "file" && model.format === "text") { | |
|
30 | this.contents.get(this.file_path, {type: 'file', format: 'text'}) | |
|
31 | .then(function(model) { | |
|
46 | 32 |
|
|
47 | 33 |
|
|
48 | 34 |
|
@@ -52,25 +38,29 b' function($,' | |||
|
52 | 38 |
|
|
53 | 39 |
|
|
54 | 40 |
|
|
55 | } else { | |
|
56 | this.codemirror.setValue("Error! Not a text file. Saving disabled."); | |
|
57 | this.save_enabled = false; | |
|
58 | } | |
|
41 | that.save_enabled = true; | |
|
42 | }, | |
|
43 | function(error) { | |
|
44 | cm.setValue("Error! " + error.message + | |
|
45 | "\nSaving disabled."); | |
|
46 | that.save_enabled = false; | |
|
59 | 47 | } |
|
60 |
|
|
|
48 | ); | |
|
61 | 49 | }; |
|
62 | 50 | |
|
63 | 51 | Editor.prototype.save = function() { |
|
64 | var split_path = this._split_path(); | |
|
52 | if (!this.save_enabled) { | |
|
53 | console.log("Not saving, save disabled"); | |
|
54 | return; | |
|
55 | } | |
|
65 | 56 | var model = { |
|
66 |
path: |
|
|
67 | name: split_path[1], | |
|
57 | path: this.file_path, | |
|
68 | 58 | type: 'file', |
|
69 | 59 | format: 'text', |
|
70 | 60 | content: this.codemirror.getValue(), |
|
71 | 61 | }; |
|
72 | 62 | var that = this; |
|
73 |
this.contents.save( |
|
|
63 | this.contents.save(this.file_path, model, { | |
|
74 | 64 | success: function() { |
|
75 | 65 | that.events.trigger("save_succeeded.TextEditor"); |
|
76 | 66 | } |
@@ -5,23 +5,22 b'' | |||
|
5 | 5 | # Distributed under the terms of the Modified BSD License. |
|
6 | 6 | |
|
7 | 7 | from tornado import web |
|
8 |
from ..base.handlers import IPythonHandler, |
|
|
8 | from ..base.handlers import IPythonHandler, path_regex | |
|
9 | 9 | from ..utils import url_escape |
|
10 | 10 | |
|
11 | 11 | class EditorHandler(IPythonHandler): |
|
12 |
"""Render the ter |
|
|
12 | """Render the text editor interface.""" | |
|
13 | 13 | @web.authenticated |
|
14 |
def get(self, path |
|
|
14 | def get(self, path): | |
|
15 | 15 | path = path.strip('/') |
|
16 |
if not self.contents_manager.file_exists( |
|
|
17 |
raise web.HTTPError(404, u'File does not exist: %s |
|
|
16 | if not self.contents_manager.file_exists(path): | |
|
17 | raise web.HTTPError(404, u'File does not exist: %s' % path) | |
|
18 | 18 | |
|
19 | file_path = url_escape(path) + "/" + url_escape(name) | |
|
20 | 19 | self.write(self.render_template('texteditor.html', |
|
21 |
file_path= |
|
|
20 | file_path=url_escape(path), | |
|
22 | 21 | ) |
|
23 | 22 | ) |
|
24 | 23 | |
|
25 | 24 | default_handlers = [ |
|
26 |
(r"/texteditor%s" % |
|
|
25 | (r"/texteditor%s" % path_regex, EditorHandler), | |
|
27 | 26 | ] No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now