Skip to content

Commit

Permalink
Merge pull request #313 from bilogic/custom-xhr-headers
Browse files Browse the repository at this point in the history
allow extra XHR headers to be specified, e.g. authorization bearer tokens etc
  • Loading branch information
ondras authored Apr 11, 2022
2 parents 9dead57 + c3db8d2 commit bbea4e9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@

<script type="text/javascript">
var d = new SQL.Designer();
// d.setXhrHeaders({"Authorization": "Bearer xxx"});
// d.setXhrHeaders({"X-CSRF-TOKEN": "xxx"});
</script>
</body>
</html>
15 changes: 10 additions & 5 deletions js/io.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,9 @@ SQL.IO.prototype.dropboxlist = function() {
SQL.IO.prototype.clientsql = function() {
var bp = this.owner.getOption("staticpath");
var path = bp + "db/"+window.DATATYPES.getAttribute("db")+"/output.xsl";
var h = this.owner.getXhrHeaders();
this.owner.window.showThrobber();
OZ.Request(path, this.finish.bind(this), {xml:true});
OZ.Request(path, this.finish.bind(this), {xml:true, headers:h});
}

SQL.IO.prototype.finish = function(xslDoc) {
Expand Down Expand Up @@ -409,7 +410,8 @@ SQL.IO.prototype.serversave = function(e, keyword) {
var xml = this.owner.toXML();
var bp = this.owner.getOption("xhrpath");
var url = bp + "backend/"+this.dom.backend.value+"/?action=save&keyword="+encodeURIComponent(name);
var h = {"Content-type":"application/xml"};
var h = this.owner.getXhrHeaders();
h["Content-type"] = "application/xml";
this.owner.window.showThrobber();
this.owner.setTitle(name);
OZ.Request(url, this.saveresponse, {xml:true, method:"post", data:xml, headers:h});
Expand All @@ -425,25 +427,28 @@ SQL.IO.prototype.serverload = function(e, keyword) {
this._name = name;
var bp = this.owner.getOption("xhrpath");
var url = bp + "backend/"+this.dom.backend.value+"/?action=load&keyword="+encodeURIComponent(name);
var h = this.owner.getXhrHeaders();
this.owner.window.showThrobber();
this.name = name;
OZ.Request(url, this.loadresponse, {xml:true});
OZ.Request(url, this.loadresponse, {xml:true, headers:h});
}

SQL.IO.prototype.serverlist = function(e) {
var bp = this.owner.getOption("xhrpath");
var url = bp + "backend/"+this.dom.backend.value+"/?action=list";
var h = this.owner.getXhrHeaders();
this.owner.window.showThrobber();
OZ.Request(url, this.listresponse);
OZ.Request(url, this.listresponse, {headers:h});
}

SQL.IO.prototype.serverimport = function(e) {
var name = prompt(_("serverimportprompt"), "");
if (!name) { return; }
var bp = this.owner.getOption("xhrpath");
var url = bp + "backend/"+this.dom.backend.value+"/?action=import&database="+name;
var h = this.owner.getXhrHeaders();
this.owner.window.showThrobber();
OZ.Request(url, this.importresponse, {xml:true});
OZ.Request(url, this.importresponse, {xml:true, headers:h});
}

SQL.IO.prototype.check = function(code) {
Expand Down
9 changes: 9 additions & 0 deletions js/wwwsqldesigner.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
SQL.Designer = function() {
SQL.Designer = this;

this.xhrheaders = {};
this.tables = [];
this.relations = [];
this.title = document.title;
Expand Down Expand Up @@ -210,6 +211,14 @@ SQL.Designer.prototype.setOption = function(name, value) {
this.setCookie(obj);
}

SQL.Designer.prototype.getXhrHeaders = function (value) {
return this.xhrheaders;
};

SQL.Designer.prototype.setXhrHeaders = function (value) {
this.xhrheaders = value;
};

SQL.Designer.prototype.raise = function(table) { /* raise a table */
var old = table.getZ();
var max = this.getMaxZ();
Expand Down

0 comments on commit bbea4e9

Please sign in to comment.