diff options
author | Bart Visscher <bartv@thisnet.nl> | 2011-11-05 20:33:42 +0100 |
---|---|---|
committer | Bart Visscher <bartv@thisnet.nl> | 2011-11-09 22:19:52 +0100 |
commit | ef124c3e21ceae49f0f704589a833d1208d99c65 (patch) | |
tree | 896f352cd5abd17fee6c300f4c389883ebd3320a | |
parent | 938c5ef21ce2870befcc16335998d48ad773433a (diff) | |
download | nextcloud-server-ef124c3e21ceae49f0f704589a833d1208d99c65.tar.gz nextcloud-server-ef124c3e21ceae49f0f704589a833d1208d99c65.zip |
Use a function to generate select options
-rw-r--r-- | apps/calendar/templates/part.eventform.php | 12 | ||||
-rw-r--r-- | apps/contacts/ajax/getdetails.php | 12 | ||||
-rw-r--r-- | apps/contacts/ajax/showaddcard.php | 5 | ||||
-rw-r--r-- | apps/contacts/ajax/showsetproperty.php | 2 | ||||
-rw-r--r-- | apps/contacts/lib/vcard.php | 20 | ||||
-rw-r--r-- | apps/contacts/templates/part.addcardform.php | 16 | ||||
-rw-r--r-- | apps/contacts/templates/part.details.php | 17 | ||||
-rw-r--r-- | apps/contacts/templates/part.setpropertyform.php | 6 | ||||
-rw-r--r-- | lib/template.php | 27 |
9 files changed, 81 insertions, 36 deletions
diff --git a/apps/calendar/templates/part.eventform.php b/apps/calendar/templates/part.eventform.php index 8588b9168f7..dfa5fb8c78a 100644 --- a/apps/calendar/templates/part.eventform.php +++ b/apps/calendar/templates/part.eventform.php @@ -13,9 +13,7 @@ <select id="category" name="categories[]" multiple="multiple" title="<?php echo $l->t("Select category") ?>"> <?php if (!isset($_['categories'])) {$_['categories'] = array();} - foreach($_['category_options'] as $category){ - echo '<option value="' . $category . '"' . (in_array($category, $_['categories']) ? ' selected="selected"' : '') . '>' . $category . '</option>'; - } + echo html_select_options($_['category_options'], $_['categories'], array('combine'=>true)); ?> </select></td> <th width="75px"> <?php echo $l->t("Calendar");?>:</th> @@ -23,9 +21,7 @@ <select style="width:140px;" name="calendar"> <?php if (!isset($_['calendar'])) {$_['calendar'] = false;} - foreach($_['calendar_options'] as $calendar){ - echo '<option value="' . $calendar['id'] . '"' . ($_['calendar'] == $calendar['id'] ? ' selected="selected"' : '') . '>' . $calendar['displayname'] . '</option>'; - } + echo html_select_options($_['calendar_options'], $_['calendar'], array('value'=>'id', 'label'=>'displayname')); ?> </select></td> </tr> @@ -66,9 +62,7 @@ <select name="repeat" style="width:350px;"> <?php if (isset($_['repeat_options'])) { - foreach($_['repeat_options'] as $id => $label){ - echo '<option value="' . $id . '"' . ($_['repeat'] == $id ? ' selected="selected"' : '') . '>' . $label . '</option>'; - } + echo html_select_options($_['repeat_options'], $_['repeat']); } ?> </select></td> diff --git a/apps/contacts/ajax/getdetails.php b/apps/contacts/ajax/getdetails.php index 0e76de61afb..260fb53a686 100644 --- a/apps/contacts/ajax/getdetails.php +++ b/apps/contacts/ajax/getdetails.php @@ -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 ))); diff --git a/apps/contacts/ajax/showaddcard.php b/apps/contacts/ajax/showaddcard.php index 2f534f0fe2d..98367758fd4 100644 --- a/apps/contacts/ajax/showaddcard.php +++ b/apps/contacts/ajax/showaddcard.php @@ -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 ))); diff --git a/apps/contacts/ajax/showsetproperty.php b/apps/contacts/ajax/showsetproperty.php index 6188f4773c3..4ec3dd7d8e1 100644 --- a/apps/contacts/ajax/showsetproperty.php +++ b/apps/contacts/ajax/showsetproperty.php @@ -61,11 +61,13 @@ if(is_null($line)){ exit(); } +$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR'); $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); $page = $tmpl->fetchPage(); OC_JSON::success(array('data' => array( 'page' => $page ))); diff --git a/apps/contacts/lib/vcard.php b/apps/contacts/lib/vcard.php index a6795c7935b..56602f25c0a 100644 --- a/apps/contacts/lib/vcard.php +++ b/apps/contacts/lib/vcard.php @@ -372,4 +372,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'), + ); + } + } } diff --git a/apps/contacts/templates/part.addcardform.php b/apps/contacts/templates/part.addcardform.php index a596ad8163a..037e3629bb9 100644 --- a/apps/contacts/templates/part.addcardform.php +++ b/apps/contacts/templates/part.addcardform.php @@ -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> @@ -46,14 +44,7 @@ <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> + <?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"> diff --git a/apps/contacts/templates/part.details.php b/apps/contacts/templates/part.details.php index 212be283d80..f5bd75809b1 100644 --- a/apps/contacts/templates/part.details.php +++ b/apps/contacts/templates/part.details.php @@ -27,10 +27,7 @@ <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> </p> <p class="contacts_property_data" id="contacts_generic"> @@ -44,8 +41,7 @@ <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> @@ -80,14 +76,7 @@ <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> + <?php echo html_select_options($_['phone_types'], 'CELL') ?> </select> </p> <p class="contacts_property_data" id="contacts_generic"> diff --git a/apps/contacts/templates/part.setpropertyform.php b/apps/contacts/templates/part.setpropertyform.php index eb8a67a8aa5..811b9626ce4 100644 --- a/apps/contacts/templates/part.setpropertyform.php +++ b/apps/contacts/templates/part.setpropertyform.php @@ -5,6 +5,12 @@ <?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] ?>"> diff --git a/lib/template.php b/lib/template.php index 440b62003e7..d1439199e1e 100644 --- a/lib/template.php +++ b/lib/template.php @@ -98,6 +98,33 @@ function relative_modified_date($timestamp) { else { return $l->t('years ago'); } } +function html_select_options($options, $selected, $params=array()) { + if (!is_array($selected)){ + $selected=array($selected); + } + if (isset($params['combine']) && $params['combine']){ + $options = array_combine($options, $options); + } + $value_name = $label_name = false; + if (isset($params['value'])){ + $value_name = $params['value']; + } + if (isset($params['label'])){ + $label_name = $params['label']; + } + $html = ''; + foreach($options as $value => $label){ + if ($value_name && is_array($label)){ + $value = $label[$value_name]; + } + if ($label_name && is_array($label)){ + $label = $label[$label_name]; + } + $select = in_array($value, $selected) ? ' selected="selected"' : ''; + $html .= '<option value="' . $value . '"' . $select . '>' . $label . '</option>'; + } + return $html; +} /** * This class provides the templates for owncloud. |