Currently, templates\wffm\forms folder has Insert Options like "Form Folder" & "Form" object. This is great for people that use the base "Form" template. In my case, I've got people who'd like to use a base payment form with hidden fields and other actions I've created.
I'd like to add my custom form "MyPaymentForm" to the Insert Options so it will be on display for all form users to select as their base form. The problem is that this is a form with fields and not a template so Insert Options will not let me add it.
I'd like my payment form with base fields to be a template for each group that uses it. For example, all will use the base fields but will also have custom fields in relation to their department.
Can you recommend a way I can serve up "MyPaymentForm" to users so that it is reusable for different groups?
Thanks,
Chris
I would recommend using a Command Template to accomplish what you're asking. A Command Template is essentially a bit of custom logic that can be assigned to Insert Options.
In your case, you could create a Command Template named 'MyPaymentForm' (or whatever you come up with) and then assign that Command Template to the Insert Options field of any template/item you wish. When a user right clicks to 'Insert->' and your Command Template is available, the user can click your 'MyPaymentForm' command template and your custom code will be executed.
The action behind your command template could be as simple as creating a copy of your base form and inserting it in the content tree where the user executed the command template.
Here is an example of command template code that could accomplish what you'd like. This is completely untested, but the concept is there.
namespace MyNameSpace
{
public class CopyPaymentFormCommand : Sitecore.Shell.Framework.Commands.Command
{
public override void Execute(Sitecore.Shell.Framework.Commands.CommandContext context)
{
if (context.Items.Length == 0)
return;
Sitecore.Data.Items.Item destinationItem = context.Items[0];
if (destinationItem == null)
return;
//retrieve the base MyPaymentForm item
Sitecore.Data.Items.Item myPaymentForm = destinationItem.Database.GetItem("MyPaymentForm GUID");
if (myPaymentForm == null)
return; // instead of just exiting here, you may want to log an error first
//copy the MyPaymentForm item to the location in the content tree from which the command template was triggered
Sitecore.Data.Items.Item copyOfMyPaymentForm = myPaymentForm.CopyTo(destinationItem, "MyPaymentForm");
//perform any necessary post-processing of your newly copied item
}
}
}
After creating your custom code, you'll need to wire up Sitecore to recognize and use your command.
1. Add a "command" element to the file /App_Config/Commands.config, like so:
<command name="mycustomcommands:forms:copypaymentform" type="MyNamespace.CopyPaymentFormCommand, MyAssemblyName" />
2. Next, create a Command Template item in your /sitecore/Templates section. You can do so by right-clicking the relevant folder under /sitecore/Templates and using Insert->Insert From Template, then select the "/sitecore/Templates/System/Branches/Command Template" data template.
3. Next, in your newly created Command Template item, populate the Command field (contained in the Data section) with this text:
mycustomcommands:forms:copypaymentform(id=$ParentID)
note: the command name matches the command name defined in the Commands.config file
4. You now have a Command Template that can be assigned as an Insert Option. To do so, simply edit the __Standard Values item of any template you choose and select Assign Insert Options. In the Insert Options dialog, browse to the Command Template item you created and add it to the 'Selected' list of insert options.
Now, when a user attempts to insert a new item underneath an item with the template containing your command template insert option, they will have the option to click on your command template. Doing so will trigger your command template code, which will in turn create a copy of your payment form in the location from which the user executed the command.
For more information on command templates, see this document on the SDN (specifically, Chapter 4): http://sdn.sitecore.net/upload/sitecore6/datadefinitioncookbook-usletter.pdf
Hope this helps!
Related
I am starting to use django-tables2 and I have added a column which should allow user to delete a record when the user clicks on the button. The code looks as follows:
class ReviewTable(tables.Table):
delete = tables.LinkColumn('review_delete', args=[tables.A('pk')], orderable=False,
empty_values=(), verbose_name='')
def render_delete(self, record):
url = static('remove.png')
href = '#'
return mark_safe('')
This basically enders the image fine in a column but all I can do is set the link to it. How can I get it to call some method where I can then filter by the record ID and delete the relevant record? Is this the correct way to do this?
When you generate HTML from code, you still have access to onclick events.
return mark_safe(''.format(href, url)
Now your delete_action can be a javascript function that gives you more control. Generated HTML is basically just any old type of HTML, so you can still use jquery event handlers with it
BTW, please note how string formatting has been used in stead of concatenation. This is more pythonic
In Odoo-8 there is list view for journal items, in that there are two selection field one for account journal and second is for account period.
What I want to do
I would like to remove default value from period and journal.
I would also like to filter period in which only open period will be
loaded.
What I have done so far
I have tried to set default value for period and journal by just
setting _defaults but then filter wasn't worked.
Check the file located in:
addons/account/static/src/xml/account_move_line_quickadd.xml
This file defines the view you are referring to.
The file:
addons/account/static/src/js/account_move_line_quickadd.js
is the js file that sets the default values. If you take a look at the js file you will see that at some point the default_get method of the account_move_line model is called.
What you can do is either modify the js (by extending the widget of course)
or you can go and override the default_get method of the account_move_line model and do your work there.
In TYPO3 6.x, what is an easy way to quickly create custom content elements?
A typical example (Maybe for a collection of testimonials):
In the backend (with adequate labels):
An image
An input field
A textarea
When rendering:
Image resized to xy
input wrapped in h2
textarea passed through parseFunc and wrapped in more markup
Ideally, these would be available in the page module as cType, but at least in the list module.
And use fluid templates.
My questions:
From another CMS I am used to content item templates being applied to the BE and the FE at the same time (you write the template for what it should do, and then there's a backend item just for that type of content element) - but that's not how fluid works - or can it be done?
Is there an extension that would handle such custom content elements (other than Templavoila)?
Or do I have to create a custom extbase/fluid extension for each such field type?
And, by the way: is there a recommendable tutorial for the new extbase kickstarter? I got scared away by all that domain modelling stuff.
That scaring domain modeling stuff is probably best option for you :)
Create an extension with FE plugin which holds and displays data as you want, so you can place it as a "Insert plugin". It's possible to add this plugin as a custom CType and I will find a sample for you, but little bit later.
Note, you don't need to create additional models as you can store required data ie. in FlexForm.
From FE plugin to CType
Let's consider that you have an extension with key hello which contains News controller with list and single actions in it.
In your ext_tables.php you have registered a FE plugin:
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin($_EXTKEY, 'News', 'Scared Hello News');
When it's working fine you can add it to the list of content types (available in TCA) just by adding fifth param to the configurePlugin method in your ext_localconf.php:
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'TYPO3.' . $_EXTKEY,
'News',
array('News' => 'list, show'),
array('News' => ''),
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::PLUGIN_TYPE_CONTENT_ELEMENT // <- this one
);
Next part (basing on this site) is adding your plugin to the New Content Element Wizard as noticed in TYPO3 Wiki since TYPO3 ver. 6.0.0 changed a little, so easiest way is adding something like this into your ext_tables.php:
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig('<INCLUDE_TYPOSCRIPT: source="FILE:EXT:hello/Configuration/TypoScript/pageTsConfig.ts">');
and in /typo3conf/ext/hello/Configuration/TypoScript/pageTsConfig.ts file write add this:
mod.wizards.newContentElement.wizardItems.plugins.elements.tx_hello_news {
icon = gfx/c_wiz/regular_text.gif
title = Scared Hello News
description = Displays Scared News
tt_content_defValues.CType = hello_news
}
# Below the same for TemplaVoila
templavoila.wizards.newContentElement.wizardItems.plugins.elements.tx_hello_news {
icon = gfx/c_wiz/regular_text.gif
title = Scared Hello News
description = Displays Scared News
tt_content_defValues.CType = hello_news
}
Note that proper key tx_hello_news should be combination of lowercased tx_, $_EXTKEY and plugin name - used in registerPlugin method.
You can stop here if you are bored ;)
Bring tt_content's fields back into your CType
Above steps will cause that no typical fields will be available in the TCA for your element, so you need to copy something or create own. To see how it works just see some sample, in the backend in left menu choose ADMIN TOOLS > Configuration > TCA > tt_content > types
There you'll find all types in the system, choose the most required and copy its [showitem] node into your own. Again in ext_tables.php add this PHP array:
$TCA['tt_content']['types']['hello_news']['showitem'] = $TCA['tt_content']['types']['textpic']['showitem'];
Again: hello_news is combination of lowercased $_EXTKEY and FE plugin name...
Of course if it's required you can compose quite own set of fields, one by one by custom string:
$TCA['tt_content']['types']['hello_news']['showitem'] = '--palette--;LLL:EXT:cms/locallang_ttc.xml:palette.general;general, --palette--;LLL:EXT:cms/locallang_ttc.xml:palette.header;header';
Access the fields in Extbase Controller:
Fortunately is easiest part as you can just access it as an Array:
$currentTtContent = $this->configurationManager->getContentObject()->data;
$header = $currentTtContent['header'];
debug($currentTtContent);
debug($header);
I think http://typo3.org/extensions/repository/view/dce will do exactly what I was looking for
I own a small website that display to the users an html template (with css). Each user can change the template (customizable).
By default i have a template i copy everytime to a new user or if i get nice template (high rates) users can choose it.
instead of copying the template over and over, is there an easy way for me to create 1 template and then when the page load, it shows on the user page and then he can interact (ajax calls, href links etc...)
for example:
new user logged for the first time, the "user license agreement" shows then he click accept and his page shows up. this "home" page has forms, links, images etc... using a default template. that is the one i want to load dynamically instead of copying this template to each users.
why: i found HTML error in the page and now i need to copy this template to 127 users ... which is a pain.
i am using LAMP
thanks
yes using jQuery!
$('#divID').load('pathToHTMLTemplate') is your answer as long as you have the html file stored on same domain :)
This will fetch the html template using ajax and append its content to the div you want. It can also be 'body'.
Here is the documentation which should tell you everything you need to.
Once the template is loaded you can load the user specific data using ajax or any app server you are using. .load function provides a callback:
$('#divID').load('pathToHTMLTemplate', function(){
// now the template is loaded and you can maniupulate it further or load user specific data
});
It sounds to me (just going off of your post) that you have a directory somewhere with a bunch of files "user1.html", "user2.html" or something similar. All of these are either the same or similar, since they're basically the same template.
My recommendation:
Have a database table (or a flat file, but I recommend a database table) that maps a user ID (or name, however you have them arranged) to a template. For example, if user1 and user2 use template_default.html, but user3 uses template_popular.html, you would have the following in your database:
name|template
user1|template_default.html
user2|template_default.html
user3|template_popular.html
Then in whatever code is currently deciding which page to show the user, change it to pull the user's chosen template out of the database and display that instead. So then you only have 1 or 2 pages instead of 127.
If the user is allowed to make edits to their template, that could be stored as metadata in the table as well, then you could use substitution parameters to add it into the template.
Example:
MySQL table:
CREATE TABLE user_templates (
`user` varchar(100),
template varchar(100)
);
Upon receiving a new user:
INSERT INTO user_templates(`user`,template) VALUES("<username>","default_template.html");
Upon user choosing a new template:
UPDATE user_templates set template = "<new template>" WHERE `user` = "<username>";
Upon user loading the user's page (this done in php):
$template = "default_template.html";
$query = "SELECT template FROM user_templates WHERE `user` = \"" . mysql_real_escape_string($username) . "\"";
$result = mysql_query($query,$databaseHandle);
if ($result && mysql_num_rows($result) > 0) {
$template = mysql_result($result,0,"template");
}
// 1st way to do it
$pageToLoad = "http://www.someserver.com/templates/$template";
header("Location: $pageToLoad");
// 2nd way, if you want it embedded in a page somewhere
$directory = "/var/www/site/templates/$template";
$pageContents = file_get_contents($directory);
print "<div id=\"userPage\">$pageContents</div>";
I assume you mean that you have an HTML file that is customized for each user (look, feel, etc):
User1-theme.html
User2-theme.html
User3-theme.html
User4-theme.html
User4-theme.html
Then you would have a file that has all of your ajax calls, links, etc that you want for each user:
User-Controls.html
What you need to do is
Ensure jQuery is downloaded and included on each of your User Theme Pages.
Add this code snipplet to each of your User Theme Pages:
$("#myDiv").load("User-Controls.html")
(where #myDiv is the div ID on the template page that you want to load the controls into
and User-Controls.html is the path to the html file containing the controls you want to load
Is it possible to filter an inline autocomplete field by a dynamic value entered by a user?
For example, I have a an admin form where staff enters games information including home and visiting team, game date and time, score, etc. They also enter individual player names and stats. I would like to add a filter to show only the players on either the home or visiting team.
I am using the InlineAutocompleteAdmin module, which provides autocomplete hints for input fields.
Here is the current inline autocomplete code:
class IndividualFootballGameInline(InlineAutocompleteAdmin):
model = IndividualFootballGame
extra = 1
related_search_fields = {
'player': ('player__first_name', 'player__last_name', '#team__sport__sport=Football', '#team__season__season_start_date__year=' + str(get_current_season_start_year('football'))),
}
If this can be accomplished, can you explain how?
InlineAutocompleteAdmin provides a template that I modified to provide this functionality. The file templates/admin/autocomplete/inline_searchinput.html defines the jQuery lookup() function. I added additional code to check for values in the visiting and home teams field, and to append them to search_fields as needed.