From 3ab001ce9775e1d0ef5558c4ed7edbebb139d900 Mon Sep 17 00:00:00 2001 From: ultimatemember Date: Fri, 9 Jan 2015 20:12:06 +0200 Subject: [PATCH] Fixed important issue with row styling --- admin/assets/js/um-admin-dragdrop.js | 6 + admin/core/um-admin-actions-fields.php | 2 +- admin/core/um-admin-builder.php | 4 +- admin/core/um-admin-dragdrop.php | 34 +++-- core/um-fields.php | 188 ++++++++++--------------- 5 files changed, 114 insertions(+), 120 deletions(-) diff --git a/admin/assets/js/um-admin-dragdrop.js b/admin/assets/js/um-admin-dragdrop.js index 79631006..2f1f215f 100644 --- a/admin/assets/js/um-admin-dragdrop.js +++ b/admin/assets/js/um-admin-dragdrop.js @@ -170,8 +170,13 @@ function UM_Rows_Refresh(){ sub_rows_count = row.find('.um-admin-drag-rowsub').length; + var origin_id = jQuery(this).attr('data-original'); + jQuery('.um_update_order_fields').append(''); + jQuery('.um_update_order_fields').append(''); jQuery('.um_update_order_fields').append(''); + + jQuery(this).attr('data-original', '_um_row_'+c ); }); @@ -300,6 +305,7 @@ jQuery(document).ready(function() { var dragg = jQuery('.um-admin-drag-ajax'); dragg.append( '
' + jQuery('.um-col-demon-row').html() + '
' ); dragg.find('.um-admin-drag-row:last').find('.um-admin-drag-row-icons').find('a.um-admin-drag-row-edit').attr('data-arg3', '_um_row_' + ( dragg.find('.um-admin-drag-row').length ) ); + dragg.find('.um-admin-drag-row:last').attr('data-original', '_um_row_' + ( dragg.find('.um-admin-drag-row').length ) ); UM_update_rows(); UM_update_subrows(); UM_Rows_Refresh(); diff --git a/admin/core/um-admin-actions-fields.php b/admin/core/um-admin-actions-fields.php index ab6cea66..fc8025b0 100644 --- a/admin/core/um-admin-actions-fields.php +++ b/admin/core/um-admin-actions-fields.php @@ -31,7 +31,7 @@ $save[ $_metakey ]['icon'] = ''; foreach( $array['post'] as $key => $val){ - if ( substr( $key, 0, 1) === '_' && $val != '' ) { // field attribute + if ( substr( $key, 0, 1) === '_' ) { // field attribute $new_key = ltrim ($key,'_'); if ( $new_key == 'options' ) { diff --git a/admin/core/um-admin-builder.php b/admin/core/um-admin-builder.php index 17fb3928..1e808969 100644 --- a/admin/core/um-admin-builder.php +++ b/admin/core/um-admin-builder.php @@ -78,6 +78,8 @@ class UM_Admin_Builder { ***/ function show_builder(){ global $ultimatemember; + + //print_r( get_option('um_form_rowdata_' . $this->form_id ) ); $fields = $ultimatemember->query->get_attr('custom_fields', $this->form_id ); @@ -149,7 +151,7 @@ class UM_Admin_Builder { ?> -
+
diff --git a/admin/core/um-admin-dragdrop.php b/admin/core/um-admin-dragdrop.php index c4341d85..8c8795c0 100644 --- a/admin/core/um-admin-dragdrop.php +++ b/admin/core/um-admin-dragdrop.php @@ -32,14 +32,14 @@ class UM_Admin_DragDrop { unset( $fields[$key] ); } } - - update_option('um_form_rowdata_' . $form_id , $this->row_data ); - + foreach( $_POST as $key => $value ) { // adding rows if (0 === strpos($key, '_um_row_')) { + $update_args = null; + $row_id = str_replace( '_um_row_', '', $key ); $row_array = array( @@ -47,14 +47,23 @@ class UM_Admin_DragDrop { 'id' => $value, 'sub_rows' => $_POST[ '_um_rowsub_'.$row_id .'_rows' ], 'cols' => $_POST[ '_um_rowcols_'.$row_id .'_cols' ], + 'origin' => $_POST[ '_um_roworigin_'.$row_id . '_val' ], ); - if ( isset( $this->row_data[$key] ) ) { - $row_args = array_merge( $this->row_data[$key], $row_array ); - } else { - $row_args = $row_array; - } + $row_args = $row_array; + if ( isset( $this->row_data[ $row_array['origin'] ] ) ) { + foreach( $this->row_data[ $row_array['origin'] ] as $k => $v ){ + if ( $k != 'position' && $k != 'metakey' ) { + $update_args[$k] = $v; + } + } + if ( isset( $update_args ) ) { + $row_args = array_merge( $update_args, $row_array ); + } + $this->exist_rows[] = $key; + } + $fields[$key] = $row_args; } @@ -101,6 +110,15 @@ class UM_Admin_DragDrop { } + foreach( $this->row_data as $k => $v ) { + if ( !in_array( $k, $this->exist_rows ) ) + unset( $this->row_data[$k] ); + } + + update_option('um_existing_rows_' . $form_id, $this->exist_rows ); + + update_option('um_form_rowdata_' . $form_id , $this->row_data ); + $ultimatemember->query->update_attr( 'custom_fields', $form_id, $fields ); } diff --git a/core/um-fields.php b/core/um-fields.php index 6971b489..ff2e8bbf 100644 --- a/core/um-fields.php +++ b/core/um-fields.php @@ -1630,64 +1630,11 @@ class UM_Fields { // master rows foreach ( $this->rows as $row_id => $row_array ) { - extract($row_array); - - $background = null; - $padding = null; - $margin = null; - $borderradius = null; - $heading_background_color = null; - $heading_padding = null; - $heading_text_color = null; - $heading_borderradius = null; - $border = null; - $bordercolor = null; - $borderstyle = null; - - // row css rules - if ( isset($row_array['padding']) ) $padding = 'padding: ' . $row_array['padding'] .';'; - if ( isset($row_array['margin']) ) { - $margin = 'margin: ' . $row_array['margin'] .';'; - } else { - $margin = 'margin: 0 0 30px 0;'; - } - if ( isset($row_array['background']) ) $background = 'background-color: ' . $row_array['background'] .';'; - if ( isset($row_array['borderradius']) ) $borderradius = 'border-radius: 0px 0px ' . $row_array['borderradius'] . ' ' . $row_array['borderradius'] . ';'; - if ( isset($row_array['border']) ) $border = 'border-width: ' . $row_array['border'] . ';'; - if ( isset($row_array['bordercolor']) ) $bordercolor = 'border-color: ' . $row_array['bordercolor'] . ';'; - if ( isset($row_array['borderstyle']) ) $borderstyle = 'border-style: ' . $row_array['borderstyle'] . ';'; - - // show the heading - if ( isset( $row_array['heading'] ) && $row_array['heading'] == 1 ) { - - if ( isset($row_array['heading_background_color']) ) { - $heading_background_color = 'background-color: ' . $row_array['heading_background_color'] .';'; - $heading_padding = 'padding: 10px 15px;'; - } - - if ( isset($row_array['heading_text_color']) ) $heading_text_color = 'color: ' . $row_array['heading_text_color'] .';'; - if ( isset($row_array['borderradius']) ) $heading_borderradius = 'border-radius: ' . $row_array['borderradius'] . ' ' . $row_array['borderradius'] . ' 0px 0px;'; - - $output .= '
'; - if ( isset( $row_array['icon'] ) ) $output .= ''; - $output .= $row_array['heading_text'] .'
'; - - } else { - - // no heading - if ( isset($row_array['borderradius']) ) $borderradius = 'border-radius: ' . $row_array['borderradius'] . ';'; - - } - - // start row $row_fields = $this->get_fields_by_row( $row_id ); + if ( $row_fields ) { - if ( !$row_fields ) return; + $output .= $this->new_row_output( $row_id, $row_array ); - $custom_row_class = (isset($row_array['css_class'])) ? $row_array['css_class'] : ''; - - $output .= '
'; - $sub_rows = ( isset( $row_array['sub_rows'] ) ) ? $row_array['sub_rows'] : 1; for( $c = 0; $c < $sub_rows; $c++ ) { @@ -1763,6 +1710,8 @@ class UM_Fields { } $output .= '
'; + + } } @@ -1914,63 +1863,10 @@ class UM_Fields { // master rows foreach ( $this->rows as $row_id => $row_array ) { - extract($row_array); - - $background = null; - $padding = null; - $margin = null; - $borderradius = null; - $heading_background_color = null; - $heading_padding = null; - $heading_text_color = null; - $heading_borderradius = null; - $border = null; - $bordercolor = null; - $borderstyle = null; - - // row css rules - if ( isset($row_array['padding']) ) $padding = 'padding: ' . $row_array['padding'] .';'; - if ( isset($row_array['margin']) ) { - $margin = 'margin: ' . $row_array['margin'] .';'; - } else { - $margin = 'margin: 0 0 30px 0;'; - } - if ( isset($row_array['background']) ) $background = 'background-color: ' . $row_array['background'] .';'; - if ( isset($row_array['borderradius']) ) $borderradius = 'border-radius: 0px 0px ' . $row_array['borderradius'] . ' ' . $row_array['borderradius'] . ';'; - if ( isset($row_array['border']) ) $border = 'border-width: ' . $row_array['border'] . ';'; - if ( isset($row_array['bordercolor']) ) $bordercolor = 'border-color: ' . $row_array['bordercolor'] . ';'; - if ( isset($row_array['borderstyle']) ) $borderstyle = 'border-style: ' . $row_array['borderstyle'] . ';'; - - // show the heading - if ( isset( $row_array['heading'] ) && $row_array['heading'] == 1 ) { - - if ( isset($row_array['heading_background_color']) ) { - $heading_background_color = 'background-color: ' . $row_array['heading_background_color'] .';'; - $heading_padding = 'padding: 10px 15px;'; - } - - if ( isset($row_array['heading_text_color']) ) $heading_text_color = 'color: ' . $row_array['heading_text_color'] .';'; - if ( isset($row_array['borderradius']) ) $heading_borderradius = 'border-radius: ' . $row_array['borderradius'] . ' ' . $row_array['borderradius'] . ' 0px 0px;'; - - $output .= '
'; - if ( isset( $row_array['icon'] ) ) $output .= ''; - $output .= $row_array['heading_text'] .'
'; - - } else { - - // no heading - if ( isset($row_array['borderradius']) ) $borderradius = 'border-radius: ' . $row_array['borderradius'] . ';'; - - } - - // start row $row_fields = $this->get_fields_by_row( $row_id ); + if ( $row_fields ) { - if ( !$row_fields ) return; - - $custom_row_class = (isset($row_array['css_class'])) ? $row_array['css_class'] : ''; - - $output .= '
'; + $output .= $this->new_row_output( $row_id, $row_array ); $sub_rows = ( isset( $row_array['sub_rows'] ) ) ? $row_array['sub_rows'] : 1; for( $c = 0; $c < $sub_rows; $c++ ) { @@ -2047,6 +1943,8 @@ class UM_Fields { } $output .= '
'; + + } } @@ -2054,5 +1952,75 @@ class UM_Fields { return $output; } + + /*** + *** @begin new row in form + ***/ + function new_row_output( $row_id, $row_array ) { + $output = null; + extract($row_array); + + $padding = (isset($padding))?$padding:''; + $margin = (isset($margin))?$margin:''; + $background = (isset($background))?$background:''; + $borderradius = (isset($borderradius))?$borderradius:''; + $border = (isset($border))?$border:''; + $bordercolor = (isset($bordercolor))?$bordercolor:''; + $borderstyle = (isset($borderstyle))?$borderstyle:''; + $heading = (isset($heading))?$heading:''; + $css_class = (isset($css_class))?$css_class:''; + + $css_padding = ''; + $css_margin = ''; + $css_background = ''; + $css_borderradius = ''; + $css_border = ''; + $css_bordercolor = ''; + $css_borderstyle = ''; + $css_heading_background_color = ''; + $css_heading_padding = ''; + $css_heading_text_color = ''; + $css_heading_borderradius = ''; + + // row css rules + if ( $padding ) $css_padding = 'padding: ' . $padding .';'; + if ( $margin ) { + $css_margin = 'margin: ' . $margin .';'; + } else { + $css_margin = 'margin: 0 0 30px 0;'; + } + + if ( $background ) $css_background = 'background-color: ' . $background .';'; + if ( $borderradius ) $css_borderradius = 'border-radius: 0px 0px ' . $borderradius . ' ' . $borderradius . ';'; + if ( $border ) $css_border = 'border-width: ' . $border . ';'; + if ( $bordercolor ) $css_bordercolor = 'border-color: ' . $bordercolor . ';'; + if ( $borderstyle ) $css_borderstyle = 'border-style: ' . $borderstyle . ';'; + + // show the heading + if ( $heading ) { + + if ( $heading_background_color ) { + $css_heading_background_color = 'background-color: ' . $heading_background_color .';'; + $css_heading_padding = 'padding: 10px 15px;'; + } + + if ( $heading_text_color ) $css_heading_text_color = 'color: ' . $heading_text_color .';'; + if ( $borderradius ) $css_heading_borderradius = 'border-radius: ' . $borderradius . ' ' . $borderradius . ' 0px 0px;'; + + $output .= '
'; + if ( $icon ) $output .= ''; + $output .= $heading_text .'
'; + + } else { + + // no heading + if ( $borderradius ) $css_borderradius = 'border-radius: ' . $borderradius . ';'; + + } + + $output .= '
'; + + return $output; + } } \ No newline at end of file