Skip to content

Commit

Permalink
Add support for Textarea, Remove copy button and translation for button
Browse files Browse the repository at this point in the history
  • Loading branch information
prugala committed Apr 9, 2021
1 parent 22a0fed commit 9fcc449
Show file tree
Hide file tree
Showing 9 changed files with 198 additions and 113 deletions.
31 changes: 0 additions & 31 deletions src/DivanteTranslationBundle/Controller/ObjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,35 +64,4 @@ public function translateFieldAction(Request $request, ProviderFactory $provider
'data' => $data,
]);
}

/**
* @Route("/get-field-data", methods={"GET"})
*/
public function getFieldDataAction(Request $request): JsonResponse
{
$object = DataObject::getById($request->get('sourceId'));

if (!$object instanceof DataObject) {
return $this->adminJson([
'success' => false,
'message' => 'Object doesn\'t exist',
]);
}

$fieldName = 'get' . ucfirst($request->get('fieldName'));

try {
$data = $object->$fieldName($this->sourceLanguage);
} catch (\Throwable $exception) {
return $this->adminJson([
'success' => false,
'message' => 'Field not found',
]);
}

return $this->adminJson([
'success' => true,
'data' => $data,
]);
}
}
1 change: 1 addition & 0 deletions src/DivanteTranslationBundle/DivanteTranslationBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function getJsPaths(): array
'/bundles/divantetranslation/js/pimcore/startup.js',
'/bundles/divantetranslation/js/pimcore/object/tags/input.js',
'/bundles/divantetranslation/js/pimcore/object/tags/wysiwyg.js',
'/bundles/divantetranslation/js/pimcore/object/tags/textarea.js',
'/bundles/divantetranslation/js/pimcore/object/elementservice.js',
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,6 @@

pimcore.registerNS("pimcore.object.elementservice.x");

pimcore.object.elementservice.addCopyButton = function (id, fieldName, component, type, lang) {
return new Ext.Button({
iconCls: "pimcore_icon_copy",
cls: 'pimcore_button_transparent',
tooltip: t("copy_from_source_lang"),
handler: function () {
Ext.Ajax.request({
url: "/admin/object/get-field-data",
method: "GET",
params: {
sourceId: id,
fieldName: fieldName,
lang: lang,
type: type
},
success: function (response) {
var res = Ext.decode(response.responseText);
if (res.success) {
if (type == 'wysiwyg') {
CKEDITOR.instances[component.editableDivId].setData(res.data);
} else {
component.setRawValue(res.data);
}
} else {
pimcore.helpers.showPrettyError('object', t("error"), t("saving_failed"), res.message);
}
}
});
}.bind(this),
style: "margin-left: 10px; filter:grayscale(100%);",
});
};


pimcore.object.elementservice.translateButton = function (id, fieldName, component, type, lang) {
return new Ext.Button({
iconCls: "pimcore_icon_translations",
Expand All @@ -63,13 +29,19 @@ pimcore.object.elementservice.translateButton = function (id, fieldName, compone
type: type
},
success: function (response) {

var res = Ext.decode(response.responseText);

if (res.success) {
if (type == 'wysiwyg') {
CKEDITOR.instances[component.editableDivId].setData(res.data);
} else {
component.setRawValue(res.data);
switch (type) {
case 'wysiwyg':
CKEDITOR.instances[component.editableDivId].setData(res.data);
break;
case 'input':
component.setRawValue(res.data);
break;
case 'textarea':
component.component.setValue(res.data);
break;
}
} else {
pimcore.helpers.showPrettyError('object', t("error"), t("saving_failed"), res.message);
Expand All @@ -79,4 +51,4 @@ pimcore.object.elementservice.translateButton = function (id, fieldName, compone
}.bind(this),
style: "margin-left: 10px; filter:grayscale(100%);",
});
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ pimcore.object.tags.input = Class.create(pimcore.object.tags.input, {

this.component = new Ext.form.TextField(input);

if (this.context.language) {
this.translateButton = new pimcore.object.elementservice.translateButton(
this.object.data.general.o_id,
this.fieldConfig.name,
this.component,
'input',
this.context.language
);
} else {
this.translateButton = {};
}

if (this.fieldConfig.showCharCount) {
var charCount = Ext.create("Ext.Panel", {
bodyStyle: '',
Expand All @@ -73,42 +85,17 @@ pimcore.object.tags.input = Class.create(pimcore.object.tags.input, {
},
items: [
this.component,
charCount
charCount,
this.translateButton,
]
});

} else {
if (this.context.language) {
this.copyButton = new pimcore.object.elementservice.addCopyButton(
this.object.data.general.o_id,
this.fieldConfig.name,
this.component,
'input',
this.context.language
);
}
else {
this.copyButton = {};

}
if (this.context.language) {
this.translateButton = new pimcore.object.elementservice.translateButton(
this.object.data.general.o_id,
this.fieldConfig.name,
this.component,
'input',
this.context.language
);
} else {
this.translateButton = {};
}

return Ext.create('Ext.form.FieldContainer', {
labelWidth: input.width,
layout: 'hbox',
items: [
this.component,
this.copyButton,
this.translateButton,
],
componentCls: "object_field",
Expand All @@ -119,4 +106,4 @@ pimcore.object.tags.input = Class.create(pimcore.object.tags.input, {
});
}
},
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Enterprise License (PEL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PEL
*/

pimcore.registerNS("pimcore.object.tags.textarea");
pimcore.object.tags.textarea = Class.create(pimcore.object.tags.abstract, {

type: "textarea",

initialize: function (data, fieldConfig) {
this.data = data;
this.fieldConfig = fieldConfig;

},

getGridColumnEditor: function(field) {
var editorConfig = {};

if (field.config) {
if (field.config.width) {
if (intval(field.config.width) > 10) {
editorConfig.width = field.config.width;
}
}
}

if(field.layout.noteditable) {
return null;
}
// TEXTAREA
if (field.type == "textarea") {
return new Ext.form.TextArea(editorConfig);
}
},

getGridColumnFilter: function(field) {
return {type: 'string', dataIndex: field.key};
},

getLayoutEdit: function () {


if (intval(this.fieldConfig.width) < 1) {
this.fieldConfig.width = 250;
}
if (intval(this.fieldConfig.height) < 1) {
this.fieldConfig.height = 250;
}

var labelWidth = this.fieldConfig.labelWidth ? this.fieldConfig.labelWidth : 100;

var conf = {
name: this.fieldConfig.name,
width: this.fieldConfig.width,
height: this.fieldConfig.height,
fieldLabel: this.fieldConfig.title,
labelWidth: labelWidth
};

if (!this.fieldConfig.showCharCount) {
conf.componentCls = "object_field object_field_type_" + this.type;
}

if (this.context.language) {
this.translateButton = new pimcore.object.elementservice.translateButton(
this.object.data.general.o_id,
this.fieldConfig.name,
this,
'textarea',
this.context.language
);
} else {
this.translateButton = {};
}

conf.width += conf.labelWidth;

if (this.data) {
conf.value = this.data;
}
if(this.fieldConfig.maxLength) {
conf.maxLength = this.fieldConfig.maxLength;
conf.enforceMaxLength = true;
}

this.component = new Ext.form.TextArea(conf);

if(this.fieldConfig.showCharCount) {
var charCount = Ext.create("Ext.Panel", {
bodyStyle: '',
margin: '0 0 0 0',
bodyCls: 'char_count',
width: conf.width,
height: 17
});

this.component.setStyle("margin-bottom", "0");
this.component.addListener("change", function(charCount) {
this.updateCharCount(this.component, charCount);
}.bind(this, charCount));

//init word count
this.updateCharCount(this.component, charCount);

return Ext.create("Ext.Panel", {
cls: "object_field object_field_type_" + this.type,
style: "margin-bottom: 10px",
layout: {
type: 'vbox',
align: 'left'
},
items: [
this.component,
charCount,
this.translateButton,
]
});

} else {
return Ext.create("Ext.Panel", {
cls: "object_field object_field_type_" + this.type,
style: "margin-bottom: 10px",
layout: {
type: 'vbox',
align: 'left'
},
items: [
this.component,
this.translateButton,
]
});
}
},

updateCharCount: function(textField, charCount) {
if( this.fieldConfig.maxLength) {
charCount.setHtml(textField.getValue().length + "/" + this.fieldConfig.maxLength);
} else {
charCount.setHtml(textField.getValue().length);
}
},


getLayoutShow: function () {
var layout = this.getLayoutEdit();
this.component.setReadOnly(true);
return layout;
},

getValue: function () {
return this.component.getValue();
},

getName: function () {
return this.fieldConfig.name;
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,6 @@ pimcore.object.tags.wysiwyg = Class.create(pimcore.object.tags.wysiwyg, {
this.ckeditor = null;
}
}.bind(this));
if (this.context.language) {
this.copyButton = new pimcore.object.elementservice.addCopyButton(
this.object.data.general.o_id,
this.fieldConfig.name,
this,
'wysiwyg',
this.context.language
);
}
else {
this.copyButton = {};
}
if (this.fieldConfig.width) {
width = this.fieldConfig.width;
}
Expand All @@ -60,7 +48,6 @@ pimcore.object.tags.wysiwyg = Class.create(pimcore.object.tags.wysiwyg, {
layout: 'hbox',
items: [
this.component,
this.copyButton,
this.translateButton,
],
componentCls: "object_field custom_wysiwyg",
Expand All @@ -71,4 +58,4 @@ pimcore.object.tags.wysiwyg = Class.create(pimcore.object.tags.wysiwyg, {
},
});
},
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
translate_field: Übersetzen
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
translate_field: Translate
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
translate_field: Tłumacz

0 comments on commit 9fcc449

Please sign in to comment.