Only allow creation of new ArrayInput elements in edit/create & make existing ones immutable/display only - admin-on-rest

I have been reading the docs and forum for a day and haven't found a solution to my answer. I am wondering if the following is possible with react-admin.
I have a resource documents that for which templates can be created added.
The number of templates is infinite, but once a template has been added, it shouldn't be editable or removable.
When I edit a document, I can edit it's title and description or add new templates, but I can't modify/delete the old ones.
Look at this image below for example:
Below Title, Description and Created on Date there is an ArrayInput field with the source='templates'.
The first entry corresponds to the one I already created, however its mutable.
At the bottom is a simple datagrid that shows the templates.
I either need to have a datagrid and be able to only create new templates, or have the existing entries in the ArrayInput be immutable.
Is there a clean or hacky way to achieve this?
If not, it should be a feature imo. What do you think?

This is a very specific usecase so we won't support this feature out of the box. However, as explained in the documentation, the only child accepted by the ArrayInput is an implementation of an iterator which is the component responsible for allowing add/remove and displaying the inputs. We only provide the SimpleFormIterator but you can make your own based on its source.
I think you'll probably need an iterator component accepting two render props, one for the existing items which will return fields, and another one for the new items which will return inputs. It would be used like this:
<ArrayInput source="templates">
<SimpleFormIterator
renderExisting={() => ([
<TextField source="country" />,
<TextField source="templateId" />,
<NumberField source="pages" />,
])}
renderNew={() => ([
<TextInput source="country" />,
<TextInput source="templateId" />,
<NumberInput source="pages" />,
])}
/>
</ArrayInput>

Related

How to make admin-on-rest render a custom list component?

I am using this to build a admin UX https://github.com/marmelab/admin-on-rest and it seems to fit perfectly into what I want to build except one feature:
My work project needs to display a tree grid to display groups or subgroups of items in a tree form and also to show a drop-down to display and select a grouping field.
I think this is what is needed to achieve this:
a) Write a custom "Datagrid" which I am able to write
b) Custom "List" component to show grouping combo
c) Add custom List actions to add '_grouping' parameter to the REST request
I am unable to pass my list component to 'Resource' since it breaks the whole app rending / events logic. In OO programming lingo this will be called a classic sub classing but React framework does not support it.
What would be a proper way to achieve this functionality ?
PS: I am new to react, redux, saga so please excuse me if this is already supported in admin-on-rest. I would appreciate if such feature is possible or can be added without forking the whole repo ( modifying the existing )
I don't think you need to implement a custom <List> component for that need. A replacement for <Datagrid> should to the trick. You just need to add a custom action button, and you've already localized the place to add it to (<List actions>).
Try like this first, and then if it doesn't work (but you'll have to illustrate why), I can maybe look into replacing the <List> component.

Organizing i18n source file for data binding

I have a SAPUI5 SplitApp application written in English. There is a need to add translation into another language.
I have already made changes to all my detail views using this documentation and I have used the first approach (jQuery.sap.resources). All translations are in WebContent>i18n>i18n.properties file and in another .properties file for another language. And it works.
The problematic part is my main menu that is situated on the master page. To build my main menu I use data binding approach. Here are the elements of the menu and how I bind them: JSBIN.
I still want to use data binding for the master page.
What is the best way to create/organize file with menu elements and file with translation of those elements?
I don't quite get your question.
You want to use Databinding for your controls and for your i18n - that's not a problem, just use two models and give one of them a name.
var oModel = [The model with the data]
var oModeli18n = [The i18n model]
sap.ui.getCore().setModel(oModel);
sap.ui.getCore().setModel(oModeli18n, "i18n");
Now you can bind your normal data using just the paths, e.g. in an XML-View:
<Text text="{title}" />
You can bind to the i18n model by just prefixing the path with the model name you set before:
<Text text="{i18n>SOME_TEXT}" />
You can use this approach with any type of model and choose any name you want to.
If I did not answer your question, please explain your problem in more detail.
Update:
I used your code to make a working simple example of the basic binding:
http://jsbin.com/wafecaqezu/1/edit?html,js,output
You just have to add the bundle...

Validation strategies with AngularJS

I'm evaluating AngularJS and so far I'm very enthusiastic about it. But there's something missing on the validation front: the available options, such as the built-in mechanisms and the AngularUI initiative, implement validators through directives and, as such, every validation should be declared in the view:
<form ng-controller="SomeController">
<!-- Notice the 'required' attribute directive below: -->
<input type="text" ng-model="user.name" name="uName" required />
</form>
In this example, the view is defining that user.name is required. It's like saying the view defines the proper shape of the model. Isn't it a little backwards? Shouldn't the view reflect the states, including error states when it's the case?
Am I mistaken? I'm wondering if it's possible to apply any validators in the controller, signaling the model's data as valid/invalid, and updating the view accordingly (painting form controls with red, showing error messages, clearing previous errors and so on). I'm assuming AngularJS is powerful enough for this, but in the docs and samples so far I just haven't seen anything like I've described above. Thanks!
I guess its all about perspective. The way I see it is, you are defining a view which contains a form and that form contains an input of type text. It is this text input that you are marking as required. If you note, angular does not care if the text is user.name or user.age or whatever else. Its just associating that text input with required. So its just validating that text input and the model associated with that model is the final result ( the place where the value goes in if the validation passes! ).
Have a look at
http://docs.angularjs.org/guide/forms
for custom form validations, if you want to to be doing validations that are not the default ones.
Since you already know the view that is getting produced in advance ( lets call it at compile time! ) , you can associate all validators in the view and hence wouldnt have to do it in the controller (which perhaps is for run-time validation! ).

How to specify a numeric component parameter for article selection

In setting up the parameters for my component,I want one of them to be an article ID that is opened and used. According to Joomla Standard Parameter Types, text is the only option.
Can integers be specified, or is there a way to validate the input?
As far as I know, text is your only standard solution. Joomla does, however, allow for custom parameter types. You could conceivably do one for integers, but if it's only for article selection, you can do what Joomla does for the com_content component.
Create a new folder in your admin component called: administrator\components\com_mycomponent\elements
Copy administrator\components\com_content\elements\article.php to your new folder (and index.html for security)
You can now specify a parameter type of "article" in your component as shown below, and you'll have a dropdown of your articles in the component configuration.
Be sure to include addpath to your elements folder in your "params".
<params addpath="/administrator/components/com_mycomponent/elements" />
<param type="article" name="article_id" default="0" label="Select Article" />

Validating Sitecore Item name uniqueness

For a sitecore project, I need to validate the uniqueness of item names (to avoid url overlap)
It is possible to add the 'Duplicate name' Item validation rule to the item's template (to see these options, make sure 'show standard fields' is selected in the 'view' tab, in the content editor ribbon)
However, the options available here are to add the validation rule to the
Quick Action bar
Validation Button
Workflow Validation Rules
Should I apply it as a workflow validation rule, and enable workflow (for all my content items)? That would work, but it seems like a lot of effort for the end user if they have to use workflow for something.
What I want to achieve is to simply show a validation message when the user tries to save the item (and uses a name which is already taken). Basically in the same way field validators work in sitecore
None of these choices seem to achieve this effect.
So my question is, what is the easiest way to achieve this?
Validation Bar Validation Rules - Runs in the bar to the right of the content editor.
You may want to override the item:saving event or the contenteditor:save command. Take a look at item:saved. The OnItemSaved event triggers the Rules for an item.
If you change the dialog in the content editor or update the events, you'll want to make sure that your logic applies to specific parts of the content tree - i.e. sitecore/content/home, and/or possible security role.
I agree about the amount of effort regarding workflow, but in certain cases, may make perfect sense for this and other validation requirements.
You can find a code example on SDN:
http://sdn.sitecore.net/Snippets/Item%20Handling/Validating/Validate%20a%20particular%20field%20on%20the%20Item%20save%20event.aspx
I have a blog post out for this which uses the item create / save event. This was implemented and tested with Sitecore 7.2. Here's the config used:
<sitecore>
<events>
<event name="item:creating">
<handler type="MySite.Customizations.Customized_Sitecore.UniqueItemNameValidator, MySite" method="OnItemCreating" />
</event>
<event name="item:saving">
<handler type="MySite.Customizations.Customized_Sitecore.UniqueItemNameValidator, MySite" method="OnItemSaving" />
</event>
</events>
</sitecore>

Resources