Commit 7e307c72 authored by Melikhov Arsenii's avatar Melikhov Arsenii

Update useMany.md;

Update text from the section about SELECT to the Many attribute
parent f8fde0ad
......@@ -6,7 +6,7 @@
Imagine that we want to add to our request information about the region of the city to which that request related for.
Since one request can relate to several regions of the city, we need to have the ability of multiple choice.
For this, we need the `MANY` datatype.
For this, we need the `Many` datatype.
Let's look at how to use it.
## Creating Many datatype attribute
......@@ -37,7 +37,7 @@ First, we need to create the entity that represents the city region.
}
```
Then, in the `req_reqList` entity add an attribute of the datatype `MANY` that is associated with the `req_cityRegion` entity:
Then, in the `req_reqList` entity add an attribute of the datatype `Many` that is associated with the `req_cityRegion` entity:
```javascript
{
"name":"regionList",
......@@ -126,18 +126,16 @@ And the last step - add a new field to the `req_reqList-fm.def`:
{ attributeName: "regionList" /*Regions name*/}
```
Now, we can make the multiple select for City Regions list:
Now, we can make the multiple select for the list of city regions:
![reqListForm](img/usingMany/reqListForm.png)
## SELECT to the Many attribute
Let's consider an example of a SELECT to many datatype attribute.
Add a button to the toolbar to the list of applications, by clicking on which you can see the number of requests for the selected region.
Let's consider an example of a SELECT for `Many` datatype attribute.
Adding a button to the entitygrid panel
Change the `req_reqList` shortcut source code to the following
We need to add a button to the toolbar to the list of applications, by clicking on which we can see the number of requests for the selected region.
For adding a button change the `req_reqList` entity shortcut command code to the following:
```javascript
{
"cmdType": "showList",
......@@ -166,17 +164,28 @@ Change the `req_reqList` shortcut source code to the following
}
```
In the toolbar of the list of requests, a button will appear
---
**NOTE**
![regionListButton](img/usingMany/regionListButton.png)
:exclamation: The syntax checker for source code can produce errors. You can ignore them.
---
By clicking on this button the req_cityRegion-select form should open.
Create this form in the application
As we see, in the toolbar for the list of requests, a button has appeared:
![regionListButton](img/usingMany/regionListButton.png)
By clicking on this button the `req_cityRegion-select` form must appear.
So, let's create this form first:
![cityRegionForm](img/usingMany/cityRegionForm.png)
With the code
---
**NOTE**
:exclamation: In the `Model` field use the name of the directory that you have created in `models` directory(`models/_your_module_name_`).
---
with the following code in `Interface's definition` section:
```javascript
exports.formDef = 'request.selectRegion'
Ext.define('request.selectRegion', {
......@@ -201,30 +210,31 @@ Ext.define('request.selectRegion', {
buttons: [{
ubID: 'btnOK',
text: UB.i18n('ok'),
glyph: UB.core.UBUtil.glyphs.faSave,
iconCls: 'fa fa-save',
formBind: true
}, {
ubID: 'btnCancel',
text: UB.i18n('cancel'),
glyph: UB.core.UBUtil.glyphs.faTimes
iconCls: 'fa fa-times'
}],
initComponent: function() {
let me = this
me.callParent(arguments)
}})
}
})
```
View of form
Now we can press on button that we have created and see the following:
![cityRegionFormView](img/usingMany/cityRegionFormView.png)
Add an event to the OK button that will read the region selected in the field and search for it in the list of regions associated with the requests.
Add this code to the `initComponent function()`
To finish our task, we should add two buttons to our form.
The `Ok` button that will use regions selected in the field to find the number of requests associated with them.
And the `Cancel` button that just closes the form.
Add the following code to the `initComponent` function:
```javascript
me.down('button[ubID="btnOK"]').handler = function() {
me.down('button[ubID="btnOK"]').handler = function() {
let region = [];
region[0] = me.getForm().findField('cbxRegion').getValue()
let regionName = me.getForm().findField('cbxRegion').findRecordByValue(region[0]).get('name');
......@@ -238,21 +248,21 @@ me.down('button[ubID="btnOK"]').handler = function() {
})
}
```
And closing the form by clicking CANCEL button
```javascript
me.down('button[ubID="btnCancel"]').handler = function() {
me.down('button[ubID="btnCancel"]').handler = function() {
me.up('window').close()
}
```
`!` Note that in order to search for regions associated with requests, the condition where must be an array and the query SELECT is made not to the req_cityRegion_map table in DB, but to the original entity req_reqList that contains the attribute regionList
---
**NOTE**
As result of the script execution should be an information window that indicates how many requests there are for the selected region
:exclamation: In order to search for regions associated with requests, the query SELECT is made not to the `req_cityRegion_map` table in the DB,
but to the original `req_reqList` entity that contains the `regionList` attribute.
---
The result of our work:
![selectResult](img/usingMany/selectResult.png)
[Next step](courses/tutorial-v5/cityPortalTutorials-v5/jQuery.md)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment