Streamlines both insert macro and change password forms.

This commit is contained in:
Shannon
2013-10-11 16:20:10 +11:00
parent 937b308444
commit 886ab32f27
4 changed files with 76 additions and 96 deletions

View File

@@ -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

View File

@@ -8,32 +8,32 @@
</div>
</div>
<div class="umb-panel-body no-header umb-scrollable" auto-scale="1">
<div class="umb-control-group" ng-switch="wizardStep">
<div class="umb-pane" ng-switch-when="macroSelect">
<div class="umb-panel-body no-header umb-scrollable" auto-scale="1" ng-switch="wizardStep">
<umb-control-group label="Choose a macro" ng-switch-when="macroSelect">
<select class="umb-editor" ng-change="submitForm()" name="selectedMacro" ng-model="$parent.$parent.selectedMacro" ng-options="m as m.name for m in macros" required>
<option value="">Choose macro...</option>
</select>
<span class="help-inline" val-msg-for="selectedMacro" val-toggle-msg="required">Required</span>
</umb-control-group>
<label for="macroName">Choose a macro</label>
<select class="umb-editor" ng-change="submitForm()" name="selectedMacro" ng-model="$parent.selectedMacro" ng-options="m as m.name for m in macros" required>
<option value="">Choose macro...</option>
</select>
</div>
<div class="umb-pane" ng-switch-when="paramSelect">
<div class="umb-pane" ng-switch-when="paramSelect">
<h5>{{$parent.selectedMacro.name}}</h5>
<h5>{{$parent.$parent.selectedMacro.name}}</h5>
<ul class="unstyled">
<li ng-repeat="param in $parent.macroParams">
<ul class="unstyled">
<li ng-repeat="param in $parent.macroParams">
<umb-control-group label="{{param.name}}">
<umb-editor model="param"></umb-editor>
</umb-control-group>
</li>
</ul>
<div class="control-group umb-control-group" ng-class="{error: insertMacroForm.$invalid}">
<label class="control-label">{{param.name}}</label>
<umb-editor model="param"></umb-editor>
</div>
</li>
</ul>
</div>
</div>
</div>
</div>

View File

@@ -1,48 +1,38 @@
<form novalidate name="passwordForm" ng-controller="Umbraco.Dashboard.StartupChangePasswordController" ng-submit="changePassword(profile)">
<h3>Change password</h3>
<p>Enter your current password, then repeat your new password to change it</p>
<umb-pane>
<umb-control-group label="Old password">
<input type="password" name="oldpass" ng-model="profile.oldPassword" required/>
<form novalidate name="passwordForm"
ng-controller="Umbraco.Dashboard.StartupChangePasswordController"
ng-submit="changePassword(profile)"
val-form-manager>
<small class="help-inline"
ng-show="passwordForm.oldpass.$error.required">
Required
</small>
<h3>Change password</h3>
<p>Enter your current password, then repeat your new password to change it</p>
<small class="help-inline"
ng-show="passwordForm.passcompare.$error.serverside">
Old password was not correct
</small>
</umb-control-group>
<umb-pane>
<umb-control-group label="Old password">
<input type="password" name="oldpass" ng-model="profile.oldPassword"
required
val-server />
<umb-control-group label="New password">
<input type="password" name="pass" ng-model="profile.newPassword" required/>
<span class="help-inline" val-msg-for="oldpass" val-toggle-msg="required">Required</span>
<span class="help-inline" val-msg-for="oldpass" val-toggle-msg="valServer"></span>
<span class="help-inline" val-msg-for="pass" val-toggle-msg="required">Required</span>
</umb-control-group>
</umb-control-group>
<umb-control-group label="Repeat new password">
<input type="password" name="passcompare"
val-custom="{compare: '$value === profile.newPassword'}"
val-custom-watch="'profile.newPassword'"
ng-model="profile.repeatNewPassword" required/>
<umb-control-group label="New password">
<input type="password" name="pass" ng-model="profile.newPassword" required/>
<small class="help-inline"
ng-show="passwordForm.passcompare.$error.required">
Required
</small>
<span class="help-inline" val-msg-for="pass" val-toggle-msg="required">Required</span>
</umb-control-group>
<small class="help-inline"
ng-show="passwordForm.passcompare.$error.compare">
You must re-enter the new password
</small>
<umb-control-group label="Repeat new password">
<input type="password" name="passcompare"
val-compare="pass"
ng-model="profile.repeatNewPassword" />
</umb-control-group>
<small class="help-inline" val-msg-for="passcompare" val-toggle-msg="valCompare">Password does not match</small>
</umb-control-group>
<umb-control-group hideLabel="1">
<button class="btn btn-primary">Change</button>
</umb-control-group>
</umb-pane>
</form>
<umb-control-group hideLabel="1">
<button class="btn btn-primary">Change</button>
</umb-control-group>
</umb-pane>
</form>

View File

@@ -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);