mirror of
https://github.com/owncloudarchive/contacts.git
synced 2024-12-01 13:24:10 +01:00
Re-added deleting properties.
This commit is contained in:
parent
7e52c45675
commit
2dba1d3672
@ -27,18 +27,37 @@ OCP\JSON::callCheck();
|
||||
|
||||
require_once __DIR__.'/../loghandler.php';
|
||||
|
||||
$id = $_POST['id'];
|
||||
$checksum = $_POST['checksum'];
|
||||
$id = isset($_POST['id']) ? $_POST['id'] : null;
|
||||
$name = isset($_POST['name']) ? $_POST['name'] : null;
|
||||
$checksum = isset($_POST['checksum']) ? $_POST['checksum'] : null;
|
||||
$l10n = OC_Contacts_App::$l10n;
|
||||
|
||||
$vcard = OC_Contacts_App::getContactVCard( $id );
|
||||
$line = OC_Contacts_App::getPropertyLineByChecksum($vcard, $checksum);
|
||||
if(is_null($line)) {
|
||||
bailOut($l10n->t('Information about vCard is incorrect. Please reload the page.'));
|
||||
exit();
|
||||
$multi_properties = array('EMAIL', 'TEL', 'IMPP', 'ADR', 'URL');
|
||||
|
||||
if(!$id) {
|
||||
bailOut(OC_Contacts_App::$l10n->t('id is not set.'));
|
||||
}
|
||||
|
||||
unset($vcard->children[$line]);
|
||||
if(!$name) {
|
||||
bailOut(OC_Contacts_App::$l10n->t('element name is not set.'));
|
||||
}
|
||||
|
||||
if(!$checksum && in_array($name, $multi_properties)) {
|
||||
bailOut(OC_Contacts_App::$l10n->t('checksum is not set.'));
|
||||
}
|
||||
|
||||
$vcard = OC_Contacts_App::getContactVCard( $id );
|
||||
|
||||
if(!is_null($checksum)) {
|
||||
$line = OC_Contacts_App::getPropertyLineByChecksum($vcard, $checksum);
|
||||
if(is_null($line)) {
|
||||
bailOut($l10n->t('Information about vCard is incorrect. Please reload the page.'));
|
||||
exit();
|
||||
}
|
||||
unset($vcard->children[$line]);
|
||||
} else {
|
||||
unset($vcard->{$name});
|
||||
}
|
||||
|
||||
try {
|
||||
OC_Contacts_VCard::edit($id, $vcard);
|
||||
|
@ -45,8 +45,9 @@ input:hover:not([type="checkbox"]), input:active:not([type="checkbox"]), textare
|
||||
dl.form { display: inline-block; width: auto; margin: 0; padding: 0; cursor: normal; }
|
||||
.form dt { display: table-cell; clear: left; float: left; width: 7em; margin: 0; padding: 0.8em 0.5em 0 0; text-align:right; text-overflow:ellipsis; o-text-overflow: ellipsis; vertical-align: text-bottom; color: #bbb;/* white-space: pre-wrap; white-space: -moz-pre-wrap !important; white-space: -pre-wrap; white-space: -o-pre-wrap;*/ }
|
||||
.form dd { display: table-cell; clear: right; float: left; margin: 0; padding: 0; white-space: nowrap; vertical-align: text-bottom; }
|
||||
.action { display: inline-block; }
|
||||
.add { background:url('%webroot%/core/img/actions/add.svg') no-repeat center; clear: both; }
|
||||
.delete { background:url('%webroot%/core/img/actions/delete.svg') no-repeat center; }
|
||||
.delete { background:url('%webroot%/core/img/actions/delete.png') no-repeat center; }
|
||||
.edit { background:url('%webroot%/core/img/actions/rename.svg') no-repeat center; }
|
||||
.share { background:url('%webroot%/core/img/actions/share.svg') no-repeat center; }
|
||||
.mail { background:url('%webroot%/core/img/actions/mail.svg') no-repeat center; }
|
||||
|
@ -38,10 +38,6 @@ OC.Contacts = OC.Contacts || {};
|
||||
}
|
||||
}
|
||||
|
||||
Contact.prototype.removeProperty = function(obj) {
|
||||
console.log('Contact.removeProperty', name)
|
||||
}
|
||||
|
||||
Contact.prototype.addProperty = function($option, name) {
|
||||
console.log('Contact.addProperty', name)
|
||||
switch(name) {
|
||||
@ -75,6 +71,54 @@ OC.Contacts = OC.Contacts || {};
|
||||
}
|
||||
}
|
||||
|
||||
Contact.prototype.deleteProperty = function(params) {
|
||||
var obj = params.obj;
|
||||
if(!this.enabled) {
|
||||
return;
|
||||
}
|
||||
var element = this.propertyTypeFor(obj);
|
||||
var $container = this.propertyContainerFor(obj);
|
||||
console.log('Contact.deleteProperty, element', element, $container);
|
||||
var params = {
|
||||
name: element,
|
||||
id: this.id
|
||||
};
|
||||
if(this.multi_properties.indexOf(element) !== -1) {
|
||||
params['checksum'] = this.checksumFor(obj);
|
||||
}
|
||||
this.setAsSaving(obj, true);
|
||||
var self = this;
|
||||
$.post(OC.filePath('contacts', 'ajax', 'contact/deleteproperty.php'), params, function(jsondata) {
|
||||
if(!jsondata) {
|
||||
$(document).trigger('status.contact.error', {
|
||||
status: 'error',
|
||||
message: t('contacts', 'Network or server error. Please inform administrator.'),
|
||||
});
|
||||
self.setAsSaving(obj, false);
|
||||
return false;
|
||||
}
|
||||
if(jsondata.status == 'success') {
|
||||
// TODO: Remove from internal data structure
|
||||
if(self.multi_properties.indexOf(element) !== -1) {
|
||||
$container.remove();
|
||||
} else {
|
||||
self.setAsSaving(obj, false);
|
||||
self.$fullelem.find('[data-element="' + element.toLowerCase() + '"]').hide();
|
||||
$container.find('input.value').val('');
|
||||
self.$addMenu.find('option[value="' + element.toUpperCase() + '"]').prop('disabled', false);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
$(document).trigger('status.contact.error', {
|
||||
status: 'error',
|
||||
message: jsondata.data.message,
|
||||
});
|
||||
self.setAsSaving(obj, false);
|
||||
return false;
|
||||
}
|
||||
},'json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Act on change of a property.
|
||||
* If this is a new contact it will first be saved to the datastore and a
|
||||
@ -93,6 +137,7 @@ OC.Contacts = OC.Contacts || {};
|
||||
if(params.obj) {
|
||||
obj = params.obj;
|
||||
q = this.queryStringFor(obj);
|
||||
element = this.propertyTypeFor(obj);
|
||||
} else {
|
||||
element = params.name;
|
||||
q += 'value=' + encodeURIComponent(params.value) + '&name=' + element;
|
||||
@ -110,8 +155,15 @@ OC.Contacts = OC.Contacts || {};
|
||||
return false;
|
||||
}
|
||||
if(jsondata.status == 'success') {
|
||||
console.log(self.data[element]);
|
||||
if(!self.data[element]) {
|
||||
self.data[element] = [];
|
||||
}
|
||||
if(self.multi_properties.indexOf(element) !== -1) {
|
||||
$container.data('checksum', jsondata.data.checksum);
|
||||
self.propertyContainerFor(obj).data('checksum', jsondata.data.checksum);
|
||||
} else {
|
||||
// TODO: Save value and parameters internally
|
||||
self.data[element][0] = {name: element};
|
||||
}
|
||||
self.setAsSaving(obj, false);
|
||||
return true;
|
||||
@ -216,7 +268,7 @@ OC.Contacts = OC.Contacts || {};
|
||||
q += '&value=' + encodeURIComponent($(obj).val());
|
||||
} else {
|
||||
q += '&' + this.propertyContainerFor(obj)
|
||||
.find('input.value,select.value,textarea.value').serialize();
|
||||
.find('input.value,select.value,textarea.value,.parameter').serialize();
|
||||
}
|
||||
return q;
|
||||
}
|
||||
@ -291,7 +343,22 @@ OC.Contacts = OC.Contacts || {};
|
||||
self.addProperty($opt, $(this).val());
|
||||
$(this).val('');
|
||||
});
|
||||
this.$fullelem.on('change', '.value', function(event) {
|
||||
var $singleelements = this.$fullelem.find('dd.propertycontainer');
|
||||
$singleelements.find('.action').css('opacity', '0');
|
||||
$singleelements.on('mouseenter', function() {
|
||||
$(this).find('.action').css('opacity', '1');
|
||||
}).on('mouseleave', function() {
|
||||
$(this).find('.action').css('opacity', '0');
|
||||
});
|
||||
this.$fullelem.on('click keydown', '.delete', function(event) {
|
||||
console.log('delete', event);
|
||||
$('.tipsy').remove();
|
||||
if(wrongKey(event)) {
|
||||
return;
|
||||
}
|
||||
self.deleteProperty({obj:event.target});
|
||||
});
|
||||
this.$fullelem.on('change', '.value,.parameter', function(event) {
|
||||
console.log('change', event);
|
||||
self.saveProperty({obj:event.target});
|
||||
});
|
||||
|
@ -89,7 +89,7 @@
|
||||
|
||||
<script id="contactListItemTemplate" type="text/template">
|
||||
<tr class="contact" data-id="{id}">
|
||||
<td class="name"
|
||||
<td class="name"
|
||||
style="background: url('<?php echo OCP\Util::linkTo('contacts', 'thumbnail.php'); ?>?id={id}')">
|
||||
<input type="checkbox" name="id" value="{id}" />{name}
|
||||
</td>
|
||||
@ -129,24 +129,28 @@
|
||||
</dt>
|
||||
<dd data-element="nickname" class="propertycontainer">
|
||||
<input class="value" type="text" name="value" value="{nickname}" />
|
||||
<a role="button" class="action delete" title="<?php echo $l->t('Delete'); ?>"></a>
|
||||
</dd>
|
||||
<dt data-element="title">
|
||||
<?php echo $l->t('Title'); ?>
|
||||
</dt>
|
||||
<dd data-element="title" class="propertycontainer">
|
||||
<input class="value" type="text" name="value" value="{title}" />
|
||||
<a role="button" class="action delete" title="<?php echo $l->t('Delete'); ?>"></a>
|
||||
</dd>
|
||||
<dt data-element="org">
|
||||
<?php echo $l->t('Organization'); ?>
|
||||
</dt>
|
||||
<dd data-element="org" class="propertycontainer">
|
||||
<input class="value" type="text" name="value" value="{org}" />
|
||||
<a role="button" class="action delete" title="<?php echo $l->t('Delete'); ?>"></a>
|
||||
</dd>
|
||||
<dt data-element="bday">
|
||||
<?php echo $l->t('Birthday'); ?>
|
||||
</dt>
|
||||
<dd data-element="bday" class="propertycontainer">
|
||||
<input class="value" type="text" name="value" value="{bday}" />
|
||||
<a role="button" class="action delete" title="<?php echo $l->t('Delete'); ?>"></a>
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
@ -199,10 +203,10 @@
|
||||
<script id="contactDetailsTemplate" class="hidden" type="text/template">
|
||||
<div class="email">
|
||||
<li data-element="email" data-checksum="{checksum}" class="propertycontainer">
|
||||
<select class="rtl type value" name="parameters[TYPE][]">
|
||||
<select class="rtl type parameter" name="parameters[TYPE][]">
|
||||
<?php echo OCP\html_select_options($_['email_types'], array()) ?>
|
||||
</select>
|
||||
<input type="checkbox" class="value tip" name="parameters[TYPE][]" value="PREF" title="<?php echo $l->t('Preferred'); ?>" />
|
||||
<input type="checkbox" class="parameter tip" name="parameters[TYPE][]" value="PREF" title="<?php echo $l->t('Preferred'); ?>" />
|
||||
<input type="email" required="required" class="nonempty value" name="value" value="{value}" x-moz-errormessage="<?php echo $l->t('Please specify a valid email address.'); ?>" placeholder="<?php echo $l->t('someone@example.com'); ?>" />
|
||||
<span class="listactions">
|
||||
<a class="action mail" title="<?php echo $l->t('Mail to address'); ?>"></a>
|
||||
@ -212,10 +216,10 @@
|
||||
</div>
|
||||
<div class="tel">
|
||||
<li data-element="tel" data-checksum="{checksum}" class="propertycontainer">
|
||||
<select class="rtl type value" name="parameters[TYPE][]">
|
||||
<select class="rtl type parameter" name="parameters[TYPE][]">
|
||||
<?php echo OCP\html_select_options($_['phone_types'], array()) ?>
|
||||
</select>
|
||||
<input type="checkbox" class="value tip" name="parameters[TYPE][]" value="PREF" title="<?php echo $l->t('Preferred'); ?>" />
|
||||
<input type="checkbox" class="parameter tip" name="parameters[TYPE][]" value="PREF" title="<?php echo $l->t('Preferred'); ?>" />
|
||||
<input type="tel" required="required" class="nonempty value" name="value" value="{value}" placeholder="<?php echo $l->t('Enter phone number'); ?>" />
|
||||
<span class="listactions">
|
||||
<a role="button" class="action delete" title="<?php echo $l->t('Delete phone number'); ?>"></a>
|
||||
@ -224,10 +228,10 @@
|
||||
</div>
|
||||
<div class="url">
|
||||
<li data-element="url" data-checksum="{checksum}" class="propertycontainer">
|
||||
<select class="rtl type value" name="parameters[TYPE][]">
|
||||
<select class="rtl type parameter" name="parameters[TYPE][]">
|
||||
<?php echo OCP\html_select_options($_['email_types'], array()) ?>
|
||||
</select>
|
||||
<input type="checkbox" class="value tip" name="parameters[TYPE][]" value="PREF" title="<?php echo $l->t('Preferred'); ?>" />
|
||||
<input type="checkbox" class="parameter tip" name="parameters[TYPE][]" value="PREF" title="<?php echo $l->t('Preferred'); ?>" />
|
||||
<input type="url" required="required" class="nonempty value" name="value" value="{value}" placeholder="http://www.example.com/" />
|
||||
<span class="listactions">
|
||||
<a role="button" class="action globe" title="<?php echo $l->t('Go to web site'); ?>">
|
||||
@ -237,10 +241,10 @@
|
||||
</div>
|
||||
<div class="adr">
|
||||
<li data-element="adr" data-checksum="{checksum}" class="propertycontainer">
|
||||
<select class="rtl type value" name="parameters[TYPE][]">
|
||||
<select class="rtl type parameter" name="parameters[TYPE][]">
|
||||
<?php echo OCP\html_select_options($_['adr_types'], array()) ?>
|
||||
</select>
|
||||
<input type="checkbox" class="value tip" name="parameters[TYPE][]" value="PREF" title="<?php echo $l->t('Preferred'); ?>" />
|
||||
<input type="checkbox" class="parameter tip" name="parameters[TYPE][]" value="PREF" title="<?php echo $l->t('Preferred'); ?>" />
|
||||
<span class="float adr">{value}</span>
|
||||
<span class="listactions">
|
||||
<a class="action globe" title="<?php echo $l->t('View on map'); ?>"></a>
|
||||
@ -257,12 +261,12 @@
|
||||
</div>
|
||||
<div class="impp">
|
||||
<li data-element="impp" data-checksum="{checksum}" class="propertycontainer">
|
||||
<select class="type value" name="parameters[TYPE][]">
|
||||
<select class="type parameter" name="parameters[TYPE][]">
|
||||
<?php echo OCP\html_select_options($_['impp_types'], array()) ?>
|
||||
</select>
|
||||
<input type="checkbox" class="value impp tip" name="parameters[TYPE][]" value="PREF" title="<?php echo $l->t('Preferred'); ?>" />
|
||||
<input type="checkbox" class="parameter impp tip" name="parameters[TYPE][]" value="PREF" title="<?php echo $l->t('Preferred'); ?>" />
|
||||
<div class="select_wrapper">
|
||||
<select class="rtl value label impp" name="parameters[X-SERVICE-TYPE]">
|
||||
<select class="rtl parameter label impp" name="parameters[X-SERVICE-TYPE]">
|
||||
<?php echo OCP\html_select_options($_['im_protocols'], array()) ?>
|
||||
</select>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user