[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] hrm/js/ajax prajax_util.js sarissa_test.js
From: |
Sigurd Nes |
Subject: |
[Phpgroupware-cvs] hrm/js/ajax prajax_util.js sarissa_test.js |
Date: |
Tue, 22 Aug 2006 08:38:11 +0000 |
CVSROOT: /sources/phpgroupware
Module name: hrm
Changes by: Sigurd Nes <sigurdne> 06/08/22 08:38:11
Added files:
js/ajax : prajax_util.js sarissa_test.js
Log message:
Added test for ajax
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/hrm/js/ajax/prajax_util.js?cvsroot=phpgroupware&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/hrm/js/ajax/sarissa_test.js?cvsroot=phpgroupware&rev=1.1
Patches:
Index: prajax_util.js
===================================================================
RCS file: prajax_util.js
diff -N prajax_util.js
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ prajax_util.js 22 Aug 2006 08:38:11 -0000 1.1
@@ -0,0 +1,156 @@
+// ----------------------------------------------
+// PRAjax - JavaScript code
+// (C) Maarten Balliauw
+// http://prajax.sf.net
+// Version: PRAjaxUtil v1.2.3
+// ----------------------------------------------
+
+// Static class
+var PRAjaxUtil = new ( function () {
+ // Add event
+ this.addEvent = function (pElement, pEventType, pFuncton, pUseCapture) {
+ if (pElement.addEventListener) {
+ return pElement.addEventListener(pEventType, pFuncton,
pUseCapture);
+ } else if (pElement.attachEvent) {
+ return pElement.attachEvent('on' + pEventType,
pFuncton, pUseCapture);
+ } else {
+ return false;
+ }
+ }
+
+ // Add slashes (PHP equivalent)
+ this.addSlashes = function (pString) {
+ pString = pString + "";
+ pString = pString.replace(/\\/g,"\\\\");
+ pString = pString.replace(/\'/g,"\\'");
+ pString = pString.replace(/\"/g,"\\\"");
+ return pString;
+ }
+
+ // Strip slashes (PHP equivalent)
+ this.stripSlashes = function (pString) {
+ pString = pString + "";
+ return pString.replace(/(\\)([\\\'\"])/g,"$2");
+ }
+} ) ();
+
+
+// ----------------------------------------------
+// JSON Extensions
+// http://www.json.org/js.html
+//
+// Modified by Maarten Balliauw
+//
+// Usage: variable.toJSONString() and variable.parseJSON()
+// ----------------------------------------------
+(function () {
+ var m = {
+ '\b': '\\b',
+ '\t': '\\t',
+ '\n': '\\n',
+ '\f': '\\f',
+ '\r': '\\r',
+ '"' : '\\"',
+ '\\': '\\\\'
+ },
+ s = {
+ array: function (x) {
+ var a = ['['], b, f, i, l = x.length, v;
+ for (i = 0; i < l; i += 1) {
+ v = x[i];
+ f = s[typeof v];
+ if (f) {
+ v = f(v);
+ if (typeof v == 'string') {
+ if (b) {
+ a[a.length] = ',';
+ }
+ a[a.length] = v;
+ b = true;
+ }
+ }
+ }
+ a[a.length] = ']';
+ return a.join('');
+ },
+ 'boolean': function (x) {
+ return String(x);
+ },
+ 'null': function (x) {
+ return "null";
+ },
+ number: function (x) {
+ return isFinite(x) ? String(x) : 'null';
+ },
+ object: function (x) {
+ if (x) {
+ if (x instanceof Array) {
+ return s.array(x);
+ }
+ var a = ['{'], b, f, i, v;
+ for (i in x) {
+ v = x[i];
+ f = s[typeof v];
+ if (f) {
+ v = f(v);
+ if (typeof v == 'string') {
+ if (b) {
+ a[a.length] = ',';
+ }
+ a.push(s.string(i), ':', v);
+ b = true;
+ }
+ }
+ }
+ a[a.length] = '}';
+ return a.join('');
+ }
+ return 'null';
+ },
+ string: function (x) {
+ if (/["\\\x00-\x1f]/.test(x)) {
+ x = x.replace(/([\x00-\x1f\\"])/g, function(a, b) {
+ var c = m[b];
+ if (c) {
+ return c;
+ }
+ c = b.charCodeAt();
+ return '\\u00' +
+ Math.floor(c / 16).toString(16) +
+ (c % 16).toString(16);
+ });
+ }
+ return '"' + x + '"';
+ }
+ };
+
+ Boolean.prototype.toJSONString = function () {
+ return s.boolean(this);
+ };
+
+ Number.prototype.toJSONString = function () {
+ return s.number(this);
+ };
+
+ String.prototype.toJSONString = function () {
+ return s.string(this);
+ };
+
+ Object.prototype.toJSONString = function () {
+ return s.object(this);
+ };
+
+ Array.prototype.toJSONString = function () {
+ return s.array(this);
+ };
+})();
+
+String.prototype.parseJSON = function () {
+ try {
+ return !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(
+ this.replace(/"(\\.|[^"\\])*"/g, ''))) &&
+ eval('(' + this + ')');
+ } catch (e) {
+ return false;
+ }
+};
\ No newline at end of file
Index: sarissa_test.js
===================================================================
RCS file: sarissa_test.js
diff -N sarissa_test.js
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ sarissa_test.js 22 Aug 2006 08:38:11 -0000 1.1
@@ -0,0 +1,188 @@
+//this assumes you have used the JS class to include sarissa and json
+
+
+/**
+* @var object oParams the normal arguments you would use for phpgw::link
+*/
+
+
+/**
+* @var object the XMLHttpRequest object for request (may use sarissa)
+*/
+
+var xmlhttp = new XMLHttpRequest();
+
+function Airport()
+{
+ var oParams = {menuaction: 'hrm.sarissa_test.airport', id: 1};
+ xmlhttp.open('GET', phpGWLink('/index.php', oParams, true), true);
+ xmlhttp.onreadystatechange=function()
+ {
+ if (xmlhttp.readyState==4)
+ {
+ if (xmlhttp.status!=404)
+ {
+ var local=new Function("return
"+xmlhttp.responseText)();
+ alert("Code - Name\n"+local[0].id+' -
'+local[0].name);
+ }
+ else
+ {
+ alert("Airport not found");
+ }
+ }
+ }
+ xmlhttp.send(null);
+}
+
+function HelloWorld()
+{
+ var oParams = {menuaction: 'hrm.sarissa_test.HelloWorld'};
+ xmlhttp.open('GET', phpGWLink('/index.php', oParams, true), true);
+ xmlhttp.onreadystatechange=function()
+ {
+ if (xmlhttp.readyState==4)
+ {
+ if (xmlhttp.status!=404)
+ {
+ var local=new Function("return
"+xmlhttp.responseText)();
+ alert(local);
+ }
+ else
+ {
+ alert("Error");
+ }
+ }
+ }
+ xmlhttp.send(null);
+}
+
+
+function HelloWorldParams(Firstname,Lastname)
+{
+ var oParams = {menuaction: 'hrm.sarissa_test.HelloWorldParams',
firstname: Firstname, lastname: Lastname};
+ xmlhttp.open('GET', phpGWLink('/index.php', oParams, true), true);
+ xmlhttp.onreadystatechange=function()
+ {
+ if (xmlhttp.readyState==4)
+ {
+ if (xmlhttp.status!=404)
+ {
+ var local=new Function("return
"+xmlhttp.responseText)();
+ alert(local);
+ }
+ else
+ {
+ alert("Error");
+ }
+ }
+ }
+ xmlhttp.send(null);
+}
+
+function HelloWorldArray(name)
+{
+ name = escape(name.toJSONString());
+ var oParams = {menuaction: 'hrm.sarissa_test.HelloWorldArray', name:
name};
+ xmlhttp.open('GET', phpGWLink('/index.php', oParams, true), true);
+ xmlhttp.onreadystatechange=function()
+ {
+ if (xmlhttp.readyState==4)
+ {
+ if (xmlhttp.status!=404)
+ {
+ var local=new Function("return
"+xmlhttp.responseText)();
+ alert(local[0]);
+ alert(local[1]);
+ alert(local[2]);
+ }
+ else
+ {
+ alert("Error");
+ }
+ }
+ }
+ xmlhttp.send(null);
+}
+
+
+var strCurPath = '';
+
+function getFile(strFilename)
+{
+ window.location = phpGWLink('/index.php' , {menuaction:
'filemanager.bofilemanager.f_download', path : encodeURI(strCurPath), file:
strFilename});
+}
+
+function getFolder(strPath)
+{
+ if ( strCurPath == strPath )
+ {
+ return;//no need to do anything
+ }
+
+ strCurPath = strPath;
+ var xhr = new XMLHttpRequest();
+ xhr.open('GET', phpGWLink('/index.php' , {menuaction:
'filemanager.bofilemanager.load_files', path : encodeURI(strPath), sortby:
'name'}, true) );
+ xhr.onreadystatechange = function()
+ {
+ if ( xhr.readyState == 4 )
+ {
+ var elmParent =
document.getElementById('sitemgr_site_nnv_file_list');
+ while ( elmParent.childNodes.length )
+ {
+ elmParent.removeChild(elmParent.firstChild); //
+ }
+
+ if (xhr.status == 200)
+ {
+ var elmIMG, elmA, elmDIV;
+ var elmTarget = document.createElement('ul');
+
+ var iFound = 0;
+
+ var arFiles = eval(xhr.responseText);
+ var iCount = arFiles.length;
+ for ( var i = 0; i < iCount; ++i )
+ {
+ if ( arFiles[i]['mime_type'] ==
'Directory' )
+ {
+ continue;
+ }
+ ++iFound;
+ elmIMG = document.createElement('img');
+ elmIMG.src = '{mime_img_dir}' +
arFiles[i]['mime_type'].replace('\/', '-') + '.png';
+ elmIMG.alt = arFiles[i]['name'];
+
+ elmA = document.createElement('a');
+ elmA.href = 'javascript:getFile("' +
arFiles[i]['name'] + '")';
+ elmA.appendChild(elmIMG);
+
elmA.appendChild(document.createElement('br'));
+
elmA.appendChild(document.createTextNode(arFiles[i]['name']));
+
+ elmLI = document.createElement('li');
+ elmLI.className = 'file';
+ elmLI.appendChild(elmA);
+
+ elmTarget.appendChild(elmLI);
+ }
+
+ if ( iFound )
+ {
+ elmParent.appendChild(elmTarget); //
+ }
+ else
+ {
+
elmParent.appendChild(document.createTextNode('Directory Empty'));
+ }
+ }
+ else if ( xhr.status == 403 )
+ {
+ alert('ERROR: access denied!');
+ }
+ else
+ {
+ alert('ERROR: unknown!');
+ }
+ }
+ }
+ xhr.send(null);
+}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Phpgroupware-cvs] hrm/js/ajax prajax_util.js sarissa_test.js,
Sigurd Nes <=