Skip to content

Commit

Permalink
Merge pull request #67 from TAMULib/dame-sprint-dec-d01232-modals_sec…
Browse files Browse the repository at this point in the history
…ond_submit

Defect D-01232: Modal submissions don't block second attempts
  • Loading branch information
kaladay authored Dec 19, 2018
2 parents d3649a5 + 43794f6 commit acf1c7a
Show file tree
Hide file tree
Showing 18 changed files with 123 additions and 91 deletions.
30 changes: 19 additions & 11 deletions src/main/webapp/app/controllers/iRManagementController.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ cap.controller("IrManagementController", function($controller, $scope, $q, $loca
$scope: $scope
}));

$scope.irs = IRRepo.getAll();
$scope.irs = IRRepo.getAll();
$scope.iRTypes = [];


$scope.submitClicked = false;

IRRepo.getTypes($scope.iRTypes).then(function() {
$scope.irToCreate = IRRepo.getScaffold({
type: $scope.iRTypes[0].value
Expand Down Expand Up @@ -36,8 +38,8 @@ cap.controller("IrManagementController", function($controller, $scope, $q, $loca
if (force || $scope.verificationResults.status === 'SUCCESS') {
$scope.verificationResults = {};
}
};
};

$scope.irToDelete = {};
$scope.irToEdit = {};
resetVerification(true);
Expand All @@ -56,24 +58,26 @@ cap.controller("IrManagementController", function($controller, $scope, $q, $loca
}
resetVerification(true);
delete $scope.irToVerify;
$scope.closeModal();
$scope.closeModal();
};

$scope.resetIrForms();
$scope.resetIrForms();

$scope.startCreate = function() {
$scope.schemas = SchemaRepo.getAll();
$scope.openModal("#createIRModal");
};

$scope.createIr = function() {
$scope.submitClicked = true;
IRRepo.create($scope.irToCreate).then(function(res) {
if(angular.fromJson(res.body).meta.status === "SUCCESS") {
$scope.cancelCreateIr();
}
$scope.submitClicked = false;
});
};

$scope.cancelCreateIr = function() {
angular.extend($scope.irToCreate, IRRepo.getScaffold());
$scope.resetIrForms();
Expand All @@ -86,15 +90,17 @@ cap.controller("IrManagementController", function($controller, $scope, $q, $loca
};

$scope.updateIr = function() {
$scope.submitClicked = true;
$scope.irToEdit.dirty(true);
$scope.irToEdit.save().then(function() {
$scope.cancelEditIr();
$scope.submitClicked = false;
});
};

$scope.cancelEditIr = function(ir) {
$scope.irToEdit.refresh();
$scope.irToEdit = {};
$scope.irToEdit = {};
$scope.resetIrForms();
};

Expand All @@ -104,14 +110,16 @@ cap.controller("IrManagementController", function($controller, $scope, $q, $loca
};

$scope.cancelDeleteIr = function(ir) {
$scope.irToDelete = {};
$scope.irToDelete = {};
$scope.closeModal();
};

$scope.deleteIr = function(ir) {
$scope.submitClicked = true;
IRRepo.delete(ir).then(function(res) {
if(angular.fromJson(res.body).meta.status === "SUCCESS") {
$scope.cancelDeleteIr();
$scope.submitClicked = false;
}
});
};
Expand Down Expand Up @@ -146,4 +154,4 @@ cap.controller("IrManagementController", function($controller, $scope, $q, $loca
$scope.setTable();
});

});
});
25 changes: 23 additions & 2 deletions src/main/webapp/app/controllers/irContextController.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ cap.controller("IrContextController", function ($controller, $location, $routePa

$scope.irForm = {};

$scope.submitClicked = false;

$scope.theaterMode = false;

$scope.setOrToggleTheaterMode = function (mode) {
Expand All @@ -27,6 +29,7 @@ cap.controller("IrContextController", function ($controller, $location, $routePa
$scope.context = $scope.ir.loadContext($scope.ir.contextUri);

$scope.createContainer = function (form) {
$scope.submitClicked = true;
var subject = $scope.context.uri;
var triples = [];
angular.forEach(form.entries, function (entry) {
Expand All @@ -41,18 +44,23 @@ cap.controller("IrContextController", function ($controller, $location, $routePa

$scope.context.createContainer(triples).then(function () {
$scope.closeModal();
$scope.submitClicked = false;
});
};

$scope.advancedUpdate = function (sparql) {
$scope.submitClicked = true;
$scope.context.advancedUpdate(sparql).then(function () {
$scope.closeModal();
$scope.submitClicked = false;
});
};

$scope.uploadResource = function (file) {
$scope.submitClicked = true;
$scope.context.createResource(file).then(function () {
$scope.resetUploadResource();
$scope.submitClicked = false;
});
};

Expand All @@ -76,6 +84,8 @@ cap.controller("IrContextController", function ($controller, $location, $routePa
};

$scope.addMetadata = function (form) {
$scope.submitClicked = true;

var triples = [];
angular.forEach(form.entries, function (entry) {
triples.push({
Expand All @@ -87,6 +97,7 @@ cap.controller("IrContextController", function ($controller, $location, $routePa

$scope.context.createMetadata(triples).then(function () {
$scope.closeModal();
$scope.submitClicked = false;
});
};

Expand All @@ -96,22 +107,25 @@ cap.controller("IrContextController", function ($controller, $location, $routePa
};

$scope.deleteIrContext = function () {
$scope.submitClicked = true;

var ir = $scope.context.ir;
var currentTriple = $scope.context.triple;
var isResource = $scope.context.resource;

var deleteContext = isResource ? $scope.context.removeResources : $scope.context.removeContainers;

$scope.context = ir.loadContext($scope.context.parent.object);

deleteContext([currentTriple]).then(function () {
$scope.context = ir.loadContext($scope.context.uri, true);
$scope.submitClicked = false;
});

};

$scope.revertVersion = function () {
$scope.submitClicked = true;

var ir = $scope.context.ir;
var currentContext = $scope.context;
Expand All @@ -120,10 +134,12 @@ cap.controller("IrContextController", function ($controller, $location, $routePa

$scope.context.revertVersion(currentContext).then(function () {
$scope.context = ir.loadContext($scope.context.uri, true);
$scope.submitClicked = false;
});
};

$scope.deleteVersion = function () {
$scope.submitClicked = true;

var ir = $scope.context.ir;
var currentContext = $scope.context;
Expand All @@ -134,6 +150,7 @@ cap.controller("IrContextController", function ($controller, $location, $routePa

$scope.context.deleteVersion(currentContext).then(function () {
$scope.context = ir.loadContext($scope.context.uri, true);
$scope.submitClicked = false;
});
};

Expand All @@ -142,14 +159,18 @@ cap.controller("IrContextController", function ($controller, $location, $routePa
};

$scope.commitTransaction = function() {
$scope.submitClicked = true;
$scope.context.ir.commitTransaction().then(function() {
$scope.closeModal();
$scope.submitClicked = false;
});
};

$scope.rollbackTransaction = function() {
$scope.submitClicked = true;
$scope.context.ir.rollbackTransaction().then(function() {
$scope.closeModal();
$scope.submitClicked = false;
});
};

Expand Down Expand Up @@ -213,4 +234,4 @@ cap.controller("IrContextController", function ($controller, $location, $routePa

});

});
});
26 changes: 17 additions & 9 deletions src/main/webapp/app/controllers/schemaManagementController.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
cap.controller("SchemaManagementController", function($controller, $scope, SchemaRepo, NgTableParams) {

angular.extend(this, $controller('CoreAdminController', {
$scope: $scope
}));

$scope.schemas = SchemaRepo.getAll();
$scope.schemas = SchemaRepo.getAll();

$scope.schemaToCreate = SchemaRepo.getScaffold();
$scope.schemaToEdit = SchemaRepo.getScaffold();
Expand All @@ -14,24 +14,28 @@ cap.controller("SchemaManagementController", function($controller, $scope, Schem
validations: SchemaRepo.getValidations(),
getResults: SchemaRepo.getValidationResults
};


$scope.submitClicked = false;

$scope.resetSchemaForms = function() {
SchemaRepo.clearValidationResults();
for (var key in $scope.schemaForms) {
if ($scope.schemaForms[key] !== undefined && !$scope.schemaForms[key].$pristine && $scope.schemaForms[key].$setPristine) {
$scope.schemaForms[key].$setPristine();
}
}
$scope.closeModal();
$scope.closeModal();
};

$scope.resetSchemaForms();

$scope.createSchema = function() {
$scope.submitClicked = true;
SchemaRepo.create($scope.schemaToCreate).then(function(res) {
if(angular.fromJson(res.body).meta.status === "SUCCESS") {
$scope.cancelCreateSchema();
}
$scope.submitClicked = false;
});
};

Expand All @@ -46,14 +50,16 @@ cap.controller("SchemaManagementController", function($controller, $scope, Schem
};

$scope.updateSchema = function() {
$scope.submitClicked = true;
$scope.schemaToEdit.save().then(function() {
$scope.cancelEditSchema();
$scope.submitClicked = false;
});
};

$scope.cancelEditSchema = function(schema) {
$scope.schemaToEdit.refresh();
$scope.schemaToEdit = SchemaRepo.getScaffold();
$scope.schemaToEdit = SchemaRepo.getScaffold();
$scope.resetSchemaForms();
};

Expand All @@ -63,15 +69,17 @@ cap.controller("SchemaManagementController", function($controller, $scope, Schem
};

$scope.cancelDeleteSchema = function(schema) {
$scope.schemaToDelete = {};
$scope.schemaToDelete = {};
$scope.closeModal();
};

$scope.deleteSchema = function(schema) {
$scope.submitClicked = true;
SchemaRepo.delete(schema).then(function(res) {
if(angular.fromJson(res.body).meta.status === "SUCCESS") {
$scope.resetSchemaForms();
}
$scope.submitClicked = false;
});
};

Expand All @@ -96,6 +104,6 @@ cap.controller("SchemaManagementController", function($controller, $scope, Schem
});
};
$scope.setTable();
});
});
});

});
2 changes: 1 addition & 1 deletion src/main/webapp/app/views/modals/addMetadataModal.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ <h4 class="modal-title">Add Metadata</h4>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" ng-class="{'btn-warning': irForm.addMetadata.$dirty}" ng-click="closeModal()">Cancel</button>
<button type="submit" class="btn btn-success" ng-disabled="irForm.addMetadata.$invalid">Add</button>
<button type="submit" class="btn btn-success" ng-disabled="irForm.addMetadata.$invalid || submitClicked">Add</button>
</div>
</form>
4 changes: 2 additions & 2 deletions src/main/webapp/app/views/modals/advancedUpdateModal.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ <h4 class="modal-title">Advanced Update</h4>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" ng-click="resetAdvancedUpdate()">Cancel</button>
<button type="submit" class="btn btn-success" ng-disabled="irForm.advancedUpdate.query.length === 0">Update</button>
<button type="submit" class="btn btn-success" ng-disabled="irForm.advancedUpdate.query.length === 0 || submitClicked">Update</button>
</div>
</form>
</form>
4 changes: 2 additions & 2 deletions src/main/webapp/app/views/modals/commitTransactionModal.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ <h4 class="modal-title">Confirm Commit</h4>
</div>
<div class="modal-body">
<h3>Are you sure you want to commit this transaction?</h3>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" ng-click="closeModal()">Cancel</button>
<button type="button" class="btn btn-success" ng-click="commitTransaction()">Confirm</button>
<button type="button" class="btn btn-success" ng-click="commitTransaction()" ng-disabled="submitClicked">Confirm</button>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ <h4 class="modal-title">Confirm Removal</h4>
<div class="modal-body">
<h3>Are you sure you want to remove:</h3>
<p>{{context.name}}</p>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" ng-click="closeModal()">Cancel</button>
<button type="submit" class="btn btn-danger">Confirm</button>
<button type="submit" class="btn btn-danger" ng-disabled="submitClicked">Confirm</button>
</div>
</form>
</form>
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ <h4 class="modal-title">Confirm Reversion</h4>
<div class="modal-body">
<h3>Are you sure you want to revert to this version:</h3>
<p>{{context.name}}</p>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" ng-click="closeModal()">Cancel</button>
<button type="submit" class="btn btn-warning">Confirm</button>
<button type="submit" class="btn btn-warning" ng-disabled="submitClicked">Confirm</button>
</div>
</form>
</form>
4 changes: 2 additions & 2 deletions src/main/webapp/app/views/modals/createContainerModal.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ <h4 class="modal-title">Create Container</h4>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" ng-click="resetCreateContainer()">Cancel</button>
<button type="submit" class="btn btn-success">Create</button>
<button type="submit" class="btn btn-success" ng-disabled="submitClicked">Create</button>
</div>

</form>
</form>
Loading

0 comments on commit acf1c7a

Please sign in to comment.