I have a survey form I would like an admin to be able to add more questions to on the fly. The way I'm thinking of doing this is to have the admin add questions to a Questions collection with several properties e.g:
{
"description" : "desc",
"fieldType" : "textField",
"sortOrder" : 1,
"dataType" : "text",
"_id" : "eFopP8XFgY8Br93fA"
}
and then on the client side, loop through these using an #each block and a dynamic template like so:
{{#each questions}}
{{>Template.dynamic template=fieldType}}
{{/each}}
Now the "fieldType" field would correspond to the name of a stored template e.g
<template name="textField">
<div>
<input id="{{_id}}" type="{{dataType}}" class="validate">
<label for="{{_id}}">{{description}}</label>
</div>
</template>
and inside these templates would have different input fields depending on the type.
I have two issues:
Is this a good way to go about this problem?
If it is, how would you be able to get the values of these input fields when saving the answers (as we don't know what fields could be there at compile time)
Regarding your first question, I agree with #Kyll regarding autoform and I think you can pass the schema as a json object dynamically.
Regarding your 2nd question, please check SO question Dynamically add form fields in meteorjs where you will find answer to your second question. You can easily grab value of all fields in your dynamically created form using .serializeArray() JQuery serializeArray
Related
So I have an easy-search template as such:
{{> EasySearch.Autosuggest index=PlayersIndex labelField="Player" valueField="Team"}}
My index is defined as:
export const PlayersIndex = new Index({
collection: Stocks,
fields: ['Player', 'Team'],
engine: new MinimongoEngine(),
});
And I want the autosuggest box to display both the Player and the Team. Right now it just shows the Player. How can I achieve this?
You should first visit the autosuggest's documentation which is pretty short. From there it's pretty clear that only the first member of the fields array (in your case "Player") is chosen as the value to present when searching. To change this behavior you can pass a different template through the renderSuggestion parameter that EasySearch.Autosuggest seems to accept. By default it's using the
EasySearch_Autosuggest_DefaultRenderSuggestion template which you can find here. You can just create your own template in one of your files
<template name="playerTeamAuto">
<div>
<span class="autosuggest-title">
<span class="name">{{label}}</span>
<span class="teamName">{{doc.Team}}</span>
</span>
</div>
</template>
This will work only for your set of results where the returned documents would have a guranteed field of Team that's why we can access it through the doc variable. This comes from the object that the template is rendered with here on this specific line. As you can see it has all the data fields returned through the form of item, as even the label is gotten from there. I've added a between the player and team name, but you can format them any way you want.
I want to add a text field for each file that is added to the attached package items in alfresco to write notes regarding each file, is it possible to do?
I have implemented something that could be reused for your use case.
You can define a property with multiple values that will contain the list of notes associated with each attachment.
There is a simple trick to post a property with multiple values: add "[]" to the name of the property. For example:
<input id="template_x002e_edit-metadata_x002e_edit-metadata_x0023_default_prop_someco_notes_0"
name="prop_someco_notes[]"
tabindex="0"
type="text"
value="Meeting minutes"
title="Notes"
noderef="workflow://...."
>
<input id="template_x002e_edit-metadata_x002e_edit-metadata_x0023_default_prop_someco_notes_1"
name="prop_someco_notes[]"
tabindex="1"
type="text"
value="Meeting minutes"
title="Notes"
noderef="workflow://...."
>
As you can see, the name of the input ends with []. Both input textfields have the same name.
The Alfresco Form Engine will consider these two inputs as the value for the property with multiple values: "someco:notes".
The bigger problem is that you need to generate this html with some smart javascript and free marker template.
You can write a custom free marker template to render the initial html: if a user opens a task on which documents have been already attached, you will need to generate the list of inputs using a custom control (you can of course start from textfield.ftl).
It won't be easy to generate the initial list because unfortunately Alfresco returns the list of values as a single comma separated value.
You can customise the webscript that injects the model in the free marker template "org.alfresco.web.scripts.forms.FormUIGet" to pass an array instead of a csv.
A quicker and dirtier solution is to split the csv value. In share-config-custom.xml, you can specify what textfield.ftl show use as a separator instead of the comma.
When a user adds/remove elements from the package, you can intercept the update and add/remove the correspondent note. Notice that I have added the filed "noderef" to each input so it is possible to know the relation between the notes and the nodes in the package.
UPDATE:
For the associations (used for example to define the package in a workflow task), Share uses a javascript library called "object finder" (or "object picker"). This library fires an event called "formValueChanged" that you can intercept:
YAHOO.Bubbling.fire("formValueChanged",
{
eventGroup: this,
addedItems: addedItems,
removedItems: removedItems,
selectedItems: selectedItems,
selectedItemsMetaData: Alfresco.util.deepCopy(this.selectedItems)
});
I have a unique requirement by my company to have a page for each sub-folder in a particular folder of alfresco share. So basically there would be hundreds of sub-folders and corresponding hundreds of pages representing it. The page for that folder should have links to its sub-folders and maybe even documents within it in the form of a collapsible list as shown:
Folder 1
-Category 1
Doc 1
Doc 2
-Category 2
-Sub-category 1
doc 3
I want to have something like shown above on one side of the page and the other side should have all the recent activities related to the folder, like who added a doc, what edits were made, were there any comments, etc. I searched a lot related to this but I am not sure if alfresco supports this kind of customization. I found some really good tutorials on creating custom pages in share using JSON widgets but don't think it would help in this case. Other option would be generate an html page for every new folder created and populate it using javascript. But this method won't have much flexibility in terms of designing the page. Does anyone know of a better approach or idea for this requirement ? I would really appreciate any thoughts on this.
I'll just write it as an answer (relating to my previous comment). I've done something similar in this way (using the link provided in the comments:
create a simple alfresco web script that returns a json of what you need (in you case recently modified documents). I've done it with listing a folder, this is mywebscript.get.json.ftl:
{
"docprop" : [
<#list companyhome.childByNamePath["MyFolder"].children as child>
{
"name" : "${child.properties.name}" ,
"author" : "${child.properties["cm:author"]}",
"CreatedDate" : "${child.properties.created?datetime}"
}
<#if child_has_next> , </#if>
</#list>
]
}
create Share widget controller file where you call this web script with retrievedoc.get.js:
var connector = remote.connect("alfresco");
var data = connector.get("/mywebscript.json"); //the url is declared in your `mywebscript.get.desc.xml`
// create json object from data
var result = eval('(' + data + ')');
model.docprop = result["docprop"];
create Share widget presentation template with retrievedoc.get.html.ftl:
<div class="dashlet">
<div class="title">${msg("header.retrievedocTitle")}</div>
<div class="body retrievedoc">
<table>
<tr>
<th>Name: </th>
<thAuthor: </th>
<th>Created: </th>
</tr>
<#list docprop as t>
<tr>
<td>${t.name}</td>
<td>${t.author}</td>
<td>${t.CreatedDate}</td>
</tr>
</#list>
</table>
</div>
You then need to register your widget in Share, and use it in your dashboard. It will call the Alfresco script and populate the widget with the results. Obviously you need to change your Alfresco script to return recent activities (you could make a query like: all documents modified in the last 24 hours, or something like this. But the method is the same.
Hope it helps.
You could create new folder tree component in alfresco share to meetup your requirement.
Alfresco share page madeup of multiple comoponents which are kind of self sufficient components in terms of data and dependancy(Excluding few alfresco common dependancy).
Here is the outline for the approch
Create one folder tree comopnent in alfresco, which will be nothing
but a webscript which render related webscripts output on page in
which component is included.
Create one Dynamic YUI tree with some dummy data and check weather
you are able to generate or not.(Just to make sure you have all
depenency included).
Create one data webscript on repository side which will fetch folder
structure related data from repository.Make it in such way that if
you pass folder noderef if will return all childrens under
that.There is one similar webscript also avilable out of box may be
you could reuse that.
Once you have that webscript working properly call that repository
webscript to populate your dynamic tree and remove all dummy data.
I hope this gives you good starting point.
You will certainly find documentation for each of these steps.
I am rather new to Symfony (2 weeks) so forgive my ignorance.
I am trying to add a custom action button that will link to a pre filtered list of a RELATED entity. I have done a lot of research but can't quite seem to find what I need.
Currently I have two entities Books and Authors with a manyToOne relation ship.
I have these set up in Sonata Admin in the usual way and all works well. I even have an author filter on the book list page which I am hoping can be leveraged to accomplish my goal.
In the Author list view, I would like to add an action button on each row next to View and Edit, called "View Books By Author". I can get the button but fail to correctly build the URL.
I have 3 issues with the routing:
1) I am trying to use admin.generateObjectUrl() or similar in my button template to cleanly build an admin URL but can't get a path to an alternate entity. In my case, since I am currently viewing authors, the links always point to the author entity not books as I would like.
2) I am uncertain how to get the id of the current author in order to pass it to the filters
3) I am uncertain how to cleanly build the filter query string parameters. I could do it by hand if necessary: bookEntityListPath + "?filter[author][value][]=" + $authorID
But obviously this is not that clean and I would prefer a better method if possible.
Thanks in advance!!!
I had the same issue and started trying out some code when I could not find an answer. Using the path() twig method (route to path conversion) it is quite easy to create a link like that.
See this documentation: http://symfony.com/doc/current/book/routing.html#generating-urls-from-a-template
Your link would look something like this:
<a href="{{ path('admin_application_book_list', {
'filter[author][value]': object.id
}) }}" class="btn btn-small">
With 'admin_application_book_list' being the path to the list of books (bookEntityListPath?) and object.id being the id of your author (would have the name object in a detail or edit template of that entity)
The question is: how to display complex documents returned from Mongodb.
Suppose I have two projects in my Projects collection and each project has 2 People embedded by their IDs from the People collection.
Project.find() returns this CURSOR which I'm presenting as JSON for readability:
{ "_id" : "5ed5ade8-c140-46f7-8d9e-2344fc53df8e", "name" : "Project1", "personnel" : [ "b4690c4b-d126-4737-8f40-921234567890", "977a6335-a1be-4af5-8b3f-4abcdefghijk" ] }
{ "_id" : "23f073c7-a713-4713-86a7-7d6600433146", "name" : "Project2", "personnel" : [ "b4690c4b-d126-4737-8f40-92b43072d7a1", "977a6335-a1be-4af5-8b3f-48cd5f8328db" ]}
My template in .html file:
<template name="theProjects">
{{#each theTitles}}
Name: {{name}}
Personnel: {{personnel}}
{{/each}}
</template>
renders this in the browser:
Name: Project1
Personnel: b4690c4b-d126-4737-8f40-921234567890,977a6335-a1be-4af5-8b3f-4abcdefghijk
Name: Project2
Personnel:b4690c4b-d126-4737-8f40-92b43072d7a1,977a6335-a1be-4af5-8b3f-48cd5f8328db
Questions:
The {{personnel}} field is simply being filled in by the contents of the personnel array in the Projects collect. I want to list these separately on their own line. Can't figure that out. Just slicing won't do because...
The greater need clearly is to be able to manipulate and edit the Personnel data so the template has to be properly Meteor reactive.
Now the hard one: the personnel ID's from the People collection are embedded in the Project documents. How would I use Meteor to replace the ID's with the appropriate names from the Personnel collection and still keep their data reactivity?
I know this is a lot to ask but these kind of things seem like they are foundational to bigger and more complex web site.
Thanks everyone.
https://gist.github.com/3220991
This is a gist I made to show you use the of Handlebars helpers. This will stay reactive and is very easy to use. I hope you can use it.
If you need more help or comments , just mention me.