mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-29 20:19:22 +03:00
Merge all example plugins
This commit is contained in:
parent
f588c91570
commit
eb61563db4
23 changed files with 230 additions and 425 deletions
20
plugins/example/LICENSE
Normal file
20
plugins/example/LICENSE
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 RainLoop Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
|
@ -31,6 +31,22 @@ class ExamplePlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
$this->addTemplate(string $sFile, bool $bAdminScope = false);
|
||||
$this->addTemplateHook(string $sName, string $sPlace, string $sLocalTemplateName, bool $bPrepend = false);
|
||||
*/
|
||||
|
||||
// $this->addHook('login.credentials', 'FilterLoginCredentials');
|
||||
|
||||
|
||||
$this->UseLangs(true); // start use langs folder
|
||||
|
||||
// User Settings tab
|
||||
$this->addJs('js/ExampleUserSettings.js'); // add js file
|
||||
$this->addJsonHook('JsonGetExampleUserData', 'JsonGetExampleUserData');
|
||||
$this->addJsonHook('JsonSaveExampleUserData', 'JsonSaveExampleUserData');
|
||||
$this->addTemplate('templates/ExampleUserSettingsTab.html');
|
||||
|
||||
// Admin Settings tab
|
||||
$this->addJs('js/ExampleAdminSettings.js', true); // add js file
|
||||
$this->addJsonHook('JsonAdminGetData', 'JsonAdminGetData');
|
||||
$this->addTemplate('templates/ExampleAdminSettingsTab.html', true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -61,6 +77,77 @@ class ExamplePlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
}
|
||||
}
|
||||
|
||||
public function JsonAdminGetData()
|
||||
{
|
||||
return $this->jsonResponse(__FUNCTION__, array(
|
||||
'PHP' => \phpversion()
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sEmail
|
||||
* @param string $sLogin
|
||||
* @param string $sPassword
|
||||
*
|
||||
* @throws \RainLoop\Exceptions\ClientException
|
||||
*/
|
||||
public function FilterLoginCredentials(&$sEmail, &$sLogin, &$sPassword)
|
||||
{
|
||||
// Your custom php logic
|
||||
// You may change login credentials
|
||||
if ('demo@snappymail.eu' === $sEmail)
|
||||
{
|
||||
$sEmail = 'user@snappymail.eu';
|
||||
$sLogin = 'user@snappymail.eu';
|
||||
$sPassword = 'super-duper-password';
|
||||
}
|
||||
else
|
||||
{
|
||||
// or throw auth exeption
|
||||
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::AuthError);
|
||||
// or
|
||||
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::AccountNotAllowed);
|
||||
// or
|
||||
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::DomainNotAllowed);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function JsonGetExampleUserData()
|
||||
{
|
||||
$aSettings = $this->getUserSettings();
|
||||
|
||||
$sUserFacebook = isset($aSettings['UserFacebook']) ? $aSettings['UserFacebook'] : '';
|
||||
$sUserSkype = isset($aSettings['UserSkype']) ? $aSettings['UserSkype'] : '';
|
||||
|
||||
// or get user's data from your custom storage ( DB / LDAP / ... ).
|
||||
|
||||
\sleep(1);
|
||||
return $this->jsonResponse(__FUNCTION__, array(
|
||||
'UserFacebook' => $sUserFacebook,
|
||||
'UserSkype' => $sUserSkype
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function JsonSaveExampleUserData()
|
||||
{
|
||||
$sUserFacebook = $this->jsonParam('UserFacebook');
|
||||
$sUserSkype = $this->jsonParam('UserSkype');
|
||||
|
||||
// or put user's data to your custom storage ( DB / LDAP / ... ).
|
||||
|
||||
\sleep(1);
|
||||
return $this->jsonResponse(__FUNCTION__, $this->saveUserSettings(array(
|
||||
'UserFacebook' => $sUserFacebook,
|
||||
'UserSkype' => $sUserSkype
|
||||
)));
|
||||
}
|
||||
|
||||
/*
|
||||
public function Config() : \RainLoop\Config\Plugin
|
||||
public function Description() : string
|
||||
|
|
|
|||
37
plugins/example/js/ExampleAdminSettings.js
Normal file
37
plugins/example/js/ExampleAdminSettings.js
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
|
||||
(rl => { if (rl) {
|
||||
|
||||
class ExampleAdminSettings
|
||||
{
|
||||
constructor()
|
||||
{
|
||||
this.php = ko.observable('');
|
||||
this.loading = ko.observable(false);
|
||||
}
|
||||
|
||||
onBuild()
|
||||
{
|
||||
this.loading(true);
|
||||
|
||||
rl.pluginRemoteRequest((iError, oData) => {
|
||||
|
||||
this.loading(false);
|
||||
|
||||
if (iError) {
|
||||
console.error({
|
||||
iError: iError,
|
||||
oData: oData
|
||||
});
|
||||
} else {
|
||||
this.php(oData.Result.PHP || '');
|
||||
}
|
||||
|
||||
}, 'JsonAdminGetData');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
rl.addSettingsViewModelForAdmin(ExampleAdminSettings, 'ExampleAdminSettingsTab',
|
||||
'SETTINGS_EXAMPLE_ADMIN_EXAMPLE_TAB_PLUGIN/TAB_NAME', 'Example');
|
||||
|
||||
}})(window.rl);
|
||||
68
plugins/example/js/ExampleUserSettings.js
Normal file
68
plugins/example/js/ExampleUserSettings.js
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
|
||||
(rl => { if (rl) {
|
||||
|
||||
class ExampleUserSettings
|
||||
{
|
||||
constructor()
|
||||
{
|
||||
this.userSkype = ko.observable('');
|
||||
this.userFacebook = ko.observable('');
|
||||
|
||||
this.loading = ko.observable(false);
|
||||
this.saving = ko.observable(false);
|
||||
|
||||
this.savingOrLoading = ko.computed(() => {
|
||||
return this.loading() || this.saving();
|
||||
});
|
||||
}
|
||||
|
||||
exampleJsonSaveData()
|
||||
{
|
||||
if (!this.saving()) {
|
||||
this.saving(true);
|
||||
|
||||
rl.pluginRemoteRequest((iError, oData) => {
|
||||
|
||||
this.saving(false);
|
||||
|
||||
if (iError) {
|
||||
console.error({
|
||||
iError: iError,
|
||||
oData: oData
|
||||
});
|
||||
} else {
|
||||
console.dir({
|
||||
iError: iError,
|
||||
oData: oData
|
||||
});
|
||||
}
|
||||
|
||||
}, 'JsonSaveExampleUserData', {
|
||||
'UserSkype': this.userSkype(),
|
||||
'UserFacebook': this.userFacebook()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
onBuild()
|
||||
{
|
||||
this.loading(true);
|
||||
|
||||
rl.pluginRemoteRequest((iError, oData) => {
|
||||
|
||||
this.loading(false);
|
||||
|
||||
if (!iError) {
|
||||
self.userSkype(oData.Result.UserSkype || '');
|
||||
self.userFacebook(oData.Result.UserFacebook || '');
|
||||
}
|
||||
|
||||
}, 'JsonGetExampleUserData');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
rl.addSettingsViewModel(ExampleUserSettings, 'ExampleUserSettingsTab',
|
||||
'SETTINGS_EXAMPLE_PLUGIN/TAB_NAME', 'Example');
|
||||
|
||||
}})(window.rl);
|
||||
15
plugins/example/langs/en.json
Normal file
15
plugins/example/langs/en.json
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"SETTINGS_EXAMPLE_ADMIN_EXAMPLE_TAB_PLUGIN": {
|
||||
"TAB_NAME": "Example Extension Tab",
|
||||
"LEGEND_EXAMPLE": "Example Extension Tab (Example)",
|
||||
"LABEL_PHP_VERSION": "PHP version"
|
||||
},
|
||||
"SETTINGS_EXAMPLE_PLUGIN": {
|
||||
"TAB_NAME": "Example Extension",
|
||||
"LEGEND_EXAMPLE": "Example Extension (Example)",
|
||||
"LABEL_PHP_VERSION": "PHP version",
|
||||
"LABEL_SKYPE": "Skype",
|
||||
"LABEL_FACEBOOK": "Facebook",
|
||||
"BUTTON_SAVE": "Save"
|
||||
}
|
||||
}
|
||||
17
plugins/example/templates/ExampleAdminSettingsTab.html
Normal file
17
plugins/example/templates/ExampleAdminSettingsTab.html
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<div>
|
||||
<div class="form-horizontal">
|
||||
<div class="legend">
|
||||
<span class="i18n" data-i18n="SETTINGS_EXAMPLE_ADMIN_EXAMPLE_TAB_PLUGIN/LEGEND_EXAMPLE"></span>
|
||||
|
||||
<i class="icon-spinner animated" style="margin-top: 5px" data-bind="visible: loading"></i>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label">
|
||||
<span class="i18n" data-i18n="SETTINGS_EXAMPLE_ADMIN_EXAMPLE_TAB_PLUGIN/LABEL_PHP_VERSION"></span>
|
||||
</label>
|
||||
<div class="controls" style="padding-top: 5px">
|
||||
<b data-bind="text: php"></b>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
34
plugins/example/templates/ExampleUserSettingsTab.html
Normal file
34
plugins/example/templates/ExampleUserSettingsTab.html
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<div>
|
||||
<div class="form-horizontal">
|
||||
<div class="legend">
|
||||
<span class="i18n" data-i18n="SETTINGS_EXAMPLE_PLUGIN/LEGEND_EXAMPLE"></span>
|
||||
|
||||
<i class="icon-spinner animated" style="margin-top: 5px" data-bind="visible: loading"></i>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label">
|
||||
<span class="i18n" data-i18n="SETTINGS_EXAMPLE_PLUGIN/LABEL_SKYPE"></span>
|
||||
</label>
|
||||
<div class="controls">
|
||||
<input type="text" data-bind="value: userSkype, enable: !savingOrLoading()" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label">
|
||||
<span class="i18n" data-i18n="SETTINGS_EXAMPLE_PLUGIN/LABEL_FACEBOOK"></span>
|
||||
</label>
|
||||
<div class="controls">
|
||||
<input type="text" data-bind="value: userFacebook, enable: !savingOrLoading()" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
<button class="btn" data-bind="click: exampleJsonSaveData, enable: !savingOrLoading()">
|
||||
<i data-bind="css: {'icon-floppy': !saving(), 'icon-spinner animated': saving()}" class="icon-floppy"></i>
|
||||
|
||||
<span class="i18n" data-i18n="SETTINGS_EXAMPLE_PLUGIN/BUTTON_SAVE"></span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
Loading…
Add table
Add a link
Reference in a new issue