Merge pull request #1665 from umbraco/temp-U4-9325
fixes: U4-9325 New template editor stays in a $dirty state if you cha…
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
function TemplatesEditController($scope, $routeParams, templateResource, assetsService, notificationsService, editorState, navigationService, appState, macroService, treeService) {
|
||||
function TemplatesEditController($scope, $routeParams, templateResource, assetsService, notificationsService, editorState, navigationService, appState, macroService, treeService, angularHelper) {
|
||||
|
||||
var vm = this;
|
||||
var oldMasterTemplateAlias = null;
|
||||
@@ -53,6 +53,10 @@
|
||||
|
||||
}
|
||||
|
||||
// clear $dirty state on form
|
||||
setFormState("pristine");
|
||||
|
||||
|
||||
}, function (err) {
|
||||
notificationsService.error("Template save failed");
|
||||
vm.page.saveButtonState = "error";
|
||||
@@ -426,6 +430,10 @@
|
||||
vm.editor.setValue(templateCode);
|
||||
vm.editor.clearSelection();
|
||||
vm.editor.navigateFileStart();
|
||||
|
||||
// set form state to $dirty
|
||||
setFormState("dirty");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -433,6 +441,9 @@
|
||||
vm.editor.moveCursorToPosition(vm.currentPosition);
|
||||
vm.editor.insert(str);
|
||||
vm.editor.focus();
|
||||
|
||||
// set form state to $dirty
|
||||
setFormState("dirty");
|
||||
}
|
||||
|
||||
function wrap(str) {
|
||||
@@ -441,12 +452,28 @@
|
||||
str = str.replace("{0}", selectedContent);
|
||||
vm.editor.insert(str);
|
||||
vm.editor.focus();
|
||||
|
||||
// set form state to $dirty
|
||||
setFormState("dirty");
|
||||
}
|
||||
|
||||
function persistCurrentLocation() {
|
||||
vm.currentPosition = vm.editor.getCursorPosition();
|
||||
}
|
||||
|
||||
function setFormState(state) {
|
||||
|
||||
// get the current form
|
||||
var currentForm = angularHelper.getCurrentForm($scope);
|
||||
|
||||
// set state
|
||||
if(state === "dirty") {
|
||||
currentForm.$setDirty();
|
||||
} else if(state === "pristine") {
|
||||
currentForm.$setPristine();
|
||||
}
|
||||
}
|
||||
|
||||
vm.init();
|
||||
|
||||
}
|
||||
|
||||
@@ -88,7 +88,15 @@
|
||||
appState: {
|
||||
getSectionState : function() { return {}; }
|
||||
},
|
||||
macroService: {}
|
||||
macroService: {},
|
||||
angularHelper: {
|
||||
getCurrentForm: function() {
|
||||
return {
|
||||
$setDirty: function() {},
|
||||
$setPristine: function() {}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user