Permalink
Browse files

Improve Profile page by showing which clouds are enabled.

  • Loading branch information...
1 parent c02d701 commit ebdbd83a948dbd8aa3dec7a3d867e8b0e2fa5b68 @oldpatricka oldpatricka committed Jan 29, 2013
Showing with 100 additions and 30 deletions.
  1. +77 −25 phantomweb/static/js/phantom_profile.js
  2. +23 −5 phantomweb/templates/profile.html
@@ -1,4 +1,5 @@
var g_cloud_map = {};
+var g_selected_cloud = null;
var ENTER_KEYCODE = 13;
@@ -25,6 +26,13 @@ $(document).ready(function() {
return false;
});
+ $("#cloud_table_body").on('click', 'tr', function(event){
+ $(this).parent().children().removeClass("info");
+ var cloud_name = $(this).children().first().text();
+ phantom_cloud_edit_change_cloud(cloud_name);
+ });
+
+
$("#change_password_button").click(function() {
change_password_click();
return false;
@@ -58,7 +66,6 @@ function phantom_cloud_edit_enable(enable) {
$("#phantom_cloud_edit_remove").removeAttr("disabled", "disabled");
$('#phantom_cloud_edit_name').removeAttr("disabled", "disabled");
- console.log("len: " + $("#phantom_cloud_edit_keyname_list").children());
if ($("#phantom_cloud_edit_keyname_list").children().length === 0) {
$("#phantom_cloud_edit_keyname_list").parent().parent().hide();
}
@@ -73,9 +80,6 @@ function phantom_cloud_edit_enable(enable) {
$("#phantom_cloud_edit_remove").attr("disabled", "disabled");
$("#phantom_cloud_edit_name").attr("disabled", "disabled");
$('#loading').show();
- $("#phantom_cloud_edit_access").val("");
- $("#phantom_cloud_edit_secret").val("");
- $("#phantom_cloud_edit_keyname_list").empty();
}
}
@@ -128,7 +132,8 @@ function phantom_cloud_edit_add_click() {
$("#cloud-credentials .help-inline").remove();
$("#cloud-credentials div").removeClass("error");
- var nameCtl = $("#phantom_cloud_edit_name").val().trim();
+ var nameCtl = $("#cloud_table_body tr.info td").first().text();
+ //var nameCtl = $("#phantom_cloud_edit_name").val().trim();
var accessCtl = $("#phantom_cloud_edit_access").val().trim();
var secretCtl = $("#phantom_cloud_edit_secret").val().trim();
var keyCtl = $("#phantom_cloud_edit_keyname_list").val();
@@ -160,16 +165,11 @@ function phantom_cloud_edit_add_click() {
//send call to service
var success_func = function (obj) {
- $("#phantom_cloud_edit_name").empty();
- $("#phantom_cloud_edit_access").val("");
- $("#phantom_cloud_edit_secret").val("");
- $("#phantom_cloud_edit_keyname_list").empty();
-
phantom_cloud_edit_load_sites();
}
var error_func = function(obj, message) {
- alert(message);
+ phantom_alert(message);
phantom_cloud_edit_enable(true);
}
@@ -179,17 +179,35 @@ function phantom_cloud_edit_add_click() {
}
-function phantom_cloud_edit_change_cloud_internal () {
- var selected_cloud_name = $("#phantom_cloud_edit_name").val();
+function phantom_cloud_edit_change_cloud_internal(selected_cloud_name) {
+
+ if (!selected_cloud_name) {
+ if (g_selected_cloud) {
+ selected_cloud_name = g_selected_cloud;
+ }
+ else {
+ selected_cloud_name = $("#cloud_table_body tr td").first().text();
+ }
+ }
+
+ g_selected_cloud = selected_cloud_name;
+
+ $(".control-group").removeClass("error");
+
+ $("#cloud_table_body tr td:contains('" + selected_cloud_name + "')")
+ .parent().addClass("info");
+
var val = g_cloud_map[selected_cloud_name];
$("#phantom_cloud_edit_key_message").text("");
$("#phantom_cloud_edit_keyname_list").empty();
if (val == undefined) {
$("#phantom_cloud_edit_access").val("");
$("#phantom_cloud_edit_secret").val("");
+ $("#phantom_cloud_edit_keyname_list").parent().parent().hide();
}
else {
+ $("#phantom_cloud_edit_keyname_list").parent().parent().show();
$("#phantom_cloud_edit_access").val(val['access_key']);
$("#phantom_cloud_edit_secret").val(val['secret_key']);
if (val.status_msg) {
@@ -210,6 +228,7 @@ function phantom_cloud_edit_change_cloud_internal () {
else {
$("#phantom_cloud_edit_keyname_list").val(val.keyname);
}
+
}
}
@@ -219,31 +238,64 @@ function show_cloud_edit_guides() {
}
-function phantom_cloud_edit_change_cloud () {
+function phantom_cloud_edit_change_cloud (cloud_name) {
try {
- phantom_cloud_edit_change_cloud_internal();
+ phantom_cloud_edit_change_cloud_internal(cloud_name);
}
catch(err) {
alert(err);
}
}
+function make_cloud_table_row(site, status) {
+
+ if (status === "Enabled") {
+ status = '<span class="label label-success">' + status + '</span>';
+ }
+ else if (status === "Incomplete") {
+ status = '<span class="label label-warning">' + status + '</span>';
+ }
+ else if (status === "Disabled") {
+ status = '<span class="label">' + status + '</span>';
+ }
+ else {
+ status = '<span class="label">' + status + '</span>';
+ }
+
+ var row = "<tr id='cloud-row-" + site + "'>" +
+ "<td class='cloud-data-site'>" + site + "</td>" +
+ "<td>" + status + "</td>" +
+ "</tr>";
+ return row;
+}
+
function phantom_cloud_edit_load_sites() {
var url = make_url('api/sites/load');
var success_func = function(obj){
$("#cloud-credentials .help-inline").remove();
+ $("#cloud_table_body").empty();
var selected_cloud_name = $("#phantom_cloud_edit_name").val();
- for(var site in obj.sites) {
- g_cloud_map = obj.sites;
- var new_opt = $('<li>', {'name': site});
- new_opt.text(site);
- }
- for(var site in obj.all_sites) {
- site = obj.all_sites[site];
- var new_choice = $('<option>', {'name': site, value: site, text: site});
- $("#phantom_cloud_edit_name").append(new_choice);
+
+ g_cloud_map = obj.sites;
+
+ for(var site_name in obj.all_sites) {
+ site = obj.all_sites[site_name];
+
+ var status = null;
+ if (site in obj.sites) {
+ if (!obj.sites[site]["keyname"]) {
+ status = "Incomplete";
+ }
+ else {
+ status = "Enabled";
+ }
+ }
+ else {
+ status = "Disabled";
+ }
+ $("#cloud_table_body").append(make_cloud_table_row(site, status));
}
phantom_cloud_edit_change_cloud_internal();
phantom_cloud_edit_enable(true);
@@ -269,7 +321,7 @@ function phantom_cloud_edit_load_page() {
}
function phantom_cloud_edit_remove_click() {
- var cloud_name = $("#phantom_cloud_edit_name").val();
+ var cloud_name = $("#cloud_table_body tr.info td").first().text();
var q = "Are you sure you want to remove the cloud ".concat(cloud_name).concat(" from your configuration?");
var doit = confirm(q);
@@ -42,15 +42,31 @@
<div class="tab-content span10">
<div class="tab-pane" id="cloud-credentials">
<div class="well well-small">
+ <h5 class="magic-underline">Cloud Credentials</h5>
+ <div class="row-fluid">
+ <div class="span2">
+ <table class="table table-condensed table-bordered table-hover table-white" id="clouds_table">
+ <thead>
+ <tr>
+ <th>Cloud</th>
+ <th>Status</th>
+ </tr>
+ </thead>
+ <tbody id="cloud_table_body">
+ </tbody>
+ </table>
+ </div>
+ <div class="span10 well well-small">
+
<form action="." method="post" class="form-horizontal">{% csrf_token %}
<fieldset>
- <h5 class="magic-underline">Cloud Credentials</h5>
- <div class="control-group" >
+ <!--<div class="control-group" >
<label for="phantom_cloud_edit_name" class="control-label">Cloud:</label>
<div class="controls">
<select id="phantom_cloud_edit_name" class="xphantom_cloud_edit_input"></select>
</div>
- </div>
+ </div>-->
+
<div class="control-group" >
<label class="control-label" for="phantom_cloud_edit_access">Access Key:</label>
<div class="controls">
@@ -71,8 +87,8 @@ <h5 class="magic-underline">Cloud Credentials</h5>
</div>
<div class="control-group" >
<div class="controls">
- <input id="phantom_cloud_edit_add" type="button" class="btn btn-primary" value="Save"/>
- <input id="phantom_cloud_edit_remove" type="button" class="btn btn-danger" value="Remove"/>
+ <input id="phantom_cloud_edit_add" type="button" class="btn btn-primary" value="Save Credentials"/>
+ <input id="phantom_cloud_edit_remove" type="button" class="btn btn-danger" value="Disable"/>
</div>
</div>
<div class="phantom_cloud_edit_configured_list">
@@ -87,6 +103,8 @@ <h5 class="magic-underline">Cloud Credentials</h5>
</fieldset>
</form>
</div>
+ </div>
+ </div>
</div><!--/span-->
<div class="tab-pane" id="account-settings">
<div class="well well-small">

0 comments on commit ebdbd83

Please sign in to comment.