Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e9da0aa351 | |||
| b42e411e49 | |||
| 4c4b09b187 |
@@ -32,6 +32,9 @@ namespace Archetype.Models
|
||||
[JsonProperty("hidePropertyLabel")]
|
||||
public bool HidePropertyLabel { get; set; }
|
||||
|
||||
[JsonProperty("minFieldsets", NullValueHandling = NullValueHandling.Ignore)]
|
||||
public int MinFieldsets { get; set; }
|
||||
|
||||
[JsonProperty("maxFieldsets", NullValueHandling = NullValueHandling.Ignore)]
|
||||
public int MaxFieldsets { get; set; }
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ angular.module("umbraco").controller("Imulus.ArchetypeConfigController", functio
|
||||
//define empty items
|
||||
var newPropertyModel = '{"alias": "", "remove": false, "collapse": false, "label": "", "helpText": "", "dataTypeGuid": "0cc0eba1-9960-42c9-bf9b-60e150b429ae", "value": ""}';
|
||||
var newFieldsetModel = '{"alias": "", "remove": false, "collapse": false, "labelTemplate": "", "icon": "", "label": "", "properties": [' + newPropertyModel + ']}';
|
||||
var defaultFieldsetConfigModel = JSON.parse('{"showAdvancedOptions": false, "startWithAddButton": false, "hideFieldsetToolbar": false, "enableMultipleFieldsets": false, "hideFieldsetControls": false, "hidePropertyLabel": false, "maxFieldsets": null, "enableCollapsing": true, "enableCloning": false, "enableDisabling": true, "enableDeepDatatypeRequests": false, "fieldsets": [' + newFieldsetModel + ']}');
|
||||
var defaultFieldsetConfigModel = JSON.parse('{"showAdvancedOptions": false, "startWithAddButton": false, "hideFieldsetToolbar": false, "enableMultipleFieldsets": false, "hideFieldsetControls": false, "hidePropertyLabel": false, "minFieldsets": null, "maxFieldsets": null, "enableCollapsing": true, "enableCloning": false, "enableDisabling": true, "enableDeepDatatypeRequests": false, "fieldsets": [' + newFieldsetModel + ']}');
|
||||
|
||||
//ini the model
|
||||
$scope.model.value = $scope.model.value || defaultFieldsetConfigModel;
|
||||
@@ -104,7 +104,7 @@ angular.module("umbraco").controller("Imulus.ArchetypeConfigController", functio
|
||||
|
||||
//ini the properties
|
||||
_.each($scope.archetypeConfigRenderModel.fieldsets, function(fieldset){
|
||||
$scope.focusProperty(fieldset.properties);
|
||||
$scope.focusProperty(fieldset.properties);
|
||||
});
|
||||
|
||||
//setup JSON.stringify helpers
|
||||
|
||||
@@ -88,8 +88,11 @@ angular.module("umbraco").controller("Imulus.ArchetypeController", function ($sc
|
||||
$scope.model.value.fieldsets.push(newFieldset);
|
||||
}
|
||||
}
|
||||
|
||||
$scope.setDirty();
|
||||
|
||||
$scope.$broadcast("archetypeAddFieldset", {index: $index, visible: countVisible()});
|
||||
|
||||
newFieldset.collapse = $scope.model.config.enableCollapsing ? true : false;
|
||||
$scope.focusFieldset(newFieldset);
|
||||
}
|
||||
@@ -100,7 +103,7 @@ angular.module("umbraco").controller("Imulus.ArchetypeController", function ($sc
|
||||
if (confirm('Are you sure you want to remove this?')) {
|
||||
$scope.setDirty();
|
||||
$scope.model.value.fieldsets.splice($index, 1);
|
||||
$scope.$broadcast("archetypeRemoveFieldset", {index: $index});
|
||||
$scope.$broadcast("archetypeRemoveFieldset", {index: $index, visible: countVisible()});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -364,6 +367,7 @@ angular.module("umbraco").controller("Imulus.ArchetypeController", function ($sc
|
||||
|
||||
// recursive validation of nested fieldsets
|
||||
var nestedFieldsetsValid = true;
|
||||
|
||||
_.each(fieldset.properties, function (property) {
|
||||
if (property != null && property.value != null && property.propertyEditorAlias == "Imulus.Archetype") {
|
||||
_.each(property.value.fieldsets, function (inner) {
|
||||
@@ -403,10 +407,12 @@ angular.module("umbraco").controller("Imulus.ArchetypeController", function ($sc
|
||||
// we need to monitor the "formSubmitting" event from a custom property and broadcast our own event
|
||||
// to forcefully update the appropriate model.value's
|
||||
$scope.activeSubmitWatcher = 0;
|
||||
|
||||
$scope.submitWatcherOnLoad = function () {
|
||||
$scope.activeSubmitWatcher++;
|
||||
return $scope.activeSubmitWatcher;
|
||||
}
|
||||
|
||||
$scope.submitWatcherOnSubmit = function () {
|
||||
$scope.$broadcast("archetypeFormSubmitting");
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
angular.module("umbraco.directives").directive('archetypeProperty', function ($compile, $http, archetypePropertyEditorResource, umbPropEditorHelper, $timeout, $rootScope, $q, fileManager, editorState, archetypeService, archetypeCacheService) {
|
||||
angular.module("umbraco.directives").directive('archetypeProperty', function ($compile, $http, archetypePropertyEditorResource, umbPropEditorHelper, $timeout, $rootScope, $q, fileManager, editorState, archetypeService, archetypeCacheService, notificationsService) {
|
||||
|
||||
var linker = function (scope, element, attrs, ngModelCtrl) {
|
||||
var configFieldsetModel = archetypeService.getFieldsetByAlias(scope.archetypeConfig.fieldsets, scope.fieldset.alias);
|
||||
@@ -40,64 +40,12 @@ angular.module("umbraco.directives").directive('archetypeProperty', function ($c
|
||||
|
||||
var mergedConfig = _.extend(defaultConfigObj, config);
|
||||
|
||||
loadView(pathToView, mergedConfig, defaultValue, alias, propertyAlias, scope, element, ngModelCtrl, propertyValueChanged);
|
||||
loadView(pathToView, mergedConfig, defaultValue, alias, propertyAlias, scope, element, ngModelCtrl, configFieldsetModel);
|
||||
});
|
||||
});
|
||||
|
||||
scope.$on("archetypeFormSubmitting", function (ev, args) {
|
||||
// validate all fieldset properties
|
||||
_.each(scope.fieldset.properties, function (property) {
|
||||
validateProperty(scope.fieldset, property);
|
||||
});
|
||||
|
||||
var validationKey = "validation-f" + scope.fieldsetIndex;
|
||||
ngModelCtrl.$setValidity(validationKey, scope.fieldset.isValid);
|
||||
});
|
||||
|
||||
scope.$on("archetypeRemoveFieldset", function (ev, args) {
|
||||
var validationKey = "validation-f" + args.index;
|
||||
ngModelCtrl.$setValidity(validationKey, true);
|
||||
});
|
||||
|
||||
|
||||
// called when the value of any property in a fieldset changes
|
||||
function propertyValueChanged(fieldset, property) {
|
||||
// it's the Umbraco way to hide the invalid state when altering an invalid property, even if the new value isn't valid either
|
||||
property.isValid = true;
|
||||
setFieldsetValidity(fieldset);
|
||||
}
|
||||
|
||||
// validate a property in a fieldset
|
||||
function validateProperty(fieldset, property) {
|
||||
var propertyConfig = archetypeService.getPropertyByAlias(configFieldsetModel, property.alias);
|
||||
if (propertyConfig) {
|
||||
// use property.value !== property.value to check for NaN values on numeric inputs
|
||||
if (propertyConfig.required && (property.value == null || property.value === "" || property.value !== property.value)) {
|
||||
property.isValid = false;
|
||||
}
|
||||
// issue 116: RegEx validate property value
|
||||
// Only validate the property value if anything has been entered - RegEx is considered a supplement to "required".
|
||||
if (property.isValid == true && propertyConfig.regEx && property.value) {
|
||||
var regEx = new RegExp(propertyConfig.regEx);
|
||||
if (regEx.test(property.value) == false) {
|
||||
property.isValid = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setFieldsetValidity(fieldset);
|
||||
}
|
||||
|
||||
function setFieldsetValidity(fieldset) {
|
||||
// mark the entire fieldset as invalid if there are any invalid properties in the fieldset, otherwise mark it as valid
|
||||
fieldset.isValid =
|
||||
_.find(fieldset.properties, function (property) {
|
||||
return property.isValid == false
|
||||
}) == null;
|
||||
}
|
||||
}
|
||||
|
||||
function loadView(view, config, defaultValue, alias, propertyAlias, scope, element, ngModelCtrl, propertyValueChanged) {
|
||||
function loadView(view, config, defaultValue, alias, propertyAlias, scope, element, ngModelCtrl, configFieldsetModel) {
|
||||
if (view)
|
||||
{
|
||||
$http.get(view, { cache: true }).success(function (data) {
|
||||
@@ -120,6 +68,7 @@ angular.module("umbraco.directives").directive('archetypeProperty', function ($c
|
||||
archetypeService.getFieldset(scope).properties.push(JSON.parse('{"alias": "' + alias + '", "value": "' + defaultValue + '"}'));
|
||||
scope.renderModelPropertyIndex = archetypeService.getPropertyIndexByAlias(archetypeService.getFieldset(scope).properties, alias);
|
||||
}
|
||||
|
||||
scope.renderModel = {};
|
||||
scope.model.value = archetypeService.getFieldsetProperty(scope).value;
|
||||
|
||||
@@ -158,13 +107,28 @@ angular.module("umbraco.directives").directive('archetypeProperty', function ($c
|
||||
|
||||
//watch for changes since there is no two-way binding with the local model.value
|
||||
scope.$watch('model.value', function (newValue, oldValue) {
|
||||
|
||||
archetypeService.getFieldsetProperty(scope).value = newValue;
|
||||
|
||||
// notify the linker that the property value changed
|
||||
propertyValueChanged(archetypeService.getFieldset(scope), archetypeService.getFieldsetProperty(scope));
|
||||
archetypeService.propertyValueChanged(archetypeService.getFieldset(scope), archetypeService.getFieldsetProperty(scope));
|
||||
});
|
||||
|
||||
scope.$on('formSubmitting', function(ev, args){
|
||||
archetypeCacheService.clearInvalidations();
|
||||
archetypeCacheService.clearNotifications();
|
||||
});
|
||||
|
||||
scope.$on('archetypeFormSubmitting', function (ev, args) {
|
||||
// validate all fieldset properties
|
||||
_.each(scope.fieldset.properties, function (property) {
|
||||
archetypeService.validateProperty(scope.fieldset, property, configFieldsetModel);
|
||||
});
|
||||
|
||||
var validationKey = "validation-f" + scope.fieldsetIndex;
|
||||
|
||||
ngModelCtrl.$setValidity(validationKey, scope.fieldset.isValid);
|
||||
|
||||
// did the value change (if it did, it most likely did so during the "formSubmitting" event)
|
||||
var property = archetypeService.getFieldsetProperty(scope);
|
||||
|
||||
@@ -174,15 +138,21 @@ angular.module("umbraco.directives").directive('archetypeProperty', function ($c
|
||||
archetypeService.getFieldsetProperty(scope).value = scope.model.value;
|
||||
|
||||
// notify the linker that the property value changed
|
||||
propertyValueChanged(archetypeService.getFieldset(scope), archetypeService.getFieldsetProperty(scope));
|
||||
archetypeService.propertyValueChanged(archetypeService.getFieldset(scope), archetypeService.getFieldsetProperty(scope));
|
||||
}
|
||||
|
||||
archetypeService.validateMinFieldsets(scope);
|
||||
|
||||
archetypeCacheService.notifyEditor();
|
||||
});
|
||||
|
||||
// issue 114: handle file selection on property editors
|
||||
scope.$on("filesSelected", function (event, args) {
|
||||
// populate the fileNames collection on the property editor state
|
||||
var property = archetypeService.getFieldsetProperty(scope);
|
||||
|
||||
property.editorState.fileNames = [];
|
||||
|
||||
_.each(args.files, function (item) {
|
||||
property.editorState.fileNames.push(item.name);
|
||||
});
|
||||
@@ -195,6 +165,19 @@ angular.module("umbraco.directives").directive('archetypeProperty', function ($c
|
||||
scope.archetypeRenderModel.setFiles(args.files);
|
||||
});
|
||||
|
||||
scope.$on("archetypeRemoveFieldset", function (ev, args) {
|
||||
var validationKey = "validation-f" + args.index;
|
||||
ngModelCtrl.$setValidity(validationKey, true);
|
||||
|
||||
scope.archetypeRenderModel.fieldsets.length = args.visible;
|
||||
|
||||
archetypeService.validateMinFieldsets(scope);
|
||||
});
|
||||
|
||||
scope.$on("archetypeAddFieldset", function (ev, args) {
|
||||
archetypeService.validateMinFieldsets(scope);
|
||||
});
|
||||
|
||||
element.html(data).show();
|
||||
$compile(element.contents())(scope);
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
"toggleAdvancedDescription": "Show advanced options.",
|
||||
"hidePropertyLabels": "Hide Property Labels?",
|
||||
"hidePropertyLabelsDescription": "Hides the property labels.",
|
||||
"minFieldsets": "Min Fieldsets",
|
||||
"maxFieldsets": "Max Fieldsets",
|
||||
"maxFieldsetsDescription": "How many Fieldsets are allowed? Entering '1' will disable the controls. Default is unlimited.",
|
||||
"enableMultipleFieldsets": "Enable Multiple Fieldsets?",
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
"toggleAdvancedDescription": "Show advanced options.",
|
||||
"hidePropertyLabels": "Hide Property Labels?",
|
||||
"hidePropertyLabelsDescription": "Hides the property labels.",
|
||||
"minFieldsets": "Min Fieldsets",
|
||||
"maxFieldsets": "Max Fieldsets",
|
||||
"maxFieldsetsDescription": "How many Fieldsets are allowed? Entering '1' will disable the controls. Default is unlimited.",
|
||||
"enableMultipleFieldsets": "Enable Multiple Fieldsets?",
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
"toggleAdvancedDescription": "Show advanced options.",
|
||||
"hidePropertyLabels": "Hide Property Labels?",
|
||||
"hidePropertyLabelsDescription": "Hides the property labels.",
|
||||
"minFieldsets": "Min Fieldsets",
|
||||
"maxFieldsets": "Max Fieldsets",
|
||||
"maxFieldsetsDescription": "How many Fieldsets are allowed? Entering '1' will disable the controls. Default is unlimited.",
|
||||
"enableMultipleFieldsets": "Enable Multiple Fieldsets?",
|
||||
|
||||
@@ -325,7 +325,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
.archetypeMaxFieldsets{
|
||||
.archetypeMaxFieldsets, .archetypeMinFieldsets {
|
||||
border: 1px solid #ddd;
|
||||
width: 40px;
|
||||
text-align: right;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
angular.module('umbraco.services').factory('archetypeCacheService', function (archetypePropertyEditorResource) {
|
||||
angular.module('umbraco.services').factory('archetypeCacheService', function (archetypePropertyEditorResource, notificationsService) {
|
||||
//private
|
||||
|
||||
var isEntityLookupLoading = false;
|
||||
@@ -7,7 +7,78 @@ angular.module('umbraco.services').factory('archetypeCacheService', function (ar
|
||||
var isDatatypeLookupLoading = false;
|
||||
var datatypeCache = [];
|
||||
|
||||
var notificationQueue = [];
|
||||
var notificationCache = [];
|
||||
|
||||
var invalidationCache = [];
|
||||
|
||||
function findItem(array, item) {
|
||||
return _.find(array, function(value){
|
||||
return value == item;
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
notifyEditor: function() {
|
||||
console.log("queue-v");
|
||||
console.log(notificationQueue);
|
||||
console.log("sent-v");
|
||||
console.log(notificationCache);
|
||||
|
||||
if(this.shouldBeNotified("minFieldsets") && !this.hasBeenNotified("minFieldsets")) {
|
||||
notificationsService.error("Error", "Some of your properties do not contain enough fieldsets.");
|
||||
|
||||
this.removeNotification("minFieldsets");
|
||||
|
||||
notificationCache.push("minFieldsets");
|
||||
}
|
||||
},
|
||||
|
||||
clearInvalidations: function() {
|
||||
invalidationCache = [];
|
||||
},
|
||||
|
||||
addInvalidation: function(key) {
|
||||
if(!this.hasBeenInvalidated(invalidationCache, key)) {
|
||||
invalidationCache.push(key);
|
||||
}
|
||||
},
|
||||
|
||||
removeInvalidation: function(key) {
|
||||
invalidationCache = _.reject(invalidationCache, function(value){
|
||||
return value == key;
|
||||
});
|
||||
},
|
||||
|
||||
hasBeenInvalidated: function(key) {
|
||||
return (typeof findItem(invalidationCache, key) != 'undefined');
|
||||
},
|
||||
|
||||
clearNotifications: function() {
|
||||
notificationCache = [];
|
||||
|
||||
},
|
||||
|
||||
addNotification: function(key) {
|
||||
if(!this.shouldBeNotified(key) && !this.hasBeenNotified(notificationCache, key)) {
|
||||
notificationQueue.push(key);
|
||||
}
|
||||
},
|
||||
|
||||
removeNotification: function(key) {
|
||||
notificationQueue = _.reject(notificationQueue, function(value){
|
||||
return value == key;
|
||||
});
|
||||
},
|
||||
|
||||
shouldBeNotified: function(key) {
|
||||
return (typeof findItem(notificationQueue, key) != 'undefined');
|
||||
},
|
||||
|
||||
hasBeenNotified: function(key) {
|
||||
return (typeof findItem(notificationCache, key) != 'undefined');
|
||||
},
|
||||
|
||||
getDataTypeFromCache: function(guid) {
|
||||
return _.find(datatypeCache, function (dt){
|
||||
return dt.dataTypeGuid == guid;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
angular.module('umbraco.services').factory('archetypeService', function () {
|
||||
|
||||
angular.module('umbraco.services').factory('archetypeService', function (archetypeCacheService) {
|
||||
//public
|
||||
return {
|
||||
//helper that returns a JS ojbect from 'value' string or the original string
|
||||
@@ -67,6 +66,49 @@ angular.module('umbraco.services').factory('archetypeService', function () {
|
||||
},
|
||||
getFieldsetProperty: function (scope) {
|
||||
return this.getFieldset(scope).properties[scope.renderModelPropertyIndex];
|
||||
},
|
||||
setFieldsetValidity: function (fieldset) {
|
||||
// mark the entire fieldset as invalid if there are any invalid properties in the fieldset, otherwise mark it as valid
|
||||
fieldset.isValid =
|
||||
_.find(fieldset.properties, function (property) {
|
||||
return property.isValid == false
|
||||
}) == null;
|
||||
},
|
||||
validateProperty: function (fieldset, property, configFieldsetModel) {
|
||||
var propertyConfig = this.getPropertyByAlias(configFieldsetModel, property.alias);
|
||||
|
||||
if (propertyConfig) {
|
||||
// use property.value !== property.value to check for NaN values on numeric inputs
|
||||
if (propertyConfig.required && (property.value == null || property.value === "" || property.value !== property.value)) {
|
||||
property.isValid = false;
|
||||
}
|
||||
// issue 116: RegEx validate property value
|
||||
// Only validate the property value if anything has been entered - RegEx is considered a supplement to "required".
|
||||
if (property.isValid == true && propertyConfig.regEx && property.value) {
|
||||
var regEx = new RegExp(propertyConfig.regEx);
|
||||
if (regEx.test(property.value) == false) {
|
||||
property.isValid = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.setFieldsetValidity(fieldset);
|
||||
},
|
||||
// called when the value of any property in a fieldset changes
|
||||
propertyValueChanged: function (fieldset, property) {
|
||||
// it's the Umbraco way to hide the invalid state when altering an invalid property, even if the new value isn't valid either
|
||||
property.isValid = true;
|
||||
this.setFieldsetValidity(fieldset);
|
||||
},
|
||||
validateMinFieldsets: function(scope) {
|
||||
//ngModelCtrl.$setValidity('propertyForm', true);
|
||||
archetypeCacheService.removeInvalidation("minFieldsets");
|
||||
|
||||
if(scope.archetypeConfig.minFieldsets && scope.archetypeRenderModel.fieldsets.length < scope.archetypeConfig.minFieldsets) {
|
||||
//ngModelCtrl.$setValidity('propertyForm', false);
|
||||
archetypeCacheService.addInvalidation("minFieldsets");
|
||||
archetypeCacheService.addNotification("minFieldsets");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -97,6 +97,10 @@
|
||||
<label for="archetypeAdvancedOptionsHideLabels"><archetype-localize key="hidePropertyLabels">Hide Property Labels?</archetype-localize><small><archetype-localize key="hidePropertyLabelsDescription">Hides the property labels.</archetype-localize></small></label>
|
||||
<input type="checkbox" id="archetypeAdvancedOptionsHideLabels" ng-model="archetypeConfigRenderModel.hidePropertyLabels"/>
|
||||
</div>
|
||||
<div>
|
||||
<label for="archetypeAdvancedOptionsMinFieldsets"><archetype-localize key="minFieldsets">Min Fieldsets</archetype-localize><small><archetype-localize key="minFieldsetsDescription">How many Fieldsets are required? Leaving blank will disable the control. Default is unlimited.</archetype-localize></small></label>
|
||||
<input type="number" id="archetypeAdvancedOptionsMinFieldsets" class="archetypeMinFieldsets" ng-model="archetypeConfigRenderModel.minFieldsets"/>
|
||||
</div>
|
||||
<div>
|
||||
<label for="archetypeAdvancedOptionsMaxFieldsets"><archetype-localize key="maxFieldsets">Max Fieldsets</archetype-localize><small><archetype-localize key="maxFieldsetsDescription">How many Fieldsets are allowed? Entering '1' will disable the controls. Default is unlimited.</archetype-localize></small></label>
|
||||
<input type="number" id="archetypeAdvancedOptionsMaxFieldsets" class="archetypeMaxFieldsets" ng-model="archetypeConfigRenderModel.maxFieldsets"/>
|
||||
|
||||
Reference in New Issue
Block a user