settings tab in admin editor
This commit is contained in:
@@ -14,6 +14,7 @@ from gluon.utils import web2py_uuid
|
|||||||
from glob import glob
|
from glob import glob
|
||||||
import shutil
|
import shutil
|
||||||
import platform
|
import platform
|
||||||
|
import ConfigParser
|
||||||
try:
|
try:
|
||||||
import git
|
import git
|
||||||
if git.__version__ < '0.3.1':
|
if git.__version__ < '0.3.1':
|
||||||
@@ -560,6 +561,16 @@ def edit():
|
|||||||
""" File edit handler """
|
""" File edit handler """
|
||||||
# Load json only if it is ajax edited...
|
# Load json only if it is ajax edited...
|
||||||
app = get_app(request.vars.app)
|
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):
|
if not(request.ajax):
|
||||||
# return the scaffolding, the rest will be through ajax requests
|
# return the scaffolding, the rest will be through ajax requests
|
||||||
@@ -573,7 +584,25 @@ def edit():
|
|||||||
for key in editarea_preferences:
|
for key in editarea_preferences:
|
||||||
if key in globals():
|
if key in globals():
|
||||||
editarea_preferences[key] = globals()[key]
|
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 """
|
""" File edit handler """
|
||||||
# Load json only if it is ajax edited...
|
# Load json only if it is ajax edited...
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
.twitter-typeahead {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
.twitter-typeahead .tt-query,
|
.twitter-typeahead .tt-query,
|
||||||
.twitter-typeahead .tt-hint {
|
.twitter-typeahead .tt-hint {
|
||||||
margin-bottom: 0px;
|
margin-bottom: 0px;
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
}}
|
}}
|
||||||
{{cm=URL('static','codemirror')}}
|
{{cm=URL('static','codemirror')}}
|
||||||
<link rel="stylesheet" href="{{=cm}}/lib/codemirror.css">
|
<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}}/lib/codemirror.js"></script>
|
||||||
<script src="{{=cm}}/mode/clike/clike.js"></script>
|
<script src="{{=cm}}/mode/clike/clike.js"></script>
|
||||||
<script src="{{=cm}}/addon/edit/matchbrackets.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','typeahead.js-bootstrap.css')}}">
|
||||||
<link rel="stylesheet" href="{{=URL('static/css','web2py-codemirror.css')}}">
|
<link rel="stylesheet" href="{{=URL('static/css','web2py-codemirror.css')}}">
|
||||||
<script type="text/javascript">
|
<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
|
var current_font_incr = 0; // Default font-size, 0 means don't set
|
||||||
jQuery(document).on('shown click', 'a[data-toggle="tab"]', function (e) {
|
jQuery(document).on('shown click', 'a[data-toggle="tab"]', function (e) {
|
||||||
var tab_id = jQuery(this).attr('href');
|
var tab_id = jQuery(this).attr('href');
|
||||||
@@ -84,32 +84,27 @@ jQuery(document).on('click', '#restore', function (e) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// open the selected file
|
// open the selected file
|
||||||
jQuery(document).on('click', 'a.editor_filelink', function (e) {
|
jQuery(document).on('click', 'a.editor_filelink, a#editor_settingslink', function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
var url = jQuery(this).attr("href");
|
var url = jQuery(this).attr("href");
|
||||||
load_file(url);
|
load_file(url);
|
||||||
});
|
});
|
||||||
|
|
||||||
// change the codemirror theme
|
function update_theme(name) {
|
||||||
jQuery(document).on('click', '#themes a', function (e) {
|
var href = "{{="%s/theme/" % cm}}" + name + ".css";
|
||||||
e.preventDefault();
|
var link = jQuery("<link>");
|
||||||
var href = jQuery(this).attr('href');
|
link.attr({
|
||||||
var name = jQuery(this).text().replace('.css', '');
|
type: 'text/css',
|
||||||
var link = jQuery("<link>");
|
rel: 'stylesheet',
|
||||||
link.attr({
|
href: href
|
||||||
type: 'text/css',
|
});
|
||||||
rel: 'stylesheet',
|
jQuery("head").append( link );
|
||||||
href: href
|
jQuery('textarea[name="data"]') .each(function(id, ta) {
|
||||||
});
|
editor = jQuery(ta).data('editor');
|
||||||
jQuery("head").append( link );
|
editor.setOption("theme", name);
|
||||||
jQuery('textarea[name="data"]') .each(function(id, ta) {
|
});
|
||||||
editor = jQuery(ta).data('editor');
|
current_theme = name;
|
||||||
editor.setOption("theme", name);
|
}
|
||||||
});
|
|
||||||
jQuery('#themeName').html(name);
|
|
||||||
current_theme = name;
|
|
||||||
//#TODO save on session
|
|
||||||
});
|
|
||||||
|
|
||||||
// incr/decr editor font-size
|
// incr/decr editor font-size
|
||||||
jQuery(document).on('click', 'a.font_button', function (e) {
|
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">
|
<div class="btn-group">
|
||||||
<a class="button btn" onclick="jQuery('#files').toggle(); return false" href="#">Files toggle</a>
|
<a class="button btn" onclick="jQuery('#files').toggle(); return false" href="#">Files toggle</a>
|
||||||
</div>
|
</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">
|
<div class="btn-group">
|
||||||
<a id="decr" class="button btn font_button">-</a>
|
<a id="decr" class="button btn font_button">-</a>
|
||||||
<a id="default" class="button btn font_button" >A</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>
|
<a class="button btn" href="http://www.web2py.com/sqldesigner" target="_blank"><span>{{=T('online designer')}}</span></a>
|
||||||
{{#pass}}
|
{{#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" 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>
|
</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