Skip to content

Commit

Permalink
Add in the Folders section a textarea for setting up the messages (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
san4op committed Oct 4, 2021
1 parent 33da571 commit ea887ff
Show file tree
Hide file tree
Showing 7 changed files with 256 additions and 69 deletions.
181 changes: 120 additions & 61 deletions folder_info.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,65 +2,124 @@
* Folder Info plugin script
*/

var update_message = function(folder) {
var formating = function(message) {
if( folder in rcmail.env.folder_info_messages_args ) {
switch( typeof rcmail.env.folder_info_messages_args[folder] ) {
case 'number':
case 'string':
message = message.replace('{}', rcmail.env.folder_info_messages_args[folder]);
break;
default:
for(var i=0; i<rcmail.env.folder_info_messages_args[folder].length; i++) {
message = message.replace('{}', rcmail.env.folder_info_messages_args[folder][i]);
}
break;
}
}
return message;
};
if( folder in rcmail.env.folder_info_messages ) {
$('.folder_info > span').html(formating(rcmail.env.folder_info_messages[folder]));
$('.folder_info').show();
if (rcmail.env.skin === 'larry') {
$('.messagelist thead th:first-child').css('border-top-left-radius', '0');
}
} else {
switch( folder ) {
case rcmail.env.trash_mailbox:
$('.folder_info > span').html(formating(rcmail.gettext('trash_message', 'folder_info')));
$('.folder_info').show();
if (rcmail.env.skin === 'larry') {
$('.messagelist thead th:first-child').css('border-top-left-radius', '0');
}
break;
case rcmail.env.junk_mailbox:
$('.folder_info > span').html(formating(rcmail.gettext('junk_message', 'folder_info')));
$('.folder_info').show();
if (rcmail.env.skin === 'larry') {
$('.messagelist thead th:first-child').css('border-top-left-radius', '0');
}
break;
default:
$('.folder_info > span').html('');
$('.folder_info').hide();
if (rcmail.env.skin === 'larry') {
$('.messagelist thead th:first-child').css('border-top-left-radius', '');
}
break;
}
}
};

$('.folder_info').ready(function(){
var folder_info = $('.folder_info');
var folder_info_fixed = folder_info.clone()
.addClass('folder_info_fixed')
.css({ position: 'fixed' });
folder_info.before(folder_info_fixed);
$(window).resize(function(){ folder_info_fixed.width($('#messagelist').width()); });
});
$(function() {
function folder_info_plugin() {
this.base_element;
this.fixed_element;

this.messages = {};
this.args = {};

var ref = this;

this.init = function() {
this.messages = rcmail.env.folder_info_messages;
this.args = rcmail.env.folder_info_messages_args;

this.base_element = $('.folder_info');
this.fixed_element = this.base_element.clone()
.addClass('folder_info_fixed')
.css({position: 'fixed'});
this.base_element.before(this.fixed_element);

rcmail.addEventListener('init', function(event) {
if (event.task === 'mail') {
ref.update(rcmail.env.mailbox);

var splitter;
switch (rcmail.env.skin) {
case 'classic':
case 'larry':
splitter = $('#mailviewsplitterv, #mailviewsplitter2');
break;
case 'elastic':
splitter = $('.column-resizer');
break;
}
console.log(splitter);
if (typeof splitter === 'object' && splitter.length > 0) {
splitter.on('mousedown.folder_info', function() {
$(document).on('mouseup.folder_info', function() { ref.updateUI(); });
});
}
}
else if (event.task === 'settings' && event.action === 'edit-folder') {
rcmail.enable_command('toggle-editor', true);
rcmail.editor_init(rcmail.env.editor_config, 'rcmfd_folder_info_message');
}
});

rcmail.addEventListener('selectfolder', function(event) {
ref.update(event.folder);
});

rcmail.addEventListener('listupdate', function() {
ref.updateUI();
});

rcmail.addEventListener('init', function(evt){ if( evt.task == "mail" ) {update_message(rcmail.env.mailbox);} });
rcmail.addEventListener('selectfolder', function(evt){ update_message(evt.folder); });
rcmail.addEventListener('listupdate', function(evt){ $('.folder_info_fixed').width($('#messagelist').width()); });
window.addEventListener('resize', function() {
ref.updateUI();
});
};

this.format = function(message) {
if (this.folder in this.args) {
switch (typeof this.args[this.folder]) {
case 'number':
case 'string':
message = message.replace('{}', this.args[this.folder]);
break;
case 'object':
for (var i = 0; i < this.args[this.folder].length; i++) {
message = message.replace('{}', this.args[this.folder][i]);
}
break;
}
}
return message;
};

this.update = function(folder) {
this.folder = folder;

if (folder in this.messages) {
if (typeof this.messages[folder] === 'string') {
this.set_message(this.messages[folder]);
}
else {
this.set_message('');
}
}
else switch (folder) {
case rcmail.env.trash_mailbox:
this.set_message(rcmail.gettext('trash_message', 'folder_info'));
break;
case rcmail.env.junk_mailbox:
this.set_message(rcmail.gettext('junk_message', 'folder_info'));
break;
default:
this.set_message('');
break;
}
};

this.updateUI = function() {
this.fixed_element.width($('#messagelist').width());
};

this.set_message = function(message) {
if (message !== '') {
message = this.format(message);
}
$('.folder_info > span').html(message);
$('.folder_info')[message !== '' ? 'show' : 'hide']();
if (rcmail.env.skin === 'larry') {
$('.messagelist thead th:first-child').css('border-top-left-radius', message !== '' ? '0' : '');
}
};
}

var folder_info = new folder_info_plugin();

folder_info.init();
});
92 changes: 86 additions & 6 deletions folder_info.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,30 @@

class folder_info extends rcube_plugin
{
public $task = 'mail';
public $task = 'mail|settings';
private $rc;

function init()
{
$rcmail = rcube::get_instance();
$this->rc = rcube::get_instance();
$this->load_config();

$this->include_stylesheet($this->local_skin_path() . '/folder_info.css');
$this->include_script('folder_info.js');

$this->add_hook('template_object_messages', array($this, 'add_info_message'));
$this->add_texts('localization/', true);

$this->api->output->set_env('folder_info_messages', $rcmail->config->get('folder_info_messages', array()));
$this->api->output->set_env('folder_info_messages_args', $rcmail->config->get('folder_info_messages_args', array()));
switch ($this->rc->task) {
case 'mail':
$this->api->output->set_env('folder_info_messages', $this->rc->config->get('folder_info_messages', array()));
$this->api->output->set_env('folder_info_messages_args', $this->rc->config->get('folder_info_messages_args', array()));
$this->add_hook('template_object_messages', array($this, 'add_info_message'));
break;
case 'settings':
$this->add_hook('folder_form', array($this, 'folder_form'));
$this->add_hook('folder_create', array($this, 'folder_save'));
$this->add_hook('folder_update', array($this, 'folder_save'));
break;
}
}

function add_info_message($data)
Expand All @@ -36,6 +45,77 @@ function add_info_message($data)

return $data;
}

function folder_form($args)
{
$folder = $args['name'];

// load html editor
$this->rc->html_editor('identity'); // using "identity" for minimal editor
$this->api->output->add_label('editorwarning');

// load messages
$messages = $this->rc->config->get('folder_info_messages', array());

// get folder's message
if (isset($messages[$folder])) {
$value = $messages[$folder];
}
else switch ($folder) {
case $this->rc->config->get('trash_mbox'):
$value = $this->gettext('trash_message');
break;
case $this->rc->config->get('junk_mbox'):
$value = $this->gettext('junk_message');
break;
default:
$value = '';
}

// add field: textarea
$field_message = new html_textarea(array(
'id' => 'rcmfd_folder_info_message',
'name' => 'rcmfd_folder_info_message',
'rows' => 6,
'cols' => 40,
'spellcheck' => true,
));
$args['form']['props']['fieldsets']['settings']['content']['folder_info_message'] = array(
'label' => $this->gettext('folder_info_message'),
'value' => $field_message->show($value),
);

// add field: checkbox
$field_htmleditor = new html_checkbox(array(
'id' => 'rcmfd_folder_info_htmleditor',
'name' => 'rcmfd_folder_info_htmleditor',
'value' => '1',
'onclick' => 'return rcmail.command(\'toggle-editor\', {id: \'rcmfd_folder_info_message\', html: this.checked, noconvert: true}, \'\', event)',
));
$args['form']['props']['fieldsets']['settings']['content']['folder_info_htmleditor'] = array(
'label' => $this->gettext('folder_info_htmleditor'),
'value' => $field_htmleditor->show(false),
);

return $args;
}

function folder_save($args)
{
$folder = $args['record']['name'];

// load messages
$messages = $this->rc->config->get('folder_info_messages', array());

// set new message
$message = rcube_utils::get_input_value('rcmfd_folder_info_message', rcube_utils::INPUT_POST, true);
$messages[$folder] = strval($message);

// save messages
$this->rc->user->save_prefs(array('folder_info_messages' => $messages));

return $args;
}
}

?>
4 changes: 3 additions & 1 deletion localization/en_US.inc
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php

$labels = array();
$labels['folder_info_message'] = 'Message above folder';
$labels['folder_info_htmleditor'] = 'Enable HTML editor';
$labels['trash_message'] = 'Messages that have been in Trash more than {} days will be automatically deleted.';
$labels['junk_message'] = 'Messages that have been in Junk more than {} days will be automatically deleted.';

?>
?>
4 changes: 3 additions & 1 deletion localization/ru_RU.inc
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php

$labels = array();
$labels['folder_info_message'] = 'Сообщение над папкой';
$labels['folder_info_htmleditor'] = 'Включить HTML-редактор';
$labels['trash_message'] = 'Письма, находящиеся в корзине более {} дней, будут автоматически удалены.';
$labels['junk_message'] = 'Письма, находящиеся в спаме более {} дней, будут автоматически удалены.';

?>
?>
18 changes: 18 additions & 0 deletions skins/classic/folder_info.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,21 @@
background-color: #F9EDBE;
padding: 2px;
}

.folder_info span p {
margin: 0;
}

.folder_info span p + p {
margin-top: .5em;
}

.folder_info_fixed {
z-index: 1;
}

#rcmfd_folder_info_message {
width: 99%;
min-width: 390px;
font-family: monospace;
}
12 changes: 12 additions & 0 deletions skins/elastic/folder_info.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,15 @@
background-color: #d9f3ff;
padding: 4px;
}

.folder_info span p {
margin: 0;
}

.folder_info span p + p {
margin-top: .5rem;
}

#rcmfd_folder_info_message {
font-family: monospace;
}
14 changes: 14 additions & 0 deletions skins/larry/folder_info.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@
padding: 4px;
}

.folder_info span p {
margin: 0;
}

.folder_info span p + p {
margin-top: .5em;
}

#mainscreencontent.list .folder_info span, #mainscreencontent.desktop .folder_info span {
border-radius: 4px 4px 0 0;
}

#rcmfd_folder_info_message {
width: 99%;
min-width: 390px;
font-family: monospace;
}

0 comments on commit ea887ff

Please sign in to comment.