1
0
mirror of https://github.com/owncloudarchive/contacts.git synced 2025-01-19 08:52:22 +01:00

Disable save button while saving. Streamlined code.

This commit is contained in:
Tom Needham 2011-11-29 22:11:42 +00:00
parent 05ba42ae8b
commit 868f196381
14 changed files with 168 additions and 58 deletions

View File

@ -68,11 +68,16 @@ foreach( $add as $propname){
}
$id = OC_Contacts_VCard::add($aid,$vcard->serialize());
$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR');
$phone_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'TEL');
$details = OC_Contacts_VCard::structureContact($vcard);
$name = $details['FN'][0]['value'];
$tmpl = new OC_Template('contacts','part.details');
$tmpl->assign('details',$details);
$tmpl->assign('id',$id);
$tmpl->assign('adr_types',$adr_types);
$tmpl->assign('phone_types',$phone_types);
$page = $tmpl->fetchPage();
OC_JSON::success(array('data' => array( 'id' => $id, 'name' => $name, 'page' => $page )));

View File

@ -51,10 +51,22 @@ if(is_null($vcard)){
exit();
}
$property_types = array(
'ADR' => $l10n->t('Address'),
'TEL' => $l10n->t('Telephone'),
'EMAIL' => $l10n->t('Email'),
'ORG' => $l10n->t('Organization'),
);
$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR');
$phone_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'TEL');
$details = OC_Contacts_VCard::structureContact($vcard);
$tmpl = new OC_Template('contacts','part.details');
$tmpl->assign('details',$details);
$tmpl->assign('id',$id);
$tmpl->assign('property_types',$property_types);
$tmpl->assign('adr_types',$adr_types);
$tmpl->assign('phone_types',$phone_types);
$page = $tmpl->fetchPage();
OC_JSON::success(array('data' => array( 'id' => $id, 'page' => $page )));

View File

@ -70,6 +70,9 @@ $vcard->children[$line]->setValue($value);
// Add parameters
$postparameters = isset($_POST['parameters'])?$_POST['parameters']:array();
if ($vcard->children[$line]->name == 'TEL' && !array_key_exists('TYPE', $postparameters)){
$postparameters['TYPE']='';
}
for($i=0;$i<count($vcard->children[$line]->parameters);$i++){
$name = $vcard->children[$line]->parameters[$i]->name;
if(array_key_exists($name,$postparameters)){
@ -77,7 +80,14 @@ for($i=0;$i<count($vcard->children[$line]->parameters);$i++){
unset($vcard->children[$line]->parameters[$i]);
}
else{
$vcard->children[$line]->parameters[$i]->value = $postparameters[$name];
unset($vcard->children[$line][$name]);
$values = $postparameters[$name];
if (!is_array($values)){
$values = array($values);
}
foreach($values as $value){
$vcard->children[$line]->add($name, $value);
}
}
unset($postparameters[$name]);
}
@ -94,7 +104,12 @@ $checksum = md5($vcard->children[$line]->serialize());
OC_Contacts_VCard::edit($id,$vcard->serialize());
$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR');
$phone_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'TEL');
$tmpl = new OC_Template('contacts','part.property');
$tmpl->assign('adr_types',$adr_types);
$tmpl->assign('phone_types',$phone_types);
$tmpl->assign('property',OC_Contacts_VCard::structureProperty($vcard->children[$line],$line));
$page = $tmpl->fetchPage();

View File

@ -29,9 +29,14 @@ $l10n = new OC_L10N('contacts');
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR');
$phone_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'TEL');
$addressbooks = OC_Contacts_Addressbook::all(OC_USER::getUser());
$tmpl = new OC_Template('contacts','part.addcardform');
$tmpl->assign('addressbooks',$addressbooks);
$tmpl->assign('adr_types',$adr_types);
$tmpl->assign('phone_types',$phone_types);
$page = $tmpl->fetchPage();
OC_JSON::success(array('data' => array( 'page' => $page )));

View File

@ -61,11 +61,15 @@ if(is_null($line)){
exit();
}
$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR');
$phone_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'TEL');
$tmpl = new OC_Template('contacts','part.setpropertyform');
$tmpl->assign('id',$id);
$tmpl->assign('checksum',$checksum);
$tmpl->assign('property',OC_Contacts_VCard::structureProperty($vcard->children[$line]));
$tmpl->assign('adr_types',$adr_types);
$tmpl->assign('phone_types',$phone_types);
$page = $tmpl->fetchPage();
OC_JSON::success(array('data' => array( 'page' => $page )));

View File

@ -94,16 +94,14 @@ This stylesheet forms part of the Formtastic Rails Plugin
/* INPUTS
--------------------------------------------------------------------------------------------------*/
.formtastic .inputs {
overflow:hidden; /* clear containing floats */
}
.formtastic .input {
overflow:hidden; /* clear containing floats */
padding:0.5em 0; /* padding and negative margin juggling is for Firefox */
margin-top:-0.5em;
margin-bottom:1em;
}
.formtastic .input {
}
/* LEFT ALIGNED LABELS
--------------------------------------------------------------------------------------------------*/

View File

@ -3,16 +3,22 @@
#contacts_deletecard {position:absolute;top:15px;right:0;}
#contacts_details_list { list-style:none; }
#contacts_details_list li { overflow:hidden; }
#contacts_details_list li p.contacts_property_name { width:25%; float:left;text-align:right;padding-right:0.3em; }
#contacts_details_list li p.contacts_property_data, #contacts_details_list li ul.contacts_property_data { width:72%; overflow:hidden; }
#contacts_addproperty, #contacts_addproperty_button { margin-left:25%; }
#contacts_details_list li { overflow:visible; }
#contacts_details_list li p.contacts_property_name { width:25%; float:left;text-align:right;padding-right:0.3em;color:#666; }
#contacts_details_list li p.contacts_property_data, #contacts_details_list li ul.contacts_property_data { width:72%;float:left; }
#contacts_setproperty_button { margin-left:25%; }
.contacts_property_data ul, .contacts_property_data ol { list-style:none; }
.contacts_property_data ul, ol.contacts_property_data { list-style:none; }
.contacts_property_data li { overflow: hidden; }
.contacts_property_data li label { width:20%; float:left; text-align:right;padding-right:0.3em; }
.contacts_property_data input { float:left; }
.contacts_property_data li input { width:70%;overflow:hidden; }
.chzn-container { margin:3px 0 0; }
.chzn-container .chzn-choices { border-radius: 0.5em; }
.chzn-container.chzn-container-active .chzn-choices { border-bottom-left-radius: 0;border-bottom-right-radius: 0; }
.chzn-container .chzn-drop { border-bottom-left-radius: 0.5em;border-bottom-right-radius: 0.5em; }
/* Form setup ----------------------------------------------------------------*/
/* .forme {} */
/* .forme ul, .forme ol { list-style:none; } */

View File

@ -75,8 +75,14 @@ if( !is_null($id) || count($contacts)){
$details = OC_Contacts_VCard::structureContact($vcard);
}
$l10n = new OC_L10N('contacts');
$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR');
$phone_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'TEL');
// Process the template
$tmpl = new OC_Template( 'contacts', 'index', 'user' );
$tmpl->assign('adr_types',$adr_types);
$tmpl->assign('phone_types',$phone_types);
$tmpl->assign('addressbooks', $addressbooks);
$tmpl->assign('contacts', $contacts);
$tmpl->assign('details', $details );

View File

@ -56,14 +56,15 @@ $(document).ready(function(){
$('#contacts_addpropertyform #contacts_fieldpart').remove();
$('#contacts_addpropertyform #contacts_generic').remove();
if($(this).val() == 'ADR'){
$('#contacts_addresspart').clone().insertBefore($('#contacts_addpropertyform input[type="submit"]'));
$('#contacts_addresspart').clone().insertAfter($('#contacts_addpropertyform .contacts_property_name'));
}
else if($(this).val() == 'TEL'){
$('#contacts_phonepart').clone().insertBefore($('#contacts_addpropertyform input[type="submit"]'));
$('#contacts_phonepart').clone().insertAfter($('#contacts_addpropertyform .contacts_property_name'));
}
else{
$('#contacts_generic').clone().insertBefore($('#contacts_addpropertyform input[type="submit"]'));
$('#contacts_generic').clone().insertAfter($('#contacts_addpropertyform .contacts_property_name'));
}
$('#contacts_addpropertyform .contacts_property_data select').chosen();
});
$('#contacts_addpropertyform input[type="submit"]').live('click',function(){
@ -82,7 +83,8 @@ $(document).ready(function(){
$.getJSON('ajax/showaddcard.php',{},function(jsondata){
if(jsondata.status == 'success'){
$('#rightcontent').data('id','');
$('#rightcontent').html(jsondata.data.page);
$('#rightcontent').html(jsondata.data.page)
.find('select').chosen();
}
else{
alert(jsondata.data.message);
@ -111,7 +113,8 @@ $(document).ready(function(){
var checksum = $(this).parents('li').first().data('checksum');
$.getJSON('ajax/showsetproperty.php',{'id': id, 'checksum': checksum },function(jsondata){
if(jsondata.status == 'success'){
$('.contacts_property[data-checksum="'+checksum+'"]').html(jsondata.data.page);
$('.contacts_property[data-checksum="'+checksum+'"]').html(jsondata.data.page)
.find('select').chosen();
}
else{
alert(jsondata.data.message);
@ -148,10 +151,12 @@ $(document).ready(function(){
$('.contacts_property').live('mouseenter',function(){
$(this).find('span').show();
$(this).find('span[data-use]').show();
});
$('.contacts_property').live('mouseleave',function(){
$(this).find('span').hide();
$(this).find('span[data-use]').hide();
});
$('#contacts_addcardform select').chosen();
});

View File

@ -95,10 +95,15 @@ class OC_Contacts_VCard{
$card = self::parse($data);
if(!is_null($card)){
// VCARD must have a version
$hasversion = false;
foreach($card->children as $property){
if($property->name == 'FN'){
$fn = $property->value;
}
elseif($property->name == 'VERSION'){
$hasversion = true;
}
elseif(is_null($uri) && $property->name == 'UID' ){
$uri = $property->value.'.vcf';
}
@ -109,6 +114,11 @@ class OC_Contacts_VCard{
$card->add(new Sabre_VObject_Property('UID',$uid));
$data = $card->serialize();
};
// Add version if needed
if(!$hasversion){
$card->add(new Sabre_VObject_Property('VERSION','3.0'));
$data = $card->serialize();
}
}
else{
// that's hard. Creating a UID and not saving it
@ -286,7 +296,13 @@ class OC_Contacts_VCard{
$property = new Sabre_VObject_Property( $name, $value );
$parameternames = array_keys($parameters);
foreach($parameternames as $i){
$property->parameters[] = new Sabre_VObject_Parameter($i,$parameters[$i]);
$values = $parameters[$i];
if (!is_array($values)){
$values = array($values);
}
foreach($values as $value){
$property->add($i, $value);
}
}
$vcard->add($property);
@ -342,7 +358,17 @@ class OC_Contacts_VCard{
$parameter->name = 'PREF';
$parameter->value = '1';
}
$temp['parameters'][$parameter->name] = $parameter->value;
if ($property->name == 'TEL' && $parameter->name == 'TYPE'){
if (isset($temp['parameters'][$parameter->name])){
$temp['parameters'][$parameter->name][] = $parameter->value;
}
else{
$temp['parameters'][$parameter->name] = array($parameter->value);
}
}
else{
$temp['parameters'][$parameter->name] = $parameter->value;
}
}
return $temp;
}
@ -362,4 +388,24 @@ class OC_Contacts_VCard{
return null;
}
}
public static function getTypesOfProperty($l, $prop){
switch($prop){
case 'ADR':
return array(
'WORK' => $l->t('Work'),
'HOME' => $l->t('Home'),
);
case 'TEL':
return array(
'HOME' => $l->t('Home'),
'CELL' => $l->t('Mobile'),
'WORK' => $l->t('Work'),
'TEXT' => $l->t('Text'),
'VOICE' => $l->t('Voice'),
'FAX' => $l->t('Fax'),
'VIDEO' => $l->t('Video'),
'PAGER' => $l->t('Pager'),
);
}
}
}

View File

@ -7,9 +7,7 @@
<li class="input stringish">
<label class="label" for="id"><?php echo $l->t('Group'); ?></label>
<select name="id" size="1">
<?php foreach($_['addressbooks'] as $addressbook): ?>
<option value="<?php echo $addressbook['id']; ?>"><?php echo $addressbook['displayname']; ?></option>
<?php endforeach; ?>
<?php echo html_select_options($_['addressbooks'], null, array('value'=>'id', 'label'=>'displayname')); ?>
</select>
</li>
</ol>
@ -45,15 +43,8 @@
</li>
<li class="fragment">
<label for="tel_type"><?php echo $l->t('Type'); ?></label>
<select id="TEL" name="parameters[TEL][TYPE]" size="1">
<option value="home"><?php echo $l->t('Home'); ?></option>
<option value="cell" selected="selected"><?php echo $l->t('Mobile'); ?></option>
<option value="work"><?php echo $l->t('Work'); ?></option>
<option value="text"><?php echo $l->t('Text'); ?></option>
<option value="voice"><?php echo $l->t('Voice'); ?></option>
<option value="fax"><?php echo $l->t('Fax'); ?></option>
<option value="video"><?php echo $l->t('Video'); ?></option>
<option value="pager"><?php echo $l->t('Pager'); ?></option>
<select id="TEL" name="parameters[TEL][TYPE][]" multiple="multiple">
<?php echo html_select_options($_['phone_types'], 'CELL') ?>
</select>
</li>
</ol>
@ -67,8 +58,7 @@
<li class="input">
<label class="label" for="adr_type"><?php echo $l->t('Type'); ?></label>
<select id="adr_type" name="parameters[ADR][TYPE]" size="1">
<option value="work"><?php echo $l->t('Work'); ?></option>
<option value="home" selected="selected"><?php echo $l->t('Home'); ?></option>
<?php echo html_select_options($_['adr_types'], 'HOME') ?>
</select>
</li>
<li class="input stringish">

View File

@ -27,24 +27,21 @@
<input type="hidden" name="id" value="<?php echo $_['id']; ?>">
<p class="contacts_property_name">
<select name="name" size="1">
<option value="ADR"><?php echo $l->t('Address'); ?></option>
<option value="TEL"><?php echo $l->t('Telephone'); ?></option>
<option value="EMAIL" selected="selected"><?php echo $l->t('Email'); ?></option>
<option value="ORG"><?php echo $l->t('Organization'); ?></option>
<?php echo html_select_options($_['property_types'], 'EMAIL') ?>
</select>
<br>
<input id="contacts_addproperty_button" type="submit" value="<?php echo $l->t('Add'); ?>">
</p>
<p class="contacts_property_data" id="contacts_generic">
<input type="text" name="value" value="">
</p><br>
<input id="contacts_addproperty_button" type="submit" value="<?php echo $l->t('Add'); ?>">
</p>
</form>
<div id="contacts_addcontactsparts" style="display:none;">
<ul class="contacts_property_data" id="contacts_addresspart">
<li>
<label for="adr_type"><?php echo $l->t('Type'); ?></label>
<select id="adr_type" name="parameters[TYPE]" size="1">
<option value="work"><?php echo $l->t('Work'); ?></option>
<option value="home" selected="selected"><?php echo $l->t('Home'); ?></option>
<?php echo html_select_options($_['adr_types'], 'HOME') ?>
</select>
</li>
<li>
@ -78,15 +75,8 @@
</ul>
<p class="contacts_property_data" id="contacts_phonepart">
<input type="text" name="value" value="">
<select name="parameters[TYPE]" size="1">
<option value="home"><?php echo $l->t('Home'); ?></option>
<option value="cell" selected="selected"><?php echo $l->t('Mobile'); ?></option>
<option value="work"><?php echo $l->t('Work'); ?></option>
<option value="text"><?php echo $l->t('Text'); ?></option>
<option value="voice"><?php echo $l->t('Voice'); ?></option>
<option value="fax"><?php echo $l->t('Fax'); ?></option>
<option value="video"><?php echo $l->t('Video'); ?></option>
<option value="pager"><?php echo $l->t('Pager'); ?></option>
<select name="parameters[TYPE][]" multiple="multiple" data-placeholder="<?php echo $l->t('Type') ?>">
<?php echo html_select_options($_['phone_types'], 'CELL') ?>
</select>
</p>
<p class="contacts_property_data" id="contacts_generic">

View File

@ -23,8 +23,20 @@
<p class="contacts_property_name"><?php echo $l->t('Phone'); ?></p>
<p class="contacts_property_data">
<?php echo $_['property']['value']; ?>
<?php if(isset($_['property']['parameters']['TYPE'])): ?>
(<?php echo $l->t(ucwords(str_replace('cell','mobile',strtolower($_['property']['parameters']['TYPE'])))); ?>)
<?php if(isset($_['property']['parameters']['TYPE']) && !empty($_['property']['parameters']['TYPE'])): ?>
<?php
$types = array();
foreach($_['property']['parameters']['TYPE'] as $type):
if (isset($_['phone_types'][strtoupper($type)])){
$types[]=$_['phone_types'][strtoupper($type)];
}
else{
$types[]=$l->t(ucwords(strtolower($type)));
}
endforeach;
$label = join(' ', $types);
?>
(<?php echo $label; ?>)
<?php endif; ?>
<span style="display:none;" data-use="edit"><img class="svg action" src="<?php echo image_path('', 'actions/rename.svg'); ?>" /></span>
<span style="display:none;" data-use="delete"><img class="svg action" src="<?php echo image_path('', 'actions/delete.svg'); ?>" /></span>
@ -34,7 +46,16 @@
<?php echo $l->t('Address'); ?>
<?php if(isset($_['property']['parameters']['TYPE'])): ?>
<br>
(<?php echo $l->t(ucwords($_['property']['parameters']['TYPE'])); ?>)
<?php
$type = $_['property']['parameters']['TYPE'];
if (isset($_['adr_types'][strtoupper($type)])){
$label=$_['adr_types'][strtoupper($type)];
}
else{
$label=$l->t(ucwords(strtolower($type)));
}
?>
(<?php echo $label; ?>)
<?php endif; ?>
</p>
<p class="contacts_property_data">

View File

@ -1,10 +1,15 @@
<li class="contacts_property_edit" data-checksum="<?php echo $_['property']['checksum']; ?>">
<form id="contacts_setpropertyform">
<input type="hidden" name="checksum" value="<?php echo $_['property']['checksum']; ?>">
<input type="hidden" name="id" value="<?php echo $_['id']; ?>">
<?php if($_['property']['name']=='ADR'): ?>
<p class="contacts_property_name"><label for="adr_pobox"><?php echo $l->t('Address'); ?></label></p>
<ol class="contacts_property_data" id="contacts_addresspart">
<li class="input">
<label class="label" for="adr_type"><?php echo $l->t('Type'); ?></label>
<select id="adr_type" name="parameters[TYPE]" size="1">
<?php echo html_select_options($_['adr_types'], strtoupper($_['property']['parameters']['TYPE'])) ?>
</select>
</li>
<li>
<label for="adr_pobox"><?php echo $l->t('PO Box'); ?></label>
<input id="adr_pobox" type="text" name="value[0]" value="<?php echo $_['property']['value'][0] ?>">
@ -36,7 +41,10 @@
</ol>
<?php elseif($_['property']['name']=='TEL'): ?>
<p class="contacts_property_name"><label for="tel"><?php echo $l->t('Phone'); ?></label></p>
<p class="contacts_property_data"><input id="tel" type="phone" name="value" value="<?php echo $_['property']['value']; ?>"></p>
<p class="contacts_property_data"><input id="tel" type="phone" name="value" value="<?php echo $_['property']['value'] ?>">
<select id="tel_type<?php echo $_['property']['checksum'] ?>" name="parameters[TYPE][]" multiple="multiple" data-placeholder="<?php echo $l->t('Type') ?>">
<?php echo html_select_options($_['phone_types'], isset($_['property']['parameters']['TYPE'])?$_['property']['parameters']['TYPE']:'') ?>
</select></p>
<?php elseif($_['property']['name']=='EMAIL'): ?>
<p class="contacts_property_name"><label for="email"><?php echo $l->t('Email'); ?></label></p>
<p class="contacts_property_data"><input id="email" type="text" name="value" value="<?php echo $_['property']['value']; ?>"></p>
@ -44,6 +52,5 @@
<p class="contacts_property_name"><label for="org"><?php echo $l->t('Organization'); ?></label></p>
<p class="contacts_property_data"><input id="org" type="text" name="value" value="<?php echo $_['property']['value']; ?>"></p>
<?php endif; ?>
<input id="contacts_setproperty_button" type="submit" value="<?php echo $l->t('Edit'); ?>">
<input id="contacts_setproperty_button" type="submit" value="<?php echo $l->t('Update'); ?>">
</form>
</li>