diff --git a/entity/Activity_entity/Activity_entity.aod b/entity/Activity_entity/Activity_entity.aod index fac358483e655ed4957327bfd601fefd8488671b..c4045e6098d69063f9d6fef36ea39f7bc8c1b6d0 100644 --- a/entity/Activity_entity/Activity_entity.aod +++ b/entity/Activity_entity/Activity_entity.aod @@ -363,6 +363,7 @@ <entityConsumer> <name>Attributes</name> <fieldType>DEPENDENCY_OUT</fieldType> + <onValidation>%aditoprj%/entity/Activity_entity/entityfields/attributes/onValidation.js</onValidation> <dependency> <name>dependency</name> <entityName>AttributeRelation_entity</entityName> diff --git a/entity/Activity_entity/entityfields/attributes/onValidation.js b/entity/Activity_entity/entityfields/attributes/onValidation.js new file mode 100644 index 0000000000000000000000000000000000000000..ca9cf00a30589c25dcb79bc116cdef263f6b526c --- /dev/null +++ b/entity/Activity_entity/entityfields/attributes/onValidation.js @@ -0,0 +1,6 @@ +import("Context_lib"); +import("system.vars"); +import("Attribute_lib"); +import("system.result"); + +result.string(AttributeRelationUtils.validateAttributeCount(vars.get("$sys.uid"), ContextUtils.getCurrentContextId(), vars.get("$field.Attributes.insertedRows"))); \ No newline at end of file diff --git a/entity/AttributeRelation_entity/AttributeRelation_entity.aod b/entity/AttributeRelation_entity/AttributeRelation_entity.aod index 22812c87250a31ceb015f1c4060c1ea1a3f05647..151311bd51fe79d53e6337dd08b8e655e176b97a 100644 --- a/entity/AttributeRelation_entity/AttributeRelation_entity.aod +++ b/entity/AttributeRelation_entity/AttributeRelation_entity.aod @@ -3,6 +3,7 @@ <name>AttributeRelation_entity</name> <majorModelMode>DISTRIBUTED</majorModelMode> <title>Attribute</title> + <onValidation>%aditoprj%/entity/AttributeRelation_entity/onValidation.js</onValidation> <titlePlural>Attributes</titlePlural> <recordContainer>jdito</recordContainer> <entityFields> diff --git a/entity/AttributeRelation_entity/entityfields/specificattribute/children/attributecount_param/valueProcess.js b/entity/AttributeRelation_entity/entityfields/specificattribute/children/attributecount_param/valueProcess.js index feab7983edde4183300888452e1f30a7cbf7050a..069564215deafe58fe6dd3db05b8f5e05a1fb73b 100644 --- a/entity/AttributeRelation_entity/entityfields/specificattribute/children/attributecount_param/valueProcess.js +++ b/entity/AttributeRelation_entity/entityfields/specificattribute/children/attributecount_param/valueProcess.js @@ -1,25 +1,8 @@ +import("Attribute_lib"); import("system.result"); -import("system.db"); -import("Sql_lib"); import("system.vars"); var objectType = vars.exists("$param.ObjectType_param") && vars.get("$param.ObjectType_param"); var rowId = vars.exists("$param.ObjectRowId_param") && vars.get("$param.ObjectRowId_param"); if (rowId) -{ - var condition = SqlCondition.begin() - .andPrepare("AB_ATTRIBUTERELATION.OBJECT_ROWID", rowId); - if (objectType) - condition.andPrepare("AB_ATTRIBUTERELATION.OBJECT_TYPE", objectType); - var relationCounts = db.table(condition.buildSql( - "select AB_ATTRIBUTE_ID, count(AB_ATTRIBUTE_ID) from AB_ATTRIBUTERELATION", - "1=2", - "group by AB_ATTRIBUTE_ID" - )); - var countObj = {}; - relationCounts.forEach(function (row) - { - this[row[0]] = row[1]; - }, countObj); - result.object(countObj); -} \ No newline at end of file + result.object(AttributeRelationUtils.countAttributeRelations(rowId, objectType)); \ No newline at end of file diff --git a/entity/AttributeRelation_entity/onValidation.js b/entity/AttributeRelation_entity/onValidation.js new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/entity/Campaign_entity/Campaign_entity.aod b/entity/Campaign_entity/Campaign_entity.aod index 5a0a67752856a3bf194a0971f5856dcf74896965..fff53a7ae3080c7169afc97553c76ab4745f4084 100644 --- a/entity/Campaign_entity/Campaign_entity.aod +++ b/entity/Campaign_entity/Campaign_entity.aod @@ -350,6 +350,7 @@ <entityConsumer> <name>Attributes</name> <fieldType>DEPENDENCY_OUT</fieldType> + <onValidation>%aditoprj%/entity/Campaign_entity/entityfields/attributes/onValidation.js</onValidation> <dependency> <name>dependency</name> <entityName>AttributeRelation_entity</entityName> diff --git a/entity/Campaign_entity/entityfields/attributes/onValidation.js b/entity/Campaign_entity/entityfields/attributes/onValidation.js new file mode 100644 index 0000000000000000000000000000000000000000..ca9cf00a30589c25dcb79bc116cdef263f6b526c --- /dev/null +++ b/entity/Campaign_entity/entityfields/attributes/onValidation.js @@ -0,0 +1,6 @@ +import("Context_lib"); +import("system.vars"); +import("Attribute_lib"); +import("system.result"); + +result.string(AttributeRelationUtils.validateAttributeCount(vars.get("$sys.uid"), ContextUtils.getCurrentContextId(), vars.get("$field.Attributes.insertedRows"))); \ No newline at end of file diff --git a/entity/Contract_entity/Contract_entity.aod b/entity/Contract_entity/Contract_entity.aod index b5b4e2e54ee72305aff1f4694c788a657f35e730..c1cc63e3d91e30b2e8a283e218455a2ccddc792d 100644 --- a/entity/Contract_entity/Contract_entity.aod +++ b/entity/Contract_entity/Contract_entity.aod @@ -35,8 +35,8 @@ <contentType>DATE</contentType> <resolution>DAY</resolution> <outputFormat>dd.MM.yyyy</outputFormat> - <onValidation>%aditoprj%/entity/Contract_entity/entityfields/contractend/onValidation.js</onValidation> <onValueChange>%aditoprj%/entity/Contract_entity/entityfields/contractend/onValueChange.js</onValueChange> + <onValidation>%aditoprj%/entity/Contract_entity/entityfields/contractend/onValidation.js</onValidation> </entityField> <entityField> <name>CONTRACTID</name> @@ -51,8 +51,8 @@ <resolution>DAY</resolution> <outputFormat>dd.MM.yyyy</outputFormat> <valueProcess>%aditoprj%/entity/Contract_entity/entityfields/contractstart/valueProcess.js</valueProcess> - <onValidation>%aditoprj%/entity/Contract_entity/entityfields/contractstart/onValidation.js</onValidation> <onValueChange>%aditoprj%/entity/Contract_entity/entityfields/contractstart/onValueChange.js</onValueChange> + <onValidation>%aditoprj%/entity/Contract_entity/entityfields/contractstart/onValidation.js</onValidation> </entityField> <entityField> <name>CONTRACTSTATUS</name> @@ -294,6 +294,7 @@ <entityConsumer> <name>Attributes</name> <fieldType>DEPENDENCY_OUT</fieldType> + <onValidation>%aditoprj%/entity/Contract_entity/entityfields/attributes/onValidation.js</onValidation> <dependency> <name>dependency</name> <entityName>AttributeRelation_entity</entityName> diff --git a/entity/Contract_entity/entityfields/attributes/onValidation.js b/entity/Contract_entity/entityfields/attributes/onValidation.js new file mode 100644 index 0000000000000000000000000000000000000000..ca9cf00a30589c25dcb79bc116cdef263f6b526c --- /dev/null +++ b/entity/Contract_entity/entityfields/attributes/onValidation.js @@ -0,0 +1,6 @@ +import("Context_lib"); +import("system.vars"); +import("Attribute_lib"); +import("system.result"); + +result.string(AttributeRelationUtils.validateAttributeCount(vars.get("$sys.uid"), ContextUtils.getCurrentContextId(), vars.get("$field.Attributes.insertedRows"))); \ No newline at end of file diff --git a/entity/DocumentTemplate_entity/DocumentTemplate_entity.aod b/entity/DocumentTemplate_entity/DocumentTemplate_entity.aod index 788ee601e4a6fdd8c72242e0635ddfe3d8f01d87..a5e9e9837713a65dc581dc46c30cbc45f31db43b 100644 --- a/entity/DocumentTemplate_entity/DocumentTemplate_entity.aod +++ b/entity/DocumentTemplate_entity/DocumentTemplate_entity.aod @@ -113,6 +113,7 @@ <entityConsumer> <name>Attributes</name> <fieldType>DEPENDENCY_OUT</fieldType> + <onValidation>%aditoprj%/entity/DocumentTemplate_entity/entityfields/attributes/onValidation.js</onValidation> <dependency> <name>dependency</name> <entityName>AttributeRelation_entity</entityName> diff --git a/entity/DocumentTemplate_entity/entityfields/attributes/onValidation.js b/entity/DocumentTemplate_entity/entityfields/attributes/onValidation.js new file mode 100644 index 0000000000000000000000000000000000000000..ca9cf00a30589c25dcb79bc116cdef263f6b526c --- /dev/null +++ b/entity/DocumentTemplate_entity/entityfields/attributes/onValidation.js @@ -0,0 +1,6 @@ +import("Context_lib"); +import("system.vars"); +import("Attribute_lib"); +import("system.result"); + +result.string(AttributeRelationUtils.validateAttributeCount(vars.get("$sys.uid"), ContextUtils.getCurrentContextId(), vars.get("$field.Attributes.insertedRows"))); \ No newline at end of file diff --git a/entity/Employee_entity/Employee_entity.aod b/entity/Employee_entity/Employee_entity.aod index 388552cb8f508b2e216b1c02f78b447c297c398b..637d3e554564f78fb834d449b361d200f5a43894 100644 --- a/entity/Employee_entity/Employee_entity.aod +++ b/entity/Employee_entity/Employee_entity.aod @@ -32,8 +32,8 @@ <linkedContext>Person</linkedContext> <mandatory v="true" /> <stateProcess>%aditoprj%/entity/Employee_entity/entityfields/contact_id/stateProcess.js</stateProcess> - <onValidation>%aditoprj%/entity/Employee_entity/entityfields/contact_id/onValidation.js</onValidation> <onValueChange>%aditoprj%/entity/Employee_entity/entityfields/contact_id/onValueChange.js</onValueChange> + <onValidation>%aditoprj%/entity/Employee_entity/entityfields/contact_id/onValidation.js</onValidation> </entityField> <entityField> <name>FIRSTNAME</name> @@ -107,6 +107,7 @@ <entityConsumer> <name>Attributes</name> <fieldType>DEPENDENCY_OUT</fieldType> + <onValidation>%aditoprj%/entity/Employee_entity/entityfields/attributes/onValidation.js</onValidation> <dependency> <name>dependency</name> <entityName>AttributeRelation_entity</entityName> diff --git a/entity/Employee_entity/entityfields/attributes/onValidation.js b/entity/Employee_entity/entityfields/attributes/onValidation.js new file mode 100644 index 0000000000000000000000000000000000000000..ca5cebe6bd635865e7f58c5adc5d116c21bfe0a1 --- /dev/null +++ b/entity/Employee_entity/entityfields/attributes/onValidation.js @@ -0,0 +1,8 @@ +import("Employee_lib"); +import("Context_lib"); +import("system.vars"); +import("Attribute_lib"); +import("system.result"); + +result.string(AttributeRelationUtils.validateAttributeCount(EmployeeUtils.sliceUserId(vars.get("$field.UID")), + ContextUtils.getCurrentContextId(), vars.get("$field.Attributes.insertedRows"))); \ No newline at end of file diff --git a/entity/Offer_entity/Offer_entity.aod b/entity/Offer_entity/Offer_entity.aod index 8c9c6bc7cc2f46ea0b1a4d0440bae43ca3ecbd65..9e87ef60ec09dfa81c41c3e32a45378243fc19bc 100644 --- a/entity/Offer_entity/Offer_entity.aod +++ b/entity/Offer_entity/Offer_entity.aod @@ -613,6 +613,7 @@ <entityConsumer> <name>Attributes</name> <fieldType>DEPENDENCY_OUT</fieldType> + <onValidation>%aditoprj%/entity/Offer_entity/entityfields/attributes/onValidation.js</onValidation> <dependency> <name>dependency</name> <entityName>AttributeRelation_entity</entityName> diff --git a/entity/Offer_entity/entityfields/attributes/onValidation.js b/entity/Offer_entity/entityfields/attributes/onValidation.js new file mode 100644 index 0000000000000000000000000000000000000000..ca9cf00a30589c25dcb79bc116cdef263f6b526c --- /dev/null +++ b/entity/Offer_entity/entityfields/attributes/onValidation.js @@ -0,0 +1,6 @@ +import("Context_lib"); +import("system.vars"); +import("Attribute_lib"); +import("system.result"); + +result.string(AttributeRelationUtils.validateAttributeCount(vars.get("$sys.uid"), ContextUtils.getCurrentContextId(), vars.get("$field.Attributes.insertedRows"))); \ No newline at end of file diff --git a/entity/Order_entity/Order_entity.aod b/entity/Order_entity/Order_entity.aod index 8635f28461e0e852635cbdd424b89857bc1b53a9..7ae7a3c97c0e052b01de99bfe6229c0cd07a473a 100644 --- a/entity/Order_entity/Order_entity.aod +++ b/entity/Order_entity/Order_entity.aod @@ -435,6 +435,7 @@ <entityConsumer> <name>Attributes</name> <fieldType>DEPENDENCY_OUT</fieldType> + <onValidation>%aditoprj%/entity/Order_entity/entityfields/attributes/onValidation.js</onValidation> <dependency> <name>dependency</name> <entityName>AttributeRelation_entity</entityName> diff --git a/entity/Order_entity/entityfields/attributes/onValidation.js b/entity/Order_entity/entityfields/attributes/onValidation.js new file mode 100644 index 0000000000000000000000000000000000000000..3dc21efcc3ba693e83bd3ba87c46bd7beb3fb2c2 --- /dev/null +++ b/entity/Order_entity/entityfields/attributes/onValidation.js @@ -0,0 +1,6 @@ +import("Context_lib"); +import("system.vars"); +import("Attribute_lib"); +import("system.result"); + +result.string(AttributeRelationUtils.validateAttributeCount(vars.get("$field.SALESORDERID"), ContextUtils.getCurrentContextId(), vars.get("$field.Attributes.insertedRows"))); \ No newline at end of file diff --git a/entity/Organisation_entity/Organisation_entity.aod b/entity/Organisation_entity/Organisation_entity.aod index 8b17de684f70e44fb679865ce497af8534f64afc..f2ebb2b70d752bbd8c99fcd70ddeeae89609b810 100644 --- a/entity/Organisation_entity/Organisation_entity.aod +++ b/entity/Organisation_entity/Organisation_entity.aod @@ -259,9 +259,6 @@ <fieldName>Documents</fieldName> </dependency> <children> - <entityParameter> - <name>AssignmentName_param</name> - </entityParameter> <entityParameter> <name>AssignmentRowId_param</name> <valueProcess>%aditoprj%/entity/Organisation_entity/entityfields/documents/children/assignmentrowid_param/valueProcess.js</valueProcess> @@ -370,6 +367,7 @@ <entityConsumer> <name>Attributes</name> <fieldType>DEPENDENCY_OUT</fieldType> + <onValidation>%aditoprj%/entity/Organisation_entity/entityfields/attributes/onValidation.js</onValidation> <dependency> <name>dependency</name> <entityName>AttributeRelation_entity</entityName> diff --git a/entity/Organisation_entity/entityfields/attributes/children/objectrowid_param/valueProcess.js b/entity/Organisation_entity/entityfields/attributes/children/objectrowid_param/valueProcess.js index bcfda44fe71eac93b3f8c11cc0c85a496f2cd51c..533f8ec837ea2f9b588ddf05545ac47cdda23d18 100644 --- a/entity/Organisation_entity/entityfields/attributes/children/objectrowid_param/valueProcess.js +++ b/entity/Organisation_entity/entityfields/attributes/children/objectrowid_param/valueProcess.js @@ -1,4 +1,4 @@ import("system.vars"); import("system.result"); -result.string(vars.get("$field.ORGANISATIONID")); \ No newline at end of file +result.string(vars.get("$sys.uid")); \ No newline at end of file diff --git a/entity/Organisation_entity/entityfields/attributes/onValidation.js b/entity/Organisation_entity/entityfields/attributes/onValidation.js new file mode 100644 index 0000000000000000000000000000000000000000..ca9cf00a30589c25dcb79bc116cdef263f6b526c --- /dev/null +++ b/entity/Organisation_entity/entityfields/attributes/onValidation.js @@ -0,0 +1,6 @@ +import("Context_lib"); +import("system.vars"); +import("Attribute_lib"); +import("system.result"); + +result.string(AttributeRelationUtils.validateAttributeCount(vars.get("$sys.uid"), ContextUtils.getCurrentContextId(), vars.get("$field.Attributes.insertedRows"))); \ No newline at end of file diff --git a/entity/Person_entity/Person_entity.aod b/entity/Person_entity/Person_entity.aod index 290daec830c48dd872c5119e30e1f9929a0cbf4e..ec4f4f9b8cd100bb07f2736fcee833f80e88c8c5 100644 --- a/entity/Person_entity/Person_entity.aod +++ b/entity/Person_entity/Person_entity.aod @@ -149,8 +149,8 @@ <searchable v="true" /> <valueProcess>%aditoprj%/entity/Person_entity/entityfields/organisation_id/valueProcess.js</valueProcess> <displayValueProcess>%aditoprj%/entity/Person_entity/entityfields/organisation_id/displayValueProcess.js</displayValueProcess> - <onValidation>%aditoprj%/entity/Person_entity/entityfields/organisation_id/onValidation.js</onValidation> <onValueChange>%aditoprj%/entity/Person_entity/entityfields/organisation_id/onValueChange.js</onValueChange> + <onValidation>%aditoprj%/entity/Person_entity/entityfields/organisation_id/onValidation.js</onValidation> </entityField> <entityConsumer> <name>PersAddresses</name> @@ -300,9 +300,6 @@ Usually this is used for filtering COMMUNICATION-entries by a specified contact <fieldName>Documents</fieldName> </dependency> <children> - <entityParameter> - <name>AssignmentName_param</name> - </entityParameter> <entityParameter> <name>AssignmentRowId_param</name> <valueProcess>%aditoprj%/entity/Person_entity/entityfields/documents/children/assignmentrowid_param/valueProcess.js</valueProcess> @@ -557,6 +554,7 @@ Usually this is used for filtering COMMUNICATION-entries by a specified contact <entityConsumer> <name>Attributes</name> <fieldType>DEPENDENCY_OUT</fieldType> + <onValidation>%aditoprj%/entity/Person_entity/entityfields/attributes/onValidation.js</onValidation> <dependency> <name>dependency</name> <entityName>AttributeRelation_entity</entityName> diff --git a/entity/Person_entity/entityfields/attributes/onValidation.js b/entity/Person_entity/entityfields/attributes/onValidation.js new file mode 100644 index 0000000000000000000000000000000000000000..ca9cf00a30589c25dcb79bc116cdef263f6b526c --- /dev/null +++ b/entity/Person_entity/entityfields/attributes/onValidation.js @@ -0,0 +1,6 @@ +import("Context_lib"); +import("system.vars"); +import("Attribute_lib"); +import("system.result"); + +result.string(AttributeRelationUtils.validateAttributeCount(vars.get("$sys.uid"), ContextUtils.getCurrentContextId(), vars.get("$field.Attributes.insertedRows"))); \ No newline at end of file diff --git a/entity/Product_entity/Product_entity.aod b/entity/Product_entity/Product_entity.aod index 4e5a6938c967b68556fcec85968e22cc5ed7de9a..7eee235ab693d5d9426e5f2b6e38ade66ff7afd0 100644 --- a/entity/Product_entity/Product_entity.aod +++ b/entity/Product_entity/Product_entity.aod @@ -327,6 +327,7 @@ <entityConsumer> <name>Attributes</name> <fieldType>DEPENDENCY_OUT</fieldType> + <onValidation>%aditoprj%/entity/Product_entity/entityfields/attributes/onValidation.js</onValidation> <dependency> <name>dependency</name> <entityName>AttributeRelation_entity</entityName> diff --git a/entity/Product_entity/entityfields/attributes/onValidation.js b/entity/Product_entity/entityfields/attributes/onValidation.js new file mode 100644 index 0000000000000000000000000000000000000000..ca9cf00a30589c25dcb79bc116cdef263f6b526c --- /dev/null +++ b/entity/Product_entity/entityfields/attributes/onValidation.js @@ -0,0 +1,6 @@ +import("Context_lib"); +import("system.vars"); +import("Attribute_lib"); +import("system.result"); + +result.string(AttributeRelationUtils.validateAttributeCount(vars.get("$sys.uid"), ContextUtils.getCurrentContextId(), vars.get("$field.Attributes.insertedRows"))); \ No newline at end of file diff --git a/entity/Salesproject_entity/Salesproject_entity.aod b/entity/Salesproject_entity/Salesproject_entity.aod index 993787b67b39900cfbeaf1768bf757f0cdf4314e..72c15972365fc9c0e92a96032022a0f433af5048 100644 --- a/entity/Salesproject_entity/Salesproject_entity.aod +++ b/entity/Salesproject_entity/Salesproject_entity.aod @@ -534,6 +534,7 @@ <entityConsumer> <name>Attributes</name> <fieldType>DEPENDENCY_OUT</fieldType> + <onValidation>%aditoprj%/entity/Salesproject_entity/entityfields/attributes/onValidation.js</onValidation> <dependency> <name>dependency</name> <entityName>AttributeRelation_entity</entityName> diff --git a/entity/Salesproject_entity/entityfields/attributes/onValidation.js b/entity/Salesproject_entity/entityfields/attributes/onValidation.js new file mode 100644 index 0000000000000000000000000000000000000000..ca9cf00a30589c25dcb79bc116cdef263f6b526c --- /dev/null +++ b/entity/Salesproject_entity/entityfields/attributes/onValidation.js @@ -0,0 +1,6 @@ +import("Context_lib"); +import("system.vars"); +import("Attribute_lib"); +import("system.result"); + +result.string(AttributeRelationUtils.validateAttributeCount(vars.get("$sys.uid"), ContextUtils.getCurrentContextId(), vars.get("$field.Attributes.insertedRows"))); \ No newline at end of file diff --git a/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod b/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod index eb19c8c002d0cb24ace0f95f16556cf0212f520f..87403d28b252c67e86808c884f708522f11892db 100644 --- a/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod +++ b/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod @@ -3867,6 +3867,18 @@ <entry> <key>Files</key> </entry> + <entry> + <key>${COUNT_PREPOSITION_SINGLE}</key> + </entry> + <entry> + <key>Attribute \"%0\" has to be used at least %1.</key> + </entry> + <entry> + <key>${COUNT_PREPOSITION_MULTIPLE}</key> + </entry> + <entry> + <key>Attribute \"%0\" can't be used more than %1.</key> + </entry> </keyValueMap> <font name="Dialog" style="0" size="11" /> <sqlModels> diff --git a/language/_____LANGUAGE_de/_____LANGUAGE_de.aod b/language/_____LANGUAGE_de/_____LANGUAGE_de.aod index edbc06804e3607d6ca38ecb5d282e7d72ae86e4e..31ea3281b351d37ecb95d2dbbd8f64babfabe5b7 100644 --- a/language/_____LANGUAGE_de/_____LANGUAGE_de.aod +++ b/language/_____LANGUAGE_de/_____LANGUAGE_de.aod @@ -34,6 +34,10 @@ <key>Open tasks</key> <value>Offene Aufgaben</value> </entry> + <entry> + <key>Attribute \"%0\" can't be used more than %1.</key> + <value>Eigenschaft \"%0\" darf maximal %1 verwendet werden.</value> + </entry> <entry> <key>Picture</key> <value>Bild</value> @@ -46,6 +50,10 @@ <key>Overdue tasks</key> <value>Überfällige Aufgaben</value> </entry> + <entry> + <key>Attribute \"%0\" has to be used at least %1.</key> + <value>Eigenschaft \"%0\" muss mindestens %1 verwendet werden.</value> + </entry> <entry> <key>Confirm password</key> <value>Passwort prüfen</value> @@ -82,6 +90,10 @@ <key>Discount %</key> <value>Rabatt %</value> </entry> + <entry> + <key>${COUNT_PREPOSITION_MULTIPLE}</key> + <value>mal</value> + </entry> <entry> <key>SalesprojectPhase</key> <value>Phase</value> @@ -90,6 +102,10 @@ <key>Email must be unique!</key> <value>Die E-Mail-Adresse muss eindeutig sein!</value> </entry> + <entry> + <key>${COUNT_PREPOSITION_SINGLE}</key> + <value>mal</value> + </entry> <entry> <key>E-Mail</key> <value>E-Mail</value> diff --git a/language/_____LANGUAGE_en/_____LANGUAGE_en.aod b/language/_____LANGUAGE_en/_____LANGUAGE_en.aod index 6aaf037638547cd5bdbb003a10c8f2dc7f3ec9e0..88a89a43268cea68611b777bb6e52a8ff9497d3a 100644 --- a/language/_____LANGUAGE_en/_____LANGUAGE_en.aod +++ b/language/_____LANGUAGE_en/_____LANGUAGE_en.aod @@ -3916,6 +3916,20 @@ <entry> <key>Files</key> </entry> + <entry> + <key>${COUNT_PREPOSITION_SINGLE}</key> + <value>time</value> + </entry> + <entry> + <key>Attribute \"%0\" has to be used at least %1.</key> + </entry> + <entry> + <key>${COUNT_PREPOSITION_MULTIPLE}</key> + <value>times</value> + </entry> + <entry> + <key>Attribute \"%0\" can't be used more than %1.</key> + </entry> </keyValueMap> <font name="Dialog" style="0" size="11" /> </language> diff --git a/process/Attribute_lib/process.js b/process/Attribute_lib/process.js index f8e1f4f0e911b5fefee973e04d8d7da8881604d0..82369b852c871725445e0a15c7783076580628f7 100644 --- a/process/Attribute_lib/process.js +++ b/process/Attribute_lib/process.js @@ -361,6 +361,81 @@ AttributeRelationUtils.presetMandatoryAttributes = function (pObjectType, pConsu }); } +/** + * adds rows for attributes with min_count > 0 + * + * @param {String} pObjectType the object type + * @param {String} pConsumer the name of the attribute relation consumer + */ +AttributeRelationUtils.validateAttributeCount = function (pRowId, pObjectType, pInsertedRows) +{ + var countObj = AttributeRelationUtils.countAttributeRelations(pRowId, pObjectType); + if (pInsertedRows) + { + pInsertedRows.forEach(function (row) + { + this[row.AB_ATTRIBUTE_ID] = (this[row.AB_ATTRIBUTE_ID] || 0) + 1; + }, countObj); + } + var attributeCondition = SqlCondition.begin(); + AttributeUtil.getPossibleAttributes(pObjectType).forEach(function (attributeId) + { + this.orPrepare("AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID", attributeId); + }, attributeCondition); + + var usageCondition = SqlCondition.begin() + .andPrepare("AB_ATTRIBUTEUSAGE.OBJECT_TYPE", pObjectType) + .andSqlCondition(attributeCondition, "1=2"); + + var minMaxCounts = db.table(usageCondition.buildSql( + "select AB_ATTRIBUTEID, ATTRIBUTE_NAME, MIN_COUNT, MAX_COUNT from AB_ATTRIBUTEUSAGE " + + "join AB_ATTRIBUTE on AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID = AB_ATTRIBUTE.AB_ATTRIBUTEID", "1=2" + )); + var validationMessage = []; + minMaxCounts.forEach(function ([attributeId, name, minCount, maxCount]) + { + let count = this[attributeId] || 0; + if (count < minCount) + validationMessage.push(translate.withArguments("Attribute \"%0\" has to be used at least %1.", [name, _getTranslatedCount(minCount)])); + if (maxCount && count > maxCount) + validationMessage.push(translate.withArguments("Attribute \"%0\" can't be used more than %1.", [name, _getTranslatedCount(maxCount)])); + }, countObj); + return validationMessage.join("\n"); + + function _getTranslatedCount (pCount) + { + if (pCount == 1) + return pCount + " " + translate.text("${COUNT_PREPOSITION_SINGLE}"); + return pCount + " " + translate.text("${COUNT_PREPOSITION_MULTIPLE}"); + } +} + +/** + * adds rows for attributes with min_count > 0 + * + * @param {String} pObjectType the object type + * @param {String} pConsumer the name of the attribute relation consumer + */ +AttributeRelationUtils.countAttributeRelations = function (pRowId, pObjectType) +{ + var condition = SqlCondition.begin() + .andPrepare("AB_ATTRIBUTERELATION.OBJECT_ROWID", pRowId); + if (pObjectType) + condition.andPrepare("AB_ATTRIBUTERELATION.OBJECT_TYPE", pObjectType); + var relationCounts = db.table(condition.buildSql( + "select AB_ATTRIBUTE_ID, count(AB_ATTRIBUTE_ID) from AB_ATTRIBUTERELATION", + "1=2", + "group by AB_ATTRIBUTE_ID" + )); + var countObj = {}; + relationCounts.forEach(function ([attributeId, count]) + { + this[attributeId] = parseInt(count); + }, countObj); + + return countObj; +} + /*********************************************************************************************************************/