
var EscEditor = function() {
    return {

        validateName : function(name) {
            return true;
        },
        
        editPropertiesFor : function(env, app) {
            $('#editor').empty();
            $('#editor').append("Editing /environments/" + env + "/" + app + "<br/><br/>");    

            $.ajax({
                type: "GET",
                url: "/environments/" + env + "/" + app,
                success: function(data, textStatus) {
                    $('#editor').html("<center><h3><b><font size='+1'>" + app + "</font></b> in <b><font size='+1'>" + env + "</font></b></center><br />");
                    var table = '<table class="keyvalue" id="key_value_table"><tr class="keyvalueheader"><th>Key</th><th>Value</th><th>&nbsp;</th></tr>';
					rowcolour = 1
                    $.each(data.split('\n'), function(i, item) {
						if (rowcolour == 1) { //Alternating row colours
							rowcolour = 0
						}else {
							rowcolour = 1
						}
						
                        table += ('<tr class="tr-' + rowcolour + '">');
                        table += "<th>" + item.slice(0, item.indexOf("=")) + "</th>";
                        table += "<td class='keyeditbox'>" + item.slice(item.indexOf("=") + 1) + "</td>";
						table += "<td class='keydeletebox' id='deletekey-" + item.slice(0, item.indexOf("=")) + "'><img src='/images/delete.png'/></td>"
                    });
                    table += "</table>";
                    $('#editor').append(table);
                    $('#key_env_name').val(env);
                    $('#key_app_name').val(app);
                    $.uiTableEdit($('#key_value_table'), {
                        editDone: function(newText, oldText, e, td) {
                            var key;
                            var value;
                            $.each(td.siblings().andSelf(), function(i, item) {
                                if (i % 2) {
                                    value = $(item).text();
                                } else {
                                    key = $(item).text();
                                }
                            });
                            $.ajax({
                                type: "PUT",
                                url: "/environments/" + env + "/" + app + "/" + key,
                                data: value,
                                complete: function(XMLHttpRequest, textStatus) {
                                    $('#app_list').change();  
                                },
                            });
                        },
                    });
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    alert("Error getting properties for app '" + app + "' in environment '" + env + "'");
                },
            });
        },

// End of namespace
    };
}();

$(document).ready(function() {
    $('#new_key_form').submit(function() {
        var newName = $('#new_key_name').val();
        var envName = $('#key_env_name').val();
        var appName = $('#key_app_name').val();
        if (EscEditor.validateName(newName)) {
            $('#new_key_name').val("");
            $.ajax({
                type: "PUT",
                url: "/environments/" + envName + "/" + appName + "/" + newName,
                data: "",
                complete: function(XMLHttpRequest, textStatus) {
                    EscEditor.editPropertiesFor(envName, appName);
                },
            });
        } else {
            alert("Not going to create new key called " + newName);
        }
    });
});



@@ -1651,16 +1651,61 @@
 le'), %7B%0A
+                        find: %22.keyeditbox%22,%0A
         
@@ -1805,396 +1805,85 @@
  key
-;%0A                            var value;%0A                            $.each(td.siblings().andSelf(), function(i, item) %7B%0A                                if (i %25 2) %7B%0A                                    value = $(item).text();%0A                                %7D else %7B%0A                                    key = $(item).text();%0A                                %7D%0A                            %7D
+ = td.siblings('th').text();%0A                            var value = td.text(
 );%0A 

Fix the edit table so it works again. Was broken by the addition of the delete key button.