From f6fa897a4eac1a98f6979965a1eab4a12a37c653 Mon Sep 17 00:00:00 2001 From: johnyma22 Date: Fri, 2 Nov 2012 14:31:52 +0000 Subject: [PATCH] actually using text area is a lot less stupid --- src/static/css/admin.css | 11 ++--- src/static/js/admin/settings.js | 76 +++++++++++++++++-------------- src/templates/admin/settings.html | 6 ++- 3 files changed, 52 insertions(+), 41 deletions(-) diff --git a/src/static/css/admin.css b/src/static/css/admin.css index 45dae7277..1c9e490ad 100644 --- a/src/static/css/admin.css +++ b/src/static/css/admin.css @@ -120,10 +120,9 @@ td, th { padding: 2px; overflow: auto; } -.settings pre{ - white-space: pre-wrap; - white-space: -moz-pre-wrap; - white-space: -pre-wrap; - white-space: -o-pre-wrap; - word-wrap: break-word; +.settings { + margin-top:10px; + width:100%; + min-height:600px; } + diff --git a/src/static/js/admin/settings.js b/src/static/js/admin/settings.js index 136b3a08f..af5ec46f9 100644 --- a/src/static/js/admin/settings.js +++ b/src/static/js/admin/settings.js @@ -123,44 +123,52 @@ $(document).ready(function () { }); */ - socket.on('settings', function (data) { - $('.settings').append(data.results); - $('.settings').sloppyForm(); // Turn JSON into Form + socket.on('settings', function (settings) { -/* $("#installed-plugins *").remove(); - for (plugin_name in data.results) { - if (plugin_name == "ep_etherpad-lite") continue; // Hack... - var plugin = data.results[plugin_name]; - var row = $("#installed-plugin-template").clone(); + /* Check to make sure the JSON is clean before proceeding */ - for (attr in plugin.package) { - row.find("." + attr).html(plugin.package[attr]); - } - $("#installed-plugins").append(row); + if(isJSONClean(settings.results)) + { + $('.settings').append(settings.results); } - updateHandlers(); -*/ + else{ + alert("YOUR JSON IS BAD AND YOU SHOULD FEEL BAD") + } + + $('#saveSettings').on('click', function(){ + var editedSettings = $('.settings').val(); + if(isJSONClean(editedSettings)){ + // JSON is clean so emit it to the server + }else{ + alert("YOUR JSON IS BAD AND YOU SHOULD FEEL BAD") + } + }); + + $('#restartEtherpad').on('click', function(){ + + }); + + }); socket.emit("load"); search(); }); - -/* A jQuery plugin to turn JSON strings into forms */ -(function($){ - $.fn.sloppyForm = function() { - return this.each(function() { - // Firstly get a clean object with comments stripped out - var settings = ($.parseJSON(JSON.minify($(this).text()))); - - // For each create form bla bla - - }); - }; -})(jQuery); - - +function isJSONClean(data){ + var cleanSettings = JSON.minify(data); + try{ + var response = jQuery.parseJSON(cleanSettings); + } + catch(e){ + return false; // the JSON failed to be parsed + } + if(typeof response !== 'object'){ + return false; + }else{ + return true; + } +} /* Strip crap out of JSON */ @@ -174,18 +182,18 @@ $(document).ready(function () { if (typeof global.JSON == "undefined" || !global.JSON) { global.JSON = {}; } - + global.JSON.minify = function(json) { - + var tokenizer = /"|(\/\*)|(\*\/)|(\/\/)|\n|\r/g, in_string = false, in_multiline_comment = false, in_singleline_comment = false, tmp, tmp2, new_str = [], ns = 0, from = 0, lc, rc ; - + tokenizer.lastIndex = 0; - + while (tmp = tokenizer.exec(json)) { lc = RegExp.leftContext; rc = RegExp.rightContext; @@ -197,7 +205,7 @@ $(document).ready(function () { new_str[ns++] = tmp2; } from = tokenizer.lastIndex; - + if (tmp[0] == "\"" && !in_multiline_comment && !in_singleline_comment) { tmp2 = lc.match(/(\\)*$/); if (!in_string || !tmp2 || (tmp2[0].length % 2) == 0) { // start of string with ", or unescaped " character found to end string diff --git a/src/templates/admin/settings.html b/src/templates/admin/settings.html index b3d6b32a8..7a7cc6d60 100644 --- a/src/templates/admin/settings.html +++ b/src/templates/admin/settings.html @@ -20,7 +20,11 @@

Etherpad Lite Settings

-
+ Example production settings template + Example development settings template + + +