1
0
mirror of https://github.com/owncloudarchive/contacts.git synced 2025-01-18 07:52:21 +01:00

code clean in js config dialog

distinction between a ldap addressbook edition and a local addressbook edition in the UI
several bug fixes
This commit is contained in:
babelouest 2014-04-09 13:38:09 -04:00
parent e354d0fae3
commit c674b8db00
10 changed files with 406 additions and 425 deletions

View File

@ -40,7 +40,7 @@ $this->create('contacts_address_book_connectors', 'connectors/{backend}')
function($params) {
\OC::$session->close();
$dispatcher = new Dispatcher($params);
$dispatcher->dispatch('BackendController', 'getLdapConnectors');
$dispatcher->dispatch('BackendController', 'getConnectors');
}
)
->requirements(array('backend'));

View File

@ -68,79 +68,118 @@ OC.Contacts = OC.Contacts || {};
});
});
});
$('#add-address-book-element').on('click keypress', function() {
$('#add-ldap-address-book-element').on('click keypress', function() {
var $rightContent = $('#app-content');
$rightContent.append('<div id="addressbook-ui-dialog"></div>');
var frmDlg = $('#addressbooks-ui').clone().octemplate();
var divDlg = $('#addressbook-ui-dialog');
divDlg.html(frmDlg).ocdialog({
var $dlg = $('#addressBookConfigTemplate').octemplate({backend: 'ldap'});
var $divDlg = $('#addressbook-ui-dialog');
$divDlg.html($dlg).ocdialog({
modal: true,
closeOnEscape: true,
title: t('contacts', 'Add new Addressbook'),
title: t('contacts', 'Add new LDAP Addressbook'),
height: 'auto',
width: 'auto',
buttons: [
{
text: t('contacts', 'Ok'),
click: function() {
OC.Contacts.addressBookDialog.addressbookUiOk(divDlg);
OC.Contacts.otherBackendConfig.addressbookUiOk($divDlg);
},
defaultButton: true
},
{
text: t('contacts', 'Cancel'),
click: function() {
OC.Contacts.addressBookDialog.addressbookUiClose(divDlg);
OC.Contacts.otherBackendConfig.addressbookUiClose($divDlg);
}
}
],
close: function(/*event, ui*/) {
OC.Contacts.addressBookDialog.addressbookUiClose(divDlg);
OC.Contacts.otherBackendConfig.addressbookUiClose($divDlg);
},
open: function(/*event, ui*/) {
OC.Contacts.addressBookDialog.openAddressbookUi();
OC.Contacts.otherBackendConfig.openAddressbookUi();
}
});
});
this.$li.find('a.action.edit').on('click keypress', function(/*event*/) {
this.$li.find('a.action.edit').on('click keypress', function(event) {
$.when(self.storage.getAddressBook(self.getBackend(), self.getId()))
.then(function(response) {
if(!response.error) {
if(response.data) {
var addressbook = response.data;
console.log('addressbook', addressbook);
var $rightContent = $('#app-content');
$rightContent.append('<div id="addressbook-ui-dialog"></div>');
var frmDlg = $('#addressbooks-ui').clone().octemplate();
var divDlg = $('#addressbook-ui-dialog');
divDlg.html(frmDlg).ocdialog({
modal: true,
closeOnEscape: true,
title: t('contacts', 'Edit Addressbook'),
height: 'auto', width: 'auto',
buttons: [
{
text: t('contacts', 'Ok'),
click: function() {
OC.Contacts.addressBookDialog.addressbookUiEditOk(divDlg);
self.setDisplayName($('#addressbooks-ui-name').val());
},
defaultButton: true
},
{
text: t('contacts', 'Cancel'),
click: function() {
OC.Contacts.addressBookDialog.addressbookUiClose(divDlg);
}
}
],
close: function(/*event, ui*/) {
OC.Contacts.addressBookDialog.addressbookUiClose(divDlg);
},
open: function(/*event, ui*/) {
OC.Contacts.addressBookDialog.editAddressbookUI(addressbook);
if (addressbook.backend === 'local') {
if($(this).data('open')) {
return;
}
});
var editor = this;
event.stopPropagation();
event.preventDefault();
var $dropdown = $('<li><div><input type="text" value="{name}" /></div></li>')
.octemplate({name:self.getDisplayName()}).insertAfter(self.$li);
var $input = $dropdown.find('input');
//$input.focus().get(0).select();
$input.addnew({
autoOpen: true,
//autoClose: false,
addText: t('contacts', 'Save'),
ok: function(event, name) {
console.log('edit-address-book ok', name);
$input.addClass('loading');
self.update({displayname:name}, function(response) {
console.log('response', response);
if(response.error) {
$(document).trigger('status.contacts.error', response);
} else {
self.setDisplayName(response.data.displayname);
$input.addnew('close');
}
$input.removeClass('loading');
});
},
close: function() {
$dropdown.remove();
$(editor).data('open', false);
}
});
$(this).data('open', true);
} else {
var $rightContent = $('#app-content');
$rightContent.append('<div id="addressbook-ui-dialog"></div>');
var $dlg = $('#addressBookConfigTemplate').octemplate({backend: 'ldap'});
var $divDlg = $('#addressbook-ui-dialog');
//var $divDlg = $('#addressbook-ui-dialog');
$divDlg.html($dlg).ocdialog({
modal: true,
closeOnEscape: true,
title: t('contacts', 'Edit Addressbook'),
height: 'auto', width: 'auto',
buttons: [
{
text: t('contacts', 'Ok'),
click: function() {
OC.Contacts.otherBackendConfig.addressbookUiEditOk($divDlg);
self.setDisplayName($('#addressbooks-ui-name').val());
},
defaultButton: true
},
{
text: t('contacts', 'Cancel'),
click: function() {
OC.Contacts.otherBackendConfig.addressbookUiClose($divDlg);
}
}
],
close: function() {
OC.Contacts.otherBackendConfig.addressbookUiClose($divDlg);
},
open: function() {
OC.Contacts.otherBackendConfig.editAddressbookUI(addressbook);
}
});
}
return this.$li;
}
} else {
console.warn('Addressbook getAddressbook - no data !!');

View File

@ -168,7 +168,11 @@ OC.notify = function(params) {
$('#app-settings-content'),
$('#addressBookTemplate')
);
this.addressBookDialog = new OC.Contacts.AddressBookDialog();
this.otherBackendConfig = new OC.Contacts.OtherBackendConfig(
this.storage,
this.addressBooks,
$('#addressBookConfigTemplate')
);
this.contacts = new OC.Contacts.ContactList(
this.storage,
this.addressBooks,

View File

@ -1,361 +0,0 @@
OC.Contacts = OC.Contacts || {};
(function(window, $, OC) {
'use strict';
var AddressBookDialog = function() {
};
OC.Contacts.AddressBookDialog = AddressBookDialog;
AddressBookDialog.prototype.openAddressbookUi = function() {
var self = this;
$('#addressbooks-ui')[0].reset();
$('#addressbooks-ui-uri').attr('disabled', false);
$('#addressbooks-ui-ldapanonymous').attr('checked', false);
$('#addressbooks-ui-ldapreadonly').attr('checked', false);
$('#addressbooks-ui-ldapuser').attr('disabled', false);
$('#addressbooks-ui-ldappass').attr('disabled', false);
$('#addressbooks-ui-ldapbasednmodify').attr('disabled', false);
$('#addressbooks-ui-backend').change(function() {
var storage = OC.Contacts.storage;
self.addressbookUiInit();
$.when(storage.getConnectors($('#addressbooks-ui-backend').val()))
.then(function(response) {
$('#addressbooks-ui-ldapvcardconnector').empty();
var $option = null;
for (var id in response.data) {
if (response.data[id] != null) {
$option = $('<option value="' + response.data[id].id + '">' + response.data[id].name + '</option>');
$('#addressbooks-ui-ldapvcardconnector').append($option);
}
}
$option = $('<option value="">' + 'Custom connector' + '</option>');
$('#addressbooks-ui-ldapvcardconnector').append($option);
})
.fail(function(jqxhr, textStatus, error) {
var err = textStatus + ', ' + error;
console.log('Request Failed', + err);
defer.reject({error:true, message:error});
});
});
this.addressbookUiInit();
};
AddressBookDialog.prototype.editAddressbookUI = function(addressbook) {
var storage = OC.Contacts.storage;
$('#addressbooks-ui-addressbookid').val(addressbook.id);
$('#addressbooks-ui-backend option[value='+addressbook.backend+']').prop('selected', true);
$('#addressbooks-ui-backend').prop('disabled', true);
$('#addressbooks-ui-name').val(addressbook.displayname);
if (addressbook.backend === 'ldap') {
$('#addressbooks-ui-uri').val(addressbook.uri);
$('#addressbooks-ui-description').val(addressbook.description);
$('#addressbooks-ui-ldapurl').val(addressbook.ldapurl);
$('#addressbooks-ui-ldapanonymous').attr('checked', (addressbook.ldapanonymous===true));
$('#addressbooks-ui-ldapreadonly').attr('checked', (addressbook.ldapreadonly===true));
$('#addressbooks-ui-ldapuser').val(addressbook.ldapuser);
$('#addressbooks-ui-ldappass').val('nochange');
$('#addressbooks-ui-ldappass-modified').val('false');
$('#addressbooks-ui-ldappagesize').val(addressbook.ldappagesize);
$('#addressbooks-ui-ldapbasednsearch').val(addressbook.ldapbasednsearch);
$('#addressbooks-ui-ldapfilter').val(addressbook.ldapfilter);
$('#addressbooks-ui-ldapbasednmodify').val(addressbook.ldapbasednmodify);
$('#addressbooks-ui-uri').attr('disabled', true);
if ($('#addressbooks-ui-ldapanonymous').prop('checked')) {
$('#addressbooks-ui-ldapuser').attr('disabled', true);
$('#addressbooks-ui-ldappass').attr('disabled', true);
} else {
$('#addressbooks-ui-ldapuser').removeAttr('disabled');
$('#addressbooks-ui-ldappass').removeAttr('disabled');
}
if ($('#addressbooks-ui-ldapreadonly').prop('checked')) {
$('#addressbooks-ui-ldapbasednmodify').attr('disabled', true);
} else {
$('#addressbooks-ui-ldapbasednmodify').removeAttr('disabled');
}
$('#addressbooks-ui-ldappass').change(function() {
$('#addressbooks-ui-ldappass-modified').val('true');
});
$.when(storage.getConnectors($('#addressbooks-ui-backend').val()))
.then(function(response) {
$('#addressbooks-ui-ldapvcardconnector').empty();
var custom = true;
console.log('addressbook.ldapconnectorid', addressbook.ldapconnectorid);
for (var id in response.data) {
console.log('response.data[id][\'id\']', response.data[id].id);
var $option = null;
if (response.data[id].id === addressbook.ldapconnectorid) {
$option = $('<option value="' + response.data[id].id + '">' + response.data[id].name + '</option>').attr('selected','selected');
custom = false;
} else {
$option = $('<option value="' + response.data[id].id + '">' + response.data[id].name + '</option>');
}
$('#addressbooks-ui-ldapvcardconnector').append($option);
}
if (custom) {
var $option = $('<option value="">' + 'Custom connector' + '</option>').attr('selected','selected');
$('#addressbooks-ui-ldapvcardconnector-value-p').show();
$('#addressbooks-ui-ldapvcardconnector-copyfrom-p').show();
$.when(storage.getConnectors($('#addressbooks-ui-backend').val()))
.then(function(response) {
$('#addressbooks-ui-ldapvcardconnector-copyfrom').empty();
var $option = $('<option value="">' + 'Select connector' + '</option>').attr('selected','selected');
$('#addressbooks-ui-ldapvcardconnector-copyfrom').append($option);
for (id in response.data) {
$option = $('<option value="' + response.data[id].id + '">' + response.data[id].name + '</option>');
$('#addressbooks-ui-ldapvcardconnector-copyfrom').append($option);
}
})
.fail(function(jqxhr, textStatus, error) {
var err = textStatus + ', ' + error;
console.log('Request Failed', + err);
defer.reject({error:true, message:error});
});
$('#addressbooks-ui-ldapvcardconnector-copyfrom').change(function() {
if ($('#addressbooks-ui-ldapvcardconnector-copyfrom').val() !== '') {
$.when(storage.getConnectors($('#addressbooks-ui-backend').val()))
.then(function(response) {
for (id in response.data) {
if ($('#addressbooks-ui-ldapvcardconnector-copyfrom').val() === response.data[id].id) {
console.log(response.data[id].id);
$('#addressbooks-ui-ldapvcardconnector-value').text(response.data[id].xml);
}
}
})
.fail(function(jqxhr, textStatus, error) {
var err = textStatus + ', ' + error;
console.log('Request Failed', + err);
defer.reject({error:true, message:error});
});
}
});
$('#addressbooks-ui-ldapvcardconnector-value').text(addressbook.ldap_vcard_connector);
} else {
var $option = $('<option value="">' + 'Custom connector' + '</option>');
}
$('#addressbooks-ui-ldapvcardconnector').append($option);
})
.fail(function(jqxhr, textStatus, error) {
var err = textStatus + ', ' + error;
console.log('Request Failed', + err);
defer.reject({error:true, message:error});
});
}
this.addressbookUiInit();
};
AddressBookDialog.prototype.addressbookUiOk = function(divDlg) {
var defer = $.Deferred();
var storage = OC.Contacts.storage;
var addressbook = OC.Contacts.addressBooks;
$.when(storage.addAddressBook($('#addressbooks-ui-backend').val(),
{
displayname: $('#addressbooks-ui-name').val(),
description: $('#addressbooks-ui-description').val(),
uri: ($('#addressbooks-ui-uri').val()==='')?$('#addressbooks-ui-name').val():$('#addressbooks-ui-uri').val(),
ldapurl: $('#addressbooks-ui-ldapurl').val(),
ldapanonymous: $('#addressbooks-ui-ldapanonymous').prop('checked')===true?'true':'false',
ldapreadonly: $('#addressbooks-ui-ldapreadonly').prop('checked')===true?'true':'false',
ldapuser: $('#addressbooks-ui-ldapuser').val(),
ldappass: $('#addressbooks-ui-ldappass').val(),
ldappagesize: $('#addressbooks-ui-ldappagesize').val(),
ldapbasednsearch: $('#addressbooks-ui-ldapbasednsearch').val(),
ldapfilter: $('#addressbooks-ui-ldapfilter').val(),
ldapbasednmodify: $('#addressbooks-ui-ldapbasednmodify').val(),
ldapvcardconnector: $('#addressbooks-ui-ldapvcardconnector').val(),
ldapvcardconnectorvalue: $('#addressbooks-ui-ldapvcardconnector-value').val(),
}
)).then(function(response) {
if(response.error) {
error = response.message;
if(typeof cb === 'function') {
cb({error:true, message:error});
}
defer.reject(response);
} else {
console.log('response.data', response.data);
var book = addressbook.insertAddressBook(response.data);
$(document).trigger('status.addressbook.added');
if(typeof cb === 'function') {
cb({error:false, addressbook: book});
}
defer.resolve({error:false, addressbook: book});
}
OC.Contacts.addressBookDialog.addressbookUiClose(divDlg);
})
.fail(function(jqxhr, textStatus, error) {
$(this).removeClass('loading');
var err = textStatus + ', ' + error;
console.log('Request Failed', + err);
error = t('contacts', 'Failed adding address book: {error}', {error:err});
if(typeof cb === 'function') {
cb({error:true, message:error});
}
defer.reject({error:true, message:error});
OC.Contacts.addressBookDialog.addressbookUiClose(divDlg);
});
};
AddressBookDialog.prototype.addressbookUiEditOk = function(divDlg) {
var storage = OC.Contacts.storage;
var defer = $.Deferred();
$.when(storage.updateAddressBook($('#addressbooks-ui-backend').val(), $('#addressbooks-ui-addressbookid').val(),
{
displayname: $('#addressbooks-ui-name').val(),
description: $('#addressbooks-ui-description').val(),
uri: $('#addressbooks-ui-uri').val(),
ldapurl: $('#addressbooks-ui-ldapurl').val(),
ldapanonymous: $('#addressbooks-ui-ldapanonymous').prop('checked')===true?'true':'false',
ldapreadonly: $('#addressbooks-ui-ldapreadonly').prop('checked')===true?'true':'false',
ldapuser: $('#addressbooks-ui-ldapuser').val(),
ldappassmodified: $('#addressbooks-ui-ldappass-modified').val(),
ldappass: $('#addressbooks-ui-ldappass').val(),
ldappagesize: $('#addressbooks-ui-ldappagesize').val(),
ldapbasednsearch: $('#addressbooks-ui-ldapbasednsearch').val(),
ldapfilter: $('#addressbooks-ui-ldapfilter').val(),
ldapbasednmodify: $('#addressbooks-ui-ldapbasednmodify').val(),
ldapvcardconnector: $('#addressbooks-ui-ldapvcardconnector').val(),
ldapvcardconnectorvalue: $('#addressbooks-ui-ldapvcardconnector-value').val(),
}
)).then(function(response) {
if(response.error) {
error = response.message;
if(typeof cb === 'function') {
cb({error:true, message:error});
}
defer.reject(response);
}
OC.Contacts.addressBookDialog.addressbookUiClose(divDlg);
})
.fail(function(jqxhr, textStatus, error) {
$(this).removeClass('loading');
var err = textStatus + ', ' + error;
console.log('Request Failed', + err);
error = t('contacts', 'Failed adding address book: {error}', {error:err});
if(typeof cb === 'function') {
cb({error:true, message:error});
}
defer.reject({error:true, message:error});
});
};
AddressBookDialog.prototype.addressbookUiClose = function(divDlg) {
divDlg.ocdialog().ocdialog('close');
divDlg.ocdialog().ocdialog('destroy').remove();
};
AddressBookDialog.prototype.addressbookUiInit = function() {
if ($('#addressbooks-ui-backend').val() == 'local') {
$('#addressbooks-ui-uri-p').hide();
$('#addressbooks-ui-description-p').hide();
$('#addressbooks-ui-ldapurl-p').hide();
$('#addressbooks-ui-ldapanonymous-p').hide();
$('#addressbooks-ui-ldapreadonly-p').hide();
$('#addressbooks-ui-ldapuser-p').hide();
$('#addressbooks-ui-ldappass-p').hide();
$('#addressbooks-ui-ldappagesize-p').hide();
$('#addressbooks-ui-ldapbasednsearch-p').hide();
$('#addressbooks-ui-ldapfilter-p').hide();
$('#addressbooks-ui-ldapbasednmodify-p').hide();
$('#addressbooks-ui-ldapvcardconnector-p').hide();
$('#addressbooks-ui-ldapvcardconnector-value-p').hide();
$('#addressbooks-ui-ldapvcardconnector-copyfrom-p').hide();
} else if ($('#addressbooks-ui-backend').val() == 'ldap') {
$('#addressbooks-ui-uri-p').show();
$('#addressbooks-ui-description-p').show();
$('#addressbooks-ui-ldapurl-p').show();
$('#addressbooks-ui-ldapanonymous-p').show();
$('#addressbooks-ui-ldapreadonly-p').show();
$('#addressbooks-ui-ldapuser-p').show();
$('#addressbooks-ui-ldappass-p').show();
$('#addressbooks-ui-ldappagesize-p').show();
$('#addressbooks-ui-ldapbasednsearch-p').show();
$('#addressbooks-ui-ldapfilter-p').show();
$('#addressbooks-ui-ldapbasednmodify-p').show();
$('#addressbooks-ui-ldapvcardconnector-p').show();
$('#addressbooks-ui-ldapvcardconnector-value-p').hide();
$('#addressbooks-ui-ldapvcardconnector-copyfrom-p').hide();
}
$('#addressbooks-ui-name').change(function() {
if ($('#addressbooks-ui-uri').val() == '') {
$('#addressbooks-ui-uri').val($('#addressbooks-ui-name').val().toLowerCase().replace(' ', '-'));
}
});
$('#addressbooks-ui-ldapanonymous').change(function() {
if ($('#addressbooks-ui-ldapanonymous').prop('checked')) {
$('#addressbooks-ui-ldapuser').attr('disabled', true);
$('#addressbooks-ui-ldappass').attr('disabled', true);
} else {
$('#addressbooks-ui-ldapuser').removeAttr('disabled');
$('#addressbooks-ui-ldappass').removeAttr('disabled');
}
});
$('#addressbooks-ui-ldapreadonly').change(function() {
if ($('#addressbooks-ui-ldapreadonly').prop('checked')) {
$('#addressbooks-ui-ldapbasednmodify').attr('disabled', true);
} else {
$('#addressbooks-ui-ldapbasednmodify').removeAttr('disabled');
}
});
$('#addressbooks-ui-ldapbasednsearch').change(function() {
if ($('#addressbooks-ui-ldapbasednmodify').val() == '') {
$('#addressbooks-ui-ldapbasednmodify').val($('#addressbooks-ui-ldapbasednsearch').val());
}
});
$('#addressbooks-ui-ldapbasednmodify').change(function() {
if ($('#addressbooks-ui-ldapbasednsearch').val() == '') {
$('#addressbooks-ui-ldapbasednsearch').val($('#addressbooks-ui-ldapbasednmodify').val());
}
});
$('#addressbooks-ui-ldapvcardconnector').change(function() {
// Custom connector
if ($('#addressbooks-ui-ldapvcardconnector').val() == '') {
$('#addressbooks-ui-ldapvcardconnector-value-p').show();
$('#addressbooks-ui-ldapvcardconnector-value').text('');
$('#addressbooks-ui-ldapvcardconnector-copyfrom-p').show();
$.when(OC.Contacts.storage.getConnectors($('#addressbooks-ui-backend').val()))
.then(function(response) {
$('#addressbooks-ui-ldapvcardconnector-copyfrom').empty();
var $option = $('<option value="">' + 'Select connector' + '</option>').attr('selected','selected');
$('#addressbooks-ui-ldapvcardconnector-copyfrom').append($option);
for (var id in response.data) {
var $option = $('<option value="' + response.data[id].id + '">' + response.data[id].name + '</option>');
$('#addressbooks-ui-ldapvcardconnector-copyfrom').append($option);
}
})
.fail(function(jqxhr, textStatus, error) {
var err = textStatus + ', ' + error;
console.log('Request Failed', + err);
defer.reject({error:true, message:error});
});
$('#addressbooks-ui-ldapvcardconnector-copyfrom').change(function() {
if ($('#addressbooks-ui-ldapvcardconnector-copyfrom').val() != '') {
$.when(OC.Contacts.storage.getConnectors($('#addressbooks-ui-backend').val()))
.then(function(response) {
for (var id in response.data) {
if ($('#addressbooks-ui-ldapvcardconnector-copyfrom').val() == response.data[id].id) {
console.log(response.data[id].id);
$('#addressbooks-ui-ldapvcardconnector-value').text(response.data[id].xml);
}
}
})
.fail(function(jqxhr, textStatus, error) {
var err = textStatus + ', ' + error;
console.log('Request Failed', + err);
defer.reject({error:true, message:error});
});
}
});
}
});
};
})(window, jQuery, OC);

307
js/otherbackendconfig.js Normal file
View File

@ -0,0 +1,307 @@
OC.Contacts = OC.Contacts || {};
(function(window, $, OC) {
'use strict';
var OtherBackendConfig = function(storage, addressbooks, $template) {
this.storage = storage;
this.addressbooks = addressbooks;
this.$template = $template;
};
OC.Contacts.OtherBackendConfig = OtherBackendConfig;
OtherBackendConfig.prototype.openAddressbookUi = function() {
var self = this;
this.addressbookUiInit();
};
OtherBackendConfig.prototype.editAddressbookUI = function(addressbook) {
var self = this;
$('#addressbooks-ui-addressbookid').val(addressbook.id);
$('#addressbooks-ui-name').val(addressbook.displayname);
$('#addressbooks-ui-uri').val(addressbook.uri);
$('#addressbooks-ui-description').val(addressbook.description);
$('#addressbooks-ui-ldapurl').val(addressbook.ldapurl);
$('#addressbooks-ui-ldapanonymous').attr('checked', (addressbook.ldapanonymous===true));
$('#addressbooks-ui-ldapreadonly').attr('checked', (addressbook.ldapreadonly===true));
$('#addressbooks-ui-ldapuser').val(addressbook.ldapuser);
$('#addressbooks-ui-ldappass').val('nochange');
$('#addressbooks-ui-ldappass-modified').val('false');
$('#addressbooks-ui-ldappagesize').val(addressbook.ldappagesize);
$('#addressbooks-ui-ldapbasednsearch').val(addressbook.ldapbasednsearch);
$('#addressbooks-ui-ldapfilter').val(addressbook.ldapfilter);
$('#addressbooks-ui-ldapbasednmodify').val(addressbook.ldapbasednmodify);
$('#addressbooks-ui-uri').prop('disabled', true);
if ($('#addressbooks-ui-ldapanonymous').prop('checked')) {
$('#addressbooks-ui-ldapuser').prop('disabled', true);
$('#addressbooks-ui-ldappass').prop('disabled', true);
} else {
$('#addressbooks-ui-ldapuser').removeProp('disabled');
$('#addressbooks-ui-ldappass').removeProp('disabled');
}
if ($('#addressbooks-ui-ldapreadonly').prop('checked')) {
$('#addressbooks-ui-ldapbasednmodify').prop('disabled', true);
} else {
$('#addressbooks-ui-ldapbasednmodify').removeProp('disabled');
}
$('#addressbooks-ui-ldappass').change(function() {
$('#addressbooks-ui-ldappass-modified').val('true');
});
this.addressbookUiInit();
$.when(self.storage.getConnectors($('#addressbooks-ui-backend').val()))
.then(function(response) {
$('#addressbooks-ui-ldapvcardconnector').empty();
console.log('addressbook.ldapconnectorid', addressbook.ldapconnectorid);
var custom = true;
for (var id = 0; id < response.data.length; id++) {
console.log('response.data[id][\'id\']', response.data[id].id);
var $option = null;
if (response.data[id].id === addressbook.ldapconnectorid) {
$option = $('<option value="' + response.data[id].id + '">' + response.data[id].name + '</option>').attr('selected','selected');
custom = false;
} else {
$option = $('<option value="' + response.data[id].id + '">' + response.data[id].name + '</option>');
}
$('#addressbooks-ui-ldapvcardconnector').append($option);
}
if (custom) {
console.log("custom selected");
var $option = $('<option value="">' + 'Custom connector' + '</option>').attr('selected','selected');
$('#addressbooks-ui-ldapvcardconnector-value-p').show();
$('#addressbooks-ui-ldapvcardconnector-copyfrom-p').show();
$.when(self.storage.getConnectors($('#addressbooks-ui-backend').val()))
.then(function(response) {
$('#addressbooks-ui-ldapvcardconnector-copyfrom').empty();
var $option = $('<option value="">' + 'Select connector' + '</option>').attr('selected','selected');
$('#addressbooks-ui-ldapvcardconnector-copyfrom').append($option);
for (var id = 0; id < response.data.length; id++) {
$option = $('<option value="' + response.data[id].id + '">' + response.data[id].name + '</option>');
$('#addressbooks-ui-ldapvcardconnector-copyfrom').append($option);
}
})
.fail(function(jqxhr, textStatus, error) {
var err = textStatus + ', ' + error;
console.log('Request Failed', + err);
defer.reject({error:true, message:error});
});
$('#addressbooks-ui-ldapvcardconnector-value').text(addressbook.ldap_vcard_connector);
} else {
console.log("custom not selected");
var $option = $('<option value="">' + 'Custom connector' + '</option>');
}
$('#addressbooks-ui-ldapvcardconnector').append($option);
})
.fail(function(jqxhr, textStatus, error) {
var err = textStatus + ', ' + error;
console.log('Request Failed', + err);
defer.reject({error:true, message:error});
});
};
OtherBackendConfig.prototype.addressbookUiOk = function(divDlg) {
var defer = $.Deferred();
var addressbook = OC.Contacts.addressBooks;
$.when(this.storage.addAddressBook($('#addressbooks-ui-backend').val(),
{
displayname: $('#addressbooks-ui-name').val(),
description: $('#addressbooks-ui-description').val(),
uri: ($('#addressbooks-ui-uri').val()==='')?$('#addressbooks-ui-name').val():$('#addressbooks-ui-uri').val(),
ldapurl: $('#addressbooks-ui-ldapurl').val(),
ldapanonymous: $('#addressbooks-ui-ldapanonymous').prop('checked')===true?'true':'false',
ldapreadonly: $('#addressbooks-ui-ldapreadonly').prop('checked')===true?'true':'false',
ldapuser: $('#addressbooks-ui-ldapuser').val(),
ldappass: $('#addressbooks-ui-ldappass').val(),
ldappagesize: $('#addressbooks-ui-ldappagesize').val(),
ldapbasednsearch: $('#addressbooks-ui-ldapbasednsearch').val(),
ldapfilter: $('#addressbooks-ui-ldapfilter').val(),
ldapbasednmodify: $('#addressbooks-ui-ldapbasednmodify').val(),
ldapvcardconnector: $('#addressbooks-ui-ldapvcardconnector').val(),
ldapvcardconnectorvalue: $('#addressbooks-ui-ldapvcardconnector-value').val(),
}
)).then(function(response) {
if(response.error) {
error = response.message;
if(typeof cb === 'function') {
cb({error:true, message:error});
}
defer.reject(response);
} else {
console.log('response.data', response.data);
var book = addressbook.insertAddressBook(response.data);
$(document).trigger('status.addressbook.added');
if(typeof cb === 'function') {
cb({error:false, addressbook: book});
}
defer.resolve({error:false, addressbook: book});
}
OC.Contacts.otherBackendConfig.addressbookUiClose(divDlg);
})
.fail(function(jqxhr, textStatus, error) {
$(this).removeClass('loading');
var err = textStatus + ', ' + error;
console.log('Request Failed', + err);
error = t('contacts', 'Failed adding address book: {error}', {error:err});
if(typeof cb === 'function') {
cb({error:true, message:error});
}
defer.reject({error:true, message:error});
OC.Contacts.otherBackendConfig.addressbookUiClose(divDlg);
});
};
OtherBackendConfig.prototype.addressbookUiEditOk = function(divDlg) {
var defer = $.Deferred();
$.when(this.storage.updateAddressBook($('#addressbooks-ui-backend').val(), $('#addressbooks-ui-addressbookid').val(),
{properties:
{
displayname: $('#addressbooks-ui-name').val(),
description: $('#addressbooks-ui-description').val(),
uri: $('#addressbooks-ui-uri').val(),
ldapurl: $('#addressbooks-ui-ldapurl').val(),
ldapanonymous: $('#addressbooks-ui-ldapanonymous').prop('checked')===true?'true':'false',
ldapreadonly: $('#addressbooks-ui-ldapreadonly').prop('checked')===true?'true':'false',
ldapuser: $('#addressbooks-ui-ldapuser').val(),
ldappassmodified: $('#addressbooks-ui-ldappass-modified').val(),
ldappass: $('#addressbooks-ui-ldappass').val(),
ldappagesize: $('#addressbooks-ui-ldappagesize').val(),
ldapbasednsearch: $('#addressbooks-ui-ldapbasednsearch').val(),
ldapfilter: $('#addressbooks-ui-ldapfilter').val(),
ldapbasednmodify: $('#addressbooks-ui-ldapbasednmodify').val(),
ldapvcardconnector: $('#addressbooks-ui-ldapvcardconnector').val(),
ldapvcardconnectorvalue: $('#addressbooks-ui-ldapvcardconnector-value').val(),
}
}
)).then(function(response) {
if(response.error) {
error = response.message;
if(typeof cb === 'function') {
cb({error:true, message:error});
}
defer.reject(response);
}
OC.Contacts.otherBackendConfig.addressbookUiClose(divDlg);
})
.fail(function(jqxhr, textStatus, error) {
$(this).removeClass('loading');
var err = textStatus + ', ' + error;
console.log('Request Failed', + err);
error = t('contacts', 'Failed adding address book: {error}', {error:err});
if(typeof cb === 'function') {
cb({error:true, message:error});
}
defer.reject({error:true, message:error});
});
};
OtherBackendConfig.prototype.addressbookUiClose = function(divDlg) {
divDlg.ocdialog().ocdialog('close');
divDlg.ocdialog().ocdialog('destroy').remove();
};
OtherBackendConfig.prototype.addressbookUiInit = function() {
var self = this;
$('#addressbooks-ui-ldapvcardconnector-value-p').hide();
$('#addressbooks-ui-ldapvcardconnector-copyfrom-p').hide();
$('#addressbooks-ui-name').change(function() {
if ($('#addressbooks-ui-uri').val() === '') {
$('#addressbooks-ui-uri').val($('#addressbooks-ui-name').val().toLowerCase().replace(' ', '-'));
}
});
$('#addressbooks-ui-ldapanonymous').change(function() {
if ($('#addressbooks-ui-ldapanonymous').prop('checked')) {
$('#addressbooks-ui-ldapuser').prop('disabled', true);
$('#addressbooks-ui-ldappass').prop('disabled', true);
} else {
$('#addressbooks-ui-ldapuser').removeProp('disabled');
$('#addressbooks-ui-ldappass').removeProp('disabled');
}
});
$('#addressbooks-ui-ldapreadonly').change(function() {
if ($('#addressbooks-ui-ldapreadonly').prop('checked')) {
$('#addressbooks-ui-ldapbasednmodify').prop('disabled', true);
} else {
$('#addressbooks-ui-ldapbasednmodify').removeProp('disabled');
}
});
$('#addressbooks-ui-ldapbasednsearch').change(function() {
if ($('#addressbooks-ui-ldapbasednmodify').val() == '') {
$('#addressbooks-ui-ldapbasednmodify').val($('#addressbooks-ui-ldapbasednsearch').val());
}
});
$('#addressbooks-ui-ldapbasednmodify').change(function() {
if ($('#addressbooks-ui-ldapbasednsearch').val() == '') {
$('#addressbooks-ui-ldapbasednsearch').val($('#addressbooks-ui-ldapbasednmodify').val());
}
});
$.when(self.storage.getConnectors('ldap'))
.then(function(response) {
$('#addressbooks-ui-ldapvcardconnector').empty();
var $option = null;
for (var id = 0; id < response.data.length; id++) {
if (response.data[id] != null) {
$option = $('<option value="' + response.data[id].id + '">' + response.data[id].name + '</option>');
$('#addressbooks-ui-ldapvcardconnector').append($option);
}
}
$option = $('<option value="">' + 'Custom connector' + '</option>');
$('#addressbooks-ui-ldapvcardconnector').append($option);
})
.fail(function(jqxhr, textStatus, error) {
var err = textStatus + ', ' + error;
console.log('Request Failed', + err);
defer.reject({error:true, message:error});
});
$('#addressbooks-ui-ldapvcardconnector').change(function() {
// Custom connector
if ($('#addressbooks-ui-ldapvcardconnector').val() == '') {
$('#addressbooks-ui-ldapvcardconnector-value-p').show();
$('#addressbooks-ui-ldapvcardconnector-copyfrom-p').show();
$.when(self.storage.getConnectors($('#addressbooks-ui-backend').val()))
.then(function(response) {
$('#addressbooks-ui-ldapvcardconnector-copyfrom').empty();
var $option = $('<option value="">' + 'Select connector' + '</option>').attr('selected','selected');
$('#addressbooks-ui-ldapvcardconnector-copyfrom').append($option);
for (var id = 0; id < response.data.length; id++) {
var $option = $('<option value="' + response.data[id].id + '">' + response.data[id].name + '</option>');
$('#addressbooks-ui-ldapvcardconnector-copyfrom').append($option);
}
})
.fail(function(jqxhr, textStatus, error) {
var err = textStatus + ', ' + error;
console.log('Request Failed', + err);
defer.reject({error:true, message:error});
});
} else {
$('#addressbooks-ui-ldapvcardconnector-value-p').hide();
$('#addressbooks-ui-ldapvcardconnector-copyfrom-p').hide();
}
});
$('#addressbooks-ui-ldapvcardconnector-copyfrom').change(function() {
if ($('#addressbooks-ui-ldapvcardconnector-copyfrom').val() != '') {
$.when(self.storage.getConnectors($('#addressbooks-ui-backend').val()))
.then(function(response) {
for (var id = 0; id < response.data.length; id++) {
if ($('#addressbooks-ui-ldapvcardconnector-copyfrom').val() == response.data[id].id) {
console.log(response.data[id].id);
$('#addressbooks-ui-ldapvcardconnector-value').text(response.data[id].xml);
}
}
})
.fail(function(jqxhr, textStatus, error) {
var err = textStatus + ', ' + error;
console.log('Request Failed', + err);
defer.reject({error:true, message:error});
});
}
});
};
})(window, jQuery, OC);

View File

@ -150,7 +150,7 @@ OC.Contacts = OC.Contacts || {};
* }
*/
Storage.prototype.updateAddressBook = function(backend, addressBookId, properties) {
console.log('Storage.updateAddressBook', backend, addressBookId);
console.log('Storage.updateAddressBook', backend, addressBookId, properties);
return this.requestRoute(
'addressbook/{backend}/{addressBookId}',
'POST',

View File

@ -174,8 +174,7 @@ class AddressBookController extends Controller {
$response = new JSONResponse();
$addressBook = $this->app->getAddressBook($params['backend'], $params['addressBookId']);
//$addressBook->update($this->request['properties']);
$addressBook->update($this->request->post);
$addressBook->update($this->request['properties']);
return $response->setParams($addressBook->getMetaData());
}

View File

@ -24,7 +24,7 @@ class BackendController extends Controller {
* @NoAdminRequired
* @NoCSRFRequired
*/
public function getLdapConnectors() {
public function getConnectors() {
$response = new JSONResponse();
$prefix = "backend_ldap_";
$suffix = "_connector.xml";
@ -38,7 +38,7 @@ class BackendController extends Controller {
if ($format) {
if (isset($format['name'])) {
$formatId = substr($file, strlen($prefix), - strlen($suffix));
$formats[$formatId] = array('id' => $formatId, 'name' => (string)$format['name'], 'xml' => $format->asXML());
$formats[] = array('id' => $formatId, 'name' => (string)$format['name'], 'xml' => $format->asXML());
}
}
}

View File

@ -50,7 +50,7 @@ class PageController extends Controller {
\OCP\Util::addScript('contacts', 'storage');
\OCP\Util::addScript('contacts', 'groups');
\OCP\Util::addScript('contacts', 'jquery.ocaddnew');
\OCP\Util::addScript('contacts', 'dialog');
\OCP\Util::addScript('contacts', 'otherbackendconfig');
\OCP\Util::addScript('files', 'jquery.fileupload');
\OCP\Util::addScript('3rdparty/Jcrop', 'jquery.Jcrop');
\OCP\Util::addStyle('', 'jquery.multiselect');

View File

@ -22,8 +22,9 @@ use OCA\Contacts\ImportManager;
<h2 data-id="addressbooks" tabindex="0" role="button"><?php p($l->t('Address books')); ?></h2>
<ul class="addressbooklist">
</ul>
<input type="text" tabindex="0" autofocus id="add-address-book" placeholder="<?php p($l->t('Display name')); ?>" title="<?php p($l->t('Add Address Book')); ?>" />
<ul class="oc-addnew">
<li id="add-address-book-element"><a class="oc-addnew-init"><?php p($l->t('Add Address Book')); ?></a></li>
<li id="add-ldap-address-book-element"><a class="oc-addnew-init"><?php p($l->t('Add LDAP Address Book')); ?></a></li>
</ul>
</div>
<div id="import">
@ -510,18 +511,10 @@ use OCA\Contacts\ImportManager;
</li>
</script>
<form id="addressbooks-ui" method="GET" name="addressbook-ui" action="#">
<div id="addressbooks-ui-div" title="Add new addressbook" class="addressbooks-ui-class">
<script id="addressBookConfigTemplate" class="hidden" type="text/template">
<div id="addressbooks-ui-div" class="addressbooks-ui-class">
<input type="hidden" id="addressbooks-ui-addressbookid" />
<p id="addressbooks-ui-backend-p">
<label for="addressbooks-ui-backend">
<?php p($l->t('Addressbook type')); ?>:
</label>
<select id="addressbooks-ui-backend">
<option value="local">Local</option>
<option value="ldap">LDAP</option>
</select>
</p>
<input type="hidden" id="addressbooks-ui-backend" value="{backend}" />
<p id="addressbooks-ui-name-p">
<label for="addressbooks-ui-name">
<?php p($l->t('Name')); ?>:
@ -614,16 +607,16 @@ use OCA\Contacts\ImportManager;
</p>
<p id="addressbooks-ui-ldapvcardconnector-value-p">
<label for="addressbooks-ui-ldapvcardconnector-value">
<?php p($l->t('Connector value')); ?>:
<?php p($l->t('Connector value (Better use external editor and copy/paste)')); ?>:
</label>
<textarea id="addressbooks-ui-ldapvcardconnector-value"></textarea>
</p>
<p id="addressbooks-ui-ldapvcardconnector-copyfrom-p">
<label for="addressbooks-ui-ldapvcardconnector-copyfrom">
<?php p($l->t('Copy from (Warning, it will replace the current custom value)')); ?>:
<?php p($l->t('Copy from (Warning, replaces current custom value)')); ?>:
</label>
<select id="addressbooks-ui-ldapvcardconnector-copyfrom">
</select>
</p>
</div>
</form>
</script>