Contacts: Fix adding/updating address book with empty name.
This commit is contained in:
parent
456ada01fa
commit
ffdfe8257b
|
@ -13,7 +13,13 @@ OC_JSON::checkLoggedIn();
|
||||||
OC_JSON::checkAppEnabled('contacts');
|
OC_JSON::checkAppEnabled('contacts');
|
||||||
|
|
||||||
$userid = OC_User::getUser();
|
$userid = OC_User::getUser();
|
||||||
$bookid = OC_Contacts_Addressbook::add($userid, strip_tags($_POST['name']), null);
|
$name = trim(strip_tags($_POST['name']));
|
||||||
|
if(!$name) {
|
||||||
|
OC_JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('Cannot add addressbook with an empty name.'))));
|
||||||
|
OC_Log::write('contacts','ajax/createaddressbook.php: Cannot add addressbook with an empty name: '.strip_tags($_POST['name']), OC_Log::ERROR);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
$bookid = OC_Contacts_Addressbook::add($userid, $name, null);
|
||||||
if(!$bookid) {
|
if(!$bookid) {
|
||||||
OC_JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('Error adding addressbook.'))));
|
OC_JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('Error adding addressbook.'))));
|
||||||
OC_Log::write('contacts','ajax/createaddressbook.php: Error adding addressbook: '.$_POST['name'], OC_Log::ERROR);
|
OC_Log::write('contacts','ajax/createaddressbook.php: Error adding addressbook: '.$_POST['name'], OC_Log::ERROR);
|
||||||
|
|
|
@ -15,7 +15,14 @@ OC_JSON::checkAppEnabled('contacts');
|
||||||
$bookid = $_POST['id'];
|
$bookid = $_POST['id'];
|
||||||
OC_Contacts_App::getAddressbook($bookid); // is owner access check
|
OC_Contacts_App::getAddressbook($bookid); // is owner access check
|
||||||
|
|
||||||
if(!OC_Contacts_Addressbook::edit($bookid, $_POST['name'], null)) {
|
$name = trim(strip_tags($_POST['name']));
|
||||||
|
if(!$name) {
|
||||||
|
OC_JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('Cannot update addressbook with an empty name.'))));
|
||||||
|
OC_Log::write('contacts','ajax/updateaddressbook.php: Cannot update addressbook with an empty name: '.strip_tags($_POST['name']), OC_Log::ERROR);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!OC_Contacts_Addressbook::edit($bookid, $name, null)) {
|
||||||
OC_JSON::error(array('data' => array('message' => $l->t('Error updating addressbook.'))));
|
OC_JSON::error(array('data' => array('message' => $l->t('Error updating addressbook.'))));
|
||||||
OC_Log::write('contacts','ajax/updateaddressbook.php: Error adding addressbook: ', OC_Log::ERROR);
|
OC_Log::write('contacts','ajax/updateaddressbook.php: Error adding addressbook: ', OC_Log::ERROR);
|
||||||
//exit();
|
//exit();
|
||||||
|
|
|
@ -1043,13 +1043,13 @@ Contacts={
|
||||||
return false;
|
return false;
|
||||||
}else{
|
}else{
|
||||||
$.post(OC.filePath('contacts', 'ajax', 'deletebook.php'), { id: bookid},
|
$.post(OC.filePath('contacts', 'ajax', 'deletebook.php'), { id: bookid},
|
||||||
function(data) {
|
function(jsondata) {
|
||||||
if (data.status == 'success'){
|
if (jsondata.status == 'success'){
|
||||||
$('#chooseaddressbook_dialog').dialog('destroy').remove();
|
$('#chooseaddressbook_dialog').dialog('destroy').remove();
|
||||||
Contacts.UI.Contacts.update();
|
Contacts.UI.Contacts.update();
|
||||||
Contacts.UI.Addressbooks.overview();
|
Contacts.UI.Addressbooks.overview();
|
||||||
} else {
|
} else {
|
||||||
Contacts.UI.messageBox(t('contacts', 'Error'), data.message);
|
Contacts.UI.messageBox(t('contacts', 'Error'), jsondata.data.message);
|
||||||
//alert('Error: ' + data.message);
|
//alert('Error: ' + data.message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1059,10 +1059,14 @@ Contacts={
|
||||||
Contacts.UI.notImplemented();
|
Contacts.UI.notImplemented();
|
||||||
},
|
},
|
||||||
submit:function(button, bookid){
|
submit:function(button, bookid){
|
||||||
var displayname = $("#displayname_"+bookid).val();
|
var displayname = $("#displayname_"+bookid).val().trim();
|
||||||
var active = $("#edit_active_"+bookid+":checked").length;
|
var active = $("#edit_active_"+bookid+":checked").length;
|
||||||
var description = $("#description_"+bookid).val();
|
var description = $("#description_"+bookid).val();
|
||||||
|
|
||||||
|
if(displayname.length == 0) {
|
||||||
|
Contacts.UI.messageBox(t('contacts', 'Error'), t('contacts', 'Displayname cannot be empty.'));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
var url;
|
var url;
|
||||||
if (bookid == 'new'){
|
if (bookid == 'new'){
|
||||||
url = OC.filePath('contacts', 'ajax', 'createaddressbook.php');
|
url = OC.filePath('contacts', 'ajax', 'createaddressbook.php');
|
||||||
|
@ -1070,12 +1074,14 @@ Contacts={
|
||||||
url = OC.filePath('contacts', 'ajax', 'updateaddressbook.php');
|
url = OC.filePath('contacts', 'ajax', 'updateaddressbook.php');
|
||||||
}
|
}
|
||||||
$.post(url, { id: bookid, name: displayname, active: active, description: description },
|
$.post(url, { id: bookid, name: displayname, active: active, description: description },
|
||||||
function(data){
|
function(jsondata){
|
||||||
if(data.status == 'success'){
|
if(jsondata.status == 'success'){
|
||||||
$(button).closest('tr').prev().html(data.page).show().next().remove();
|
$(button).closest('tr').prev().html(data.page).show().next().remove();
|
||||||
|
Contacts.UI.Contacts.update();
|
||||||
|
} else {
|
||||||
|
Contacts.UI.messageBox(t('contacts', 'Error'), jsondata.data.message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Contacts.UI.Contacts.update();
|
|
||||||
},
|
},
|
||||||
cancel:function(button, bookid){
|
cancel:function(button, bookid){
|
||||||
$(button).closest('tr').prev().show().next().remove();
|
$(button).closest('tr').prev().show().next().remove();
|
||||||
|
|
|
@ -124,12 +124,14 @@ Contacts={
|
||||||
url = OC.filePath('contacts', 'ajax', 'updateaddressbook.php');
|
url = OC.filePath('contacts', 'ajax', 'updateaddressbook.php');
|
||||||
}
|
}
|
||||||
$.post(url, { id: bookid, name: displayname, active: active, description: description },
|
$.post(url, { id: bookid, name: displayname, active: active, description: description },
|
||||||
function(data){
|
function(jsondata){
|
||||||
if(data.status == 'success'){
|
if(jsondata.status == 'success'){
|
||||||
$(button).closest('tr').prev().html(data.page).show().next().remove();
|
$(button).closest('tr').prev().html(data.page).show().next().remove();
|
||||||
|
Contacts.UI.Contacts.update();
|
||||||
|
} else {
|
||||||
|
Contacts.UI.messageBox(t('contacts', 'Error'), jsondata.data.message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Contacts.UI.Contacts.update();
|
|
||||||
},
|
},
|
||||||
cancel:function(button, bookid){
|
cancel:function(button, bookid){
|
||||||
$(button).closest('tr').prev().show().next().remove();
|
$(button).closest('tr').prev().show().next().remove();
|
||||||
|
|
Loading…
Reference in New Issue