Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor: deactivate placeables in read-only mode #461

Merged
merged 5 commits into from
Apr 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ v.next (unreleased)
* Browser: disabled projects are taken out from counters by default (#425).
* Editor: allowed to filter units from enabled/disabled projects (#425).
* Fixed bug where no overview stats were shown for language pages (#425).
* Editor: placeables are not actionable in read-only mode (#460).


v0.9.1 (2020-03-11)
Expand Down
8 changes: 7 additions & 1 deletion pootle/apps/pootle_store/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,12 @@ def get_sources(self):
sources[self.source_language.code] = self.object.source_f.strings
return sources

def get_tm_suggestions(self, ctx):
can_edit = ctx["cansuggest"] or ctx["cantranslate"]
if not can_edit:
return []
return self.object.get_tm_suggestions()[:MAX_TM_RESULTS]

def get_context_data(self, *args, **kwargs):
return {
"unit": self.object,
Expand Down Expand Up @@ -468,7 +474,7 @@ def get_context_data(self, *args, **kwargs):
def get_response_data(self, context):
return {
"editor": self.render_edit_template(context),
"tm_suggestions": self.object.get_tm_suggestions()[:MAX_TM_RESULTS],
"tm_suggestions": self.get_tm_suggestions(context),
"is_obsolete": self.object.isobsolete(),
"sources": self.get_sources(),
"target": self.object.target_f.strings,
Expand Down
6 changes: 5 additions & 1 deletion pootle/static/js/editor/components/UnitSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { highlightRW } from '../../utils';

const UnitSource = React.createClass({
propTypes: {
canEdit: React.PropTypes.bool.isRequired,
id: React.PropTypes.number.isRequired,
values: React.PropTypes.array.isRequired,
hasPlurals: React.PropTypes.bool.isRequired,
Expand All @@ -27,6 +28,7 @@ const UnitSource = React.createClass({
lang: this.props.sourceLocaleCode,
dir: this.props.sourceLocaleDir,
};
const placeablesExtraClassName = this.props.canEdit ? 'js-editor-copytext' : '';

return (
<div key={`source-value-${index}`}>
Expand All @@ -38,7 +40,9 @@ const UnitSource = React.createClass({
<div
className="translation-text js-translation-text"
data-string={sourceValue}
dangerouslySetInnerHTML={{ __html: highlightRW(sourceValue) }}
dangerouslySetInnerHTML={{
__html: highlightRW(sourceValue, placeablesExtraClassName),
}}
{...props}
></div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions pootle/static/js/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const ReactEditor = {
);
ReactRenderer.render(
<UnitSource
canEdit={this.props.canSuggest || this.props.canTranslate}
id={this.props.unitId}
values={this.props.sourceValues}
hasPlurals={this.props.hasPlurals}
Expand All @@ -71,6 +72,7 @@ const ReactEditor = {
const unit = this.props.alternativeSources[mountNode.dataset.id];
ReactRenderer.render(
<UnitSource
canEdit={this.props.canSuggest || this.props.canTranslate}
id={unit.id}
values={unit.target}
hasPlurals={unit.has_plurals}
Expand Down
15 changes: 5 additions & 10 deletions pootle/static/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export function highlightRO(text) {
);
}

export function highlightRW(text) {
export function highlightRW(text, className = '') {
return highlightSymbols(
nl2br(
highlightPunctuation(
Expand All @@ -126,14 +126,14 @@ export function highlightRW(text) {
// is managed as a component.
text.replace(/\r\n/g, '\n')
),
'js-editor-copytext'
className
),
'js-editor-copytext'
className
),
'js-editor-copytext'
className
)
),
'js-editor-copytext'
className
);
}

Expand All @@ -152,10 +152,6 @@ export function highlightRONodes(selector) {
return highlightNodes(selector, highlightRO);
}

export function highlightRWNodes(selector) {
return highlightNodes(selector, highlightRW);
}

export function blinkClass($elem, className, n, delay) {
$elem.toggleClass(className);
if (n > 1) {
Expand All @@ -168,7 +164,6 @@ export default {
highlightRO,
highlightRW,
highlightRONodes,
highlightRWNodes,
getHash,
getParsedHash,
strCmp,
Expand Down
4 changes: 4 additions & 0 deletions pootle/templates/editor/units/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
{% endif %}

<!-- Terminology suggestions -->
{% if cansuggest or cantranslate %}
{% with unit.terminology as terms %}
{% if terms %}
<div id="tm" class="sidebar" dir="{% locale_dir %}">
Expand All @@ -57,6 +58,7 @@
</div>
{% endif %}
{% endwith %}
{% endif %}

{% if unit.developer_comment %}
<!-- Developer comments -->
Expand Down Expand Up @@ -178,6 +180,8 @@

<script type="text/javascript">
PTL.reactEditor.init({
canSuggest: {{ cansuggest|yesno:'true,false' }},
canTranslate: {{ cantranslate|yesno:'true,false' }},
initialValues: {{ unit_values|to_jquery_safe_js }},
isDisabled: {{ form.target_f.field.widget.attrs.disabled|yesno:'true,false' }},
currentLocaleCode: '{{ language.code }}',
Expand Down