<%namespace name="Modals" file="jm2l:templates/modals.mako"/>
<%namespace name="helpers" file="jm2l:templates/helpers.mako"/>
<%def name="profil_wrapper(uprofil, profil_form)">
    <div class="profile-icon" style="float:right;height:250px;width:250px;">
        <% photos = uprofil.PhotosLinks %>
        <div id="MyPictureCarousel" class="carousel slide">
            <div style="text-align: center;line-height:20px;">
                <a data-target="#AjaxModal" Myhref="/2015/modal/Password/1" role="button" handle="modal">Changer mon mot de passe</a>
            </div>
            % if len(photos)>1:
            <!-- Carousel nav -->
            <a class="Ucarousel-control left" href="#MyPictureCarousel" data-slide="prev">&lsaquo;</a>
            <a class="Ucarousel-control right" href="#MyPictureCarousel" data-slide="next">&rsaquo;</a>
            % endif
            <div style="text-align: center;line-height:20px;">
                <a data-target="#AjaxModal" Myhref="/2015/modal/UserPicture/${uprofil.uid}" handle="modal">Changer ma photo</a>
            </div>
            <!-- Carousel items -->
            <div class="carousel-inner" style="height: 220px;">
            % if len(photos):
                % for num, link in enumerate(photos):
                <div class="${['','active '][num==0]}item" id="UserPic${num}">
                    <div style="margin:auto;">
                        <img src="${link}" class="img-polaroid" style="max-height:205px;max-width:235px;" alt="Photo ${uprofil.slug}" />
                    </div>
                </div>
                % endfor
            % else:
                <div class="active item" id="UserPic0">
                    <div style="margin:auto;width:170px;">
                        <img src="/img/default-user.png" class="img-polaroid" alt="Photo ${uprofil.slug}" style="max-height:205px;"  />
                    </div>
                </div>
            % endif
            </div>
        </div>
    </div>
<a href="/sign/jm2l/${uprofil.my_hash}">Mon lien</a>    
    <h3>${profil_form.prenom.data} ${profil_form.nom.data}</h3>

##<form id="ProfilForm" action="javascript:DoPost('/2015/modal/Place/${form.place_id.data}');">
% if uprofil!=request.user and request.user.uid==1:
    <form id="ProfilForm" action="/MesJM2L?user=${uprofil.uid}" method="POST">
% else:
    <form id="ProfilForm" action="/MesJM2L" method="POST">
% endif

<%
DicForm = {
    'nom':     {'PlaceHolder':u"Mon Nom",               "FieldStyle":"width:16em;", 'ContainerStyle':"float:left;"},
    'prenom':  {'PlaceHolder':u"Mon Prénom",            "FieldStyle":"width:16em;"},
    'pseudo':  {'PlaceHolder':u"Mon Pseudo",            "FieldStyle":"width:16em;", 'ContainerStyle':"float:left;"},
    'mail':    {'PlaceHolder':u"mon.mail@fqdn.tld",     "FieldStyle":"width:16em;"},
    'phone':   {'PlaceHolder':u"0612345678",            "FieldStyle":"width:16em;", 'ContainerStyle':"float:left;"},
    'website': {'PlaceHolder':u"http://ma-page-web.moi","FieldStyle":"width:16em;"},    
    'gpg_key': {'PlaceHolder':u"Ma clé gpg",            "FieldStyle":"width:90%;"},
    'soc_link':{'PlaceHolder':u"#jm2l sur irc.freenode.org","FieldStyle":"width:90%;"},    
    'bio':     {'PlaceHolder':u"Ma Bilibiographie",     "FieldStyle":"width:95%;min-height:150px;", "fieldset":True },
    'tiersship':  {'Ignore':True}    
    }
%>
    ${helpers.DisplayForm(profil_form, DicForm)}

<fieldset>
    <legend>Activité</legend>
    <div class="repeat">
        <table class="wrapper table table-striped table-bordered" width="100%">
            <thead>
              <tr class="row">
                ##<th></th>
                <th style="width:4em;text-align:center;">Année</th>
                <th style="width:19em;">Entitée</th>
                <th>Rôle</th>
                <th style="width:6em;">Action</th>            
              </tr>            
            </thead>
            <tbody class="container">
            <tr class="row template" style="line-height:2.2em;">
                ##<td><span class="move btn btn-mini btn-info">Move</span></td>
                <td style="text-align:center;">
                    <input type="hidden" style="width:20em;" class="form-control" name="tiersship-{{row-count-placeholder}}-year_uid" 
                        value="2015" /> 2015
                </td>
                <td style="text-align: center;">
                    <input type="hidden" class="form-control" name="tiersship-{{row-count-placeholder}}-user_uid" 
                        value="${uprofil.uid}" style="width:4em;" />                
                    <input type="hidden" class="form-control" style="width:20em;" name="tiersship-{{row-count-placeholder}}-tiers_uid"
                        id="tiersship-{{row-count-placeholder}}-tiers_uid" />
                </td>
                <td style="text-align:center;">
                    <input style="width:100%;margin:-7px;" type="text" class="form-control" name="tiersship-{{row-count-placeholder}}-role" 
                        value="" />
                </td>                
                <td>
                    <span class="remove btn btn-mini btn-danger">
                        <i class="icon-remove-sign icon-white"></i> Suppr.
                    </span>
                </td>            
            </tr>
            % for num, dicdata in enumerate(profil_form._fields.get("tiersship").data):
            <tr class="row" style="padding:5px;line-height:2.2em;">
                ##<td><span class="move btn btn-mini btn-info">Move</span></td>
                <td style="text-align:center;">
                    <input type="hidden" class="form-control" name="tiersship-${num}-year_uid" 
                        value="${dicdata.get('year_uid')}" style="width:4em;" />
                    ${dicdata.get('year_uid')}
                </td>
                <td style="text-align:center;">
                    <input type="hidden" class="form-control" name="tiersship-${num}-user_uid" 
                        value="${dicdata.get('user_uid')}" style="width:4em;" />
                    <input type="hidden" class="form-control" name="tiersship-${num}-tiers_uid" 
                        value="${dicdata.get('tiers_uid')}" style="width:4em;" />
                    <% 
                    entity = DBTiers.by_id(dicdata.get('tiers_uid'))
                    %>
                    % if entity:
                    <small>${entity.get_entity_type.entity_subtype}</small>
                    <a href="/entity/${entity.get_entity_type.entity_type}/${entity.slug}">${entity.name}</a>
                    % endif
                </td>
                <td style="text-align:center;">
                    <input style="width:100%;margin:-7px;" type="text" class="form-control" name="tiersship-${num}-role" 
                        value="${dicdata.get('role')}" />
                </td>
                <td>
                    <span class="remove btn btn-mini btn-danger">
                        <i class="icon-remove-sign icon-white"></i> Suppr.
                    </span>
                </td>
            </tr>
            % endfor
            </tbody>
            <tfoot>
              <tr>
                <td colspan="5" style="text-align:center;line-height: 3em;">
                    <span class="add btn btn-mini btn-primary"><i class="icon-plus-sign icon-white"></i> Ajouter</span>
                </td>
              </tr>            
            </tfoot>
        </table>
    </div>
    </fieldset>


    <input type="submit" value="Enregistrer !" />
    
    </form>



## Handle Popover of this form
##<script type="text/javascript">
##  % for field in profil_form._fields.keys():
##   $('#${field}-help').popover();
##  %endfor
##</script>
</%def>
