Skip to content

Commit

Permalink
Need to track deletion of images in HTML editor so that attachment li…
Browse files Browse the repository at this point in the history
…mits are correctly applied
  • Loading branch information
slusarz committed Jun 11, 2014
1 parent 62f75e1 commit 2ee0e61
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
28 changes: 28 additions & 0 deletions imp/js/ckeditor/pasteattachment.js
Expand Up @@ -10,6 +10,8 @@ CKEDITOR.plugins.add('pasteattachment', {

init: function(editor)
{
var active_img = [];

function attachCallback(r)
{
var iframe = editor.getThemeSpace('contents').$.down('IFRAME');
Expand All @@ -19,6 +21,32 @@ CKEDITOR.plugins.add('pasteattachment', {
elt.setAttribute(r.img.related[0], r.img.related[1]);
elt.setAttribute('height', elt.height);
elt.setAttribute('width', elt.width);

/* CKEditor 3 doesn't support onchange event for content
* body. Poll the attached images to detect deletions,
* since this may influence attachment limits. */
if (!active_img.size()) {
new PeriodicalExecuter(function(pe) {
active_img.each(function(a) {
if (!a.parentNode) {
active_img = active_img.without(a);

if (!active_img.size()) {
pe.stop();
DimpCore.doAction(
'deleteAttach',
DimpCompose.actionParams({
atc_indices: Object.toJSON([ a.getAttribute('dropatc_id') ]),
quiet: 1
})
);
}
}
});
}, 2);
}

active_img.push(elt);
} else {
elt.parentNode.removeChild(elt);
}
Expand Down
7 changes: 5 additions & 2 deletions imp/lib/Ajax/Application/Handler/Dynamic.php
Expand Up @@ -753,6 +753,7 @@ public function addressHeader()
* Variables used:
* - atc_indices: (string) [JSON array] Attachment IDs to delete.
* - imp_compose: (string) The IMP_Compose cache identifier.
* - quiet: (boolean) If true, don't output notifications.
*
* @return array The list of attchment IDs that were deleted.
*/
Expand All @@ -766,15 +767,17 @@ public function deleteAttach()
$imp_compose = $injector->getInstance('IMP_Factory_Compose')->create($this->vars->imp_compose);
foreach (json_decode($this->vars->atc_indices) as $val) {
if (isset($imp_compose[$val])) {
$notification->push(sprintf(_("Deleted attachment \"%s\"."), Horde_Mime::decode($imp_compose[$val]->getPart()->getName(true))), 'horde.success');
if (empty($this->vars->quiet)) {
$notification->push(sprintf(_("Deleted attachment \"%s\"."), Horde_Mime::decode($imp_compose[$val]->getPart()->getName(true))), 'horde.success');
}
unset($imp_compose[$val]);
$result[] = $val;
$this->_base->queue->compose($imp_compose);
}
}
}

if (empty($result)) {
if (empty($result) && empty($this->vars->quiet)) {
$notification->push(_("At least one attachment could not be deleted."), 'horde.error');
}

Expand Down

0 comments on commit 2ee0e61

Please sign in to comment.