提交 e813005b 编写于 作者: T Tijs Rademakers 提交者: Joram Barrez
上级 bb376da4
......@@ -177,7 +177,9 @@ public interface StencilConstants {
final String PROPERTY_FORM_READABLE = "readable";
final String PROPERTY_FORM_WRITABLE = "writable";
final String PROPERTY_FORM_ENUM_VALUES = "enumValues";
final String PROPERTY_FORM_ENUM_VALUES_NAME = "name";
final String PROPERTY_FORM_ENUM_VALUES_ID = "id";
final String PROPERTY_DATA_PROPERTIES = "dataproperties";
final String PROPERTY_DATA_ID = "dataproperty_id";
final String PROPERTY_DATA_NAME = "dataproperty_name";
......
......@@ -419,7 +419,8 @@ public abstract class BaseBpmnJsonConverter implements EditorJsonConstants, Sten
ArrayNode valuesNode = objectMapper.createArrayNode();
for (FormValue formValue : property.getFormValues()) {
ObjectNode valueNode = objectMapper.createObjectNode();
valueNode.put("value", formValue.getName());
valueNode.put(PROPERTY_FORM_ENUM_VALUES_NAME, formValue.getName());
valueNode.put(PROPERTY_FORM_ENUM_VALUES_ID, formValue.getId());
valuesNode.add(valueNode);
}
propertyItemNode.put(PROPERTY_FORM_ENUM_VALUES, valuesNode);
......@@ -515,19 +516,29 @@ public abstract class BaseBpmnJsonConverter implements EditorJsonConstants, Sten
formProperty.setType(getValueAsString(PROPERTY_FORM_TYPE, formNode));
formProperty.setExpression(getValueAsString(PROPERTY_FORM_EXPRESSION, formNode));
formProperty.setVariable(getValueAsString(PROPERTY_FORM_VARIABLE, formNode));
if ("date".equalsIgnoreCase(formProperty.getType())) {
formProperty.setDatePattern(getValueAsString(PROPERTY_FORM_DATE_PATTERN, formNode));
} else if ("enum".equalsIgnoreCase(formProperty.getType())) {
JsonNode enumValuesNode = formNode.get(PROPERTY_FORM_ENUM_VALUES);
if (enumValuesNode != null) {
List<FormValue> formValueList = new ArrayList<FormValue>();
for (JsonNode enumNode : enumValuesNode) {
if (enumNode.get("value") != null && enumNode.get("value").isNull() == false) {
FormValue formValue = new FormValue();
formValue.setId(enumNode.get("value").asText());
formValue.setName(enumNode.get("value").asText());
formValueList.add(formValue);
}
if (enumNode.get(PROPERTY_FORM_ENUM_VALUES_ID) != null && enumNode.get(PROPERTY_FORM_ENUM_VALUES_ID).isNull() == false &&
enumNode.get(PROPERTY_FORM_ENUM_VALUES_NAME) != null && enumNode.get(PROPERTY_FORM_ENUM_VALUES_NAME).isNull() == false) {
FormValue formValue = new FormValue();
formValue.setId(enumNode.get(PROPERTY_FORM_ENUM_VALUES_ID).asText());
formValue.setName(enumNode.get(PROPERTY_FORM_ENUM_VALUES_NAME).asText());
formValueList.add(formValue);
} else if (enumNode.get("value") != null && enumNode.get("value").isNull() == false) {
FormValue formValue = new FormValue();
formValue.setId(enumNode.get("value").asText());
formValue.setName(enumNode.get("value").asText());
formValueList.add(formValue);
}
}
formProperty.setFormValues(formValueList);
}
......
......@@ -42,9 +42,26 @@ angular.module('activitiModeler').controller('KisBpmFormPropertiesPopupCtrl',
// Note that we clone the json object rather then setting it directly,
// this to cope with the fact that the user can click the cancel button and no changes should have happended
$scope.formProperties = angular.copy($scope.property.value.formProperties);
for (var i = 0; i < $scope.formProperties.length; i++) {
var formProperty = $scope.formProperties[i];
if (formProperty.enumValues && formProperty.enumValues.length > 0) {
for (var j = 0; j < formProperty.enumValues.length; j++) {
var enumValue = formProperty.enumValues[j];
if (!enumValue.id && !enumValue.name && enumValue.value) {
enumValue.id = enumValue.value;
enumValue.name = enumValue.value;
}
}
}
}
} else {
$scope.formProperties = [];
}
$scope.selectedProperties = [];
$scope.selectedEnumValues = [];
$scope.translationsRetrieved = false;
......@@ -75,6 +92,18 @@ angular.module('activitiModeler').controller('KisBpmFormPropertiesPopupCtrl',
{field: 'name', displayName: $scope.labels.nameLabel},
{field: 'type', displayName: $scope.labels.typeLabel}]
};
$scope.enumGridOptions = {
data: 'selectedProperties[0].enumValues',
enableRowReordering: true,
headerRowHeight: 28,
multiSelect: false,
keepLastSelected : false,
selectedItems: $scope.selectedEnumValues,
columnDefs: [{ field: 'id', displayName: $scope.labels.idLabel },
{ field: 'name', displayName: $scope.labels.nameLabel}]
}
$scope.gridOptions.onRegisterApi = function (gridApi) {
//set gridApi on scope
......@@ -97,23 +126,12 @@ angular.module('activitiModeler').controller('KisBpmFormPropertiesPopupCtrl',
// Check enum. If enum, show list of options
if ($scope.selectedProperty.type === 'enum') {
$scope.selectedProperty.enumValues = [{value: 'value 1'}, {value: 'value 2'}];
$scope.selectedProperties[0].enumValues = [ {id: 'value1', name: 'Value 1'}, {id: 'value2', name: 'Value 2'}];
} else {
delete $scope.selectedProperty.enumValues;
}
};
// Click handler for + button after enum value
var valueIndex = 3;
$scope.addEnumValue = function (index) {
$scope.selectedProperty.enumValues.splice(index + 1, 0, {value: 'value ' + valueIndex++});
};
// Click handler for - button after enum value
$scope.removeEnumValue = function (index) {
$scope.selectedProperty.enumValues.splice(index, 1);
};
// Click handler for add button
var propertyIndex = 1;
$scope.addNewProperty = function () {
......@@ -124,6 +142,10 @@ angular.module('activitiModeler').controller('KisBpmFormPropertiesPopupCtrl',
readable: true,
writable: true
};
$timeout(function(){
$scope.gridOptions.selectItem($scope.formProperties.length - 1, true);
});
$scope.formProperties.push(newProperty);
......@@ -187,6 +209,69 @@ angular.module('activitiModeler').controller('KisBpmFormPropertiesPopupCtrl',
}
}
};
$scope.addNewEnumValue = function() {
if ($scope.selectedProperties.length > 0) {
$scope.selectedProperties[0].enumValues.push({ id : '', name : ''});
}
$timeout(function(){
$scope.enumGridOptions.selectItem($scope.selectedProperties[0].enumValues.length - 1, true);
});
};
// Click handler for remove button
$scope.removeEnumValue = function() {
if ($scope.selectedProperties.length > 0 && $scope.selectedEnumValues.length > 0) {
var index = $scope.selectedProperties[0].enumValues.indexOf($scope.selectedEnumValues[0]);
$scope.enumGridOptions.selectItem(index, false);
$scope.selectedProperties[0].enumValues.splice(index, 1);
$scope.selectedEnumValues.length = 0;
if (index < $scope.selectedProperties[0].enumValues.length) {
$timeout(function(){
$scope.enumGridOptions.selectItem(index + 1, true);
});
} else if ($scope.selectedProperties[0].enumValues.length > 0) {
$timeout(function(){
$scope.enumGridOptions.selectItem(index - 1, true);
});
}
}
};
// Click handler for up button
$scope.moveEnumValueUp = function() {
if ($scope.selectedProperties.length > 0 && $scope.selectedEnumValues.length > 0) {
var index = $scope.selectedProperties[0].enumValues.indexOf($scope.selectedEnumValues[0]);
if (index != 0) { // If it's the first, no moving up of course
// Reason for funny way of swapping, see https://github.com/angular-ui/ng-grid/issues/272
var temp = $scope.selectedProperties[0].enumValues[index];
$scope.selectedProperties[0].enumValues.splice(index, 1);
$timeout(function(){
$scope.selectedProperties[0].enumValues.splice(index + -1, 0, temp);
});
}
}
};
// Click handler for down button
$scope.moveEnumValueDown = function() {
if ($scope.selectedProperties.length > 0 && $scope.selectedEnumValues.length > 0) {
var index = $scope.selectedProperties[0].enumValues.indexOf($scope.selectedEnumValues[0]);
if (index != $scope.selectedProperties[0].enumValues.length - 1) { // If it's the last element, no moving down of course
// Reason for funny way of swapping, see https://github.com/angular-ui/ng-grid/issues/272
var temp = $scope.selectedProperties[0].enumValues[index];
$scope.selectedProperties[0].enumValues.splice(index, 1);
$timeout(function(){
$scope.selectedProperties[0].enumValues.splice(index + 1, 0, temp);
});
}
}
};
// Click handler for save button
$scope.save = function () {
......
......@@ -48,13 +48,37 @@
<label for="datePatternField">{{'PROPERTY.FORMPROPERTIES.DATEPATTERN' | translate}}</label>
<input id="datePatternField" class="form-control" type="text" ng-model="selectedProperty.datePattern" placeholder="{{'PROPERTY.FORMPROPERTIES.DATEPATTERN.PLACEHOLDER' | translate }}" />
</div>
<div class="form-group" ng-show="selectedProperty.enumValues">
<label for="valueField">{{'PROPERTY.FORMPROPERTIES.VALUES' | translate}}</label>
<div ng-repeat="enum in selectedProperty.enumValues">
<input id="valueField" class="form-control" type="text" ng-model="enum.value" />
<i class="glyphicon glyphicon-minus clickable-property" ng-click="removeEnumValue($index)"></i>
<i ng-if="$index == (selectedProperty.enumValues.length - 1)" class="glyphicon glyphicon-plus clickable-property" ng-click="addEnumValue($index)"></i>
<div ng-if="selectedProperties[0].type == 'enum'" style="padding-bottom:10px">
<div class="row row-no-gutter">
<div class="col-xs-6">
<div ng-if="translationsRetrieved" class="kis-listener-grid" ng-grid="enumGridOptions"></div>
<div class="pull-right">
<div class="btn-group">
<a class="btn btn-icon btn-lg" rel="tooltip" data-title="{{ACTION.MOVE.UP | translate}}" data-placement="bottom" data-original-title="" title="" ng-click="moveEnumValueUp()"><i class="glyphicon glyphicon-arrow-up"></i></a>
<a class="btn btn-icon btn-lg" rel="tooltip" data-title="{{ACTION.MOVE.DOWN | translate}}" data-placement="bottom" data-original-title="" title="" ng-click="moveEnumValueDown()"><i class="glyphicon glyphicon-arrow-down"></i></a>
</div>
<div class="btn-group">
<a class="btn btn-icon btn-lg" rel="tooltip" data-title="{{ACTION.ADD | translate}}" data-placement="bottom" data-original-title="" title="" ng-click="addNewEnumValue()"><i class="glyphicon glyphicon-plus"></i></a>
<a class="btn btn-icon btn-lg" rel="tooltip" data-title="{{ACTION.REMOVE | translate}}" data-placement="bottom" data-original-title="" title="" ng-click="removeEnumValue()"><i class="glyphicon glyphicon-minus"></i></a>
</div>
</div>
</div>
<div class="col-xs-6">
<div ng-show="selectedEnumValues.length > 0">
<div class="form-group">
<label for="classField">{{'PROPERTY.FORMPROPERTIES.VALUES.ID' | translate}}</label>
<input type="text" id="classField" class="form-control" ng-model="selectedEnumValues[0].id" placeholder="{{'PROPERTY.FORMPROPERTIES.VALUES.ID.PLACEHOLDER' | translate}}" />
</div>
<div class="form-group">
<label for="classField">{{'PROPERTY.FORMPROPERTIES.VALUES.NAME' | translate}}</label>
<input type="text" id="classField" class="form-control" ng-model="selectedEnumValues[0].name" placeholder="{{'PROPERTY.FORMPROPERTIES.VALUES.NAME.PLACEHOLDER' | translate}}" />
</div>
</div>
<div ng-show="selectedEnumValues.length == 0" class="muted no-property-selected" translate>PROPERTY.FORMPROPERTIES.ENUMVALUES.EMPTY</div>
</div>
</div>
</div>
<div class="form-group">
<label for="expressionField">{{'PROPERTY.FORMPROPERTIES.EXPRESSION' | translate}}</label>
......
......@@ -1376,7 +1376,7 @@
"PROPERTY.FIELDS.UNSELECTED" : "No Field selected",
"PROPERTY.FORMPROPERTIES.VALUE" : "{{length}} form properties",
"PROPERTY.FORMPROPERTIES.EMPTY" : "No form properties configured",
"PROPERTY.FORMPROPERTIES.EMPTY" : "No form properties selected",
"PROPERTY.FORMPROPERTIES.ID" : "Id",
"PROPERTY.FORMPROPERTIES.ID.PLACEHOLDER" : "Enter an id",
"PROPERTY.FORMPROPERTIES.NAME" : "Name",
......@@ -1385,6 +1385,11 @@
"PROPERTY.FORMPROPERTIES.DATEPATTERN" : "Date pattern",
"PROPERTY.FORMPROPERTIES.DATEPATTERN.PLACEHOLDER" : "Enter date pattern",
"PROPERTY.FORMPROPERTIES.VALUES" : "Values",
"PROPERTY.FORMPROPERTIES.ENUMVALUES.EMPTY" : "No enum value selected",
"PROPERTY.FORMPROPERTIES.VALUES.ID" : "Id",
"PROPERTY.FORMPROPERTIES.VALUES.NAME" : "Name",
"PROPERTY.FORMPROPERTIES.VALUES.ID.PLACEHOLDER" : "Enter id of a value",
"PROPERTY.FORMPROPERTIES.VALUES.NAME.PLACEHOLDER" : "Enter name of a value",
"PROPERTY.FORMPROPERTIES.EXPRESSION" : "Expression",
"PROPERTY.FORMPROPERTIES.EXPRESSION.PLACEHOLDER" : "Enter an expression",
"PROPERTY.FORMPROPERTIES.VARIABLE" : "Variable",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册