codemirror seems to work with admin
This commit is contained in:
@@ -1 +1 @@
|
|||||||
Version 2.0.8 (2012-09-08 22:22:02) stable
|
Version 2.0.8 (2012-09-08 23:22:37) stable
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ WEB2PY_VERSION_URL = WEB2PY_URL+'/examples/default/version'
|
|||||||
# browser.
|
# browser.
|
||||||
|
|
||||||
## Default editor
|
## Default editor
|
||||||
TEXT_EDITOR = 'ace' or 'edit_area' or 'amy'
|
TEXT_EDITOR = 'ace' or 'edit_area' or 'amy' or 'codemirror'
|
||||||
## Editor Color scheme (only for ace)
|
## Editor Color scheme (only for ace)
|
||||||
TEXT_EDITOR_THEME = (
|
TEXT_EDITOR_THEME = (
|
||||||
"chrome", "clouds", "clouds_midnight", "cobalt", "crimson_editor", "dawn",
|
"chrome", "clouds", "clouds_midnight", "cobalt", "crimson_editor", "dawn",
|
||||||
|
|||||||
@@ -10,14 +10,14 @@ function prepareMultiPartPOST(data) {
|
|||||||
var boundary = '' + Math.floor(Math.random()*10000);
|
var boundary = '' + Math.floor(Math.random()*10000);
|
||||||
var reqdata = '--' + boundary + '\r\n';
|
var reqdata = '--' + boundary + '\r\n';
|
||||||
//console.log(data.length);
|
//console.log(data.length);
|
||||||
for (var i=0;i < data.length;i++)
|
for (var i=0;i < data.length;i++) {
|
||||||
{
|
reqdata += 'content-disposition: form-data; name="';
|
||||||
reqdata += 'content-disposition: form-data; name="' + data[i].Name + '"';
|
reqdata += data[i].Name + '"';
|
||||||
reqdata += "\r\n\r\n" ;
|
reqdata += "\r\n\r\n" ;
|
||||||
reqdata += data[i].Data;
|
reqdata += data[i].Data;
|
||||||
reqdata += "\r\n" ;
|
reqdata += "\r\n" ;
|
||||||
reqdata += '--' + boundary + '\r\n';
|
reqdata += '--' + boundary + '\r\n';
|
||||||
}
|
}
|
||||||
return new Array(reqdata,boundary);
|
return new Array(reqdata,boundary);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,101 +27,120 @@ function on_error() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getData() {
|
function getData() {
|
||||||
try {
|
if (window.ace_editor) {
|
||||||
var data = window.ace_editor.getSession().getValue();
|
var data = window.ace_editor.getSession().getValue();
|
||||||
} catch(e) {
|
} else if (window.mirror) {
|
||||||
try {
|
var data = window.mirror.getValue();
|
||||||
var data = eamy.instances[0].getText();
|
} else if (window.eamy) {
|
||||||
} catch(e) {
|
var data = window.eamy.instances[0].getText();
|
||||||
var data = area.textarea.value;
|
} else if (window.textarea) {
|
||||||
}
|
var data = textarea.value;
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
function doHighlight(highlight) {
|
function doHighlight(highlight) {
|
||||||
try {
|
if (window.ace_editor) {
|
||||||
window.ace_editor.gotoLine(highlight.lineno);
|
window.ace_editor.gotoLine(highlight.lineno);
|
||||||
} catch(e) {
|
} else if (window.mirror) {
|
||||||
editAreaLoader.setSelectionRange('body', highlight.start, highlight.end);
|
window.mirror.setSelection({line:highlight.lineno,ch:0},
|
||||||
}
|
{line:highlight.end,ch:0});
|
||||||
|
} else if (window.eamy) {
|
||||||
|
// not implemented
|
||||||
|
} else if (window.textarea) {
|
||||||
|
editAreaLoader.setSelectionRange('body', highlight.start, highlight.end);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function doClickSave() {
|
function doClickSave() {
|
||||||
var data = getData();
|
var data = getData();
|
||||||
var dataForPost = prepareMultiPartPOST(new Array(
|
var dataForPost = prepareMultiPartPOST(new Array(
|
||||||
prepareDataForSave('data', data),
|
prepareDataForSave('data', data),
|
||||||
prepareDataForSave('file_hash', jQuery("input[name='file_hash']").val()),
|
prepareDataForSave('file_hash',
|
||||||
prepareDataForSave('saved_on', jQuery("input[name='saved_on']").val()),
|
jQuery("input[name='file_hash']").val()),
|
||||||
prepareDataForSave('saved_on', jQuery("input[name='saved_on']").val()),
|
prepareDataForSave('saved_on',
|
||||||
|
jQuery("input[name='saved_on']").val()),
|
||||||
|
prepareDataForSave('saved_on',
|
||||||
|
jQuery("input[name='saved_on']").val()),
|
||||||
prepareDataForSave('from_ajax','true')));
|
prepareDataForSave('from_ajax','true')));
|
||||||
// console.info(area.textarea.value);
|
// console.info(area.textarea.value);
|
||||||
jQuery("input[name='saved_on']").attr('style','background-color:yellow');
|
jQuery("input[name='saved_on']").attr('style',
|
||||||
|
'background-color:yellow');
|
||||||
jQuery("input[name='saved_on']").val('saving now...')
|
jQuery("input[name='saved_on']").val('saving now...')
|
||||||
jQuery.ajax({
|
jQuery.ajax({
|
||||||
type: "POST",
|
type: "POST",
|
||||||
contentType: 'multipart/form-data;boundary="' + dataForPost[1] + '"',
|
contentType: 'multipart/form-data;boundary="'
|
||||||
|
+ dataForPost[1] + '"',
|
||||||
url: self.location.href,
|
url: self.location.href,
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
data: dataForPost[0],
|
data: dataForPost[0],
|
||||||
timeout: 5000,
|
timeout: 5000,
|
||||||
beforeSend: function(xhr) {
|
beforeSend: function(xhr) {
|
||||||
xhr.setRequestHeader('web2py-component-location',document.location);
|
xhr.setRequestHeader('web2py-component-location',
|
||||||
xhr.setRequestHeader('web2py-component-element','doClickSave');},
|
document.location);
|
||||||
|
xhr.setRequestHeader('web2py-component-element',
|
||||||
|
'doClickSave');
|
||||||
|
},
|
||||||
success: function(json,text,xhr){
|
success: function(json,text,xhr){
|
||||||
|
|
||||||
// show flash message (if any)
|
// show flash message (if any)
|
||||||
var flash=xhr.getResponseHeader('web2py-component-flash');
|
var flash=xhr.getResponseHeader('web2py-component-flash');
|
||||||
if (flash) jQuery('.flash').html(decodeURIComponent(flash)).slideDown();
|
if (flash) {
|
||||||
else jQuery('.flash').hide();
|
var flashhtml = decodeURIComponent(flash);
|
||||||
|
jQuery('.flash').html(flashhtml).slideDown();
|
||||||
|
} else jQuery('.flash').hide();
|
||||||
|
|
||||||
// reenable disabled submit button
|
// reenable disabled submit button
|
||||||
var t=jQuery("input[name='save']");
|
var t=jQuery("input[name='save']");
|
||||||
t.attr('class','');
|
t.attr('class','');
|
||||||
t.attr('disabled','');
|
t.attr('disabled','');
|
||||||
|
try {
|
||||||
try {
|
if (json.error) {
|
||||||
if (json.error) {
|
window.location.href=json.redirect;
|
||||||
window.location.href=json.redirect;
|
} else {
|
||||||
} else {
|
// console.info( json.file_hash );
|
||||||
// console.info( json.file_hash );
|
jQuery("input[name='file_hash']").val(json.file_hash);
|
||||||
jQuery("input[name='file_hash']").val(json.file_hash);
|
jQuery("input[name='saved_on']").val(json.saved_on);
|
||||||
jQuery("input[name='saved_on']").val(json.saved_on);
|
if (json.highlight) {
|
||||||
if (json.highlight) {
|
doHighlight(json.highlight);
|
||||||
doHighlight(json.highlight);
|
} else {
|
||||||
} else {
|
jQuery("input[name='saved_on']").attr('style','background-color:#99FF99');
|
||||||
jQuery("input[name='saved_on']").attr('style','background-color:#99FF99');
|
jQuery(".flash").delay(1000).fadeOut('slow');
|
||||||
jQuery(".flash").delay(1000).fadeOut('slow');
|
|
||||||
}
|
|
||||||
// console.info(jQuery("input[name='file_hash']").val());
|
|
||||||
|
|
||||||
var output = '<b>exposes:</b> ';
|
|
||||||
for ( var i in json.functions) {
|
|
||||||
output += ' <a href="/' + json.application + '/' + json.controller + '/' + json.functions[i] + '">' + json.functions[i] + '</a>,';
|
|
||||||
}
|
|
||||||
if(output!='<b>exposes:</b> ') {
|
|
||||||
jQuery("#exposed").html( output.substring(0, output.length-1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch(e) {
|
|
||||||
on_error();
|
|
||||||
}
|
}
|
||||||
|
// console.info(jQuery("input[name='file_hash']").val());
|
||||||
|
var output = '<b>exposes:</b> ';
|
||||||
|
for ( var i in json.functions) {
|
||||||
|
output += ' <a href="/' + json.application + '/' + json.controller + '/' + json.functions[i] + '">' + json.functions[i] + '</a>,';
|
||||||
|
}
|
||||||
|
if(output!='<b>exposes:</b> ') {
|
||||||
|
jQuery("#exposed").html( output.substring(0, output.length-1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch(e) { on_error();}
|
||||||
},
|
},
|
||||||
error: function(json) { on_error(); }
|
error: function(json) { on_error(); }
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSelectionRange() {
|
function getSelectionRange() {
|
||||||
var sel;
|
var sel;
|
||||||
try {
|
if (window.ace_editor) {
|
||||||
sel = {};
|
sel = {};
|
||||||
range = window.ace_editor.getSelectionRange();
|
range = window.ace_editor.getSelectionRange();
|
||||||
// passing the line number directly, no need to read the text
|
// passing the line number directly, no need to read the text
|
||||||
sel['start'] = range.start.row;
|
sel['start'] = range.start.row;
|
||||||
sel['end'] = range.end.row;
|
sel['end'] = range.end.row;
|
||||||
sel['data'] = '';
|
sel['data'] = '';
|
||||||
} catch(e) {
|
} else if (window.mirror) {
|
||||||
|
sel = {};
|
||||||
|
sel['start'] = window.mirror.getCursor(true).line;
|
||||||
|
sel['end'] = window.mirror.getCursor(false).line;
|
||||||
|
sel['data'] = '';
|
||||||
|
} else if (window.eamy) {
|
||||||
|
sel = {};
|
||||||
|
// not implemented
|
||||||
|
} else if (window.textarea) {
|
||||||
// passing offset, needs the text to calculate the line:
|
// passing offset, needs the text to calculate the line:
|
||||||
sel = editAreaLoader.getSelectionRange('body');
|
sel = editAreaLoader.getSelectionRange('body');
|
||||||
sel['data'] = getData();
|
sel['data'] = getData();
|
||||||
@@ -130,7 +149,7 @@ function getSelectionRange() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function doToggleBreakpoint(filename, url) {
|
function doToggleBreakpoint(filename, url) {
|
||||||
var sel = getSelectionRange();
|
var sel = getSelectionRange();
|
||||||
var dataForPost = prepareMultiPartPOST(new Array(
|
var dataForPost = prepareMultiPartPOST(new Array(
|
||||||
prepareDataForSave('filename', filename),
|
prepareDataForSave('filename', filename),
|
||||||
prepareDataForSave('sel_start', sel["start"]),
|
prepareDataForSave('sel_start', sel["start"]),
|
||||||
@@ -138,35 +157,34 @@ function doToggleBreakpoint(filename, url) {
|
|||||||
prepareDataForSave('data', sel['data'])));
|
prepareDataForSave('data', sel['data'])));
|
||||||
jQuery.ajax({
|
jQuery.ajax({
|
||||||
type: "POST",
|
type: "POST",
|
||||||
contentType: 'multipart/form-data;boundary="' + dataForPost[1] + '"',
|
contentType: 'multipart/form-data;boundary="'+dataForPost[1]+'"',
|
||||||
url: url,
|
url: url,
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
data: dataForPost[0],
|
data: dataForPost[0],
|
||||||
timeout: 5000,
|
timeout: 5000,
|
||||||
beforeSend: function(xhr) {
|
beforeSend: function(xhr) {
|
||||||
xhr.setRequestHeader('web2py-component-location',document.location);
|
xhr.setRequestHeader('web2py-component-location',
|
||||||
xhr.setRequestHeader('web2py-component-element','doSetBreakpoint');},
|
document.location);
|
||||||
|
xhr.setRequestHeader('web2py-component-element',
|
||||||
|
'doSetBreakpoint');},
|
||||||
success: function(json,text,xhr){
|
success: function(json,text,xhr){
|
||||||
|
// show flash message (if any)
|
||||||
// show flash message (if any)
|
var flash=xhr.getResponseHeader('web2py-component-flash');
|
||||||
var flash=xhr.getResponseHeader('web2py-component-flash');
|
if (flash) jQuery('.flash').html(decodeURIComponent(flash)).slideDown();
|
||||||
if (flash) jQuery('.flash').html(decodeURIComponent(flash)).slideDown();
|
else jQuery('.flash').hide();
|
||||||
else jQuery('.flash').hide();
|
try {
|
||||||
try {
|
if (json.error) {
|
||||||
if (json.error) {
|
window.location.href=json.redirect;
|
||||||
window.location.href=json.redirect;
|
} else {
|
||||||
} else {
|
// mark the breakpoint if ok=True
|
||||||
// mark the breakpoint if ok=True, remove mark if ok=False
|
// remove mark if ok=False
|
||||||
// do nothing if ok = null
|
// do nothing if ok = null
|
||||||
// alert(json.ok + json.lineno);
|
// alert(json.ok + json.lineno);
|
||||||
}
|
}
|
||||||
} catch(e) {
|
} catch(e) { on_error(); }
|
||||||
on_error();
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
},
|
||||||
error: function(json) { on_error(); }
|
error: function(json) { on_error(); }
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,10 +17,7 @@
|
|||||||
<script src="{{=cm}}/mode/css/css.js"></script>
|
<script src="{{=cm}}/mode/css/css.js"></script>
|
||||||
<script src="{{=cm}}/mode/javascript/javascript.js"></script>
|
<script src="{{=cm}}/mode/javascript/javascript.js"></script>
|
||||||
<script src="{{=cm}}/mode/htmlmixed/htmlmixed.js"></script>
|
<script src="{{=cm}}/mode/htmlmixed/htmlmixed.js"></script>
|
||||||
<!-- note to self:
|
<script language="Javascript" type="text/javascript" src="{{=URL('static','js/ajax_editor.js')}}"></script>
|
||||||
for this to be able to save, it requires ajax_editor.js
|
|
||||||
but ajax_editor only works for ace because debugger breakpoints
|
|
||||||
//-->
|
|
||||||
{{elif TEXT_EDITOR == 'ace':}}
|
{{elif TEXT_EDITOR == 'ace':}}
|
||||||
<script src="{{=URL(r=request,c='static',f='ace/src/ace.js')}}" type="text/javascript" charset="utf-8"></script>
|
<script src="{{=URL(r=request,c='static',f='ace/src/ace.js')}}" type="text/javascript" charset="utf-8"></script>
|
||||||
<script src="{{=URL(r=request,c='static',f='ace/src/theme-%s.js' % TEXT_EDITOR_THEME)}}" type="text/javascript" charset="utf-8"></script>
|
<script src="{{=URL(r=request,c='static',f='ace/src/theme-%s.js' % TEXT_EDITOR_THEME)}}" type="text/javascript" charset="utf-8"></script>
|
||||||
@@ -127,9 +124,10 @@ jQuery(document).ready(function(){
|
|||||||
{{=T('Last saved on:')}} <input type="input" name="saved_on" value="{{=saved_on}}" readonly="readonly"/>
|
{{=T('Last saved on:')}} <input type="input" name="saved_on" value="{{=saved_on}}" readonly="readonly"/>
|
||||||
<br><hr>
|
<br><hr>
|
||||||
{{if TEXT_EDITOR == 'amy':}}
|
{{if TEXT_EDITOR == 'amy':}}
|
||||||
<textarea style="width: auto; height:400px;direction:ltr;" rows="58" cols="100" -amy-enabled="true" id="body" name="data"><div id="editor"/>{{=data}}</textarea>
|
|
||||||
{{elif TEXT_EDITOR == 'codemirror':}}
|
|
||||||
<textarea style="width: auto; height:400px;direction:ltr;" rows="58" cols="100" -amy-enabled="true" id="body" name="data">{{=data}}</textarea>
|
<textarea style="width: auto; height:400px;direction:ltr;" rows="58" cols="100" -amy-enabled="true" id="body" name="data">{{=data}}</textarea>
|
||||||
|
<script>window.eamy = eamy;</script>
|
||||||
|
{{elif TEXT_EDITOR == 'codemirror':}}
|
||||||
|
<textarea style="width: auto; height:400px;direction:ltr;" id="body" name="data">{{=data}}</textarea>
|
||||||
{{cm_mode = {'html':'htmlmixed'}.get(filetype,filetype)}}
|
{{cm_mode = {'html':'htmlmixed'}.get(filetype,filetype)}}
|
||||||
<script>
|
<script>
|
||||||
var editor = CodeMirror.fromTextArea(document.getElementById("body"),
|
var editor = CodeMirror.fromTextArea(document.getElementById("body"),
|
||||||
@@ -137,10 +135,11 @@ jQuery(document).ready(function(){
|
|||||||
lineNumbers: true,
|
lineNumbers: true,
|
||||||
indentUnit: 4,
|
indentUnit: 4,
|
||||||
tabMode: "shift",
|
tabMode: "shift",
|
||||||
saveFunction: function() { doClickSave(); },
|
extraKeys: { "Ctrl-S": function(instance) {doClickSave();} },
|
||||||
{{if TEXT_EDITOR_KEYBINDING == 'emacs':}}keyMap: "emacs",{{pass}}
|
{{if TEXT_EDITOR_KEYBINDING == 'emacs':}}keyMap: "emacs",{{pass}}
|
||||||
matchBrackets: true
|
matchBrackets: true
|
||||||
});
|
});
|
||||||
|
window.mirror = editor;
|
||||||
</script>
|
</script>
|
||||||
{{elif TEXT_EDITOR == 'ace':}}
|
{{elif TEXT_EDITOR == 'ace':}}
|
||||||
<div id="editor" style="height: 500px; width: auto; position: relative">{{=data}}</div>
|
<div id="editor" style="height: 500px; width: auto; position: relative">{{=data}}</div>
|
||||||
@@ -166,9 +165,9 @@ window.onload = function() {
|
|||||||
window.ace_editor = editor;
|
window.ace_editor = editor;
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{{else:}}
|
{{else:}}
|
||||||
<textarea cols="80" rows="25" id="body" style="direction:ltr;" name="data">{{=data}}</textarea>
|
<textarea cols="80" rows="25" id="body" style="direction:ltr;" name="data">{{=data}}</textarea>
|
||||||
|
<script>window.textarea = area.textarea;</script>
|
||||||
{{pass}}
|
{{pass}}
|
||||||
<button class="editbutton" onclick="window.location.reload(); return false">{{=T('restore')}}</button> {{=T('currently saved or')}} <button class="editbutton" type="submit" name="revert">{{=T('revert')}}</button>
|
<button class="editbutton" onclick="window.location.reload(); return false">{{=T('restore')}}</button> {{=T('currently saved or')}} <button class="editbutton" type="submit" name="revert">{{=T('revert')}}</button>
|
||||||
{{=T('to previous version.')}}
|
{{=T('to previous version.')}}
|
||||||
|
|||||||
Reference in New Issue
Block a user