Skip to content

Commit

Permalink
disable published option in datatables
Browse files Browse the repository at this point in the history
  • Loading branch information
MattBudz committed Feb 5, 2025
1 parent 1666c73 commit 8d1dcf4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
30 changes: 25 additions & 5 deletions app/assets/javascripts/shared/datatable/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,41 @@ DradisDatatable.prototype.setupStateButtons = function () {
api = this;

states.forEach(function (state) {
const publishDisabled =
state[0] === 'Published' &&
$('[data-published-state]').data('published-state') === false;

let attrs;

if (publishDisabled) {
attrs = {
'data-bs-toggle': 'tooltip',
'data-bs-title': 'You are not a Reviewer for this project.',
};
}

stateButtons.push({
text: $(
`<i class="fa-solid ${state[1]} fa-fw me-2"></i><span>${state[0]}</span>`
),
action: DradisDatatable.prototype.updateRecordState.call(
api,
state[0].toLowerCase().replaceAll(' ', '_')
state[0].toLowerCase().replaceAll(' ', '_'),
$('[data-published-state]').data('published-state') != false
),
attr: attrs,
className: publishDisabled ? 'disabled' : null,
text: $(
`<i class="fa-solid ${state[1]} fa-fw me-2"></i><span>${state[0]}</span>`
),
});
});

return stateButtons;
};

DradisDatatable.prototype.updateRecordState = function (newState) {
DradisDatatable.prototype.updateRecordState = function (newState, canPublish) {
if (newState == 'Published' && canPublish) {
return;
}

var api = this;

return function () {
Expand Down
6 changes: 6 additions & 0 deletions app/assets/stylesheets/shared/datatables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,12 @@ div.dataTables_wrapper {
}
}

&.disabled {
color: $text-muted;
cursor: not-allowed;
pointer-events: auto;
}

&:focus,
&:hover {
outline: none;
Expand Down
1 change: 1 addition & 0 deletions app/views/issues/_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
'item-name': 'issue',
'local-storage-key': local_storage_key,
'new-tag-path': new_project_tag_path(current_project),
'published-state': can?(:publish, current_project),
'state-icons': local_assigns[:qa_state_icons] ? local_assigns[:qa_state_icons] : state_icons,
'tags-path': project_tags_path(current_project)
}%>
Expand Down

0 comments on commit 8d1dcf4

Please sign in to comment.