Polls

Setup

Usage

To make the default poll widget (or usage of the default polls template) work, import the polls API:

In your JS/ES code:

import PollWebtool from "@mod-publisher/js/webtools/poll";
dompack.register('.wh-poll', node => new PollWebtool(node));

In your CSS/SCSS:

@import "~@webhare-publisher/webtools/pollstyles";

@at-root
{
  @include wh-poll-flex;
  @include wh-poll-results-percentage;
}

Allowing the user to make polls:

  <!-- Bibliotheek / peilingen -->
  <apply>
    <to type="all" pathmask="/bibliotheek/peilingen/*" />
    <denyfiletype typedef="*" />
    <denyfoldertype typedef="*" />
    <allowfoldertype typedef="http://www.webhare.net/xmlns/publisher/normalfolder" />
    <allowfiletype typedef="http://www.webhare.net/xmlns/publisher/pollwebtool" />
  </apply>

Allowing the user to make poll widget files:

  <apply>
    <to type="all" parenttype="http://www.weekvanhetgeld.nl/siteprl/widgetsfolder"/>

    <!-- DEFAULT POLL WIDGET -->
    <allowfiletype typedef="http://www.webhare.net/xmlns/publisher/pollwidget"/>

    <!-- CUSTOM POLL WIDGET -->
    <allowfiletype typedef="http://www.weekvanhetgeld.nl/widget/poll"/>
  </apply>

Poll settings

Some settings are only available for developers. These can be set through a siteprofile. Usually you want to settings to be applies globally, so all polls on your site use these settings: (although you could target paths such as /library/polls or target specific polls)

  <apply>
    <to type="all"/>

    <!-- allow voting after a day (1440 minutes) -->
    <pollsettings allowvotingagainafter="2880"></pollsettings>
  </apply>

Styling

Classes used for layout/content

Classes used for state

Creating a custom poll widget

Use cases

PUBLIC OBJECTTYPE PollWidget EXTEND WidgetBase
<
  UPDATE PUBLIC MACRO Render()
  {
    OBJECT pollobj := OpenPoll(this->data.poll);
    IF(NOT ObjectExists(pollobj))
      RETURN;

    this->EmbedComponent([ poll := PTR pollobj->Render(this) ]);
  }
>;
PUBLIC OBJECTTYPE PollWidget EXTEND WidgetBase
<
  UPDATE PUBLIC MACRO Render()
  {
    OBJECT pollobj := OpenPoll(this->data.poll);
    IF(NOT ObjectExists(pollobj))
      RETURN;

    RECORD wittyfields := pollobj->GetWittyFields(context);
    INSERT CELL debugdata := PTR DumpValue(wittyfields, "htmltree") INTO wittyfields;
    this->EmbedComponent(wittyfields);
  }
>;

Caveats