Sha256: 259c7a00eb1908656e6bccb57dba21de9d1054e7e2b43ab877e6dc8299c2c171

Contents?: true

Size: 1.66 KB

Versions: 1

Compression:

Stored size: 1.66 KB

Contents

##
# PublishingHelper
#
# Some shared code for rendering alerts, and toggling fields
#
class outpost.PublishingHelper
    defaults:
        statusPending:    "3"
        statusPublished:  "5"

    constructor: (@options={}) ->
        _.defaults @options, @defaults

        @statusPending   = @options.statusPending
        @statusPublished = @options.statusPublished

        # Elements
        @form          = $ @options.form
        @container     = $ @options.container,     @form # Wrapper for the fields
        @statusField   = $ @options.statusField,   @form # Status select
        @notifications = $ @options.notifications, @form # Notification bucket

        # Event for when the status field is changed
        @statusField.on
            change: (event) =>
                @setStatus()
                @notify()

    #----------
    # Get the current status from the dropdown
    setStatus: ->
        @status = $("option:selected", @statusField).val()

    #----------
    # Helpers for finding current and original status
    isPending: ->
        @status is @statusPending

    isPublished: ->
        @status is @statusPublished

    wasPending: ->
        @originalStatus is @statusPending

    wasPublished: ->
        @originalStatus is @statusPublished

    #----------
    # Handles scenarios
    notify: ->
        # Override me

    #----------
    # Render the notification
    alert: (key) ->
        @alerts[key].render()

    #----------
    # Mass-Detach all of the alerts
    clearAlerts: ->
        alert.detach() for name,alert of @alerts

    #----------

    showFields: ->
        @container.show()

    #----------

    hideFields: ->
        @container.hide()

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
outpost-publishing-1.0.1 lib/assets/javascripts/outpost/publishing_helper.js.coffee