diff options
Diffstat (limited to 'share/www/script/futon.browse.js')
-rw-r--r-- | share/www/script/futon.browse.js | 48 |
1 files changed, 45 insertions, 3 deletions
diff --git a/share/www/script/futon.browse.js b/share/www/script/futon.browse.js index 5a8b3fa7..39f38365 100644 --- a/share/www/script/futon.browse.js +++ b/share/www/script/futon.browse.js @@ -688,6 +688,9 @@ page = this; this.activateTabularView = function() { + if ($("#fields tbody.source textarea").length > 0) + return; + $("#tabs li").removeClass("active").filter(".tabular").addClass("active"); $("#fields thead th:first").text("Field").attr("colspan", 1).next().show(); $("#fields tbody.content").show(); @@ -699,7 +702,41 @@ $("#fields thead th:first").text("Source").attr("colspan", 2).next().hide(); $("#fields tbody.content").hide(); $("#fields tbody.source").find("td").each(function() { - $(this).html($("<pre></pre>").html($.futon.formatJSON(page.doc, {html: true}))); + $(this).html($("<pre></pre>").html($.futon.formatJSON(page.doc, {html: true}))) + .makeEditable({allowEmpty: false, + createInput: function(value) { + return $("<textarea rows='8' cols='80' spellcheck='false'></textarea>"); + }, + prepareInput: function(input) { + $(input).makeResizable({vertical: true}); + }, + end: function() { + $(this).html($("<pre></pre>").html($.futon.formatJSON(page.doc, {html: true}))); + }, + accept: function(newValue) { + page.doc = JSON.parse(newValue); + page.isDirty = true; + page.updateFieldListing(true); + }, + populate: function(value) { + return $.futon.formatJSON(page.doc); + }, + validate: function(value) { + try { + var doc = JSON.parse(value); + if (typeof doc != "object") + throw new SyntaxError("Please enter a valid JSON document (for example, {})."); + return true; + } catch (err) { + var msg = err.message; + if (msg == "parseJSON" || msg == "JSON.parse") { + msg = "There is a syntax error in the document."; + } + $("<div class='error'></div>").text(msg).appendTo(this); + return false; + } + } + }); }).end().show(); } @@ -732,7 +769,7 @@ } } - this.updateFieldListing = function() { + this.updateFieldListing = function(noReload) { $("#fields tbody.content").empty(); function handleResult(doc, revs) { @@ -767,11 +804,16 @@ $("#fields tbody.footer td span").text("Showing revision " + (revs.length - currentIndex) + " of " + revs.length); } - if (location.hash == "#source") { + if (location.hash == "#source" && !noReload) { page.activateSourceView(); } } + if (noReload) { + handleResult(page.doc, []); + return; + } + if (!page.isNew) { db.openDoc(docId, {revs_info: true, success: function(doc) { |