From e403ccd80ac1aafda148b3dbb8bf1b771eadd844 Mon Sep 17 00:00:00 2001 From: JamieRL Date: Mon, 11 Jun 2018 13:55:30 -0700 Subject: [PATCH] add poll embed component, you can now embed a poll by clicking the 'poll' button in the embed toolbar --- dispatch/modules/content/embeds.py | 10 ------ dispatch/modules/content/render.py | 4 +++ .../ArticleEditor/ArticleContentEditor.js | 6 ++-- .../src/js/components/fields/PollField.js | 2 +- .../inputs/selects/PollSelectInput.js | 2 +- .../dispatch-editor/embeds/PollEmbed.js | 32 +++++++++++++++++++ .../js/vendor/dispatch-editor/embeds/index.js | 4 ++- .../src/js/vendor/dispatch-editor/index.js | 6 ++-- 8 files changed, 49 insertions(+), 17 deletions(-) create mode 100644 dispatch/static/manager/src/js/vendor/dispatch-editor/embeds/PollEmbed.js diff --git a/dispatch/modules/content/embeds.py b/dispatch/modules/content/embeds.py index 72ff401fc..6ab9c90a4 100644 --- a/dispatch/modules/content/embeds.py +++ b/dispatch/modules/content/embeds.py @@ -97,16 +97,6 @@ def render(self, data): return '' return widget.render(data=data['data']) - - # except ZoneNotFound: - # return '' - - # try: - # return zone.widget.render(add_context=kwargs) - # except (WidgetNotFound, AttributeError): - # pass - - # return '' class ImageEmbed(AbstractTemplateEmbed): TEMPLATE = 'embeds/image.html' diff --git a/dispatch/modules/content/render.py b/dispatch/modules/content/render.py index 4201ddeca..5e18ba7f7 100644 --- a/dispatch/modules/content/render.py +++ b/dispatch/modules/content/render.py @@ -12,6 +12,10 @@ def render_node(html, node): return html + '

%s

' % node['data'] else: try: + if node['type'] == 'poll': + node['type'] = 'widget' + node['data']['data'] = node['data'] + return html + embeds.render(node['type'], node['data']) except EmbedException: return html diff --git a/dispatch/static/manager/src/js/components/ArticleEditor/ArticleContentEditor.js b/dispatch/static/manager/src/js/components/ArticleEditor/ArticleContentEditor.js index af8385739..3ac9d00bd 100644 --- a/dispatch/static/manager/src/js/components/ArticleEditor/ArticleContentEditor.js +++ b/dispatch/static/manager/src/js/components/ArticleEditor/ArticleContentEditor.js @@ -9,7 +9,8 @@ import { PullQuoteEmbed, GalleryEmbed, CodeEmbed, - WidgetEmbed + WidgetEmbed, + PollEmbed } from '../../vendor/dispatch-editor' const embeds = [ @@ -18,7 +19,8 @@ const embeds = [ CodeEmbed, PullQuoteEmbed, GalleryEmbed, - WidgetEmbed + WidgetEmbed, + PollEmbed ] export default class ArticleContentEditor extends React.Component { diff --git a/dispatch/static/manager/src/js/components/fields/PollField.js b/dispatch/static/manager/src/js/components/fields/PollField.js index f7633740f..5b6e8914c 100644 --- a/dispatch/static/manager/src/js/components/fields/PollField.js +++ b/dispatch/static/manager/src/js/components/fields/PollField.js @@ -9,4 +9,4 @@ export default function PollField(props) { many={props.field.many} onChange={selected => props.onChange(selected)} /> ) -} \ No newline at end of file +} diff --git a/dispatch/static/manager/src/js/components/inputs/selects/PollSelectInput.js b/dispatch/static/manager/src/js/components/inputs/selects/PollSelectInput.js index cc2a2ffc7..30d8055f9 100644 --- a/dispatch/static/manager/src/js/components/inputs/selects/PollSelectInput.js +++ b/dispatch/static/manager/src/js/components/inputs/selects/PollSelectInput.js @@ -22,7 +22,7 @@ class PollSelectInputComponent extends React.Component { return ( +
+ + { + props.updateField('poll',selected) + props.stopEditing() + } + } /> + +
+ + ) +} + +export default { + type: 'poll', + component: PollEmbedComponent, + defaultData: { + poll:'', + widget_id: 'poll' + } +} diff --git a/dispatch/static/manager/src/js/vendor/dispatch-editor/embeds/index.js b/dispatch/static/manager/src/js/vendor/dispatch-editor/embeds/index.js index d4db1b36a..b7585e9cd 100644 --- a/dispatch/static/manager/src/js/vendor/dispatch-editor/embeds/index.js +++ b/dispatch/static/manager/src/js/vendor/dispatch-editor/embeds/index.js @@ -4,6 +4,7 @@ import CodeEmbed from './CodeEmbed' import PullQuoteEmbed from './PullQuoteEmbed' import GalleryEmbed from './GalleryEmbed' import WidgetEmbed from './WidgetEmbed' +import PollEmbed from './PollEmbed' export { ImageEmbed, @@ -11,5 +12,6 @@ export { PullQuoteEmbed, CodeEmbed, GalleryEmbed, - WidgetEmbed + WidgetEmbed, + PollEmbed } diff --git a/dispatch/static/manager/src/js/vendor/dispatch-editor/index.js b/dispatch/static/manager/src/js/vendor/dispatch-editor/index.js index 1b19d53a4..24076aeb4 100644 --- a/dispatch/static/manager/src/js/vendor/dispatch-editor/index.js +++ b/dispatch/static/manager/src/js/vendor/dispatch-editor/index.js @@ -6,7 +6,8 @@ import { PullQuoteEmbed, VideoEmbed, CodeEmbed, - WidgetEmbed + WidgetEmbed, + PollEmbed } from './embeds' import { @@ -28,5 +29,6 @@ export { PullQuoteEmbed, VideoEmbed, CodeEmbed, - WidgetEmbed + WidgetEmbed, + PollEmbed }