1
0
mirror of https://github.com/owncloudarchive/contacts.git synced 2024-11-29 11:24:11 +01:00

put dialog UI functions in a new js class

change addressbook name in UI when changed
This commit is contained in:
babelouest 2014-04-07 01:18:09 -04:00
parent 57211530f8
commit 489aaa1eae
3 changed files with 356 additions and 386 deletions

View File

@ -69,36 +69,37 @@ OC.Contacts = OC.Contacts || {};
});
});
$('#add-address-book-element').on('click keypress', function() {
console.log('OC.Contacts', OC.Contacts);
$("#addressbooks-ui")
.dialog({
title:"Add new Addressbook",
close: function() { $(this).hide() },
close: function() { $(this).hide(); },
modal: false,
width: 'auto',
height: 'auto',
position: ['top', 100],
buttons: {
Ok: function() {
addressbookUiOk();
OC.Contacts.addressBookDialog.addressbookUiOk();
},
Cancel: function() {
addressbookUiCancel();
OC.Contacts.addressBookDialog.addressbookUiCancel();
}
},
open: openAddressbookUi()
open: function() {
OC.Contacts.addressBookDialog.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);
$("#addressbooks-ui")
$('#addressbooks-ui')
.dialog({
title:"Edit Addressbook",
title:'Edit Addressbook',
close: function() { $(this).hide() },
modal: false,
width: 'auto',
@ -106,15 +107,15 @@ OC.Contacts = OC.Contacts || {};
position: ['top', 100],
buttons: {
Ok: function() {
addressbookUiEditOk();
OC.Contacts.addressBookDialog.addressbookUiEditOk();
self.setDisplayName($('#addressbooks-ui-name').val());
},
Cancel: function() {
addressbookUiCancel();
OC.Contacts.addressBookDialog.addressbookUiCancel();
}
},
open: editAddressbookUI(addressbook)
open: OC.Contacts.addressBookDialog.editAddressbookUI(addressbook)
});
//self.insertContacts(response.data.contacts);
}
} else {
console.warn('Addressbook getAddressbook - no data !!');
@ -124,41 +125,6 @@ OC.Contacts = OC.Contacts || {};
console.warn('Request Failed:', response.message);
$(document).trigger('status.contacts.error', response);
});
// TODO: remove this mock value
/*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);*/
});
return this.$li;
};
@ -355,7 +321,7 @@ OC.Contacts = OC.Contacts || {};
});
this.$importFileInput.fileupload({
dataType: 'json',
start: function(e, data) {
start: function(/*e, data*/) {
self.$importProgress.progressbar({value:false});
$('.tipsy').remove();
$('.import-upload').hide();

View File

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

View File

@ -1,352 +1,355 @@
OC.Contacts = OC.Contacts || {};
function openAddressbookUi() {
$('#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);
(function(window, $, OC) {
'use strict';
$('#addressbooks-ui-backend').change(function() {
storage = new OC.Contacts.Storage();
addressbookUiInit();
$.when(storage.getConnectors($('#addressbooks-ui-backend').val()))
.then(function(response) {
$('#addressbooks-ui-ldapvcardconnector').empty();
for (id in response.data) {
var $option = $('<option value="' + response.data[id]["id"] + '">' + response.data[id]["name"] + '</option>');
$('#addressbooks-ui-ldapvcardconnector').append($option);
}
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});
});
});
addressbookUiInit();
}
function editAddressbookUI(addressbook) {
storage = new 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 (id in response.data) {
console.log('response.data[id][\'id\']', response.data[id]['id']);
if (response.data[id]['id'] == addressbook.ldapconnectorid) {
var $option = $('<option value="' + response.data[id]['id'] + '">' + response.data[id]['name'] + '</option>').attr('selected','selected');
custom = false;
} else {
var $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) {
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(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});
});
}
addressbookUiInit();
}
function addressbookUiOk() {
storage = new OC.Contacts.Storage();
//addressbook = new OC.Contacts.AddressBook();
var defer = $.Deferred();
$.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 {
var book = OC.Contacts.addressBooks.insertAddressBook(response.data);
$(document).trigger('status.addressbook.added');
if(typeof cb === 'function') {
cb({error:false, addressbook: book});
}
defer.resolve({error:false, addressbook: book});
$("#addressbooks-ui").dialog('close');
}
})
.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});
});
}
function addressbookUiEditOk() {
storage = new OC.Contacts.Storage();
//addressbook = new OC.Contacts.Addressbook();
var defer = $.Deferred();
console.log($("#addressbooks-ui-addressbookid").val())
$.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);
} else {
/*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});*/
$("#addressbooks-ui").dialog('close');
}
})
.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});
});
}
function addressbookUiCancel() {
$('#addressbooks-ui').dialog('close');
}
function addressbookUiInit() {
storage = new OC.Contacts.Storage();
var AddressBookDialog = 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();
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-copyfrom').empty();
var $option = $('<option value="">' + 'Select connector' + '</option>').attr('selected','selected');
$('#addressbooks-ui-ldapvcardconnector-copyfrom').append($option);
for (id in response.data) {
var $option = $('<option value="' + response.data[id]['id'] + '">' + response.data[id]['name'] + '</option>');
$('#addressbooks-ui-ldapvcardconnector-copyfrom').append($option);
$('#addressbooks-ui-ldapvcardconnector').empty();
for (var id in response.data) {
var $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-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});
});
}
});
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);
if (response.data[id].id === addressbook.ldapconnectorid) {
var $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() {
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 {
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});
$('#addressbooks-ui').dialog('close');
}
})
.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.addressbookUiEditOk = function() {
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);
} else {
$("#addressbooks-ui").dialog('close');
}
})
.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.addressbookUiCancel = function() {
$('#addressbooks-ui').dialog('close');
}
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(this.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) {
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(this.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});
});
}
});
}
});
}
})(window, jQuery, OC);