What a mess this is turing out to be 👎

This commit is contained in:
kgiszewski
2015-08-18 12:09:16 -04:00
parent b42e411e49
commit e9da0aa351
3 changed files with 86 additions and 21 deletions
+11 -2
View File
@@ -114,6 +114,11 @@ angular.module("umbraco.directives").directive('archetypeProperty', function ($c
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) {
@@ -135,6 +140,10 @@ angular.module("umbraco.directives").directive('archetypeProperty', function ($c
// notify the linker that the property value changed
archetypeService.propertyValueChanged(archetypeService.getFieldset(scope), archetypeService.getFieldsetProperty(scope));
}
archetypeService.validateMinFieldsets(scope);
archetypeCacheService.notifyEditor();
});
// issue 114: handle file selection on property editors
@@ -162,11 +171,11 @@ angular.module("umbraco.directives").directive('archetypeProperty', function ($c
scope.archetypeRenderModel.fieldsets.length = args.visible;
archetypeService.validateMinFieldsets(scope, ngModelCtrl, notificationsService);
archetypeService.validateMinFieldsets(scope);
});
scope.$on("archetypeAddFieldset", function (ev, args) {
archetypeService.validateMinFieldsets(scope, ngModelCtrl, notificationsService);
archetypeService.validateMinFieldsets(scope);
});
element.html(data).show();
+69 -10
View File
@@ -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,19 +7,78 @@ angular.module('umbraco.services').factory('archetypeCacheService', function (ar
var isDatatypeLookupLoading = false;
var datatypeCache = [];
var notificationsCache = [];
var notificationQueue = [];
var notificationCache = [];
var invalidationCache = [];
function findItem(array, item) {
return _.find(array, function(value){
return value == item;
});
}
return {
addNotification: function(key) {
notificationsCache.push(key);
},
hasBeenNotified: function(key) {
var notification = _.find(notificationsCache, function(value){
return value.toLowerCase() == key.toLowerCase();
});
notifyEditor: function() {
console.log("queue-v");
console.log(notificationQueue);
console.log("sent-v");
console.log(notificationCache);
return (typeof notification != 'undefined');
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;
+6 -9
View File
@@ -100,17 +100,14 @@ angular.module('umbraco.services').factory('archetypeService', function (archety
property.isValid = true;
this.setFieldsetValidity(fieldset);
},
validateMinFieldsets: function(scope, ngModelCtrl, notificationsService) {
ngModelCtrl.$setValidity('propertyForm', true);
validateMinFieldsets: function(scope) {
//ngModelCtrl.$setValidity('propertyForm', true);
archetypeCacheService.removeInvalidation("minFieldsets");
//min fieldsets
if(scope.archetypeConfig.minFieldsets && scope.archetypeRenderModel.fieldsets.length < scope.archetypeConfig.minFieldsets) {
ngModelCtrl.$setValidity('propertyForm', false);
if(!archetypeCacheService.hasBeenNotified("minFieldsets")) {
notificationsService.error("Error", "Please check your input as it requires at least " + scope.archetypeConfig.minFieldsets + " fieldsets.");
archetypeCacheService.addNotification("minFieldsets");
}
//ngModelCtrl.$setValidity('propertyForm', false);
archetypeCacheService.addInvalidation("minFieldsets");
archetypeCacheService.addNotification("minFieldsets");
}
}
}