Skip to content

Commit

Permalink
[mms] Fix handling image attachments when added via the HTML editor I…
Browse files Browse the repository at this point in the history
…mage dialog.
  • Loading branch information
slusarz committed Jun 28, 2014
1 parent 8d65ee3 commit ba5e8e1
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 42 deletions.
8 changes: 5 additions & 3 deletions imp/docs/CHANGES
Expand Up @@ -2,11 +2,13 @@
v6.2.0-git
----------

[mms] Fix handling image attachments when added via the HTML editor Image
dialog.


------
v6.2.0
------
-----------
v6.2.0beta3
-----------

[mms] Fix saving attachments to sent-mail message in smartmobile view (Bug
#13257).
Expand Down
70 changes: 70 additions & 0 deletions imp/js/ckeditor/imagepoll.js
@@ -0,0 +1,70 @@
/**
* Utility object used to poll for deletion of image (attachment) data.
*
* CKEditor 3 doesn't support onchange event for content body.
* Instead, poll the attached images to detect deletions, since this may
* influence attachment limits.
*
* @author Michael Slusarz <slusarz@horde.org>
* @copyright 2014 Horde LLC
* @license GPL-2 (http://www.horde.org/licenses/gpl)
*/

var IMP_Ckeditor_Imagepoll = {};
// 'related_attr' property set in IMP_Script_Package_ComposeBase

(function (ob) {

var active = [];

ob.add = function(elt)
{
if (!active.size()) {
new PeriodicalExecuter(function(pe) {
var del = [];

active.each(function(a) {
if (!a.parentNode) {
del.push(a);
}
});

if (del.size()) {
ob.remove(del);

// Array.without() doesn't support array input.
active = active.findAll(function(v) {
return !del.include(v);
});

if (!active.size()) {
pe.stop();
}
}
}, 2);
}

active.push(elt);
};

ob.remove = function(elts)
{
var ids = [];

elts.invoke('getAttribute', ob.related_attr).compact().each(function(r) {
var s = r.split(';', 2);
ids.push(s[1]);
});

if (ids.size()) {
DimpCore.doAction(
'deleteAttach',
DimpCompose.actionParams({
atc_indices: Object.toJSON(ids),
quiet: 1
})
);
}
};

}(IMP_Ckeditor_Imagepoll));
23 changes: 17 additions & 6 deletions imp/js/ckeditor/imageupload.js
Expand Up @@ -15,12 +15,6 @@ document.observe('dom:loaded', function() {
upload = definition.getContents('Upload');

rf = upload.add({
commit: function(type, element, internalCommit) {
if (type == 1 && rf.attrdata) {
element.setAttributes(rf.attrdata);
delete rf.attrdata;
}
},
hidden: true,
id: 'related_fields',
type: 'text'
Expand All @@ -32,6 +26,7 @@ document.observe('dom:loaded', function() {
upload.get('uploadButton').filebrowser = {
action: 'QuickUpload',
onSelect: function(fileUrl, data) {
delete rf.attrdata;
if (!Object.isString(data)) {
rf.attrdata = data;
}
Expand All @@ -51,6 +46,22 @@ document.observe('dom:loaded', function() {
style: 'display:inline-block;margin-top:10px;',
type: 'button'
}, 'browse');

definition.dialog.on('cancel', function(ev2) {
if (rf.attrdata) {
IMP_Ckeditor_Imagepoll.remove([
new CKEDITOR.dom.element('IMG').writeAttribute(rf.attrdata)
]);
}
});

definition.dialog.on('hide', function(ev2) {
var elt = new CKEDITOR.dom.element(ev2.sender.imageElement.$);
if (elt.isVisible()) {
elt.setAttributes(rf.attrdata);
IMP_Ckeditor_Imagepoll.add(elt.$);
}
});
}
});
});
29 changes: 1 addition & 28 deletions imp/js/ckeditor/pasteattachment.js
Expand Up @@ -10,8 +10,6 @@ CKEDITOR.plugins.add('pasteattachment', {

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

function attachCallback(r)
{
var iframe = editor.getThemeSpace('contents').$.down('IFRAME');
Expand All @@ -21,32 +19,7 @@ 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);
IMP_Ckeditor_Imagepoll.add(elt);
} else {
elt.parentNode.removeChild(elt);
}
Expand Down
4 changes: 4 additions & 0 deletions imp/lib/Script/Package/ComposeBase.php
Expand Up @@ -36,6 +36,10 @@ public function __construct()
switch ($registry->getView()) {
case $registry::VIEW_DYNAMIC:
$this->_files[] = new Horde_Script_File_JsDir('ckeditor/imageupload.js', 'imp');
$this->_files[] = new Horde_Script_File_JsDir('ckeditor/imagepoll.js', 'imp');
$page_output->addInlineJsVars(array(
'IMP_Ckeditor_Imagepoll.related_attr' => IMP_Compose::RELATED_ATTR
));

$plugin = 'pasteattachment';
$upload_url = $registry->getServiceLink('ajax', 'imp')->url . 'addAttachmentCkeditor';
Expand Down
12 changes: 7 additions & 5 deletions imp/package.xml
Expand Up @@ -22,7 +22,7 @@
<email>chuck@horde.org</email>
<active>no</active>
</lead>
<date>2014-06-21</date>
<date>2014-06-28</date>
<version>
<release>6.3.0</release>
<api>6.2.0</api>
Expand All @@ -33,7 +33,7 @@
</stability>
<license uri="http://www.horde.org/licenses/gpl">GPL-2.0</license>
<notes>
*
*
</notes>
<contents>
<dir baseinstalldir="/" name="/">
Expand Down Expand Up @@ -69,6 +69,7 @@
</dir> <!-- /docs -->
<dir name="js">
<dir name="ckeditor">
<file name="imagepoll.js" role="horde" />
<file name="imageupload.js" role="horde" />
<file name="pasteattachment.js" role="horde" />
<file name="pasteignore.js" role="horde" />
Expand Down Expand Up @@ -1558,6 +1559,7 @@
<install as="imp/js/smartmobile.js" name="js/smartmobile.js" />
<install as="imp/js/viewport.js" name="js/viewport.js" />
<install as="imp/js/viewport_utils.js" name="js/viewport_utils.js" />
<install as="imp/js/ckeditor/imagepoll.js" name="js/ckeditor/imagepoll.js" />
<install as="imp/js/ckeditor/imageupload.js" name="js/ckeditor/imageupload.js" />
<install as="imp/js/ckeditor/pasteattachment.js" name="js/ckeditor/pasteattachment.js" />
<install as="imp/js/ckeditor/pasteignore.js" name="js/ckeditor/pasteignore.js" />
Expand Down Expand Up @@ -3653,15 +3655,15 @@
</release>
<release>
<version>
<release>6.3.0</release>
<release>6.2.0beta4</release>
<api>6.2.0</api></version>
<stability>
<release>beta</release>
<api>beta</api></stability>
<date>2014-06-21</date>
<date>2014-06-28</date>
<license uri="http://www.horde.org/licenses/gpl">GPL-2.0</license>
<notes>
*
* [mms] Fix handling image attachments when added via the HTML editor Image dialog.
</notes>
</release>
</changelog>
Expand Down

0 comments on commit ba5e8e1

Please sign in to comment.