From 9b4888e6d73c3437c486cc9d13a19b5defcfbf50 Mon Sep 17 00:00:00 2001 From: ilvalle Date: Mon, 27 May 2013 16:30:27 +0200 Subject: [PATCH 1/4] initial import for tabs in the online editor --- applications/admin/controllers/default.py | 43 +- applications/admin/static/js/ajax_editor.js | 77 +++- applications/admin/views/default/edit.html | 399 +++++------------- applications/admin/views/default/edit_js.html | 116 +++++ 4 files changed, 311 insertions(+), 324 deletions(-) create mode 100644 applications/admin/views/default/edit_js.html diff --git a/applications/admin/controllers/default.py b/applications/admin/controllers/default.py index 7f8106d9..35a14530 100644 --- a/applications/admin/controllers/default.py +++ b/applications/admin/controllers/default.py @@ -586,6 +586,24 @@ def edit(): """ File edit handler """ # Load json only if it is ajax edited... app = get_app(request.vars.app) + + if not(request.ajax): + # return the scaffolding, the rest will be through ajax requests + response.title = T('Editing %s' % app) + editarea_preferences = {} + editarea_preferences['FONT_SIZE'] = '10' + editarea_preferences['FULL_SCREEN'] = 'false' + editarea_preferences['ALLOW_TOGGLE'] = 'true' + editarea_preferences['REPLACE_TAB_BY_SPACES'] = '4' + editarea_preferences['DISPLAY'] = 'onload' + 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)) + + """ File edit handler """ + # Load json only if it is ajax edited... + app = get_app(request.vars.app) filename = '/'.join(request.args) response.title = request.args[-1] if request.vars.app: @@ -708,7 +726,7 @@ def edit(): cfilename = os.path.join(request.args[0], 'controllers', request.args[2] + '.py') if os.path.exists(apath(cfilename, r=request)): - edit_controller = URL('edit',args=[cfilename.replace(os.sep, "/")]) + edit_controller = URL('edit', args=[cfilename.replace(os.sep, "/")]) view = request.args[3].replace('.html', '') view_link = URL(request.args[0], request.args[2], view) elif filetype == 'python' and request.args[1] == 'controllers': @@ -730,6 +748,7 @@ def edit(): vf = os.path.split(v)[-1] vargs = "/".join([viewpath.replace(os.sep, "/"), vf]) editviewlinks.append(A(vf.split(".")[0], + _class="editor_filelink", _href=URL('edit', args=[vargs]))) if len(request.args) > 2 and request.args[1] == 'controllers': @@ -741,17 +760,7 @@ def edit(): if 'from_ajax' in request.vars: return response.json({'file_hash': file_hash, 'saved_on': saved_on, 'functions': functions, 'controller': controller, 'application': request.args[0], 'highlight': highlight}) else: - - editarea_preferences = {} - editarea_preferences['FONT_SIZE'] = '10' - editarea_preferences['FULL_SCREEN'] = 'false' - editarea_preferences['ALLOW_TOGGLE'] = 'true' - editarea_preferences['REPLACE_TAB_BY_SPACES'] = '4' - editarea_preferences['DISPLAY'] = 'onload' - for key in editarea_preferences: - if key in globals(): - editarea_preferences[key] = globals()[key] - return dict(app=request.args[0], + file_details = dict(app=request.args[0], filename=filename, filetype=filetype, data=data, @@ -761,9 +770,13 @@ def edit(): controller=controller, functions=functions, view_link=view_link, - editarea_preferences=editarea_preferences, - editviewlinks=editviewlinks) - + editviewlinks=editviewlinks, + id=IS_SLUG()(filename)[0], + force= True if (request.vars.restore or request.vars.revert) else False) + plain_html = response.render('default/edit_js.html', file_details) + file_details['plain_html'] = plain_html + return response.json(file_details) + def resolve(): """ diff --git a/applications/admin/static/js/ajax_editor.js b/applications/admin/static/js/ajax_editor.js index 168236d4..a406ba8a 100644 --- a/applications/admin/static/js/ajax_editor.js +++ b/applications/admin/static/js/ajax_editor.js @@ -54,25 +54,28 @@ function doHighlight(highlight) { } function doClickSave() { - var data = getData(); + var currentTabID = '#' + jQuery('#edit_placeholder div.tab-pane.active').attr('id'); + var editor = jQuery (currentTabID + ' textarea').data('editor'); + var data = editor.getValue(); var dataForPost = prepareMultiPartPOST(new Array( prepareDataForSave('data', data), prepareDataForSave('file_hash', - jQuery("input[name='file_hash']").val()), + jQuery(currentTabID + " input[name='file_hash']").val()), prepareDataForSave('saved_on', - jQuery("input[name='saved_on']").val()), + jQuery(currentTabID + " input[name='saved_on']").val()), prepareDataForSave('saved_on', - jQuery("input[name='saved_on']").val()), + jQuery(currentTabID + " input[name='saved_on']").val()), prepareDataForSave('from_ajax','true'))); // console.info(area.textarea.value); - jQuery("input[name='saved_on']").attr('style', + jQuery(currentTabID + " input[name='saved_on']").attr('style', 'background-color:yellow'); - jQuery("input[name='saved_on']").val('saving now...') + jQuery(currentTabID + " input[name='saved_on']").val('saving now...') + currentUrl = jQuery(currentTabID + ' form').attr('action'); jQuery.ajax({ type: "POST", contentType: 'multipart/form-data;boundary="' + dataForPost[1] + '"', - url: self.location.href, + url: currentUrl, dataType: "json", data: dataForPost[0], timeout: 5000, @@ -100,12 +103,12 @@ function doClickSave() { 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); + jQuery(currentTabID + " input[name='file_hash']").val(json.file_hash); + jQuery(currentTabID + " 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(currentTabID + " input[name='saved_on']").attr('style','background-color:#99FF99'); //jQuery(".flash").delay(1000).fadeOut('slow'); } // console.info(jQuery("input[name='file_hash']").val()); @@ -134,10 +137,12 @@ function getSelectionRange() { sel['end'] = range.end.row; sel['data'] = ''; } else if (window.mirror) { - sel = {}; - sel['start'] = window.mirror.getCursor(true).line; - sel['end'] = window.mirror.getCursor(false).line; - sel['data'] = ''; + var currentTabID = '#' + jQuery('#edit_placeholder div.tab-pane.active').attr('id'); + var editor = jQuery (currentTabID + ' textarea').data('editor'); + sel = {}; + sel['start'] = editor.getCursor(true).line; + sel['end'] = editor.getCursor(false).line; + sel['data'] = ''; } else if (window.eamy) { sel = {}; // not implemented @@ -150,6 +155,9 @@ function getSelectionRange() { } function doToggleBreakpoint(filename, url, sel) { + var currentTabID = '#' + jQuery('#edit_placeholder div.tab-pane.active').attr('id'); + var editor = jQuery (currentTabID + ' textarea').data('editor'); + if (sel==null) { // use cursor position to determine the breakpoint line // (gutter already tell us the selected line) @@ -222,16 +230,17 @@ function doListBreakpoints(filename, url) { xhr.setRequestHeader('web2py-component-element', 'doListBreakpoints');}, success: function(json,text,xhr){ - try { - if (json.error) { - window.location.href=json.redirect; - } else { - if (window.mirror) { + try { + if (json.error) { + window.location.href=json.redirect; + } else { + var currentTabID = '#' + jQuery('#edit_placeholder div.tab-pane.active').attr('id'); + var editor = jQuery (currentTabID + ' textarea').data('editor'); + if (window.mirror) { for (i in json.breakpoints) { lineno = json.breakpoints[i]; // mark the breakpoint if ok=True - editor.setMarker(lineno-1, - " %N%"); + editor.setMarker(lineno-1, " %N%"); } } } @@ -250,3 +259,29 @@ function keepalive(url) { success: function(){}, error: function(x) { on_error(); } }); } + +function load_file (url) { + jQuery.ajax({ + type: "GET", + dataType: 'json', + url: url, + timeout: 1000, + success: function(json){ + if (typeof(json['plain_html']) !== undefined) { + if (jQuery('#' + json['id']).length === 0 || json['force'] === true) { + // Create a tab and put the code in it + var tab_header = '
  • filenameDefault
  • '.replace(/idDefault/, json['id']).replace(/filenameDefault/, json['filename'] ); + var tab_body = '
    htmlDefault
    '.replace(/htmlDefault/, json['plain_html']).replace(/idDefault/, json['id']); + if (json['force'] === false) { + jQuery('#filesTab').append(jQuery(tab_header)); + jQuery('#myTabContent').append(jQuery(tab_body)); + } else { + jQuery('#' + json['id']).html(jQuery(tab_body)); + } + } + jQuery("a[href='#" + json['id'] + "']" ).click(); + } + }, + error: function(x) { on_error(); } + }); +} diff --git a/applications/admin/views/default/edit.html b/applications/admin/views/default/edit.html index a3ed3eff..de6d6720 100644 --- a/applications/admin/views/default/edit.html +++ b/applications/admin/views/default/edit.html @@ -10,13 +10,10 @@ return files def editfile(path,file,vars={}): - args=(path,file) if 'app' in vars else (app,path,file) - return A(file, _class='', _href=URL('edit', args=args, vars=vars), _style='word-wrap: break-word;') - + args=(path,file) if 'app' in vars else (app,path,file) + url = URL('edit', args=args, vars=vars) + return A(file, _class='editor_filelink', _href=url, _style='word-wrap: break-word;') }} -{{if TEXT_EDITOR == 'amy':}} -{{include 'default/amy_ajax.html'}} -{{elif TEXT_EDITOR == 'codemirror':}} {{cm=URL('static','codemirror')}} @@ -37,306 +34,132 @@ -{{elif TEXT_EDITOR == 'ace':}} - - - - {{if filetype == 'python':}} - - - {{elif filetype in ('html', 'load'):}} - - - {{elif filetype == 'js':}} - - - {{elif filetype == 'css':}} - - - {{else:}} - - - {{pass}} - {{if TEXT_EDITOR_KEYBINDING == 'emacs':}} - - - {{elif TEXT_EDITOR_KEYBINDING == 'vi':}} - - - {{else:}} - - {{pass}} - -{{else:}} - - - -{{pass}} {{block sectionclass}}edit{{end}} -

    {{=T('Editing file "%s"',filename)}}

    -{{if functions:}} -

    - - {{=B(T('exposes:'))}} {{=XML(', '.join([A(f,_href=URL(a=app,c=controller,f=f)).xml() for f in functions]))}} - - {{if editviewlinks:}}
    - {{=B(T('edit views:'))}} - {{=XML(', '.join([v.xml() for v in editviewlinks]))}} - {{pass}} -

    -{{pass}}

    - {{if filetype=='python':}} - {{=A(SPAN(T('toggle breakpoint')), - _value="breakpoint", _name="breakpoint", - _onclick="return doToggleBreakpoint('%s','%s://%s%s',null);" % (filename, - request.env['wsgi_url_scheme'], request.env['http_host'], - URL(c='debug', f='toggle_breakpoint')), - _class="button special btn btn-inverse")}} - {{pass}} {{=button(URL('design',args=request.vars.app if request.vars.app else request.args[0], anchor=request.vars.id), T('back'))}} - {{if edit_controller:}} - {{=button(edit_controller, T('edit controller'))}} - {{pass}} - {{if view_link:}} - {{=button(view_link, T('try view'))}} - {{pass}} - {{if request.args[1]=='models':}} + {{#if request.args[1]=='models':}} {{=T('online designer')}} - {{pass}} + {{#pass}} {{=T('docs')}}

    - - - -
    - -
    -
    -
    - - -
    -
    - - -
    -
    -
    - {{if TEXT_EDITOR == 'amy':}} - - - {{elif TEXT_EDITOR == 'codemirror':}} - - - {{elif TEXT_EDITOR == 'ace':}} -
    {{=data}}
    - - {{else:}} - - - {{pass}} -
    - - {{=T('currently saved or')}} - - {{=T('to previous version.')}} -
    -
    -
    -
    - -
    -
    - {{if TEXT_EDITOR=='edit_area' and filetype=='html':}} -

    {{=T('Key bindings for ZenCoding Plugin')}}

    -
      - {{=shortcut('Ctrl+S', T('Save via Ajax'))}} - {{=shortcut('Ctrl+,', T('Expand Abbreviation'))}} - {{=shortcut('Ctrl+M', T('Match Pair'))}} - {{=shortcut('Ctrl+H', T('Wrap with Abbreviation'))}} - {{=shortcut('Shift+Ctrl+M', T('Merge Lines'))}} - {{=shortcut('Ctrl+Shift+←', T('Previous Edit Point'))}} - {{=shortcut('Ctrl+Shift+→', T('Next Edit Point'))}} - {{=shortcut('Ctrl+Shift+↑', T('Go to Matching Pair'))}} -
    - {{elif TEXT_EDITOR == 'codemirror' and filetype=='html':}} -

    {{=T('Key bindings for ZenCoding Plugin')}}

    -
      - {{=shortcut('Ctrl+S', T('Save via Ajax'))}} - {{=shortcut('Ctrl+F11', T('Toggle Fullscreen'))}} - {{=shortcut('Ctrl-F / Cmd-F', T('Start searching'))}} - {{=shortcut('Ctrl-G / Cmd-G', T('Find Next'))}} - {{=shortcut('Shift-Ctrl-G / Shift-Cmd-G', T('Find Previous'))}} - {{=shortcut('Shift-Ctrl-F / Cmd-Option-F', T('Replace'))}} - {{=shortcut('Shift-Ctrl-R / Shift-Cmd-Option-F', T('Replace All'))}} - {{=shortcut('Tab', T('Expand Abbreviation'))}} -
    - {{elif TEXT_EDITOR == 'codemirror':}} -

    {{=T("Key bindings")}}

    -
      - {{=shortcut('Ctrl+S', T('Save via Ajax'))}} - {{=shortcut('Ctrl+F11', T('Toggle Fullscreen'))}} - {{=shortcut('Ctrl-F / Cmd-F', T('Start searching'))}} - {{=shortcut('Ctrl-G / Cmd-G', T('Find Next'))}} - {{=shortcut('Shift-Ctrl-G / Shift-Cmd-G', T('Find Previous'))}} - {{=shortcut('Shift-Ctrl-F / Cmd-Option-F', T('Replace'))}} - {{=shortcut('Shift-Ctrl-R / Shift-Cmd-Option-F', T('Replace All'))}} -
    - {{else:}} -

    {{=T("Key bindings")}}

    -
      - {{=shortcut('Ctrl+S', T('Save via Ajax'))}} -
    + +
    + +
    +
    diff --git a/applications/admin/views/default/edit_js.html b/applications/admin/views/default/edit_js.html new file mode 100644 index 00000000..b4d99ff6 --- /dev/null +++ b/applications/admin/views/default/edit_js.html @@ -0,0 +1,116 @@ +{{def shortcut(combo, description): + return XML('
  • %s%s
  • ' % (combo, description)) + +##TODO +#eseguire dolistbreakpoint ogni volta che si fa una load +}} + +
    +
    + + {{=IMG(_src=URL('static', 'images/save_icon.png'), _alt=T('Save'))}} + + + + +{{if filetype=='python':}} + {{=A(SPAN(T('toggle breakpoint')), + _value="breakpoint", _name="breakpoint", + _onclick="return doToggleBreakpoint('%s','%s://%s%s',null);" % (filename, + request.env['wsgi_url_scheme'], request.env['http_host'], + URL(c='debug', f='toggle_breakpoint')), + _class="button special btn btn-inverse")}} +{{pass}} +{{if view_link:}} + {{=button(view_link, T('try view'))}} +{{pass}} +

    +{{if functions:}} + + {{=B(T('exposes:'))}} {{=XML(', '.join([A(f,_target="_blank", _href=URL(a=app,c=controller,f=f)).xml() for f in functions]))}} + +{{if editviewlinks:}}
    + {{=B(T('edit views:'))}} + {{=XML(', '.join([v.xml() for v in editviewlinks]))}} +{{pass}} +{{pass}} +{{if edit_controller:}} + {{=B(T('edit controller:'))}} + {{=A(request.args[2]+'.py', _class="editor_filelink", _target="_blank", _href=edit_controller)}} +{{pass}} +

    +
    + + + + +
    + {{=T('restore')}} + {{=T('currently saved or')}} + {{=T('revert')}} + {{=T('to previous version.')}} +
    +
    +
    + +
    +
    + {{if TEXT_EDITOR == 'codemirror' and filetype=='html':}} +

    {{=T('Key bindings for ZenCoding Plugin')}}

    +
      + {{=shortcut('Ctrl+S', T('Save via Ajax'))}} + {{=shortcut('Ctrl+F11', T('Toggle Fullscreen'))}} + {{=shortcut('Ctrl-F / Cmd-F', T('Start searching'))}} + {{=shortcut('Ctrl-G / Cmd-G', T('Find Next'))}} + {{=shortcut('Shift-Ctrl-G / Shift-Cmd-G', T('Find Previous'))}} + {{=shortcut('Shift-Ctrl-F / Cmd-Option-F', T('Replace'))}} + {{=shortcut('Shift-Ctrl-R / Shift-Cmd-Option-F', T('Replace All'))}} + {{=shortcut('Tab', T('Expand Abbreviation'))}} +
    + {{elif TEXT_EDITOR == 'codemirror':}} +

    {{=T("Key bindings")}}

    +
      + {{=shortcut('Ctrl+S', T('Save via Ajax'))}} + {{=shortcut('Ctrl+F11', T('Toggle Fullscreen'))}} + {{=shortcut('Ctrl-F / Cmd-F', T('Start searching'))}} + {{=shortcut('Ctrl-G / Cmd-G', T('Find Next'))}} + {{=shortcut('Shift-Ctrl-G / Shift-Cmd-G', T('Find Previous'))}} + {{=shortcut('Shift-Ctrl-F / Cmd-Option-F', T('Replace'))}} + {{=shortcut('Shift-Ctrl-R / Shift-Cmd-Option-F', T('Replace All'))}} +
    + {{pass}} +
    +
    From ad718b48e81c40179bfb95b2277a1bd4ef79339b Mon Sep 17 00:00:00 2001 From: ilvalle Date: Tue, 28 May 2013 14:34:01 +0200 Subject: [PATCH 2/4] code cleanup (to remove the code of former editors) fix breakpoints integration --- applications/admin/static/js/ajax_editor.js | 128 ++++++------------ applications/admin/views/default/edit.html | 12 +- applications/admin/views/default/edit_js.html | 10 +- 3 files changed, 48 insertions(+), 102 deletions(-) diff --git a/applications/admin/static/js/ajax_editor.js b/applications/admin/static/js/ajax_editor.js index a406ba8a..66aeba5a 100644 --- a/applications/admin/static/js/ajax_editor.js +++ b/applications/admin/static/js/ajax_editor.js @@ -11,12 +11,12 @@ function prepareMultiPartPOST(data) { var reqdata = '--' + boundary + '\r\n'; //console.log(data.length); 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'; + 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); } @@ -26,37 +26,10 @@ function on_error() { jQuery("input[name='saved_on']").val('communication error'); } -function getData() { - if (window.ace_editor) { - var data = window.ace_editor.getSession().getValue(); - } 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) { - if (window.ace_editor) { - window.ace_editor.gotoLine(highlight.lineno); - } else if (window.mirror) { - // Put the cursor at the offending line: - window.mirror.setCursor({line:highlight.lineno-1, - ch:highlight.offset+1}); - } else if (window.eamy) { - // not implemented - } else if (window.textarea) { - editAreaLoader.setSelectionRange('body', highlight.start, highlight.end); - } -} - function doClickSave() { var currentTabID = '#' + jQuery('#edit_placeholder div.tab-pane.active').attr('id'); - var editor = jQuery (currentTabID + ' textarea').data('editor'); - var data = editor.getValue(); + var editor = jQuery (currentTabID + ' textarea').data('editor'); + var data = editor.getValue(); var dataForPost = prepareMultiPartPOST(new Array( prepareDataForSave('data', data), prepareDataForSave('file_hash', @@ -87,12 +60,7 @@ function doClickSave() { }, success: function(json,text,xhr){ - // show flash message (if any) - var flash=xhr.getResponseHeader('web2py-component-flash'); - 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']"); @@ -100,24 +68,25 @@ function doClickSave() { t.attr('disabled',''); try { if (json.error) { - window.location.href=json.redirect; + window.location.href=json.redirect; } else { // console.info( json.file_hash ); jQuery(currentTabID + " input[name='file_hash']").val(json.file_hash); jQuery(currentTabID + " input[name='saved_on']").val(json.saved_on); if (json.highlight) { - doHighlight(json.highlight); + // Put the cursor at the offending line: + editor.setCursor({line:highlight.lineno-1, ch:highlight.offset+1}); } else { - jQuery(currentTabID + " input[name='saved_on']").attr('style','background-color:#99FF99'); + jQuery(currentTabID + " 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] + ','; + output += ' ' + json.functions[i] + ','; } if(output!='exposes: ') { - jQuery("#exposed").html( output.substring(0, output.length-1)); + jQuery(currentTabID + " .exposed").html( output.substring(0, output.length-1)); } } } catch(e) { on_error();} @@ -127,37 +96,22 @@ function doClickSave() { return false; } -function getSelectionRange() { - var 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'] = ''; - } else if (window.mirror) { - var currentTabID = '#' + jQuery('#edit_placeholder div.tab-pane.active').attr('id'); - var editor = jQuery (currentTabID + ' textarea').data('editor'); - sel = {}; - sel['start'] = editor.getCursor(true).line; - sel['end'] = editor.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(); - } - return sel; -} - -function doToggleBreakpoint(filename, url, sel) { +function getActiveEditor() { var currentTabID = '#' + jQuery('#edit_placeholder div.tab-pane.active').attr('id'); var editor = jQuery (currentTabID + ' textarea').data('editor'); + return editor; +} +function getSelectionRange() { + var editor = getActiveEditor(); + var sel = {}; + sel['start'] = editor.getCursor(true).line; + sel['end'] = editor.getCursor(false).line; + sel['data'] = ''; + return sel; +} + +function doToggleBreakpoint(filename, url, sel, editor) { if (sel==null) { // use cursor position to determine the breakpoint line // (gutter already tell us the selected line) @@ -193,17 +147,14 @@ function doToggleBreakpoint(filename, url, sel) { if (json.error) { window.location.href=json.redirect; } else { - if (json.ok==true && window.mirror) { + if (json.ok==true) { // mark the breakpoint if ok=True editor.setMarker(json.lineno-1, " %N%") - } else if (json.ok==false && window.mirror) { + } else if (json.ok==false) { // remove mark if ok=False editor.setMarker(json.lineno-1, "%N%") - } else { - // do nothing if ok = null - } - // alert(json.ok + json.lineno); + } } } catch(e) { on_error(); } }, @@ -234,16 +185,13 @@ function doListBreakpoints(filename, url) { if (json.error) { window.location.href=json.redirect; } else { - var currentTabID = '#' + jQuery('#edit_placeholder div.tab-pane.active').attr('id'); - var editor = jQuery (currentTabID + ' textarea').data('editor'); - if (window.mirror) { - for (i in json.breakpoints) { - lineno = json.breakpoints[i]; - // mark the breakpoint if ok=True - editor.setMarker(lineno-1, " %N%"); - } - } - } + var editor = getActiveEditor(); + for (i in json.breakpoints) { + lineno = json.breakpoints[i]; + // mark the breakpoint if ok=True + editor.setMarker(lineno-1, " %N%"); + } + } } catch(e) { on_error(); } }, error: function(json) { on_error(); } diff --git a/applications/admin/views/default/edit.html b/applications/admin/views/default/edit.html index de6d6720..8a62106d 100644 --- a/applications/admin/views/default/edit.html +++ b/applications/admin/views/default/edit.html @@ -33,17 +33,14 @@
    From c741fc4a6b368a4f0e883fb7a56830f73985bbae Mon Sep 17 00:00:00 2001 From: ilvalle Date: Tue, 28 May 2013 16:29:48 +0200 Subject: [PATCH 3/4] fix breakpoint --- applications/admin/static/js/ajax_editor.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/applications/admin/static/js/ajax_editor.js b/applications/admin/static/js/ajax_editor.js index 66aeba5a..7b123268 100644 --- a/applications/admin/static/js/ajax_editor.js +++ b/applications/admin/static/js/ajax_editor.js @@ -111,7 +111,8 @@ function getSelectionRange() { return sel; } -function doToggleBreakpoint(filename, url, sel, editor) { +function doToggleBreakpoint(filename, url, sel) { + var editor = getActiveEditor(); if (sel==null) { // use cursor position to determine the breakpoint line // (gutter already tell us the selected line) @@ -164,7 +165,7 @@ function doToggleBreakpoint(filename, url, sel, editor) { } // on load, update all breakpoints markers: -function doListBreakpoints(filename, url) { +function doListBreakpoints(filename, url, editor) { var dataForPost = prepareMultiPartPOST(new Array( prepareDataForSave('filename', filename) )); From 131eda75a6fc7734d0259fd0f4efb366d91c7e8f Mon Sep 17 00:00:00 2001 From: ilvalle Date: Tue, 4 Jun 2013 10:08:50 +0200 Subject: [PATCH 4/4] theme selector (js part) --- applications/admin/views/default/edit.html | 33 ++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/applications/admin/views/default/edit.html b/applications/admin/views/default/edit.html index 8a62106d..882284ec 100644 --- a/applications/admin/views/default/edit.html +++ b/applications/admin/views/default/edit.html @@ -74,6 +74,26 @@ jQuery(document).on('click', 'a.editor_filelink', function (e) { 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.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); +//#TODO save on session +}); + function isFullScreen(instance) { return /\bCodeMirror-fullscreen\b/.test(instance.getWrapperElement().className); } @@ -121,13 +141,22 @@ jQuery(document).on('click', 'a.editor_filelink', function (e) {
    -

    +

    + {{=button(URL('design',args=request.vars.app if request.vars.app else request.args[0], anchor=request.vars.id), T('back'))}} {{#if request.args[1]=='models':}} {{=T('online designer')}} {{#pass}} {{=T('docs')}} -

    + +