Skip to content

Commit

Permalink
Hide ViewObjectButton for invalid filetype or size
Browse files Browse the repository at this point in the history
Issue #1758
  • Loading branch information
robyngit committed Sep 18, 2024
1 parent 21a6e20 commit cc43393
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/js/views/DataObjectView.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ define([

const supportedFormats = Object.values(this.formatMap).flat();
const formatValid = supportedFormats.includes(format);
if (sizeValid && format) {
if (sizeValid && formatValid) {
return true;
}
const errors = {};
Expand Down
16 changes: 15 additions & 1 deletion src/js/views/ViewObjectButtonView.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,22 @@ define(["jquery", "backbone", "views/DataObjectView"], (
this.modalContainer = options.modalContainer || document.body;
},

/**
* @see DataObjectView#checkSizeAndFormat
* @returns {boolean} True if the object is a valid type and size
*/
isValidSizeAndFormat() {
this.formatMap = DataObjectView.prototype.formatMap;
this.sizeLimit = DataObjectView.prototype.sizeLimit;
return DataObjectView.prototype.isValidSizeAndFormat.call(this);
},

/** @inheritdoc */
render() {
if (this.isValidSizeAndFormat() !== true) {
this.el.style.display = "none";
return this;
}
this.el.innerHTML = BUTTON_TEXT;
const icon = document.createElement("i");
icon.classList.add(...CLASS_NAMES.icon);
Expand All @@ -101,7 +115,7 @@ define(["jquery", "backbone", "views/DataObjectView"], (
const modalFooter = modal.find(`.${CLASS_NAMES.footer.join(".")}`)[0];
const objectView = new DataObjectView({
model: this.model,
buttonContainer: modalFooter
buttonContainer: modalFooter,
});
modalBody.empty();
modalBody.append(objectView.render().el);
Expand Down

0 comments on commit cc43393

Please sign in to comment.