how to add a form to a page in alfresco - alfresco

I defined the form in the share-config-custom.xml configuration file and I have a home.ftl page. How can I associate a form definition in the configuration file with the home.ftl page?

You can retrieve configured form by the /components/form webscript, so you can use a javascript controller to inject your form in your page as mentioned in the previous answer by #vikash or you can use Spring surf to create the page, for that you can check Alfresco documentation Surf Pages.
In the definition page, make /components/form as url and url parameters as properties, as mentioned in the following example
<?xml version="1.0" encoding="UTF-8"?>
<component>
<url>/components/form</url>
<properties>
<itemKind>type</itemKind>
<itemId>contentType</itemId>
<mode>edit</mode>
<formUI>true</formUI>
<submitType>json</submitType>
<showCaption>true</showCaption>
<showCancelButton>true</showCancelButton>
</properties>
</component>
If you want to get a form for a configured type you should make type in itemKind and type name in itemId (cm:xxx)

You can open the share form using content-type
To open form
function render(htmlPageId) {
var contentType = "content_type";
var formHtmlId = htmlPageId+ "-metadata-form";
var url = YAHOO.lang
.substitute(
"{serviceContext}components/form"
+ "?itemKind=type&itemId={itemId}&mode=create&submitType=json"
+ "&formId={formId}&showCancelButton=true&htmlid={htmlid}"
+ "&destination={destination}&siteId={siteId}&containerId={containerId}&uploadDirectory={uploadDirectory}",
{
serviceContext : Alfresco.constants.URL_SERVICECONTEXT,
itemId : contentType,
itemKind : "model",
formId : "upload-folder",
destination : "workspace://SpacesStore/e9d60c89-823a-4e3e-abb2-522e59a09d0f",
siteId : "production",
containerId : "documentLibrary",
uploadDirectory : "/GM",
htmlid : formHtmlId
});
Alfresco.util.Ajax.request({
url : url,
responseContentType : "html",
execScripts : true,
successCallback : {
fn : function(response) {
var formNode = YAHOO.util.Dom.get(formHtmlId);
formNode.innerHTML = response.serverResponse.responseText;
},
scope : this
},
failureCallback : {
fn : function(response) {
Alfresco.logger.debug("onContentTypeChange failureCallback",
arguments);
},
scope : this
}
});
}
Pass your content type here in - contentType which type of form you wanted to open.
and
var formNode = YAHOO.util.Dom.get(formHtmlId);
formNode.innerHTML = response.serverResponse.responseText;
formHtmlId is the id of your html component
like
<div id="${el}-renderForm" onload="render(htmlID)">
</div>
pass your current htmlId in this funtion.

Related

AWS AppSync - DeleteItem doesn't execute response mapping template

When attempting to delete an item using the following request mapping:
{
"version" : "2017-02-28",
"operation" : "DeleteItem",
"key" : {
"id": { "S" : "$ctx.args.id"},
"sortKey" : { "S" : "$ctx.args.sortKey"}
}
}
If the item exists it will process the result through the response template, however when the item does not exist the response template is never run.
Response template:
#set($ctx.result.status = "SUCCESS")
#set($ctx.result.message = "This was a success!")
$utils.toJson($ctx.result)
I am aware that when an item does not exist in Dynamo it will perform no action but I would expect that it would still process through the template.
Is there anything I am missing or is it impossible for AppSync to processed a DeleteItem request through the response mapping when the document does not exist?
This the expected execution behavior for the version of the template you are using (2017-02-28).
You can switch your request mapping template version to 2018-05-29 and your response mapping template will be executed, with the following characteristics:
If the datasource invocation result is null, the response mapping template is executed.
If the datasource invocation yields an error, it is now up to you to handle the error. The invocation error is accessible using $ctx.error.
The response mapping template evaluated result will always be placed inside the GraphQL response data block. You can also raise or append an error using $util.error() and $util.appendError() respectively.
More info https://docs.aws.amazon.com/appsync/latest/devguide/resolver-mapping-template-changelog.html#aws-appsync-resolver-mapping-template-version-2018-05-29
So for your example:
{
"version" : "2018-05-29", ## Note the new version
"operation" : "DeleteItem",
"key" : {
"id": { "S" : "$ctx.args.id"},
"sortKey" : { "S" : "$ctx.args.sortKey"}
}
}
and response template
#if ( $ctx.error )
$util.error($ctx.error.message, $ctx.error.type)
#end
#set($ctx.result.status = "SUCCESS")
#set($ctx.result.message = "This was a success!")
$utils.toJson($ctx.result)

Error while instanciating Restivus "Cannot find name 'Restivus' "

I imported restivus using :
meteor add nimble:restivus
And while using Restivus I encounter this error on meteor startup :
"Cannot find name 'Restivus' ".
I can although GET requests but I wonder if it impacts the behavior of the app.
Here is the code used :
if (Meteor.isServer) {
// Global API configuration
var Api = new Restivus({
apiPath: 'api/',
prettyJson: true
});
}
When receiving POSTs my request.body and my bodyParams are empty :
Api.addRoute(':id/test', {
post: function () {
var id = this.urlParams.id;
console.log("Body contains : ");
console.log(this.bodyParams);
return {
status: 'success',
url : 'post test from id: '+id,
body : this.bodyParams
};
}
});
Does anyone know how to make this error disappear and if this is linked to the POST body problem ?
If you use Meteor 1.4+ you can try to import Restivus to your file with something like this:
import Restivus from 'nibmle:restivus';
The problem with post body being empty was caused by the request I made :
I wasn't specifying the Content-type header.
Once I specified the "Content-Type": "application/json" it worked.
The "Cannot find 'Restivus' " Error is still here though.
Your code looks ok. Here is some code from a server-only file that I am using:
// Global API configuration
var Api = new Restivus({
useDefaultAuth: true,
prettyJson: true,
apiPath: 'restAPI/',
defaultHeaders: { 'Content-Type': 'application/json;encoding="UTF-8"' }
});
// Generates: GET, POST on /api/items and GET, PUT, DELETE on
// /api/items/:id for the Items collection
Api.addCollection(Policy);
Perhaps you should move your code to the server directory? I am on Meteor 1.3.4.

How to use Trello API with asp.net?

I am new to using the Trello API and am using asp.net
I have built an asp.net form containing card information. I want to save the form information into Trello, as a new card, instead of storing it in my database.
First add the script key to the page:
<script type="text/javascript" src="https://api.trello.com/1/client.js?key=yourAppKeyGoesHere"></script>
Log in to Trello and go to this URL to get your Application key.
This code can be used to authorize the user with your application:
Trello.authorize({
type: "redirect",
name: "YourWebsite.com",
scope: {
read: true,
write: true,
account: true
},
error: function () { onFailedAuthorization(); },
expiration: "never"
});
function onFailedAuthorization() {
alert("Trello login failed.")
}
You can then use a function like this to Create a card in Trello:
function CreateCard(cardName, Descr, listID, dueDate)
var newCard =
{
name: cardName, desc: Descr, pos: "top", idList: listID, due: dueDate, idMembers: member.id
};
Trello.post("/cards", newCard)
The idList can be found by opening a card in the Trello List. Add .json to the URL and search the JSON for idList.
Visit the Trello API Docs for more info.

How to get site's name from WP API

I'm trying to get WordPress website title using javascript and WP API plugin
I didn't find any example on how to get the site's name but I found the variable name under the entities section in the developer guide
function _updateTitle(documentTitle) {
document.querySelector('title').innerHTML =
documentTitle + ' | '+ $http.get('wp-json/name');
}
The output string of $http.get('wp-json/name') is [object Object]
Does anyone know how to use fix this?
You didn't get enough context. What's $http? What happens when you go to wp-json/name directly in your browser? Here's what I see:
[{
"code":"json_no_route",
"message":"No route was found matching the URL and request method"
}]
Here's a simple example to get you the title:
var siteName;
$.getJSON( "/wp-json", function( data ) {
siteName = data.name;
});
See more elegant solution here https://wordpress.stackexchange.com/a/314767/94636
response will not contain extra data like:
authentication: []
namespaces: ["oembed/1.0", "akismet/v1", "acf/v3", "wp/v2"]
routes: {/: {namespace: "", methods: ["GET"],…},…}
timezone_string: ""
...
_links: {help: [{href: "http://v2.wp-api.org/"}]}

How cfs s3 uploading works

I've previously used slingshot and the process it pretty simple: we upload the image and it returns the uploaded url of the s3 bucket.
Now I want to resize the image and need to perform some operations on the image, so I switched to the cfs:s3 package. But when I try to upload the image, it returns some record with no url and in the db it stores it as:
{
"_id" : "Rwa7Xo65pv6cAP2aY",
"copies" : {
"thumbs" : {
"name" : "306032-facebook.jpg",
"type" : "image/jpeg",
"size" : 4262,
"key" : "thumbs/Rwa7Xo65pv6cAP2aY-306032-facebook.jpg",
"updatedAt" : ISODate("2015-02-14T06:44:04.476Z"),
"createdAt" : ISODate("2015-02-14T06:44:04.476Z")
}
},
"original" : {
"name" : "306032-facebook.jpg",
"updatedAt" : ISODate("2015-01-30T09:48:58.000Z"),
"size" : 4262,
"type" : "image/jpeg"
},
"uploadedAt" : ISODate("2015-02-14T06:43:59.062Z")
}
How can I get the URL from this record? (I suppose it is key in thumbs) Is it linking my server url to amazon s3 url?
What are the advantages of this method over slingshot?
How do I know the upload is completed? I can't figure out any ui helpers, are there any reactive helpers to track download percentage?
The URL will be your s3 end point (e.g. s3-us-west-2.amazonaws.com/) + the key. I suggest you to create a constant for your end point and a register helper to return the URL.
Something like this
Template.registerHelper('THUMBS_URL', function(key){
return S3_ENDPOINT + key;
})
I haven't used slingshot yet so can't comment on it.
There is a isUploaded helper function in collectionFS.
https://github.com/CollectionFS/Meteor-CollectionFS#isuploaded

Resources