Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hide publish related toolbar buttons if permission is missing
- Loading branch information
Showing
6 changed files
with
138 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 36 additions & 24 deletions
60
...dle/AdminBundle/Resources/js/views/Form/toolbarActions/SaveWithPublishingToolbarAction.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,51 @@ | ||
// @flow | ||
import jexl from 'jexl'; | ||
import {translate} from '../../../utils/Translator'; | ||
import AbstractFormToolbarAction from './AbstractFormToolbarAction'; | ||
|
||
export default class SaveWithPublishingToolbarAction extends AbstractFormToolbarAction { | ||
getToolbarItemConfig() { | ||
const { | ||
publish_display_condition: publishDisplayCondition, | ||
} = this.options; | ||
|
||
const {dirty, data, saving} = this.resourceFormStore; | ||
|
||
const options = [ | ||
{ | ||
label: translate('sulu_admin.save_draft'), | ||
disabled: !dirty, | ||
onClick: () => { | ||
this.form.submit('draft'); | ||
}, | ||
}, | ||
]; | ||
|
||
if (!publishDisplayCondition || jexl.evalSync(publishDisplayCondition, this.resourceFormStore.data)) { | ||
options.push({ | ||
label: translate('sulu_admin.save_publish'), | ||
disabled: !dirty, | ||
onClick: () => { | ||
this.form.submit('publish'); | ||
}, | ||
}); | ||
|
||
options.push({ | ||
label: translate('sulu_admin.publish'), | ||
// TODO do not hardcode "publishedState" but use metadata instead | ||
disabled: dirty || data.publishedState === undefined || !!data.publishedState, | ||
onClick: () => { | ||
this.form.submit('publish'); | ||
}, | ||
}); | ||
} | ||
|
||
return { | ||
type: 'dropdown', | ||
label: translate('sulu_admin.save'), | ||
icon: 'su-save', | ||
loading: saving, | ||
options: [ | ||
{ | ||
label: translate('sulu_admin.save_draft'), | ||
disabled: !dirty, | ||
onClick: () => { | ||
this.form.submit('draft'); | ||
}, | ||
}, | ||
{ | ||
label: translate('sulu_admin.save_publish'), | ||
disabled: !dirty, | ||
onClick: () => { | ||
this.form.submit('publish'); | ||
}, | ||
}, | ||
{ | ||
label: translate('sulu_admin.publish'), | ||
// TODO do not hardcode "publishedState" but use metadata instead | ||
disabled: dirty || data.publishedState === undefined || !!data.publishedState, | ||
onClick: () => { | ||
this.form.submit('publish'); | ||
}, | ||
}, | ||
], | ||
options, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters