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.
|
||||
|
||||
## 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)
|
||||
TEXT_EDITOR_THEME = (
|
||||
"chrome", "clouds", "clouds_midnight", "cobalt", "crimson_editor", "dawn",
|
||||
|
||||
@@ -10,14 +10,14 @@ function prepareMultiPartPOST(data) {
|
||||
var boundary = '' + Math.floor(Math.random()*10000);
|
||||
var reqdata = '--' + boundary + '\r\n';
|
||||
//console.log(data.length);
|
||||
for (var i=0;i < data.length;i++)
|
||||
{
|
||||
reqdata += 'content-disposition: form-data; name="' + data[i].Name + '"';
|
||||
reqdata += "\r\n\r\n" ;
|
||||
reqdata += data[i].Data;
|
||||
reqdata += "\r\n" ;
|
||||
reqdata += '--' + boundary + '\r\n';
|
||||
}
|
||||
for (var i=0;i < data.length;i++) {
|
||||
reqdata += 'content-disposition: form-data; name="';
|
||||
reqdata += data[i].Name + '"';
|
||||
reqdata += "\r\n\r\n" ;
|
||||
reqdata += data[i].Data;
|
||||
reqdata += "\r\n" ;
|
||||
reqdata += '--' + boundary + '\r\n';
|
||||
}
|
||||
return new Array(reqdata,boundary);
|
||||
}
|
||||
|
||||
@@ -27,101 +27,120 @@ function on_error() {
|
||||
}
|
||||
|
||||
function getData() {
|
||||
try {
|
||||
if (window.ace_editor) {
|
||||
var data = window.ace_editor.getSession().getValue();
|
||||
} catch(e) {
|
||||
try {
|
||||
var data = eamy.instances[0].getText();
|
||||
} catch(e) {
|
||||
var data = area.textarea.value;
|
||||
}
|
||||
} else if (window.mirror) {
|
||||
var data = window.mirror.getValue();
|
||||
} else if (window.eamy) {
|
||||
var data = window.eamy.instances[0].getText();
|
||||
} else if (window.textarea) {
|
||||
var data = textarea.value;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
function doHighlight(highlight) {
|
||||
try {
|
||||
window.ace_editor.gotoLine(highlight.lineno);
|
||||
} catch(e) {
|
||||
editAreaLoader.setSelectionRange('body', highlight.start, highlight.end);
|
||||
}
|
||||
if (window.ace_editor) {
|
||||
window.ace_editor.gotoLine(highlight.lineno);
|
||||
} else if (window.mirror) {
|
||||
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() {
|
||||
var data = getData();
|
||||
var dataForPost = prepareMultiPartPOST(new Array(
|
||||
prepareDataForSave('data', data),
|
||||
prepareDataForSave('file_hash', 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('file_hash',
|
||||
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('from_ajax','true')));
|
||||
// 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.ajax({
|
||||
type: "POST",
|
||||
contentType: 'multipart/form-data;boundary="' + dataForPost[1] + '"',
|
||||
contentType: 'multipart/form-data;boundary="'
|
||||
+ dataForPost[1] + '"',
|
||||
url: self.location.href,
|
||||
dataType: "json",
|
||||
data: dataForPost[0],
|
||||
timeout: 5000,
|
||||
beforeSend: function(xhr) {
|
||||
xhr.setRequestHeader('web2py-component-location',document.location);
|
||||
xhr.setRequestHeader('web2py-component-element','doClickSave');},
|
||||
xhr.setRequestHeader('web2py-component-location',
|
||||
document.location);
|
||||
xhr.setRequestHeader('web2py-component-element',
|
||||
'doClickSave');
|
||||
},
|
||||
success: function(json,text,xhr){
|
||||
|
||||
// show flash message (if any)
|
||||
var flash=xhr.getResponseHeader('web2py-component-flash');
|
||||
if (flash) jQuery('.flash').html(decodeURIComponent(flash)).slideDown();
|
||||
else jQuery('.flash').hide();
|
||||
if (flash) {
|
||||
var flashhtml = decodeURIComponent(flash);
|
||||
jQuery('.flash').html(flashhtml).slideDown();
|
||||
} else jQuery('.flash').hide();
|
||||
|
||||
// reenable disabled submit button
|
||||
var t=jQuery("input[name='save']");
|
||||
t.attr('class','');
|
||||
t.attr('disabled','');
|
||||
|
||||
try {
|
||||
if (json.error) {
|
||||
window.location.href=json.redirect;
|
||||
} else {
|
||||
// console.info( json.file_hash );
|
||||
jQuery("input[name='file_hash']").val(json.file_hash);
|
||||
jQuery("input[name='saved_on']").val(json.saved_on);
|
||||
if (json.highlight) {
|
||||
doHighlight(json.highlight);
|
||||
} else {
|
||||
jQuery("input[name='saved_on']").attr('style','background-color:#99FF99');
|
||||
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();
|
||||
try {
|
||||
if (json.error) {
|
||||
window.location.href=json.redirect;
|
||||
} else {
|
||||
// console.info( json.file_hash );
|
||||
jQuery("input[name='file_hash']").val(json.file_hash);
|
||||
jQuery("input[name='saved_on']").val(json.saved_on);
|
||||
if (json.highlight) {
|
||||
doHighlight(json.highlight);
|
||||
} else {
|
||||
jQuery("input[name='saved_on']").attr('style','background-color:#99FF99');
|
||||
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();}
|
||||
},
|
||||
error: function(json) { on_error(); }
|
||||
});
|
||||
error: function(json) { on_error(); }
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
function getSelectionRange() {
|
||||
var sel;
|
||||
try {
|
||||
sel = {};
|
||||
if (window.ace_editor) {
|
||||
sel = {};
|
||||
range = window.ace_editor.getSelectionRange();
|
||||
// passing the line number directly, no need to read the text
|
||||
sel['start'] = range.start.row;
|
||||
sel['end'] = range.end.row;
|
||||
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:
|
||||
sel = editAreaLoader.getSelectionRange('body');
|
||||
sel['data'] = getData();
|
||||
@@ -130,7 +149,7 @@ function getSelectionRange() {
|
||||
}
|
||||
|
||||
function doToggleBreakpoint(filename, url) {
|
||||
var sel = getSelectionRange();
|
||||
var sel = getSelectionRange();
|
||||
var dataForPost = prepareMultiPartPOST(new Array(
|
||||
prepareDataForSave('filename', filename),
|
||||
prepareDataForSave('sel_start', sel["start"]),
|
||||
@@ -138,35 +157,34 @@ function doToggleBreakpoint(filename, url) {
|
||||
prepareDataForSave('data', sel['data'])));
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
contentType: 'multipart/form-data;boundary="' + dataForPost[1] + '"',
|
||||
contentType: 'multipart/form-data;boundary="'+dataForPost[1]+'"',
|
||||
url: url,
|
||||
dataType: "json",
|
||||
data: dataForPost[0],
|
||||
timeout: 5000,
|
||||
beforeSend: function(xhr) {
|
||||
xhr.setRequestHeader('web2py-component-location',document.location);
|
||||
xhr.setRequestHeader('web2py-component-element','doSetBreakpoint');},
|
||||
xhr.setRequestHeader('web2py-component-location',
|
||||
document.location);
|
||||
xhr.setRequestHeader('web2py-component-element',
|
||||
'doSetBreakpoint');},
|
||||
success: function(json,text,xhr){
|
||||
|
||||
// show flash message (if any)
|
||||
var flash=xhr.getResponseHeader('web2py-component-flash');
|
||||
if (flash) jQuery('.flash').html(decodeURIComponent(flash)).slideDown();
|
||||
else jQuery('.flash').hide();
|
||||
try {
|
||||
if (json.error) {
|
||||
window.location.href=json.redirect;
|
||||
} else {
|
||||
// mark the breakpoint if ok=True, remove mark if ok=False
|
||||
// do nothing if ok = null
|
||||
// alert(json.ok + json.lineno);
|
||||
}
|
||||
} catch(e) {
|
||||
on_error();
|
||||
}
|
||||
|
||||
// show flash message (if any)
|
||||
var flash=xhr.getResponseHeader('web2py-component-flash');
|
||||
if (flash) jQuery('.flash').html(decodeURIComponent(flash)).slideDown();
|
||||
else jQuery('.flash').hide();
|
||||
try {
|
||||
if (json.error) {
|
||||
window.location.href=json.redirect;
|
||||
} else {
|
||||
// mark the breakpoint if ok=True
|
||||
// remove mark if ok=False
|
||||
// do nothing if ok = null
|
||||
// alert(json.ok + json.lineno);
|
||||
}
|
||||
} catch(e) { on_error(); }
|
||||
},
|
||||
error: function(json) { on_error(); }
|
||||
});
|
||||
error: function(json) { on_error(); }
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,10 +17,7 @@
|
||||
<script src="{{=cm}}/mode/css/css.js"></script>
|
||||
<script src="{{=cm}}/mode/javascript/javascript.js"></script>
|
||||
<script src="{{=cm}}/mode/htmlmixed/htmlmixed.js"></script>
|
||||
<!-- note to self:
|
||||
for this to be able to save, it requires ajax_editor.js
|
||||
but ajax_editor only works for ace because debugger breakpoints
|
||||
//-->
|
||||
<script language="Javascript" type="text/javascript" src="{{=URL('static','js/ajax_editor.js')}}"></script>
|
||||
{{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/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"/>
|
||||
<br><hr>
|
||||
{{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>
|
||||
<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)}}
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("body"),
|
||||
@@ -137,10 +135,11 @@ jQuery(document).ready(function(){
|
||||
lineNumbers: true,
|
||||
indentUnit: 4,
|
||||
tabMode: "shift",
|
||||
saveFunction: function() { doClickSave(); },
|
||||
extraKeys: { "Ctrl-S": function(instance) {doClickSave();} },
|
||||
{{if TEXT_EDITOR_KEYBINDING == 'emacs':}}keyMap: "emacs",{{pass}}
|
||||
matchBrackets: true
|
||||
});
|
||||
window.mirror = editor;
|
||||
</script>
|
||||
{{elif TEXT_EDITOR == 'ace':}}
|
||||
<div id="editor" style="height: 500px; width: auto; position: relative">{{=data}}</div>
|
||||
@@ -166,9 +165,9 @@ window.onload = function() {
|
||||
window.ace_editor = editor;
|
||||
};
|
||||
</script>
|
||||
|
||||
{{else:}}
|
||||
<textarea cols="80" rows="25" id="body" style="direction:ltr;" name="data">{{=data}}</textarea>
|
||||
<script>window.textarea = area.textarea;</script>
|
||||
{{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>
|
||||
{{=T('to previous version.')}}
|
||||
|
||||
Reference in New Issue
Block a user