Modificar user profile

cancel
Showing results for 
Search instead for 
Did you mean: 
fegor
Senior Member

Re: Modificar user profile

Hola,

La aplicación Alfresco Share está fuertemente basada en WebScripts mediante el Framework Surf y por tanto casi todas las "vistas" son mediante plantillas de Freemarker.

Por ejemplo, para hacer que salga la información del "profile" o perfil del usuario puedes modificar la plantilla que hay en {tomcat}/webapps/share/WEB-INF/classes/alfresco/site-webscripts/org/alfresco/components/profile/userprofile.get.html.ftl

Esta es una modificada para que visualice el Número de Seguridad Social que he extendido en el contentModel.xml de Alfresco.


<script type="text/javascript">//<![CDATA[
   var userProfile = new Alfresco.UserProfile("${args.htmlid}").setOptions(
   {
      userId: "${user.name}",
      profile: {
         isMutable: ${((profile.capabilities.isMutable)!false)?string},
         name: "<#if profile.name??>${profile.name?js_string}</#if>",
         lastName: "<#if profile.lastName??>${profile.lastName?js_string}</#if>",
         firstName: "<#if profile.firstName??>${profile.firstName?js_string}</#if>",
         jobtitle: "<#if profile.jobTitle??>${profile.jobTitle?js_string}</#if>",
         location: "<#if profile.location??>${profile.location?js_string}</#if>",
         bio: "<#if profile.biography??>${profile.biography?js_string}</#if>",
         telephone: "<#if profile.telephone??>${profile.telephone?js_string}</#if>",
         mobile: "<#if profile.mobilePhone??>${profile.mobilePhone?js_string}</#if>",
         email :"<#if profile.email??>${profile.email?js_string}</#if>",
         skype: "<#if profile.skype??>${profile.skype?js_string}</#if>",
         instantmsg: "<#if profile.instantMsg??>${profile.instantMsg?js_string}</#if>",
         organization: "<#if profile.organization??>${profile.organization?js_string}</#if>",
         companyaddress1: "<#if profile.companyAddress1??>${profile.companyAddress1?js_string}</#if>",
         companyaddress2: "<#if profile.companyAddress2??>${profile.companyAddress2?js_string}</#if>",
         companyaddress3:"<#if profile.companyAddress3??>${profile.companyAddress3?js_string}</#if>",
         companypostcode: "<#if profile.companyPostcode??>${profile.companyPostcode?js_string}</#if>",
         companytelephone: "<#if profile.companyTelephone??>${profile.companyTelephone?js_string}</#if>",
         companyfax: "<#if profile.companyFax??>${profile.companyFax?js_string}</#if>",
         companyemail: "<#if profile.companyEmail??>${profile.companyEmail?js_string}</#if>",
         numSS: "<#if profile.numSS??>${profile.numSS?js_string}</#if>"
      }
   }).setMessages(
      ${messages}
   );
//]]></script>

<#assign el=args.htmlid>
<#assign displayname=profile.firstName>
<#if profile.lastName??><#assign displayname=displayname + " " + profile.lastName></#if>
<div id="${el}-body" class="profile">
   <div id="${el}-readview" class="hidden">
      <#if profile.capabilities.isMutable>
      <div class="editcolumn">
         <div class="btn-edit"><button id="${el}-button-edit" name="edit">${msg("button.editprofile")}</button></div>
      </div>
      </#if>
      <div class="viewcolumn">
         <div class="header-bar">${msg("label.about")}</div>
         <div class="photorow">
            <div class="photo">
               <img class="photoimg" src="${url.context}<#if profile.properties.avatar??>/proxy/alfresco/api/node/${profile.properties.avatar?replace('://','/')}/content/thumbnails/avatar?c=force<#else>/components/images/no-user-photo-64.png</#if>" alt="" />
            </div>
            <div class="namelabel">${displayname?html}</div>
            <#if profile.jobTitle?? && profile.jobTitle?length!=0><div class="fieldlabel">${profile.jobTitle?html}</div></#if>
            <#if profile.organization?? && profile.organization?length!=0><div class="fieldlabel">${profile.organization?html}</div></#if>
            <#if profile.location?? && profile.location?length!=0><div class="fieldlabel">${profile.location?html}</div></#if>
         </div>
         <#if biohtml?? && biohtml?length!=0>
         <div class="biorow">
            <hr/>
            <div>${biohtml}</div>
         </div>
         </#if>
        
         <div class="header-bar">${msg("label.contactinfo")}</div>
         <#if profile.email?? && profile.email?length!=0>
         <div class="row">
            <span class="fieldlabelright">${msg("label.email")}:</span>
            <span class="fieldvalue">${profile.email?html}</span>
         </div>
         </#if>
         <#if profile.telephone?? && profile.telephone?length!=0>
         <div class="row">
            <span class="fieldlabelright">${msg("label.telephone")}:</span>
            <span class="fieldvalue">${profile.telephone?html}</span>
         </div>
         </#if>
         <#if profile.mobilePhone?? && profile.mobilePhone?length!=0>
         <div class="row">
            <span class="fieldlabelright">${msg("label.mobile")}:</span>
            <span class="fieldvalue">${profile.mobilePhone?html}</span>
         </div>
         </#if>
         <#if profile.skype?? && profile.skype?length!=0>
         <div class="row">
            <span class="fieldlabelright">${msg("label.skype")}:</span>
            <span class="fieldvalue">${profile.skype?html}</span>
         </div>
         </#if>
         <#if profile.instantMsg?? && profile.instantMsg?length!=0>
         <div class="row">
            <span class="fieldlabelright">${msg("label.im")}:</span>
            <span class="fieldvalue">${profile.instantMsg?html}</span>
         </div>
         </#if>
        
         <div class="header-bar">${msg("label.companyinfo")}</div>
         <#if profile.organization?? && profile.organization?length!=0>
         <div class="row">
            <span class="fieldlabelright">${msg("label.name")}:</span>
            <span class="fieldvalue">${profile.organization?html}</span>
         </div>
         </#if>
         <#if (profile.companyAddress1?? && profile.companyAddress1?length!=0) ||
              (profile.companyAddress2?? && profile.companyAddress2?length!=0) ||
              (profile.companyAddress3?? && profile.companyAddress3?length!=0) ||
              (profile.companyPostcode?? && profile.companyPostcode?length!=0)>
         <div class="row">
            <span class="fieldlabelright">${msg("label.address")}:</span>
            <span class="fieldvalue"><#if profile.companyAddress1?? && profile.companyAddress1?length!=0>${profile.companyAddress1?html}<br /></#if>
               <#if profile.companyAddress2?? && profile.companyAddress2?length!=0>${profile.companyAddress2?html}<br /></#if>
               <#if profile.companyAddress3?? && profile.companyAddress3?length!=0>${profile.companyAddress3?html}<br /></#if>
               <#if profile.companyPostcode?? && profile.companyPostcode?length!=0>${profile.companyPostcode?html}</#if>
            </span>
         </div>
         </#if>
         <!–
         <div class="row">
            <span class="fieldlabelright">${msg("label.map")}:</span>
            <span class="fieldvalue"></span>
         </div>
         –>
         <#if profile.companyTelephone?? && profile.companyTelephone?length!=0>
         <div class="row">
            <span class="fieldlabelright">${msg("label.telephone")}:</span>
            <span class="fieldvalue">${profile.companyTelephone?html}</span>
         </div>
         </#if>
         <#if profile.companyFax?? && profile.companyFax?length!=0>
         <div class="row">
            <span class="fieldlabelright">${msg("label.fax")}:</span>
            <span class="fieldvalue">${profile.companyFax?html}</span>
         </div>
         </#if>
         <#if profile.companyEmail?? && profile.companyEmail?length!=0>
         <div class="row">
            <span class="fieldlabelright">${msg("label.email")}:</span>
            <span class="fieldvalue">${profile.companyEmail?html}</span>
         </div>
         </#if>
         <#if profile.numSS?? && profile.numSS?length!=0>
         <div class="row">
            <span class="fieldlabelright">${msg("label.numSS")}:</span>
            <span class="fieldvalue">${profile.numSS?html}</span>
         </div>
         </#if>
      </div>
   </div>
  
   <#if profile.capabilities.isMutable>
   <div id="${el}-editview" class="hidden">
      <form id="${htmlid}-form" action="${url.context}/service/components/profile/userprofile" method="post">
     
      <div class="header-bar">${msg("label.about")}</div>
      <div class="drow">
         <div class="reqcolumn"> *</div>
         <div class="rightcolumn">
            <span class="label"><label for="${el}-input-lastName">${msg("label.lastname")}:</label></span>
            <span class="input"><input type="text" maxlength="256" size="30" id="${el}-input-lastName" value="" /></span>
         </div>
         <div class="leftcolumn">
            <span class="label"><label for="${el}-input-firstName">${msg("label.firstname")}:</label></span>
            <span class="input"><input type="text" maxlength="256" size="30" id="${el}-input-firstName" value="" /> *</span>
         </div>
      </div>
      <div class="drow">
         <div class="reqcolumn"> </div>        
         <div class="leftcolumn">
            <span class="label"><label for="${el}-input-jobtitle">${msg("label.jobtitle")}:</label></span>
            <span class="input"><input type="text" maxlength="256" size="30" id="${el}-input-jobtitle" value="" /></span>
         </div>
         <div class="rightcolumn">
            <span class="label"><label for="${el}-input-location">${msg("label.location")}:</label></span>
            <span class="input"><input type="text" maxlength="256" size="30" id="${el}-input-location" value="" /></span>
         </div>
      </div>
      <!–
      <div class="drow">
         <div class="leftcolumn">
            <span class="label">${msg("label.timezone")}:</span>
            <span class="input"><input type="text" maxlength="256" size="30" id="${el}-input-timezone" /></span>
         </div>
         <div class="rightcolumn">
         </div>
      </div>
      –>
      <div class="row">
         <span class="label"><label for="${el}-input-bio">${msg("label.bio")}:</label></span>
         <span class="input"><textarea id="${el}-input-bio" name="${el}-text-biography" rows="5" cols="60"></textarea></span>
      </div>
     
      <div class="header-bar">${msg("label.photo")}</div>
      <div class="photorow">
         <div class="photo">
            <img class="photoimg" src="${url.context}<#if profile.properties.avatar??>/proxy/alfresco/api/node/${profile.properties.avatar?replace('://','/')}/content/thumbnails/avatar?c=force<#else>/components/images/no-user-photo-64.png</#if>" alt="" />
         </div>
         <div class="photobtn">
            <button id="${el}-button-upload" name="upload">${msg("button.upload")}</button>
            <div class="phototxt">${msg("label.photoimagesize")}</div>
            <div class="phototxt">${msg("label.photonote")}</div>
         </div>
      </div>
     
      <div class="header-bar">${msg("label.contactinfo")}</div>
      <div class="row">
         <span class="label"><label for="${el}-input-telephone">${msg("label.telephone")}:</label></span>
         <span class="input"><input type="text" maxlength="256" size="30" id="${el}-input-telephone" value="" /></span>
      </div>
      <div class="row">
         <span class="label"><label for="${el}-input-mobile">${msg("label.mobile")}:</label></span>
         <span class="input"><input type="text" maxlength="256" size="30" id="${el}-input-mobile" value="" /></span>
      </div>
      <div class="row">
         <span class="label"><label for="${el}-input-email">${msg("label.email")}:</label></span>
         <span class="input"><input type="text" maxlength="256" size="30" id="${el}-input-email" value="" /></span>
      </div>
      <div class="row">
         <span class="label"><label for="${el}-input-skype">${msg("label.skype")}:</label></span>
         <span class="input"><input type="text" maxlength="256" size="30" id="${el}-input-skype" value="" /></span>
      </div>
      <div class="row">
         <span class="label"><label for="${el}-input-instantmsg">${msg("label.im")}:</label></span>
         <span class="input"><input type="text" maxlength="256" size="30" id="${el}-input-instantmsg" value="" /></span>
      </div>
     
      <div class="header-bar">${msg("label.companyinfo")}</div>
      <div class="row">
         <span class="label"><label for="${el}-input-organization">${msg("label.name")}:</label></span>
         <span class="input"><input type="text" maxlength="256" size="30" id="${el}-input-organization" value="" /></span>
      </div>
      <div class="row">
         <span class="label"><label for="${el}-input-companyaddress1">${msg("label.address")}:</label></span>
         <span class="input"><input type="text" maxlength="256" size="30" id="${el}-input-companyaddress1" value="" /></span>
      </div>
      <div class="row">
         <span class="label"></span>
         <span class="input"><input type="text" maxlength="256" size="30" id="${el}-input-companyaddress2" value="" /></span>
      </div>
      <div class="row">
         <span class="label"></span>
         <span class="input"><input type="text" maxlength="256" size="30" id="${el}-input-companyaddress3" value="" /></span>
      </div>
      <div class="row">
         <span class="label"><label for="${el}-input-companypostcode">${msg("label.postcode")}:</label></span>
         <span class="input"><input type="text" maxlength="256" size="30" id="${el}-input-companypostcode" value="" /></span>
      </div>
      <!–
      <div class="row">
         <span class="label">${msg("label.map")}:</span>
         <span class="check"><input type="checkbox" id="${el}-input-showmap" /> ${msg("label.showmap")}</span>
      </div>
      –>
      <div class="row">
         <span class="label"><label for="${el}-input-companytelephone">${msg("label.telephone")}:</label></span>
         <span class="input"><input type="text" maxlength="256" size="30" id="${el}-input-companytelephone" value="" /></span>
      </div>
      <div class="row">
         <span class="label"><label for="${el}-input-companyfax">${msg("label.fax")}:</label></span>
         <span class="input"><input type="text" maxlength="256" size="30" id="${el}-input-companyfax" value="" /></span>
      </div>
      <div class="row">
         <span class="label"><label for="${el}-input-companyemail">${msg("label.email")}:</label></span>
         <span class="input"><input type="text" maxlength="256" size="30" id="${el}-input-companyemail" value="" /></span>
      </div>
      <div class="row">
         <span class="label"><label for="${el}-input-numSS">${msg("label.numSS")}:</label></span>
         <span class="input"><input type="text" maxlength="256" size="30" id="${el}-input-numSS" value="" /></span>
      </div>
     
      <hr/>
     
      <div class="buttons">
         <button id="${el}-button-save" name="save">${msg("button.savechanges")}</button>
         <button id="${el}-button-cancel" name="cancel">${msg("button.cancel")}</button>
      </div>
     
      </form>
   </div>
   </#if>

</div>

Solo tienes que buscar "numSS" para ver como he ido poniendo el código.

Un saludo.
ruben_arjonilla
Member II

Re: Modificar user profile

muchas gracias de nuevo,
solo unas dudillas:

1 - yo haciendo exactamente lo que tu, cambiando numSS por las mias, no me salen los valores de dichos campos, entiendo que la primera parte (la del script), asignamos las variables a userProfile o algo así, y luego, en la parte de las divs, mostramos los valores, pero, antes no hay que tocar algo para que realmente cargue mis propiedades en la variable "profile"? algun webscript (probablemente al hacer login), la parte de js o algo? quien le dice que cargue esos valores en la variable "profile"?

2 - y otra duda, he visto que tambien tienes un input para el numSS, hay que modificar el webscript  "userprofile.post"? porque a mi el input (al igual que en la vista de detalle), me sale vacio, sin contenido, y al guardar no guarda nada, continua saliendo en blanco (y desde el webclient continua teniendo el valor que tenia al principio)
ruben_arjonilla
Member II

Re: Modificar user profile

He probado a hacer una cosa (tengo Alfresco montado con eclipse):

He buscado la palabra "skype" en todo el proyecto de alfresco (esta sale en el profile de share por defecto, por tanto, si creo que si pongo mis variables donde sale esta, es posible que me funcione), y alli donde ha ido aparenciendo, le he ido añadiendo mis propiedades.

Estos son los ficheros que he modificado:
  • remote-api/config/alfresco/templates/webscripts/org/alfresco/repository/person/person.lib.ftl
  • repository/config/alfresco/model/contentModel.xml
  • repository/source/java/org/alfresco/model/ContentModel.java
  • slingshot/config/alfresco/messages/slingshot.properties
  • slingshot/config/alfresco/site-webscripts/org/alfresco/components/console/users.get.html.ftl
  • slingshot/config/alfresco/site-webscripts/org/alfresco/components/dashlets/my-profile.get.html.ftl
  • slingshot/config/alfresco/site-webscripts/org/alfresco/components/dashlets/my-profile.get.properties
  • slingshot/config/alfresco/site-webscripts/org/alfresco/components/profile/userprofile.get.html.ftl
  • slingshot/source/java/org/alfresco/web/site/SlingshotUserFactory.java
  • slingshot/source/web/components/console/users.js
  • slingshot/source/web/components/profile/profile.js

  • He compilado de nuevo alfresco y lo he ejecutado.

    Mi resultado es el siguiente:
    Me continua sin salir las propiedades propias (la variable profile no tiene valor para mis propiedades, por tanto no sale nada), al ir al perfil de usuario y modificar, los input me salen vacios (entiendo que el problema es el mismo que debo tener con la vista detalle), pero si pongo valores en estos campos y guardo, estos si que son guardados en el perfil del usuario (desde el webclient de alfresco si que puedo ver que me ha guardado los nuevos datos).

    o sea que ahora el único problema que tengo es que desde share no consigo que me muestre mis propiedades.
    alguna idea de que me he dejado o que puedo haber echo mal?
    fegor
    Senior Member

    Re: Modificar user profile

    Si user es un objeto que devuelve una lista (colección) de propiedades fija parece ser… :/
    ruben_arjonilla
    Member II

    Re: Modificar user profile

    bueno, lo he medio "arreglado".

    Quizas no es la manera mas correcta de hacerlo, pero funciona.
    en el fichero "userprofile.get.js", que es el que recoge los datos del perfil, al final le he añadido las siguientes lineas:

    var jsonStr = remote.call('/api/login.json?u=user&pw=password'); //usuario y password del administrador
    var json = eval('(' + jsonStr + ')');
    var data = json['data'];

    var connector = remote.connect('alfresco');
    var result = connector.get('/api/people/'+user.id+'?alf_ticket='+data.ticket);
    model.person = eval('(' + result + ')');

    lo que hago es volver a recoger los datos mediante la api de Alfresco (es lo que no me gusta, que parece que este cargando los datos 2 veces…), y luego en el fichero que muestra la vista detalle y la de entrada de datos, en vez de irme a buscar las variables de share, uso las que he recogido yo.
    fegor
    Senior Member

    Re: Modificar user profile

    Pues como tú mismo dices, no es la mejor solución, pero si funciona ;-)

    Quizás lo mejor sería reemplazar getUser() del objeto user para que devuelve todas las propiedades de "cmSmiley Tongueerson".

    Un saludo.