<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[GlotPress][891] trunk: Add bulk setting for priority.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="https://glotpress.trac.wordpress.org/changeset/891">891</a></dd>
<dt>Author</dt> <dd>markoheijnen</dd>
<dt>Date</dt> <dd>2014-05-06 17:38:26 +0000 (Tue, 06 May 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Add bulk setting for priority. Props yoavf
Fixes <a href="http://glotpress.trac.wordpress.org/ticket/134">#134</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkgpincludesroutestranslationphp">trunk/gp-includes/routes/translation.php</a></li>
<li><a href="#trunkgptemplatestranslationsphp">trunk/gp-templates/translations.php</a></li>
<li><a href="#trunkjstranslationspagejs">trunk/js/translations-page.js</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkgpincludesroutestranslationphp"></a>
<div class="modfile"><h4>Modified: trunk/gp-includes/routes/translation.php (890 => 891)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/gp-includes/routes/translation.php 2014-05-06 08:41:08 UTC (rev 890)
+++ trunk/gp-includes/routes/translation.php 2014-05-06 17:38:26 UTC (rev 891)
</span><span class="lines">@@ -183,9 +183,14 @@
</span><span class="cx">
</span><span class="cx"> $bulk = gp_post('bulk');
</span><span class="cx"> $bulk['row-ids'] = array_filter( explode( ',', $bulk['row-ids'] ) );
</span><del>- if ( !empty( $bulk['row-ids'] ) ) {
- if ( 'approve' == $bulk['action'] || 'reject' == $bulk['action'] ) {
- $this->_bulk_approve( $project, $locale, $translation_set, $bulk );
</del><ins>+ if ( ! empty( $bulk['row-ids'] ) ) {
+ switch( $bulk['action'] ) {
+ case 'approve':
+ case 'reject' :
+ $this->_bulk_approve( $project, $locale, $translation_set, $bulk );
+ break;
+ case 'set-priority':
+ $this->_bulk_set_priority( $project, $locale, $translation_set, $bulk );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> do_action( 'gp_translation_set_bulk_action_post', $project, $locale, $translation_set, $bulk );
</span><span class="lines">@@ -208,7 +213,7 @@
</span><span class="cx"> $ok = $error = 0;
</span><span class="cx"> $new_status = 'approve' == $action? 'current' : 'rejected';
</span><span class="cx"> foreach( $bulk['row-ids'] as $row_id ) {
</span><del>- $translation_id = gp_array_get( split( '-', $row_id ), 1 );
</del><ins>+ $translation_id = gp_array_get( explode( '-', $row_id ), 1 );
</ins><span class="cx"> $translation = GP::$translation->get( $translation_id );
</span><span class="cx"> if ( !$translation ) continue;
</span><span class="cx"> if ( $translation->set_status( $new_status ) )
</span><span class="lines">@@ -247,6 +252,49 @@
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ function _bulk_set_priority( $project, $locale, $translation_set, $bulk ) {
+
+ if ( $this->cannot_and_redirect( 'write', 'project', $project->id ) ){
+ return;
+ }
+
+ $ok = $error = 0;
+ foreach( $bulk['row-ids'] as $row_id ) {
+ $original_id = gp_array_get( explode( '-', $row_id ), 0 );
+ $original = GP::$original->get( $original_id );
+
+ if ( ! $original ) {
+ continue;
+ }
+
+ $original->priority = $bulk['priority'];
+
+ if ( ! $original->validate() ) {
+ $this->die_with_error( 'Invalid priority value!' );
+ }
+
+ if ( ! $original->save() ) {
+ $error++;
+ } else {
+ $ok ++;
+ }
+ }
+
+ if ( 0 === $error) {
+ $this->notices[] = sprintf( _n( 'Priority of one original modified.', 'Priority of %d originals modified.', $ok ), $ok );
+ } else {
+ if ( $ok > 0 ) {
+ $message = sprintf( _n( 'Error modifying priority of one original.', 'Error modifying priority of %d originals.', $error ), $error );
+ $message.= sprintf( _n( 'The remaining original was modified successfully.', 'The remaining %d originals were modified successfully.', $ok ), $ok );
+
+ $this->errors[] = $message;
+ } else {
+ $this->errors[] = sprintf( _n( 'Error modifying priority of the original.', 'Error modifying priority of all %d originals.', $error ), $error );
+ }
+ }
+
+ }
+
</ins><span class="cx"> function discard_warning( $project_path, $locale_slug, $translation_set_slug ) {
</span><span class="cx"> return $this->edit_single_translation( $project_path, $locale_slug, $translation_set_slug, array( $this, 'discard_warning_edit_function' ) );
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkgptemplatestranslationsphp"></a>
<div class="modfile"><h4>Modified: trunk/gp-templates/translations.php (890 => 891)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/gp-templates/translations.php 2014-05-06 08:41:08 UTC (rev 890)
+++ trunk/gp-templates/translations.php 2014-05-06 17:38:26 UTC (rev 891)
</span><span class="lines">@@ -30,12 +30,25 @@
</span><span class="cx"> <?php if ( $can_approve ): ?>
</span><span class="cx"> <form id="bulk-actions-toolbar" class="filters-toolbar bulk-actions" action="<?php echo $bulk_action; ?>" method="post">
</span><span class="cx"> <div>
</span><del>- <select name="bulk[action]">
</del><ins>+ <select name="bulk[action]" id="bulk-action">
</ins><span class="cx"> <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option>
</span><span class="cx"> <option value="approve"><?php _e('Approve'); ?></option>
</span><span class="cx"> <option value="reject"><?php _e('Reject'); ?></option>
</span><ins>+ <?php if( $can_write ) : ?>
+ <option value="set-priority"><?php _e('Set Priority'); ?></option>
+ <?php endif; ?>
</ins><span class="cx"> <?php do_action( 'gp_translation_set_bulk_action', $translation_set ); ?>
</span><span class="cx"> </select>
</span><ins>+ <?php if( $can_write ) : ?>
+ <select name="bulk[priority]" id="bulk-priority">
+ <?php
+ foreach( GP::$original->get_static( 'priorities' ) as $value => $label ) {
+ $selected = $value == 'normal' ? " selected='selected'" : '';
+ echo "\t<option value='" . esc_attr( $value ) . "' $selected>" . esc_html( $label ) . "</option>\n";
+ }
+ ?>
+ </select>
+ <?php endif; ?>
</ins><span class="cx"> <input type="hidden" name="bulk[redirect_to]" value="<?php echo esc_attr(gp_url_current()); ?>" id="bulk[redirect_to]" />
</span><span class="cx"> <input type="hidden" name="bulk[row-ids]" value="" id="bulk[row-ids]" />
</span><span class="cx"> <input type="submit" class="button" value="<?php esc_attr_e( 'Apply' ); ?>" />
</span></span></pre></div>
<a id="trunkjstranslationspagejs"></a>
<div class="modfile"><h4>Modified: trunk/js/translations-page.js (890 => 891)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/js/translations-page.js 2014-05-06 08:41:08 UTC (rev 890)
+++ trunk/js/translations-page.js 2014-05-06 17:38:26 UTC (rev 891)
</span><span class="lines">@@ -12,6 +12,15 @@
</span><span class="cx">
</span><span class="cx"> var rows_checked = 0;
</span><span class="cx">
</span><ins>+ $('#bulk-priority').hide();
+ $('#bulk-action').on( 'change', function (e) {
+ var optionSelected = $("option:selected", this);
+ if ( 'set-priority' == optionSelected.val() ) {
+ $('#bulk-priority').show();
+ } else {
+ $('#bulk-priority').hide();
+ }
+ });
</ins><span class="cx"> $('form.filters-toolbar.bulk-actions').submit(function(e) {
</span><span class="cx"> var row_ids = $('input:checked', $('table#translations th.checkbox')).map(function() {
</span><span class="cx"> return $(this).parents('tr.preview').attr('row');
</span><span class="lines">@@ -83,4 +92,5 @@
</span><span class="cx"> return false;
</span><span class="cx"> });
</span><span class="cx"> });
</span><ins>+
</ins><span class="cx"> });
</span></span></pre>
</div>
</div>
</body>
</html>