added xhr_change and deleted the submit based issue change handler

This commit is contained in:
hyung-hwan 2016-01-18 16:26:14 +00:00
parent f1b31c85dd
commit 93e4bc5320
4 changed files with 224 additions and 127 deletions

View File

@ -176,37 +176,9 @@ class Issue extends Controller
} }
else else
{ {
/*
$change_post = $this->input->post('issue_change'); $change_post = $this->input->post('issue_change');
if ($change_post == 'change') if ($change_post == 'undo')
{
$change = new stdClass();
$change->type = $this->input->post('issue_change_type');
$change->status = $this->input->post('issue_change_status');
$change->owner = $this->input->post('issue_change_owner');
$change->priority = $this->input->post('issue_change_priority');
$change->comment = $this->input->post('issue_change_comment');
if (!$login['sysadmin?'] &&
$this->projects->projectHasMember($project->id, $login['id']) === FALSE)
{
$data['project'] = $project;
$data['message'] = sprintf (
$this->lang->line('MSG_PROJECT_MEMBERSHIP_REQUIRED'), $projectid);
$this->load->view ($this->VIEW_ERROR, $data);
}
else if ($this->issues->change ($login['id'], $project, $id, $change) === FALSE)
{
$data['project'] = $project;
$data['message'] = 'DATABASE ERROR';
$this->load->view ($this->VIEW_ERROR, $data);
}
else
{
redirect ("/issue/show/{$projectid}/{$hexid}");
}
return;
}
else if ($change_post == 'undo')
{ {
if (!$login['sysadmin?'] && if (!$login['sysadmin?'] &&
$this->projects->projectHasMember($project->id, $login['id']) === FALSE) $this->projects->projectHasMember($project->id, $login['id']) === FALSE)
@ -227,7 +199,7 @@ class Issue extends Controller
redirect ("/issue/show/{$projectid}/{$hexid}"); redirect ("/issue/show/{$projectid}/{$hexid}");
} }
return; return;
} }*/
$issue = $this->issues->get ($login['id'], $project, $id); $issue = $this->issues->get ($login['id'], $project, $id);
if ($issue === FALSE) if ($issue === FALSE)
@ -664,6 +636,61 @@ class Issue extends Controller
} }
function xhr_change ($projectid = '', $issueid = '')
{
$this->load->model ('ProjectModel', 'projects');
$this->load->model ('IssueModel', 'issues');
$login = $this->login->getUser ();
if ($login['id'] == '')
{
$status = 'error - anonymous user';
}
else
{
$issueid = $this->converter->HexToAscii ($issueid);
$is_nonmember = FALSE;
$project = $this->projects->get ($projectid);
if ($project === FALSE)
{
$status = "error - failed to get the project {$projectid}";
}
else if ($project === NULL)
{
$status = "error - no such project {$projectid}";
}
else if (!$login['sysadmin?'] &&
$this->projects->projectHasMember($projectid, $login['id']) === FALSE &&
($is_nonmember = $this->issues->isIssueCreatedBy($projectid, $issueid, $login['id'])) === FALSE)
{
$status = "error - not a member nor a creator - {$login['id']}";
}
else
{
$change = new stdClass();
$change->type = $this->input->post('issue_change_type');
$change->status = $this->input->post('issue_change_status');
$change->owner = $this->input->post('issue_change_owner');
$change->priority = $this->input->post('issue_change_priority');
$change->comment = $this->input->post('issue_change_comment');
if ($this->issues->change ($login['id'], $project, $issueid, $change, $is_nonmember) === FALSE)
{
$status = 'error - ' . $this->issues->getErrorMessage();
}
else
{
$status = 'ok';
}
}
}
print $status;
}
function xhr_edit_comment ($projectid = '', $issueid = '') function xhr_edit_comment ($projectid = '', $issueid = '')
{ {
$this->load->model ('ProjectModel', 'projects'); $this->load->model ('ProjectModel', 'projects');

View File

@ -313,11 +313,11 @@ class IssueModel extends Model
return $issue->id; return $issue->id;
} }
function change ($userid, $project, $id, $change) function change ($userid, $project, $id, $change, $disallow_state_change)
{ {
$now = codepot_nowtodbdate(); $now = codepot_nowtodbdate();
$this->db->trans_start (); $this->db->trans_begin ();
$this->db->where ('projectid', $project->id); $this->db->where ('projectid', $project->id);
$this->db->where ('id', $id); $this->db->where ('id', $id);
@ -325,13 +325,54 @@ class IssueModel extends Model
$query = $this->db->get ('issue_change'); $query = $this->db->get ('issue_change');
if ($this->db->trans_status() === FALSE) if ($this->db->trans_status() === FALSE)
{ {
$this->db->trans_complete (); $this->errmsg = $this->db->_error_message();
$this->db->trans_rollback ();
return FALSE; return FALSE;
} }
$result = $query->result(); $result = $query->result();
$maxsno = (empty($result) || $result[0] == NULL)? 0: $result[0]->maxsno; $maxsno = (empty($result) || $result[0] == NULL)? 0: $result[0]->maxsno;
$newsno = $maxsno + 1; $newsno = $maxsno + 1;
if ($change->comment == '' || $disallow_state_change)
{
$this->db->where ('projectid', $project->id);
$this->db->where ('id', $id);
$this->db->where ('sno', $maxsno);
$this->db->select('type,status,owner,priority');
$query = $this->db->get ('issue_change');
if ($this->db->trans_status() === FALSE)
{
$this->errmsg = $this->db->_error_message();
$this->db->trans_rollback ();
return FALSE;
}
$result = $query->result();
if (!empty($result))
{
$c = $result[0];
if ($c->type == $change->type &&
$c->status == $change->status &&
$c->owner == $change->owner &&
$c->priority == $change->priority)
{
if ($change->comment == '')
{
$this->errmsg = 'empty comment but no state change in the input';
$this->db->trans_rollback ();
return FALSE;
}
}
else if ($disallow_state_change)
{
$this->errmsg = 'state change disallowed';
$this->db->trans_rollback ();
return FALSE;
}
}
}
$this->db->set ('projectid', $project->id); $this->db->set ('projectid', $project->id);
$this->db->set ('id', $id); $this->db->set ('id', $id);
$this->db->set ('sno', $newsno); $this->db->set ('sno', $newsno);
@ -345,6 +386,12 @@ class IssueModel extends Model
$this->db->set ('updatedon', $now); $this->db->set ('updatedon', $now);
$this->db->set ('updatedby', $userid); $this->db->set ('updatedby', $userid);
$this->db->insert ('issue_change'); $this->db->insert ('issue_change');
if ($this->db->trans_status() === FALSE)
{
$this->errmsg = $this->db->_error_message();
$this->db->trans_rollback ();
return FALSE;
}
$this->db->where ('projectid', $project->id); $this->db->where ('projectid', $project->id);
$this->db->where ('id', $id); $this->db->where ('id', $id);
@ -355,6 +402,12 @@ class IssueModel extends Model
$this->db->set ('updatedon', $now); $this->db->set ('updatedon', $now);
$this->db->set ('updatedby', $userid); $this->db->set ('updatedby', $userid);
$this->db->update ('issue'); $this->db->update ('issue');
if ($this->db->trans_status() === FALSE)
{
$this->errmsg = $this->db->_error_message();
$this->db->trans_rollback ();
return FALSE;
}
$this->db->set ('createdon', $now); $this->db->set ('createdon', $now);
$this->db->set ('type', 'issue'); $this->db->set ('type', 'issue');
@ -363,10 +416,14 @@ class IssueModel extends Model
$this->db->set ('userid', $userid); $this->db->set ('userid', $userid);
$this->db->set ('message', $id); $this->db->set ('message', $id);
$this->db->insert ('log'); $this->db->insert ('log');
if ($this->db->trans_status() === FALSE)
{
$this->errmsg = $this->db->_error_message();
$this->db->trans_rollback ();
return FALSE;
}
$this->db->trans_complete (); $this->db->trans_commit ();
if ($this->db->trans_status() === FALSE) return FALSE;
return $id; return $id;
} }

View File

@ -685,20 +685,61 @@ $(function () {
width: '85%', width: '85%',
buttons: { buttons: {
'<?php print $this->lang->line('OK')?>': function () { '<?php print $this->lang->line('OK')?>': function () {
var comment = $('#issue_change_comment'); if (work_in_progress) return;
if (comment.val().trim().length <= 0)
if (!!window.FormData)
{ {
comment.addClass ('ui-state-error'); // FormData is supported
setTimeout (function () { work_in_progress = true;
comment.removeClass ('ui-state-error', 500);
}, 500); var form_data = new FormData();
form_data.append ('issue_change_type', $('#issue_change_type').val());
form_data.append ('issue_change_status', $('#issue_change_status').val());
form_data.append ('issue_change_priority', $('#issue_change_priority').val());
form_data.append ('issue_change_owner', $('#issue_change_owner').val());
form_data.append ('issue_change_comment', $('#issue_change_comment').val());
$('#issue_show_change_form').dialog('disable');
$.ajax({
url: codepot_merge_path('<?php print site_url() ?>', '<?php print "/issue/xhr_change/{$project->id}/{$hex_issue_id}"; ?>'),
type: 'POST',
data: form_data,
mimeType: 'multipart/form-data',
contentType: false,
processData: false,
cache: false,
success: function (data, textStatus, jqXHR) {
work_in_progress = false;
$('#issue_show_change_form').dialog('enable');
$('#issue_show_change_form').dialog('close');
if (data == 'ok')
{
// refresh the page to the head revision
$(location).attr ('href', codepot_merge_path('<?php print site_url(); ?>', '<?php print "/issue/show/{$project->id}/{$hex_issue_id}"; ?>'));
}
else
{
show_alert ('<pre>' + codepot_htmlspecialchars(data) + '</pre>', "<?php print $this->lang->line('Error')?>");
}
},
error: function (jqXHR, textStatus, errorThrown) {
work_in_progress = false;
$('#issue_show_change_form').dialog('enable');
$('#issue_show_change_form').dialog('close');
show_alert ('Failed - ' + errorThrown, "<?php print $this->lang->line('Error')?>");
}
});
} }
else else
{ {
$(this).dialog('close'); show_alert ('<pre>NOT SUPPORTED</pre>', "<?php print $this->lang->line('Error')?>");
$('#issue_change').val ('change');
$('#issue_change_form').submit ();
} }
}, },
'<?php print $this->lang->line('Cancel')?>': function () { '<?php print $this->lang->line('Cancel')?>': function () {
$(this).dialog('close'); $(this).dialog('close');
@ -1035,18 +1076,16 @@ function print_issue_state ($con, $issue, $old, $issue_type_array, $issue_status
$new = $issue->changes[0]; $new = $issue->changes[0];
print '<div id="issue_show_change_start" class="codepot-issue-start">'; print '<div id="issue_show_change_start" class="codepot-issue-start">';
print '<div class="codepot-issue-change">'; print '<div class="codepot-issue-start-topline">';
print '<div class="codepot-issue-change-topline">'; printf ('<div class="codepot-issue-change-date">%s</div>', codepot_dbdatetodispdate($new->updatedon));
printf ('<div class="codepot-issue-change-date">%s</div>', codepot_dbdatetodispdate($new->updatedon)); print '<div class="codepot-issue-comment-updater">';
print '<div class="codepot-issue-comment-updater">'; $user_icon_url = codepot_merge_path (site_url(), '/user/icon/' . $this->converter->AsciiToHex($new->updatedby));
$user_icon_url = codepot_merge_path (site_url(), '/user/icon/' . $this->converter->AsciiToHex($new->updatedby)); print "<img src='{$user_icon_url}' class='codepot-committer-icon-24x24' /> ";
print "<img src='{$user_icon_url}' class='codepot-committer-icon-24x24' /> "; print htmlspecialchars($new->updatedby);
print htmlspecialchars($new->updatedby);
print '</div>';
print '<div class="codepot-issue-comment-actions"></div>';
print '<div style="clear: both;"></div>';
print '</div>'; print '</div>';
print '<div class="codepot-issue-comment-actions"></div>';
print '<div style="clear: both;"></div>';
print '</div>'; print '</div>';
print '<ul id="issue_show_change_start_list" class="codepot-issue-horizontal-list">'; print '<ul id="issue_show_change_start_list" class="codepot-issue-horizontal-list">';
@ -1181,81 +1220,53 @@ function print_issue_state ($con, $issue, $old, $issue_type_array, $issue_status
<div id="issue_show_change_form"> <div id="issue_show_change_form">
<?php print form_open("issue/show/{$project->id}/{$hex_issue_id}/", 'id="issue_change_form"')?> <div>
<input type='hidden' name='issue_change' id='issue_change' value='change' />
<div>
<?php print form_label ($this->lang->line('Type'),
'issue_change_type')
?>
<?php print form_dropdown('issue_change_type',
$issue_type_array,
set_value('issue_change_type', $issue->type),
'id="issue_change_type"')
?>
<?php print form_label ($this->lang->line('Status'),
'issue_change_status')
?>
<?php print form_dropdown('issue_change_status',
$issue_status_array,
set_value('issue_change_status', $issue->status),
'id="issue_change_status"')
?>
<?php print form_label ($this->lang->line('Priority'),
'issue_change_priority')
?>
<?php print form_dropdown (
'issue_change_priority',
$issue_priority_array,
set_value('issue_change_priority', $issue->priority),
'id="issue_change_priority"')
?>
</div>
<div>
<?php <?php
print form_label ($this->lang->line('Owner'), 'issue_change_owner'); print form_label ($this->lang->line('Type'), 'issue_change_type');
print form_dropdown('issue_change_type', $issue_type_array, set_value('issue_change_type', $issue->type), 'id="issue_change_type"');
$owner_array = array (); print ' ';
$found = FALSE; print form_label ($this->lang->line('Status'), 'issue_change_status');
foreach ($project->members as $t) print form_dropdown('issue_change_status', $issue_status_array, set_value('issue_change_status', $issue->status), 'id="issue_change_status"');
{
if ($issue->owner == $t) $found = TRUE;
$owner_array[$t] = $t;
}
if ($found === FALSE) $owner_array[$issue->owner] = $issue->owner;
print form_dropdown ( print ' ';
'issue_change_owner', print form_label ($this->lang->line('Priority'), 'issue_change_priority');
$owner_array, print form_dropdown ('issue_change_priority', $issue_priority_array, set_value('issue_change_priority', $issue->priority), 'id="issue_change_priority"');
set_value('issue_change_owner', $issue->owner),
'id="issue_change_owner"');
?>
</div>
<div> print ' ';
<?php print form_label ($this->lang->line('Comment'), 'issue_change_comment')?> print form_label ($this->lang->line('Owner'), 'issue_change_owner');
<a href='#' id='issue_change_comment_preview_button'><?php print $this->lang->line('Preview')?></a> $owner_array = array ();
</div> $found = FALSE;
<div> foreach ($project->members as $t)
<?php {
$xdata = array ( if ($issue->owner == $t) $found = TRUE;
'name' => 'issue_change_comment', $owner_array[$t] = $t;
'value' => set_value ('issue_change_comment', ''), }
'id' => 'issue_change_comment', if ($found === FALSE) $owner_array[$issue->owner] = $issue->owner;
'rows' => 10,
'cols' => 80 print form_dropdown ('issue_change_owner', $owner_array, set_value('issue_change_owner', $issue->owner), 'id="issue_change_owner"');
); ?>
print form_textarea ($xdata); </div>
?>
</div> <div>
<?php print form_label ($this->lang->line('Comment'), 'issue_change_comment')?>
<a href='#' id='issue_change_comment_preview_button'><?php print $this->lang->line('Preview')?></a>
</div>
<div>
<?php
$xdata = array (
'name' => 'issue_change_comment',
'value' => set_value ('issue_change_comment', ''),
'id' => 'issue_change_comment',
'rows' => 10,
'cols' => 80
);
print form_textarea ($xdata);
?>
</div>
<div id='issue_change_comment_preview' class='codepot-styled-text-preview'></div>
<div id='issue_change_comment_preview' class='codepot-styled-text-preview'></div>
<?php print form_close()?>
</div> <!-- issue_show_change_form --> </div> <!-- issue_show_change_form -->

View File

@ -11,7 +11,8 @@ ul.codepot-issue-horizontal-list li {
float: left; float: left;
} }
.codepot-issue-change ul.codepot-issue-horizontal-list { .codepot-issue-start ul.codepot-issue-horizontal-list,
.codepot-issue-change ul.codepot-issue-horizontal-list {
padding: 0.3em 0 0.3em 0; padding: 0.3em 0 0.3em 0;
} }
@ -21,11 +22,12 @@ ul.codepot-issue-horizontal-list li {
} }
.codepot-issue-change { .codepot-issue-change {
border-top: 1px solid #cccccc; border-top: 1px dashed #EAEAEA;
} }
.codepot-issue-start-topline,
.codepot-issue-change-topline { .codepot-issue-change-topline {
background-color: #EEEEEE; background-color: #F5F5F5;
padding: 0.3em; padding: 0.3em;
-moz-border-radius: 3px; -moz-border-radius: 3px;