Sha256: f8890e2840c9c5a1bba2959c2fb45139aa5e160bca0e94c298be0e072e0305ec

Contents?: true

Size: 1.62 KB

Versions: 2

Compression:

Stored size: 1.62 KB

Contents

/**
 * FORM ITEM CHOICE
 */

import { _FormItemEditor } from './form_item_editor'


class FieldSettingChoices {
	
	constructor()
	{
		this.target = '.field-setting-choices--choice'
	}

	isSet()
	{
		if ( $( this.target ).length > 0 ) { return true }
		else { return false }
	}

	setEvents()
	{
		$(document).on('click', '.field-setting-choices--add-choice', addChoice )
		
		$(document).on('click', '.field-setting-choices--delete-choice', deleteChoice )
		$(document).on('click', '.field-setting-choices--js-delete-choice', function( event )
		{
			event.preventDefault()
			$( this ).closest('.field-setting-choices--choice').remove()
			// Update form item editor size
			_FormItemEditor.resize()
		})
	}
}

export let _FieldSettingChoices = new FieldSettingChoices()


/**
 * HELPER FUNCTIONS
 */

function addChoice(event)
{
	event.preventDefault()
	// Clone the new choice field
	var choices_id = $( this ).data('choices-id')
	var choices = $(`#${choices_id}`)
	var newchoice = choices.find('.field-setting-choices--new-choice')
	var clone = newchoice.clone().removeClass('field-setting-choices--new-choice').toggle()
	clone.find('.field-setting-choices--toggle-choice').toggle()
	// Append the clone right after
	choices.prepend( clone )
	// Update form item editor size
	_FormItemEditor.resize()
}


function deleteChoice( event )
{
	event.preventDefault()

	var choice = $( this ).closest('.field-setting-choices--choice')
	var destination = $( this ).attr('href')
	var self = this

	$.ajax({
		url: destination,
		type: 'DELETE',
		success: function() { 
			choice.remove()
			// Update form item editor size
			_FormItemEditor.resize()
		}
	})
}

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
binda-0.1.3 app/assets/javascripts/binda/components/field_setting_choices.js
binda-0.1.2 app/assets/javascripts/binda/components/field_setting_choices.js