Undoes the comma encoding for tags and istead adds support to store the tags as json or csv (U4-4741)

This commit is contained in:
Shannon
2014-05-15 12:49:03 +10:00
parent 157428dbc8
commit 1c7d83f589
13 changed files with 190 additions and 47 deletions

View File

@@ -12,15 +12,21 @@ angular.module("umbraco")
//load current value
$scope.currentTags = [];
if ($scope.model.value) {
$scope.currentTags = $scope.model.value.split(",");
if ($scope.model.config.storageType && $scope.model.config.storageType === "Json") {
//it's a json array already
$scope.currentTags = $scope.model.value;
}
else {
//it is csv
$scope.currentTags = $scope.model.value.split(",");
}
}
//Helper method to add a tag on enter or on typeahead select
function addTag(tagToAdd) {
if (tagToAdd.length > 0) {
if ($scope.currentTags.indexOf(tagToAdd) < 0) {
//we need to html encode any tag containing commas: http://issues.umbraco.org/issue/U4-4741
tagToAdd = tagToAdd.replace(/\,/g, "&#44;");
if ($scope.currentTags.indexOf(tagToAdd) < 0) {
$scope.currentTags.push(tagToAdd);
}
}
@@ -49,16 +55,24 @@ angular.module("umbraco")
}
};
//sync model on submit (needed since we convert an array to string)
//sync model on submit, always push up a json array
$scope.$on("formSubmitting", function (ev, args) {
$scope.model.value = $scope.currentTags.join();
$scope.model.value = $scope.currentTags;
});
//vice versa
$scope.model.onValueChanged = function (newVal, oldVal) {
//update the display val again if it has changed from the server
$scope.model.val = newVal;
$scope.currentTags = $scope.model.value.split(",");
$scope.model.value = newVal;
if ($scope.model.config.storageType && $scope.model.config.storageType === "Json") {
//it's a json array already
$scope.currentTags = $scope.model.value;
}
else {
//it is csv
$scope.currentTags = $scope.model.value.split(",");
}
};
//configure the tags data source

View File

@@ -0,0 +1,10 @@
<div >
<select name="dropDownList"
class="umb-editor umb-dropdown"
ng-model="model.value">
<option>Csv</option>
<option>Json</option>
</select>
</div>