Creating another task stay in the popover

This commit is contained in:
Frederic Guillot
2015-09-05 17:06:01 -04:00
parent ccaf78b348
commit 70d3340cd0
9 changed files with 78 additions and 43 deletions

View File

@@ -7,6 +7,8 @@ New features:
Improvements: Improvements:
* Creating another task stay in the popover (no full page refresh anymore)
Bug fixes: Bug fixes:
* Fix typo in template that prevent the Gitlab oauth link to be displayed * Fix typo in template that prevent the Gitlab oauth link to be displayed

View File

@@ -59,25 +59,29 @@ class Taskcreation extends Base
list($valid, $errors) = $this->taskValidator->validateCreation($values); list($valid, $errors) = $this->taskValidator->validateCreation($values);
if ($valid) { if ($valid && $this->taskCreation->create($values)) {
$this->session->flash(t('Task created successfully.'));
if ($this->taskCreation->create($values)) { $this->afterSave($project, $values);
$this->session->flash(t('Task created successfully.')); }
else {
if (isset($values['another_task']) && $values['another_task'] == 1) { $this->session->flashError(t('Unable to create your task.'));
unset($values['title']);
unset($values['description']);
$this->response->redirect($this->helper->url->to('taskcreation', 'create', $values));
}
else {
$this->response->redirect($this->helper->url->to('board', 'show', array('project_id' => $project['id'])));
}
}
else {
$this->session->flashError(t('Unable to create your task.'));
}
} }
$this->create($values, $errors); $this->create($values, $errors);
} }
private function afterSave(array $project, array &$values)
{
if (isset($values['another_task']) && $values['another_task'] == 1) {
unset($values['title']);
unset($values['description']);
if (! $this->request->isAjax()) {
$this->response->redirect($this->helper->url->to('taskcreation', 'create', $values));
}
}
else {
$this->response->redirect($this->helper->url->to('board', 'show', array('project_id' => $project['id'])));
}
}
} }

View File

@@ -126,11 +126,13 @@ class Taskmodification extends Base
); );
if ($ajax) { if ($ajax) {
$this->response->html($this->template->render('task_modification/edit_task', $params)); $html = $this->template->render('task_modification/edit_task', $params);
} }
else { else {
$this->response->html($this->taskLayout('task_modification/edit_task', $params)); $html = $this->taskLayout('task_modification/edit_task', $params);
} }
$this->response->html($html);
} }
/** /**
@@ -145,24 +147,20 @@ class Taskmodification extends Base
list($valid, $errors) = $this->taskValidator->validateModification($values); list($valid, $errors) = $this->taskValidator->validateModification($values);
if ($valid) { if ($valid && $this->taskModification->update($values)) {
$this->session->flash(t('Task updated successfully.'));
if ($this->taskModification->update($values)) { if ($this->request->isAjax()) {
$this->session->flash(t('Task updated successfully.')); $this->response->redirect($this->helper->url->to('board', 'show', array('project_id' => $task['project_id'])));
if ($this->request->getIntegerParam('ajax')) {
$this->response->redirect($this->helper->url->to('board', 'show', array('project_id' => $task['project_id'])));
}
else {
$this->response->redirect($this->helper->url->to('task', 'show', array('project_id' => $task['project_id'], 'task_id' => $task['id'])));
}
} }
else { else {
$this->session->flashError(t('Unable to update your task.')); $this->response->redirect($this->helper->url->to('task', 'show', array('project_id' => $task['project_id'], 'task_id' => $task['id'])));
} }
} }
else {
$this->edit($values, $errors); $this->session->flashError(t('Unable to update your task.'));
$this->edit($values, $errors);
}
} }
/** /**

View File

@@ -66,7 +66,13 @@ class Response
*/ */
public function redirect($url) public function redirect($url)
{ {
header('Location: '.$url); if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest') {
header('X-Ajax-Redirect: '.$url);
}
else {
header('Location: '.$url);
}
exit; exit;
} }

View File

@@ -67,9 +67,11 @@ class App extends \Core\Base
if (isset($this->session['flash_message'])) { if (isset($this->session['flash_message'])) {
$html = '<div class="alert alert-success alert-fade-out">'.$this->helper->e($this->session['flash_message']).'</div>'; $html = '<div class="alert alert-success alert-fade-out">'.$this->helper->e($this->session['flash_message']).'</div>';
unset($this->session['flash_message']); unset($this->session['flash_message']);
unset($this->session['flash_error_message']);
} }
else if (isset($this->session['flash_error_message'])) { else if (isset($this->session['flash_error_message'])) {
$html = '<div class="alert alert-error">'.$this->helper->e($this->session['flash_error_message']).'</div>'; $html = '<div class="alert alert-error">'.$this->helper->e($this->session['flash_error_message']).'</div>';
unset($this->session['flash_message']);
unset($this->session['flash_error_message']); unset($this->session['flash_error_message']);
} }

View File

@@ -10,8 +10,7 @@
</div> </div>
<?php endif ?> <?php endif ?>
<section id="task-section"> <form id="task-form" method="post" action="<?= $this->url->href('taskcreation', 'save', array('project_id' => $values['project_id'])) ?>" autocomplete="off">
<form method="post" action="<?= $this->url->href('taskcreation', 'save', array('project_id' => $values['project_id'])) ?>" autocomplete="off">
<?= $this->form->csrf() ?> <?= $this->form->csrf() ?>
@@ -81,4 +80,3 @@
<?= t('or') ?> <?= $this->url->link(t('cancel'), 'board', 'show', array('project_id' => $values['project_id']), false, 'close-popover') ?> <?= t('or') ?> <?= $this->url->link(t('cancel'), 'board', 'show', array('project_id' => $values['project_id']), false, 'close-popover') ?>
</div> </div>
</form> </form>
</section>

View File

@@ -1,8 +1,7 @@
<div class="page-header"> <div class="page-header">
<h2><?= t('Edit a task') ?></h2> <h2><?= t('Edit a task') ?></h2>
</div> </div>
<section id="task-section"> <form id="task-form" method="post" action="<?= $this->url->href('taskmodification', 'update', array('task_id' => $task['id'], 'project_id' => $task['project_id'])) ?>" autocomplete="off">
<form method="post" action="<?= $this->url->href('taskmodification', 'update', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'ajax' => $ajax)) ?>" autocomplete="off">
<?= $this->form->csrf() ?> <?= $this->form->csrf() ?>
@@ -63,4 +62,3 @@
<?php endif ?> <?php endif ?>
</div> </div>
</form> </form>
</section>

File diff suppressed because one or more lines are too long

View File

@@ -15,7 +15,8 @@ Popover.prototype.open = function(link) {
$.get(link, function(content) { $.get(link, function(content) {
$("body").append('<div id="popover-container"><div id="popover-content">' + content + '</div></div>'); $("body").append('<div id="popover-container"><div id="popover-content">' + content + '</div></div>');
self.router.dispatch(); self.router.dispatch();
self.app.listen(); self.app.refresh();
self.afterOpen();
}); });
}; };
@@ -48,3 +49,29 @@ Popover.prototype.listen = function() {
$(document).on("click", "#popover-container", this.close.bind(this)); $(document).on("click", "#popover-container", this.close.bind(this));
$(document).on("click", "#popover-content", function(e) { e.stopPropagation(); }); $(document).on("click", "#popover-content", function(e) { e.stopPropagation(); });
}; };
Popover.prototype.afterOpen = function() {
var self = this;
var taskForm = $("#task-form");
if (taskForm) {
taskForm.on("submit", function(e) {
e.preventDefault();
$.ajax({
type: "POST",
url: taskForm.attr("action"),
data: taskForm.serialize(),
success: function(data, textStatus, request) {
if (request.getResponseHeader("X-Ajax-Redirect")) {
window.location = request.getResponseHeader("X-Ajax-Redirect");
}
else {
$("#popover-content").html(data);
self.afterOpen();
}
}
});
});
}
};