mirror of
https://github.com/owncloudarchive/contacts.git
synced 2024-11-29 11:24:11 +01:00
use ocdialog
fix a bug in the contact.save() methid that was readonly for no reason
This commit is contained in:
parent
ec89124db1
commit
e354d0fae3
@ -60,7 +60,7 @@
|
||||
<ldap_core>
|
||||
<object_class name="top" />
|
||||
<object_class name="inetOrgPerson" />
|
||||
<unassigned_vcard_property ldap_name="telexnumber" />
|
||||
<unassigned_vcard_property ldap_name="businessCategory" />
|
||||
<ldap_id name="cn" />
|
||||
<not_null name="sn">
|
||||
<action_switch name="givenname"/>
|
||||
|
@ -69,23 +69,35 @@ OC.Contacts = OC.Contacts || {};
|
||||
});
|
||||
});
|
||||
$('#add-address-book-element').on('click keypress', function() {
|
||||
$("#addressbooks-ui")
|
||||
.dialog({
|
||||
title:"Add new Addressbook",
|
||||
close: function() { $(this).hide(); },
|
||||
modal: false,
|
||||
width: 'auto',
|
||||
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', 'Add new Addressbook'),
|
||||
height: 'auto',
|
||||
position: ['top', 100],
|
||||
buttons: {
|
||||
Ok: function() {
|
||||
OC.Contacts.addressBookDialog.addressbookUiOk();
|
||||
width: 'auto',
|
||||
buttons: [
|
||||
{
|
||||
text: t('contacts', 'Ok'),
|
||||
click: function() {
|
||||
OC.Contacts.addressBookDialog.addressbookUiOk(divDlg);
|
||||
},
|
||||
defaultButton: true
|
||||
},
|
||||
Cancel: function() {
|
||||
OC.Contacts.addressBookDialog.addressbookUiCancel();
|
||||
{
|
||||
text: t('contacts', 'Cancel'),
|
||||
click: function() {
|
||||
OC.Contacts.addressBookDialog.addressbookUiClose(divDlg);
|
||||
}
|
||||
}
|
||||
],
|
||||
close: function(/*event, ui*/) {
|
||||
OC.Contacts.addressBookDialog.addressbookUiClose(divDlg);
|
||||
},
|
||||
open: function() {
|
||||
open: function(/*event, ui*/) {
|
||||
OC.Contacts.addressBookDialog.openAddressbookUi();
|
||||
}
|
||||
});
|
||||
@ -97,24 +109,37 @@ OC.Contacts = OC.Contacts || {};
|
||||
if(response.data) {
|
||||
var addressbook = response.data;
|
||||
console.log('addressbook', addressbook);
|
||||
$('#addressbooks-ui')
|
||||
.dialog({
|
||||
title:'Edit Addressbook',
|
||||
close: function() { $(this).hide() },
|
||||
modal: false,
|
||||
width: 'auto',
|
||||
height: 'auto',
|
||||
position: ['top', 100],
|
||||
buttons: {
|
||||
Ok: function() {
|
||||
OC.Contacts.addressBookDialog.addressbookUiEditOk();
|
||||
self.setDisplayName($('#addressbooks-ui-name').val());
|
||||
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
|
||||
},
|
||||
Cancel: function() {
|
||||
OC.Contacts.addressBookDialog.addressbookUiCancel();
|
||||
{
|
||||
text: t('contacts', 'Cancel'),
|
||||
click: function() {
|
||||
OC.Contacts.addressBookDialog.addressbookUiClose(divDlg);
|
||||
}
|
||||
}
|
||||
],
|
||||
close: function(/*event, ui*/) {
|
||||
OC.Contacts.addressBookDialog.addressbookUiClose(divDlg);
|
||||
},
|
||||
open: OC.Contacts.addressBookDialog.editAddressbookUI(addressbook)
|
||||
open: function(/*event, ui*/) {
|
||||
OC.Contacts.addressBookDialog.editAddressbookUI(addressbook);
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
|
46
js/dialog.js
46
js/dialog.js
@ -24,9 +24,12 @@ OC.Contacts = OC.Contacts || {};
|
||||
$.when(storage.getConnectors($('#addressbooks-ui-backend').val()))
|
||||
.then(function(response) {
|
||||
$('#addressbooks-ui-ldapvcardconnector').empty();
|
||||
var $option = null;
|
||||
for (var id in response.data) {
|
||||
var $option = $('<option value="' + response.data[id].id + '">' + response.data[id].name + '</option>');
|
||||
$('#addressbooks-ui-ldapvcardconnector').append($option);
|
||||
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);
|
||||
@ -38,7 +41,7 @@ OC.Contacts = OC.Contacts || {};
|
||||
});
|
||||
});
|
||||
this.addressbookUiInit();
|
||||
}
|
||||
};
|
||||
|
||||
AddressBookDialog.prototype.editAddressbookUI = function(addressbook) {
|
||||
var storage = OC.Contacts.storage;
|
||||
@ -84,8 +87,9 @@ OC.Contacts = OC.Contacts || {};
|
||||
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) {
|
||||
var $option = $('<option value="' + response.data[id].id + '">' + response.data[id].name + '</option>').attr('selected','selected');
|
||||
$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>');
|
||||
@ -143,9 +147,9 @@ OC.Contacts = OC.Contacts || {};
|
||||
});
|
||||
}
|
||||
this.addressbookUiInit();
|
||||
}
|
||||
};
|
||||
|
||||
AddressBookDialog.prototype.addressbookUiOk = function() {
|
||||
AddressBookDialog.prototype.addressbookUiOk = function(divDlg) {
|
||||
var defer = $.Deferred();
|
||||
var storage = OC.Contacts.storage;
|
||||
var addressbook = OC.Contacts.addressBooks;
|
||||
@ -175,14 +179,15 @@ OC.Contacts = OC.Contacts || {};
|
||||
}
|
||||
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});
|
||||
$('#addressbooks-ui').dialog('close');
|
||||
}
|
||||
OC.Contacts.addressBookDialog.addressbookUiClose(divDlg);
|
||||
})
|
||||
.fail(function(jqxhr, textStatus, error) {
|
||||
$(this).removeClass('loading');
|
||||
@ -193,10 +198,11 @@ OC.Contacts = OC.Contacts || {};
|
||||
cb({error:true, message:error});
|
||||
}
|
||||
defer.reject({error:true, message:error});
|
||||
OC.Contacts.addressBookDialog.addressbookUiClose(divDlg);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
AddressBookDialog.prototype.addressbookUiEditOk = function() {
|
||||
AddressBookDialog.prototype.addressbookUiEditOk = function(divDlg) {
|
||||
var storage = OC.Contacts.storage;
|
||||
var defer = $.Deferred();
|
||||
|
||||
@ -225,9 +231,8 @@ OC.Contacts = OC.Contacts || {};
|
||||
cb({error:true, message:error});
|
||||
}
|
||||
defer.reject(response);
|
||||
} else {
|
||||
$("#addressbooks-ui").dialog('close');
|
||||
}
|
||||
OC.Contacts.addressBookDialog.addressbookUiClose(divDlg);
|
||||
})
|
||||
.fail(function(jqxhr, textStatus, error) {
|
||||
$(this).removeClass('loading');
|
||||
@ -239,11 +244,12 @@ OC.Contacts = OC.Contacts || {};
|
||||
}
|
||||
defer.reject({error:true, message:error});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
AddressBookDialog.prototype.addressbookUiCancel = function() {
|
||||
$('#addressbooks-ui').dialog('close');
|
||||
}
|
||||
AddressBookDialog.prototype.addressbookUiClose = function(divDlg) {
|
||||
divDlg.ocdialog().ocdialog('close');
|
||||
divDlg.ocdialog().ocdialog('destroy').remove();
|
||||
};
|
||||
|
||||
AddressBookDialog.prototype.addressbookUiInit = function() {
|
||||
|
||||
@ -315,12 +321,12 @@ OC.Contacts = OC.Contacts || {};
|
||||
$('#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()))
|
||||
$.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 (id in response.data) {
|
||||
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);
|
||||
}
|
||||
@ -332,9 +338,9 @@ OC.Contacts = OC.Contacts || {};
|
||||
});
|
||||
$('#addressbooks-ui-ldapvcardconnector-copyfrom').change(function() {
|
||||
if ($('#addressbooks-ui-ldapvcardconnector-copyfrom').val() != '') {
|
||||
$.when(this.storage.getConnectors($('#addressbooks-ui-backend').val()))
|
||||
$.when(OC.Contacts.storage.getConnectors($('#addressbooks-ui-backend').val()))
|
||||
.then(function(response) {
|
||||
for (id in response.data) {
|
||||
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);
|
||||
@ -350,6 +356,6 @@ OC.Contacts = OC.Contacts || {};
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
})(window, jQuery, OC);
|
||||
|
@ -38,10 +38,15 @@ class Ldap extends AbstractBackend {
|
||||
* @var string
|
||||
*/
|
||||
public $name='ldap';
|
||||
static private $preparedQueries = array();
|
||||
private $ldapConnection = null;
|
||||
private $connector = null;
|
||||
|
||||
/**
|
||||
* The cached address books.
|
||||
* @var array[]
|
||||
*/
|
||||
public $addressBooks;
|
||||
|
||||
/**
|
||||
* @brief validates and sets the ldap parameters
|
||||
* @param $ldapParams array containing the parameters
|
||||
@ -252,9 +257,8 @@ class Ldap extends AbstractBackend {
|
||||
*/
|
||||
public function getAddressBooksForUser(array $options = array()) {
|
||||
$addressbookidList = $this->getAddressbookList();
|
||||
$this->addressbooks = array();
|
||||
foreach($addressbookidList as $addressbookid) {
|
||||
error_log(__METHOD__." am i here ? ".$addressbookid);
|
||||
//error_log(__METHOD__." am i here ? ".$addressbookid);
|
||||
$this->addressbooks[] = self::getAddressBook($addressbookid);
|
||||
}
|
||||
return $this->addressbooks;
|
||||
@ -273,16 +277,6 @@ class Ldap extends AbstractBackend {
|
||||
* @return array $properties
|
||||
*/
|
||||
public function getAddressBook($addressbookid, array $options = array()) {
|
||||
$backtrace = debug_backtrace();
|
||||
$trace=array();
|
||||
foreach ($backtrace as $elt) {
|
||||
foreach ($elt as $key => $line) {
|
||||
if ($key == "file" || $key == "line") {
|
||||
$trace[] = $line;
|
||||
}
|
||||
}
|
||||
}
|
||||
//error_log(__METHOD__." ".print_r($trace,1));
|
||||
//\OC_Log::write('contacts', __METHOD__.' id: '
|
||||
// . $addressbookid, \OC_Log::DEBUG);
|
||||
if($this->addressbooks && isset($this->addressbooks[$addressbookid])) {
|
||||
@ -293,6 +287,7 @@ class Ldap extends AbstractBackend {
|
||||
$preferences = self::getPreferences($addressbookid);
|
||||
if (count($preferences) > 0) {
|
||||
$preferences['id'] = (string)$addressbookid;
|
||||
$preferences['backend'] = $this->name;
|
||||
$preferences['owner'] = $this->userid;
|
||||
$preferences['permissions'] = \OCP\PERMISSION_ALL;
|
||||
$preferences['lastmodified'] = self::lastModifiedAddressBook($addressbookid);
|
||||
@ -596,7 +591,7 @@ class Ldap extends AbstractBackend {
|
||||
$URI = (string)$vcard->{'X-LDAP-DN'};
|
||||
}
|
||||
return array('id' => $UID,
|
||||
'permissions' => \OCP\PERMISSION_READ,
|
||||
'permissions' => \OCP\PERMISSION_ALL,
|
||||
'displayname' => $FN,
|
||||
'carddata' => $vcard->serialize(),
|
||||
'uri' => $URI,
|
||||
@ -611,16 +606,6 @@ class Ldap extends AbstractBackend {
|
||||
* @return string|bool The identifier for the new contact or false on error.
|
||||
*/
|
||||
public function createContact($addressbookid, $contact, array $options = array()) {
|
||||
$backtrace = debug_backtrace();
|
||||
$trace=array();
|
||||
foreach ($backtrace as $elt) {
|
||||
foreach ($elt as $key => $line) {
|
||||
if ($key == "file" || $key == "line") {
|
||||
$trace[] = $line;
|
||||
}
|
||||
}
|
||||
}
|
||||
//error_log("stay added ".print_r($trace,1));
|
||||
|
||||
$uri = isset($options['uri']) ? $options['uri'] : null;
|
||||
|
||||
@ -741,16 +726,6 @@ class Ldap extends AbstractBackend {
|
||||
* @return bool
|
||||
*/
|
||||
public function deleteContact($addressbookid, $id, array $options = array()) {
|
||||
$backtrace = debug_backtrace();
|
||||
$trace=array();
|
||||
foreach ($backtrace as $elt) {
|
||||
foreach ($elt as $key => $line) {
|
||||
if ($key == "file" || $key == "line") {
|
||||
$trace[] = $line;
|
||||
}
|
||||
}
|
||||
}
|
||||
//error_log("stay dead ".print_r($trace, 1));
|
||||
self::setLdapParams($addressbookid);
|
||||
self::ldapCreateAndBindConnection();
|
||||
$card=null;
|
||||
@ -790,23 +765,12 @@ class Ldap extends AbstractBackend {
|
||||
}
|
||||
}
|
||||
|
||||
// Please remove this
|
||||
public function debug_string_backtrace() {
|
||||
ob_start();
|
||||
debug_print_backtrace();
|
||||
$trace = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
// Remove first item from backtrace as it's this function which
|
||||
// is redundant.
|
||||
$trace = preg_replace ('/^#0\s+' . __FUNCTION__ . "[^\n]*\n/", '', $trace, 1);
|
||||
|
||||
// Renumber backtrace items.
|
||||
$trace = preg_replace ('/^#(\d+)/me', '\'#\' . ($1 - 1)', $trace);
|
||||
|
||||
return $trace;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief sets the list of ldap addressbooks in the preferences
|
||||
* with the list given in parameter
|
||||
* @param the new list
|
||||
* @returns result|false
|
||||
*/
|
||||
protected function setAddressbookList(array $addressbookList) {
|
||||
$key = $this->name . "_list";
|
||||
$data = json_encode($addressbookList);
|
||||
@ -816,11 +780,14 @@ class Ldap extends AbstractBackend {
|
||||
: false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief gets the list of ldap addressbooks in the preferences
|
||||
* returns array()
|
||||
*/
|
||||
protected function getAddressbookList() {
|
||||
$key = $this->name . "_list";
|
||||
$data = \OCP\Config::getUserValue($this->userid, 'contacts', $key, false);
|
||||
|
||||
error_log($key." - ".$this->userid);
|
||||
return $data ? json_decode($data) : array();
|
||||
}
|
||||
}
|
||||
|
@ -90,7 +90,6 @@ class ContactController extends Controller {
|
||||
|
||||
$addressBook = $this->app->getAddressBook($params['backend'], $params['addressBookId']);
|
||||
$contact = $addressBook->getChild($params['contactId']);
|
||||
error_log($params['contactId']." found ? ".$contact->serialize());
|
||||
|
||||
if (!$contact) {
|
||||
return $response
|
||||
@ -147,7 +146,6 @@ class ContactController extends Controller {
|
||||
}
|
||||
|
||||
if (!$contact->save()) {
|
||||
error_log("not good");
|
||||
return $response->bailOut(App::$l10n->t('Error saving contact to backend'));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user