ajax-ify approved transcript editing

This commit is contained in:
John Bintz 2009-09-30 20:45:05 -04:00
parent 2746d66882
commit bb9f29a1fd
6 changed files with 101 additions and 46 deletions

View File

@ -389,6 +389,8 @@ class WhatDidTheySayAdmin {
* @return string|false A string if a message is to be displayed, or false if no message. * @return string|false A string if a message is to be displayed, or false if no message.
*/ */
function handle_update_manage_post_transcripts($info) { function handle_update_manage_post_transcripts($info) {
if (!is_admin()) { $this->is_ajax = true; }
$updated = false; $updated = false;
if (current_user_can('approve_transcriptions')) { if (current_user_can('approve_transcriptions')) {
$approved_transcript_manager = new WDTSApprovedTranscript($info['post_id']); $approved_transcript_manager = new WDTSApprovedTranscript($info['post_id']);
@ -417,9 +419,17 @@ class WhatDidTheySayAdmin {
foreach (array_keys($transcripts_to_delete) as $id) { $queued_transcripts->delete_transcript($id); } foreach (array_keys($transcripts_to_delete) as $id) { $queued_transcripts->delete_transcript($id); }
} }
if (is_admin()) {
$updated = __('Transcripts updated.', 'what-did-they-say'); $updated = __('Transcripts updated.', 'what-did-they-say');
} else {
return;
} }
}
if (is_admin()) {
return $updated; return $updated;
} else {
header('HTTP/1.1 401 Unauthorized');
}
} }
/** /**

View File

@ -11,7 +11,9 @@
'scene_action': '<?php _e('Enter the scene action:', 'what-did-they-say') ?>', 'scene_action': '<?php _e('Enter the scene action:', 'what-did-they-say') ?>',
'dialog_name': '<?php _e('Enter the character name:', 'what-did-they-say') ?>', 'dialog_name': '<?php _e('Enter the character name:', 'what-did-they-say') ?>',
'dialog_direction': '<?php _e('Enter the direction in which the character is speaking:', 'what-did-they-say') ?>', 'dialog_direction': '<?php _e('Enter the direction in which the character is speaking:', 'what-did-they-say') ?>',
'dialog_speech': '<?php _e('Enter what the character is speaking:', 'what-did-they-say') ?>' 'dialog_speech': '<?php _e('Enter what the character is speaking:', 'what-did-they-say') ?>',
'transcripts_updated': '<?php _e('Transcripts updated.', 'what-did-they-say') ?>',
'transcripts_failure': '<?php _e('Transcript update failure!', 'what-did-they-say') ?>'
}; };
WhatDidTheySay.button_labels = { WhatDidTheySay.button_labels = {

View File

@ -0,0 +1,35 @@
<?php if ((count($queued_transcripts_for_user) > 0) && !current_user_can('approve_transcriptions')) { ?>
<h3 style="margin-top: 0.5em"><?php _e('Your Submitted Transcripts:', 'what-did-they-say') ?></h3>
<?php
foreach ($queued_transcripts_for_user as $transcript) {
include(dirname(__FILE__) . '/classes/partials/_display-queued-transcript.inc');
}
?>
<?php } ?>
<?php if (current_user_can('submit_transcriptions')) { ?>
<?php if ($transcript_options->are_new_transcripts_allowed()) { ?>
<h3 class="wdts"><?php _e('Submit a new transcript:', 'what-did-they-say') ?></h3>
<form method="post" id="<?php echo $id = "wdts-" . md5(rand()) ?>">
<input type="hidden" name="wdts[_nonce]" value="<?php echo wp_create_nonce('what-did-they-say') ?>" />
<input type="hidden" name="wdts[module]" value="queue-transcript" />
<input type="hidden" name="wdts[post_id]" value="<?php echo $post->ID ?>" />
<div class="wdts-transcript-editor">
<label>
<?php _e('Language:', 'what-did-they-say') ?>
<select name="wdts[language]">
<?php foreach ($language_options->get_languages() as $code => $info) { ?>
<option value="<?php echo $code ?>"><?php echo $info['name'] ?></option>
<?php } ?>
</select>
</label>
<div class="wdts-button-holder"></div>
<textarea style="height: 200px; width: 99%" name="wdts[transcript]"></textarea>
<input type="submit" value="<?php _e('Submit For Approval', 'what-did-they-say') ?>" />
</div>
</form>
<script type="text/javascript">WhatDidTheySay.setup_transcript_editor('<?php echo $id ?>')</script>
<?php } ?>
<?php } ?>

View File

@ -1,5 +1,3 @@
<input type="hidden" name="wdts[_nonce]" value="<?php echo $nonce ?>" />
<input type="hidden" name="wdts[module]" value="manage-post-transcripts" />
<input type="hidden" name="wdts[post_id]" value="<?php echo $post->ID ?>" /> <input type="hidden" name="wdts[post_id]" value="<?php echo $post->ID ?>" />
<label> <label>
@ -41,6 +39,8 @@
} ?> } ?>
<textarea class="edit-transcript" name="wdts[transcripts][<?php echo $code ?>]" style="display: none; width: 99%; height: 200px"><?php echo $approved_transcript_text ?></textarea> <textarea class="edit-transcript" name="wdts[transcripts][<?php echo $code ?>]" style="display: none; width: 99%; height: 200px"><?php echo $approved_transcript_text ?></textarea>
<?php } ?> <?php } ?>
<input type="button" class="wdts-modify-transcript" value="<?php _e('Update All Transcripts', 'what-did-they-say') ?>" />
<span class="wdts-update-message"></span>
</div> </div>
</div> </div>
<script type="text/javascript"> <script type="text/javascript">

View File

@ -99,7 +99,51 @@ WhatDidTheySay.setup_transcript_editor = function(container) {
button_holder.insert(b); button_holder.insert(b);
}); });
}
// submit button handling
var submit_button = container.select('.wdts-modify-transcript').pop();
var update_message = container.select('.wdts-update-message').pop();
var post_id = $(container.parentNode).select("input[name*=[post_id]]").shift();
if (submit_button && update_message && post_id) {
post_id = post_id.value;
submit_button.observe('click', function(e) {
Event.stop(e);
var parameters = {
'wdts[_nonce]': WhatDidTheySay.nonce,
'wdts[module]': 'manage-post-transcripts',
'wdts[post_id]': post_id
};
container.select('textarea').each(function(t) {
parameters[t.name] = t.value;
});
var update_update_message = function(message) {
update_message.update(message);
update_message.setOpacity(1);
update_message.show();
new Effect.Highlight(update_message, { endcolor: '#DFDFDF'} );
new PeriodicalExecuter(function(pe) {
pe.stop();
new Effect.Fade(update_message, {
from: 1, to: 0, duration: 0.25, afterFinish: function() { update_message.update("") }
});
}, 3);
}
new Ajax.Request(
WhatDidTheySay.ajax_url, {
'method': 'post',
'parameters': parameters,
'onSuccess': function() { update_update_message(WhatDidTheySay.messages.transcripts_updated); },
'onFailure': function() { update_update_message(WhatDidTheySay.messages.transcripts_failure); },
}
);
});
} }
} }
}; };
@ -108,14 +152,10 @@ WhatDidTheySay.setup_transcript_editor = function(container) {
* Set up action buttons for queued transcripts. * Set up action buttons for queued transcripts.
*/ */
WhatDidTheySay.setup_transcript_action_buttons = function(container, approved_editor_container) { WhatDidTheySay.setup_transcript_action_buttons = function(container, approved_editor_container) {
top.console.log(approved_editor_container);
if (container && approved_editor_container) { if (container && approved_editor_container) {
container = $(container); container = $(container);
approved_editor_container = $(approved_editor_container); approved_editor_container = $(approved_editor_container);
top.console.log(approved_editor_container);
var actions_holder = container.select('.queued-transcript-actions').pop(); var actions_holder = container.select('.queued-transcript-actions').pop();
if (actions_holder) { if (actions_holder) {

View File

@ -214,46 +214,14 @@ function the_media_transcript_queue_editor() {
?> ?>
<?php if (current_user_can('approve_transcriptions')) { ?> <?php if (current_user_can('approve_transcriptions')) { ?>
<h3 class="wdts"><?php _e('Manage Transcripts:', 'what-did-they-say') ?></h3> <h3 class="wdts"><?php _e('Manage Transcripts:', 'what-did-they-say') ?></h3>
<form method="post" class="transcript-editor"> <form method="post" id="wdts-<?php echo $id = md5(rand()) ?>">
<?php include(dirname(__FILE__) . '/classes/partials/meta-box.inc') ?> <?php include(dirname(__FILE__) . '/classes/partials/meta-box.inc') ?>
<input type="submit" value="Modify Transcript" />
</form> </form>
<script type="text/javascript">
$('wdts-<?php echo $id ?>').observe('submit', function(e) { Event.stop(e); });
</script>
<?php } ?> <?php } ?>
<?php if ((count($queued_transcripts_for_user) > 0) && !current_user_can('approve_transcriptions')) { ?> <?php include(dirname(__FILE__) . '/classes/partials/_manage-queued-transcripts.inc') ?>
<h3 style="margin-top: 0.5em"><?php _e('Your Submitted Transcripts:', 'what-did-they-say') ?></h3>
<?php
foreach ($queued_transcripts_for_user as $transcript) {
include(dirname(__FILE__) . '/classes/partials/_display-queued-transcript.inc');
}
?>
<?php } ?>
<?php if (current_user_can('submit_transcriptions')) { ?>
<?php if ($transcript_options->are_new_transcripts_allowed()) { ?>
<h3 class="wdts"><?php _e('Submit a new transcript:', 'what-did-they-say') ?></h3>
<form method="post" id="<?php echo $id = "wdts-" . md5(rand()) ?>">
<input type="hidden" name="wdts[_nonce]" value="<?php echo wp_create_nonce('what-did-they-say') ?>" />
<input type="hidden" name="wdts[module]" value="queue-transcript" />
<input type="hidden" name="wdts[post_id]" value="<?php echo $post->ID ?>" />
<div class="wdts-transcript-editor">
<label>
<?php _e('Language:', 'what-did-they-say') ?>
<select name="wdts[language]">
<?php foreach ($language_options->get_languages() as $code => $info) { ?>
<option value="<?php echo $code ?>"><?php echo $info['name'] ?></option>
<?php } ?>
</select>
</label>
<div class="wdts-button-holder"></div>
<textarea style="height: 200px; width: 99%" name="wdts[transcript]"></textarea>
<input type="submit" value="<?php _e('Submit For Approval', 'what-did-they-say') ?>" />
</div>
</form>
<script type="text/javascript">WhatDidTheySay.setup_transcript_editor('<?php echo $id ?>')</script>
<?php } ?>
<?php } ?>
<?php } <?php }
} }