From 0f0a1719f426203f12be8b0363bcde61c6bb3a54 Mon Sep 17 00:00:00 2001 From: Sebastian Listl <s.listl@adito.de> Date: Thu, 27 Aug 2020 14:55:00 +0200 Subject: [PATCH] Attribute sorting fixed --- entity/Attribute_entity/Attribute_entity.aod | 6 ++++- .../attributechildren/documentation.adoc | 4 +++ entity/Attribute_entity/onValidation.js | 25 ------------------- .../recordcontainers/jdito/onInsert.js | 14 +++++++++-- .../AttributeList_view/AttributeList_view.aod | 3 +++ 5 files changed, 24 insertions(+), 28 deletions(-) create mode 100644 entity/Attribute_entity/entityfields/attributechildren/documentation.adoc delete mode 100644 entity/Attribute_entity/onValidation.js diff --git a/entity/Attribute_entity/Attribute_entity.aod b/entity/Attribute_entity/Attribute_entity.aod index d6f3d3eec9d..07f9d8460ea 100644 --- a/entity/Attribute_entity/Attribute_entity.aod +++ b/entity/Attribute_entity/Attribute_entity.aod @@ -7,7 +7,6 @@ <grantDeleteProcess>%aditoprj%/entity/Attribute_entity/grantDeleteProcess.js</grantDeleteProcess> <contentTitleProcess>%aditoprj%/entity/Attribute_entity/contentTitleProcess.js</contentTitleProcess> <afterUiInit>%aditoprj%/entity/Attribute_entity/afterUiInit.js</afterUiInit> - <onValidation>%aditoprj%/entity/Attribute_entity/onValidation.js</onValidation> <iconId>VAADIN:TAG</iconId> <titlePlural>Attributes</titlePlural> <recordContainer>jdito</recordContainer> @@ -390,6 +389,7 @@ <entityProvider> <name>AttributeChildren</name> <sortingField>SORTING</sortingField> + <documentation>%aditoprj%/entity/Attribute_entity/entityfields/attributechildren/documentation.adoc</documentation> <titlePlural>Child Attributes</titlePlural> <dependencies> <entityDependency> @@ -433,6 +433,10 @@ <valueProcess>%aditoprj%/entity/Attribute_entity/entityfields/attributechildren/children/getonlyfirstlevelchildren_param/valueProcess.js</valueProcess> <expose v="false" /> </entityParameter> + <entityParameter> + <name>ParentId_param</name> + <mandatory v="true" /> + </entityParameter> </children> </entityProvider> <entityConsumer> diff --git a/entity/Attribute_entity/entityfields/attributechildren/documentation.adoc b/entity/Attribute_entity/entityfields/attributechildren/documentation.adoc new file mode 100644 index 00000000000..f9ca1e5e225 --- /dev/null +++ b/entity/Attribute_entity/entityfields/attributechildren/documentation.adoc @@ -0,0 +1,4 @@ += AttributeChildren + +This provider can be used to get all child Attributes of a given parent. It is intended for displaying and editing the childs of an Attribute in the +Attribute context and allows to sort them. Only the direct children are returned. \ No newline at end of file diff --git a/entity/Attribute_entity/onValidation.js b/entity/Attribute_entity/onValidation.js deleted file mode 100644 index f1b6c7fc1f4..00000000000 --- a/entity/Attribute_entity/onValidation.js +++ /dev/null @@ -1,25 +0,0 @@ -import("system.translate"); -import("system.db"); -import("system.vars"); -import("system.text"); -import("system.neon"); -import("Sql_lib"); - -//TODO: this should no happen in onValidation; waiting for #1032668 -if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW) -{ - var parentId = vars.get("$field.ATTRIBUTE_PARENT_ID"); - if (parentId) - { - var maskingHelper = new SqlMaskingUtils(); - var newCodeNumber = newSelect(maskingHelper.max("AB_ATTRIBUTE.SORTING")) - .from("AB_ATTRIBUTE") - .where("AB_ATTRIBUTE.ATTRIBUTE_PARENT_ID", parentId) - .cell(); - - newCodeNumber = Number(newCodeNumber);//if no number exists till no, start value will be 1 (due to: ++0) - if (isNaN(newCodeNumber)) - throw new TypeError(translate.text("The code number is not a valid number.")); - neon.setFieldValue("$field.SORTING", ++newCodeNumber); - } -} \ No newline at end of file diff --git a/entity/Attribute_entity/recordcontainers/jdito/onInsert.js b/entity/Attribute_entity/recordcontainers/jdito/onInsert.js index 7e2f5457781..9678a3d086a 100644 --- a/entity/Attribute_entity/recordcontainers/jdito/onInsert.js +++ b/entity/Attribute_entity/recordcontainers/jdito/onInsert.js @@ -4,15 +4,25 @@ import("Attribute_lib"); var rowdata = vars.get("$local.rowdata"); +var sorting = rowdata["SORTING.value"]; +var parentId = rowdata["ATTRIBUTE_PARENT_ID.value"]; +if (!sorting && parentId) +{ + sorting = newSelect("max(SORTING) + 1") + .from("AB_ATTRIBUTE") + .where("AB_ATTRIBUTE.ATTRIBUTE_PARENT_ID", parentId) + .cell() || 0; +} + new SqlBuilder().insertFields({ "AB_ATTRIBUTEID" : rowdata["UID.value"], - "ATTRIBUTE_PARENT_ID" : rowdata["ATTRIBUTE_PARENT_ID.value"], + "ATTRIBUTE_PARENT_ID" : parentId, "DROPDOWNDEFINITION" : rowdata["DROPDOWNDEFINITION.value"], "ATTRIBUTE_ACTIVE" : rowdata["ATTRIBUTE_ACTIVE.value"], "ATTRIBUTE_NAME" : rowdata["ATTRIBUTE_NAME.value"], "ATTRIBUTE_TYPE" : rowdata["ATTRIBUTE_TYPE.value"], "DROPDOWNFILTER" : rowdata["DROPDOWNFILTER.value"], - "SORTING" : rowdata["SORTING.value"] + "SORTING" : sorting }, "AB_ATTRIBUTE"); if (rowdata["ATTRIBUTE_PARENT_ID.value"] && rowdata["ATTRIBUTE_TYPE.value"] !== $AttributeTypes.COMBOVALUE.toString() && vars.get("$param.GetOnlyFirstLevelChildren_param")) diff --git a/neonView/AttributeList_view/AttributeList_view.aod b/neonView/AttributeList_view/AttributeList_view.aod index 774de73db92..167cf43d52b 100644 --- a/neonView/AttributeList_view/AttributeList_view.aod +++ b/neonView/AttributeList_view/AttributeList_view.aod @@ -11,6 +11,9 @@ <titledListViewTemplate> <name>AttributeList</name> <entityField>#ENTITY</entityField> + <isDeletable v="false" /> + <isEditable v="false" /> + <isCreatable v="false" /> <columns> <neonTitledListTableColumn> <name>96544713-a302-4e2f-ab7f-6c02d44d9908</name> -- GitLab