2011-06-24 20:13:43 +02:00
|
|
|
if (window.rcmail) {
|
|
|
|
rcmail.addEventListener('init', function() {
|
|
|
|
rcmail.set_book_actions();
|
|
|
|
if (rcmail.gui_objects.editform && rcmail.env.action.match(/^plugin\.book/)) {
|
|
|
|
rcmail.enable_command('book-save', true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
rcmail.addEventListener('listupdate', function() {
|
|
|
|
rcmail.set_book_actions();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// (De-)activates address book management commands
|
|
|
|
rcube_webmail.prototype.set_book_actions = function()
|
|
|
|
{
|
|
|
|
var source = this.env.source,
|
|
|
|
sources = this.env.address_sources;
|
|
|
|
|
|
|
|
this.enable_command('book-create', true);
|
|
|
|
this.enable_command('book-edit', 'book-delete', source && sources[source] && sources[source].kolab && sources[source].editable);
|
|
|
|
};
|
|
|
|
|
|
|
|
rcube_webmail.prototype.book_create = function()
|
|
|
|
{
|
|
|
|
this.book_show_contentframe('create');
|
|
|
|
};
|
|
|
|
|
|
|
|
rcube_webmail.prototype.book_edit = function()
|
|
|
|
{
|
|
|
|
this.book_show_contentframe('edit');
|
|
|
|
};
|
|
|
|
|
|
|
|
rcube_webmail.prototype.book_delete = function()
|
|
|
|
{
|
|
|
|
if (this.env.source != '' && confirm(this.get_label('kolab_addressbook.bookdeleteconfirm'))) {
|
|
|
|
var lock = this.set_busy(true, 'kolab_addressbook.bookdeleting');
|
|
|
|
this.http_request('plugin.book', '_act=delete&_source='+urlencode(this.book_realname()), lock);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// displays page with book edit/create form
|
|
|
|
rcube_webmail.prototype.book_show_contentframe = function(action, framed)
|
|
|
|
{
|
|
|
|
var add_url = '', target = window;
|
|
|
|
|
|
|
|
// unselect contact
|
|
|
|
this.contact_list.clear_selection();
|
|
|
|
this.enable_command('edit', 'delete', 'compose', false);
|
|
|
|
|
|
|
|
if (this.env.contentframe && window.frames && window.frames[this.env.contentframe]) {
|
|
|
|
add_url = '&_framed=1';
|
|
|
|
target = window.frames[this.env.contentframe];
|
|
|
|
this.show_contentframe(true);
|
|
|
|
}
|
|
|
|
else if (framed)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (action) {
|
2011-07-29 19:00:43 +02:00
|
|
|
this.lock_frame();
|
2011-06-24 20:13:43 +02:00
|
|
|
this.location_href(this.env.comm_path+'&_action=plugin.book&_act='+action
|
|
|
|
+'&_source='+urlencode(this.book_realname())
|
|
|
|
+add_url, target);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
// submits book create/update form
|
|
|
|
rcube_webmail.prototype.book_save = function()
|
|
|
|
{
|
|
|
|
var form = this.gui_objects.editform,
|
|
|
|
input = $("input[name='_name']", form)
|
|
|
|
|
|
|
|
if (input.length && input.val() == '') {
|
|
|
|
alert(this.get_label('kolab_addressbook.nobooknamewarning'));
|
|
|
|
input.focus();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
input = this.display_message(this.get_label('kolab_addressbook.booksaving'), 'loading');
|
|
|
|
$('<input type="hidden" name="_unlock" />').val(input).appendTo(form);
|
|
|
|
|
|
|
|
form.submit();
|
|
|
|
};
|
|
|
|
|
|
|
|
// action executed after book delete
|
2013-05-28 15:52:24 +02:00
|
|
|
rcube_webmail.prototype.book_delete_done = function(id, recur)
|
2011-06-24 20:13:43 +02:00
|
|
|
{
|
2013-05-28 15:52:24 +02:00
|
|
|
var n, groups = this.env.contactgroups,
|
|
|
|
sources = this.env.address_sources,
|
|
|
|
olddata = sources[id];
|
2013-06-07 10:41:30 +02:00
|
|
|
|
2013-05-28 15:52:24 +02:00
|
|
|
this.treelist.remove(id);
|
2011-06-24 20:13:43 +02:00
|
|
|
|
|
|
|
for (n in groups)
|
2013-05-28 15:52:24 +02:00
|
|
|
if (groups[n].source == id) {
|
2011-06-24 20:13:43 +02:00
|
|
|
delete this.env.contactgroups[n];
|
2013-05-28 15:52:24 +02:00
|
|
|
delete this.env.contactfolders[n];
|
2011-06-24 20:13:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
delete this.env.address_sources[id];
|
|
|
|
delete this.env.contactfolders[id];
|
2013-05-28 15:52:24 +02:00
|
|
|
|
|
|
|
if (recur)
|
|
|
|
return;
|
|
|
|
|
2013-06-07 10:39:35 +02:00
|
|
|
this.enable_command('group-create', 'book-edit', 'book-delete', false);
|
|
|
|
|
2013-05-28 15:52:24 +02:00
|
|
|
// remove subfolders
|
|
|
|
olddata.realname += this.env.delimiter;
|
|
|
|
for (n in sources)
|
|
|
|
if (sources[n].realname && sources[n].realname.indexOf(olddata.realname) == 0)
|
|
|
|
this.book_delete_done(n, true);
|
2011-06-24 20:13:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// action executed after book create/update
|
2013-05-28 15:52:24 +02:00
|
|
|
rcube_webmail.prototype.book_update = function(data, old, recur)
|
2011-06-24 20:13:43 +02:00
|
|
|
{
|
2013-05-28 15:52:24 +02:00
|
|
|
var n, i, id, len, link, row, prop, olddata, oldid, name, sources, level,
|
|
|
|
folders = [], classes = ['addressbook'],
|
2011-06-24 20:13:43 +02:00
|
|
|
groups = this.env.contactgroups;
|
|
|
|
|
|
|
|
this.env.contactfolders[data.id] = this.env.address_sources[data.id] = data;
|
|
|
|
this.show_contentframe(false);
|
|
|
|
|
2013-05-28 15:52:24 +02:00
|
|
|
// update (remove old row)
|
2011-06-24 20:13:43 +02:00
|
|
|
if (old && old != data.id) {
|
|
|
|
olddata = this.env.address_sources[old];
|
|
|
|
delete this.env.address_sources[old];
|
|
|
|
delete this.env.contactfolders[old];
|
2013-05-28 15:52:24 +02:00
|
|
|
this.treelist.remove(old);
|
2011-06-24 20:13:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sources = this.env.address_sources;
|
|
|
|
|
|
|
|
// set row attributes
|
|
|
|
if (data.readonly)
|
2013-05-28 15:52:24 +02:00
|
|
|
classes.push('readonly');
|
2011-06-27 17:53:10 +02:00
|
|
|
if (data.class_name)
|
2013-05-28 15:52:24 +02:00
|
|
|
classes.push(data.class_name);
|
2011-06-24 20:13:43 +02:00
|
|
|
// updated currently selected book
|
|
|
|
if (this.env.source != '' && this.env.source == old) {
|
2013-05-28 15:52:24 +02:00
|
|
|
classes.push('selected');
|
2011-06-24 20:13:43 +02:00
|
|
|
this.env.source = data.id;
|
|
|
|
}
|
|
|
|
|
2013-05-28 15:52:24 +02:00
|
|
|
link = $('<a>').html(data.name)
|
|
|
|
.attr({
|
|
|
|
href: '#', rel: data.id,
|
|
|
|
onclick: "return rcmail.command('list', '" + data.id + "', this)"
|
|
|
|
});
|
|
|
|
|
|
|
|
// add row at the end of the list
|
|
|
|
// treelist widget is not very smart, we need
|
|
|
|
// to do sorting and add groups list by ourselves
|
|
|
|
this.treelist.insert({id: data.id, html:link, classes: classes, childlistclass: 'groups'}, '', false);
|
|
|
|
row = $(this.treelist.get_item(data.id));
|
|
|
|
row.append($('<ul class="groups">').hide());
|
|
|
|
|
|
|
|
// we need to sort rows because treelist can't sort by property
|
|
|
|
$.each(sources, function(i, v) {
|
|
|
|
if (v.kolab && v.realname)
|
|
|
|
folders.push(v.realname);
|
|
|
|
});
|
2011-06-24 20:13:43 +02:00
|
|
|
folders.sort();
|
|
|
|
|
|
|
|
for (n=0, len=folders.length; n<len; n++)
|
|
|
|
if (folders[n] == data.realname)
|
|
|
|
break;
|
|
|
|
|
2013-05-28 15:52:24 +02:00
|
|
|
// find the row before and re-insert after it
|
|
|
|
if (n && n < len - 1) {
|
2011-06-24 20:13:43 +02:00
|
|
|
name = folders[n-1];
|
|
|
|
for (n in sources)
|
|
|
|
if (sources[n].realname && sources[n].realname == name) {
|
2013-05-28 15:52:24 +02:00
|
|
|
row.detach().insertAfter(this.treelist.get_item(n));
|
2011-06-24 20:13:43 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (olddata) {
|
2011-11-11 16:54:29 +01:00
|
|
|
// update groups
|
2011-08-18 13:43:25 +02:00
|
|
|
for (n in groups) {
|
|
|
|
if (groups[n].source == old) {
|
2013-05-28 15:52:24 +02:00
|
|
|
prop = groups[n];
|
|
|
|
prop.type = 'group';
|
|
|
|
prop.source = data.id;
|
|
|
|
id = 'G' + prop.source + prop.id;
|
|
|
|
|
|
|
|
link = $('<a>').text(prop.name)
|
|
|
|
.attr({
|
|
|
|
href: '#', rel: prop.source + ':' + prop.id,
|
|
|
|
onclick: "return rcmail.command('listgroup', {source: '"+prop.source+"', id: '"+prop.id+"'}, this)"
|
|
|
|
});
|
|
|
|
|
|
|
|
this.treelist.insert({id:id, html:link, classes:['contactgroup']}, prop.source, true);
|
|
|
|
|
|
|
|
this.env.contactfolders[id] = this.env.contactgroups[id] = prop;
|
2011-08-18 13:43:25 +02:00
|
|
|
delete this.env.contactgroups[n];
|
2013-05-28 15:52:24 +02:00
|
|
|
delete this.env.contactfolders[n];
|
2011-08-18 13:43:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-28 15:52:24 +02:00
|
|
|
if (recur)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// update subfolders
|
|
|
|
old += '_';
|
2011-06-24 20:13:43 +02:00
|
|
|
level = olddata.realname.split(this.env.delimiter).length - data.realname.split(this.env.delimiter).length;
|
2013-05-28 15:52:24 +02:00
|
|
|
olddata.realname += this.env.delimiter;
|
|
|
|
|
2011-06-24 20:13:43 +02:00
|
|
|
for (n in sources) {
|
2013-05-28 15:52:24 +02:00
|
|
|
if (sources[n].realname && sources[n].realname.indexOf(olddata.realname) == 0) {
|
|
|
|
prop = sources[n];
|
|
|
|
oldid = sources[n].id;
|
2011-06-24 20:13:43 +02:00
|
|
|
// new ID
|
2013-05-28 15:52:24 +02:00
|
|
|
prop.id = data.id + '_' + n.substr(old.length);
|
|
|
|
prop.realname = data.realname + prop.realname.substr(olddata.realname.length - 1);
|
|
|
|
name = prop.name;
|
2011-06-24 20:13:43 +02:00
|
|
|
|
|
|
|
// update display name
|
|
|
|
if (level > 0) {
|
|
|
|
for (i=level; i>0; i--)
|
|
|
|
name = name.replace(/^ /, '');
|
|
|
|
}
|
|
|
|
else if (level < 0) {
|
|
|
|
for (i=level; i<0; i++)
|
|
|
|
name = ' ' + name;
|
|
|
|
}
|
|
|
|
|
2013-05-28 15:52:24 +02:00
|
|
|
prop.name = name;
|
|
|
|
this.book_update(prop, oldid, true)
|
2011-06-24 20:13:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// returns real IMAP folder name
|
|
|
|
rcube_webmail.prototype.book_realname = function()
|
|
|
|
{
|
|
|
|
var source = this.env.source, sources = this.env.address_sources;
|
|
|
|
return source != '' && sources[source] && sources[source].realname ? sources[source].realname : '';
|
|
|
|
};
|