PHRAS-2978 #comment update feedback expiration date #time 6h

This commit is contained in:
Harrys Ravalomanana
2020-03-17 15:34:24 +04:00
parent 9c87ba5504
commit fbc4e01ef3
4 changed files with 74 additions and 10 deletions

View File

@@ -600,6 +600,38 @@ class PushController extends Controller
);
}
public function updateExpirationAction(Request $request)
{
$ret = [
'success' => false,
'message' => $this->app->trans('Unable to save the expiration date')
];
if (is_null($request->request->get('date'))) {
$ret['message'] = $this->app->trans('The provided date is null!');
return $this->app->json($ret);
}
$repository = $this->app['repo.baskets'];
$manager = $this->getEntityManager();
$manager->beginTransaction();
try {
$basket = $repository->findUserBasket($request->request->get('basket_id'), $this->app->getAuthenticatedUser(), true);
$date = new \DateTime($request->request->get('date'));
$validation = $basket->getValidation();
if (is_null($validation)) {
return $this->app->json($ret);
}
$validation->setExpires($date);
$manager->persist($validation);
$manager->flush();
$manager->commit();
$ret['message'] = $this->app->trans('Expiration date successfully updated!');
} catch (\Exception $e) {
$ret['message'] = $e->getMessage();
$manager->rollback();
}
return $this->app->json($ret);
}
private function formatUser(User $user)
{
$subtitle = array_filter([$user->getJob(), $user->getCompany()]);
@@ -734,4 +766,5 @@ class PushController extends Controller
{
return $this->app['random.medium'];
}
}

View File

@@ -59,6 +59,9 @@ class Push implements ControllerProviderInterface, ServiceProviderInterface
$controllers->post('/validate/', 'controller.prod.push:validateAction')
->bind('prod_push_validate');
$controllers->post('/update-expiration/', 'controller.prod.push:updateExpirationAction')
->bind('prod_push_do_update_expiration');
$controllers->get('/user/{usr_id}/', 'controller.prod.push:getUserAction')
->assert('usr_id', '\d+');

View File

@@ -11,7 +11,11 @@
<span class="expiredDate">
{% if basket.getValidation() %}
{% set dateExpired = app['date-formatter'].getPrettyString(basket.getValidation().getExpires()) %}
{{ 'workzone:feedback:expiration' | trans }} : {{ dateExpired }}
{% if date(dateExpired) < date() %}
<span>{{ 'workzone:feedback:expiration-closed' | trans }} :</span>
{% else %}
<span>{{ 'workzone:feedback:expiration-open' | trans }} :</span>
{% endif %} {{ dateExpired }}
{% endif %}
</span>
<div style="margin:5px 0;max-height:160px;overflow:hidden;text-overflow:ellipsis;">

View File

@@ -1,4 +1,4 @@
<script src="https://rawgithub.com/trentrichardson/jQuery-Timepicker-Addon/master/jquery-ui-timepicker-addon.js"></script>
<div>
<button class="tools-accordion">Actions</button>
<div class="tools-panel">
@@ -101,13 +101,19 @@
{% set dateExpired = app['date-formatter'].getPrettyString(basket.getValidation().getExpires()) %}
<div class="expiredDate">
<span>{{ 'workzone:feedback:expiration' | trans }} :</span>
{% if date(dateExpired) < date() %}
<span>{{ 'workzone:feedback:expiration-closed' | trans }} :</span>
{% else %}
<span>{{ 'workzone:feedback:expiration-open' | trans }} :</span>
{% endif %}
<form class="update-feed-validation">
<input type="hidden" name="feedback-id" value={{ basket.getValidation().getId}} />
<input type="hidden" name="feedback-deadline-format" class="alternate" />
<input type="text" class="btn datepicker" name="feedback-deadline" value="{{ dateExpired }}">
<input type="hidden" name="feedbackId" value={{ basket.getId}} />
<input type="hidden" name="feedbackDate" class="alternate" />
<input type="text" class="btn feed-datepicker" name="feedback-deadline" value="{{ dateExpired }}">
<button type="submit" class="submit" title="{{ 'workzone:feedback:update' | trans }}"><i class="fa fa-save"></i></button>
</form>
<p class="message text-right" style="opacity: 0;transition: all 0.2s; color: green; display: block; ">{{ 'prod:workzone:basket:updated-message' | trans }}</p>
</div>
{% endif %}
@@ -135,7 +141,24 @@
<script type="text/javascript">
$( ".update-feed-validation" ).on( "submit", function( event ) {
event.preventDefault();
console.log( $( this ).serialize() );
var formData = $(this).serializeArray();
$.ajax({
type: 'POST',
url: '/prod/push/update-expiration/',
data: {
basket_id: formData[0].value,
date: formData[1].value
},
beforeSend: function() {
console.log(formData[0].value);
console.log(formData[1].value);
},
success: function (data) {
$('.message').css('opacity',1);
setTimeout(function(){ $('.message').css('opacity',0); }, 2000);
},
});
});
$( function() {
$.datepicker.regional['default'] = {
@@ -149,11 +172,12 @@
dayNamesMin: [ "D","L","M","M","J","V","S" ],
dateFormat: "d MM yy",
altField: ".alternate",
altFormat: "yy-mm-dd"
altFormat: "yy-mm-dd",
minDate: 0
};
$( ".datepicker" ).datepicker( $.datepicker.regional[ 'default' ]);
$( ".feed-datepicker" ).datepicker( $.datepicker.regional[ 'default' ]);
})
</script>