{#
/*
 * Spring Signage Ltd - http://www.springsignage.com
 * Copyright (C) 2017 Spring Signage Ltd
 * (notification-designer-javascript.twig)
 */
#}
<script type="text/javascript">

    /** 
    * Runs before form submit
    * @return {bool} - Form validation
    */
    function twitter_form_edit_submit() {        

        // Update text callback fields
        formHelpers.updateCKEditor();
    }

    // Runs after edit form opens
    function twitter_form_edit_open() {

        // Set duration field, using the helper ()
        formHelpers.setupCheckboxInputFields($(this).find('form'), '#useDuration', '.duration-fields');

        // Set override template field, using the helper ()
        formHelpers.setupCheckboxInputFields($(this), '#overrideTemplate', '.template-override-controls', '.template-selector-control');

        // Set effect type input field, using the helper ()
        formHelpers.setupObjectValueInputFields($(this).find('form'), '#effect', ['.effect-controls'], ['noAnim'], true);

        // Setup editors
        formHelpers.setupDualTypeTextArea(this, 'ta_text', !$(this).data('formEditorOnly'));

        // Setup template override
        formHelpers.setupTemplateOverriding(this, '#overrideTemplate', '#templateId', 
            {
                '#ta_text_advanced': 'defaultVisualEditor',
                '#ta_text': 'template',
                '#ta_css': 'css',
                '#widgetOriginalWidth': 'widgetOriginalWidth',
                '#widgetOriginalHeight': 'widgetOriginalHeight',
                '#widgetOriginalPadding': 'widgetOriginalPadding',
                '#resultContent': 'resultContent'
            });

        // Set colorpicker for the bg colour
        $(this).find('#backgroundColor').colorpicker({format: 'rgba'});

        // Tidy up colorpickers on modal close
        if($(this).hasClass('modal')) {
            $(this).on("hide.bs.modal", function(e) {
                if(e.namespace === 'bs.modal') {
                    // Remove colour pickers
                    $(this).find("#backgroundColor").colorpicker('destroy');
                }
            });
        }
    }
</script>