From 886ab32f275fd9311a543c4c88f1d54fce53a005 Mon Sep 17 00:00:00 2001 From: Shannon Date: Fri, 11 Oct 2013 16:20:10 +1100 Subject: [PATCH] Streamlines both insert macro and change password forms. --- .../common/dialogs/insertmacro.controller.js | 32 +++------ .../src/views/common/dialogs/insertmacro.html | 40 +++++------ .../src/views/dashboard/ChangePassword.html | 68 ++++++++----------- .../dashboard/dashboard.tabs.controller.js | 32 ++++----- 4 files changed, 76 insertions(+), 96 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/insertmacro.controller.js b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/insertmacro.controller.js index 40b609fa17..26f6c5376a 100644 --- a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/insertmacro.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/insertmacro.controller.js @@ -7,7 +7,7 @@ * The controller for the custom insert macro dialog. Until we upgrade the template editor to be angular this * is actually loaded into an iframe with full html. */ -function InsertMacroController($scope, entityResource, macroResource, umbPropEditorHelper, macroService) { +function InsertMacroController($scope, entityResource, macroResource, umbPropEditorHelper, macroService, formHelper) { /** changes the view to edit the params of the selected macro */ function editParams() { @@ -54,10 +54,6 @@ function InsertMacroController($scope, entityResource, macroResource, umbPropEdi //need to find the macro alias for the selected id var macroAlias = $scope.selectedMacro.alias; - /* _.find($scope.macros, function (item) { - return item.id == $scope.selectedMacro.id; - }).alias;*/ - //get the syntax based on the rendering engine var syntax; if ($scope.dialogData.renderingEngine && $scope.dialogData.renderingEngine === "WebForms") { @@ -80,24 +76,18 @@ function InsertMacroController($scope, entityResource, macroResource, umbPropEdi $scope.submitForm = function () { - if ($scope.wizardStep === "paramSelect") { - //we need to broadcast the saving event for the toggle validators to work - $scope.$broadcast("formSubmitting"); - } + if (formHelper.submitForm({ scope: $scope })) { + + formHelper.resetForm({ scope: $scope }); + + if ($scope.wizardStep === "macroSelect") { + editParams(); + } + else { + submitForm(); + } - //ensure the drop down is dirty so the styles validate - $scope.insertMacroForm.$setDirty(true); - if ($scope.insertMacroForm.$invalid) { - return; } - - if ($scope.wizardStep === "macroSelect") { - editParams(); - } - else { - submitForm(); - } - }; //here we check to see if we've been passed a selected macro and if so we'll set the diff --git a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/insertmacro.html b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/insertmacro.html index ec8e3d8ea2..5c6872d76e 100644 --- a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/insertmacro.html +++ b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/insertmacro.html @@ -8,32 +8,32 @@ -
-
-
+
+ + + + Required + - - -
-
+
-
{{$parent.selectedMacro.name}}
+
{{$parent.$parent.selectedMacro.name}}
-
    -
  • +
      +
    • + + + + + +
    • +
    -
    - - -
    -
  • -
- -
+
diff --git a/src/Umbraco.Web.UI.Client/src/views/dashboard/ChangePassword.html b/src/Umbraco.Web.UI.Client/src/views/dashboard/ChangePassword.html index 25422d0a43..e5272d6321 100644 --- a/src/Umbraco.Web.UI.Client/src/views/dashboard/ChangePassword.html +++ b/src/Umbraco.Web.UI.Client/src/views/dashboard/ChangePassword.html @@ -1,48 +1,38 @@ -
-

Change password

-

Enter your current password, then repeat your new password to change it

- - - - + - - Required - +

Change password

+

Enter your current password, then repeat your new password to change it

- - Old password was not correct - -
+ + + - - + Required + - Required - + - - + + - - Required - + Required + - - You must re-enter the new password - + + - + Password does not match + - - - - - \ No newline at end of file + + + +
+ diff --git a/src/Umbraco.Web.UI.Client/src/views/dashboard/dashboard.tabs.controller.js b/src/Umbraco.Web.UI.Client/src/views/dashboard/dashboard.tabs.controller.js index 387fc8ef0b..1d20c73c19 100644 --- a/src/Umbraco.Web.UI.Client/src/views/dashboard/dashboard.tabs.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/dashboard/dashboard.tabs.controller.js @@ -80,25 +80,25 @@ function MediaFolderBrowserDashboardController($rootScope, $scope, assetsService angular.module("umbraco").controller("Umbraco.Dashboard.MediaFolderBrowserDashboardController", MediaFolderBrowserDashboardController); -function ChangePasswordDashboardController($scope, xmlhelper, $log, userResource) { +function ChangePasswordDashboardController($scope, xmlhelper, $log, userResource, formHelper) { //this is the model we will pass to the service $scope.profile = {}; - $scope.changePassword = function (p) { - - //ensure form is dirty so the styles validate - $scope.passwordForm.$setDirty(true); - - if ($scope.passwordForm.$invalid) { - return; - } + $scope.changePassword = function(p) { - userResource.changePassword(p.oldPassword, p.newPassword).then(function () { - $scope.passwordForm.$setValidity(true); - }, function () { - //this only happens if there is a wrong oldPassword sent along - $scope.passwordForm.oldpass.$setValidity("oldPassword", false); - }); - } + if (formHelper.submitForm({ scope: $scope })) { + userResource.changePassword(p.oldPassword, p.newPassword).then(function() { + + formHelper.resetForm({ scope: $scope, notifications: data.notifications }); + + //TODO: This is temporary - server validation will work automatically with the val-server directives. + $scope.passwordForm.$setValidity(true); + }, function () { + //TODO: This is temporary - server validation will work automatically with the val-server directives. + //this only happens if there is a wrong oldPassword sent along + $scope.passwordForm.oldpass.$setValidity("oldPassword", false); + }); + } + }; } angular.module("umbraco").controller("Umbraco.Dashboard.StartupChangePasswordController", ChangePasswordDashboardController); \ No newline at end of file