[mochikit] Facing error using MochiKit.Color

2008-05-12 Thread Pearl

Hi,

I want some text to appear  onload of a page. This text should be
highlighted (yellow fading technique). For this, I am using
combination of Highlight and fade methods gievn in Mochikit.
The method is described as

function display_message(msg)
{
var test = Highlight(msg);
var test = fade(msg,{ duration:5.0, from:1, to:0.0 });

}

and on the kid page it is described as 
script
window.onload = function() {
msg = getElement('message_element');
display_message(msg);
}
/script

body
div id=result-area class=msgparea 
span py:if=msg id=message_element class=flashmsgb$
{msg}/b/span

/body

It is giving an error in the firefox error console which keep on
incrementing. The error message is :
this._base has no properties.
[Break on this error] m
+=MochiKit.Color.toColorPart(Math.round(this._base[i]
+this._delta[i]*_663));

I am using mochikit 1.4.

Please help

Thanks and Regards
Roopesh
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
MochiKit group.
To post to this group, send email to mochikit@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/mochikit?hl=en
-~--~~~~--~~--~--~---



[mochikit] Django doXHR Headers and Guidance

2008-05-12 Thread Szaijan

Hi Folks,

I have a Django application with a scratch-built AJAX Javascript layer
that works well on Safari and Firefox, but not on IE.  I am attempting
to rewrite it using MochiKit, but am having some issues with the doXHR
function, in that I seem to be getting back an empty XHR from my
Django Python script.  I have a few questions:

1) Can anyone see what I'm doing wrong in the MochKit code?  As I
said, I get back an empty XHR.  Am I accessing the return XHR
incorrectly (should be the result argument in my callback, right?)
When I use typeof(result) I get the expected XHR type.
result.toJSONString() yields {}.

2) In the first code sample, I am able to access
ajaxRequest.response_text, which should be the same as
resulot.response_text in the MochiKit example, but the result appears
to be empty.  Do I need to do something different to access the fields
of the doXHR result argument?

3) Am I getting back an empty result because doXHR sets some default
headers for the request that are incompatible with the Django return
type?  What would be a good set of headers to use?

The generic code that works looks like:

selectEntity : function (entity)
{
try
{
var url = '/visionary/game/select/?xhr';
var eId = 'harp_game_id';
var getData = eId + '=' + escape(entity.pk);
var ajaxRequest = this.createRequest(); // Creates a
generic, platform appropriate XHR
ajaxRequest.open(POST, url, true);
ajaxRequest.onreadystatechange =
MochiKit.Base.bind(function ()
{
try
{
if(ajaxRequest.readyState == 4)
{
if(ajaxRequest.status == 200)
{
var response = eval( ( +
ajaxRequest.responseText + ));
if (response.success)
{
var consoleMessage =
response.initial_console_message;
 
MochiKit.Base.map(MochiKit.Base.bind(function (index) {
consoleMessage += br+
index + :  + response[index];
var rowId = [this.app,
this.cn, response[index], 'row'].join('_');
 
this.setRowHighlight(MochiKit.DOM.getElement(rowId),
 index ==
'newId' ? true : false);
}, this), ['newId', 'oldId']);
 
this.updateConsole(consoleMessage);
}
else
{
this.errorsToConsole(response);
}
return true;
}
}
}
catch(e)
{
MochiKit.Logging.logError('selectEntity
Callback fn ' + e);
}
return false;
}, this);
ajaxRequest.setRequestHeader(Content-Type, application/
x-www-form-urlencoded);
ajaxRequest.send(getData);
return true;
}
catch(e)
{
MochiKit.Logging.logError('selectEntity(' + entity + ') '
+ e);
}
return false;
}

The MochiKit heavy code I can't get a response from looks like:

selectEntity : function (entity)
{
try
{
var url = '/visionary/game/select/?xhr';
var q = 'harp_game_id=' + entity.pk;
var r = {method: 'POST',
mimeType: 'application/javascript',
headers: [['Content-Type', 'application/x-www-
form-urlencoded'],
['Accept', 'application/
json']],
 sendContent: q};
var d = MochiKit.Async.doXHR(url, r);
d.addCallback(MochiKit.Base.bind(function (result) {
try
{
MochiKit.Logging.log('Callback Request: ' +
result);
var response = eval( ( +
result.response_text + ));
if(typeof(response) != 'undefined')
{
var consoleMessage =
response.initial_console_message;
 
MochiKit.Base.map(MochiKit.Base.bind(function (index) {
consoleMessage += br+ index +
:  + response[index];
var rowId = [this.app, this.cn,
response[index], 'row'].join('_');
 
this.setRowHighlight(MochiKit.DOM.getElement(rowId),
 index ==
'newId' ? true : false);
}, this), ['newId', 'oldId']);
this.updateConsole(consoleMessage);
}
 

[mochikit] Re: Django doXHR Headers and Guidance

2008-05-12 Thread Bob Ippolito

mimeType: 'application/javascript' doesn't do what you think it does,
it's the overrideMimeType on the XHR. For JSON it doesn't matter since
it only uses responseText, I think it's only useful for setting it to
XML.

I think your problem is that XMLHttpRequest has a responseText
attribute, not response_text.

However you should probably just use MochiKit's evalJSONRequest
instead of doing the eval yourself.

-bob

On Mon, May 12, 2008 at 9:07 AM, Szaijan [EMAIL PROTECTED] wrote:

  Hi Folks,

  I have a Django application with a scratch-built AJAX Javascript layer
  that works well on Safari and Firefox, but not on IE.  I am attempting
  to rewrite it using MochiKit, but am having some issues with the doXHR
  function, in that I seem to be getting back an empty XHR from my
  Django Python script.  I have a few questions:

  1) Can anyone see what I'm doing wrong in the MochKit code?  As I
  said, I get back an empty XHR.  Am I accessing the return XHR
  incorrectly (should be the result argument in my callback, right?)
  When I use typeof(result) I get the expected XHR type.
  result.toJSONString() yields {}.

  2) In the first code sample, I am able to access
  ajaxRequest.response_text, which should be the same as
  resulot.response_text in the MochiKit example, but the result appears
  to be empty.  Do I need to do something different to access the fields
  of the doXHR result argument?

  3) Am I getting back an empty result because doXHR sets some default
  headers for the request that are incompatible with the Django return
  type?  What would be a good set of headers to use?

  The generic code that works looks like:

 selectEntity : function (entity)
 {
 try
 {
 var url = '/visionary/game/select/?xhr';
 var eId = 'harp_game_id';
 var getData = eId + '=' + escape(entity.pk);
 var ajaxRequest = this.createRequest(); // Creates a
  generic, platform appropriate XHR
 ajaxRequest.open(POST, url, true);
 ajaxRequest.onreadystatechange =
  MochiKit.Base.bind(function ()
 {
 try
 {
 if(ajaxRequest.readyState == 4)
 {
 if(ajaxRequest.status == 200)
 {
 var response = eval( ( +
  ajaxRequest.responseText + ));
 if (response.success)
 {
 var consoleMessage =
  response.initial_console_message;

  MochiKit.Base.map(MochiKit.Base.bind(function (index) {
 consoleMessage += br+
  index + :  + response[index];
 var rowId = [this.app,
  this.cn, response[index], 'row'].join('_');

  this.setRowHighlight(MochiKit.DOM.getElement(rowId),
  index ==
  'newId' ? true : false);
 }, this), ['newId', 'oldId']);

  this.updateConsole(consoleMessage);
 }
 else
 {
 this.errorsToConsole(response);
 }
 return true;
 }
 }
 }
 catch(e)
 {
 MochiKit.Logging.logError('selectEntity
  Callback fn ' + e);
 }
 return false;
 }, this);
 ajaxRequest.setRequestHeader(Content-Type, application/
  x-www-form-urlencoded);
 ajaxRequest.send(getData);
 return true;
 }
 catch(e)
 {
 MochiKit.Logging.logError('selectEntity(' + entity + ') '
  + e);
 }
 return false;
 }

  The MochiKit heavy code I can't get a response from looks like:

 selectEntity : function (entity)
 {
 try
 {
 var url = '/visionary/game/select/?xhr';
 var q = 'harp_game_id=' + entity.pk;
 var r = {method: 'POST',
 mimeType: 'application/javascript',
 headers: [['Content-Type', 'application/x-www-
  form-urlencoded'],
 ['Accept', 'application/
  json']],
  sendContent: q};
 var d = MochiKit.Async.doXHR(url, r);
 d.addCallback(MochiKit.Base.bind(function (result) {
 try
 {
 MochiKit.Logging.log('Callback Request: ' +
  result);
 var response = eval( ( +
  result.response_text + ));
 if(typeof(response) != 'undefined')
 {