Skip to content
Snippets Groups Projects
Commit ba2ef65f authored by Jared Hancock's avatar Jared Hancock Committed by Peter Rotich
Browse files

canned: Fixup canned response insertion by staff

parent c8400d95
Branches
Tags
No related merge requests found
...@@ -104,6 +104,16 @@ class Canned { ...@@ -104,6 +104,16 @@ class Canned {
return $this->_filters; 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() { function getNumFilters() {
return count($this->getFilters()); return count($this->getFilters());
} }
...@@ -148,11 +158,18 @@ class Canned { ...@@ -148,11 +158,18 @@ class Canned {
if ($cb && is_callable($cb)) if ($cb && is_callable($cb))
$resp = $cb($resp); $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 // strip html
if (!$html) { if (!$html) {
$resp['response'] = Format::html2text($resp['response'], 90); $resp['response'] = Format::html2text($resp['response'], 90);
$resp['files'] += $this->attachments->getInlines();
} }
return Format::json_encode($resp); return Format::json_encode($resp);
break; break;
......
...@@ -93,10 +93,10 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); ...@@ -93,10 +93,10 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info);
</div> </div>
<?php <?php
$attachments = $canned_form->getField('attachments'); $attachments = $canned_form->getField('attachments');
if ($canned && ($files=$canned->attachments->getSeparates())) { if ($canned && ($files=$canned->getAttachedFiles())) {
$ids = array(); $ids = array();
foreach ($files as $f) foreach ($files as $f)
$ids[] = $f['id']; $ids[] = $f->id;
$attachments->value = $ids; $attachments->value = $ids;
} }
print $attachments->render(); ?> print $attachments->render(); ?>
......
...@@ -221,12 +221,12 @@ var scp_prep = function() { ...@@ -221,12 +221,12 @@ var scp_prep = function() {
redactor = box.data('redactor'); redactor = box.data('redactor');
if(canned.response) { if(canned.response) {
if (redactor) if (redactor)
redactor.insertHtml(canned.response); redactor.insert.html(canned.response);
else else
box.val(box.val() + canned.response); box.val(box.val() + canned.response);
if (redactor) if (redactor)
redactor.observeStart(); redactor.observe.load();
} }
//Canned attachments. //Canned attachments.
var ca = $('.attachments', fObj); var ca = $('.attachments', fObj);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment