Mailinglist Archive: yast-devel (152 mails)

< Previous Next >
[yast-devel] Re: [ruby-devel] Studio and AJAX calls
  • From: Josef Reidinger <jreidinger@xxxxxxx>
  • Date: Thu, 02 Jul 2009 14:55:09 +0200
  • Message-id: <4A4CAE2D.3060409@xxxxxxx>
Cornelius Schumacher wrote:
On Thursday 02 July 2009, Josef Reidinger wrote:
I heard that suse studion use for ajax calls pure jquery. I want use in
webyast rails helpers, but that uses scipt.aulo backend (and that breaks
all out jquery stuff), but also exist plugin 'jrails' which use jquery
as backend for helpers. Is there any reason why studion use pure jquery?

We are using jquery, because it's the superior javascript framework. When we
started, there was no working rails integration, that's why we have written
most of the stuff ourselves. Maybe we should reinvestigate the current state
of the Rails plugins.

Garrett is our jquery expert, maybe he has something to add. He is traveling
right now, though, so it might take a bit.


Thanks for reply,
today I try replace my AJAX helpers with jquery stuff, but I am not much
successfull.
How you implement observer ajax? (observer is reaction on change of
another object on page)

in helpers it is
observe_field(:region,
:frequency => 0.25,
:update => :timezones,
:url => { :action => :timezones_for_region },
:with => "'disabled=' + "+ (disabled ? "true":"false")+" +
'&value=' +value")

I look how do it jrails and it is this:
<script type="text/javascript">

//<![CDATA[
$('#region').delayedObserver(0.25, function(element, value)
{$.ajax({data:value + '&authenticity_token=' + encodeURIComponent('<%=
form_authenticity_token %>'),
success:function(request){$('#timezones').html(request);}, type:'post',
url:'timezones_for_region'})})
//]]>
</script>

but delayedObserved is another helper, which is defined in jrails.js and
look this:
delayedObserver:function(delay,callback){var el=$(this);if(typeof
window.delayedObserverStack=="undefined"){window.delayedObserverStack=[]}if(typeof
window.delayedObserverCallback=="undefined"){window.delayedObserverCallback=function(stackPos){observed=window.delayedObserverStack[stackPos];if(observed.timer){clearTimeout(observed.timer)}observed.timer=setTimeout(function(){observed.timer=null;observed.callback(observed.obj,observed.obj.formVal())},observed.delay*1000);observed.oldVal=observed.obj.formVal()}}window.delayedObserverStack.push({obj:el,timer:null,delay:delay,oldVal:el.formVal(),callback:callback});var
stackPos=window.delayedObserverStack.length-1;if(el[0].tagName=="FORM"){$(":input",el).each(function(){var
field=$(this);field.bind($.fieldEvent(field,delay),function(){observed=window.delayedObserverStack[stackPos];if(observed.obj.formVal()==observed.obj.oldVal){return}else{window.delayedObserverCallback(stackPos)}})})}else{el.bind($.fieldEvent(el,delay),function(){observed=window.delayedObserverStack[stackPos];if(observed.obj.formVal()==observed.obj.oldVal){return}else{window.delayedObserverCallback(stackPos)}})}

That is enought cryptic for me to avoid use it in my code :)
So if you in studion use some nice observer ajax stuff I welcome it at
least to test before we decide if we should use jrails or not.
Josef
--
Josef Reidinger
YaST team
maintainer of perl-Bootloader, YaST2-Repair, webyast modules language
and time
--
To unsubscribe, e-mail: yast-devel+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-devel+help@xxxxxxxxxxxx

< Previous Next >
This Thread
References