Commit 1b3cc2ff authored by KR Moorhouse's avatar KR Moorhouse Committed by GitHub

Merge pull request #3563 from wpninjas/field-data-saves

Field data saves
parents 556921e6 0aa470b0
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
/**
* Handles actions related to our toggle field.
* When we change the toggle, the setting value will be 'on' or ''.
* We need to change this to 1 or 0.
*
* @package Ninja Forms builder
* @subpackage Fields - Edit Field Drawer
* @copyright (c) 2015 WP Ninjas
* @since 3.0
*/
define( [], function() {
var controller = Marionette.Object.extend( {
initialize: function() {
// We don't want the RTE setting to re-render when the value changes.
nfRadio.channel( 'setting-type-button-toggle' ).reply( 'renderOnChange', function(){ return false; } );
// Respond to requests for field setting filtering.
nfRadio.channel( 'button-toggle' ).reply( 'before:updateSetting', this.updateSetting, this );
},
/**
* Return either 1 or 0, depending upon the toggle position.
*
* @since 3.0
* @param Object e event
* @param backbone.model fieldModel field model
* @param string name setting name
* @param backbone.model settingTypeModel field type model
* @return int 1 or 0
*/
updateSetting: function( e, fieldModel, name, settingTypeModel ) {
return e.target.value;
}
});
return controller;
} );
\ No newline at end of file
define( [], function() {
var controller = Marionette.Object.extend({
initialize: function () {
// Respond to requests for field setting filtering.
console.log( nfRadio.channel( 'radio' ) );
nfRadio.channel('radio').reply( 'before:updateSetting', this.updateSetting, this);
},
updateSetting: function( e, fieldModel, name, settingTypeModel ) {
console.log( 'test' );
}
});
return controller;
} );
\ No newline at end of file
......@@ -34,6 +34,8 @@ define(
'controllers/app/changeSettingDefault',
'controllers/app/fieldset',
'controllers/app/toggleSetting',
'controllers/app/buttonToggleSetting',
'controllers/app/radioSetting',
'controllers/app/itemControls',
'controllers/app/mergeTags',
'controllers/app/mergeTagBox',
......@@ -137,6 +139,8 @@ define(
ChangeSettingDefault,
Fieldset,
ToggleSetting,
ButtonToggleSetting,
RadioSetting,
ItemControls,
MergeTags,
MergeTagsBox,
......@@ -271,6 +275,8 @@ define(
new MainContentFieldsSortable();
new ChangeSettingDefault();
new ToggleSetting();
new ButtonToggleSetting();
new RadioSetting();
new DrawerSettingChildView();
new FieldsEditActive();
new FieldSettings();
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
File mode changed from 100644 to 100755
File mode changed from 100755 to 100644
......@@ -237,6 +237,33 @@
}
}
}
.button-toggle {
text-align: left;
border: #ccc 1px solid;
border-radius: 5px;
background: #f1f1f1;
margin-top: 35px;
padding: 9px 0px;
width: 100%;
label {
width: 48%;
display: inline-block;
margin-left: 1%;
span {
width: 100%;
display: inline-block;
cursor: pointer;
}
input:checked + span {
background-color: #1ea9ea;
border-color: #1ea9ea;
}
input + span {
background-color: #ccc;
border-color: #ccc;
}
}
}
}
.nf-drawer-buttons {
display: none;
......
......@@ -33,6 +33,10 @@ final class NF_Actions_Save extends NF_Abstracts_Action
parent::__construct();
$this->_nicename = __( 'Store Submission', 'ninja-forms' );
$settings = Ninja_Forms::config( 'ActionSaveSettings' );
$this->_settings = array_merge( $this->_settings, $settings );
}
/*
......@@ -56,20 +60,58 @@ final class NF_Actions_Save extends NF_Abstracts_Action
$hidden_field_types = apply_filters( 'nf_sub_hidden_field_types', array() );
// For each field on the form...
foreach( $data['fields'] as $field ){
// If this is a "hidden" field type.
if( in_array( $field[ 'type' ], array_values( $hidden_field_types ) ) ) {
$data['actions']['save']['hidden'][] = $field['type'];
// Do not save it.
$data[ 'actions' ][ 'save' ][ 'hidden' ][] = $field[ 'type' ];
continue;
}
$field[ 'value' ] = apply_filters( 'nf_save_sub_user_value', $field[ 'value' ], $field[ 'id' ] );
$sub->update_field_value( $field[ 'id' ], $field[ 'value' ] );
$save_all_none = $action_settings[ 'fields-save-toggle' ];
$save_field = true;
// If we were told to save all fields...
if( 'save_all' == $save_all_none ) {
$save_field = true;
// For each exception to that rule...
foreach( $action_settings[ 'exception_fields' ] as
$exception_field ) {
// Remove it from the list.
if( $field[ 'key' ] == $exception_field[ 'field'] ) {
$save_field = false;
break;
}
}
} // Otherwise... (We were told to save no fields.)
else if( 'save_none' == $save_all_none ) {
$save_field = false;
// For each exception to that rule...
foreach( $action_settings[ 'exception_fields' ] as
$exception_field ) {
// Add it to the list.
if( $field[ 'key' ] == $exception_field[ 'field'] ) {
$save_field = true;
break;
}
}
}
// If we're supposed to save this field...
if( $save_field ) {
// Do so.
$sub->update_field_value( $field['id'], $field['value'] );
}
}
// If we have extra data...
if( isset( $data[ 'extra' ] ) ) {
$sub->update_extra_values( $data['extra'] );
// Save that.
$sub->update_extra_values( $data[ 'extra' ] );
}
do_action( 'nf_before_save_sub', $sub->get_id() );
......
<?php if ( ! defined( 'ABSPATH' ) ) exit;
return apply_filters( 'ninja_forms_action_email_settings', array(
/*
* To
*/
'fields_save_toggle' => array(
'name' => 'fields-save-toggle',
'type' => 'button-toggle',
'width' => 'full',
'options' => array(
array( 'label' => __( 'Save All', 'ninja-forms' ), 'value' => 'save_all' ),
array( 'label' => __( 'Save None', 'ninja-forms' ), 'value' => 'save_none' )
),
'group' => 'primary',
'label' => __( 'Fields', 'ninja-forms' ),
'value' => 'save_all',
),
/*
|--------------------------------------------------------------------------
| Exception Field
|--------------------------------------------------------------------------
*/
'exception_fields' => array(
'name' => 'exception_fields',
'type' => 'option-repeater',
'label' => __( 'Except', 'ninja-forms' ) . ' <a href="#" class="nf-add-new">' .
__( 'Add New', 'ninja-forms' ) . '</a>',
'width' => 'full',
'group' => 'primary',
'tmpl_row' => 'nf-tmpl-save-field-repeater-row',
'value' => array(),
'columns' => array(
'form_field' => array(
'header' => __( 'Form Field', 'ninja-forms' ),
'default' => '',
'options' => array(),
),
),
),
));
......@@ -539,6 +539,46 @@ Label Three, value-three, 3
</script>
<script id="tmpl-nf-edit-setting-radio" type="text/template">
<span class="nf-setting-label">{{{ data.label }}}{{{ data.renderTooltip() }}}</span>
<#
_.each( data.options, function( option ) {
#>
<span class="nf-setting-label">{{{ option.label }}}</span>
<input type="radio" value="{{{ option.value }}}" name="{{{ data.name }}}" {{{ data.value == option.value ? "checked" : '' }}}></option>
<#
} );
#>
</script>
<script id="tmpl-nf-edit-setting-button-toggle" type="text/template">
<span class="nf-setting-label">{{{ data.label }}}{{{ data.renderTooltip() }}}</span>
<div class="nf-setting button-toggle">
<#
_.each( data.options, function( option ) {
#>
<label for="field-{{{ option.value }}}"
data-option_value="{{{ option.value }}}">
<input type="radio" id="field-{{{ option.value }}}"
style="display:none;"
class="nf-button-toggle setting"
value="{{{ option.value }}}" name="{{{data.name }}}"
{{{ data.value == option.value ? "checked" : '' }}}>
<span class="nf-button primary {{{ data.value != option.value ?
"disabled": "" }}}">{{{ option.label }}}</span>
</label>
<#
} );
#>
</div>
</script>
<script id="tmpl-nf-edit-setting-color" type="text/template">
<label for="{{{ data.name }}}" class="{{{ data.renderLabelClasses() }}}">{{{ data.label }}} {{{ data.renderTooltip() }}}</label>
......@@ -693,4 +733,20 @@ Label Three, value-three, 3
</div>
</script>
<script id="nf-tmpl-save-field-repeater-row" type="text/template">
<div>
<span class="dashicons dashicons-menu handle"></span>
</div>
<div>
<# try { #>
{{{ data.renderFieldSelect( 'field', data.field ) }}}
<# } catch ( err ) { #>
<input type="text" class="setting" value="{{ data.field }}" data-id="field" >
<# } #>
</div>
<div>
<span class="dashicons dashicons-dismiss nf-delete"></span>
</div>
</script>
<?php do_action( 'ninja_forms_builder_templates' ); ?>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment