Author: jens
Date: Wed Mar 7 09:04:26 2012
New Revision: 1297895
URL: http://svn.apache.org/viewvc?rev=1297895&view=rev
Log:
add redirect to iframe for createDoc from HTML form
Modified:
chemistry/playground/chemistry-opencmis-javascript-client/src/main/webapp/cmislib.js
chemistry/playground/chemistry-opencmis-javascript-client/src/main/webapp/index.html
chemistry/playground/chemistry-opencmis-javascript-client/src/test/resources/testcmislib.js
Modified:
chemistry/playground/chemistry-opencmis-javascript-client/src/main/webapp/cmislib.js
URL:
http://svn.apache.org/viewvc/chemistry/playground/chemistry-opencmis-javascript-client/src/main/webapp/cmislib.js?rev=1297895&r1=1297894&r2=1297895&view=diff
==============================================================================
---
chemistry/playground/chemistry-opencmis-javascript-client/src/main/webapp/cmislib.js
(original)
+++
chemistry/playground/chemistry-opencmis-javascript-client/src/main/webapp/cmislib.js
Wed Mar 7 09:04:26 2012
@@ -16,7 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
-
+function trace(text) {
+ if (window.console && window.console.log) {
+ window.console.log(text);
+ }
+}
function OperationContext() {
this.propertyFilter = "*";
@@ -44,7 +48,7 @@ function CmisSessionFactory (parameters)
};
this.getRepositories = function(cbFct) {
- console.log("getRepositories() for URL: " + this.params[PARAM_URL]);
+ trace("getRepositories() for URL: " + this.params[PARAM_URL]);
$.ajax( {
url:this.params[PARAM_URL],
dataType: "jsonp",
@@ -59,7 +63,7 @@ function CmisError (httpCode, message, c
this.cmisException = cmisException;
this.stackTrace = stackTrace;
- console.log(this.toString());
+ trace(this.toString());
};
CmisError.prototype.toString = function() {
@@ -153,7 +157,7 @@ function CmisSession(urlPrefix, reposito
cmisSelector: "repositoryInfo"
};
- console.log("getRepositoryInfo(): " + url);
+ trace("getRepositoryInfo(): " + url);
this.doJson(url, data, cbFct);
};
@@ -170,7 +174,7 @@ function CmisSession(urlPrefix, reposito
suppressResponseCodes: true
};
- console.log("getDocument(): " + url);
+ trace("getDocument(): " + url);
this.doJson(url, data, cbFct);
};
@@ -190,7 +194,7 @@ function CmisSession(urlPrefix, reposito
suppressResponseCodes: true
};
- console.log("getDocument(): " + url);
+ trace("getDocument(): " + url);
this.doJson(url, data, cbFct);
};
@@ -203,7 +207,7 @@ function CmisSession(urlPrefix, reposito
suppressResponseCodes: true
};
- console.log("deleteDocument(): " + url);
+ trace("deleteDocument(): " + url);
$.ajax( {
url: url,
data: properties,
@@ -213,12 +217,12 @@ function CmisSession(urlPrefix, reposito
};
this.createDocument = function(name, typeId, folderId, customProperties,
cbFct) {
- console.log("createDocument(), name: " + name + ", typeId: " + typeId
+ ", folderId: " + folderId);
+ trace("createDocument(), name: " + name + ", typeId: " + typeId + ",
folderId: " + folderId);
return this.create(name, typeId, folderId, customProperties,
"createDocument", cbFct);
};
this.createFolder = function(name, typeId, folderId, customProperties,
cbFct) {
- console.log("createFolder(), name: " + name + ", typeId: " + typeId +
", folderId: " + folderId);
+ trace("createFolder(), name: " + name + ", typeId: " + typeId + ",
folderId: " + folderId);
return this.create(name, typeId, folderId, customProperties,
"createFolder", cbFct);
};
@@ -261,7 +265,7 @@ function CmisSession(urlPrefix, reposito
suppressResponseCodes: true
};
- console.log("getTypeDefinition() " + url);
+ trace("getTypeDefinition() " + url);
// try cache first:
var cache = this.typeCache;
var cachedTypeDef = this.typeCache.getType(typeId);
@@ -274,7 +278,7 @@ function CmisSession(urlPrefix, reposito
// call callback function with cached type
return cbFct.call(this, cachedTypeDef);
}
- }
+ };
this.getTypeChildren = function(typeIdent, cbFct) {
var url = this.getUrl();
@@ -286,9 +290,21 @@ function CmisSession(urlPrefix, reposito
suppressResponseCodes: true
};
- console.log("getTypeDefinition() " + url);
+ trace("getTypeDefinition() " + url);
this.doJson(url, data, cbFct);
- }
+ };
+
+ this.getObjectFromTransaction = function (transId, cbFct) {
+ var url = this.getUrl();
+ var data = {
+ cmisselector: "lastResult",
+ transaction: transId,
+ suppressResponseCodes: true
+ };
+
+ trace("getObjectFromTransaction(): " + url + ", transaction-id: " +
transId);
+ this.doJson(url, data, cbFct);
+ };
this.doJson = function(urlPrefix, params, cbFct) {
$.ajax( {
@@ -317,7 +333,7 @@ CmisSession.defaultErrorHandler = functi
cmisError = new CmisError(jqXHR.status, cmisErr.message,
cmisErr.exception,
cmisErr.stacktrace);
} catch (exc) {
- console.log("Failed to parse Error as JSON: " +
jqXHR.responseText);
+ trace("Failed to parse Error as JSON: " + jqXHR.responseText);
cmisError = jqXHR.responseText;
}
}
Modified:
chemistry/playground/chemistry-opencmis-javascript-client/src/main/webapp/index.html
URL:
http://svn.apache.org/viewvc/chemistry/playground/chemistry-opencmis-javascript-client/src/main/webapp/index.html?rev=1297895&r1=1297894&r2=1297895&view=diff
==============================================================================
---
chemistry/playground/chemistry-opencmis-javascript-client/src/main/webapp/index.html
(original)
+++
chemistry/playground/chemistry-opencmis-javascript-client/src/main/webapp/index.html
Wed Mar 7 09:04:26 2012
@@ -44,7 +44,7 @@
}
function createSession(connectionUrl, repoId) {
- console.log("Initializing session to " + connectionUrl);
+ trace("Initializing session to " + connectionUrl);
var factory = new CmisSessionFactory({
url : connectionUrl,
repositoryId : repoId
@@ -52,7 +52,7 @@
session = factory.createSession();
session.getRepositoryInfo(function(repoInfos) {
- console.log("init(): getRepositoryInfo()");
+ trace("init(): getRepositoryInfo()");
for (var repoInfo in repoInfos) {
session.rootFolderId =
repoInfos[repoInfo].rootFolderId;
session.rootUrl =
repoInfos[repoInfo].rootFolderUrl;
@@ -114,7 +114,7 @@
text = "<a href='" + session.getRootUrl() +
"?cmisselector=content&objectId=" + props["cmis:objectId"].value + "' >" + text
+ "</a>"
}
row.append($('<td>').html(text));
- console.log ("add col: " + prop.value);
+ trace ("add col: " + prop.value);
} else
row.append($('<td>'));//.text("<n/a>"));
}
@@ -125,7 +125,7 @@
}
function getTypesRecursive(typeId, tbl) {
- console.log("getTypesRecursive: " + typeId );
+ trace("getTypesRecursive: " + typeId );
session.getTypeChildren(typeId, function(types) {
if (!checkError(types, "#typessection")) {
for (var i in types.types) {
@@ -136,7 +136,7 @@
row.append($('<td>').text(
types.types[i].propertyDefinitions[key].id));
}
for (var i in types.types) {
- console.log("getTypeChildren() Found type definition: "
+ types.types[i].id );
+ trace("getTypeChildren() Found type definition: " +
types.types[i].id );
getTypesRecursive(types.types[i].id, tbl);
}
}
@@ -156,25 +156,76 @@
}
function checkError(jsonObj, domId) {
- if (jsonObj != null && jsonObj.exception != null) {
+ if (jsonObj != null && jsonObj.exception) {
var cmisError = session.createErrorFromErrorResponse(jsonObj);
displayError(cmisError, domId);
return cmisError;
} else
return null;
}
+ function createRandomString() {
+ return Math.round(Math.random()*100000).toString();
+ }
+
+ function prepareCreate() {
+ // dynamically create an invisible iframe:
+ // <iframe id="createresultframeid" name="createresultframe"
style="width:0px;height:0px;visibility:hidden" onload="createDocumentDone()">
</iframe>
+ checkSession("#responsesection");
+ if (!session)
+ return false;
+
+// $('#invisibleareaid').html($('<iframe>').attr('id',
'createresultframe').attr('style', "width:0px;height:0px;visibility:hidden").
+// attr('onload', "createDocumentDone()").attr('name',
'createresultframe'));
+ $("#transactionId").val(createRandomString());
+ $("#createdochtmlid").attr("action", session.getRootUrl());
+ trace("create doc from html form with action: " +
$("#createdochtmlid").attr("action"));
+ return true;
+ }
+
+ function createDocumentDone() {
+ var transId = $("#transactionId").val();
+ var cont;
+
+ // Note that this function is called if we have a static iframe
on initial page load.
+ // This statement can be removed if we have a dynamically
created iframe on submit
+ if (!session)
+ return;
+
+ // if the server is on the same domain (same origin policy) this will
work and save you another request...
+/* try {
+ cont = $('#createresultframe').contents().text();
+ if (cont) {
+ var json = jQuery.parseJSON(cont);
+ if (!checkError(json, "#responsesection")) {
+ $("#responsesection").html("Document successfully
created with id: " + json.properties["cmis:objectId"].value + " and transaction
id: " + transId);
+ }
+ }
+ } catch (ex) {
+ // gives a permission denied exception if on another server
+ trace("Same origin policy for transaction: " + transId + ",
exception: " + ex);
+*/
+ // if the server is NOT on the same domain we will have
to do another request using the transaction id
+ trace("Creating document in transaction: " + transId);
+ session.getObjectFromTransaction(transId, function(data) {
+ if (!checkError(data, "#responsesection")) {
+ var text = "Document successfully
created with id: " + data.objectId + " and transaction id: " + transId;
+ $("#responsesection").html(text);
+ }
+ });
+// }
+ }
$(document).ready(function() {
$(document).ajaxError(function(event, request, settings, excep){
var cmisError = CmisSession.defaultErrorHandler(event, request,
settings, excep);
- displayError(cmisError);
+ displayError(cmisError, '#errorsection');
});
$('#repositories').click(function() {
var firstRepoId;
connectToRepo($("#reposfield").val(), function(repoInfos) {
- console.log("getRepositories()");
+ trace("getRepositories()");
var row;
var tbl =
$('<table>').append($('<tr>').append($('<td>').text("Found repositories:")))
.append(row = $('<tr>'));
@@ -195,7 +246,7 @@
$('#repositoryInfo').click(function() {
checkSession("#repoinfosection");
session.getRepositoryInfo(function(repoInfos) {
- console.log("getRepositoryInfo()");
+ trace("getRepositoryInfo()");
for (var repoInfo in repoInfos) {
session.rootFolderId = repoInfos[repoInfo].rootFolderId;
session.rootUrl = repoInfos[repoInfo].rootFolderUrl;
@@ -231,7 +282,7 @@
checkSession("#documentsection");
session.getDocument($('#docidfield').val(), function(doc) {
if (!checkError(doc, "#documentsection")) {
- console.log("getObject cmis:name= " +
doc.properties["cmis:name"].value);
+ trace("getObject cmis:name= " +
doc.properties["cmis:name"].value);
var text = "Retrieved document with cmis:name= " +
doc.properties["cmis:name"].value;
$("#documentsection").html(text)
}
@@ -242,7 +293,7 @@
checkSession("#documentsection");
session.deleteDocument($('#docidfield').val(), function(doc) {
if (!checkError(doc, "#documentsection")) {
- console.log("Deleted document with id: " +
$('#docidfield').val());
+ trace("Deleted document with id: " +
$('#docidfield').val());
$("#documentsection").html("Deleted document with id: "
+ $('#docidfield').val());
}
});
@@ -385,7 +436,7 @@
<div id="createdocsection">
</div>
<h3> Create a document from an HTML form: </h3>
- <form action="/inmemory/browser/A1/root" enctype="multipart/form-data"
method="post">
+ <form id="createdochtmlid" action="" target="createresultframe"
enctype="multipart/form-data" onsubmit="prepareCreate()" method="post">
<fieldset>
<legend>Create document HTML</legend>
<table>
@@ -408,14 +459,23 @@
<tr>
<td><input id="createdochtml" type="submit" value="Create
Doc!"/></td>
<td></td>
- </tr>
+ </tr>
</table>
</fieldset>
<input name="propertyId[0]" type="hidden" value="cmis:name" />
<input name="propertyId[1]" type="hidden" value="cmis:objectTypeId" />
- <input name="cmisaction" type="hidden" value="createDocument" />
+ <input name="cmisaction" type="hidden" value="createDocument" />
+ <input id="transactionId" name="transaction" type="hidden" value="" />
</form>
- <div id="createdochtmlsection">
+ <div id="responsesection">
+ </div>
+ <div id="invisibleareaid">
+ <!-- create iframe, could also be done dynamic (see above but has issues
in IE) -->
+ <iframe id="createresultframe" name="createresultframe"
style="width:0px;height:0px;visibility:hidden" onload="createDocumentDone()">
+ </iframe>
+ </div>
+
+ <div id="createfolderhtmlsection">
</div>
<h3> Create Folder (Ajax): </h3>
<form >
Modified:
chemistry/playground/chemistry-opencmis-javascript-client/src/test/resources/testcmislib.js
URL:
http://svn.apache.org/viewvc/chemistry/playground/chemistry-opencmis-javascript-client/src/test/resources/testcmislib.js?rev=1297895&r1=1297894&r2=1297895&view=diff
==============================================================================
---
chemistry/playground/chemistry-opencmis-javascript-client/src/test/resources/testcmislib.js
(original)
+++
chemistry/playground/chemistry-opencmis-javascript-client/src/test/resources/testcmislib.js
Wed Mar 7 09:04:26 2012
@@ -23,7 +23,6 @@ function checkError(jsonObj) {
function trace(text) {
console.log(text);
-
}
function getArraySize(obj) {