Re: [Zope3-Users] z3c.formjs - global js-variables and form-content in scripts

2008-09-18 Thread garz


you wrote:
> 
> Again I'm not sure if you are talking about server or client.  From
> the server perspective, if you have
> 
> @jsfunction.function('z3c')
> def myFunc(self):
>   return u"alert('the fields in this form are %s');" % [w.id for w in
> self.widgets.values()]
> 
> then calling the function from javascript will give the widgets of
> that field.  But of course this gets hard coded into the javascript
> function so it is not dynamic from the client perspective. 
> 

i'm talking about the server-side. the example that you wrote doesnt work,
because when the function is rendered, the following happens:

@property
def arguments(self):
args = inspect.getargspec(self.function)[0]
if args[0] is 'self':
del args[0]
return args

def render(self):
return self.function(*[x for x in ['self'] + self.arguments])

the value of the parameter self is not longer the form, its only a string
with the content 'self'. but even if it was not that way, a self doesnt
exist because the jsfunctions are added in the class description. the thing
one would have to do is register those functions in the update-method for
example and additionaly change the render-method of the jsfunction. this
works but this is what i meant when i wrote hacky.



> You can include any global javascript functions the same way you
> include style sheets and other resources: either by placing said
> script directly into your layout template, or using JavaScriptViewlet
> objects and the viewlet manager pattern.
> 

i think with global variables its the same. i want those global variables
have values coming from my form. so i cant use an external js-script file
and register it.


another you wrote:
> 
> If it were a widget for List fields, it would be a great addition to,
> um, z3c.widget?  z3c.listwidget?  I think.
> 

i first wanted to make a widget, but then i came to the conclusion, that
widgets should be atomic. if a widget is composed of more than one element,
then its a form. otherwise there would be no difference between those.
imagine the widget-switch from formjs for a widget that is composed of more
than one element. that wouldnt make any sense. so there will be a subform.
-- 
View this message in context: 
http://www.nabble.com/z3c.formjs---global-js-variables-and-form-content-in-scripts-tp19543467p19556221.html
Sent from the Zope3 - users mailing list archive at Nabble.com.

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] z3c.formjs - global js-variables and form-content in scripts

2008-09-18 Thread Marius Gedminas
On Wed, Sep 17, 2008 at 11:26:28PM -0700, Paul Carduner wrote:
> On Wed, Sep 17, 2008 at 4:48 PM, garz <[EMAIL PROTECTED]> wrote:
> > my goal is to write a general sequence-form, that can display a sequence
> > consisting of an arbitrary widget. it should provide delete-buttons for
> > every element. in add-forms, the functionality of these should be realized
> > through javascript, dom-manipulation plus submit and in edit-forms without
> > submit but with ajax.
> 
> This particular use case I think is too high level for a package like
> formjs, but would certainly be a great addition as an example in
> formjsdemo.  It seems quite similar to the tree editor demo in
> formjsdemo: http://demo.carduner.net/z3c.formjsdemo/test

If it were a widget for List fields, it would be a great addition to,
um, z3c.widget?  z3c.listwidget?  I think.

The ancient Zope 3 widget for List fields is pretty bad.

Marius Gedminas
-- 
Key emulation:
[ ] Intuitive
[*] Emacs(Seen in an MCEdit dialog) 


signature.asc
Description: Digital signature
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] z3c.formjs - global js-variables and form-content in scripts

2008-09-17 Thread Paul Carduner
On Wed, Sep 17, 2008 at 4:48 PM, garz <[EMAIL PROTECTED]> wrote:
>
> hi,
>
> i'm working with z3c.formjs and there are three questions that arose.
>
> 1.) defining global variables
> i'd like to define some global variables that i can refer to in the
> functions that i want to define with the jsfunction-package. for example a
> global counter that counts something. is there any possibility to do so?

You can include any global javascript functions the same way you
include style sheets and other resources: either by placing said
script directly into your layout template, or using JavaScriptViewlet
objects and the viewlet manager pattern.  As long as your global
javascript function appears before any dynamically generated
javascript within the rendered page, the function will be available in
all rendered jsfunctions.

> 2.) form-content in jsfunctions-scripts
> i want to define a jsfunction that returns a rendered widget. this widget is
> an information that the particular instance of a form has. so i need to
> somehow access that form to get that widget. as far as i can see this there
> is no possibility to do this with jfsunction-package, since the functions
> defined with it are static and they arent given any useful parameter-values
> when called.

The parameters passed to the renderer javascript function are only
javascript objects and do not have any special knowledge about the
form.  I'm not sure I completely understand your use case.  When you
say form and widget, are you referring to the form and widget as they
are represented on the server side or as they are rendered on the
client's web page?

> so i looked at jsevent and jsaction but the problem there is they dont know
> the source form neither. they know the calling request, but since im working
> with subforms, i need to know the exact form where the executed handler is
> coming from. neither the request nor the jssubscriptions know about the
> source-form.
>
> so it isnt meant to weave form-specific data into the js-script. so what is
> the solution to this? i cant see it.

Again I'm not sure if you are talking about server or client.  From
the server perspective, if you have

@jsfunction.function('z3c')
def myFunc(self):
  return u"alert('the fields in this form are %s');" % [w.id for w in
self.widgets.values()]

then calling the function from javascript will give the widgets of
that field.  But of course this gets hard coded into the javascript
function so it is not dynamic from the client perspective.

> 3.) jssubscriptions-renderer
> why are those renderers only in the testing-package? arent they good enough?
> or is this usually done another way?

There is JQuerySubscriptionRenderer in jqueryrenderer.py.  It looks
just like the one in testing because jquery is the reference
implementation.

>
> +++
>
> my goal is to write a general sequence-form, that can display a sequence
> consisting of an arbitrary widget. it should provide delete-buttons for
> every element. in add-forms, the functionality of these should be realized
> through javascript, dom-manipulation plus submit and in edit-forms without
> submit but with ajax.

This particular use case I think is too high level for a package like
formjs, but would certainly be a great addition as an example in
formjsdemo.  It seems quite similar to the tree editor demo in
formjsdemo: http://demo.carduner.net/z3c.formjsdemo/test

> since i dont think that that there is a solution to this need, i think i
> will have to adjust formjs. i would like to make that clean, means i dont
> want to do a "hacky" formjs-adaption. maybe this usecase is already known
> and there is interest in evolving formjs? maybe through new packages? maybe
> through rewrites?

Extensions to formjs for supporting these types of CRUD use cases are
certainly welcome.  Feel free to start hacking on a branch.

-- 
Paul Carduner
http://www.carduner.net
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users