Dims buttons during action to prevent multiple saves

This commit is contained in:
perploug
2013-11-28 13:06:19 +01:00
parent de1e3d150f
commit 04ccbdde4d
7 changed files with 30 additions and 13 deletions

View File

@@ -71,7 +71,7 @@
margin:0px 20px;
}
.umb-btn-toolbar .dimmed{
.umb-btn-toolbar .dimmed, .umb-dimmed{
opacity: 0.6;
}

View File

@@ -111,6 +111,8 @@ function ContentEditController($scope, $routeParams, $q, $timeout, $window, appS
function performSave(args) {
var deferred = $q.defer();
$scope.busy = true;
if (formHelper.submitForm({ scope: $scope, statusMessage: args.statusMessage })) {
args.saveMethod($scope.content, $routeParams.create, fileManager.getFiles())
@@ -125,6 +127,7 @@ function ContentEditController($scope, $routeParams, $q, $timeout, $window, appS
});
editorState.set($scope.content);
$scope.busy = false;
configureButtons(data);
@@ -143,6 +146,7 @@ function ContentEditController($scope, $routeParams, $q, $timeout, $window, appS
});
editorState.set($scope.content);
$scope.busy = false;
deferred.reject(err);
});
@@ -241,10 +245,14 @@ function ContentEditController($scope, $routeParams, $q, $timeout, $window, appS
/** this method is called for all action buttons and then we proxy based on the btn definition */
$scope.performAction = function(btn) {
if (!btn || !angular.isFunction(btn.handler)) {
throw "btn.handler must be a function reference";
}
btn.handler.apply(this);
if(!$scope.busy){
btn.handler.apply(this);
}
};
}

View File

@@ -39,14 +39,14 @@
<div class="umb-tab-buttons">
<div class="umb-tab-buttons" ng-class="{'umb-dimmed': busy}">
<div class="btn-group">
<a class="btn" ng-click="preview(content)">
<localize key="buttons_showPage">Preview page</localize>
</a>
</div>
<div class="btn-group dropup" ng-if="defaultButton">
<div class="btn-group dropup" ng-if="defaultButton" >
<!-- primary button -->
<a class="btn btn-success" href="#" ng-click="performAction(defaultButton)" prevent-default>
<localize key="{{defaultButton.labelKey}}">{{defaultButton.labelKey}}</localize>
@@ -56,14 +56,16 @@
<span class="caret"></span>
</a>
<!-- sub buttons -->
<ul class="dropdown-menu bottom-up" role="menu" aria-labelledby="dLabel" ng-if="subButtons.length > 0">
<ul class="dropdown-menu bottom-up" role="menu" aria-labelledby="dLabel" ng-if="subButtons.length > 0">
<li ng-repeat="btn in subButtons">
<a href="#" ng-click="performAction(btn)" prevent-default>
<a href="#" ng-click="performAction(btn)" ng-disabled="true" prevent-default>
<localize key="{{btn.labelKey}}">{{btn.labelKey}}</localize>
</a>
</li>
</li>
</ul>
</div>
</div>
</div>

View File

@@ -37,7 +37,7 @@
<umb-editor model="property"></umb-editor>
</umb-property>
<div class="umb-tab-buttons">
<div class="umb-tab-buttons" ng-class="{'umb-dimmed': busy}">
<div class="btn-group">
<button type="submit" data-hotkey="ctrl+s" class="btn btn-success">
<localize key="buttons_save">Save</localize>

View File

@@ -46,7 +46,9 @@ function mediaEditController($scope, $routeParams, appState, mediaResource, navi
$scope.save = function () {
if (formHelper.submitForm({ scope: $scope, statusMessage: "Saving..." })) {
if (!$scope.busy && formHelper.submitForm({ scope: $scope, statusMessage: "Saving..." })) {
$scope.busy = true;
mediaResource.save($scope.content, $routeParams.create, fileManager.getFiles())
.then(function(data) {
@@ -60,6 +62,7 @@ function mediaEditController($scope, $routeParams, appState, mediaResource, navi
});
editorState.set($scope.content);
$scope.busy = false;
navigationService.syncTree({ tree: "media", path: data.path, forceReload: true }).then(function (syncArgs) {
$scope.currentNode = syncArgs.node;
@@ -74,6 +77,7 @@ function mediaEditController($scope, $routeParams, appState, mediaResource, navi
});
editorState.set($scope.content);
$scope.busy = false;
});
}

View File

@@ -37,7 +37,7 @@
<umb-editor model="property"></umb-editor>
</umb-property>
<div class="umb-tab-buttons">
<div class="umb-tab-buttons" ng-class="{'umb-dimmed': busy}">
<div class="btn-group">
<button type="submit" data-hotkey="ctrl+s" class="btn btn-success">
<localize key="buttons_save">Save</localize>

View File

@@ -84,8 +84,10 @@ function MemberEditController($scope, $routeParams, $location, $q, $window, appS
$scope.save = function() {
if (formHelper.submitForm({ scope: $scope, statusMessage: "Saving..." })) {
if (!$scope.busy && formHelper.submitForm({ scope: $scope, statusMessage: "Saving..." })) {
$scope.busy = true;
memberResource.save($scope.content, $routeParams.create, fileManager.getFiles())
.then(function(data) {
@@ -100,7 +102,8 @@ function MemberEditController($scope, $routeParams, $location, $q, $window, appS
});
editorState.set($scope.content);
$scope.busy = false;
var path = buildTreePath(data);
navigationService.syncTree({ tree: "member", path: path.split(","), forceReload: true }).then(function (syncArgs) {
@@ -116,7 +119,7 @@ function MemberEditController($scope, $routeParams, $location, $q, $window, appS
});
editorState.set($scope.content);
$scope.busy = false;
});
}