Permalink
Browse files

design fixes for delete projection and other tiny bugs, refactored js…

… code, cleaned up a bit
  • Loading branch information...
MarkiyanMatsekh committed Nov 13, 2012
1 parent 91693c6 commit 5bebca8747856cdb7e665e4aa75e8f81417aeb2f
@@ -20,29 +20,28 @@ <h1>Delete Projection</h1>
</div>
</div>
<div class="control-group">
- <label class="control-label" for="raw_state">
+ <label class="control-label" for="projection-state">
<strong>State</strong></label>
<div class="controls">
- <div id="raw_state">
+ <div id="projection-state">
</div>
</div>
</div>
<div class="control-group">
<label class="control-label" for="source">
<strong>Source</strong></label>
<div class="controls">
- <pre id="source" style="font-family: consolas, 'courier new'; width: 400px; height: 200px;"
- class="span5"></pre>
+ <textarea disabled="disabled" id="source" ></textarea>
</div>
</div>
<div class="control-group">
<div class="controls" id="delete-container">
- <div>
+ <label class="checkbox">
<input type="checkbox" id="delete-checkpoint-stream-checkbox" disabled="disabled">Delete Checkpoint Stream
- </div>
- <div>
+ </label>
+ <label class="checkbox">
<input type="checkbox" id="delete-state-stream-checkbox" disabled="disabled">Delete State Stream
- </div>
+ </label>
<div>
<button id="delete-button" class="btn btn-success">
Confirm Delete</button>
@@ -58,59 +57,43 @@ <h1>Delete Projection</h1>
<script type="text/javascript">
- (function () {
+ (function() {
var projectionStatusUrl = "";
- function success(data, status, xhr) {
- var projection = data.projections[0];
- }
-
- function successDeleteProjection(data, status, xhr) {
- window.location = "view-projection.htm#" + projectionStatusUrl;
- }
-
- function error(xhr, status) {
- delayedRequestProjection();
- }
-
- function successState(data, status, xhr) {
- $("#raw_state").text(JSON.stringify(data));
- }
+ $(function() {
+ $.templates("editSourceTemplate", "#editSourceTemplate");
+ projectionStatusUrl = location.hash.substr(1);
- function errorState(xhr, status) {
- delayedRequestProjectionState();
- }
+ $('#delete-button').click(function() {
- function successSource(data, status, xhr) {
- $("#source").text(data);
- }
-
- function errorSource(xhr, status) {
- delayedRequestProjectionSource();
- }
+ var params = $.param({
+ deleteCheckpointStream: $("#delete-checkpoint-stream-checkbox").attr("checked") ? "yes" : "no",
+ deleteStateStream: $("#delete-state-stream-checkbox").attr("checked") ? "yes" : "no",
+ });
+ var url = projectionStatusUrl + "?" + params;
- function delayedRequestProjection() {
- setTimeout(requestProjection, 1000);
- }
+ $.ajax(url, {
+ headers: {
+ Accept: "application/json",
+ },
+ type: "DELETE",
+ success: successDeleteProjection,
+ error: function(xhr) {
+ var msg = es.util.formatError("Couldn't delete projection", xhr);
+ alert(msg);
+ }
+ });
+ });
- function delayedRequestProjectionState() {
- setTimeout(requestProjectionState, 1000);
- }
+ requestProjectionState();
+ requestProjectionSource();
- function delayedRequestProjectionSource() {
- setTimeout(requestProjectionSource, 1000);
- }
+ function successDeleteProjection(data, status, xhr) {
+ window.document.location = "projections.htm";
+ }
+ });
- function requestProjection() {
- $.ajax(projectionStatusUrl + "/statistics", {
- headers: {
- Accept: "application/json",
- },
- success: success,
- error: error
- });
- }
function requestProjectionState() {
$.ajax(projectionStatusUrl + "/state", {
@@ -120,6 +103,14 @@ <h1>Delete Projection</h1>
success: successState,
error: errorState
});
+
+ function successState(data, status, xhr) {
+ $("#projection-state").text(JSON.stringify(data));
+ }
+
+ function errorState(xhr, status) {
+ setTimeout(requestProjectionState, 1000);
+ }
}
function requestProjectionSource() {
@@ -131,32 +122,16 @@ <h1>Delete Projection</h1>
success: successSource,
error: errorSource
});
- }
- $(function () {
- $.templates("editSourceTemplate", "#editSourceTemplate");
- projectionStatusUrl = location.hash.substr(1);
+ function successSource(data, status, xhr) {
+ $("#source").text(data);
+ }
- $('#delete-button').click(function () {
- $.ajax(projectionStatusUrl + "?" + $.param({
- deleteCheckpointStream: $("#delete-checkpoint-stream-checkbox").attr("checked") ? "yes" : "no",
- deleteStateStream: $("#delete-state-stream-checkbox").attr("checked") ? "yes" : "no",
- }), {
- headers: {
- Accept: "application/json",
- },
-
-
- type: "DELETE",
- success: successDeleteProjection,
- error: function () { alert("Failed!"); }
- });
- });
+ function errorSource(xhr, status) {
+ setTimeout(requestProjectionSource, 1000);
+ }
+ }
- requestProjection();
- requestProjectionState();
- requestProjectionSource();
- });
})();
</script>
@@ -14,26 +14,19 @@
<h1>
Edit Projection Source</h1>
<div class="form-horizontal">
- <div class="row">
- <div class="span12">
- <div id="projection-status">
- </div>
- </div>
- </div>
<div class="control-group">
- <label class="control-label" for="raw_state">
+ <label class="control-label" for="projection-state">
<strong>State</strong></label>
<div class="controls">
- <div id="raw_state">
+ <div id="projection-state">
</div>
</div>
</div>
<div class="control-group">
<label class="control-label" for="source">
<strong>Source</strong></label>
<div class="controls">
- <textarea rows="20" cols="100" id="source" style="font-family: consolas, 'courier new';"
- class="span5"></textarea>
+ <textarea id="source" ></textarea>
</div>
</div>
<div class="control-group">
@@ -42,16 +35,6 @@ <h1>
Update</button>
</div>
</div>
- <div class="control-group">
- <label class="control-label" for="raw_data">
- <strong>Log:</strong></label>
- <div class="controls">
- <div id="raw_data" style="display: none; font-family: consolas, 'courier new';">
- </div>
- <div id="debug" style="display: none;">
- </div>
- </div>
- </div>
</div>
<script id="r-body">
@@ -65,55 +48,29 @@ <h1>
var projectionStatusUrl = "";
- function success(data, status, xhr) {
- var projection = data.projections[0];
- }
-
- function successUpdateSource(data, status, xhr) {
- window.location = "view-projection.htm#" + projectionStatusUrl;
- }
-
- function error(xhr, status) {
- delayedRequestProjection();
- }
-
- function successState(data, status, xhr) {
- $("#raw_state").text(JSON.stringify(data));
- }
-
- function errorState(xhr, status) {
- delayedRequestProjectionState();
- }
-
- function successSource(data, status, xhr) {
- $("#source").text(data);
- }
-
- function errorSource(xhr, status) {
- delayedRequestProjectionSource();
- }
-
- function delayedRequestProjection() {
- setTimeout(requestProjection, 1000);
- }
-
- function delayedRequestProjectionState() {
- setTimeout(requestProjectionState, 1000);
- }
+ $(function() {
+ $.templates("editSourceTemplate", "#editSourceTemplate");
+ projectionStatusUrl = location.hash.substr(1);
- function delayedRequestProjectionSource() {
- setTimeout(requestProjectionSource, 1000);
- }
+ $('#update-button').click(function(ev) {
+ $.ajax(projectionStatusUrl + "/query", {
+ headers: {
+ Accept: "application/json",
+ },
- function requestProjection() {
- $.ajax(projectionStatusUrl + "/statistics", {
- headers: {
- Accept: "application/json",
- },
- success: success,
- error: error
+ type: "PUT",
+ data: $("#source").val(),
+ success: successUpdateSource,
+ error: function(xhr) {
+ var msg = es.util.formatError("Couldn't delete projection", xhr);
+ alert(msg);
+ }
+ });
});
- }
+
+ requestProjectionState();
+ requestProjectionSource();
+ });
function requestProjectionState() {
$.ajax(projectionStatusUrl + "/state", {
@@ -123,6 +80,15 @@ <h1>
success: successState,
error: errorState
});
+
+ function successState(data, status, xhr) {
+ var state = JSON.stringify(data);
+ $("#projection-state").text(state);
+ }
+
+ function errorState(xhr, status) {
+ setTimeout(requestProjectionState, 1000);
+ }
}
function requestProjectionSource() {
@@ -134,29 +100,20 @@ <h1>
success: successSource,
error: errorSource
});
- }
- $(function() {
- $.templates("editSourceTemplate", "#editSourceTemplate");
- projectionStatusUrl = location.hash.substr(1);
+ function successSource(data, status, xhr) {
+ $("#source").text(data);
+ }
- $('#update-button').click(function() {
- $.ajax(projectionStatusUrl + "/query", {
- headers: {
- Accept: "application/json",
- },
-
- type: "PUT",
- data: $("#source").val(),
- success: successUpdateSource,
- error: function() { alert("Failed!"); }
- });
- });
+ function errorSource(xhr, status) {
+ setTimeout(requestProjectionSource, 1000);
+ }
+ }
- requestProjection();
- requestProjectionState();
- requestProjectionSource();
- });
+ function successUpdateSource(data, status, xhr) {
+ window.location = "view-projection.htm#" + projectionStatusUrl;
+ }
+
})();
</script>
@@ -28,12 +28,7 @@ $(function () {
function error(xhr, status, err) {
if (unloading)
return;
- var msg;
-
- if (xhr.status === 0)
- msg = "cannot connect to server";
- else
- msg = "error: " + err;
+ var msg = es.util.formatError("Couldn't build charts.", xhr);
$(".error").text(msg).show();
};
@@ -130,6 +125,13 @@ $(function () {
$(".error").hide();
publishNewStat(data);
}
+
+ function error(xhr, status, err) {
+ if (unloading)
+ return;
+ var msg = es.util.formatError("Couldn't update charts.", xhr);
+ $(".error").text(msg).show();
+ }
function publishNewStat(stat) {
$(document).trigger(newDataEvent, [stat]);
@@ -1,4 +1,4 @@
-es.utils.loadMenu([
+es.util.loadMenu([
{ "name": "Home", "link": "home.htm", "class": "" },
{ "name": "Projections", "link": "projections.htm", "class": "" },
{ "name": "New Projection", "link": "new-projection.htm", "class": "" },
Oops, something went wrong.

0 comments on commit 5bebca8

Please sign in to comment.