Contacts: Make js a tad DRYer. Added URL property.
This commit is contained in:
parent
ed950e3ba2
commit
5c17338ac7
4 changed files with 34 additions and 42 deletions
|
@ -33,7 +33,7 @@ $vcard = OC_Contacts_App::getContactVCard($id);
|
|||
|
||||
if(!is_array($value)){
|
||||
$value = trim($value);
|
||||
if(!$value && in_array($name, array('TEL', 'EMAIL', 'ORG', 'BDAY', 'NICKNAME', 'NOTE'))) {
|
||||
if(!$value && in_array($name, array('TEL', 'EMAIL', 'ORG', 'BDAY', 'URL', 'NICKNAME', 'NOTE'))) {
|
||||
OCP\JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('Cannot add empty property.'))));
|
||||
exit();
|
||||
}
|
||||
|
|
|
@ -98,15 +98,6 @@ if(!$value) {
|
|||
} else {
|
||||
/* setting value */
|
||||
switch($element) {
|
||||
case 'BDAY':
|
||||
case 'FN':
|
||||
case 'N':
|
||||
case 'ORG':
|
||||
case 'NOTE':
|
||||
case 'NICKNAME':
|
||||
debug('Setting string:'.$name.' '.$value);
|
||||
$vcard->setString($name, $value);
|
||||
break;
|
||||
case 'CATEGORIES':
|
||||
debug('Setting string:'.$name.' '.$value);
|
||||
$vcard->children[$line]->setValue($value);
|
||||
|
@ -128,6 +119,10 @@ if(!$value) {
|
|||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
debug('Setting string:'.$name.' '.$value);
|
||||
$vcard->setString($name, $value);
|
||||
break;
|
||||
}
|
||||
// Do checksum and be happy
|
||||
$checksum = md5($vcard->children[$line]->serialize());
|
||||
|
|
|
@ -110,10 +110,21 @@ Contacts={
|
|||
obj.tipsy('hide');
|
||||
Contacts.UI.Card.deleteProperty(obj, 'single');
|
||||
}
|
||||
|
||||
var goToUrl = function(obj) {
|
||||
var url = Contacts.UI.propertyContainerFor(obj).find('#url').val();
|
||||
if(url != '') {
|
||||
var newWindow = window.open(url,'_blank');
|
||||
newWindow.focus();
|
||||
}
|
||||
}
|
||||
|
||||
$('#identityprops a.delete').click( function() { deleteItem($(this)) });
|
||||
$('#identityprops a.delete').keydown( function() { deleteItem($(this)) });
|
||||
$('#categories_value a.edit').click( function() { $(this).tipsy('hide');OCCategories.edit(); } );
|
||||
$('#categories_value a.edit').keydown( function() { $(this).tipsy('hide');OCCategories.edit(); } );
|
||||
$('#url_value a.globe').click( function() { $(this).tipsy('hide');goToUrl($(this)); } );
|
||||
$('#url_value a.globe').keydown( function() { $(this).tipsy('hide');goToUrl($(this)); } );
|
||||
$('#fn_select').combobox({
|
||||
'id': 'fn',
|
||||
'name': 'value',
|
||||
|
@ -427,7 +438,7 @@ Contacts={
|
|||
}
|
||||
},
|
||||
loadSingleProperties:function() {
|
||||
var props = ['BDAY', 'NICKNAME', 'ORG', 'CATEGORIES'];
|
||||
var props = ['BDAY', 'NICKNAME', 'ORG', 'URL', 'CATEGORIES'];
|
||||
// Clear all elements
|
||||
$('#ident .propertycontainer').each(function(){
|
||||
if(props.indexOf($(this).data('element')) > -1) {
|
||||
|
@ -438,40 +449,22 @@ Contacts={
|
|||
}
|
||||
});
|
||||
for(var prop in props) {
|
||||
if(this.data[props[prop]] != undefined) {
|
||||
$('#contacts_propertymenu_dropdown a[data-type="'+props[prop]+'"]').parent().hide();
|
||||
var property = this.data[props[prop]][0];
|
||||
var propname = props[prop];
|
||||
if(this.data[propname] != undefined) {
|
||||
$('#contacts_propertymenu_dropdown a[data-type="'+propname+'"]').parent().hide();
|
||||
var property = this.data[propname][0];
|
||||
var value = property['value'], checksum = property['checksum'];
|
||||
switch(props[prop]) {
|
||||
case 'BDAY':
|
||||
var val = $.datepicker.parseDate('yy-mm-dd', value.substring(0, 10));
|
||||
value = $.datepicker.formatDate('dd-mm-yy', val);
|
||||
$('#contact_identity').find('#bday').val(value);
|
||||
$('#contact_identity').find('#bday_value').data('checksum', checksum);
|
||||
$('#contact_identity').find('#bday_label').show();
|
||||
$('#contact_identity').find('#bday_value').show();
|
||||
break;
|
||||
case 'NICKNAME':
|
||||
$('#contact_identity').find('#nickname').val(value);
|
||||
$('#contact_identity').find('#nickname_value').data('checksum', checksum);
|
||||
$('#contact_identity').find('#nickname_label').show();
|
||||
$('#contact_identity').find('#nickname_value').show();
|
||||
break;
|
||||
case 'ORG':
|
||||
$('#contact_identity').find('#org').val(value);
|
||||
$('#contact_identity').find('#org_value').data('checksum', checksum);
|
||||
$('#contact_identity').find('#org_label').show();
|
||||
$('#contact_identity').find('#org_value').show();
|
||||
break;
|
||||
case 'CATEGORIES':
|
||||
$('#contact_identity').find('#categories').val(value);
|
||||
$('#contact_identity').find('#categories_value').data('checksum', checksum);
|
||||
$('#contact_identity').find('#categories_label').show();
|
||||
$('#contact_identity').find('#categories_value').show();
|
||||
break;
|
||||
|
||||
if(propname == 'BDAY') {
|
||||
var val = $.datepicker.parseDate('yy-mm-dd', value.substring(0, 10));
|
||||
value = $.datepicker.formatDate('dd-mm-yy', val);
|
||||
}
|
||||
$('#contact_identity').find('#'+propname.toLowerCase()).val(value);
|
||||
$('#contact_identity').find('#'+propname.toLowerCase()+'_value').data('checksum', checksum);
|
||||
$('#contact_identity').find('#'+propname.toLowerCase()+'_label').show();
|
||||
$('#contact_identity').find('#'+propname.toLowerCase()+'_value').show();
|
||||
} else {
|
||||
$('#contacts_propertymenu_dropdown a[data-type="'+props[prop]+'"]').parent().show();
|
||||
$('#contacts_propertymenu_dropdown a[data-type="'+propname+'"]').parent().show();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -700,6 +693,7 @@ Contacts={
|
|||
Contacts.UI.Card.editAddress('new', true);
|
||||
break;
|
||||
case 'NICKNAME':
|
||||
case 'URL':
|
||||
case 'ORG':
|
||||
case 'BDAY':
|
||||
case 'CATEGORIES':
|
||||
|
|
|
@ -34,6 +34,8 @@ $id = isset($_['id']) ? $_['id'] : '';
|
|||
<dd class="propertycontainer hidden" id="org_value" data-element="ORG"><input id="org" required="required" name="value[ORG]" type="text" class="contacts_property big" name="value" value="" placeholder="<?php echo $l->t('Organization'); ?>" /><a role="button" class="action delete" title="<?php echo $l->t('Delete'); ?>"></a></dd>
|
||||
<dt class="hidden" id="nickname_label" data-element="NICKNAME"><label for="nickname"><?php echo $l->t('Nickname'); ?></label></dt>
|
||||
<dd class="propertycontainer hidden" id="nickname_value" data-element="NICKNAME"><input id="nickname" required="required" name="value[NICKNAME]" type="text" class="contacts_property big" name="value" value="" placeholder="<?php echo $l->t('Enter nickname'); ?>" /><a role="button" class="action delete" title="<?php echo $l->t('Delete'); ?>"></a></dd>
|
||||
<dt class="hidden" id="url_label" data-element="URL"><label for="nickname"><?php echo $l->t('Web site'); ?></label></dt>
|
||||
<dd class="propertycontainer hidden" id="url_value" data-element="URL"><input id="url" required="required" name="value[URL]" type="text" class="contacts_property big" name="value" value="" placeholder="<?php echo $l->t('http://www.somesite.com'); ?>" /><a role="button" class="action globe" title="<?php echo $l->t('Go to web site'); ?>"><a role="button" class="action delete" title="<?php echo $l->t('Delete'); ?>"></a></dd>
|
||||
<dt class="hidden" id="bday_label" data-element="BDAY"><label for="bday"><?php echo $l->t('Birthday'); ?></label></dt>
|
||||
<dd class="propertycontainer hidden" id="bday_value" data-element="BDAY"><input id="bday" required="required" name="value" type="text" class="contacts_property big" value="" placeholder="<?php echo $l->t('dd-mm-yyyy'); ?>" /><a role="button" class="action delete" title="<?php echo $l->t('Delete'); ?>"></a></dd>
|
||||
<dt class="hidden" id="categories_label" data-element="CATEGORIES"><label for="categories"><?php echo $l->t('Groups'); ?></label></dt>
|
||||
|
@ -108,6 +110,7 @@ $id = isset($_['id']) ? $_['id'] : '';
|
|||
<li><a role="menuitem" data-type="EMAIL"><?php echo $l->t('Email'); ?></a></li>
|
||||
<li><a role="menuitem" data-type="ADR"><?php echo $l->t('Address'); ?></a></li>
|
||||
<li><a role="menuitem" data-type="NOTE"><?php echo $l->t('Note'); ?></a></li>
|
||||
<li><a role="menuitem" data-type="URL"><?php echo $l->t('Web site'); ?></a></li>
|
||||
<li><a role="menuitem" data-type="CATEGORIES"><?php echo $l->t('Groups'); ?></a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue