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

Commit

Permalink
adding Save all to WebDAV option to store all attachments of an ema…
Browse files Browse the repository at this point in the history
…il to DAV
  • Loading branch information
Barry de Graaff committed Jul 10, 2019
1 parent a099457 commit 35678b3
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 81 deletions.
51 changes: 12 additions & 39 deletions zimlet/OwnCloudListView.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,39 +430,19 @@ OwnCloudListView.prototype._okSharePassListen = function(ev) {
var resNames = [];

this.sharePassDialog.popdown();
if(ownCloudZimletShareType)
{
for (var i = 0; i < resourcesToLink.length; i+= 1) {
resNames.push(resourcesToLink[i].getName());
}
this._ocCommons.getAttachments(
resourcesToLink,
resourcesToAttach,
new AjxCallback(
this,
this._sendFilesListCbk,
[resNames]
), this.sharedLinkPass,
this.sharedLinkExpiryDate
);
}
else{
var cc = AjxDispatcher.run("GetComposeController"),
htmlCompose = appCtxt.get(ZmSetting.COMPOSE_AS_FORMAT) === ZmSetting.COMPOSE_HTML,
extraBodyText = [];

for (var i = 0; i < resourcesToLink.length; i+= 1) {
extraBodyText.push(resourcesToLink[i].getName() + " : " + 'zimbradav:/'+encodeURI(resourcesToLink[i].getHref()));
}

cc._setView({
action: ZmOperation.NEW_MESSAGE,
inNewWindow: false,
msg: new ZmMailMsg(),
subjOverride: zimletInstance._zimletContext.getConfig("owncloud_zimlet_app_title") + " " + ZmMsg.share,
extraBodyText: extraBodyText.join(htmlCompose ? "<br>" : "\n")
});
for (var i = 0; i < resourcesToLink.length; i+= 1) {
resNames.push(resourcesToLink[i].getName());
}
this._ocCommons.getAttachments(
resourcesToLink,
resourcesToAttach,
new AjxCallback(
this,
this._sendFilesListCbk,
[resNames]
), this.sharedLinkPass,
this.sharedLinkExpiryDate
);
}

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

Expand Down
89 changes: 48 additions & 41 deletions zimlet/tk_barrydegraaff_owncloud_zimlet.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,40 @@ ownCloudZimlet._addOwnCloudLink =
return linkHtml;
};

/**Called when a message is viewed
* */
ownCloudZimlet.prototype.onMsgView = function (msg, oldMsg, msgView) {
try {
//We add an download all to dav link if the message has attachments
var zimletInstance = appCtxt._zimletMgr.getZimletByName('tk_barrydegraaff_owncloud_zimlet').handlerObject;
var div = document.createElement('div');
div.id = 'ownCloudZimlet-msgViewActions'+msg.id;
div.innerHTML = '<img style="vertical-align:middle" src="'+zimletInstance.getResource('icon.png')+'"> <a style="text-decoration:underline" class="FakeAnchor">' +
((zimletInstance.getMessage('saveAllTo').indexOf('???') == 0) ? 'Save all to' : zimletInstance.getMessage('saveAllTo')) + ' ' + zimletInstance._zimletContext.getConfig("owncloud_zimlet_app_title") + '</a>';
if(document.getElementById('zv__CLV__main_MSGC'+msg.id+'_attLinks'))
{
//conversation view, top item
document.getElementById('zv__CLV__main_MSGC'+msg.id+'_attLinks').appendChild(div);
}
else
{
//by message view, conversation view expanded item
document.getElementById(appCtxt.getCurrentView()._itemView._attLinksId).appendChild(div);
}
div.onclick = AjxCallback.simpleClosure(zimletInstance.saveAll, zimletInstance, msg);
} catch(err){}
}

/**
* Called when save all to webdav link is clicked in mailview
* */
ownCloudZimlet.prototype.saveAll =
function(msg) {
var zimletInstance = appCtxt._zimletMgr.getZimletByName('tk_barrydegraaff_owncloud_zimlet').handlerObject;
zimletInstance.saveAllBatch = msg._attInfo;
ownCloudZimlet.saveAttachment(zimletInstance.saveAllBatch[0].url, zimletInstance.sanitizeFileName(zimletInstance.saveAllBatch[0].label),true);
};

/**
* Show a Zimbra Status message (toast notification).
* @param {string} text The message.
Expand All @@ -327,9 +361,6 @@ ownCloudZimlet.prototype.status =

/**
* Save an attachment to OwnCloud.
* @param {string} mid The message id
* @param {string} part The part of the message.
* @param {string} label The label (usually the file name)
* @static
*/
ownCloudZimlet.saveAttachment =
Expand All @@ -352,7 +383,7 @@ ownCloudZimlet.prototype.targetFolderPicker =
function(method, args) {
var zimletInstance = appCtxt._zimletMgr.getZimletByName('tk_barrydegraaff_owncloud_zimlet').handlerObject;

var newFolderBtnId = Dwt.getNextId();
var newFolderBtnId = 'ownCloudZimletNewFolderBtn';
var newFolderBtn = new DwtDialog_ButtonDescriptor(newFolderBtnId, ZmMsg.newFolder, DwtDialog.ALIGN_LEFT);

zimletInstance._folderPickerDialog = new ZmDialog({
Expand Down Expand Up @@ -499,6 +530,7 @@ ownCloudZimlet.prototype._saveAttachment =
zimletInstance._folderPickerDialog.setTitle(ZmMsg.loading);
zimletInstance._folderPickerDialog.setButtonVisible(DwtDialog.OK_BUTTON, false);
zimletInstance._folderPickerDialog.setButtonVisible(DwtDialog.CANCEL_BUTTON, false);
zimletInstance._folderPickerDialog.setButtonVisible('ownCloudZimletNewFolderBtn', false);
}
else
{
Expand Down Expand Up @@ -528,12 +560,19 @@ ownCloudZimlet.prototype._saveAttachment =
var zimletInstance = appCtxt._zimletMgr.getZimletByName('tk_barrydegraaff_owncloud_zimlet').handlerObject;
if(edit==true)
{
zimletInstance._folderPickerDialog.popdown();
try {
zimletInstance.docEditor.destroyEditor();
} catch(err){}
if(zimletInstance.saveAllBatch.length > 1)
{
zimletInstance.saveAllBatch.shift();
zimletInstance._saveAttachment(zimletInstance.saveAllBatch[0].url, zimletInstance.sanitizeFileName(zimletInstance.saveAllBatch[0].label),true);
}
else
{
zimletInstance._folderPickerDialog.popdown();
try {
zimletInstance.docEditor.destroyEditor();
} catch(err){}
zimletInstance.editenable = true;
ownCloudZimlet.prototype.clicked(null, 'zimbradav:/'+path+ownCloudZimlet.prototype.sanitizeFileName(fileName));
}
}
}
}
Expand Down Expand Up @@ -1017,38 +1056,6 @@ ownCloudZimlet.prototype._onRightClickMenu = function(controller, actionMenu) {

};

/**
* Handle the action 'drop' on the Zimlet Menu Item.
* @param {ZmItem[]} zmObjects Objects dropped on the Zimlet Menu Item.
*/
ownCloudZimlet.prototype.doDrop =
function(dropObjects) {
/*
var zimletInstance = appCtxt._zimletMgr.getZimletByName('tk_barrydegraaff_owncloud_zimlet').handlerObject;
if(!tk_barrydegraaff_owncloud_zimlet_HandlerObject.settings['owncloud_zimlet_password'])
{
zimletInstance.status(ZmMsg.requiredLabel + ' ' + ZmMsg.password, ZmStatusView.LEVEL_INFO);
zimletInstance.displayDialog(1, ZmMsg.preferences, null);
return;
}
// Single selects result in an object passed,
//Multi selects results in an array of objects passed.
//Always make it an array
if(!dropObjects[0])
{
dropObjects = [dropObjects];
}
var i = 0;
var zmObjects = [];
dropObjects.forEach(function(dropObject)
{
zmObjects[i++] = dropObject.srcObj;
});
zimletInstance.targetFolderPicker(zimletInstance._doDropPropfindCbk,[zmObjects]);
*/
};

/**
* Send a list of ZmObjects to OwnCloud.
* The real copy will be made on the server, this optimization will avoid to saturate the user bandwidth.
Expand Down
1 change: 1 addition & 0 deletions zimlet/tk_barrydegraaff_owncloud_zimlet.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ userPreferences = User preferences

onlyofficeSave = Saving... it can take up to 10 seconds.
showHiddenFiles = Show hidden files
saveAllTo = Save all to
2 changes: 1 addition & 1 deletion zimlet/tk_barrydegraaff_owncloud_zimlet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ along with this program. If not, see http://www.gnu.org/licenses/.
-->
<zimlet name="tk_barrydegraaff_owncloud_zimlet"
version="1.2.1"
version="1.2.2"
target="main compose-window view-window"
label="WebDAV"
description="Attach from and save to WebDAV">
Expand Down
1 change: 1 addition & 0 deletions zimlet/tk_barrydegraaff_owncloud_zimlet_fr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ userPreferences = User preferences

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

0 comments on commit 35678b3

Please sign in to comment.