Example #1
0
    def handle_save_action(self, action, data):
        if form.applyChanges(self.context, self.form_fields, data,
                             self.adapters):
            zope.event.notify(
                zope.lifecycleevent.ObjectModifiedEvent(self.context))
            zope.event.notify(ploneformbase.EditSavedEvent(self.context))
            IStatusMessage(self.request).addStatusMessage(_("Changes saved."),
                                                          type="info")
        else:
            zope.event.notify(ploneformbase.EditCancelledEvent(self.context))
            IStatusMessage(self.request).addStatusMessage(
                _("No changes made."), type="info")

        self.settings = PageTilesSettings(self.context)
        tiles = self.settings.tiles
        index = data.get('index', -1)

        image = data.get('image')
        image_type = None
        if image != None:
            scale_width = getUtility(IRegistry)[
                'tx.tiles.configlet.ITilesControlPanel.image_scale_width']
            (image, image_type, image_size) = scaleImage(image,
                                                         width=scale_width)
        else:
            if index != -1:
                image = tiles[index].get('image')
                image_type = tiles[index].get('image_type')

        # create new uuid on each save
        uuid = uuid4().hex

        value = {
            'link_reference': data.get('link_reference'),
            'image': image,
            'image_type': image_type,
            'configuration': data.get('configuration'),
            'heading': data.get('heading'),
            'html': data.get('tile'),
            'url': data.get('url'),
            'uuid': uuid
        }

        if index == -1:
            tiles.append(value)
            index = len(tiles) - 1
        else:
            tiles[index] = value

        self.settings.tiles = tiles

        url = getMultiAdapter((self.context, self.request),
                              name='absolute_url')() + "/@@tx-tiles-settings"
        self.request.response.redirect(url)
Example #2
0
class IPageTilesSettings(Interface):
    """
    difference here is the user creates all his tiles
    """

    show = schema.Bool(title=_(u"Show the tiles"),
                       description=_(u"Uncheck to hide the tiles."),
                       default=True,
                       required=True)

    tilesposition = schema.Choice(title=_(u"Tiles position"),
                                  default="portal_top",
                                  vocabulary=SimpleVocabulary([
                                      SimpleTerm(title=_(u"Portal top"),
                                                 value='portal_top'),
                                      SimpleTerm(title=_(u"Below title"),
                                                 value='below_content_title'),
                                      SimpleTerm(title=_(u"Below content"),
                                                 value='below_content'),
                                  ]),
                                  required=True)

    tiles = schema.List(
        title=_(u"Tiles"),
        description=_(u"Use drag and drop to rearrange the tiles."),
        default=[])
Example #3
0
class ITilesSettings(Interface):
    """
    The actual tiles settings
    """

    configuration = schema.Choice(
        source="tiles_configuration_choices",
        title=_(u"Tiles layout"),
        description=_(u"Choose a layout for all tiles."),
        required=False)

    only_here = schema.Bool(
        title=_(u'Show only on this page'),
        description=_(u"If unchecked tiles will be shown on subpages"),
        default=True,
        required=True)
Example #4
0
class TilesPageSettingsForm(FieldsetsEditForm):
    """
    The page that holds all the tiles settings
    """
    tiles = FormFieldsets(IPageTilesSettings)
    tiles.id = 'tiles'
    tiles.label = _(u'Tiles')

    settings = FormFieldsets(ITilesSettings)
    settings.id = 'settings'
    settings.label = _(u'Settings')

    form_fields = FormFieldsets(tiles, settings)
    #our revised TilesWidget that only displays tiles really
    form_fields['tiles'].custom_widget = TilesWidget
    label = _(u"Edit Tiles")
Example #5
0
    def handle_cancel_action(self, action, data):
        IStatusMessage(self.request).addStatusMessage(_("Changes canceled."),
                                                      type="info")

        url = getMultiAdapter((self.context, self.request),
                              name='absolute_url')() + "/@@tx-tiles-settings"
        self.request.response.redirect(url)
        return ''
Example #6
0
class ITile(Interface):

    configuration = schema.Choice(
        source="tile_configuration_choices",
        title=_(u"Layout"),
        description=_(u"Choose a layout for this tile."),
        required=False)

    heading = schema.TextLine(
        title=_(u"Heading"),
        required=False,
    )

    image = schema.Bytes(
        title=_(u"Image"),
        description=_(u"You can drag and drop a file to this field."),
        required=False,
    )

    tile = schema.Text(
        title=_(u"Text"),
        required=False,
    )

    link_reference = schema.Choice(
        title=_(u"Link to content"),
        description=_(u"Choose a content item to link this tile to."),
        required=False,
        source=SearchableTextSourceBinder({}, default_query='path:'))

    url = schema.URI(
        title=_(u'External link'),
        description=_(
            u'Please enter a full URL. Has precedence before the above field.'
        ),
        required=False,
    )

    index = schema.Int(
        title=u'',
        required=False,
    )
Example #7
0
class ITilesControlPanel(Interface):
    """
    The actual tiles settings
    """

    configuration = schema.List(
        title=_(u'Configuration'),
        description=
        _(u"Enter one configuration per line. Format: 'Name|css-class-name'. First entry is default."
          ),
        value_type=schema.TextLine(),
        required=True)

    tile_configuration = schema.List(
        title=_(u'Tile configuration'),
        description=
        _(u"Additional configuration for individual tiles. Format: 'Name|css-class-name'."
          ),
        value_type=schema.TextLine(),
        required=False)

    image_scale_width = schema.Int(
        title=_(u"Image scale width"),
        description=_(
            u"All uploaded images will be scaled down to this value."),
        default=1000,
        required=True)
Example #8
0
class ControlPanelForm(RegistryEditForm):

    form.extends(RegistryEditForm)
    schema = ITilesControlPanel
    label = _(u"Tiles default settings")
    description = _(u'Default settings to use for all tiles.')
Example #9
0
class AddTileForm(formbase.EditFormBase):
    """
    The add/edit form for a tile
    """
    form_fields = form.FormFields(ITile)
    form_fields['index'].custom_widget = HiddenWidget
    #form_fields['image'].custom_widget = ImageWidget
    form_fields['tile'].custom_widget = WYSIWYGWidget
    form_fields['link_reference'].custom_widget = UberSelectionWidget

    label = _(u"Edit tile")
    #description = _(u'description_add_tile_form', default=u"")
    form_name = _(u"Add/Update Tile")

    @form.action(_(u"Save"), condition=form.haveInputWidgets, name=u'save')
    def handle_save_action(self, action, data):
        if form.applyChanges(self.context, self.form_fields, data,
                             self.adapters):
            zope.event.notify(
                zope.lifecycleevent.ObjectModifiedEvent(self.context))
            zope.event.notify(ploneformbase.EditSavedEvent(self.context))
            IStatusMessage(self.request).addStatusMessage(_("Changes saved."),
                                                          type="info")
        else:
            zope.event.notify(ploneformbase.EditCancelledEvent(self.context))
            IStatusMessage(self.request).addStatusMessage(
                _("No changes made."), type="info")

        self.settings = PageTilesSettings(self.context)
        tiles = self.settings.tiles
        index = data.get('index', -1)

        image = data.get('image')
        image_type = None
        if image != None:
            scale_width = getUtility(IRegistry)[
                'tx.tiles.configlet.ITilesControlPanel.image_scale_width']
            (image, image_type, image_size) = scaleImage(image,
                                                         width=scale_width)
        else:
            if index != -1:
                image = tiles[index].get('image')
                image_type = tiles[index].get('image_type')

        # create new uuid on each save
        uuid = uuid4().hex

        value = {
            'link_reference': data.get('link_reference'),
            'image': image,
            'image_type': image_type,
            'configuration': data.get('configuration'),
            'heading': data.get('heading'),
            'html': data.get('tile'),
            'url': data.get('url'),
            'uuid': uuid
        }

        if index == -1:
            tiles.append(value)
            index = len(tiles) - 1
        else:
            tiles[index] = value

        self.settings.tiles = tiles

        url = getMultiAdapter((self.context, self.request),
                              name='absolute_url')() + "/@@tx-tiles-settings"
        self.request.response.redirect(url)

    @form.action(_(u'Cancel'), validator=null_validator, name=u'cancel')
    def handle_cancel_action(self, action, data):
        IStatusMessage(self.request).addStatusMessage(_("Changes canceled."),
                                                      type="info")

        url = getMultiAdapter((self.context, self.request),
                              name='absolute_url')() + "/@@tx-tiles-settings"
        self.request.response.redirect(url)
        return ''