Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.

Commit 35678b3

Browse files
author
Barry de Graaff
committed
adding Save all to WebDAV option to store all attachments of an email to DAV
1 parent a099457 commit 35678b3

5 files changed

+63
-81
lines changed

zimlet/OwnCloudListView.js

Lines changed: 12 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -430,39 +430,19 @@ OwnCloudListView.prototype._okSharePassListen = function(ev) {
430430
var resNames = [];
431431

432432
this.sharePassDialog.popdown();
433-
if(ownCloudZimletShareType)
434-
{
435-
for (var i = 0; i < resourcesToLink.length; i+= 1) {
436-
resNames.push(resourcesToLink[i].getName());
437-
}
438-
this._ocCommons.getAttachments(
439-
resourcesToLink,
440-
resourcesToAttach,
441-
new AjxCallback(
442-
this,
443-
this._sendFilesListCbk,
444-
[resNames]
445-
), this.sharedLinkPass,
446-
this.sharedLinkExpiryDate
447-
);
448-
}
449-
else{
450-
var cc = AjxDispatcher.run("GetComposeController"),
451-
htmlCompose = appCtxt.get(ZmSetting.COMPOSE_AS_FORMAT) === ZmSetting.COMPOSE_HTML,
452-
extraBodyText = [];
453-
454-
for (var i = 0; i < resourcesToLink.length; i+= 1) {
455-
extraBodyText.push(resourcesToLink[i].getName() + " : " + 'zimbradav:/'+encodeURI(resourcesToLink[i].getHref()));
456-
}
457-
458-
cc._setView({
459-
action: ZmOperation.NEW_MESSAGE,
460-
inNewWindow: false,
461-
msg: new ZmMailMsg(),
462-
subjOverride: zimletInstance._zimletContext.getConfig("owncloud_zimlet_app_title") + " " + ZmMsg.share,
463-
extraBodyText: extraBodyText.join(htmlCompose ? "<br>" : "\n")
464-
});
433+
for (var i = 0; i < resourcesToLink.length; i+= 1) {
434+
resNames.push(resourcesToLink[i].getName());
465435
}
436+
this._ocCommons.getAttachments(
437+
resourcesToLink,
438+
resourcesToAttach,
439+
new AjxCallback(
440+
this,
441+
this._sendFilesListCbk,
442+
[resNames]
443+
), this.sharedLinkPass,
444+
this.sharedLinkExpiryDate
445+
);
466446
}
467447

468448
OwnCloudListView.prototype._sendFileAsAttachmentListener = function(ev) {
@@ -901,13 +881,6 @@ OwnCloudListView.prototype.preview = function(davResource, token) {
901881
{
902882
document.getElementById('WebDAVPreview').src=zimletInstance.getResource('/ViewerJS')+'/?zoom=page-width#'+href;
903883
}
904-
else
905-
{
906-
//This condition occurs only when clicking internal user shares
907-
var regexp = /.*name=(.*?)&contentType.*$/g;
908-
var match = regexp.exec(href);
909-
document.getElementById('WebDAVPreview').contentDocument.write('<button onclick="+window.location.assign(\''+href+'\');this.parentNode.removeChild(this);">'+ZmMsg.download + " " + decodeURIComponent(match[1])+'</button>');
910-
}
911884
}
912885
};
913886

zimlet/tk_barrydegraaff_owncloud_zimlet.js

Lines changed: 48 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,40 @@ ownCloudZimlet._addOwnCloudLink =
314314
return linkHtml;
315315
};
316316

317+
/**Called when a message is viewed
318+
* */
319+
ownCloudZimlet.prototype.onMsgView = function (msg, oldMsg, msgView) {
320+
try {
321+
//We add an download all to dav link if the message has attachments
322+
var zimletInstance = appCtxt._zimletMgr.getZimletByName('tk_barrydegraaff_owncloud_zimlet').handlerObject;
323+
var div = document.createElement('div');
324+
div.id = 'ownCloudZimlet-msgViewActions'+msg.id;
325+
div.innerHTML = '<img style="vertical-align:middle" src="'+zimletInstance.getResource('icon.png')+'"> <a style="text-decoration:underline" class="FakeAnchor">' +
326+
((zimletInstance.getMessage('saveAllTo').indexOf('???') == 0) ? 'Save all to' : zimletInstance.getMessage('saveAllTo')) + ' ' + zimletInstance._zimletContext.getConfig("owncloud_zimlet_app_title") + '</a>';
327+
if(document.getElementById('zv__CLV__main_MSGC'+msg.id+'_attLinks'))
328+
{
329+
//conversation view, top item
330+
document.getElementById('zv__CLV__main_MSGC'+msg.id+'_attLinks').appendChild(div);
331+
}
332+
else
333+
{
334+
//by message view, conversation view expanded item
335+
document.getElementById(appCtxt.getCurrentView()._itemView._attLinksId).appendChild(div);
336+
}
337+
div.onclick = AjxCallback.simpleClosure(zimletInstance.saveAll, zimletInstance, msg);
338+
} catch(err){}
339+
}
340+
341+
/**
342+
* Called when save all to webdav link is clicked in mailview
343+
* */
344+
ownCloudZimlet.prototype.saveAll =
345+
function(msg) {
346+
var zimletInstance = appCtxt._zimletMgr.getZimletByName('tk_barrydegraaff_owncloud_zimlet').handlerObject;
347+
zimletInstance.saveAllBatch = msg._attInfo;
348+
ownCloudZimlet.saveAttachment(zimletInstance.saveAllBatch[0].url, zimletInstance.sanitizeFileName(zimletInstance.saveAllBatch[0].label),true);
349+
};
350+
317351
/**
318352
* Show a Zimbra Status message (toast notification).
319353
* @param {string} text The message.
@@ -327,9 +361,6 @@ ownCloudZimlet.prototype.status =
327361

328362
/**
329363
* Save an attachment to OwnCloud.
330-
* @param {string} mid The message id
331-
* @param {string} part The part of the message.
332-
* @param {string} label The label (usually the file name)
333364
* @static
334365
*/
335366
ownCloudZimlet.saveAttachment =
@@ -352,7 +383,7 @@ ownCloudZimlet.prototype.targetFolderPicker =
352383
function(method, args) {
353384
var zimletInstance = appCtxt._zimletMgr.getZimletByName('tk_barrydegraaff_owncloud_zimlet').handlerObject;
354385

355-
var newFolderBtnId = Dwt.getNextId();
386+
var newFolderBtnId = 'ownCloudZimletNewFolderBtn';
356387
var newFolderBtn = new DwtDialog_ButtonDescriptor(newFolderBtnId, ZmMsg.newFolder, DwtDialog.ALIGN_LEFT);
357388

358389
zimletInstance._folderPickerDialog = new ZmDialog({
@@ -499,6 +530,7 @@ ownCloudZimlet.prototype._saveAttachment =
499530
zimletInstance._folderPickerDialog.setTitle(ZmMsg.loading);
500531
zimletInstance._folderPickerDialog.setButtonVisible(DwtDialog.OK_BUTTON, false);
501532
zimletInstance._folderPickerDialog.setButtonVisible(DwtDialog.CANCEL_BUTTON, false);
533+
zimletInstance._folderPickerDialog.setButtonVisible('ownCloudZimletNewFolderBtn', false);
502534
}
503535
else
504536
{
@@ -528,12 +560,19 @@ ownCloudZimlet.prototype._saveAttachment =
528560
var zimletInstance = appCtxt._zimletMgr.getZimletByName('tk_barrydegraaff_owncloud_zimlet').handlerObject;
529561
if(edit==true)
530562
{
531-
zimletInstance._folderPickerDialog.popdown();
532-
try {
533-
zimletInstance.docEditor.destroyEditor();
534-
} catch(err){}
563+
if(zimletInstance.saveAllBatch.length > 1)
564+
{
565+
zimletInstance.saveAllBatch.shift();
566+
zimletInstance._saveAttachment(zimletInstance.saveAllBatch[0].url, zimletInstance.sanitizeFileName(zimletInstance.saveAllBatch[0].label),true);
567+
}
568+
else
569+
{
570+
zimletInstance._folderPickerDialog.popdown();
571+
try {
572+
zimletInstance.docEditor.destroyEditor();
573+
} catch(err){}
535574
zimletInstance.editenable = true;
536-
ownCloudZimlet.prototype.clicked(null, 'zimbradav:/'+path+ownCloudZimlet.prototype.sanitizeFileName(fileName));
575+
}
537576
}
538577
}
539578
}
@@ -1017,38 +1056,6 @@ ownCloudZimlet.prototype._onRightClickMenu = function(controller, actionMenu) {
10171056

10181057
};
10191058

1020-
/**
1021-
* Handle the action 'drop' on the Zimlet Menu Item.
1022-
* @param {ZmItem[]} zmObjects Objects dropped on the Zimlet Menu Item.
1023-
*/
1024-
ownCloudZimlet.prototype.doDrop =
1025-
function(dropObjects) {
1026-
/*
1027-
var zimletInstance = appCtxt._zimletMgr.getZimletByName('tk_barrydegraaff_owncloud_zimlet').handlerObject;
1028-
if(!tk_barrydegraaff_owncloud_zimlet_HandlerObject.settings['owncloud_zimlet_password'])
1029-
{
1030-
zimletInstance.status(ZmMsg.requiredLabel + ' ' + ZmMsg.password, ZmStatusView.LEVEL_INFO);
1031-
zimletInstance.displayDialog(1, ZmMsg.preferences, null);
1032-
return;
1033-
}
1034-
1035-
// Single selects result in an object passed,
1036-
//Multi selects results in an array of objects passed.
1037-
//Always make it an array
1038-
if(!dropObjects[0])
1039-
{
1040-
dropObjects = [dropObjects];
1041-
}
1042-
var i = 0;
1043-
var zmObjects = [];
1044-
dropObjects.forEach(function(dropObject)
1045-
{
1046-
zmObjects[i++] = dropObject.srcObj;
1047-
});
1048-
zimletInstance.targetFolderPicker(zimletInstance._doDropPropfindCbk,[zmObjects]);
1049-
*/
1050-
};
1051-
10521059
/**
10531060
* Send a list of ZmObjects to OwnCloud.
10541061
* The real copy will be made on the server, this optimization will avoid to saturate the user bandwidth.

zimlet/tk_barrydegraaff_owncloud_zimlet.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ userPreferences = User preferences
2323

2424
onlyofficeSave = Saving... it can take up to 10 seconds.
2525
showHiddenFiles = Show hidden files
26+
saveAllTo = Save all to

zimlet/tk_barrydegraaff_owncloud_zimlet.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ along with this program. If not, see http://www.gnu.org/licenses/.
2323
2424
-->
2525
<zimlet name="tk_barrydegraaff_owncloud_zimlet"
26-
version="1.2.1"
26+
version="1.2.2"
2727
target="main compose-window view-window"
2828
label="WebDAV"
2929
description="Attach from and save to WebDAV">

zimlet/tk_barrydegraaff_owncloud_zimlet_fr.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ userPreferences = User preferences
2323

2424
onlyofficeSave = Saving... it can take up to 10 seconds.
2525
showHiddenFiles = Show hidden files
26+
saveAllTo = Save all to

0 commit comments

Comments
 (0)