View Single Post
  #7 (permalink)  
Old 11-29-2007, 02:37 PM
emoulton emoulton is offline
Junior Member
 
Posts: 8
Default JavaScript problems...

I used the Google Translator Zimlet as a base for writing the following code:

XML definition file:
Code:
<zimlet name="email_reminder" version="0.21" description="Email Reminder">
	<include>email_reminder.js</include>
	<handlerObject>Email_Reminder</handlerObject>
	<zimletPanelItem label="Email Reminder">
		<toolTipText>
			Drag and Drop An Appointment, or Double-click to configure.
		</toolTipText>
		<dragSource type="ZmAppt" />
	</zimletPanelItem>
	<userProperties>
		<property type="string" name="emailaddr" label="Send To" />
		<property type="string" name="emailuser" label="User" />
		<property type="password" name="emailpass" label="Password" />
	</userProperties>
</zimlet>
And the JavaScript file:
Code:
function Email_Reminder() {}

Email_Reminder.prototype = new ZmZimletBase();
Email_Reminder.prototype.constructor = Email_Reminder;

Email_Reminder.URL = "http://my.test.server/test/emailr.php";

Email_Reminder.prototype.doDrop = function (zmObject)
{
	this._zmObject = zmObject;
	if (!this._statusDialog) { this._initialize(); }

	this._contentDIV.innerHTML = this._zmObject.startDate;
	this._contentDIV.style.visibility = "visible";

	this._makeRequest();
}

Email_Reminder.prototype._initialize = function ()
{
	this._parentView = new DwtComposite(this.getShell());
	this._parentView.setSize("440", "175");
	
	this._contentDIV = document.createElement("DIV");
	this._contentDIV.style.height = "140px";
	this._contentDIV.style.width = "435px";
	this._contentDIV.style.backgroundColor = "#FFFFFF";
	this._contentDIV.style.padding = "3px";
	this._contentDIV.style.position = "absolute";
	this._contentDIV.style.overflow = "auto";
	this._parentView.getHtmlElement().appendChild(this._contentDIV);

	this._statusDialog = this._createDialog({title:"Status", view:this._parentView});
}

Email_Reminder.prototype._makeRequest = function ()
{
	var params = [];
	var i = 0;
	
	params[i++] = "apptStartDate=";
	params[i++] = AjxStringUtil.urlEncode(this._zmObject.startDate);
	
	var header = { "User-Agent": navigator.userAgent , "Content-Type": "application/x-www-form-urlencoded" , "Referer": "http://my.test.server/test/emailr.php" };
	var url = ZmZimletBase.PROXY + AjxStringUtil.urlEncode(Email_Reminder.URL);

	AjxRpc.invoke(params.join("") , url , header , new AjxCallback(this , this._resultCallback));
}

Email_Reminder.prototype._populateStatus = function (respObj)
{
	var result = respObj.success ? respObj.text : null;
	var divIdx = result ? result.indexOf("<div id=result_box") : null;
	var div = divIdx ? Dwt.parseHtmlFragment(result.substring(divIdx)) : null;	

	this._contentDIV.innerHTML = div ? div.innerHTML : "An error happened.";
}


Email_Reminder.prototype._resultCallback = function (obj)
{
	this._populateStatus(obj);
	if (!this._statusDialog.isPoppedUp()) { this._statusDialog.popup(); }
}
The php code is the same as my first post in this thread, except I've commented out all the lines but the ones that deal with the start date of the appointment.

I get a 403 error from the Zimbra server when I try to drag an appointment to this zimlet. The error text is: "Access to the specified resource () has been forbidden." The dialog pops up, but I get the "An error happened." message that's in the _populateStatus function. The URL that firebug is getting the 403 from is:
Code:
https://my.zimbra.server:444/service/proxy?target=http://my.test.server/test/emailr.php
I'll keep playing around with it to see if I can't figure out what's going on. Currently I have a very limited idea of what the JavaScript code is doing, and I'm not much of a JavaScript programmer to begin with.

Any suggestions would be more than welcome. Thanks!
Reply With Quote