Commit fd65c451 authored by Nicolas Wavrant's avatar Nicolas Wavrant

slaprunner: ace editor asks for unsaved changes before leaving page

parent 97a0b5be
...@@ -23,6 +23,7 @@ $(document).ready(function () { ...@@ -23,6 +23,7 @@ $(document).ready(function () {
edit_status = "", edit_status = "",
current_file = null, current_file = null,
favourite_list = new Array(), favourite_list = new Array(),
beforeunload_warning_set = false,
base_path = function () { base_path = function () {
return softwareDisplay ? currentProject : 'runner_workdir/'; return softwareDisplay ? currentProject : 'runner_workdir/';
}; };
...@@ -585,8 +586,11 @@ $(document).ready(function () { ...@@ -585,8 +586,11 @@ $(document).ready(function () {
editor = ace.edit("editor"); editor = ace.edit("editor");
modelist = require("ace/ext/modelist"); modelist = require("ace/ext/modelist");
ace.require("ace/ext/language_tools");
config = require("ace/config"); config = require("ace/config");
editor.setOptions({ enableBasicAutocompletion: true, enableSnippets: true });
editor.setTheme("ace/theme/crimson_editor"); editor.setTheme("ace/theme/crimson_editor");
editor.getSession().setMode("ace/mode/text"); editor.getSession().setMode("ace/mode/text");
editor.getSession().setTabSize(2); editor.getSession().setTabSize(2);
...@@ -603,6 +607,18 @@ $(document).ready(function () { ...@@ -603,6 +607,18 @@ $(document).ready(function () {
$("#option").Tooltip(); $("#option").Tooltip();
$("#filelist").Tooltip(); $("#filelist").Tooltip();
editor.getSession().on('change', function(){
$("#editor").val(editor.getSession().getValue());
if (!beforeunload_warning_set) {
window.onbeforeunload = function() { return "You have unsaved changes"; };
beforeunload_warning_set = true;
}
});
$('input[value="Save Changes"]').click(function() {
window.onbeforeunload = function() { return; };
});
editor.on("change", function (e) { editor.on("change", function (e) {
if (edit_status === "" && edit) { if (edit_status === "" && edit) {
$("span#edit_status").html("*"); $("span#edit_status").html("*");
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
{% if request.path != '/login' %} {% if request.path != '/login' %}
<script src="{{ url_for('static', filename='js/ace/ace.js') }}" type="text/javascript" charset="utf-8"></script> <script src="{{ url_for('static', filename='js/ace/ace.js') }}" type="text/javascript" charset="utf-8"></script>
<script src="{{ url_for('static', filename='js/ace/ext-modelist.js') }}" type="text/javascript" charset="utf-8"></script> <script src="{{ url_for('static', filename='js/ace/ext-modelist.js') }}" type="text/javascript" charset="utf-8"></script>
<script src="{{ url_for('static', filename='js/ace/ext-language_tools.js') }}" type="text/javascript" charset="utf-8"></script>
<script src="{{ url_for('static', filename='js/scripts/process.js') }}" type="text/javascript" charset="utf-8"></script> <script src="{{ url_for('static', filename='js/scripts/process.js') }}" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function() { $(document).ready(function() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment