This topic will cover editing an existing record. The Edit View is a dual-purpose in that in serves as creating new records as well as updating existing records, both have unique data flows and properties.
When creating the navigation options in the previous view you have two ways to signal we are Updating an existing record:
1. Pass in options.entry
as the entry to update.
2. Pass in options.key
which will then be used to request the entry from SData and then applied as initial data.
Function Order Overview
show(options, transition options)
onShow()
refreshRequiredFor(options)
getTag()
getContext()
ReUI.show()
load()
App._beforeViewTransitionTo(view)
onBeforeTransitionTo()
- Transition happens
App._viewTransitionTo()
getTools()
createToolLayout()
transitionTo()
refresh()
clearValues()
requestTemplate()
createTemplateRequest()
onTransitionTo()
- Navigation state applied and saved
onRequestTemplateSuccess()
processTemplateEntry(template)
convertEntry(template)
setValues(values)
applyFieldDefaults()
applyContext()
Functions in Detail
show(options, transition options)
- show is called with the navigation options, first it firesonShow()
then checks to see ifrefreshRequiredFor(options)
is true and setsthis.refreshRequired = true
if it is. Then it saves the nav options tothis.options
and sets the title bar tooptions.title
if present. Lastly it callsReUI.show()
passing the transition options.this.getTag()
andthis.getContext()
.onShow()
- fired.refreshRequiredFor(options)
- If options were passed it returns true - unless theoptions.key
matchesthis.options.key
in which case it returns false.getTag()
- returns empty.getContext()
- returns an object with resourceKind set tothis.resourceKind
, insert set totrue
and key set to false.ReUI.show()
- ReUI will now handle the transition.load()
- fires.App._beforeViewTransitionTo(view)
this is at the Application (window.App) level and it handles calling the before transition functions and it clears out all the toolbars.onBeforeTransitionTo()
is fired, sincethis.options.inserting
is true it will add thepanel-loading
class to the View which shows a spinner.ReUI applies CSS transition effect
App._viewTransitionTo()
- handles all ReUI transitionTos and first gets the tools from a) view.options.tools or from view.getTools() or sets to blank {}. The tools are then passed to each toolbar by calling the toolbars showTools(tools) function.getTools()
- this calls this.createToolLayout() and passes the result to the customization engine for the tools header.createToolLayout()
- this should define and return this.tools which is an object where the keys are the names of the toolbars and the values are array of toolbar item definitions.transitionTo()
- the transition effect has now finished and you will see an empty Detail screen. This functions checks if this.refreshRequired is true and if it is, sets it to false and calls this.refresh().refresh()
- All the magic happens here for Edit views. First it clears the following properties:this.entry
;this.changes
;this.inserting
- tothis.options.insert
or false; andcalls
clearValues()
which loops through all thethis.fields
and calls therefield.clearValue()
.Now it checks if we have a passed entry via
this.options.entry
and if we do to callprocessEntry(entry)
and then check for changes and callsetValues(changes)
as dirty data. If instead we were passed a key viathis.options.key
we make a request:requestData()
.
requestData()
- creates a request viathis.createRequest()
and callsrequest.read()
sending success toonRequestDataSuccess
and failures toonRequestDataFailure
.createRequest()
- anSage.SData.Client.SDataSingleResourceRequest
is created using the following properties:this.entry['$key'] or this.options['key']
=>request.setResourceSelector
this.contractName
=>request.setContractName
this.resourceKind
=>request.setResourceKind
this.querySelect
=>request.setQueryArg
this.queryInclude
=>request.setQueryArg
this.queryOrderBy
=>request.setQueryArg
onTransitionTo()
- firesNavigation state is cleaned up and saved to local storage
onRequestDataSuccess(entry)
- is passed with the entry and simple passes it on toprocessEntry
, then it appliesthis.options.changes
as modified data. Now it meets up as if we had passed an entry via navigation options.processEntry(entry)
- setsthis.entry
to the entry and callssetValues(changes, true)
(unmodified data) and removes thepanel-loading
set earlier.setValues(values, initial)
- it loops over thethis.fields
if the field is hidden (by checkingfield.isHidden()
) it is skipped. If a field hasapplyTo
defined it tries to get theapplyTo
property out of the suppliedvalues
, else it tries thefield.property
(orfield.name
if property is not defined). If a value is found it is then applied to the field viafield.setValue(value, true)
meaning it is an initial - "clean" value.Edit View is now finished loading and is fully interactive.
Properties
this.fields
- object where each key is a fieldsname
and the value being the corresponding field.this.options
- the navigation options, where you will findentry
,template
,changes
,insert
, and other values to base decisions off of.this.entry
- the entry, either requested or the passed in options.this.domNode
- the main<div>
element of the Edit View.