diff --git a/include/class.canned.php b/include/class.canned.php index 31c8bf773f6d08a0059a9171b01ab366f3154c2d..5a396b8bd2d8b7284cdfb69ab3f01d88385f8340 100644 --- a/include/class.canned.php +++ b/include/class.canned.php @@ -104,6 +104,16 @@ class Canned { return $this->_filters; } + function getAttachedFiles($inlines=false) { + return AttachmentFile::objects() + ->filter(array( + 'attachments__type'=>'C', + 'attachments__object_id'=>$this->getId(), + 'attachments__inline' => $inlines, + )) + ->all(); + } + function getNumFilters() { return count($this->getFilters()); } @@ -148,11 +158,18 @@ class Canned { if ($cb && is_callable($cb)) $resp = $cb($resp); - $resp['files'] = $this->attachments->getSeparates(); + $resp['files'] = array(); + foreach ($this->getAttachedFiles(!$html) as $file) { + $resp['files'][] = array( + 'id' => $file->id, + 'name' => $file->name, + 'size' => $file->size, + 'download_url' => $file->getDownloadUrl(), + ); + } // strip html if (!$html) { $resp['response'] = Format::html2text($resp['response'], 90); - $resp['files'] += $this->attachments->getInlines(); } return Format::json_encode($resp); break; diff --git a/include/staff/cannedresponse.inc.php b/include/staff/cannedresponse.inc.php index 518ad1165310fbf99ee148e5d259c6146e782677..407c5ba89466beb080c2356f7aa8113546bce33b 100644 --- a/include/staff/cannedresponse.inc.php +++ b/include/staff/cannedresponse.inc.php @@ -93,10 +93,10 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); </div> <?php $attachments = $canned_form->getField('attachments'); - if ($canned && ($files=$canned->attachments->getSeparates())) { + if ($canned && ($files=$canned->getAttachedFiles())) { $ids = array(); foreach ($files as $f) - $ids[] = $f['id']; + $ids[] = $f->id; $attachments->value = $ids; } print $attachments->render(); ?> diff --git a/scp/js/scp.js b/scp/js/scp.js index 1dfeefd1d48d7c76b5cefe85c04b8de7db1fe13e..edb2cf0c0ccf6750c3a9b58584ab3b0a1dbd1687 100644 --- a/scp/js/scp.js +++ b/scp/js/scp.js @@ -221,12 +221,12 @@ var scp_prep = function() { redactor = box.data('redactor'); if(canned.response) { if (redactor) - redactor.insertHtml(canned.response); + redactor.insert.html(canned.response); else box.val(box.val() + canned.response); if (redactor) - redactor.observeStart(); + redactor.observe.load(); } //Canned attachments. var ca = $('.attachments', fObj);