Skip to content
Snippets Groups Projects
Commit f55bd41f authored by Jared Hancock's avatar Jared Hancock
Browse files

Fix initial popup of [Draft Saved]

Instead, only show the box if the draft has been modified since initially
created / updated.
parent eb3b9ba7
Branches
Tags
No related merge requests found
......@@ -44,16 +44,32 @@ class DraftAjaxAPI extends AjaxController {
}
function _updateDraft($draft) {
$field_list = array('response', 'note', 'answer', 'body',
'message', 'issue');
foreach ($field_list as $field) {
if (isset($_POST[$field])) {
$body = urldecode($_POST[$field]);
break;
if (isset($_POST['name'])) {
$parts = array();
if (preg_match('`(\w+)\[(\w+)\]`', $_POST['name'], $parts)) {
$body = urldecode($_POST[$parts[1]][$parts[2]]);
}
else {
$body = urldecode($_POST[$_POST['name']]);
}
}
else {
$field_list = array('response', 'note', 'answer', 'body',
'message', 'issue');
foreach ($field_list as $field) {
if (isset($_POST[$field])) {
$body = urldecode($_POST[$field]);
break;
}
}
}
if (!isset($body))
return Http::response(422, "Draft body not found in request");
return JsonDataEncoder::encode(array(
'error' => array(
'message' => "Draft body not found in request",
'code' => 422,
)
));
if (!$draft->setBody($body))
return Http::response(500, "Unable to update draft body");
......@@ -227,8 +243,15 @@ class DraftAjaxAPI extends AjaxController {
'namespace' => $namespace,
);
if (isset($_POST['name']))
$vars['body'] = urldecode($_POST[$_POST['name']]);
if (isset($_POST['name'])) {
$parts = array();
if (preg_match('`(\w+)\[(\w+)\]`', $_POST['name'], $parts)) {
$vars['body'] = urldecode($_POST[$parts[1]][$parts[2]]);
}
else {
$vars['body'] = urldecode($_POST[$_POST['name']]);
}
}
return self::_createDraft($vars);
}
......
......@@ -145,8 +145,7 @@ class Draft extends VerySimpleModel {
* closing a ticket, the staff_id should be left null so that all drafts
* are cleaned up.
*/
/* static */
function deleteForNamespace($namespace, $staff_id=false) {
static function deleteForNamespace($namespace, $staff_id=false) {
$sql = 'DELETE attach FROM '.ATTACHMENT_TABLE.' attach
INNER JOIN '.DRAFT_TABLE.' draft
ON (attach.object_id = draft.id AND attach.`type`=\'D\')
......@@ -156,11 +155,10 @@ class Draft extends VerySimpleModel {
if (!db_query($sql))
return false;
$sql = 'DELETE FROM '.DRAFT_TABLE
.' WHERE `namespace` LIKE '.db_input($namespace);
$criteria = array('namespace__like'=>$namespace);
if ($staff_id)
$sql .= ' AND staff_id='.db_input($staff_id);
return (!db_query($sql) || !db_affected_rows());
$criteria['staff_id'] = $staff_id;
return static::objects()->filter($criteria)->delete();
}
static function cleanup() {
......
......@@ -81,7 +81,8 @@ RedactorPlugins.draft = {
}
// Only show the [Draft Saved] notice if there is content in the
// field that has been touched
if (!this.opts.draftOriginal || this.opts.draftOriginal == this.get()) {
if (!this.firstSave) {
this.firstSave = true;
// No change yet — dont't show the button
return;
}
......@@ -120,7 +121,7 @@ RedactorPlugins.draft = {
type: 'delete',
async: false,
success: function() {
self.draft_id = this.opts.draftId = undefined;
self.draft_id = self.opts.draftId = undefined;
self.hideDraftSaved();
self.set(self.opts.draftOriginal || '', false, false);
self.opts.autosave = self.opts.autoCreateUrl;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment