From 696886df796473af29bdc5ad716f186fd2c5f4a0 Mon Sep 17 00:00:00 2001 From: Tuna Aksoy Date: Tue, 13 Aug 2013 10:51:11 +0000 Subject: [PATCH] RM-473 ("Rename" allows you to duplicate list name) git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@53995 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../admin/rmconstraint/rmconstraint-utils.js | 18 +++++ .../rmconstraint/rmconstraint.put.json.ftl | 6 +- .../rmconstraint/rmconstraint.put.json.js | 33 +++++--- .../rmconstraint/rmconstraint.put.properties | 1 + .../rmconstraint/rmconstraints.post.json.js | 76 ++++++++----------- .../values/rmconstraint.post.json.ftl | 2 +- 6 files changed, 76 insertions(+), 60 deletions(-) create mode 100644 rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/rmconstraint/rmconstraint-utils.js create mode 100644 rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/rmconstraint/rmconstraint.put.properties diff --git a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/rmconstraint/rmconstraint-utils.js b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/rmconstraint/rmconstraint-utils.js new file mode 100644 index 0000000000..3a56b4a83d --- /dev/null +++ b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/rmconstraint/rmconstraint-utils.js @@ -0,0 +1,18 @@ +function existsTitle(caveatConfig, title) +{ + var constraints = caveatConfig.allConstraints; + + // Check for existing constraint... + var alreadyExists = false; + for (var i = 0; i < constraints.length; i++) + { + var currTitle = constraints[i].title; + if (currTitle + "" == title) + { + alreadyExists = true; + break; + } + } + + return alreadyExists; +} \ No newline at end of file diff --git a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/rmconstraint/rmconstraint.put.json.ftl b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/rmconstraint/rmconstraint.put.json.ftl index b572b81729..42a94a8b34 100644 --- a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/rmconstraint/rmconstraint.put.json.ftl +++ b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/rmconstraint/rmconstraint.put.json.ftl @@ -2,6 +2,10 @@ <#escape x as jsonUtils.encodeJSONString(x)> { - "data": <@rmconstraintLib.constraintJSON constraint=constraint /> + <#if !errorMessage??> + "data": <@rmconstraintLib.constraintJSON constraint=constraint /> + <#else> + "message" : "${msg(errorMessage, title)}" + } \ No newline at end of file diff --git a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/rmconstraint/rmconstraint.put.json.js b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/rmconstraint/rmconstraint.put.json.js index 263e7ef7d8..d9f9553dc0 100644 --- a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/rmconstraint/rmconstraint.put.json.js +++ b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/rmconstraint/rmconstraint.put.json.js @@ -1,42 +1,51 @@ + + /** * Update an rm constraint - */ + */ function main() { // Get the shortname var shortName = url.extension; - + // Get the constraint var constraint = caveatConfig.getConstraint(shortName); - + if (constraint != null) { - var allowedValues - var title = null; - + var allowedValues, + title = null; + if (json.has("constraintTitle")) { title = json.get("constraintTitle"); + if (existsTitle(caveatConfig, title)) + { + status.code = 400; + model.errorMessage = "rm.admin.list-already-exists"; + model.title = title; + return; + } constraint.updateTitle(title); } - + if (json.has("allowedValues")) { values = json.getJSONArray("allowedValues"); - + var i = 0; allowedValues = new Array(); - + if (values != null) { for (var x = 0; x < values.length(); x++) - { - allowedValues[i++] = values.get(x); + { + allowedValues[i++] = values.get(x); } } constraint.updateAllowedValues(allowedValues); } - + // Pass the constraint detail to the template model.constraint = constraint; } diff --git a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/rmconstraint/rmconstraint.put.properties b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/rmconstraint/rmconstraint.put.properties new file mode 100644 index 0000000000..28e2a155e5 --- /dev/null +++ b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/rmconstraint/rmconstraint.put.properties @@ -0,0 +1 @@ +rm.admin.list-already-exists=A list with the name "{0}" already exists. \ No newline at end of file diff --git a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/rmconstraint/rmconstraints.post.json.js b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/rmconstraint/rmconstraints.post.json.js index ad822a97e7..7bb64fc99b 100644 --- a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/rmconstraint/rmconstraints.post.json.js +++ b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/rmconstraint/rmconstraints.post.json.js @@ -1,70 +1,54 @@ + + /** * Create a new RM Constraint List - */ + */ function main() { // Parse the passed in details - var title = null; - var name = null; - var allowedValues = {}; - - if (json.has("allowedValues")) - { - values = json.getJSONArray("allowedValues"); - - var i = 0; - allowedValues = new Array(); - - if (values != null) - { - for (var x = 0; x < values.length(); x++) - { - allowedValues[i++] = values.get(x); - } - } - } - + var title = null, + name = null, + allowedValues = {}; + if (json.has("constraintName")) { - name = json.get("constraintName"); + name = json.get("constraintName"); } - + if (json.has("constraintTitle")) { - title = json.get("constraintTitle"); + title = json.get("constraintTitle"); } else { title = name; } - - var constraints = caveatConfig.allConstraints; - - // Check for existing constraint... - var alreadyExists = false; - for (var i=0; i { - "data": <@rmconstraintLib.constraintWithValuesJSON constraint=constraint /> + "data": <@rmconstraintLib.constraintWithValuesJSON constraint=constraint /> } \ No newline at end of file