mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-01 21:49:21 +03:00
Plugin system enhancements (Custom user's settings tabs)
This commit is contained in:
parent
a3f28b09f6
commit
9a58fd0a66
13 changed files with 398 additions and 16 deletions
20
plugins/custom-settings-tab/LICENSE
Normal file
20
plugins/custom-settings-tab/LICENSE
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 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.
|
||||
1
plugins/custom-settings-tab/VERSION
Normal file
1
plugins/custom-settings-tab/VERSION
Normal file
|
|
@ -0,0 +1 @@
|
|||
1.0
|
||||
57
plugins/custom-settings-tab/index.php
Normal file
57
plugins/custom-settings-tab/index.php
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
class CustomSettingsTabPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||
{
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function Init()
|
||||
{
|
||||
$this->UseLangs(true); // start use langs folder
|
||||
|
||||
$this->addJs('js/CustomUserSettings.js'); // add js file
|
||||
|
||||
$this->addAjaxHook('AjaxGetCustomUserData', 'AjaxGetCustomUserData');
|
||||
$this->addAjaxHook('AjaxSaveCustomUserData', 'AjaxSaveCustomUserData');
|
||||
|
||||
$this->addTemplate('templates/PluginCustomSettingsTag.html');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function AjaxGetCustomUserData()
|
||||
{
|
||||
$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->ajaxResponse(__FUNCTION__, array(
|
||||
'UserFacebook' => $sUserFacebook,
|
||||
'UserSkype' => $sUserSkype
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function AjaxSaveCustomUserData()
|
||||
{
|
||||
$sUserFacebook = $this->ajaxParam('UserFacebook');
|
||||
$sUserSkype = $this->ajaxParam('UserSkype');
|
||||
|
||||
// or put user's data to your custom storage ( DB / LDAP / ... ).
|
||||
|
||||
\sleep(1);
|
||||
return $this->ajaxResponse(__FUNCTION__, $this->saveUserSettings(array(
|
||||
'UserFacebook' => $sUserFacebook,
|
||||
'UserSkype' => $sUserSkype
|
||||
)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
73
plugins/custom-settings-tab/js/CustomUserSettings.js
Normal file
73
plugins/custom-settings-tab/js/CustomUserSettings.js
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
|
||||
(function () {
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function CustomUserSettings()
|
||||
{
|
||||
this.userSkype = ko.observable('');
|
||||
this.userFacebook = ko.observable('');
|
||||
|
||||
this.loading = ko.observable(false);
|
||||
this.saving = ko.observable(false);
|
||||
|
||||
this.savingOrLoading = ko.computed(function () {
|
||||
return this.loading() || this.saving();
|
||||
}, this);
|
||||
}
|
||||
|
||||
CustomUserSettings.prototype.customAjaxSaveData = function ()
|
||||
{
|
||||
var self = this;
|
||||
|
||||
if (this.saving())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
this.saving(true);
|
||||
|
||||
window.rl.pluginRemoteRequest(function (sResult, oData) {
|
||||
|
||||
self.saving(false);
|
||||
|
||||
if (window.rl.Enums.StorageResultType.Success === sResult && oData && oData.Result)
|
||||
{
|
||||
// true
|
||||
}
|
||||
else
|
||||
{
|
||||
// false
|
||||
}
|
||||
|
||||
}, 'AjaxSaveCustomUserData', {
|
||||
'UserSkype': this.userSkype(),
|
||||
'UserFacebook': this.userFacebook()
|
||||
});
|
||||
};
|
||||
|
||||
CustomUserSettings.prototype.onBuild = function () // special function
|
||||
{
|
||||
var self = this;
|
||||
|
||||
this.loading(true);
|
||||
|
||||
window.rl.pluginRemoteRequest(function (sResult, oData) {
|
||||
|
||||
self.loading(false);
|
||||
|
||||
if (window.rl.Enums.StorageResultType.Success === sResult && oData && oData.Result)
|
||||
{
|
||||
self.userSkype(oData.Result.UserSkype || '');
|
||||
self.userFacebook(oData.Result.UserFacebook || '');
|
||||
}
|
||||
|
||||
}, 'AjaxGetCustomUserData');
|
||||
|
||||
};
|
||||
|
||||
window.rl.addSettingsViewModel(CustomUserSettings, 'PluginCustomSettingsTag',
|
||||
'SETTINGS_CUSTOM_PLUGIN/TAB_NAME', 'custom');
|
||||
|
||||
}());
|
||||
6
plugins/custom-settings-tab/langs/en.ini
Normal file
6
plugins/custom-settings-tab/langs/en.ini
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
[SETTINGS_CUSTOM_PLUGIN]
|
||||
TAB_NAME = "Custom Plugin"
|
||||
LEGEND_CUSTOM = "Custom Plugin (Example)"
|
||||
LABEL_SKYPE = "Skype"
|
||||
LABEL_FACEBOOK = "Facebook"
|
||||
BUTTON_SAVE = "Save"
|
||||
6
plugins/custom-settings-tab/langs/ru.ini
Normal file
6
plugins/custom-settings-tab/langs/ru.ini
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
[SETTINGS_CUSTOM_PLUGIN]
|
||||
TAB_NAME = "Плагин"
|
||||
LEGEND_CUSTOM = "Плагин (Пример)"
|
||||
LABEL_SKYPE = "Skype"
|
||||
LABEL_FACEBOOK = "Facebook"
|
||||
BUTTON_SAVE = "Сохранить"
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
<div>
|
||||
<div class="form-horizontal">
|
||||
<div class="legend">
|
||||
<span class="i18n" data-i18n-text="SETTINGS_CUSTOM_PLUGIN/LEGEND_CUSTOM"></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-text="SETTINGS_CUSTOM_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-text="SETTINGS_CUSTOM_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: customAjaxSaveData, enable: !savingOrLoading()">
|
||||
<i data-bind="css: {'icon-floppy': !saving(), 'icon-spinner animated': saving()}" class="icon-floppy"></i>
|
||||
|
||||
<span class="i18n" data-i18n-text="SETTINGS_CUSTOM_PLUGIN/BUTTON_SAVE"></span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
Loading…
Add table
Add a link
Reference in a new issue