Skip to content

Commit

Permalink
Merge branch 'event-editor-2nd-try' into v0.11
Browse files Browse the repository at this point in the history
  • Loading branch information
slimndap committed May 29, 2015
2 parents 56ea9e6 + 7256113 commit e45f73e
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 33 deletions.
67 changes: 46 additions & 21 deletions functions/wpt_event_editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ public function add_events_meta_box() {
* @since 0.11
*/
public function enqueue_scripts() {
wp_localize_script( 'wp_theatre_admin', 'wpt_editor_defaults', $this->get_defaults() );
wp_localize_script( 'wp_theatre_admin', 'wpt_event_editor_defaults', $this->get_defaults() );

wp_localize_script(
'wp_theatre_admin',
'wpt_editor_security',
'wpt_event_editor_security',
array(
'nonce' => wp_create_nonce( 'wpt_editor_nonce' ),
'nonce' => wp_create_nonce( 'wpt_event_editor_nonce' ),
)
);
}
Expand All @@ -67,7 +67,7 @@ public function enqueue_scripts() {
*/
public function delete_event_over_ajax() {

check_ajax_referer( 'wpt_editor_nonce', 'nonce' , true );
check_ajax_referer( 'wpt_event_editor_nonce', 'nonce' , true );

$event_id = $_POST['event_id'];

Expand Down Expand Up @@ -174,7 +174,7 @@ public function get_fields( $event_id = false ) {
'id' => 'enddate',
'title' => __( 'End time', 'wp_theatre' ),
'save' => array(
'callback' => array( $this, 'save_field_enddate' ),
'callback' => array( $this, 'save_enddate' ),
),
),
array(
Expand All @@ -199,7 +199,7 @@ public function get_fields( $event_id = false ) {
'callback' => array( $this, 'get_control_tickets_status_html' ),
),
'save' => array(
'callback' => array( $this, 'save_field_tickets_status' ),
'callback' => array( $this, 'save_tickets_status' ),
),
),
array(
Expand All @@ -224,7 +224,7 @@ public function get_fields( $event_id = false ) {
'description' => __( 'Place extra prices on a new line.', 'wp_theatre' ),
),
'save' => array(
'callback' => array( $this, 'save_field_prices' ),
'callback' => array( $this, 'save_prices' ),
),
),
);
Expand Down Expand Up @@ -562,7 +562,7 @@ private function get_listing_html( $production_id ) {
$html = '';

$args = array(
'status' => 'all',
'status' => array( 'publish', 'draft' ),
'production' => $production_id,
);
$events = $wp_theatre->events->get( $args );
Expand Down Expand Up @@ -780,13 +780,43 @@ public function save_field($field, $event_id) {
call_user_func_array( $field['save']['callback'], array( $field, $event_id ) );
} else {
$value = $_POST[ 'wpt_event_editor_'.$field['id'] ];
$this->save_value( $value, $field, $event_id );
}

}

$value = apply_filters( 'wpt/event_editor/save/field/value/field='.$field['id'], $value, $event_id );
$value = apply_filters( 'wpt/event_editor/save/field/value', $value, $field, $event_id );
/**
* Saves the value for a field to the database.
*
* @since 0.11
* @access protected
* @param mixed $value The value.
* @param array $field The field.
* @param int $event_id The event.
* @param bool $update Whether of not to update an existing value (default: true).
* @return int The ID of the inserted/updated row
*/
protected function save_value($value, $field, $event_id, $update = true) {

/**
* Filter the value of an event field, before it is saved
* to the database.
*
* @since 0.11
* @param mixed $value The value.
* @param array $field The field.
* @param int $event_id The event.
*/
$value = apply_filters( 'wpt/event_editor/save/value/field='.$field['id'], $value, $event_id );
$value = apply_filters( 'wpt/event_editor/save/value', $value, $field, $event_id );

if ( $update ) {
$field_id = update_post_meta( $event_id, $field['id'], $value );
} else {
$field_id = add_post_meta( $event_id, $field['id'], $value );
}

return $field_id;
}

/**
Expand All @@ -797,7 +827,7 @@ public function save_field($field, $event_id) {
* @param int $event_id The event.
* @return void
*/
public function save_field_enddate($field, $event_id) {
public function save_enddate($field, $event_id) {

$defaults = $this->get_defaults();

Expand All @@ -809,7 +839,7 @@ public function save_field_enddate($field, $event_id) {
$value = date( 'Y-m-d H:i', $event_date + $defaults['duration'] );
}

$field_id = update_post_meta( $event_id, $field['id'], $value );
$this->save_value( $value, $field, $event_id );

}

Expand All @@ -821,15 +851,14 @@ public function save_field_enddate($field, $event_id) {
* @param int $event_id The event.
* @return void
*/
public function save_field_prices($field, $event_id) {
public function save_prices($field, $event_id) {

delete_post_meta( $event_id, $field['id'] );

$values = explode( "\n",$_POST[ 'wpt_event_editor_'.$field['id'] ] );

foreach ( $values as $value ) {
$value = apply_filters( 'wpt/event_editor/save/field/prices/value', $value, $field, $event_id );
add_post_meta( $event_id, $field['id'], $value );
$this->save_value( $value, $field, $event_id, false );
}

}
Expand All @@ -842,19 +871,15 @@ public function save_field_prices($field, $event_id) {
* @param int $event_id The event.
* @return void
*/
public function save_field_tickets_status($field, $event_id) {
public function save_tickets_status($field, $event_id) {

$value = $_POST[ 'wpt_event_editor_'.$field['id'] ];

if ( $value == WPT_Event::tickets_status_other ) {
$value = $_POST[ 'wpt_event_editor_'.$field['id'].'_other' ];
}

$value = apply_filters( 'wpt/editor/event/save/field/tickets_status/value', $value, $field, $event_id );

update_post_meta( $event_id, $field['id'], $value );

do_action( 'wpt/event_editor/save/field/tickets_status', $value, $field, $event_id );
$this->save_value( $value, $field, $event_id );

}

Expand Down
4 changes: 2 additions & 2 deletions js/admin.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion raw/coffee/admin.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# @codekit-prepend '../js/jquery.datetimepicker.js'
# @codekit-prepend 'wpt_editor.coffee'
# @codekit-prepend 'wpt_event_editor.coffee'

class wpt_admin_ticketspage
constructor: ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class wpt_editor
class wpt_event_editor
constructor: ->
@init_datetime_inputs()
@init_delete_links()
Expand All @@ -9,30 +9,30 @@ class wpt_editor
@enddate = jQuery '#wpt_event_editor_enddate'

@event_date.datetimepicker
defaultDate: wpt_editor_defaults.event_date
format : wpt_editor_defaults.datetime_format
defaultDate: wpt_event_editor_defaults.event_date
format : wpt_event_editor_defaults.datetime_format
step: 15
onChangeDateTime: (event_date, input) =>
if event_date?
enddate = new Date @enddate.val()
if not @enddate.val() or (enddate < event_date)
enddate = new Date event_date.getTime() + wpt_editor_defaults.duration * 1000
@enddate.val enddate.dateFormat wpt_editor_defaults.datetime_format
enddate = new Date event_date.getTime() + wpt_event_editor_defaults.duration * 1000
@enddate.val enddate.dateFormat wpt_event_editor_defaults.datetime_format

@enddate.datetimepicker
format : wpt_editor_defaults.datetime_format
format : wpt_event_editor_defaults.datetime_format
step: 15

init_delete_links : ->
jQuery('.wpt_event_editor_listing_action_delete').click (e) =>
if confirm wpt_editor_defaults.confirm_delete_message
if confirm wpt_event_editor_defaults.confirm_delete_message
data =
'action': 'wpt_event_editor_delete_event'
'event_id': jQuery(e.currentTarget).parents('tr').data 'event_id'
'nonce': wpt_editor_security.nonce
'nonce': wpt_event_editor_security.nonce
jQuery('.wpt_event_editor_event_listing').load ajaxurl, data, =>
@init_delete_links()
false

jQuery ->
new wpt_editor
new wpt_event_editor

0 comments on commit e45f73e

Please sign in to comment.