App.Views.ServerDoc = Backbone.View.extend({ events: { "submit form#string_s" : "upload_string", "submit form#db_key_form" : "query", "click a#clear" : "clear" }, initialize: function(dbkey) { this.render(""); }, clear: function(e){ e.preventDefault(); dbkey = this.model.get('dbkey'); token = this.model.get('api_token') var self = this; $.ajax({ type: 'POST', url: '/rc/v1/store/' + dbkey, data: {data : ''}, beforeSend: function (HttpRequest) { HttpRequest.setRequestHeader("X-RhoConnect-API-TOKEN", token); }, success: function(){ data = "

Data

" + "clear document
" + ""; $('#docdata-table').find("tr:gt(0)").remove(); $('#docdata-table tr:last').after(data); self.delegateEvents(); }, error: function(resp){ if(resp.status == 422){ new App.Views.Index() } $('#doc-alert')[0].innerHTML = resp.responseText; $('#doc-alert').css('display','block'); } }) }, upload_string: function(e){ e.preventDefault(); var self = this; $(".upload-status")[0].firstChild.className = "label label-warning"; $(".upload-status")[0].firstChild.innerHTML = "loading..."; $(".upload-status").css("visibility","visible"); var doc = $('#input_key').val(); var data = $("#data").val(); token = this.model.get('api_token'); $.ajax({ type: 'POST', url: '/rc/v1/store/' + doc, data: {data : data}, beforeSend: function (HttpRequest) { HttpRequest.setRequestHeader("X-RhoConnect-API-TOKEN", token); }, success: function(){ $(".upload-status")[0].firstChild.className = "label label-success"; $(".upload-status")[0].firstChild.innerHTML = "success"; data = "

Data

" + "clear document
" + "" + data+ ""; $('#docdata-table').find("tr:gt(0)").remove(); $('#docdata-table tr:last').after(data); self.delegateEvents(); }, error: function(resp){ if(resp.status == 422){ new App.Views.Index() } $(".upload-status")[0].firstChild.className = "label label-danger"; $(".upload-status")[0].firstChild.innerHTML = "error"; $('#doc-alert')[0].innerHTML = resp.responseText; $('#doc-alert').css('display','block'); } }) }, query: function(e){ e.preventDefault(); var dbkey = $('#input_key').val(); this.render(dbkey); $(".query-status")[0].firstChild.className = "label label-warning"; $(".query-status")[0].firstChild.innerHTML = "loading..."; $(".query-status").css("visibility","visible"); this.model.get_doc(dbkey,'string'); this.delegateEvents(); }, render: function(dbkey) { $('#secondary-nav').css('display','block'); out = ""; out += ""; out += "
"; out += ""; out += ""; out += "
"; if(dbkey != ""){ out += "
"; out += ""; out += ""; out += "
"; out += "
"; } $(this.el).html(out); $('#main_content').html(this.el); } });