Move the JS code for the main browser out of the HTML template

and into the browser.js view.
This commit is contained in:
Dave Page 2015-02-20 09:37:42 -05:00
parent b43580a19e
commit 37be918074
3 changed files with 133 additions and 130 deletions

View File

@ -73,123 +73,3 @@ CREATE INDEX tickets_detail_ticket_id
</div>
</div>
<script>
function storeLayout(pane, $pane, paneState, paneOptions) {
state = layout.readState();
settings = { setting1: "Browser/SQLPane/Size",
value1: state.center.children.layout1.south.size,
setting2: "Browser/SQLPane/Closed",
value2: state.center.children.layout1.south.initClosed,
setting3: "Browser/BrowserPane/Size",
value3: state.west.size,
setting4: "Browser/BrowserPane/Closed",
value4: state.west.initClosed,
count: 4
}
$.post("{{ url_for('settings.store') }}", settings);
return true
}
var layout
var layoutDefault = {
center__maskContents: true,
center__paneSelector: "#outer-center",
center__maskContents: true,
center__children: [{
center__paneSelector: "#inner-center",
center__maskContents: true,
center__onresize: "storeLayout",
south__maskContents: true,
south__size: {{ layout_settings.sql_size }},
south__initClosed: {{ layout_settings.sql_closed }},
south__spacing_closed: 22,
south__togglerLength_closed: 140,
south__togglerAlign_closed: "right",
south__togglerContent_closed: 'SQL Pane',
south__togglerTip_closed: "Open & Pin SQL Pane",
south__sliderTip: "Slide Open SQL Pane",
south__slideTrigger_open: "mouseover",
}],
west__maskContents: true,
west__size: {{ layout_settings.browser_size }},
west__initClosed: {{ layout_settings.browser_closed }},
west__spacing_closed: 22,
west__togglerLength_closed: 140,
west__togglerAlign_closed: "top",
west__togglerContent_closed: 'B<br />r<br />o<br />w<br />s<br />e<br />r',
west__togglerTip_closed: "Open & Pin Browser",
west__sliderTip: "Slide Open Browser",
west__slideTrigger_open: "mouseover",
};
layout = $('#container').layout(layoutDefault);
// Make the tabs, umm, tabable
$('#dashboard a').click(function (e) {
e.preventDefault()
$(this).tab('show')
})
$('#properties a').click(function (e) {
e.preventDefault()
$(this).tab('show')
})
$('#statistics a').click(function (e) {
e.preventDefault()
$(this).tab('show')
})
$('#dependencies a').click(function (e) {
e.preventDefault()
$(this).tab('show')
})
$('#dependents a').click(function (e) {
e.preventDefault()
$(this).tab('show')
})
// Syntax highlight the SQL Pane
var editor = CodeMirror.fromTextArea(document.getElementById("sql-textarea"), {
lineNumbers: true,
mode: "text/x-sql",
readOnly: true,
});
// Initialise the treeview
$('#tree').aciTree({
ajax: {
url: '{{ url_for('browser.get_nodes') }}'
},
});
var treeApi = $('#tree').aciTree('api');
$('#tree').contextMenu({
selector: '.aciTreeLine',
build: function(element) {
var item = treeApi.itemFrom(element);
var menu = {
};
menu['rename'] = {
name: 'Rename server group',
callback: function() { rename_server_group(item); }
};
menu['delete'] = {
name: 'Delete server group',
callback: function() { delete_server_group(item); }
};
return {
autoHide: true,
items: menu,
callback: null
};
}
});
</script>

View File

@ -0,0 +1,121 @@
// Store the main browser layout
function storeLayout(pane, $pane, paneState, paneOptions) {
state = layout.readState();
settings = { setting1: "Browser/SQLPane/Size",
value1: state.center.children.layout1.south.size,
setting2: "Browser/SQLPane/Closed",
value2: state.center.children.layout1.south.initClosed,
setting3: "Browser/BrowserPane/Size",
value3: state.west.size,
setting4: "Browser/BrowserPane/Closed",
value4: state.west.initClosed,
count: 4
}
$.post("{{ url_for('settings.store') }}", settings);
return true
}
// Setup the browsers
$(document).ready(function(){
// Define the main browser layout
var layout
var layoutDefault = {
center__maskContents: true,
center__paneSelector: "#outer-center",
center__maskContents: true,
center__children: [{
center__paneSelector: "#inner-center",
center__maskContents: true,
center__onresize: "storeLayout",
south__maskContents: true,
south__size: {{ layout_settings.sql_size }},
south__initClosed: {{ layout_settings.sql_closed }},
south__spacing_closed: 22,
south__togglerLength_closed: 140,
south__togglerAlign_closed: "right",
south__togglerContent_closed: 'SQL Pane',
south__togglerTip_closed: "Open & Pin SQL Pane",
south__sliderTip: "Slide Open SQL Pane",
south__slideTrigger_open: "mouseover",
}],
west__maskContents: true,
west__size: {{ layout_settings.browser_size }},
west__initClosed: {{ layout_settings.browser_closed }},
west__spacing_closed: 22,
west__togglerLength_closed: 140,
west__togglerAlign_closed: "top",
west__togglerContent_closed: 'B<br />r<br />o<br />w<br />s<br />e<br />r',
west__togglerTip_closed: "Open & Pin Browser",
west__sliderTip: "Slide Open Browser",
west__slideTrigger_open: "mouseover",
};
layout = $('#container').layout(layoutDefault);
// Make the tabs, umm, tabable
$('#dashboard a').click(function (e) {
e.preventDefault()
$(this).tab('show')
})
$('#properties a').click(function (e) {
e.preventDefault()
$(this).tab('show')
})
$('#statistics a').click(function (e) {
e.preventDefault()
$(this).tab('show')
})
$('#dependencies a').click(function (e) {
e.preventDefault()
$(this).tab('show')
})
$('#dependents a').click(function (e) {
e.preventDefault()
$(this).tab('show')
})
// Syntax highlight the SQL Pane
var editor = CodeMirror.fromTextArea(document.getElementById("sql-textarea"), {
lineNumbers: true,
mode: "text/x-sql",
readOnly: true,
});
// Initialise the treeview
$('#tree').aciTree({
ajax: {
url: '{{ url_for('browser.get_nodes') }}'
},
});
var treeApi = $('#tree').aciTree('api');
// Build the treeview context menu
$('#tree').contextMenu({
selector: '.aciTreeLine',
build: function(element) {
var item = treeApi.itemFrom(element);
var menu = {
};
menu['rename'] = {
name: 'Rename server group',
callback: function() { rename_server_group(item); }
};
menu['delete'] = {
name: 'Delete server group',
callback: function() { delete_server_group(item); }
};
return {
autoHide: true,
items: menu,
callback: null
};
}
});
});

View File

@ -96,13 +96,6 @@ def index():
tools_items = sorted(tools_items, key=lambda k: k['priority'])
help_items = sorted(help_items, key=lambda k: k['priority'])
# Get the layout settings
layout_settings = { }
layout_settings['sql_size'] = get_setting('Browser/SQLPane/Size', default=250)
layout_settings['sql_closed'] = get_setting('Browser/SQLPane/Closed', default="false")
layout_settings['browser_size'] = get_setting('Browser/BrowserPane/Size', default=250)
layout_settings['browser_closed'] = get_setting('Browser/BrowserPane/Closed', default="false")
return render_template(MODULE_NAME + '/index.html',
username=current_user.email,
file_items=file_items,
@ -110,8 +103,7 @@ def index():
tools_items=tools_items,
help_items=help_items,
stylesheets = stylesheets,
scripts = scripts,
layout_settings = layout_settings)
scripts = scripts)
@blueprint.route("/browser.js")
@login_required
@ -120,10 +112,20 @@ def browser_js():
snippets = ''
modules_and_nodes = modules + nodes
# Load the core browser code first
layout_settings = { }
layout_settings['sql_size'] = get_setting('Browser/SQLPane/Size', default=250)
layout_settings['sql_closed'] = get_setting('Browser/SQLPane/Closed', default="false")
layout_settings['browser_size'] = get_setting('Browser/BrowserPane/Size', default=250)
layout_settings['browser_closed'] = get_setting('Browser/BrowserPane/Closed', default="false")
snippets += render_template('browser/js/browser.js', layout_settings=layout_settings)
# Add module and node specific code
for module in modules_and_nodes:
if 'hooks' in dir(module) and 'get_script_snippets' in dir(module.hooks):
snippets += module.hooks.get_script_snippets()
resp = Response(response=snippets,
status=200,
mimetype="application/javascript")