Skip to content

Commit

Permalink
Merge pull request #55 from x-team/issue-21
Browse files Browse the repository at this point in the history
Push new metabox to top of the ordering list
  • Loading branch information
frankiejarrett committed Mar 28, 2014
2 parents 424044c + 54153df commit 3ca8df3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
27 changes: 23 additions & 4 deletions includes/meta-boxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public function load_page() {
'title' => sprintf( esc_html__( 'Report %d', 'stream-reports' ), absint( $key + 1 ) ),
'priority' => 'default',
'context' => 'normal',
'chart_type' => 'bar',
'chart_type' => 'line',
);

// Parse default argument
Expand Down Expand Up @@ -183,6 +183,7 @@ public function metabox_content( $object, $section ) {
'data_type' => null,
'data_group' => null,
'selector_type' => '',
'is_new' => false,
)
);

Expand All @@ -194,6 +195,13 @@ public function metabox_content( $object, $section ) {
$args['chart_type'] = 'line';
}

$configure_class = '';
if ( $args['is_new'] ) {
$configure_class = 'stream-reports-expand';
unset( self::$sections[ $key ]['is_new'] );
WP_Stream_Reports_Settings::update_user_option( 'sections', self::$sections );
}

$chart_options = $this->get_chart_options( $args );
$data_types = $this->get_data_types();
$selector_types = $this->get_selector_types();
Expand All @@ -214,9 +222,9 @@ protected function get_chart_options( $args ) {

protected function get_chart_types() {
return array(
'multibar' => 'dashicons-chart-bar',
'pie' => 'dashicons-chart-pie',
'line' => 'dashicons-chart-area',
'pie' => 'dashicons-chart-pie',
'multibar' => 'dashicons-chart-bar',
);
}

Expand Down Expand Up @@ -636,7 +644,18 @@ public function update_metabox_display() {
*/
public function add_metabox() {
// Add a new section
self::$sections[] = array();
self::$sections[] = array(
'is_new' => true,
);

// Push new metabox to top of the display
$new_section_id = 'wp-stream-reports-' . ( count( self::$sections ) - 1 );
$order = get_user_option( 'meta-box-order_stream_page_' . WP_Stream_Reports::REPORTS_PAGE_SLUG );
$normal_order = explode( ',', $order['normal'] );

array_unshift( $normal_order, $new_section_id );
$order['normal'] = join( ',', $normal_order );
update_user_option( get_current_user_id(), 'meta-box-order_stream_page_' . WP_Stream_Reports::REPORTS_PAGE_SLUG, $order, true );

WP_Stream_Reports_Settings::update_user_option_and_redirect( 'sections', self::$sections );
}
Expand Down
7 changes: 4 additions & 3 deletions ui/js/stream-reports.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@

if (_.isFunction($.fn.select2)) {
predefined.select2({
'placeholder': 'Select an Interval to Report',
'allowClear': true
});
}
Expand Down Expand Up @@ -200,10 +199,10 @@

// Configuration toggle
this.$configureBtn.on('click.streamReports', function () {
var $target = $(this), $title,
var $target = $(this), $title;

// Hold parent container
$curPostbox = $target.parents('.postbox');
var $curPostbox = $target.parents('.postbox');

// Get the title of the metabox
$title = $curPostbox.find('.hndle .title');
Expand Down Expand Up @@ -234,6 +233,8 @@
// Show the configure div
$curPostbox.find('.inside .configure').toggleClass('visible');
});

this.$configureDiv.filter( '.stream-reports-expand' ).closest( '.postbox' ).find( '.postbox-title-action a.open-box').click();
},

configureSave: function() {
Expand Down
2 changes: 1 addition & 1 deletion views/meta-box.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="stream-section-wrapper">

<div class="configure">
<div class="configure <?php echo esc_attr( $configure_class ); ?>">

<div class="inside">

Expand Down

0 comments on commit 3ca8df3

Please sign in to comment.