2016-09-07 15:39:43 +12:00
|
|
|
import jQuery from 'jQuery';
|
|
|
|
import React from 'react';
|
|
|
|
import ReactDOM from 'react-dom';
|
|
|
|
import { Provider } from 'react-redux';
|
2016-10-20 08:37:41 +13:00
|
|
|
import FormBuilderLoader from 'containers/FormBuilderLoader/FormBuilderLoader';
|
2017-08-15 12:10:31 +12:00
|
|
|
import { provideInjector } from 'lib/Injector';
|
2016-09-07 15:39:43 +12:00
|
|
|
|
2017-04-20 13:14:45 +12:00
|
|
|
const sectionConfigKey = 'TestReactFormBuilder';
|
2017-08-15 12:10:31 +12:00
|
|
|
const InjectedFormBuilderLoader = provideInjector(FormBuilderLoader);
|
2016-09-07 15:39:43 +12:00
|
|
|
jQuery.entwine('ss', ($) => {
|
2016-09-29 13:39:07 +13:00
|
|
|
/**
|
|
|
|
* Kick off Test React FormBuilder admin section.
|
|
|
|
* Uses React to rebuild the list of fields from FrameworkTest's TestPages.
|
|
|
|
*/
|
|
|
|
$('.TestReactFormBuilder').entwine({
|
|
|
|
onmatch() {
|
|
|
|
setTimeout(() => this._renderForm(), 100);
|
|
|
|
// need to force scrollable .css() doesn't work with important which is needed for this case
|
|
|
|
this[0].style.setProperty('overflow-y', 'scroll', 'important');
|
|
|
|
},
|
2016-09-07 15:39:43 +12:00
|
|
|
|
2016-09-29 13:39:07 +13:00
|
|
|
onunmatch() {
|
|
|
|
this._clearForm();
|
|
|
|
this.css('overflow-y', false);
|
|
|
|
},
|
2016-09-07 15:39:43 +12:00
|
|
|
|
2016-09-29 13:39:07 +13:00
|
|
|
open() {
|
|
|
|
this._renderForm();
|
|
|
|
},
|
2016-09-07 15:39:43 +12:00
|
|
|
|
2016-09-29 13:39:07 +13:00
|
|
|
close() {
|
|
|
|
this._clearForm();
|
|
|
|
},
|
2016-09-07 15:39:43 +12:00
|
|
|
|
2016-09-29 13:39:07 +13:00
|
|
|
_renderForm() {
|
|
|
|
const store = window.ss.store;
|
|
|
|
const sectionConfig = store.getState()
|
2017-04-20 13:14:45 +12:00
|
|
|
.config.sections.find((section) => section.name === sectionConfigKey);
|
2016-09-29 13:39:07 +13:00
|
|
|
const schemaUrl = sectionConfig.form.TestEditForm.schemaUrl;
|
2016-09-07 15:39:43 +12:00
|
|
|
|
2016-09-29 13:39:07 +13:00
|
|
|
ReactDOM.render(
|
|
|
|
<Provider store={store}>
|
2017-08-15 12:10:31 +12:00
|
|
|
<InjectedFormBuilderLoader
|
|
|
|
identifier="TestReactForm"
|
2016-09-29 13:39:07 +13:00
|
|
|
schemaUrl={schemaUrl}
|
|
|
|
handleSubmit={(...args) => this._handleSubmit(...args)}
|
|
|
|
/>
|
|
|
|
</Provider>,
|
|
|
|
this[0]
|
|
|
|
);
|
|
|
|
},
|
2016-09-07 15:39:43 +12:00
|
|
|
|
2016-09-29 13:39:07 +13:00
|
|
|
_clearForm() {
|
|
|
|
ReactDOM.unmountComponentAtNode(this[0]);
|
|
|
|
// this.empty();
|
|
|
|
},
|
2016-09-07 15:39:43 +12:00
|
|
|
|
2016-09-29 13:39:07 +13:00
|
|
|
_handleSubmit(event, fieldValues, submitFn) {
|
|
|
|
event.preventDefault();
|
2016-09-07 15:39:43 +12:00
|
|
|
|
2016-09-29 13:39:07 +13:00
|
|
|
return submitFn();
|
|
|
|
},
|
2016-09-07 15:39:43 +12:00
|
|
|
|
2016-09-29 13:39:07 +13:00
|
|
|
});
|
2016-09-07 15:39:43 +12:00
|
|
|
|
2016-09-29 13:39:07 +13:00
|
|
|
$('.TestReactFormBuilder .nav-link').entwine({
|
|
|
|
onclick: function (e) {
|
|
|
|
// this is required because the React version of e.preventDefault() doesn't work
|
|
|
|
// this is to stop React Tabs from navigating the page
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
});
|
2016-09-07 15:39:43 +12:00
|
|
|
});
|