Reload the widget form with the ajax response after save, add Close link to the widgets, don't auto-close on save to show possible errors returned from validation
git-svn-id: http://svn.automattic.com/wordpress/trunk@11498 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
f09eba1776
commit
b7bc0faa73
|
@ -1289,6 +1289,9 @@ case 'save-widget' :
|
|||
$id_base = $_POST['id_base'];
|
||||
$widget_id = $_POST['widget-id'];
|
||||
$sidebar_id = $_POST['sidebar'];
|
||||
$multi_number = !empty($_POST['multi_number']) ? (int) $_POST['multi_number'] : 0;
|
||||
$settings = isset($_POST['widget-' . $id_base]) && is_array($_POST['widget-' . $id_base]) ? $_POST['widget-' . $id_base] : false;
|
||||
$error = '<p>' . __('An error has occured. Please reload the page and try again.') . '</p>';
|
||||
|
||||
$sidebars = wp_get_sidebars_widgets();
|
||||
$sidebar = isset($sidebars[$sidebar_id]) ? $sidebars[$sidebar_id] : array();
|
||||
|
@ -1297,10 +1300,17 @@ case 'save-widget' :
|
|||
if ( isset($_POST['delete_widget']) && $_POST['delete_widget'] ) {
|
||||
|
||||
if ( !isset($wp_registered_widgets[$widget_id]) )
|
||||
die('-1');
|
||||
die($error);
|
||||
|
||||
$sidebar = array_diff( $sidebar, array($widget_id) );
|
||||
$_POST = array('sidebar' => $sidebar_id, 'widget-' . $id_base => array(), 'the-widget-id' => $widget_id, 'delete_widget' => '1');
|
||||
} elseif ( $settings && preg_match( '/__i__|%i%/', key($settings) ) ) {
|
||||
if ( !$multi_number )
|
||||
die($error);
|
||||
|
||||
$_POST['widget-' . $id_base] = array( $multi_number => array_shift($settings) );
|
||||
$widget_id = $id_base . '-' . $multi_number;
|
||||
$sidebar[] = $widget_id;
|
||||
}
|
||||
$_POST['widget-id'] = $sidebar;
|
||||
|
||||
|
@ -1324,7 +1334,13 @@ case 'save-widget' :
|
|||
die();
|
||||
}
|
||||
|
||||
die('1');
|
||||
if ( !empty($_POST['add_new']) )
|
||||
die();
|
||||
|
||||
if ( $form = $wp_registered_widget_controls[$widget_id] )
|
||||
call_user_func_array( $form['callback'], $form['params'] );
|
||||
|
||||
die();
|
||||
break;
|
||||
default :
|
||||
do_action( 'wp_ajax_' . $_POST['action'] );
|
||||
|
|
|
@ -188,7 +188,7 @@ a.widget-action {
|
|||
|
||||
.widget .widget-inside,
|
||||
.widget .widget-description {
|
||||
padding: 15px;
|
||||
padding: 12px 12px 10px;
|
||||
font-size: 11px;
|
||||
line-height: 16px;
|
||||
}
|
||||
|
@ -226,6 +226,18 @@ a.widget-action {
|
|||
text-decoration: none;
|
||||
}
|
||||
|
||||
.widget-control-actions a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.widget-control-actions .ajax-feedback {
|
||||
padding-bottom: 3px;
|
||||
}
|
||||
|
||||
.widget-control-actions div.alignleft {
|
||||
margin-top: 6px;
|
||||
}
|
||||
|
||||
div#sidebar-info {
|
||||
padding: 0 1em;
|
||||
margin-bottom: 1em;
|
||||
|
|
|
@ -168,12 +168,13 @@ function wp_widget_control( $sidebar_args ) {
|
|||
|
||||
<div class="widget-inside">
|
||||
<form action="" method="post">
|
||||
<div class="widget-content">
|
||||
<?php
|
||||
if ( isset($control['callback']) )
|
||||
$has_form = call_user_func_array( $control['callback'], $control['params'] );
|
||||
else
|
||||
echo "\t\t<p>" . __('There are no options for this widget.') . "</p>\n"; ?>
|
||||
|
||||
</div>
|
||||
<input type="hidden" name="widget-id" class="widget-id" value="<?php echo esc_attr($id_format); ?>" />
|
||||
<input type="hidden" name="id_base" class="id_base" value="<?php echo esc_attr($id_base); ?>" />
|
||||
<input type="hidden" name="widget-width" class="widget-width" value="<?php echo esc_attr($control['width']); ?>" />
|
||||
|
@ -183,9 +184,15 @@ function wp_widget_control( $sidebar_args ) {
|
|||
<input type="hidden" name="add_new" class="add_new" value="<?php echo esc_attr($add_new); ?>" />
|
||||
|
||||
<div class="widget-control-actions">
|
||||
<a class="button widget-control-remove alignleft" href="#remove"><?php _e('Remove'); ?></a>
|
||||
<div class="alignleft">
|
||||
<a class="widget-control-remove" href="#remove"><?php _e('Remove'); ?></a> |
|
||||
<a class="widget-control-close" href="#close"><?php _e('Close'); ?></a>
|
||||
</div>
|
||||
<?php if ( 'noform' !== $has_form ) { ?>
|
||||
<input type="submit" name="savewidget" class="button-primary widget-control-save alignright" value="<?php esc_attr_e('Save'); ?>" />
|
||||
<div class="alignright">
|
||||
<img src="images/wpspin_light.gif" class="ajax-feedback " title="" alt="" />
|
||||
<input type="submit" name="savewidget" class="button-primary widget-control-save" value="<?php esc_attr_e('Save'); ?>" />
|
||||
</div>
|
||||
<?php } ?>
|
||||
<br class="clear" />
|
||||
</div>
|
||||
|
|
|
@ -92,7 +92,7 @@ wpWidgets = {
|
|||
ui.item.draggable('destroy');
|
||||
|
||||
if ( ui.item.hasClass('deleting') ) {
|
||||
wpWidgets.save( ui.item, 1, 0, 0, 1 ); // delete widget
|
||||
wpWidgets.save( ui.item, 1, 0, 1 ); // delete widget
|
||||
ui.item.remove();
|
||||
return;
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ wpWidgets = {
|
|||
rem = 'div#' + id;
|
||||
}
|
||||
wpWidgets.addEvents(ui.item);
|
||||
wpWidgets.save( ui.item, 0, 0, 0, 1 );
|
||||
wpWidgets.save( ui.item, 0, 0, 1 );
|
||||
ui.item.find('input.add_new').val('');
|
||||
ui.item.find('a.widget-action').click();
|
||||
return;
|
||||
|
@ -125,12 +125,7 @@ wpWidgets = {
|
|||
}
|
||||
}).not(':visible').sortable('disable');
|
||||
wpWidgets.resize();
|
||||
|
||||
$('.widget-inside label').each(function(){
|
||||
var f = $(this).attr('for');
|
||||
if ( f && f == $('input', this).attr('id') )
|
||||
$(this).removeAttr('for');
|
||||
});
|
||||
wpWidgets.fixLabels();
|
||||
},
|
||||
|
||||
saveOrder : function(sb) {
|
||||
|
@ -153,10 +148,10 @@ wpWidgets = {
|
|||
this.resize();
|
||||
},
|
||||
|
||||
save : function(widget, del, close, animate, order) {
|
||||
save : function(widget, del, animate, order) {
|
||||
var sb = widget.parents('.widgets-sortables').attr('id'), data = widget.find('form').serialize(), a;
|
||||
widget = $(widget);
|
||||
$('#' + sb).parents('.widgets-holder-wrap').find('.ajax-feedback').css('visibility', 'visible');
|
||||
widget.find('.ajax-feedback').css('visibility', 'visible');
|
||||
|
||||
a = {
|
||||
action: 'save-widget',
|
||||
|
@ -191,12 +186,13 @@ wpWidgets = {
|
|||
widget.remove();
|
||||
wpWidgets.resize();
|
||||
}
|
||||
} else if ( close ) {
|
||||
widget.find('.widget-inside').slideUp('fast', function(){
|
||||
widget.css({'width':'','marginLeft':''});
|
||||
} else {
|
||||
$('.ajax-feedback').css('visibility', 'hidden');
|
||||
if ( r && r.length > 2 ) {
|
||||
$('.widget-content', widget).html(r);
|
||||
wpWidgets.appendTitle(widget);
|
||||
$('.ajax-feedback').css('visibility', 'hidden');
|
||||
});
|
||||
wpWidgets.fixLabels(widget);
|
||||
}
|
||||
}
|
||||
if ( order )
|
||||
wpWidgets.saveOrder();
|
||||
|
@ -230,6 +226,23 @@ wpWidgets = {
|
|||
KhtmlUserSelect: n
|
||||
});
|
||||
},
|
||||
|
||||
fixLabels : function(sc) {
|
||||
sc = sc || document;
|
||||
|
||||
$('.widget-inside label', sc).each(function(){
|
||||
var f = $(this).attr('for');
|
||||
|
||||
if ( f && f == $('input', this).attr('id') )
|
||||
$(this).removeAttr('for');
|
||||
});
|
||||
},
|
||||
|
||||
close : function(widget) {
|
||||
widget.find('.widget-inside').slideUp('fast', function(){
|
||||
widget.css({'width':'','marginLeft':''});
|
||||
});
|
||||
},
|
||||
|
||||
addEvents : function(sc) {
|
||||
sc = sc || document;
|
||||
|
@ -249,11 +262,15 @@ wpWidgets = {
|
|||
return false;
|
||||
});
|
||||
$('.widget-control-save', sc).click(function(){
|
||||
wpWidgets.save( $(this).parents('.widget'), 0, 1, 1, 0 );
|
||||
wpWidgets.save( $(this).parents('.widget'), 0, 1, 0 );
|
||||
return false;
|
||||
});
|
||||
$('.widget-control-remove', sc).click(function(){
|
||||
wpWidgets.save( $(this).parents('.widget'), 1, 1, 1, 0 );
|
||||
wpWidgets.save( $(this).parents('.widget'), 1, 1, 0 );
|
||||
return false;
|
||||
});
|
||||
$('.widget-control-close', sc).click(function(){
|
||||
wpWidgets.close( $(this).parents('.widget') );
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -332,7 +332,7 @@ function wp_default_scripts( &$scripts ) {
|
|||
$scripts->add( 'media-upload', "/wp-admin/js/media-upload$suffix.js", array( 'thickbox' ), '20090114' );
|
||||
$scripts->add_data( 'media-upload', 'group', 1 );
|
||||
|
||||
$scripts->add( 'admin-widgets', "/wp-admin/js/widgets$suffix.js", array( 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable' ), '20090524' );
|
||||
$scripts->add( 'admin-widgets', "/wp-admin/js/widgets$suffix.js", array( 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable' ), '20090530' );
|
||||
$scripts->add_data( 'admin-widgets', 'group', 1 );
|
||||
|
||||
$scripts->add( 'word-count', "/wp-admin/js/word-count$suffix.js", array( 'jquery' ), '20090422' );
|
||||
|
@ -438,7 +438,7 @@ function wp_default_styles( &$styles ) {
|
|||
|
||||
$styles->add( 'global', '/wp-admin/css/global.css', array(), '20090514' );
|
||||
$styles->add( 'media', '/wp-admin/css/media.css', array(), '20090516' );
|
||||
$styles->add( 'widgets', '/wp-admin/css/widgets.css', array(), '20090514' );
|
||||
$styles->add( 'widgets', '/wp-admin/css/widgets.css', array(), '20090530' );
|
||||
$styles->add( 'dashboard', '/wp-admin/css/dashboard.css', array(), '20090514' );
|
||||
$styles->add( 'install', '/wp-admin/css/install.css', array(), '20090514' );
|
||||
$styles->add( 'theme-editor', '/wp-admin/css/theme-editor.css', array(), '20090514' );
|
||||
|
|
|
@ -297,7 +297,7 @@ class WP_Widget {
|
|||
$settings = wp_convert_widget_settings($this->id_base, $this->option_name, $settings);
|
||||
}
|
||||
|
||||
unset($settings['_multiwidget']);
|
||||
unset($settings['_multiwidget'], $settings['__i__']);
|
||||
return $settings;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue