Browse Source

Pass through the language to the editor SDK.

release/4.x
Sebastian 5 years ago
parent
commit
68e8903f95
  1. 4
      backend/i18n/frontend_en.json
  2. 4
      backend/i18n/source/frontend_en.json
  3. 16
      backend/src/Squidex/wwwroot/scripts/editor-log.html
  4. 68
      backend/src/Squidex/wwwroot/scripts/editor-sdk.js
  5. 3
      frontend/app/features/content/shared/forms/field-editor.component.html
  6. 20
      frontend/app/framework/angular/forms/editors/iframe-editor.component.ts

4
backend/i18n/frontend_en.json

@ -384,8 +384,8 @@
"contents.localizedFieldDescription": "The '{fieldName}' field of the content item (localized).", "contents.localizedFieldDescription": "The '{fieldName}' field of the content item (localized).",
"contents.newStatusFieldDescription": "The new status of the content item.", "contents.newStatusFieldDescription": "The new status of the content item.",
"contents.noReference": "- No Reference -", "contents.noReference": "- No Reference -",
"contents.pendingChangesTextToChange": "You have unsaved changes.\n\nWhen you change the status you will loose them.\n\n**Do you want to continue anyway?**", "contents.pendingChangesTextToChange": "You have unsaved changes.\n\nWhen you change the status you will lose them.\n\n**Do you want to continue anyway?**",
"contents.pendingChangesTextToClose": "You have unsaved changes.\n\nWhen you close the current content view you will loose them.\n\n**Do you want to continue anyway?**", "contents.pendingChangesTextToClose": "You have unsaved changes.\n\nWhen you close the current content view you will lose them.\n\n**Do you want to continue anyway?**",
"contents.pendingChangesTitle": "Unsaved changes", "contents.pendingChangesTitle": "Unsaved changes",
"contents.referencesCreateNew": "Add New", "contents.referencesCreateNew": "Add New",
"contents.referencesCreatePublish": "Create and Publish", "contents.referencesCreatePublish": "Create and Publish",

4
backend/i18n/source/frontend_en.json

@ -384,8 +384,8 @@
"contents.localizedFieldDescription": "The '{fieldName}' field of the content item (localized).", "contents.localizedFieldDescription": "The '{fieldName}' field of the content item (localized).",
"contents.newStatusFieldDescription": "The new status of the content item.", "contents.newStatusFieldDescription": "The new status of the content item.",
"contents.noReference": "- No Reference -", "contents.noReference": "- No Reference -",
"contents.pendingChangesTextToChange": "You have unsaved changes.\n\nWhen you change the status you will loose them.\n\n**Do you want to continue anyway?**", "contents.pendingChangesTextToChange": "You have unsaved changes.\n\nWhen you change the status you will lose them.\n\n**Do you want to continue anyway?**",
"contents.pendingChangesTextToClose": "You have unsaved changes.\n\nWhen you close the current content view you will loose them.\n\n**Do you want to continue anyway?**", "contents.pendingChangesTextToClose": "You have unsaved changes.\n\nWhen you close the current content view you will lose them.\n\n**Do you want to continue anyway?**",
"contents.pendingChangesTitle": "Unsaved changes", "contents.pendingChangesTitle": "Unsaved changes",
"contents.referencesCreateNew": "Add New", "contents.referencesCreateNew": "Add New",
"contents.referencesCreatePublish": "Create and Publish", "contents.referencesCreatePublish": "Create and Publish",

16
backend/src/Squidex/wwwroot/scripts/editor-log.html

@ -22,7 +22,7 @@
var field = new SquidexFormField(); var field = new SquidexFormField();
function logState(message) { function logState(message) {
console.log(`${message}. Value: <${JSON.stringify(field.getValue(), 2)}>, Form Value: <${JSON.stringify(field.getFormValue())}>`); console.log(`${message}.\n\Language: ${field.getLanguage()}\n\nValue\n<${JSON.stringify(field.getValue(), 2)}>\n\nForm Value\n<${JSON.stringify(field.getFormValue())}>\n\nDisabled: ${field.isDisabled()}`);
} }
logState('Setup'); logState('Setup');
@ -41,12 +41,18 @@
logState('Init'); logState('Init');
}); });
// Handle the value change event and set the text to the editor. field.onValueChanged(function () {
field.onValueChanged(function (value) { logState('Value changed');
logState(`Value changed: <${JSON.stringify(value, 2)}>`); });
field.onFormValueChanged(function () {
logState('Form value changed');
});
field.onLanguageChanged(function () {
logState('Field language changed');
}); });
// Disable the editor when it should be disabled.
field.onDisabled(function (disabled) { field.onDisabled(function (disabled) {
logState(`Disabled: <${JSON.stringify(disabled, 2)}>`); logState(`Disabled: <${JSON.stringify(disabled, 2)}>`);
}); });

68
backend/src/Squidex/wwwroot/scripts/editor-sdk.js

@ -86,7 +86,7 @@ function SquidexPlugin() {
}, },
/** /**
* Register the init handler. * Register an function that is called when the sidebar is initialized.
*/ */
onInit: function (callback) { onInit: function (callback) {
initHandler = callback; initHandler = callback;
@ -95,7 +95,9 @@ function SquidexPlugin() {
}, },
/** /**
* Register the content changed handler. * Register an function that is called whenever the value of the content has changed.
*
* The callback has one argument with the value of the content (any).
*/ */
onContentChanged: function (callback) { onContentChanged: function (callback) {
contentHandler = callback; contentHandler = callback;
@ -128,6 +130,8 @@ function SquidexFormField() {
var fullscreenHandler = false; var fullscreenHandler = false;
var valueHandler; var valueHandler;
var value; var value;
var languageHandler;
var language;
var formValueHandler; var formValueHandler;
var formValue; var formValue;
var context; var context;
@ -151,6 +155,12 @@ function SquidexFormField() {
} }
} }
function raiseLanguageChanged() {
if (languageHandler && language) {
languageHandler(language);
}
}
function raiseFullscreen() { function raiseFullscreen() {
if (fullscreenHandler) { if (fullscreenHandler) {
fullscreenHandler(fullscreen); fullscreenHandler(fullscreen);
@ -186,6 +196,10 @@ function SquidexFormField() {
fullscreen = event.data.fullscreen; fullscreen = event.data.fullscreen;
raiseFullscreen(); raiseFullscreen();
} else if (type === 'languageChanged') {
language = event.data.language;
raiseLanguageChanged();
} else if (type === 'init') { } else if (type === 'init') {
context = event.data.context; context = event.data.context;
@ -220,6 +234,27 @@ function SquidexFormField() {
return formValue; return formValue;
}, },
/*
* Get the current field language.
*/
getLanguage: function () {
return language;
},
/*
* Get the disabled state.
*/
isDisabled: function () {
return disabled;
},
/*
* Get the fullscreen state.
*/
isFullscreen: function () {
return fullscreen;
},
/** /**
* Notifies the control container that the editor has been touched. * Notifies the control container that the editor has been touched.
*/ */
@ -265,7 +300,7 @@ function SquidexFormField() {
}, },
/** /**
* Register the init handler. * Register an function that is called when the field is initialized.
*/ */
onInit: function (callback) { onInit: function (callback) {
initHandler = callback; initHandler = callback;
@ -274,7 +309,9 @@ function SquidexFormField() {
}, },
/** /**
* Register the disabled handler. * Register an function that is called whenever the field is disabled or enabled.
*
* The callback has one argument with disabled state (disabled = true, enabled = false).
*/ */
onDisabled: function (callback) { onDisabled: function (callback) {
disabledHandler = callback; disabledHandler = callback;
@ -283,7 +320,20 @@ function SquidexFormField() {
}, },
/** /**
* Register the value changed handler. * Register an function that is called whenever the field language is changed.
*
* The callback has one argument with the language of the field (string).
*/
onLanguageChanged: function (callback) {
languageHandler = callback;
raiseLanguageChanged();
},
/**
* Register an function that is called whenever the value of the field has changed.
*
* The callback has one argument with the value of the field (any).
*/ */
onValueChanged: function (callback) { onValueChanged: function (callback) {
valueHandler = callback; valueHandler = callback;
@ -292,7 +342,9 @@ function SquidexFormField() {
}, },
/** /**
* Register the form value changed handler. * Register an function that is called whenever the value of the content has changed.
*
* The callback has one argument with the value of the content (any).
*/ */
onFormValueChanged: function (callback) { onFormValueChanged: function (callback) {
formValueHandler = callback; formValueHandler = callback;
@ -301,7 +353,9 @@ function SquidexFormField() {
}, },
/** /**
* Register the fullscreen changed handler. * Register an function that is called whenever the fullscreen mode has changed.
*
* The callback has one argument with fullscreen state (fullscreen on = true, fullscreen off = false).
*/ */
onFullscreen: function (callback) { onFullscreen: function (callback) {
fullscreenHandler = callback; fullscreenHandler = callback;

3
frontend/app/features/content/shared/forms/field-editor.component.html

@ -12,7 +12,8 @@
<sqx-iframe-editor [url]="field.properties.editorUrl" <sqx-iframe-editor [url]="field.properties.editorUrl"
[context]="formContext" [context]="formContext"
[formControl]="editorControl" [formControl]="editorControl"
[formValue]="form?.value | async"> [formValue]="form?.value | async"
[language]="language?.iso2Code">
</sqx-iframe-editor> </sqx-iframe-editor>
</ng-container> </ng-container>

20
frontend/app/framework/angular/forms/editors/iframe-editor.component.ts

@ -48,6 +48,9 @@ export class IFrameEditorComponent extends StatefulControlComponent<State, any>
@Input() @Input()
public formValue: any; public formValue: any;
@Input()
public language: string;
@Input() @Input()
public url: string; public url: string;
@ -72,9 +75,13 @@ export class IFrameEditorComponent extends StatefulControlComponent<State, any>
this.setupUrl(); this.setupUrl();
} }
if (changes['formValue'] && this.formValue) { if (changes['formValue']) {
this.sendFormValue(); this.sendFormValue();
} }
if (changes['language']) {
this.sendLanguage();
}
} }
} }
@ -96,6 +103,7 @@ export class IFrameEditorComponent extends StatefulControlComponent<State, any>
this.sendInit(); this.sendInit();
this.sendFullscreen(); this.sendFullscreen();
this.sendFormValue(); this.sendFormValue();
this.sendLanguage();
this.sendDisabled(); this.sendDisabled();
this.sendValue(); this.sendValue();
} else if (type === 'resize') { } else if (type === 'resize') {
@ -158,7 +166,15 @@ export class IFrameEditorComponent extends StatefulControlComponent<State, any>
} }
private sendFormValue() { private sendFormValue() {
this.sendMessage('formValueChanged', { formValue: this.formValue }); if (this.formValue) {
this.sendMessage('formValueChanged', { formValue: this.formValue });
}
}
private sendLanguage() {
if (this.language) {
this.sendMessage('languageChanged', { language: this.language });
}
} }
private toggleFullscreen(isFullscreen: boolean) { private toggleFullscreen(isFullscreen: boolean) {

Loading…
Cancel
Save