Can add/remove/edit addresses
[platal.git] / templates / profile / adresses.tpl
1 {**************************************************************************}
2 {*                                                                        *}
3 {*  Copyright (C) 2003-2007 Polytechnique.org                             *}
4 {*  http://opensource.polytechnique.org/                                  *}
5 {*                                                                        *}
6 {*  This program is free software; you can redistribute it and/or modify  *}
7 {*  it under the terms of the GNU General Public License as published by  *}
8 {*  the Free Software Foundation; either version 2 of the License, or     *}
9 {*  (at your option) any later version.                                   *}
10 {*                                                                        *}
11 {*  This program is distributed in the hope that it will be useful,       *}
12 {*  but WITHOUT ANY WARRANTY; without even the implied warranty of        *}
13 {*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *}
14 {*  GNU General Public License for more details.                          *}
15 {*                                                                        *}
16 {*  You should have received a copy of the GNU General Public License     *}
17 {*  along with this program; if not, write to the Free Software           *}
18 {*  Foundation, Inc.,                                                     *}
19 {*  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA               *}
20 {*                                                                        *}
21 {**************************************************************************}
22
23 <script type="text/javascript">//<![CDATA[
24 {literal}
25 function removeObject(id, pref)
26 {
27   document.getElementById(id).style.display = "none";
28   document.forms.prof_annu[pref + "[removed]"].value = "1";
29 }
30
31 function getAddressElement(adrid, adelement)
32 {
33   return document.forms.prof_annu["addresses[" + adrid + "][" + adelement + "]"];
34 }
35
36 function checkCurrentAddress(newCurrent)
37 {
38   var hasCurrent = false;
39   var i = 0;
40   while (getAddressElement(i, 'pub') != null) {
41     var radio = getAddressElement(i, 'current');
42     var removed = getAddressElement(i, 'removed');
43     if (removed.value == "1" && radio.checked) {
44       radio.checked = false;
45     } else if (radio.checked && radio != newCurrent) {
46       radio.checked = false;
47     } else if (radio.checked) {
48       hasCurrent = true;
49     }
50     i++;
51   }
52   if (!hasCurrent) {
53     i = 0;
54     while (getAddressElement(i, 'pub') != null) {
55       var radio = getAddressElement(i, 'current');
56       var removed = getAddressElement(i, 'removed');
57       if (removed.value != "1") {
58         radio.checked= true;
59         return;
60       }
61       i++;
62     }
63   }
64 }
65
66 function removeAddress(id, pref)
67 {
68   removeObject(id, pref);
69   checkCurrentAddress(null);
70 }
71
72 function addAddress()
73 {
74   var i = 0;
75   while (getAddressElement(i, 'pub') != null) {
76     i++;
77   }
78   $("#add_adr").before('<div id="addresses_' + i + '"></div>');
79   Ajax.update_html('addresses_' + i, 'profile/ajax/address/' + i, checkCurrentAddress);
80 }
81
82 function addTel(id)
83 {
84   var i = 0;
85   var adid = 'addresses_' + id;
86   var tel  = adid + '_tel_';
87   while (document.getElementById(tel + i) != null) {
88     i++;
89   }
90   $('#' + adid + '_add_tel').before('<div id="' + tel + i + '" style="clear: both"></div>');
91   Ajax.update_html(tel + i, 'profile/ajax/tel/' + id + '/' + i);
92 }
93
94 {/literal}
95 //]]></script>
96
97 {foreach key=i item=adr from=$addresses}
98 <div id="{"addresses_$i"}">
99 {include file="profile/adresses.address.tpl" i=$i adr=$adr}
100 </div>
101 {/foreach}
102 {if $addresses|@count eq 0}
103 <div id="addresses_0">
104 {include file="profile/adresses.address.tpl" i=0 adr=0}
105 </div>
106 {/if}
107
108 <div id="add_adr" class="center">
109   <a href="javascript:addAddress()">
110     {icon name=add title="Ajouter une adresse"} Ajouter une adresse
111   </a>
112 </div>
113
114 {* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}