net.put => net.request('PUT'; improved usability for "Save" buttons
This commit is contained in:
parent
e7afb4f19e
commit
eccc98b83b
4 changed files with 28 additions and 31 deletions
|
|
@ -182,7 +182,7 @@ function saveDoc(name, callback) {
|
||||||
else if (parts[0] == "ace")
|
else if (parts[0] == "ace")
|
||||||
path = "lib/" + path;
|
path = "lib/" + path;
|
||||||
|
|
||||||
net.put(path, doc.session.getValue(), callback);
|
net.request('PUT', path, doc.session.getValue(), callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
|
||||||
|
|
@ -9,22 +9,9 @@ define(function(require, exports, module) {
|
||||||
"use strict";
|
"use strict";
|
||||||
var dom = require("./dom");
|
var dom = require("./dom");
|
||||||
|
|
||||||
exports.get = function (url, callback) {
|
exports.request = function (verb, url, data, callback) {
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
xhr.open('GET', url, true);
|
xhr.open(verb, url, true);
|
||||||
xhr.onreadystatechange = function () {
|
|
||||||
//Do not explicitly handle errors, those should be
|
|
||||||
//visible via console output in the browser.
|
|
||||||
if (xhr.readyState === 4) {
|
|
||||||
callback(xhr.responseText);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
xhr.send(null);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.put = function (url, data, callback) {
|
|
||||||
var xhr = new XMLHttpRequest();
|
|
||||||
xhr.open('PUT', url, true);
|
|
||||||
xhr.onreadystatechange = function () {
|
xhr.onreadystatechange = function () {
|
||||||
//Do not explicitly handle errors, those should be
|
//Do not explicitly handle errors, those should be
|
||||||
//visible via console output in the browser.
|
//visible via console output in the browser.
|
||||||
|
|
@ -35,6 +22,10 @@ exports.put = function (url, data, callback) {
|
||||||
xhr.send(data);
|
xhr.send(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.get = function (url, callback) {
|
||||||
|
this.request('GET', url, null, callback);
|
||||||
|
};
|
||||||
|
|
||||||
exports.loadScript = function(path, callback) {
|
exports.loadScript = function(path, callback) {
|
||||||
var head = dom.getDocumentHead();
|
var head = dom.getDocumentHead();
|
||||||
var s = document.createElement('script');
|
var s = document.createElement('script');
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@
|
||||||
<select id="modeEl" size="1"></select>
|
<select id="modeEl" size="1"></select>
|
||||||
<input type="button" value="⟳" title="sync" id="syncToMode"></select>
|
<input type="button" value="⟳" title="sync" id="syncToMode"></select>
|
||||||
<span id="tablist"></span>
|
<span id="tablist"></span>
|
||||||
<input type="button" value="Upload" id="uploadToServer1"></select>
|
<input type="button" value="Save" id="uploadToServer1"></select>
|
||||||
<span class="separator-h"></span>
|
<span class="separator-h"></span>
|
||||||
<label for="autorunEl">live preview</label>
|
<label for="autorunEl">live preview</label>
|
||||||
<input type="checkbox" label="autorun" id="autorunEl" checked>
|
<input type="checkbox" label="autorun" id="autorunEl" checked>
|
||||||
|
|
@ -71,7 +71,7 @@
|
||||||
<label for="themeEl">Theme</label>
|
<label for="themeEl">Theme</label>
|
||||||
<select id="themeEl" size="1" value="textmate"></select>
|
<select id="themeEl" size="1" value="textmate"></select>
|
||||||
<span class="separator-h"></span>
|
<span class="separator-h"></span>
|
||||||
<input type="button" value="Upload" id="uploadToServer2"></select>
|
<input type="button" value="Save" id="uploadToServer2"></select>
|
||||||
<label for="doc">Document</label>
|
<label for="doc">Document</label>
|
||||||
<select id="doc" size="1"></select>
|
<select id="doc" size="1"></select>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -96,24 +96,14 @@ var uploadEl2 = document.getElementById("uploadToServer2");
|
||||||
uploadEl1.onclick = function() {
|
uploadEl1.onclick = function() {
|
||||||
var text = savedLeadingComments + editor1.getValue();
|
var text = savedLeadingComments + editor1.getValue();
|
||||||
var url = "./lib/ace/mode/" + modeEl.value + "_highlight_rules.js";
|
var url = "./lib/ace/mode/" + modeEl.value + "_highlight_rules.js";
|
||||||
net.put(url, text, function(text) {
|
net.request('PUT', url, text, function(text) {
|
||||||
if (text.trim().length > 0)
|
handle_put_result(text, editor1, uploadEl1);
|
||||||
log(text);
|
|
||||||
else {
|
|
||||||
uploadEl1.disabled = true;
|
|
||||||
editor1.getSession().getUndoManager().markClean();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
editor1.commands.bindKey("Ctrl-S", uploadEl1.onclick);
|
editor1.commands.bindKey("Ctrl-S", uploadEl1.onclick);
|
||||||
uploadEl2.onclick = function() {
|
uploadEl2.onclick = function() {
|
||||||
doclist.saveDoc(docEl.value, function(text) {
|
doclist.saveDoc(docEl.value, function(text) {
|
||||||
if (text.trim().length > 0)
|
handle_put_result(text, editor2, uploadEl2);
|
||||||
log(text);
|
|
||||||
else {
|
|
||||||
uploadEl2.disabled = true;
|
|
||||||
editor2.getSession().getUndoManager().markClean();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
editor2.commands.bindKey("Ctrl-S", uploadEl2.onclick);
|
editor2.commands.bindKey("Ctrl-S", uploadEl2.onclick);
|
||||||
|
|
@ -124,6 +114,22 @@ editor2.on('change', function() {
|
||||||
uploadEl2.disabled = false;
|
uploadEl2.disabled = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function handle_put_result(text, editor, buttonEl) {
|
||||||
|
text = text.trim();
|
||||||
|
if (text.length == 0) {
|
||||||
|
buttonEl.disabled = true;
|
||||||
|
editor.getSession().getUndoManager().markClean();
|
||||||
|
} else {
|
||||||
|
if (text.indexOf("405") == 0) {
|
||||||
|
log("Write access to this file is disabled.\n"+
|
||||||
|
"To enable saving your changes to disk, clone the Ace repository"+
|
||||||
|
"\nand run the included static.py web server with the option\n"+
|
||||||
|
"--puttable='lib/ace/mode/*_highlight_rules.js,demo/kitchen-sink/docs/*'");
|
||||||
|
} else
|
||||||
|
log(text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
document.getElementById("perfTest").onclick = function() {
|
document.getElementById("perfTest").onclick = function() {
|
||||||
var lines = editor2.session.doc.getAllLines();
|
var lines = editor2.session.doc.getAllLines();
|
||||||
if (!lines.length)
|
if (!lines.length)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue