Changed files:
web2py/applications/admin/controllers/default.py
web2py/applications/admin/static/ajax_editor.js
web2py/applications/admin/views/default/edit.html
web2py/applications/admin/views/layout.html
web2py/applications/admin/views/web2py_ajax.html
this time patch is more intrusive than from last time, because i had to
change html layout to make "flash" field available.
Still missing part is relogin but this time this is just response to your
request :)
I don't know why it does not work from konqueror as jquery should be
portable that much?
Anyway for now this is MozillaFirefox only untill I found out what is not
working in my JavaScript code :-\
On Mon, Feb 23, 2009 at 7:52 PM, Boris Manojlovic <
[email protected]> wrote:
> will try to do it asap :)
> only missing will be "relogin" as i still didn't look into session issue.
> You would have to open new window(tab) and login there untill i find some
> nice solution for session timeout.
>
>
> On Mon, Feb 23, 2009 at 7:16 PM, mdipierro <[email protected]>wrote:
>
>>
>> ok but can you send me a patch that does 1,2,3?
>>
>> On Feb 23, 9:59 am, Boris Manojlovic <[email protected]>
>> wrote:
>> > hello,
>> > 1) what exactly you need is very simple to achive as putting with JS
>> value
>> > into some <div> (or I'm missing your point, which i think is case here)
>> > 2) this is done already trough javascript (ajax_editor.js) as that was
>> > needed for successful "save" functionality (or resolve redirect is
>> received
>> > if it is not sent)
>> > 3) that is still to be done on client side - server side is same (and
>> > implemented) code as it was before for /edit/ control,JSON should
>> contain
>> > standard errors you receive by HTML as you can see in patch
>> >
>> >
>> >
>> > On Mon, Feb 23, 2009 at 4:41 AM, mdipierro <[email protected]>
>> wrote:
>> >
>> > > Boris. I really like this but we need
>> >
>> > > 1) make hash value visible and readonly
>> > > 2) return the same when it was saved as well
>> > > 3) some kind of notification (possibly in the form of flash) that
>> > > informs the user if the file was saved or not.
>> >
>> > > Massimo
>> >
>> > > On Feb 22, 12:43 pm, Boris Manojlovic <[email protected]>
>> > > wrote:
>> > > > Please try this patch last one was non working...
>> >
>> > > > On Sun, Feb 22, 2009 at 7:16 PM, Boris Manojlovic <
>> >
>> > > > [email protected]> wrote:
>> > > > > Hello to All,
>> >
>> > > > > i have started to work on something called "ajax" code editor.
>> > > > > What exactly does it mean?
>> >
>> > > > > 1. No need for reloads on editor page (just think about undo
>> redo in
>> > > > > editor window)
>> > > > > 2. No "terrible loss of code" if you are logged out
>> (application
>> > > > > timeout... with that "great" redirect to login page...)
>> > > > > 3. speed gain
>> >
>> > > > > Current implementation has "save" functionality only and it works
>> just
>> > > from
>> > > > > firefox (konqueror ignores my jquery code and same for opera...).
>> > > > > Most coding as it would be expected should (and is) done on client
>> side
>> > > and
>> > > > > will degrade depending if user use javascript at all - no script
>> no
>> > > ajax
>> > > > > anyway.
>> > > > > All messages in current stage are json passed to client.
>> > > > > Patch against latest SVN from google code
>> >
>> > > > > P.S. Comments welcome and needed (to continue on this idea or not)
>> > > > > --
>> > > > > "Only two things are infinite, the universe and human stupidity,
>> and
>> > > I'm
>> > > > > not sure about the former."-Albert Einstein
>> >
>> > > > --
>> > > > "Only two things are infinite, the universe and human stupidity, and
>> I'm
>> > > not
>> > > > sure about the former."-Albert Einstein
>> >
>> > > > ajax_editor.patch
>> > > > 7KViewDownload
>> >
>> > --
>> > "Only two things are infinite, the universe and human stupidity, and I'm
>> not
>> > sure about the former."-Albert Einstein
>> >>
>>
>
>
> --
> "Only two things are infinite, the universe and human stupidity, and I'm
> not sure about the former."-Albert Einstein
>
--
"Only two things are infinite, the universe and human stupidity, and I'm not
sure about the former."-Albert Einstein
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---
--- web2py_orig/applications/admin/controllers/default.py 2009-02-22 02:22:10.000000000 +0100
+++ web2py/applications/admin/controllers/default.py 2009-02-23 20:55:08.000000000 +0100
@@ -425,6 +425,9 @@
def edit():
""" File edit handler """
+ # Load json only if it is ajax edited...
+ if request.vars.has_key('from_ajax'):
+ import gluon.contrib.simplejson as json
filename = '/'.join(request.args)
@@ -450,7 +453,10 @@
data1 = open(path, 'r').read()
except IOError:
session.flash = 'Invalid action'
- redirect(URL(r=request, f='site'))
+ if request.vars.has_key('from_ajax'):
+ return json.dumps({'error': 'Invalid action'})
+ else:
+ redirect(URL(r=request, f='site'))
file_hash = md5_hash(data)
open(path, 'w').write(data)
@@ -461,7 +467,10 @@
data = open(path, 'r').read()
except IOError:
session.flash = 'Invalid action'
- redirect(URL(r=request, f='site'))
+ if request.vars.has_key('from_ajax'):
+ return json.dumps({'error': 'Invalid action'})
+ else:
+ redirect(URL(r=request, f='site'))
file_hash = md5_hash(data)
@@ -469,7 +478,11 @@
session.flash = T('file changed on disk')
data = request.vars.data.replace('\r\n', '\n').strip() + '\n'
open(path + '.1', 'w').write(data)
- redirect(URL(r=request, f='resolve', args=request.args))
+ if request.vars.has_key('from_ajax'):
+ #return json.dumps({'error': session.flash, 'resolve': 'true'})
+ return json.dumps({'error': 'file changed on disk', 'resolve': 'true'})
+ else:
+ redirect(URL(r=request, f='resolve', args=request.args))
elif request.vars.data:
open(path + '.bak', 'w').write(data)
data = request.vars.data.replace('\r\n', '\n').strip() + '\n'
@@ -504,15 +517,18 @@
else:
(controller, functions) = (None, None)
- return dict(app=request.args[0],
- filename=filename,
- filetype=filetype,
- data=data,
- edit_controller=edit_controller,
- file_hash=file_hash,
- controller=controller,
- functions=functions)
-
+ if request.vars.has_key('from_ajax'):
+ return json.dumps({'file_hash': file_hash,'error' :''})
+ #return response.json(file_hash) # maybe?
+ else:
+ return dict(app=request.args[0],
+ filename=filename,
+ filetype=filetype,
+ data=data,
+ edit_controller=edit_controller,
+ file_hash=file_hash,
+ controller=controller,
+ functions=functions)
def resolve():
""" """
--- web2py_orig/applications/admin/static/ajax_editor.js 1970-01-01 01:00:00.000000000 +0100
+++ web2py/applications/admin/static/ajax_editor.js 2009-02-23 21:09:40.000000000 +0100
@@ -0,0 +1,53 @@
+function prepareDataForSave(name,data) {
+ var obj = new Object();
+ obj.Name = name;
+ obj.Data = data;
+ return obj;
+}
+
+function prepareMultiPartPOST(data) {
+ var boundary = 'sPlItME' + Math.floor(Math.random()*10000);
+ var reqdata = '--' + boundary;
+ //console.log(data.length);
+ for (var i=0;i < data.length;i++)
+ {
+ reqdata += "\r\n" ;
+ reqdata += 'content-disposition: form-data; name="' + data[i].Name + '"';
+ reqdata += "\r\n" ;
+ reqdata += data[i].Data;
+ reqdata += "\r\n" ;
+ reqdata += '--' + boundary;
+ }
+ return new Array(reqdata,boundary);
+}
+
+function doClickSave() {
+ var dataForPost = prepareMultiPartPOST(
+ new Array(
+ prepareDataForSave('data', area.textarea.value),
+ prepareDataForSave('file_hash', $("input[name='file_hash']").val()),
+ prepareDataForSave('from_ajax','true')
+ )
+ )
+ //console.info(area.textarea.value);
+ $.ajax({
+ type: "POST",
+ contentType: 'multipart/form-data;boundary="' + dataForPost[1] + '"',
+ url: self.location.href,
+ dataType: "json",
+ data: dataForPost[0],
+ success: function(json){
+ //console.info( json.file_hash );
+ if (json.error == '') {
+ $("input[name='file_hash']").val(json.file_hash);
+ //console.info($("input[name='file_hash']").val());
+ $('.flash').text('saved with file_hash= "' + json.file_hash + '"');
+ $('.flash').removeClass('error'); // remove error class if we had it in previous call...
+ } else {
+ $('.flash').addClass('error');
+ $('.flash').text('THERE WERE ERRORS SAVING FILE = "' + json.error + '"');
+ }
+ $('.flash').slideDown('slow');
+ }
+ });
+}
--- web2py_orig/applications/admin/views/default/edit.html 2009-02-22 02:22:09.000000000 +0100
+++ web2py/applications/admin/views/default/edit.html 2009-02-22 19:02:49.000000000 +0100
@@ -2,7 +2,12 @@
<script language="Javascript" type="text/javascript" src="{{=URL(r=request,c='static',f='edit_area/edit_area_full.js')}}"></script><script language="Javascript" type="text/javascript">
editAreaLoader.init({id: "body",start_highlight: true,allow_resize: "both",allow_toggle: true,language: "en",syntax: "{{=filetype}}",replace_tab_by_spaces: 4});
</script>
+<script language="Javascript" type="text/javascript" src="/{{=request.application}}/static/ajax_editor.js"></script><script language="Javascript" type="text/javascript">
+$(document).ready(function(){
+ $("form").bind("submit", function() { doClickSave();return false; });
+});
+</script>
<h1>Editing file "{{=filename}}"</h1>
{{if functions:}}
--- web2py_orig/applications/admin/views/layout.html 2009-02-22 02:22:10.000000000 +0100
+++ web2py/applications/admin/views/layout.html 2009-02-23 20:23:15.000000000 +0100
@@ -31,9 +31,11 @@
<div id="main_inner" class="fixed">
<div id="primaryContent_columnless">
<div id="columnA_columnless">
+ <div class="flash">
{{if response.flash:}}
- <div class="flash">{{=response.flash}}</div>
+ {{=response.flash}}
{{pass}}
+ </div>
{{include}}
</div>
</div>
--- web2py_orig/applications/admin/views/web2py_ajax.html 2009-02-22 02:22:10.000000000 +0100
+++ web2py/applications/admin/views/web2py_ajax.html 2009-02-23 20:43:09.000000000 +0100
@@ -22,8 +22,11 @@
$(document).ready(function() {
$('.hidden').hide();
$('.error').hide().slideDown('slow');
-$('.flash').hide().slideDown('slow')
-$('.flash').click(function() { $(this).fadeOut('slow'); return false; });
+if ($('.flash').text() == '')
+ $('.flash').hide().slideDown('slow');
+else
+ $('.flash').hide();
+$('.flash').click(function() { $(this).slideUp('slow'); return false; }); //changed from default fadeout as it is too much intrusive :)
$('input.string').attr('size',50);
$('textarea.text').attr('cols',50).attr('rows',10);
$('input.integer').keyup(function(){this.value=this.value.reverse().replace(/[^0-9\-]|\-(?=.)/g,'').reverse();});