Skip to content

Commit 6659a0b

Browse files
committed
Merge branch 'feature/update-to-4-1' into 'release/2.0'
Release 2.0.0 - upgrade to 4.1 See merge request b2bcode/oro/extensions/cms-form-builder!2
2 parents c20ad3a + d15c97f commit 6659a0b

File tree

11 files changed

+193
-1
lines changed

11 files changed

+193
-1
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
]
1818
},
1919
"require": {
20-
"oro/commerce": "3.1.*"
20+
"oro/commerce": "4.1.x-dev"
2121
},
2222
"minimum-stability": "dev"
2323
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
app-modules:
2+
- b2bcodecmsform/js/app/modules/grapesjs-module
3+
dynamic-imports:
4+
b2bcodecmsform:
5+
- b2bcodecmsform/js/app/components/field-options-component
6+
- b2bcodecmsform/js/app/components/sortable-fields-component

src/B2bCode/Bundle/CmsFormBundle/Resources/config/services.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ services:
2424
- !tagged b2b_code_cms_form.field_type_provider
2525

2626
B2bCode\Bundle\CmsFormBundle\Builder\FormBuilderInterface:
27+
public: true
2728
class: B2bCode\Bundle\CmsFormBundle\Builder\FormBuilder
2829
arguments:
2930
- '@form.factory'
@@ -33,6 +34,7 @@ services:
3334
- '@B2bCode\Bundle\CmsFormBundle\Validator\ConstraintProviderInterface'
3435

3536
B2bCode\Bundle\CmsFormBundle\Provider\GeneralFieldProvider:
37+
public: true
3638
class: B2bCode\Bundle\CmsFormBundle\Provider\GeneralFieldProvider
3739

3840
B2bCode\Bundle\CmsFormBundle\Form\Extension\FieldOptionsExtension:
@@ -70,6 +72,7 @@ services:
7072
- { name: kernel.event_listener, event: oro_datagrid.orm_datasource.result.after.b2bcode-cms-form-responses-grid, method: onResultAfter }
7173

7274
B2bCode\Bundle\CmsFormBundle\Notification\NotificationInterface:
75+
public: true
7376
class: B2bCode\Bundle\CmsFormBundle\Notification\SendEmailNotification
7477
arguments:
7578
- '@oro_message_queue.message_producer'
@@ -106,6 +109,7 @@ services:
106109
b2b_code_cms_form.field_manager.api:
107110
class: Oro\Bundle\SoapBundle\Entity\Manager\ApiEntityManager
108111
parent: oro_soap.manager.entity_manager.abstract
112+
public: true
109113
arguments:
110114
- B2bCode\Bundle\CmsFormBundle\Entity\CmsFormField
111115
- '@doctrine.orm.entity_manager'
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
import _ from 'underscore';
2+
import __ from 'orotranslation/js/translator';
3+
import BaseTypeBuilder from 'orocms/js/app/grapesjs/type-builders/base-type-builder';
4+
import DialogWidget from 'oro/dialog-widget';
5+
import template from 'tpl-loader!b2bcodecmsform/templates/grapesjs-cms-form.html';
6+
import routing from 'routing';
7+
8+
/**
9+
* CMS form type builder
10+
*/
11+
const CmsFormTypeBuilder = BaseTypeBuilder.extend({
12+
button: {
13+
label: __('b2bcode.cmsform.wysiwyg.component.cms_form.label'),
14+
category: 'Basic',
15+
attributes: {
16+
'class': 'fa fa-file-text'
17+
}
18+
},
19+
20+
editorEvents: {
21+
'canvas:drop': 'onDrop'
22+
},
23+
24+
commands: {
25+
'cms-form-settings': (editor, sender, componentModel) => {
26+
const datagridName = 'b2bcode-cms-forms-grid';
27+
const container = editor.Commands.isActive('fullscreen') ? editor.getEl() : 'body';
28+
const routeParams = {
29+
gridName: datagridName
30+
};
31+
32+
const dialog = new DialogWidget({
33+
title: __('b2bcode.cmsform.wysiwyg.component.cms_form.dialog.title'),
34+
url: routing.generate(
35+
'oro_datagrid_widget',
36+
routeParams
37+
),
38+
loadingElement: container,
39+
dialogOptions: {
40+
modal: true,
41+
resizable: true,
42+
autoResize: true,
43+
appendTo: container,
44+
close: function() {
45+
if (componentModel.cid && !componentModel.get('cmsForm')) {
46+
componentModel.remove();
47+
}
48+
}
49+
}
50+
});
51+
52+
dialog.on('contentLoad', function(data, widget) {
53+
const gridWidget = widget.componentManager.get(datagridName);
54+
gridWidget.grid.columns.remove(_.last(gridWidget.grid.columns.models));
55+
});
56+
57+
dialog.on('grid-row-select', function(data) {
58+
let selected = editor.getSelected();
59+
60+
if (componentModel.cid) {
61+
selected = componentModel;
62+
}
63+
64+
selected.set('cmsForm', data.model);
65+
dialog.remove();
66+
});
67+
68+
dialog.render();
69+
}
70+
},
71+
72+
modelMixin: {
73+
defaults: {
74+
tagName: 'div',
75+
classes: ['cms-form', 'content-placeholder'],
76+
cmsForm: null,
77+
droppable: false
78+
},
79+
80+
initialize(...args) {
81+
this.constructor.__super__.initialize.call(this, ...args);
82+
83+
const toolbar = this.get('toolbar');
84+
const commandExists = _.some(toolbar, {
85+
command: 'cms-form-settings'
86+
});
87+
88+
if (!commandExists) {
89+
toolbar.unshift({
90+
attributes: {
91+
'class': 'fa fa-gear',
92+
'label': __('b2bcode.cmsform.wysiwyg.component.cms_form.block_setting')
93+
},
94+
command: 'cms-form-settings'
95+
});
96+
97+
this.set('toolbar', toolbar);
98+
}
99+
100+
this.listenTo(this, 'change:cmsForm', this.onCmsFormChange, this);
101+
},
102+
103+
onCmsFormChange(model, cmsForm) {
104+
this.set('attributes', {
105+
'data-title': cmsForm.get('name')
106+
});
107+
108+
this.set('content', '{{ b2b_code_form("' + cmsForm.get('alias') + '") }}');
109+
this.view.render();
110+
}
111+
},
112+
113+
viewMixin: {
114+
onRender() {
115+
let title;
116+
const cmsForm = this.model.get('cmsForm');
117+
118+
if (cmsForm) {
119+
title = cmsForm.cid ? cmsForm.get('name') : cmsForm.name;
120+
} else {
121+
title = this.$el.attr('data-title');
122+
}
123+
124+
this.$el.html(template({title}));
125+
}
126+
},
127+
128+
/**
129+
* @inheritDoc
130+
*/
131+
constructor: function CmsFormTypeBuilder(options) {
132+
CmsFormTypeBuilder.__super__.constructor.call(this, options);
133+
},
134+
135+
onDrop(DataTransfer, model) {
136+
if (model instanceof this.Model) {
137+
this.editor.runCommand('cms-form-settings', model);
138+
}
139+
},
140+
141+
isComponent(el) {
142+
let result = null;
143+
144+
if (el.tagName === 'DIV' && el.classList.contains('cms-form')) {
145+
result = {
146+
type: this.componentType
147+
};
148+
}
149+
150+
return result;
151+
}
152+
});
153+
154+
export default CmsFormTypeBuilder;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import ComponentManager from 'orocms/js/app/grapesjs/plugins/components/component-manager';
2+
import CmsFormTypeBuilder from 'b2bcodecmsform/js/app/grapesjs/type-builders/cms-form-type-builder';
3+
4+
ComponentManager.registerComponentTypes({
5+
'cms-form': {
6+
Constructor: CmsFormTypeBuilder
7+
},
8+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<% if (title) { %>
2+
<div class="cms-form-placeholder">
3+
<h3 class="cms-form-placeholder-title"><%- title %></h3>
4+
<p><%- _.__('b2bcode.cmsform.wysiwyg.component.cms_form.label') %></p>
5+
</div>
6+
<% } %>

src/B2bCode/Bundle/CmsFormBundle/Resources/translations/jsmessages.en.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,10 @@ b2bcode:
77
success: Your form has been successfully submitted
88
reorder:
99
error: Error
10+
wysiwyg:
11+
component:
12+
cms_form:
13+
label: CMS Form
14+
dialog:
15+
title: Select CMS Form
16+
block_setting: Settings

src/B2bCode/Bundle/CmsFormBundle/Resources/translations/messages.en.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ b2bcode:
157157
saved_message: Form saved
158158

159159
cmsformresponse:
160+
resolved:
161+
label: Resolved
160162
field_responses:
161163
label: Field response
162164
form:

src/B2bCode/Bundle/CmsFormBundle/Resources/views/Form/responses.html.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{% extends 'OroUIBundle:actions:view.html.twig' %}
22
{% import 'OroDataGridBundle::macros.html.twig' as dataGrid %}
3+
{% import 'OroUIBundle::macros.html.twig' as UI %}
34

45
{% oro_title_set({params : {"%name%": entity.name }}) %}
56

src/B2bCode/Bundle/CmsFormBundle/Resources/views/Form/view.html.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{% extends 'OroUIBundle:actions:view.html.twig' %}
22
{% import 'OroDataGridBundle::macros.html.twig' as dataGrid %}
3+
{% import 'OroUIBundle::macros.html.twig' as UI %}
34

45
{% oro_title_set({params : {"%name%": entity.name }}) %}
56

0 commit comments

Comments
 (0)