(js) Prohibit duplicate calendar categories

This commit is contained in:
Francis Lachapelle
2018-08-02 09:29:33 -04:00
parent 5a48fca43d
commit 30a81528a2
4 changed files with 28 additions and 1 deletions
@@ -69,6 +69,10 @@
form.$setDirty();
};
this.resetCalendarCategoryValidity = function(index, form) {
form['calendarCategory_' + index].$setValidity('duplicate', true);
};
this.removeCalendarCategory = function(index, form) {
var key = this.preferences.defaults.SOGoCalendarCategories[index];
this.preferences.defaults.SOGoCalendarCategories.splice(index, 1);
@@ -320,6 +324,7 @@
}
}
// IMAP labels must be unique
if (this.preferences.defaults.SOGoMailLabelsColorsKeys.length !=
this.preferences.defaults.SOGoMailLabelsColorsValues.length ||
this.preferences.defaults.SOGoMailLabelsColorsKeys.length !=
@@ -335,6 +340,20 @@
});
}
// Calendar categories must be unique
if (this.preferences.defaults.SOGoCalendarCategories.length !=
_.uniq(this.preferences.defaults.SOGoCalendarCategories).length) {
Dialog.alert(l('Error'), l("Calendar categories must have unique names."));
_.forEach(this.preferences.defaults.SOGoCalendarCategories, function (value, i, keys) {
if (form['calendarCategory_' + i].$dirty &&
(keys.indexOf(value) != i ||
keys.indexOf(value, i+1) > -1)) {
form['calendarCategory_' + i].$setValidity('duplicate', false);
sendForm = false;
}
});
}
if (sendForm)
return this.preferences.$save().then(function(data) {
if (!options || !options.quick) {