|
From: Thyamad c. <th...@us...> - 2005-09-12 18:43:12
|
Update of /cvsroot/thyapi/thyapi/thyfunctions In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7271/thyfunctions Added Files: thyajaxcontent.js Log Message: Commiting file additions and modification from SVN revision 1937 to 1938... Changes made by vinicius on 2005-09-12 20:59:10 +0200 (Mon, 12 Sep 2005) corresponding to SVN revision 1938 with message: ThyAjaxContent functions initial version --- NEW FILE: thyajaxcontent.js --- /***************************************************************************\ * ThyAPI - Thyamad Javascript API - AJAX Change Content Functions * * http://www.thyamad.com * * * * Copyright (C) 2005 - Vinicius Cubas Brand * * Based on DynAPI v3.0b1 * * ------------------------------------------------------------------------- * * This library is free software; you can redistribute it and/or modify it * * under the terms of the GNU Lesser General Public License as published * * by the Free Software Foundation; either version 2.1 of the License, * * or any later version. * * This library is distributed in the hope that it will be useful, but * * WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * See the GNU Lesser General Public License for more details. * \***************************************************************************/ /** * Function: thyAjaxChangeContent * * Changes the innerHTML of an DOM element (e.g. div) with the response of * a RPC method called through AJAX * * Parameters: * * id - the DOM Element ID * class - the CSS Class to be atributed to the DOM Element after content change * method - name of the RPC method * parameters - parameters of the RPC method, defaults an empty array * protocol - the protocol to be used, for instance, 'xmlrpc' * url - the url to be used */ function thyAjaxChangeContent(params) { //Parameter handling var defaultParams = { protocol : 'xmlrpc', parameters : { }, append : false //Defined if content will be changed or appended, hidden attribute }; //fill with default values for(var i in defaultParams) { if (params[i] == null && typeof(params[i]) != 'object') //undefined { params[i] = defaultParams[i]; } } var self = this; this.DOMElement = dynapi.functions.getElementById(params['id']); this.protocol = thyProtocol(params['protocol'],params['url']); this.append = params['append']; this.CSSClass = params['class']; if (!params['class']) { params['class'] = 'default_read'; } // thyConnector is a Singleton! if (!window.thyConnectorObj) { window.thyConnectorObj = new thyConnector(); window.thyConnectorObj.setVisible(true); } if (this.DOMElement) { var handler = function(response) { var data = self.protocol.decode(response); if (self.append) { self.DOMElement.innerHTML += data; } else { self.DOMElement.innerHTML = data; } if (self.CSSClass) { self.DOMElement.className = self.CSSClass; } } var data = this.protocol.encode(params['method'],params['parameters']); thyConnectorObj.setContentType(this.protocol.getContentType()); thyConnectorObj.newRequest(params['class'],params['url'],data,handler); } } /** * Function: thyAjaxAppendContent * * Appends the response of a RPC method to the content of a DOM element * * Parameters: * * id - the DOM Element ID * class - the CSS Class to be atributed to the DOM Element after content append * method - name of the RPC method * parameters - parameters of the RPC method, defaults an empty array * protocol - the name of the protocol to be used, for instance, 'xmlrpc' * url - the url to be used */ function thyAjaxAppendContent(params) { params['append'] = true; return thyAjaxChangeContent(params); } |