[Proto-Scripty] Re: A question about submitting multiple parameters using Ajax.Updater

2009-10-16 Thread Alex McAuley

parameters : {

variable_1: 'Somevar',
variable_2: 'Some Other Var',
variable_3: 'Some third var'

}

is that what you mean ?

Alex Mcauley
http://www.thevacancymarket.com
- Original Message - 
From: kashyap ckkash...@gmail.com
To: Prototype  script.aculo.us prototype-scriptaculous@googlegroups.com
Sent: Thursday, October 15, 2009 11:49 AM
Subject: [Proto-Scripty] A question about submitting multiple parameters 
using Ajax.Updater



 Hi,
 How can I use Ajax.Updater to send parameters from HTML - param1 and
 param2 the values of which are not in a form as such using
 Ajax.Updater in a manner such that on the server side, I use the
 model's update_attributes method.

 new Ajax.Updater(
   '#{options[:update_html_id]}',
   '#{options[:update_url]}'+id,
   {asynchronous:true, evalScripts:true,
 parameters:'authenticity_token=' +
 encodeURIComponent('Hl7TS7DG2dM0zmGAO09HMU8rKTNJwto37APahAPK9vA=') }
   )

 How can I modify the Updater above to generate the data below so that
 I can use model.udate_attributes(params[:some_model])

 { authenticity_token=Hl7TS7DG2dM0zmGAO09HMU8rKTNJwto37APahAPK9vA=,
 some_model={param1=value1,
 param2=value2},
 id=100}


 --
 Regards,
 Kashyap

 
 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: A question about submitting multiple parameters using Ajax.Updater

2009-10-16 Thread C K Kashyap

On Fri, Oct 16, 2009 at 12:36 PM, Alex McAuley
webmas...@thecarmarketplace.com wrote:

 parameters : {

 variable_1: 'Somevar',
 variable_2: 'Some Other Var',
 variable_3: 'Some third var'

 }

 is that what you mean ?

Almost - except

parameters : {

variable_1: 'Somevar',
variable_2: {
   a: 'hash members',
   b: 'of',
   c: 'variable 2'
},
variable_3: 'Some third var'

}

A nested hash basically.

Regards,
Kashyap

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: A question about submitting multiple parameters using Ajax.Updater

2009-10-16 Thread Alex McAuley

you will probably need to set variable 2 as a json object and decode it on 
the server.

I have sent json objects like this before to the server and decoded them 
back to an array once they arrive.

for example...
var data={};

for(i=0; i=10;++i) {
data[i]=i;
}
var params=Object.toJSON(data);

var request=new Ajax.Request(...

parameters : {
variable_1 : 'Hi i am variable one',
variable_2 : params // The json object
}
...

HTH


Alex Mcauley
http://www.thevacancymarket.com


- Original Message - 
From: C K Kashyap ckkash...@gmail.com
To: prototype-scriptaculous@googlegroups.com
Sent: Friday, October 16, 2009 9:17 AM
Subject: [Proto-Scripty] Re: A question about submitting multiple parameters 
using Ajax.Updater



 On Fri, Oct 16, 2009 at 12:36 PM, Alex McAuley
 webmas...@thecarmarketplace.com wrote:

 parameters : {

 variable_1: 'Somevar',
 variable_2: 'Some Other Var',
 variable_3: 'Some third var'

 }

 is that what you mean ?

 Almost - except

 parameters : {

 variable_1: 'Somevar',
 variable_2: {
   a: 'hash members',
   b: 'of',
   c: 'variable 2'
 },
 variable_3: 'Some third var'

 }

 A nested hash basically.

 Regards,
 Kashyap

 
 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Tying an Element and a custom class together

2009-10-16 Thread Eric

Hi,

While I agree with T.J. arguments, there are cases when it is nice to
have this behavior (DOM element and Plain object in the same
object). On of those case is, for example when you're creating a new
control class.

The way I do it is:
- building the DOM element in the class's constructor (and keeping it
in an attribute) (*)
- implement the toElement() method in the class (to return this DOM
element) (*)

The second step allows you to provide your class instance to any
prototype method instead of a DOM element.
A small example: http://jsbin.com/omaza

Ops: Previous sentence was wrong... After trying to write the
example, and checking in the source, it seems that you can only use
this kind of object as a DOM element in a handfull of prototype's
methods (insert, update and replace)...

Is it any reason why this behavior is not implemented in $() (this
would actually allow to use a custom class everywhere where a DOM
element is needed, and just add one line of code).

Eric

(*) This was the simplest way to explain the process, but you may
prefer dynamically create the DOM element on the first call of
toElement() for better efficiency.
On Sep 10, 10:56 am, T.J. Crowder t...@crowdersoftware.com wrote:
 Hi Andrea,

 FWIW, I'd say the best practice is:  Don't do that, it conflates the
 model with the view *and* the controller. :-)  (MVC is not by any
 means the only game in town, but the terminology is useful for
 questions like this.)  If you ever want to present the business object
 in two different ways in two different panels (in a list, for
 instance, and in a details pane that shows the details of the
 highlighted object in the list), you can't, or rather the code gets
 ugly fast.

 Instead, I'd suggest keeping the business object separate from the
 element and using a has a rather than an is a relationship.  You
 can do that by storing the business object ID on the element in some
 way (data-key is the attribute I usually use for this, and fits with
 the proposed HTML5 data attributes standard), either directly or via a
 small controller.

 The business object should never update the element directly, and so
 it doesn't need to know about it.  Instead, it should raise events
 that controllers can respond to by updating the elements they
 control.  When I say fire event, I'm not necessarily talking
 browserspeak (I wouldn't use browser events for this), just a minimal
 implementation of the Observer pattern (as a mixin or similar you can
 use for lots of different objects).

 FWIW, and apologies if I went OT, but I hope I didn't,
 --
 T.J. Crowder
 tj / crowder software / comwww.crowdersoftware.com

 On Sep 9, 3:02 pm, Andrea Campi andrea.ca...@gmail.com wrote:

  Hi,

  in my application I need JS objects to represent some business
  objects, which are represented on the page by an Element.
  I would like to be able to tie the two together in such a way that I
  can use them interchangeably.
  This sounds like it should be a common pattern, so I was wondering
  what the best practices are.

  Example:

  var Foo = Class.create({
    initialize: function(parent) {
      var element = Object.extend(new Element(div, { 'class': 'foo',
  'id': 'myFoo' }), this);
      parent.insert(element);
    },

    bar: function() {
    }
    // more methods

  };

  Thanks to Object.extend I can easily call: $('myFoo').bar()
  But I cannot do the opposite, for instance:

  var foo = new Foo();
  foo.childElements();

  Note that it would just work if I could return 'element' (which now
  behaves like Foo).
  However, I've readhttp://dev.rubyonrails.org/ticket/11481andit has
  reasonable objections to letting the constructor return a value.

  So, what gives? Any suggestion?

  TIA,
    Andrea


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Tying an Element and a custom class together

2009-10-16 Thread Matt Foster

The has a relationship is the only way to go for sure.

You could create an ElementProxy class that inherits all the Element
methods but just keeps a reference to the actual DOM reference
internally. All of the Element.Methods are parameterized so I'm sure
there'd be an easy way to delegate the reference.  As long as the
ElementProxy class implements all the regular methods then core
prototype processes wouldn't know the difference between the two.

--

http://positionabsolute.net



On Oct 16, 12:02 pm, Eric lefauv...@gmail.com wrote:
 Hi,

 While I agree with T.J. arguments, there are cases when it is nice to
 have this behavior (DOM element and Plain object in the same
 object). On of those case is, for example when you're creating a new
 control class.

 The way I do it is:
 - building the DOM element in the class's constructor (and keeping it
 in an attribute) (*)
 - implement the toElement() method in the class (to return this DOM
 element) (*)

 The second step allows you to provide your class instance to any
 prototype method instead of a DOM element.
 A small example:http://jsbin.com/omaza

 Ops: Previous sentence was wrong... After trying to write the
 example, and checking in the source, it seems that you can only use
 this kind of object as a DOM element in a handfull of prototype's
 methods (insert, update and replace)...

 Is it any reason why this behavior is not implemented in $() (this
 would actually allow to use a custom class everywhere where a DOM
 element is needed, and just add one line of code).

 Eric

 (*) This was the simplest way to explain the process, but you may
 prefer dynamically create the DOM element on the first call of
 toElement() for better efficiency.
 On Sep 10, 10:56 am, T.J. Crowder t...@crowdersoftware.com wrote:

  Hi Andrea,

  FWIW, I'd say the best practice is:  Don't do that, it conflates the
  model with the view *and* the controller. :-)  (MVC is not by any
  means the only game in town, but the terminology is useful for
  questions like this.)  If you ever want to present the business object
  in two different ways in two different panels (in a list, for
  instance, and in a details pane that shows the details of the
  highlighted object in the list), you can't, or rather the code gets
  ugly fast.

  Instead, I'd suggest keeping the business object separate from the
  element and using a has a rather than an is a relationship.  You
  can do that by storing the business object ID on the element in some
  way (data-key is the attribute I usually use for this, and fits with
  the proposed HTML5 data attributes standard), either directly or via a
  small controller.

  The business object should never update the element directly, and so
  it doesn't need to know about it.  Instead, it should raise events
  that controllers can respond to by updating the elements they
  control.  When I say fire event, I'm not necessarily talking
  browserspeak (I wouldn't use browser events for this), just a minimal
  implementation of the Observer pattern (as a mixin or similar you can
  use for lots of different objects).

  FWIW, and apologies if I went OT, but I hope I didn't,
  --
  T.J. Crowder
  tj / crowder software / comwww.crowdersoftware.com

  On Sep 9, 3:02 pm, Andrea Campi andrea.ca...@gmail.com wrote:

   Hi,

   in my application I need JS objects to represent some business
   objects, which are represented on the page by an Element.
   I would like to be able to tie the two together in such a way that I
   can use them interchangeably.
   This sounds like it should be a common pattern, so I was wondering
   what the best practices are.

   Example:

   var Foo = Class.create({
     initialize: function(parent) {
       var element = Object.extend(new Element(div, { 'class': 'foo',
   'id': 'myFoo' }), this);
       parent.insert(element);
     },

     bar: function() {
     }
     // more methods

   };

   Thanks to Object.extend I can easily call: $('myFoo').bar()
   But I cannot do the opposite, for instance:

   var foo = new Foo();
   foo.childElements();

   Note that it would just work if I could return 'element' (which now
   behaves like Foo).
   However, I've readhttp://dev.rubyonrails.org/ticket/11481andithas
   reasonable objections to letting the constructor return a value.

   So, what gives? Any suggestion?

   TIA,
     Andrea
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Magento....

2009-10-16 Thread Brian Williams
anyone out there do any work with Magento?  It uses Prototype/Scriptaculous.
I'm trying to implement a simple vertical accordion menu but just can't seem
to get it to work.

using default varien/accordion.js (afeared that I am doing something
stupidly obvious wrong)

and this code:

[code]
script type=text/javascript src=?php echo
$this-getJsUrl('varien/accordion.js') ?/script
ol id=left_menu_nav class=left_nav
li id=best-sellers_menu class=section 
div class=head
h3a href=# class=a-itemBest Sellers/a/h3
/div
div id=
asdfasdfbr /asdfasdf
/div
/li
li id=new-arrivals_menu class=section 
div class=head
h3a href=# class=a-itemNew Arrivals/a/h3
/div
div id=
asdfasdfbr /asdfasdf
/div
/li
/ol
[/code]

Any help would be appreciated.

Thanks!

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Magento....

2009-10-16 Thread Julius Seporaitis
Hi,

try to change *class=section* to *class=section allow.*

On Fri, Oct 16, 2009 at 10:22 PM, Brian Williams brianw1...@gmail.comwrote:

 anyone out there do any work with Magento?  It uses
 Prototype/Scriptaculous.
 I'm trying to implement a simple vertical accordion menu but just can't
 seem to get it to work.

 using default varien/accordion.js (afeared that I am doing something
 stupidly obvious wrong)

 and this code:

 [code]
 script type=text/javascript src=?php echo
 $this-getJsUrl('varien/accordion.js') ?/script
 ol id=left_menu_nav class=left_nav
 li id=best-sellers_menu class=section 
 div class=head
 h3a href=# class=a-itemBest Sellers/a/h3
 /div
 div id=
 asdfasdfbr /asdfasdf
 /div
 /li
 li id=new-arrivals_menu class=section 
 div class=head
 h3a href=# class=a-itemNew Arrivals/a/h3
 /div
 div id=
 asdfasdfbr /asdfasdf
 /div
 /li
 /ol
 [/code]

 Any help would be appreciated.

 Thanks!

 



-- 
Pagarbiai,
Julius Šėporaitis
Blogeris @ http://www.seporaitis.net/
Narys ir organizatorius @ http://www.jjgklubas.lt/

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Magento....

2009-10-16 Thread Brian Williams
Thanks for the tip,  it wasn't all that was required but I did manage to get
it working.
Final working code as follows:

ol id=left_menu_nav class=left_nav
li id=best-sellers_menu class=section allow 
div class=headh3a href=# class=img
src=?=$this-getSkinUrl('images/bestsellerslinkleft.png');? alt=Best
Sellers //a/h3/div
div id= class=a-item style=display:none;
asdfbr /asdf

/div
/li
/ol


Thanks again

On Fri, Oct 16, 2009 at 3:37 PM, Julius Seporaitis jul...@seporaitis.netwrote:

 Hi,

 try to change *class=section* to *class=section allow.*

 On Fri, Oct 16, 2009 at 10:22 PM, Brian Williams brianw1...@gmail.comwrote:

 anyone out there do any work with Magento?  It uses
 Prototype/Scriptaculous.
 I'm trying to implement a simple vertical accordion menu but just can't
 seem to get it to work.

 using default varien/accordion.js (afeared that I am doing something
 stupidly obvious wrong)

 and this code:

 [code]
 script type=text/javascript src=?php echo
 $this-getJsUrl('varien/accordion.js') ?/script
 ol id=left_menu_nav class=left_nav
 li id=best-sellers_menu class=section 
 div class=head
  h3a href=# class=a-itemBest Sellers/a/h3
 /div
 div id=
 asdfasdfbr /asdfasdf
 /div
 /li
 li id=new-arrivals_menu class=section 
 div class=head
 h3a href=# class=a-itemNew Arrivals/a/h3
 /div
 div id=
 asdfasdfbr /asdfasdf
 /div
 /li
 /ol
 [/code]

 Any help would be appreciated.

 Thanks!





 --
 Pagarbiai,
 Julius Šėporaitis
 Blogeris @ http://www.seporaitis.net/
 Narys ir organizatorius @ http://www.jjgklubas.lt/

 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Tying an Element and a custom class together

2009-10-16 Thread Matt Foster

Quick and dirty, im sure there are errors but conceptually this would
be my approach...

var ElementProxy = Class.create({
initialize : function(ele){
this.element = $(ele);
this.nodeType = this.element.nodeType;
this.tagName = this.element.tagName;
this.delegateMethods();
},
delegateMethods : function(){
var methods = Element.Methods;
for(var method in methods){
var __method = methods[method];
if (Object.isFunction(__method)  
!(__method in this))
this.assignMethod(method, 
__method);
}
},
assignMethod : function(method, __method){
this[method] = function(){ return 
__method.apply(this.element,
[this.element].concat($A(arguments))); };
}
});

--

http://positionabsolute.net

On Oct 16, 3:01 pm, Matt Foster mattfoste...@gmail.com wrote:
 The has a relationship is the only way to go for sure.

 You could create an ElementProxy class that inherits all the Element
 methods but just keeps a reference to the actual DOM reference
 internally. All of the Element.Methods are parameterized so I'm sure
 there'd be an easy way to delegate the reference.  As long as the
 ElementProxy class implements all the regular methods then core
 prototype processes wouldn't know the difference between the two.

 --

 http://positionabsolute.net

 On Oct 16, 12:02 pm, Eric lefauv...@gmail.com wrote:

  Hi,

  While I agree with T.J. arguments, there are cases when it is nice to
  have this behavior (DOM element and Plain object in the same
  object). On of those case is, for example when you're creating a new
  control class.

  The way I do it is:
  - building the DOM element in the class's constructor (and keeping it
  in an attribute) (*)
  - implement the toElement() method in the class (to return this DOM
  element) (*)

  The second step allows you to provide your class instance to any
  prototype method instead of a DOM element.
  A small example:http://jsbin.com/omaza

  Ops: Previous sentence was wrong... After trying to write the
  example, and checking in the source, it seems that you can only use
  this kind of object as a DOM element in a handfull of prototype's
  methods (insert, update and replace)...

  Is it any reason why this behavior is not implemented in $() (this
  would actually allow to use a custom class everywhere where a DOM
  element is needed, and just add one line of code).

  Eric

  (*) This was the simplest way to explain the process, but you may
  prefer dynamically create the DOM element on the first call of
  toElement() for better efficiency.
  On Sep 10, 10:56 am, T.J. Crowder t...@crowdersoftware.com wrote:

   Hi Andrea,

   FWIW, I'd say the best practice is:  Don't do that, it conflates the
   model with the view *and* the controller. :-)  (MVC is not by any
   means the only game in town, but the terminology is useful for
   questions like this.)  If you ever want to present the business object
   in two different ways in two different panels (in a list, for
   instance, and in a details pane that shows the details of the
   highlighted object in the list), you can't, or rather the code gets
   ugly fast.

   Instead, I'd suggest keeping the business object separate from the
   element and using a has a rather than an is a relationship.  You
   can do that by storing the business object ID on the element in some
   way (data-key is the attribute I usually use for this, and fits with
   the proposed HTML5 data attributes standard), either directly or via a
   small controller.

   The business object should never update the element directly, and so
   it doesn't need to know about it.  Instead, it should raise events
   that controllers can respond to by updating the elements they
   control.  When I say fire event, I'm not necessarily talking
   browserspeak (I wouldn't use browser events for this), just a minimal
   implementation of the Observer pattern (as a mixin or similar you can
   use for lots of different objects).

   FWIW, and apologies if I went OT, but I hope I didn't,
   --
   T.J. Crowder
   tj / crowder software / comwww.crowdersoftware.com

   On Sep 9, 3:02 pm, Andrea Campi andrea.ca...@gmail.com wrote:

Hi,

in my application I need JS objects to represent some business
objects, which are represented on the page by an Element.
I would like to be able to tie the two together in such a way that I
can use them interchangeably.
This sounds like it should be a common pattern, so I was wondering
what the