diff --git a/VERSION b/VERSION index 5ff93dea..128b466d 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 2.0.8 (2012-09-08 22:22:02) stable +Version 2.0.8 (2012-09-08 23:22:37) stable diff --git a/applications/admin/models/0.py b/applications/admin/models/0.py index 160118cf..4ac46f71 100644 --- a/applications/admin/models/0.py +++ b/applications/admin/models/0.py @@ -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", diff --git a/applications/admin/static/js/ajax_editor.js b/applications/admin/static/js/ajax_editor.js index 4edbfd24..cd7923eb 100644 --- a/applications/admin/static/js/ajax_editor.js +++ b/applications/admin/static/js/ajax_editor.js @@ -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 = 'exposes: '; - for ( var i in json.functions) { - output += ' ' + json.functions[i] + ','; - } - if(output!='exposes: ') { - 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 = 'exposes: '; + for ( var i in json.functions) { + output += ' ' + json.functions[i] + ','; + } + if(output!='exposes: ') { + 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; } diff --git a/applications/admin/views/default/edit.html b/applications/admin/views/default/edit.html index 1977b683..ee9426b5 100644 --- a/applications/admin/views/default/edit.html +++ b/applications/admin/views/default/edit.html @@ -17,10 +17,7 @@ - + {{elif TEXT_EDITOR == 'ace':}} @@ -127,9 +124,10 @@ jQuery(document).ready(function(){ {{=T('Last saved on:')}}

{{if TEXT_EDITOR == 'amy':}} - - {{elif TEXT_EDITOR == 'codemirror':}} + + {{elif TEXT_EDITOR == 'codemirror':}} + {{cm_mode = {'html':'htmlmixed'}.get(filetype,filetype)}} {{elif TEXT_EDITOR == 'ace':}}
{{=data}}
@@ -166,9 +165,9 @@ window.onload = function() { window.ace_editor = editor; }; - {{else:}} + {{pass}} {{=T('currently saved or')}} {{=T('to previous version.')}}