SAP UI5 value help only for Smartfield - sapui5

I have a smartfield that has a value-list annotation.
I would like it to behave such that text input is disabled for the field so the user is forced to open the value help when he clicks on the field, and select from a valid list - much like the valueHelpOnly property of sap.m.Input. I was looking for a similar property for smartfield but there isn't seem to be one?
If there's no standard property for this, what's the best way to validate input vs valid value help values for smartfields?
Thanks in advance.

You need to do the following steps. Assume you defined the SmartField like this:
<smartField:SmartField value="{XXX}" textInEditModeSource="ValueList" innerControlsCreated="onControlCreated">
<smartField:configuration>
<smartField:Configuration preventInitialDataFetchInValueHelpDialog="false" displayBehaviour="idAndDescription"/>
</smartField:configuration>
</smartField:SmartField>
Of course you have defined the needed annotation that shows the value list itesm. Something like this:
<Annotations Target="Metadata.YourEntityName/XXX">
<Annotation Term="Common.Text" Path="Planttxt">
<Annotation Term="UI.TextArrangement" EnumMember="UI.TextArrangementType/TextLast"/>
</Annotation>
<Annotation Term="Common.ValueListWithFixedValues" Bool="false"/>
<Annotation Term="Common.ValueList">
<Record>
<PropertyValue Property="CollectionPath" String="XxxSet"/>
<PropertyValue Property="Parameters">
<Collection>
<Record Type="Common.ValueListParameterInOut">
<PropertyValue Property="LocalDataProperty" PropertyPath="XXX"/>
<PropertyValue Property="ValueListProperty" String="Id"/>
</Record>
<Record Type="Common.ValueListParameterDisplayOnly">
<PropertyValue Property="ValueListProperty" String="Name"/>
</Record>
</Collection>
</PropertyValue>
</Record>
</Annotation>
</Annotations>
We defined a innerControlsCreated="onControlCreated" handler, we need to provide the code for that in related controller:
/**
* event fired by innerControlsCreated of SmartField
* #param {sap.ui.base.Event} oEvent pattern match event
*/
onControlCreated: function (oEvent) {
if (oEvent.getParameters()[0] instanceof sap.m.Input && oEvent.getParameters()[0].getShowValueHelp()) {
// set ValueHelpOnly for Inputs with ValueHelp
oEvent.getParameters()[0].setValueHelpOnly(true);
}
},

I have a work around, if any one has a better solution then kindly suggest me
Add a class to you SmartField and using the class get the ID and add disabled attribute to the SmartField input tag
var sSmrtFldId = "#" + jQuery(".CustomSmrtFldClass").attr("id") + ".sapMInputBaseInner";
jQuery(sSmrtFldId).attr("disabled ", true);

You have to use the Event innerControlsCreated of SmartField, then check if is a Input and call the method setValueHelpOnly(true)
onInnerControlsCreated: function (oEvent){
oEvent.getParameters()[0].setValueHelpOnly(true);
}
Note: This code is a sample, you need to check if is a Input and avoid hard code the index access on the array of parameters.

Related

Annotations are not used in Fiori Elements List Report with TreeTable

I have created a Fiori Elements List Report and set the table type to TreeTable. The table is displayed as a TreeTable but every entity is displayed as a root entity in the table and the following error is in the log: "Neither navigation paths parameters, nor (complete/valid) tree hierarchy annotations where provided to the TreeBinding.".
The OData service is based on the following projection view:
#Metadata.allowExtensions: true
#ObjectModel.representativeKey: 'Element'
#ObjectModel.dataCategory: #HIERARCHY
#Hierarchy.parentChild: [
{ recurse.child: ['Element'],
recurse.parent: ['ParentElement'],
recurseBy: '_ParentElement',
multipleParents: true,
siblingsOrder: [{by: 'Element', direction: #DESC}],
orphanedNode.handling: #ROOT_NODES
}
]
define root view entity ZC_Element
as projection on ZI_Element
{
#ObjectModel.foreignKey.association: '_Element'
key Element,
ParentElement,
ChildNode,
ParentNode,
HierarchyLevel,
HierarchyTreeSize,
HierarchyRank,
HierarchyParentRank,
HierarchyIsOrphan,
HierarchyIsCycle,
HierarchyDrillState,
CreatedBy,
CreatedAt,
LastChangedBy,
LastChangedAt,
_Element,
_ParentElement
}
The hierarchy, which is at the basis of the views, is as followed:
define hierarchy ZHI_ElementHierarchy
as parent child hierarchy(
source ZHI_ElementRelation
child to parent association _ParentElement
start where
ParentElement is initial
siblings order by
Element
multiple parents allowed
orphans root
)
{
#ObjectModel.foreignKey.association: '_VirtualDirectory'
key Element,
_Element,
ParentElement,
_ParentElement,
$node.parent_id as ParentNode,
$node.node_id as ChildNode,
$node.hierarchy_is_orphan as HierarchyIsOrphan,
$node.hierarchy_level as HierarchyLevel,
$node.hierarchy_rank as HierarchyRank,
$node.hierarchy_parent_rank as HierarchyParentRank,
$node.hierarchy_tree_size as HierarchyTreeSize,
$node.hierarchy_is_cycle as HierarchyIsCycle,
CreatedBy,
CreatedAt,
LastChangedBy,
LastChangedAt
}
The metadata file of the OData service does not contain any hierarchy annotations. I have also attempted to add the following annotations manually to the annotations.xml file but this does not have any effect either:
<Annotations Target="cds_zsd_elements.ElementType">
<Annotation Term="UI.LineItem">
<Collection>
<Record Type="UI.DataField">
<PropertyValue Property="Value" Path="Element"/>
<PropertyValue Property="sap:hierarchy-node-for" Path="Element"/>
</Record>
<Record Type="UI.DataField">
<PropertyValue Property="Value" Path="ParentElement"/>
<PropertyValue Property="sap:hierarchy-parent-node-for" Path="Element"/>
</Record>
<Record Type="UI.DataField">
<PropertyValue Property="Value" Path="HierarchyLevel"/>
<PropertyValue Property="sap:hierarchy-level-for" Path="Element"/>
</Record>
<Record Type="UI.DataField">
<PropertyValue Property="Value" Path="HierarchyDrillState"/>
<PropertyValue Property="sap:hierarchy-drill-state-for" Path="Element"/>
</Record>
</Collection>
</Annotation>
</Annotations>
I have used the projection view in an ABAP program with ALV TreeTable as well and the output is displayed correctly, so the hierarchy and data seems to be correct. What can I do to get the hierarchy annotations correct?

Sulu: error when trying to use custom data provider

I'm following docs from here: https://docs.sulu.io/en/2.2/cookbook/smart-content-data-provider.html
Trying to make custom data provider for my custom entity type "MatchEvent":
I did it how it's explained here. Since I have services.yaml file I defined those 2 like this:
app.match_event_repository:
class: App\Repository\MatchEventRepository
factory: ['#doctrine', 'getRepository']
arguments:
- Symfony\Bridge\Doctrine\ManagerRegistry
app.smart_content.data_provider.matchevent:
class: App\SmartContent\MatchEventDataProvider
arguments: ['#app.match_event_repository', '#sulu_core.array_serializer', '#request_stack' ]
tags: [{name: 'sulu.content.type', alias: 'smart_matchevent_selection'}]
So, if I understood well, after that I should have my custom content data provider named "smart_matchevent_selection" and I can use it like this:
<property name="match" type="smart_content">
<meta>
<title lang="en">Match</title>
<title lang="de">Match</title>
</meta>
<params>
<param name="provider" value="smart_matchevent_selection"/>
</params>
</property>
But when I try to edit page containing this field I get error:
Missing parameter token in Sulu\Bundle\PreviewBundle\Controller\PreviewController
Exception is triggered at project/vendor/sulu/sulu/src/Sulu/Bundle/PreviewBundle/Controller/PreviewController.php:
public function stopAction(Request $request): Response
{
$this->preview->stop($this->getRequestParameter($request, 'token', true));
return new JsonResponse();
}
What I'm doing wrong here?
If you carefully look at the service definition of the SmartContentDataProvider in the documentation, you will notice that the tag should be {name: 'sulu.smart_content.data_provider', alias: 'match_events'} instead of {name: 'sulu.content.type', alias: 'smart_matchevent_selection'} ...
Then you can use it like <param name="provider" value="match_events"/>

Extending Modx modResource schema errors

I'm trying to extend the modx modresource object, but keep getting errors & I can't seem to figure out why. It is related to the schema (I think) but everything looks correct.
Schema:
<?xml version="1.0" encoding="UTF-8"?>
<model package="extresource" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" tablePrefix="modx_" version="1.0.0">
<object class="extResource" extends="modResource">
<composite alias="ResourceData" class="ResourceData" local="id" foreign="internalKey" cardinality="one" owner="local"/>
</object>
<object class="ResourceData" table="resource_data" extends="xPDOSimpleObject">
<field key="internalKey" dbtype="int" precision="11" phptype="integer" null="false" attributes="unsigned"/>
<field key="views" dbtype="int" precision="11" phptype="integer" null="true" />
<field key="starred" dbtype="int" precision="10" phptype="integer" null="false" />
<index alias="internalKey" name="internalKey" primary="false" unique="true" type="BTREE" >
<column key="internalKey" length="" collation="A" null="false" />
</index>
<aggregate alias="Resource" class="modResource" local="internalKey" foreign="id" cardinality="one" owner="foreign"/>
</object>
</model>
I'm testing it using:
$resource = $modx->getObject('modResource', 11112);
echo $resource->get('pagetitle'); //test I have the resource
$data = $resource->getOne('ResourceData');
The errors I get are:
Could not getOne: foreign key definition for alias ResourceData not
found. No foreign key definition for parentClass: modDocument using
relation alias: ResourceData
The table exists & has data, the package is registered in the modx extension packages. I've been over the schema many times & it looks right.
What is causing these errors?
You have to use the right object class in $modx->getObject. Otherwise you will get a modResource object, that does not know the extended object data and relationship.
$resource = $modx->getObject('extResource', 11112);
Does the resource you are loading have its class_key field set to extResource? That's needed for it to load the right resource object class.

OpenERP 7 - Add another status to account.invoice workflow

I wanted to add another status ("advanced") to account.invoice's workflow, between "open" and "paid".
So I inherited the module with
class advance_invoice_workflow(osv.osv) :
_name = 'account.invoice'
_inherit = "account.invoice"
_columns = {
'state': fields.selection([
('draft','Draft'),
('proforma','Pro-forma'),
('proforma2','Pro-forma'),
('open','Open'),
('advanced','Advanced'),
('paid','Paid'),
('paid_advanced','Paid advanced'),
('cancel','Cancelled'),
],'Status', select=True, readonly=True, track_visibility='onchange',
help='* The \'Draft\' status is used when a user is encoding a new and unconfirmed Invoice. \
\n* The \'Pro-forma\' when invoice is in Pro-forma status,invoice does not have an invoice number. \
\n* The \'Open\' status is used when user create invoice,a invoice number is generated.Its in open status till user does not pay invoice. \
\n* The \'Paid\' status is set automatically when the invoice is paid. Its related journal entries may or may not be reconciled. \
\n* The \'Cancelled\' status is used when user cancel invoice. \
'),
}
and declared the status in the XML file by making
<record id="act_advanced" model="workflow.activity">
<field name="wkf_id" ref="account.wkf" />
<field name="name">advanced</field>
<field name="kind">function</field>
<field name="action">set_advanced()</field>
</record>
So I have two transitions:
the first one from open to advanced,
<record id="t2" model="workflow.transition">
<field name="act_from" ref="account.act_open" />
<field name="act_to" ref="act_advanced" />
<field name="trigger_model">account.move.line</field>
<field name="trigger_expr_id">move_line_id_payment_get()</field>
<field name="condition">test_advanced()</field>
<field name="signal">button_confirm_advance</field>
</record>
the second one from advanced to paid
<record id="t1" model="workflow.transition">
<field name="act_from" ref="act_advanced"/>
<field name="act_to" ref="account.act_paid"/>
<field name="trigger_model">account.move.line</field>
<field name="trigger_expr_id">move_line_id_payment_get()</field>
<field name="condition">test_paid()</field>
</record>
From an external module, that does not inherit from account.invoice, but that refers to it, I want to send the signal to the workflow to move from "act_open" to "act_advanced".
So I added a button with name="button_confirm_advance" that binds this action:
def button_confirm_advance(self,cr,uid,ids,context=None):
context = context or {}
for invoice in self.browse(cr,uid,ids,context=context):
wf_service = netsvc.LocalService("workflow")
self.write(cr, uid, [invoice.id],{})
wf_service.trg_validate(uid,'account.invoice',invoice.id,'button_confirm_advance',cr)
return {'type': 'ir.actions.act_window_close'}
All variables are correct, but the trg_validate returns False.
What am I wrong?
Thanks,
Patrizio
I solved delegating the flowchart management to another class that inherits from account.invoice
class advance_invoice_account_ui(osv.osv) :
_name = 'account.invoice'
_inherit = "account.invoice"

Orbeon control details in own component

I'm making my own component, and I want to have oportunity to set some properties in form builder. In all I want to reach effect similar to autocomplete control, where I can set 3 properties (URI, xpath, and relative xpath). I read, that I can do it using control-details markup, but unfortunately it does not work. This is code (I working on davinci tutorial):
<xbl:binding element="fr|tutorial-davinci" id="fr-tutorial-davinci" xxbl:mode="lhha binding value">
<metadata xmlns="http://orbeon.org/oxf/xml/form-builder" xmlns:xf="http://www.w3.org/2002/xforms">
<display-name lang="en">davinci-modified</display-name>
<templates>
<instance label=""/>
<view>
<fr:tutorial-davinci id="" appearance="minimal" labelref="#label" xmlns="" resource="" >
<xf:label ref=""/>
<xf:hint ref=""/>
<xf:help ref=""/>
<xf:alert ref=""/>
</fr:tutorial-davinci>
</view>
</templates>
<control-details>
<xf:input>
<xf:label lang="en">Some param</xf:label>
</xf:input>
</control-details>
</metadata>
<xbl:template>
<xf:model>
<xf:instance id="id1"><value/></xf:instance>
</xf:model>
<xf:input ref="instance('id1')" />
</xbl:template>
</xbl:binding>
You must have a ref attribute on<xf:input> which points to an attribute or element where the information will be stored. In autocomplete.xml, there is in particular theresource` attribute, which:
is pointed to by <xf:input>
is present on the <fr:autocomplete> template