Skip to content

Commit

Permalink
Fixes #9779: Save button is not disable during saving
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphaelGauthier committed Dec 6, 2016
1 parent d2f0c74 commit e1f0ebf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion builder/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ <h4 class="panel-title">
<span class="glyphicon glyphicon-plus-sign" style="margin-right:5px"></span>
Add methods
</div>
<button ng-disabled="editForm.$pending || editForm.$invalid || CForm.form.$invalid || checkSelectedTechnique() || saving" class="btn btn-default pull-right btn-save" ng-class="{saving : saving}" ng-click="saveTechnique()">
<button ng-disabled="editForm.$pending || editForm.$invalid || CForm.form.$invalid || checkSelectedTechnique() || selectedTechnique.saving" class="btn btn-default pull-right btn-save" ng-class="{saving : selectedTechnique.saving}" ng-click="saveTechnique()">
<span class="glyphicon glyphicon-cog saving"></span>
Save
</button>
Expand Down
15 changes: 8 additions & 7 deletions builder/js/ncf.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,6 @@ app.controller('ncf-builder', function ($scope, $modal, $http, $log, $location,

$scope.CForm = {};

$scope.saving = false;

$scope.setPath = function() {
var path = $location.search().path;
if (path === undefined) {
Expand Down Expand Up @@ -433,6 +431,7 @@ $scope.groupMethodsByCategory = function () {
// Select the technique, by using angular.copy to have different objects
$scope.selectedTechnique=angular.copy(technique);
$scope.originalTechnique=angular.copy($scope.selectedTechnique);
$scope.selectedTechnique.saving=false;
}
};

Expand Down Expand Up @@ -755,6 +754,7 @@ $scope.groupMethodsByCategory = function () {
// Resets a Technique to its original state
$scope.resetTechnique = function() {
$scope.selectedTechnique=angular.copy($scope.originalTechnique);
$scope.selectedTechnique.saving=false;
// Reset selected method too
if ($scope.selectedMethod !== undefined) {
// if original_index did not exists, close the edit method tab
Expand Down Expand Up @@ -809,6 +809,7 @@ $scope.groupMethodsByCategory = function () {

// Save a technique
$scope.saveTechnique = function() {
$scope.selectedTechnique.saving = true;
// Set technique bundle name
$scope.setBundleName($scope.selectedTechnique);
// make a copy of data so we don't lose the selected technique
Expand All @@ -822,14 +823,15 @@ $scope.groupMethodsByCategory = function () {
// Update selected technique if it's still the same technique
// update technique from the tree
var saveSuccess = function(data, status, headers, config) {
$scope.saving = false;
$scope.selectedTechnique.saving = false;
// Transform back ncfTechnique to UITechnique, that will make it ok
var savedTechnique = toTechUI(ncfTechnique);

// Update technique if still selected
if (angular.equals($scope.originalTechnique, origin_technique)) {
// If we were cloning a technique, remove its 'clone' state
savedTechnique.isClone = false;
savedTechnique.saving = false;
$scope.originalTechnique=angular.copy(savedTechnique);
$scope.selectedTechnique=angular.copy(savedTechnique);
// We will lose the link between the selected method and the technique, to prevent unintended behavior, close the edit method panel
Expand All @@ -848,22 +850,21 @@ $scope.groupMethodsByCategory = function () {
}
}
var saveError = function(action, data) {
$scope.saving = false;
$scope.selectedTechnique.saving = false;
$scope.handle_error("while "+action+" Technique '"+ data.technique.name+"'")
}

// Actually save the technique through API
$scope.saving = true;
if ($scope.originalTechnique.bundle_name === undefined) {
$http.post("/ncf/api/techniques", data).
success(saveSuccess).
error(saveError("creating", data));
} else {
$http.put("/ncf/api/techniques", data).
success(saveSuccess).
error(saveError("saving",data));
error(saveError("saving", data));
}
};

// Popup definitions

// Popup to know if there is some changes to save before switching of selected technique
Expand Down

0 comments on commit e1f0ebf

Please sign in to comment.