settings tab in admin editor
This commit is contained in:
@@ -14,6 +14,7 @@ from gluon.utils import web2py_uuid
|
||||
from glob import glob
|
||||
import shutil
|
||||
import platform
|
||||
import ConfigParser
|
||||
try:
|
||||
import git
|
||||
if git.__version__ < '0.3.1':
|
||||
@@ -560,6 +561,16 @@ def edit():
|
||||
""" File edit handler """
|
||||
# Load json only if it is ajax edited...
|
||||
app = get_app(request.vars.app)
|
||||
admin_path = apath("admin", r=request)
|
||||
editor_defaults={'theme':'web2py'}
|
||||
config = ConfigParser.ConfigParser(editor_defaults)
|
||||
config.read( os.path.join(admin_path, 'settings.cfg') )
|
||||
if not config.has_section('editor'):
|
||||
config.add_section('editor')
|
||||
if not( isinstance(session.editor_settings, dict) ):
|
||||
preferences = dict(config.items('editor'))
|
||||
else:
|
||||
preferences = session.editor_settings
|
||||
|
||||
if not(request.ajax):
|
||||
# return the scaffolding, the rest will be through ajax requests
|
||||
@@ -573,7 +584,25 @@ def edit():
|
||||
for key in editarea_preferences:
|
||||
if key in globals():
|
||||
editarea_preferences[key] = globals()[key]
|
||||
return response.render ('default/edit.html', dict(app=request.args[0], editarea_preferences=editarea_preferences))
|
||||
return response.render ('default/edit.html', dict(app=request.args[0], editor_settings=preferences, editarea_preferences=editarea_preferences))
|
||||
|
||||
# show settings tab and save prefernces
|
||||
if 'settings' in request.vars:
|
||||
if request.post_vars: #save new preferences
|
||||
for option, value in request.post_vars.items():
|
||||
config.set('editor', option, value)
|
||||
try:
|
||||
config.write(open(os.path.join(admin_path, 'settings.cfg'), 'w'))
|
||||
response.headers["web2py-component-flash"] = T('Preferences saved correctly')
|
||||
except:
|
||||
response.headers["web2py-component-flash"] = T('Preferences saved on session only')
|
||||
session.editor_settings = dict(config.items('editor'))
|
||||
response.headers["web2py-component-command"] = "update_theme('%s'); jQuery('a[href=#editor_settings] button.close').click();" % config.get('editor', 'theme')
|
||||
return
|
||||
else:
|
||||
details = {'filename':'settings', 'id':'editor_settings', 'force': False}
|
||||
details['plain_html'] = response.render('default/editor_settings.html', {'editor_settings':preferences})
|
||||
return response.json(details)
|
||||
|
||||
""" File edit handler """
|
||||
# Load json only if it is ajax edited...
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
.twitter-typeahead {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.twitter-typeahead .tt-query,
|
||||
.twitter-typeahead .tt-hint {
|
||||
margin-bottom: 0px;
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
}}
|
||||
{{cm=URL('static','codemirror')}}
|
||||
<link rel="stylesheet" href="{{=cm}}/lib/codemirror.css">
|
||||
<link rel="stylesheet" href="{{=cm}}/theme/web2py.css">
|
||||
<link rel="stylesheet" href="{{="%s/theme/%s.css" % (cm, editor_settings['theme'])}}">
|
||||
<script src="{{=cm}}/lib/codemirror.js"></script>
|
||||
<script src="{{=cm}}/mode/clike/clike.js"></script>
|
||||
<script src="{{=cm}}/addon/edit/matchbrackets.js"></script>
|
||||
@@ -42,7 +42,7 @@
|
||||
<link rel="stylesheet" href="{{=URL('static/css','typeahead.js-bootstrap.css')}}">
|
||||
<link rel="stylesheet" href="{{=URL('static/css','web2py-codemirror.css')}}">
|
||||
<script type="text/javascript">
|
||||
var current_theme = "web2py"; //Default theme
|
||||
var current_theme = "{{=editor_settings['theme']}}"; //Default theme
|
||||
var current_font_incr = 0; // Default font-size, 0 means don't set
|
||||
jQuery(document).on('shown click', 'a[data-toggle="tab"]', function (e) {
|
||||
var tab_id = jQuery(this).attr('href');
|
||||
@@ -84,32 +84,27 @@ jQuery(document).on('click', '#restore', function (e) {
|
||||
});
|
||||
|
||||
// open the selected file
|
||||
jQuery(document).on('click', 'a.editor_filelink', function (e) {
|
||||
e.preventDefault();
|
||||
var url = jQuery(this).attr("href");
|
||||
load_file(url);
|
||||
jQuery(document).on('click', 'a.editor_filelink, a#editor_settingslink', function (e) {
|
||||
e.preventDefault();
|
||||
var url = jQuery(this).attr("href");
|
||||
load_file(url);
|
||||
});
|
||||
|
||||
// change the codemirror theme
|
||||
jQuery(document).on('click', '#themes a', function (e) {
|
||||
e.preventDefault();
|
||||
var href = jQuery(this).attr('href');
|
||||
var name = jQuery(this).text().replace('.css', '');
|
||||
var link = jQuery("<link>");
|
||||
link.attr({
|
||||
type: 'text/css',
|
||||
rel: 'stylesheet',
|
||||
href: href
|
||||
});
|
||||
jQuery("head").append( link );
|
||||
jQuery('textarea[name="data"]') .each(function(id, ta) {
|
||||
editor = jQuery(ta).data('editor');
|
||||
editor.setOption("theme", name);
|
||||
});
|
||||
jQuery('#themeName').html(name);
|
||||
current_theme = name;
|
||||
//#TODO save on session
|
||||
});
|
||||
function update_theme(name) {
|
||||
var href = "{{="%s/theme/" % cm}}" + name + ".css";
|
||||
var link = jQuery("<link>");
|
||||
link.attr({
|
||||
type: 'text/css',
|
||||
rel: 'stylesheet',
|
||||
href: href
|
||||
});
|
||||
jQuery("head").append( link );
|
||||
jQuery('textarea[name="data"]') .each(function(id, ta) {
|
||||
editor = jQuery(ta).data('editor');
|
||||
editor.setOption("theme", name);
|
||||
});
|
||||
current_theme = name;
|
||||
}
|
||||
|
||||
// incr/decr editor font-size
|
||||
jQuery(document).on('click', 'a.font_button', function (e) {
|
||||
@@ -166,14 +161,6 @@ jQuery(document).on('click', 'a.font_button', function (e) {
|
||||
<div class="btn-group">
|
||||
<a class="button btn" onclick="jQuery('#files').toggle(); return false" href="#">Files toggle</a>
|
||||
</div>
|
||||
<div class="dropdown btn-group pull-left">
|
||||
<a class="dropdown-toggle button btn" data-target="themes" data-toggle="dropdown" href="#" >Theme: <span id="themeName" style="color: #E8953C">Web2py</span> <span class="caret"></span></a>
|
||||
<ul class="dropdown-menu" role="menu" id="themes">
|
||||
{{for f in listfiles('admin', "static/codemirror/theme", regexp='.*\.css$' ):}}
|
||||
<li class=""><a href="{{=URL('static/codemirror/theme', f, host=True)}}">{{=f[:-4]}}</a></li>
|
||||
{{pass}}
|
||||
</ul>
|
||||
</div>
|
||||
<div class="btn-group">
|
||||
<a id="decr" class="button btn font_button">-</a>
|
||||
<a id="default" class="button btn font_button" >A</a>
|
||||
@@ -185,6 +172,7 @@ jQuery(document).on('click', 'a.font_button', function (e) {
|
||||
<a class="button btn" href="http://www.web2py.com/sqldesigner" target="_blank"><span>{{=T('online designer')}}</span></a>
|
||||
{{#pass}}
|
||||
<a class="button btn" href="http://www.web2py.com/examples/static/epydoc/index.html" target="_blank"><span>{{=T('docs')}}</span></a>
|
||||
<a class="button btn" title="{{=T('change editor settings')}}" id="editor_settingslink" href="{{=URL('default', 'edit', args=request.args, vars={'settings':True})}}"><i class="icon-cog"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
{{
|
||||
def listfiles(app, dir, regexp='.*\.py$'):
|
||||
files = sorted(
|
||||
listdir(apath('%(app)s/%(dir)s/' % {'app':app, 'dir':dir}, r=request), regexp))
|
||||
files = [x.replace('\\', '/') for x in files if not x.endswith('.bak')]
|
||||
return files
|
||||
}}
|
||||
{{themes = [f[:-4] for f in listfiles('admin', "static/codemirror/theme", regexp='.*\.css$' )]}}
|
||||
<form id="editor_settings_form" class="form-horizontal">
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="selectTheme">{{=T('Theme')}}</label>
|
||||
<div class="controls">{{=SELECT(themes, value=editor_settings['theme'], _name="theme" )}}</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<div class="controls"><button type="submit" class="disabled btn btn-primary">{{=T('Save')}}</button></div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
<script>
|
||||
web2py_trap_form("{{=URL('default', 'edit', args=request.args, vars={'settings':True})}}", "editor_settings");
|
||||
jQuery("#editor_settings_form").on('change', 'select, input', function (e) {
|
||||
jQuery("#editor_settings_form button[type=submit]").removeClass('disabled');
|
||||
});
|
||||
</script>
|
||||
Reference in New Issue
Block a user