mirror of
https://github.com/the-djmaze/snappymail.git
synced 2024-09-20 15:45:55 +08:00
Moved from master
This commit is contained in:
parent
134deb8d73
commit
19c78c2350
|
@ -51,6 +51,7 @@ import { NotificationUserStore } from 'Stores/User/Notification';
|
|||
import { AccountUserStore } from 'Stores/User/Account';
|
||||
import { ContactUserStore } from 'Stores/User/Contact';
|
||||
import { IdentityUserStore } from 'Stores/User/Identity';
|
||||
import { TemplateUserStore } from 'Stores/User/Template';
|
||||
import { FolderUserStore } from 'Stores/User/Folder';
|
||||
import { PgpUserStore } from 'Stores/User/Pgp';
|
||||
import { MessageUserStore } from 'Stores/User/Message';
|
||||
|
@ -64,6 +65,7 @@ import Remote from 'Remote/User/Fetch';
|
|||
import { EmailModel } from 'Model/Email';
|
||||
import { AccountModel } from 'Model/Account';
|
||||
import { IdentityModel } from 'Model/Identity';
|
||||
import { TemplateModel } from 'Model/Template';
|
||||
import { OpenPgpKeyModel } from 'Model/OpenPgpKey';
|
||||
|
||||
import { LoginUserScreen } from 'Screen/User/Login';
|
||||
|
@ -495,6 +497,24 @@ class AppUser extends AbstractApp {
|
|||
});
|
||||
}
|
||||
|
||||
templates() {
|
||||
TemplateUserStore.templates.loading(true);
|
||||
|
||||
Remote.templates((iError, data) => {
|
||||
TemplateUserStore.templates.loading(false);
|
||||
|
||||
if (!iError && isArray(data.Result.Templates)) {
|
||||
delegateRunOnDestroy(TemplateUserStore.templates());
|
||||
|
||||
TemplateUserStore.templates(
|
||||
data.Result.Templates.map(templateData =>
|
||||
TemplateModel.reviveFromJson(templateData)
|
||||
).filter(v => v)
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
quota() {
|
||||
Remote.quota((iError, data) => {
|
||||
if (
|
||||
|
|
|
@ -21,6 +21,7 @@ export const Capa = {
|
|||
UserBackground: 'USER_BACKGROUND',
|
||||
Sieve: 'SIEVE',
|
||||
AttachmentThumbnails: 'ATTACHMENT_THUMBNAILS',
|
||||
Templates: 'TEMPLATES',
|
||||
AutoLogout: 'AUTOLOGOUT',
|
||||
AdditionalAccounts: 'ADDITIONAL_ACCOUNTS',
|
||||
Identities: 'IDENTITIES'
|
||||
|
|
23
dev/Model/Template.js
Normal file
23
dev/Model/Template.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
import ko from 'ko';
|
||||
|
||||
import { AbstractModel } from 'Knoin/AbstractModel';
|
||||
|
||||
export class TemplateModel extends AbstractModel {
|
||||
/**
|
||||
* @param {string} id
|
||||
* @param {string} name
|
||||
* @param {string} body
|
||||
*/
|
||||
constructor(id = '', name = '', body = '') {
|
||||
super();
|
||||
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.body = body;
|
||||
this.populated = true;
|
||||
|
||||
this.deleteAccess = ko.observable(false);
|
||||
}
|
||||
|
||||
// static reviveFromJson(json) {}
|
||||
}
|
|
@ -185,6 +185,47 @@ class RemoteUserFetch extends AbstractFetchRemote {
|
|||
this.defaultRequest(fCallback, 'Filters', {});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {?Function} fCallback
|
||||
*/
|
||||
templates(fCallback) {
|
||||
this.defaultRequest(fCallback, 'Templates', {});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Function} fCallback
|
||||
* @param {string} sID
|
||||
*/
|
||||
templateGetById(fCallback, sID) {
|
||||
this.defaultRequest(fCallback, 'TemplateGetByID', {
|
||||
ID: sID
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Function} fCallback
|
||||
* @param {string} sID
|
||||
*/
|
||||
templateDelete(fCallback, sID) {
|
||||
this.defaultRequest(fCallback, 'TemplateDelete', {
|
||||
IdToDelete: sID
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Function} fCallback
|
||||
* @param {string} sID
|
||||
* @param {string} sName
|
||||
* @param {string} sBody
|
||||
*/
|
||||
templateSetup(fCallback, sID, sName, sBody) {
|
||||
this.defaultRequest(fCallback, 'TemplateSetup', {
|
||||
ID: sID,
|
||||
Name: sName,
|
||||
Body: sBody
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Function} fCallback
|
||||
* @param {object} params
|
||||
|
|
|
@ -14,6 +14,7 @@ import { ContactsUserSettings } from 'Settings/User/Contacts';
|
|||
import { AccountsUserSettings } from 'Settings/User/Accounts';
|
||||
import { FiltersUserSettings } from 'Settings/User/Filters';
|
||||
import { SecurityUserSettings } from 'Settings/User/Security';
|
||||
import { TemplatesUserSettings } from 'Settings/User/Templates';
|
||||
import { FoldersUserSettings } from 'Settings/User/Folders';
|
||||
import { ThemesUserSettings } from 'Settings/User/Themes';
|
||||
import { OpenPgpUserSettings } from 'Settings/User/OpenPgp';
|
||||
|
@ -67,6 +68,15 @@ export class SettingsUserScreen extends AbstractSettingsScreen {
|
|||
settingsAddViewModel(SecurityUserSettings, 'SettingsSecurity', 'SETTINGS_LABELS/LABEL_SECURITY_NAME', 'security');
|
||||
}
|
||||
|
||||
if (Settings.capa(Capa.Templates)) {
|
||||
settingsAddViewModel(
|
||||
TemplatesUserSettings,
|
||||
'SettingsTemplates',
|
||||
'SETTINGS_LABELS/LABEL_TEMPLATES_NAME',
|
||||
'templates'
|
||||
);
|
||||
}
|
||||
|
||||
settingsAddViewModel(FoldersUserSettings, 'SettingsFolders', 'SETTINGS_LABELS/LABEL_FOLDERS_NAME', 'folders');
|
||||
|
||||
if (Settings.capa(Capa.Themes)) {
|
||||
|
|
|
@ -48,6 +48,7 @@ export class GeneralAdminSettings {
|
|||
capaAdditionalAccounts: Settings.capa(Capa.AdditionalAccounts),
|
||||
capaIdentities: Settings.capa(Capa.Identities),
|
||||
capaAttachmentThumbnails: Settings.capa(Capa.AttachmentThumbnails),
|
||||
capaTemplates: Settings.capa(Capa.Templates),
|
||||
dataFolderAccess: false
|
||||
});
|
||||
|
||||
|
@ -125,6 +126,8 @@ export class GeneralAdminSettings {
|
|||
|
||||
capaIdentities: fSaveBoolHelper('CapaIdentities'),
|
||||
|
||||
capaTemplates: fSaveBoolHelper('CapaTemplates'),
|
||||
|
||||
capaAttachmentThumbnails: fSaveBoolHelper('CapaAttachmentThumbnails'),
|
||||
|
||||
capaThemes: fSaveBoolHelper('CapaThemes'),
|
||||
|
|
62
dev/Settings/User/Templates.js
Normal file
62
dev/Settings/User/Templates.js
Normal file
|
@ -0,0 +1,62 @@
|
|||
import ko from 'ko';
|
||||
|
||||
import { i18n } from 'Common/Translator';
|
||||
|
||||
import { TemplateUserStore } from 'Stores/User/Template';
|
||||
import Remote from 'Remote/User/Fetch';
|
||||
|
||||
import { showScreenPopup } from 'Knoin/Knoin';
|
||||
|
||||
import { TemplatePopupView } from 'View/Popup/Template';
|
||||
import { addComputablesTo } from 'Common/Utils';
|
||||
|
||||
export class TemplatesUserSettings {
|
||||
constructor() {
|
||||
this.templates = TemplateUserStore.templates;
|
||||
|
||||
addComputablesTo(this, {
|
||||
processText: () => TemplateUserStore.templates.loading() ? i18n('SETTINGS_TEMPLETS/LOADING_PROCESS') : '',
|
||||
|
||||
visibility: () => this.processText() ? 'visible' : 'hidden'
|
||||
});
|
||||
|
||||
this.templateForDeletion = ko.observable(null).deleteAccessHelper();
|
||||
}
|
||||
|
||||
addNewTemplate() {
|
||||
showScreenPopup(TemplatePopupView);
|
||||
}
|
||||
|
||||
editTemplate(oTemplateItem) {
|
||||
if (oTemplateItem) {
|
||||
showScreenPopup(TemplatePopupView, [oTemplateItem]);
|
||||
}
|
||||
}
|
||||
|
||||
deleteTemplate(templateToRemove) {
|
||||
if (templateToRemove && templateToRemove.deleteAccess()) {
|
||||
this.templateForDeletion(null);
|
||||
|
||||
if (templateToRemove) {
|
||||
this.templates.remove((template) => templateToRemove === template);
|
||||
|
||||
Remote.templateDelete(() => {
|
||||
this.reloadTemplates();
|
||||
}, templateToRemove.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
reloadTemplates() {
|
||||
rl.app.templates();
|
||||
}
|
||||
|
||||
onBuild(oDom) {
|
||||
oDom.addEventListener('click', event => {
|
||||
const el = event.target.closestWithin('td.e-action', oDom);
|
||||
el && ko.dataFor(el) && this.editTemplate(ko.dataFor(el));
|
||||
});
|
||||
|
||||
this.reloadTemplates();
|
||||
}
|
||||
}
|
28
dev/Stores/User/Template.js
Normal file
28
dev/Stores/User/Template.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
import ko from 'ko';
|
||||
|
||||
// import Remote from 'Remote/User/Fetch';
|
||||
|
||||
export const TemplateUserStore = new class {
|
||||
constructor() {
|
||||
this.templates = ko.observableArray();
|
||||
this.templates.loading = ko.observable(false).extend({ debounce: 100 });
|
||||
|
||||
this.templatesNames = ko.observableArray().extend({ debounce: 1000 });
|
||||
this.templatesNames.skipFirst = true;
|
||||
|
||||
this.templates.subscribe((list) => {
|
||||
this.templatesNames(list.map(item => (item ? item.name : null)).filter(v => v));
|
||||
});
|
||||
|
||||
// this.templatesNames.subscribe((aList) => {
|
||||
// if (this.templatesNames.skipFirst)
|
||||
// {
|
||||
// this.templatesNames.skipFirst = false;
|
||||
// }
|
||||
// else if (aList && aList.length)
|
||||
// {
|
||||
// Remote.templatesSortOrder(null, aList);
|
||||
// }
|
||||
// });
|
||||
}
|
||||
};
|
|
@ -33,6 +33,7 @@
|
|||
@import "User/Shortcuts.less";
|
||||
@import "User/FolderList.less";
|
||||
@import "User/Filter.less";
|
||||
@import "User/Template.less";
|
||||
@import "User/OpenPgpKey.less";
|
||||
@import "User/Identity.less";
|
||||
@import "User/AdvancedSearch.less";
|
||||
|
@ -46,6 +47,7 @@
|
|||
@import "User/Settings.less";
|
||||
@import "User/SettingsGeneral.less";
|
||||
@import "User/SettingsAccounts.less";
|
||||
@import "User/SettingsTemplates.less";
|
||||
@import "User/SettingsOpenPGP.less";
|
||||
@import "User/SettingsFolders.less";
|
||||
@import "User/SettingsThemes.less";
|
||||
|
|
21
dev/Styles/User/SettingsTemplates.less
Normal file
21
dev/Styles/User/SettingsTemplates.less
Normal file
|
@ -0,0 +1,21 @@
|
|||
|
||||
.b-settings-templates {
|
||||
|
||||
td + td {
|
||||
width: 150px;
|
||||
}
|
||||
td + td + td {
|
||||
width: 1%;
|
||||
}
|
||||
|
||||
.template-name {
|
||||
display: inline-block;
|
||||
line-height: 22px;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.delete-template {
|
||||
cursor: pointer;
|
||||
opacity: 0.5;
|
||||
}
|
||||
}
|
10
dev/Styles/User/Template.less
Normal file
10
dev/Styles/User/Template.less
Normal file
|
@ -0,0 +1,10 @@
|
|||
.b-template-add-content {
|
||||
|
||||
&.modal {
|
||||
max-width: 750px;
|
||||
}
|
||||
|
||||
.e-template-place {
|
||||
height: 300px;
|
||||
}
|
||||
}
|
148
dev/View/Popup/Template.js
Normal file
148
dev/View/Popup/Template.js
Normal file
|
@ -0,0 +1,148 @@
|
|||
import { getNotification } from 'Common/Translator';
|
||||
import { HtmlEditor } from 'Common/Html';
|
||||
|
||||
import Remote from 'Remote/User/Fetch';
|
||||
|
||||
import { decorateKoCommands } from 'Knoin/Knoin';
|
||||
import { AbstractViewPopup } from 'Knoin/AbstractViews';
|
||||
import { TemplateModel } from 'Model/Template';
|
||||
|
||||
class TemplatePopupView extends AbstractViewPopup {
|
||||
constructor() {
|
||||
super('Template');
|
||||
|
||||
this.editor = null;
|
||||
|
||||
this.addObservables({
|
||||
signatureDom: null,
|
||||
|
||||
id: '',
|
||||
|
||||
name: '',
|
||||
nameError: false,
|
||||
|
||||
body: '',
|
||||
bodyLoading: false,
|
||||
bodyError: false,
|
||||
|
||||
submitRequest: false,
|
||||
submitError: ''
|
||||
});
|
||||
|
||||
this.name.subscribe(() => this.nameError(false));
|
||||
|
||||
this.body.subscribe(() => this.bodyError(false));
|
||||
|
||||
decorateKoCommands(this, {
|
||||
addTemplateCommand: self => !self.submitRequest()
|
||||
});
|
||||
}
|
||||
|
||||
addTemplateCommand() {
|
||||
this.populateBodyFromEditor();
|
||||
|
||||
this.nameError(!this.name().trim());
|
||||
this.bodyError(!this.body().trim() || ':HTML:' === this.body().trim());
|
||||
|
||||
if (this.nameError() || this.bodyError()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.submitRequest(true);
|
||||
|
||||
Remote.templateSetup(
|
||||
iError => {
|
||||
this.submitRequest(false);
|
||||
if (iError) {
|
||||
this.submitError(getNotification(iError));
|
||||
} else {
|
||||
rl.app.templates();
|
||||
this.cancelCommand();
|
||||
}
|
||||
},
|
||||
this.id(),
|
||||
this.name(),
|
||||
this.body()
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
clearPopup() {
|
||||
this.id('');
|
||||
|
||||
this.name('');
|
||||
this.nameError(false);
|
||||
|
||||
this.body('');
|
||||
this.bodyLoading(false);
|
||||
this.bodyError(false);
|
||||
|
||||
this.submitRequest(false);
|
||||
this.submitError('');
|
||||
|
||||
if (this.editor) {
|
||||
this.editor.setPlain('');
|
||||
}
|
||||
}
|
||||
|
||||
populateBodyFromEditor() {
|
||||
if (this.editor) {
|
||||
this.body(this.editor.getDataWithHtmlMark());
|
||||
}
|
||||
}
|
||||
|
||||
editorSetBody(sBody) {
|
||||
if (!this.editor && this.signatureDom()) {
|
||||
this.editor = new HtmlEditor(
|
||||
this.signatureDom(),
|
||||
() => this.populateBodyFromEditor(),
|
||||
() => this.editor.setHtmlOrPlain(sBody)
|
||||
);
|
||||
} else {
|
||||
this.editor.setHtmlOrPlain(sBody);
|
||||
}
|
||||
}
|
||||
|
||||
onShow(template) {
|
||||
this.clearPopup();
|
||||
|
||||
if (template && template.id) {
|
||||
this.id(template.id);
|
||||
this.name(template.name);
|
||||
this.body(template.body);
|
||||
|
||||
if (template.populated) {
|
||||
this.editorSetBody(this.body());
|
||||
} else {
|
||||
this.bodyLoading(true);
|
||||
this.bodyError(false);
|
||||
|
||||
Remote.templateGetById((iError, data) => {
|
||||
this.bodyLoading(false);
|
||||
|
||||
if (
|
||||
!iError &&
|
||||
TemplateModel.validJson(data.Result) &&
|
||||
null != data.Result.Body
|
||||
) {
|
||||
template.body = data.Result.Body;
|
||||
template.populated = true;
|
||||
|
||||
this.body(template.body);
|
||||
this.bodyError(false);
|
||||
} else {
|
||||
this.body('');
|
||||
this.bodyError(true);
|
||||
}
|
||||
|
||||
this.editorSetBody(this.body());
|
||||
}, this.id());
|
||||
}
|
||||
} else {
|
||||
this.editorSetBody('');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export { TemplatePopupView, TemplatePopupView as default };
|
|
@ -1932,6 +1932,10 @@ class Actions
|
|||
$aResult[] = Enumerations\Capa::IDENTITIES;
|
||||
}
|
||||
|
||||
if ($oConfig->Get('capa', 'x-templates', true)) {
|
||||
$aResult[] = Enumerations\Capa::TEMPLATES;
|
||||
}
|
||||
|
||||
if ($oConfig->Get('webmail', 'allow_themes', false)) {
|
||||
$aResult[] = Enumerations\Capa::THEMES;
|
||||
}
|
||||
|
|
|
@ -83,6 +83,9 @@ trait Admin
|
|||
case Capa::IDENTITIES:
|
||||
$this->setConfigFromParams($oConfig, $sParamName, 'webmail', 'allow_additional_identities', 'bool');
|
||||
break;
|
||||
case Capa::TEMPLATES:
|
||||
$this->setConfigFromParams($oConfig, $sParamName, 'capa', 'x-templates', 'bool');
|
||||
break;
|
||||
case Capa::ATTACHMENT_THUMBNAILS:
|
||||
$this->setConfigFromParams($oConfig, $sParamName, 'interface', 'show_attachment_thumbnail', 'bool');
|
||||
break;
|
||||
|
@ -147,6 +150,7 @@ trait Admin
|
|||
|
||||
$this->setCapaFromParams($oConfig, 'CapaAdditionalAccounts', Capa::ADDITIONAL_ACCOUNTS);
|
||||
$this->setCapaFromParams($oConfig, 'CapaIdentities', Capa::IDENTITIES);
|
||||
$this->setCapaFromParams($oConfig, 'CapaTemplates', Capa::TEMPLATES);
|
||||
$this->setCapaFromParams($oConfig, 'CapaOpenPGP', Capa::OPEN_PGP);
|
||||
$this->setCapaFromParams($oConfig, 'CapaThemes', Capa::THEMES);
|
||||
$this->setCapaFromParams($oConfig, 'CapaUserBackground', Capa::USER_BACKGROUND);
|
||||
|
|
215
snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Templates.php
Normal file
215
snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Templates.php
Normal file
|
@ -0,0 +1,215 @@
|
|||
<?php
|
||||
|
||||
namespace RainLoop\Actions;
|
||||
|
||||
use \RainLoop\Enumerations\Capa;
|
||||
use \RainLoop\Exceptions\ClientException;
|
||||
use \RainLoop\Model\Account;
|
||||
use \RainLoop\Model\Template;
|
||||
use \RainLoop\Notifications;
|
||||
|
||||
trait Templates
|
||||
{
|
||||
|
||||
/**
|
||||
* @throws \MailSo\Base\Exceptions\Exception
|
||||
*/
|
||||
public function DoTemplateSetup() : array
|
||||
{
|
||||
$oAccount = $this->getAccountFromToken();
|
||||
|
||||
if (!$this->GetCapa(false, Capa::TEMPLATES, $oAccount))
|
||||
{
|
||||
return $this->FalseResponse(__FUNCTION__);
|
||||
}
|
||||
|
||||
$oTemplate = new Template();
|
||||
if (!$oTemplate->FromJSON($this->GetActionParams(), true))
|
||||
{
|
||||
throw new ClientException(Notifications::InvalidInputArgument);
|
||||
}
|
||||
|
||||
if ('' === $oTemplate->Id())
|
||||
{
|
||||
$oTemplate->GenerateID();
|
||||
}
|
||||
|
||||
$aTemplatesForSave = array();
|
||||
$aTemplates = $this->GetTemplates($oAccount);
|
||||
|
||||
|
||||
foreach ($aTemplates as $oItem)
|
||||
{
|
||||
if ($oItem && $oItem->Id() !== $oTemplate->Id())
|
||||
{
|
||||
$aTemplatesForSave[] = $oItem;
|
||||
}
|
||||
}
|
||||
|
||||
$aTemplatesForSave[] = $oTemplate;
|
||||
|
||||
return $this->DefaultResponse(__FUNCTION__, $this->SetTemplates($oAccount, $aTemplatesForSave));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \MailSo\Base\Exceptions\Exception
|
||||
*/
|
||||
public function DoTemplateDelete() : array
|
||||
{
|
||||
$oAccount = $this->getAccountFromToken();
|
||||
|
||||
if (!$this->GetCapa(false, Capa::TEMPLATES, $oAccount))
|
||||
{
|
||||
return $this->FalseResponse(__FUNCTION__);
|
||||
}
|
||||
|
||||
$sId = \trim($this->GetActionParam('IdToDelete', ''));
|
||||
if (empty($sId))
|
||||
{
|
||||
throw new ClientException(Notifications::UnknownError);
|
||||
}
|
||||
|
||||
$aNew = array();
|
||||
$aTemplates = $this->GetTemplates($oAccount);
|
||||
foreach ($aTemplates as $oItem)
|
||||
{
|
||||
if ($oItem && $sId !== $oItem->Id())
|
||||
{
|
||||
$aNew[] = $oItem;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->DefaultResponse(__FUNCTION__, $this->SetTemplates($oAccount, $aNew));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \MailSo\Base\Exceptions\Exception
|
||||
*/
|
||||
public function DoTemplateGetByID() : array
|
||||
{
|
||||
$oAccount = $this->getAccountFromToken();
|
||||
|
||||
if (!$this->GetCapa(false, Capa::TEMPLATES, $oAccount))
|
||||
{
|
||||
return $this->FalseResponse(__FUNCTION__);
|
||||
}
|
||||
|
||||
$sId = \trim($this->GetActionParam('ID', ''));
|
||||
if (empty($sId))
|
||||
{
|
||||
throw new ClientException(Notifications::UnknownError);
|
||||
}
|
||||
|
||||
$oTemplate = false;
|
||||
$aTemplates = $this->GetTemplates($oAccount);
|
||||
|
||||
foreach ($aTemplates as $oItem)
|
||||
{
|
||||
if ($oItem && $sId === $oItem->Id())
|
||||
{
|
||||
$oTemplate = $oItem;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$oTemplate->SetPopulateAlways(true);
|
||||
return $this->DefaultResponse(__FUNCTION__, $oTemplate);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \MailSo\Base\Exceptions\Exception
|
||||
*/
|
||||
public function DoTemplates() : array
|
||||
{
|
||||
$oAccount = $this->getAccountFromToken();
|
||||
|
||||
if (!$this->GetCapa(false, Capa::TEMPLATES, $oAccount))
|
||||
{
|
||||
return $this->FalseResponse(__FUNCTION__);
|
||||
}
|
||||
|
||||
return $this->DefaultResponse(__FUNCTION__, array(
|
||||
'Templates' => $this->GetTemplates($oAccount)
|
||||
));
|
||||
}
|
||||
|
||||
private function GetTemplates(?Account $oAccount) : array
|
||||
{
|
||||
$aTemplates = array();
|
||||
if ($oAccount)
|
||||
{
|
||||
$aData = array();
|
||||
|
||||
$sData = $this->StorageProvider(true)->Get($oAccount,
|
||||
\RainLoop\Providers\Storage\Enumerations\StorageType::CONFIG,
|
||||
'templates'
|
||||
);
|
||||
|
||||
if ('' !== $sData && '[' === \substr($sData, 0, 1))
|
||||
{
|
||||
$aData = \json_decode($sData, true);
|
||||
}
|
||||
|
||||
if (\is_array($aData) && 0 < \count($aData))
|
||||
{
|
||||
foreach ($aData as $aItem)
|
||||
{
|
||||
$oItem = new Template();
|
||||
$oItem->FromJSON($aItem);
|
||||
|
||||
if ($oItem && $oItem->Validate())
|
||||
{
|
||||
\array_push($aTemplates, $oItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (1 < \count($aTemplates))
|
||||
{
|
||||
$sOrder = $this->StorageProvider()->Get($oAccount,
|
||||
\RainLoop\Providers\Storage\Enumerations\StorageType::CONFIG,
|
||||
'templates_order'
|
||||
);
|
||||
|
||||
$aOrder = empty($sOrder) ? array() : \json_decode($sOrder, true);
|
||||
if (\is_array($aOrder) && 1 < \count($aOrder))
|
||||
{
|
||||
\usort($aTemplates, function ($a, $b) use ($aOrder) {
|
||||
return \array_search($a->Id(), $aOrder) < \array_search($b->Id(), $aOrder) ? -1 : 1;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $aTemplates;
|
||||
}
|
||||
|
||||
private function GetTemplateByID(Account $oAccount, string $sID) : ?\RainLoop\Model\Identity
|
||||
{
|
||||
$aTemplates = $this->GetTemplates($oAccount);
|
||||
foreach ($aTemplates as $oIdentity)
|
||||
{
|
||||
if ($oIdentity && $sID === $oIdentity->Id())
|
||||
{
|
||||
return $oIdentity;
|
||||
}
|
||||
}
|
||||
|
||||
return isset($aTemplates[0]) ? $aTemplates[0] : null;
|
||||
}
|
||||
|
||||
private function SetTemplates(Account $oAccount, array $aTemplates = array()) : bool
|
||||
{
|
||||
$aResult = array();
|
||||
foreach ($aTemplates as $oItem)
|
||||
{
|
||||
$aResult[] = $oItem->ToSimpleJSON();
|
||||
}
|
||||
|
||||
return $this->StorageProvider(true)->Put($oAccount,
|
||||
\RainLoop\Providers\Storage\Enumerations\StorageType::CONFIG,
|
||||
'templates',
|
||||
\json_encode($aResult)
|
||||
);
|
||||
}
|
||||
}
|
|
@ -14,6 +14,7 @@ trait User
|
|||
use Filters;
|
||||
use Folders;
|
||||
use Messages;
|
||||
use Templates;
|
||||
|
||||
/**
|
||||
* @throws \MailSo\Base\Exceptions\Exception
|
||||
|
|
|
@ -194,6 +194,7 @@ class Application extends \RainLoop\Config\AbstractConfig
|
|||
'reload' => array(true),
|
||||
'search' => array(true),
|
||||
'search_adv' => array(true),
|
||||
'x-templates' => array(false),
|
||||
'dangerous_actions' => array(true),
|
||||
'message_actions' => array(true),
|
||||
'messagelist_actions' => array(true),
|
||||
|
|
106
snappymail/v/0.0.0/app/libraries/RainLoop/Model/Template.php
Normal file
106
snappymail/v/0.0.0/app/libraries/RainLoop/Model/Template.php
Normal file
|
@ -0,0 +1,106 @@
|
|||
<?php
|
||||
|
||||
namespace RainLoop\Model;
|
||||
|
||||
class Template implements \JsonSerializable
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $sId;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $sName;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $sBody;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $bPopulateAlways;
|
||||
|
||||
function __construct(string $sId = '', string $sName = '', string $sBody = '')
|
||||
{
|
||||
$this->sId = $sId;
|
||||
$this->sName = $sName;
|
||||
$this->sBody = $sBody;
|
||||
$this->bPopulateAlways = false;
|
||||
}
|
||||
|
||||
public function Id() : string
|
||||
{
|
||||
return $this->sId;
|
||||
}
|
||||
|
||||
public function Name() : string
|
||||
{
|
||||
return $this->sName;
|
||||
}
|
||||
|
||||
public function Body() : string
|
||||
{
|
||||
return $this->sBody;
|
||||
}
|
||||
|
||||
public function SetPopulateAlways(bool $bPopulateAlways)
|
||||
{
|
||||
$this->bPopulateAlways = $bPopulateAlways;
|
||||
}
|
||||
|
||||
public function FromJSON(array $aData, bool $bJson = false) : bool
|
||||
{
|
||||
if (isset($aData['ID'], $aData['Name'], $aData['Body']))
|
||||
{
|
||||
$this->sId = $aData['ID'];
|
||||
$this->sName = $aData['Name'];
|
||||
$this->sBody = $aData['Body'];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function ToSimpleJSON() : array
|
||||
{
|
||||
return array(
|
||||
'ID' => $this->Id(),
|
||||
'Name' => $this->Name(),
|
||||
'Body' => $this->Body()
|
||||
);
|
||||
}
|
||||
|
||||
public function jsonSerialize()
|
||||
{
|
||||
$sBody = $this->Body();
|
||||
$bPopulated = true;
|
||||
if ($bPopulated && !$this->bPopulateAlways) {
|
||||
if (1024 * 5 < \strlen($sBody) || true) {
|
||||
$bPopulated = false;
|
||||
$sBody = '';
|
||||
}
|
||||
}
|
||||
return array(
|
||||
'@Object' => 'Object/Template',
|
||||
'id' => $this->Id(),
|
||||
'name' => $this->Name(),
|
||||
'body' => $sBody,
|
||||
'populated' => $bPopulated
|
||||
);
|
||||
}
|
||||
|
||||
public function GenerateID() : bool
|
||||
{
|
||||
return $this->sId = \MailSo\Base\Utils::Md5Rand();
|
||||
}
|
||||
|
||||
public function Validate() : bool
|
||||
{
|
||||
return 0 < \strlen($this->sBody);
|
||||
}
|
||||
}
|
|
@ -32,6 +32,7 @@
|
|||
"LABEL_ATTACHMENT_SIZE_LIMIT": "Größenlimit für Anhänge",
|
||||
"LABEL_ALLOW_ADDITIONAL_ACCOUNTS": "Zusätzliche Konten erlauben",
|
||||
"LABEL_ALLOW_IDENTITIES": "Mehrere Identitäten erlauben",
|
||||
"LABEL_ALLOW_TEMPLATES": "Vorlagen erlauben",
|
||||
"ALERT_DATA_ACCESS": "Data folder is accessible. Please configure your web server to hide the data folder from external access. Read more here:",
|
||||
"ALERT_WARNING": "Warnung!",
|
||||
"HTML_ALERT_WEAK_PASSWORD": "Sie verwenden das Standard-Admin-Passwort.\n<br \/>\nBitte <strong><a href=\"#\/security\">ändern<\/a><\/strong> Sie\naus Sicherheitsgründen das Passwort jetzt.\n"
|
||||
|
|
|
@ -355,6 +355,7 @@
|
|||
"LABEL_ACCOUNTS_NAME": "Konten",
|
||||
"LABEL_IDENTITIES_NAME": "Identitäten",
|
||||
"LABEL_FILTERS_NAME": "Filter",
|
||||
"LABEL_TEMPLATES_NAME": "Vorlagen",
|
||||
"LABEL_SECURITY_NAME": "Sicherheit",
|
||||
"LABEL_THEMES_NAME": "Themen"
|
||||
},
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
"LABEL_ATTACHMENT_SIZE_LIMIT": "Attachment size limit",
|
||||
"LABEL_ALLOW_ADDITIONAL_ACCOUNTS": "Allow additional accounts",
|
||||
"LABEL_ALLOW_IDENTITIES": "Allow multiple identities",
|
||||
"LABEL_ALLOW_TEMPLATES": "Allow templates",
|
||||
"ALERT_DATA_ACCESS": "Data folder is accessible. Please configure your web server to hide the data folder from external access. Read more here:",
|
||||
"ALERT_WARNING": "Warning!",
|
||||
"HTML_ALERT_WEAK_PASSWORD": "You are using the default admin password.\n<br \/>\nFor security reasons please\n<strong><a href=\"#\/security\">change<\/a><\/strong>\npassword to something else now.\n"
|
||||
|
|
|
@ -355,6 +355,7 @@
|
|||
"LABEL_ACCOUNTS_NAME": "Accounts",
|
||||
"LABEL_IDENTITIES_NAME": "Identities",
|
||||
"LABEL_FILTERS_NAME": "Filters",
|
||||
"LABEL_TEMPLATES_NAME": "Templates",
|
||||
"LABEL_SECURITY_NAME": "Security",
|
||||
"LABEL_THEMES_NAME": "Themes"
|
||||
},
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
"LABEL_ATTACHMENT_SIZE_LIMIT": "Tamaño máximo para adjuntos",
|
||||
"LABEL_ALLOW_ADDITIONAL_ACCOUNTS": "Permitir cuentas adicionales",
|
||||
"LABEL_ALLOW_IDENTITIES": "Permitir múltiples identidades",
|
||||
"LABEL_ALLOW_TEMPLATES": "Permitir plantillas",
|
||||
"ALERT_DATA_ACCESS": "Data folder is accessible. Please configure your web server to hide the data folder from external access. Read more here:",
|
||||
"ALERT_WARNING": "¡Atención!",
|
||||
"HTML_ALERT_WEAK_PASSWORD": "Estas utilizando la contraseña por defecto.\n<br \/>\nDebido a razones de seguridad, debes\n<strong><a href=\"#\/security\">cambiar<\/a><\/strong>\ntu contraseña inmediatamente.\n"
|
||||
|
|
|
@ -355,6 +355,7 @@
|
|||
"LABEL_ACCOUNTS_NAME": "Cuentas",
|
||||
"LABEL_IDENTITIES_NAME": "Identidades",
|
||||
"LABEL_FILTERS_NAME": "Filtros",
|
||||
"LABEL_TEMPLATES_NAME": "Plantillas",
|
||||
"LABEL_SECURITY_NAME": "Seguridad",
|
||||
"LABEL_THEMES_NAME": "Temas"
|
||||
},
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
"LABEL_ATTACHMENT_SIZE_LIMIT": "Taille limite des pièces jointes",
|
||||
"LABEL_ALLOW_ADDITIONAL_ACCOUNTS": "Autoriser les comptes supplémentaires",
|
||||
"LABEL_ALLOW_IDENTITIES": "Autoriser les identités multiples",
|
||||
"LABEL_ALLOW_TEMPLATES": "Autoriser les modèles",
|
||||
"ALERT_DATA_ACCESS": "Data folder is accessible. Please configure your web server to hide the data folder from external access. Read more here:",
|
||||
"ALERT_WARNING": "ATTENTION !",
|
||||
"HTML_ALERT_WEAK_PASSWORD": "Vous utilisez le mot de passe administrateur par défaut.\n<br \/>\nPour des raisons de sécurité, veuillez\n<strong><a href=\"#\/security\">changer le mot de passe <\/a><\/strong>\ndès maintenant.\n"
|
||||
|
|
|
@ -355,6 +355,7 @@
|
|||
"LABEL_ACCOUNTS_NAME": "Comptes",
|
||||
"LABEL_IDENTITIES_NAME": "Identités",
|
||||
"LABEL_FILTERS_NAME": "Filtres",
|
||||
"LABEL_TEMPLATES_NAME": "Modèles",
|
||||
"LABEL_SECURITY_NAME": "Sécurité",
|
||||
"LABEL_THEMES_NAME": "Thèmes"
|
||||
},
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
"LABEL_ATTACHMENT_SIZE_LIMIT": "Melléklet méret korlát",
|
||||
"LABEL_ALLOW_ADDITIONAL_ACCOUNTS": "További fiókok engedélyezése",
|
||||
"LABEL_ALLOW_IDENTITIES": "Több identitás engedélyezése",
|
||||
"LABEL_ALLOW_TEMPLATES": "Sablonok engedélyezése",
|
||||
"ALERT_DATA_ACCESS": "A RainLoop adatmappája hozzáférhető. Kérlek állítsd be úgy a webszervert, hogy az adatmappát rejtse el a külső hozzáférés elől. További tudnivalók itt:",
|
||||
"ALERT_WARNING": "Figyelmeztetés!",
|
||||
"HTML_ALERT_WEAK_PASSWORD": "Az alapértelmezett admin jelszót használod\n<br \/>\nBiztonsági okokból kérlek\n<strong><a href=\"#\/security\">változtasd meg<\/a><\/strong>\na jelszót valami másra!\n"
|
||||
|
|
|
@ -355,6 +355,7 @@
|
|||
"LABEL_ACCOUNTS_NAME": "Fiókok",
|
||||
"LABEL_IDENTITIES_NAME": "Identitások",
|
||||
"LABEL_FILTERS_NAME": "Szűrők",
|
||||
"LABEL_TEMPLATES_NAME": "Sablonok",
|
||||
"LABEL_SECURITY_NAME": "Biztonság",
|
||||
"LABEL_THEMES_NAME": "Témák"
|
||||
},
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
"LABEL_ATTACHMENT_SIZE_LIMIT": "Maximale bijlage grootte",
|
||||
"LABEL_ALLOW_ADDITIONAL_ACCOUNTS": "Sta extra accounts toe",
|
||||
"LABEL_ALLOW_IDENTITIES": "Meerdere identiteiten toestaan",
|
||||
"LABEL_ALLOW_TEMPLATES": "Sta templates toe",
|
||||
"ALERT_DATA_ACCESS": "Data folder is accessible. Please configure your web server to hide the data folder from external access. Read more here:",
|
||||
"ALERT_WARNING": "Waarschuwing!",
|
||||
"HTML_ALERT_WEAK_PASSWORD": "U gebruikt het standaard beheer wachtwoord.\n<br \/>\n<strong><a href=\"#\/security\">Wijzig<\/a><\/strong>\na.u.b. voor uw veiligheid direct het wachtwoord.\n"
|
||||
|
|
|
@ -355,6 +355,7 @@
|
|||
"LABEL_ACCOUNTS_NAME": "Accounts",
|
||||
"LABEL_IDENTITIES_NAME": "Identiteiten",
|
||||
"LABEL_FILTERS_NAME": "Filters",
|
||||
"LABEL_TEMPLATES_NAME": "Templates",
|
||||
"LABEL_SECURITY_NAME": "Beveiliging",
|
||||
"LABEL_THEMES_NAME": "Thema's"
|
||||
},
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
"LABEL_ATTACHMENT_SIZE_LIMIT": "Bilagor storlek",
|
||||
"LABEL_ALLOW_ADDITIONAL_ACCOUNTS": "Tillåt ytterligare konton",
|
||||
"LABEL_ALLOW_IDENTITIES": "Tillåt multiidentiteter",
|
||||
"LABEL_ALLOW_TEMPLATES": "Tillåt mallar",
|
||||
"ALERT_DATA_ACCESS": "RainLoops datamapp är åtkomstbar. Var vänlig konfigurera din webb-server för att förhindra extern åtkomst och synlighet. Läs mer här: ",
|
||||
"ALERT_WARNING": "Varning!",
|
||||
"HTML_ALERT_WEAK_PASSWORD": "Du använder standardlösenord.\n<br \/>\nFör säkerhetsskäl\n<strong><a href=\"#\/security\">ändra<\/a><\/strong>\nlösenord till något annat\n"
|
||||
|
|
|
@ -355,6 +355,7 @@
|
|||
"LABEL_ACCOUNTS_NAME": "Konton",
|
||||
"LABEL_IDENTITIES_NAME": "Identiteter",
|
||||
"LABEL_FILTERS_NAME": "Filter",
|
||||
"LABEL_TEMPLATES_NAME": "Templates",
|
||||
"LABEL_SECURITY_NAME": "Säkerhet",
|
||||
"LABEL_THEMES_NAME": "Teman"
|
||||
},
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
"LABEL_ATTACHMENT_SIZE_LIMIT": "附件大小限制",
|
||||
"LABEL_ALLOW_ADDITIONAL_ACCOUNTS": "允许额外的账户",
|
||||
"LABEL_ALLOW_IDENTITIES": "允许多重身份",
|
||||
"LABEL_ALLOW_TEMPLATES": "允许使用模板",
|
||||
"ALERT_DATA_ACCESS": "数据文件夹可被访问。请配置您的 Web 服务器以阻止从外部访问数据文件夹。获取更多帮助:",
|
||||
"ALERT_WARNING": "警告!",
|
||||
"HTML_ALERT_WEAK_PASSWORD": "您正在使用默认的管理员密码\n<br \/>\n安全起见,请立即将密码\n<strong><a href=\"#\/security\">更改<\/a><\/strong>\n为其他的字符串。\n"
|
||||
|
|
|
@ -355,6 +355,7 @@
|
|||
"LABEL_ACCOUNTS_NAME": "账户",
|
||||
"LABEL_IDENTITIES_NAME": "身份",
|
||||
"LABEL_FILTERS_NAME": "筛选条件",
|
||||
"LABEL_TEMPLATES_NAME": "模版",
|
||||
"LABEL_SECURITY_NAME": "安全",
|
||||
"LABEL_THEMES_NAME": "主题"
|
||||
},
|
||||
|
|
|
@ -128,5 +128,18 @@
|
|||
}"></div>
|
||||
</div>
|
||||
</div>
|
||||
<!--
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
<div data-bind="component: {
|
||||
name: 'Checkbox',
|
||||
params: {
|
||||
label: 'TAB_GENERAL/LABEL_ALLOW_TEMPLATES',
|
||||
value: capaTemplates
|
||||
}
|
||||
}"></div>
|
||||
</div>
|
||||
</div>
|
||||
-->
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
<div class="modal fade b-template-add-content" data-bind="modal: modalVisibility">
|
||||
<div class="modal-header g-ui-user-select-none">
|
||||
<button type="button" class="close" data-bind="command: cancelCommand">×</button>
|
||||
<h3>
|
||||
<span data-bind="visible: '' === id()" data-i18n="POPUPS_ADD_TEMPLATE/TITLE_ADD_TEMPLATE"></span>
|
||||
<span data-bind="visible: '' !== id()" data-i18n="POPUPS_ADD_TEMPLATE/TITLE_UPDATE_TEMPLATE"></span>
|
||||
</h3>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="form-horizontal g-ui-user-select-none">
|
||||
<div class="alert" data-bind="visible: '' !== submitError()">
|
||||
<button type="button" class="close" data-bind="click: function () { submitError('') }">×</button>
|
||||
<span data-bind="text: submitError"></span>
|
||||
</div>
|
||||
<br />
|
||||
<div class="control-group" data-bind="css: {'error': nameError}">
|
||||
<label class="control-label" data-i18n="GLOBAL/NAME"></label>
|
||||
<div class="controls">
|
||||
<input type="text" class="inputName input-xlarge"
|
||||
autofocus="" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"
|
||||
data-bind="textInput: name, onEnter: addTemplateCommand" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<hr />
|
||||
<div class="form-horizontal">
|
||||
<div class="control-group" data-bind="css: {'error': bodyError}">
|
||||
<div class="e-template-place" data-bind="initDom: signatureDom"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<a class="btn buttonAddAccount" data-bind="command: addTemplateCommand">
|
||||
<i data-bind="visible: '' == id(), css: {'icon-user-add': !submitRequest(), 'icon-spinner': submitRequest()}"></i>
|
||||
<span data-bind="visible: '' == id()" data-i18n="POPUPS_ADD_TEMPLATE/BUTTON_ADD_TEMPLATE"></span>
|
||||
<i data-bind="visible: '' !== id(), css: {'icon-ok': !submitRequest(), 'icon-spinner': submitRequest()}"></i>
|
||||
<span data-bind="visible: '' !== id()" data-i18n="POPUPS_ADD_TEMPLATE/BUTTON_UPDATE_TEMPLATE"></span>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
|
@ -0,0 +1,28 @@
|
|||
<div class="b-settings-templates g-ui-user-select-none">
|
||||
<div class="legend">
|
||||
<span data-i18n="SETTINGS_TEMPLATES/LEGEND_TEMPLATES"></span>
|
||||
|
||||
<i class="icon-spinner" style="margin-top: 5px" data-bind="visible: templates.loading"></i>
|
||||
</div>
|
||||
<a class="btn" data-bind="click: addNewTemplate">
|
||||
<i class="icon-user-add"></i>
|
||||
<span data-i18n="SETTINGS_TEMPLATES/BUTTON_ADD_TEMPLATE"></span>
|
||||
</a>
|
||||
<table class="table table-hover list-table templates-list" data-bind="i18nUpdate: templates">
|
||||
<tbody data-bind="foreach: templates">
|
||||
<tr draggable="true" data-bind="sortableItem: { list: $root.templates }">
|
||||
<td class="e-action">
|
||||
<i class="fontastic drag-handle">⬍</i>
|
||||
<span class="template-name" data-bind="text: name"></span>
|
||||
</td>
|
||||
<td>
|
||||
<a class="btn btn-small btn-small-small btn-danger pull-right button-confirm-delete button-delete-transitions" data-bind="css: {'delete-access': deleteAccess}, click: function(oTemplate) { $root.deleteTemplate(oTemplate); }"
|
||||
data-i18n="GLOBAL/ARE_YOU_SURE"></a>
|
||||
</td>
|
||||
<td>
|
||||
<span class="delete-template fontastic" data-bind="visible: !deleteAccess(), click: function (oTemplate) { $root.templateForDeletion(oTemplate); }">🗑</span>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
Loading…
Reference in a new issue