mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-09-11 23:54:15 +08:00
Added JavaScript rl-view-model.create
event for advanced code injections
This commit contains one for Nextcloud, so you understand how it works
This commit is contained in:
parent
0e56b693c1
commit
b2e1fa993d
4 changed files with 53 additions and 3 deletions
|
@ -35,6 +35,8 @@ const
|
|||
dialog = ViewTypePopup === vm.viewType,
|
||||
vmPlace = doc.getElementById(position);
|
||||
|
||||
fireEvent('rl-view-model.create', vm);
|
||||
|
||||
ViewModelClass.__builded = true;
|
||||
ViewModelClass.__vm = vm;
|
||||
|
||||
|
|
|
@ -378,8 +378,14 @@ $Plugin->addHook('hook.name', 'functionName');
|
|||
## Misc
|
||||
### idle
|
||||
### rl-layout
|
||||
|
||||
### rl-view-model.create
|
||||
event.detail = the ViewModel class
|
||||
Happens immediately after the ViewModel constructor
|
||||
|
||||
### rl-view-model
|
||||
event.detail = the ViewModel class
|
||||
Happens after the full build (vm.onBuild()) and contains viewModelDom
|
||||
|
||||
### sm-admin-login
|
||||
event.detail = FormData
|
||||
|
|
|
@ -15,7 +15,7 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
if (static::IsIntegrated()) {
|
||||
$this->addHook('main.fabrica', 'MainFabrica');
|
||||
$this->addHook('filter.app-data', 'FilterAppData');
|
||||
$this->addHook('json.attachments', 'SaveAttachments');
|
||||
$this->addHook('json.attachments', 'DoAttachmentsActions');
|
||||
|
||||
$this->addJs('js/attachments.js');
|
||||
}
|
||||
|
@ -36,8 +36,7 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
return static::IsIntegrated() && \OC::$server->getUserSession()->isLoggedIn();
|
||||
}
|
||||
|
||||
// DoAttachmentsActions
|
||||
public function SaveAttachments(\SnappyMail\AttachmentsAction $data)
|
||||
public function DoAttachmentsActions(\SnappyMail\AttachmentsAction $data)
|
||||
{
|
||||
if ('nextcloud' === $data->action) {
|
||||
$oFiles = \OCP\Files::getStorage('files');
|
||||
|
|
43
plugins/nextcloud/js/attachments.js
Normal file
43
plugins/nextcloud/js/attachments.js
Normal file
|
@ -0,0 +1,43 @@
|
|||
(rl => {
|
||||
if (rl) {
|
||||
addEventListener('rl-view-model.create', e => {
|
||||
if ('MailMessageView' === e.detail.viewModelTemplateID) {
|
||||
let view = e.detail;
|
||||
view.saveNextcloudError = ko.observable(false).extend({ falseTimeout: 7000 });
|
||||
view.saveNextcloudLoading = ko.observable(false);
|
||||
view.saveNextcloud = () => {
|
||||
const
|
||||
hashes = (view.message()?.attachments || [])
|
||||
.map(item => item?.checked() /*&& !item?.isLinked()*/ ? item.download : '')
|
||||
.filter(v => v);
|
||||
if (hashes.length) {
|
||||
rl.fetchJSON('./?/Json/&q[]=/0/', {}, {
|
||||
Action: 'AttachmentsActions',
|
||||
Do: 'nextcloud',
|
||||
Hashes: hashes
|
||||
})
|
||||
.then(result => {
|
||||
if (result?.Result) {
|
||||
// success
|
||||
} else {
|
||||
view.saveNextcloudError(true);
|
||||
}
|
||||
})
|
||||
.catch(() => view.saveNextcloudError(true));
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
let template = document.getElementById('MailMessageView');
|
||||
const attachmentsControls = template.content.querySelector('.attachmentsControls');
|
||||
if (attachmentsControls) {
|
||||
attachmentsControls.append(Element.fromHTML('<span>'
|
||||
+ '<i class="fontastic iconcolor-red" data-bind="visible: saveNextcloudError">✖</i>'
|
||||
+ '<i class="icon-file-archive" data-bind="visible: !saveNextcloudError(), css: {\'icon-file-archive\': !saveNextcloudLoading(), \'icon-spinner\': saveNextcloudLoading()}"></i>'
|
||||
+ '<span class="g-ui-link" data-bind="click: saveNextcloud" data-i18n="NEXTCLOUD/SAVE_ATTACHMENTS">Save Nextcloud</span>'
|
||||
+ '</span>'));
|
||||
}
|
||||
}
|
||||
})(window.rl);
|
Loading…
Add table
Reference in a new issue