Factor out client side settings functions into their own JS file,

and add additional variations for getting ints, floats and bools.
This commit is contained in:
Dave Page 2015-02-11 15:50:36 +00:00
parent adeb2f9e84
commit afb029e284
4 changed files with 54 additions and 24 deletions

View File

@ -50,29 +50,11 @@ function storeLayout(pane, $pane, paneState, paneOptions) {
return true
}
function getSetting(setting, defval) {
var value
$.ajaxSetup({
async: false
});
$.post("{{ url_for('settings.get') }}", { setting: setting, default: defval })
.done(function(data) {
value = data
});
$.ajaxSetup({
async: true
});
return value
}
// Get the previous settings
var sqlPaneSize = getSetting("Browser/SQLPane/Size", "250")
var sqlPaneClosed = (getSetting("Browser/SQLPane/Closed", "false") == "true" ? true : false)
var browserPaneSize = getSetting("Browser/BrowserPane/Size", "250")
var browserPaneClosed = (getSetting("Browser/BrowserPane/Closed", "false") == "true" ? true : false)
var sqlPaneSize = getIntegerSetting("Browser/SQLPane/Size", 250)
var sqlPaneClosed = getBooleanSetting("Browser/SQLPane/Closed", false)
var browserPaneSize = getIntegerSetting("Browser/BrowserPane/Size", 250)
var browserPaneClosed = getBooleanSetting("Browser/BrowserPane/Closed", false)
var layout
var layoutDefault = {

View File

@ -1 +0,0 @@

View File

@ -42,7 +42,9 @@
<script src="{{ url_for('static', filename='js/vendor/jquery-ui/jquery-ui.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/vendor/jquery-layout/jquery.layout.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/vendor/jquery-layout/plugins/jquery.layout.state.js') }}"></script>
<script src="{{ url_for('static', filename='js/main.js') }}"></script>
<script>
{% include "js/settings.js" %}
</script>
<script>
alertify.defaults.transition = "zoom";

View File

@ -0,0 +1,47 @@
// Get a setting from the server. Returns a string value
function getSetting(setting, defval) {
var value
$.ajaxSetup({
async: false
});
$.post("{{ url_for('settings.get') }}", { setting: setting, default: defval })
.done(function(data) {
value = data
});
$.ajaxSetup({
async: true
});
return value
}
// Get a setting from the server. Returns a boolean value
function getBooleanSetting(setting, defval) {
return (getSetting(setting, defval) == "true" ? true : false)
}
// Get a setting from the server. Returns an integer value
function getIntegerSetting(setting, defval) {
return parseInt(getSetting(setting, defval))
}
// Get a setting from the server. Returns an float value
function getFloatSetting(setting, defval) {
return parseFloat(getSetting(setting, defval))
}
// Store a single setting
function storeSetting(setting, value) {
$.post("{{ url_for('settings.store') }}", { setting: setting, value: value });
}
// Store a number of settings.
// settings is a javascript object containing values for settingX and valueX,
// along with a count value which equals the number of setting/value pairs.
// X is 1 based.
function storeSetting(settings) {
$.post("{{ url_for('settings.store') }}", settings);
}