Xslt, JavaScript y WebService en Sharepoint – Demo 3

 No solo de WebParts vive el hombre – Parte 1 – Demostración 3

En el día de ayer, 06-12-2007 tuvimos la oportunidad de realizar un WebCast a la comunidad de desarrolladores de Sharepoint y le damos las gracias a Brandon Aday de Microsoft por la oportunidad que nos brindo.

En este WebCast presentamos una forma alternativa de realizar componentes para Sharepoint sin utilizar código de servidor.

Acá les dejamos parte del código fuente de la primera presentación realizada, los archivos JavaScript y el formulario ASPX utilizado

Código Fuente – Formulario aspx

 

<asp:Content id="Content1" runat="Server" contentplaceholderid="PlaceHolderMain">

<WebPartPages:DataFormWebPart runat="server" IsIncluded="True" FrameType="None" NoDefaultStyle=’TRUE’ ViewFlag=’0′ Title=’Documentos’ __markuptype=’vsattributemarkup’ __WebPartId='{DA04C944-BB6F-4DE1-B39A-7C1D47C2DD20}’ id=’g_5d5344cf_89e6_45b9_b8be_3698bebad8f6′>

<DataSources>

<SharePoint:SPDataSource runat="server" DataSourceMode="List" UseInternalName="true" selectcommand="&lt;View&gt;&lt;/View&gt;" id="Documentos1"><UpdateParameters><WebPartPages:dataformparameter PropertyName="ParameterValues" ParameterKey="ListID" DefaultValue="{2256D73A-FF33-4F07-A8E4-EBC8B69C47D9}" Name="ListID">

</WebPartPages:dataformparameter>

</UpdateParameters><DeleteParameters><WebPartPages:dataformparameter PropertyName="ParameterValues" ParameterKey="ListID" DefaultValue="{2256D73A-FF33-4F07-A8E4-EBC8B69C47D9}" Name="ListID">

</WebPartPages:dataformparameter>

</DeleteParameters><InsertParameters><WebPartPages:dataformparameter PropertyName="ParameterValues" ParameterKey="ListItemId" DefaultValue="0" Name="ListItemId">

</WebPartPages:dataformparameter><WebPartPages:dataformparameter PropertyName="ParameterValues" ParameterKey="ListID" DefaultValue="{2256D73A-FF33-4F07-A8E4-EBC8B69C47D9}" Name="ListID">

</WebPartPages:dataformparameter>

</InsertParameters><SelectParameters><WebPartPages:dataformparameter PropertyName="ParameterValues" ParameterKey="ListID" DefaultValue="{2256D73A-FF33-4F07-A8E4-EBC8B69C47D9}" Name="ListID">

</WebPartPages:dataformparameter>

</SelectParameters>

</SharePoint:SPDataSource>

</DataSources>

<ParameterBindings>

<ParameterBinding Name="dvt_apos" Location="Postback;Connection"/>

<ParameterBinding Name="UserID" Location="CAMLVariable" DefaultValue="CurrentUserName"/>

<ParameterBinding Name="Today" Location="CAMLVariable" DefaultValue="CurrentDate"/>

<ParameterBinding Name="ListID" Location="None" DefaultValue="{2256D73A-FF33-4F07-A8E4-EBC8B69C47D9}"/>

</ParameterBindings>

<datafields>@FileLeafRef,Nombre (para uso en formularios);@Title,Título;@_DCDateCreated,Fecha de creación;@ID,ID;@ContentType,Tipo de contenido;@Created,Creado;@Author,Creado por;@Modified,Modificado;@Editor,Modificado por;@_CopySource,Copiar origen;@CheckoutUser,Desprotegido para;@_CheckinComment,Comentario de protección;@CheckedOutTitle,Desprotegido para;@CheckedOutUserId,Id. del usuario que tiene desprotegido el elemento;@FileDirRef,Ruta;@FSObjType,Tipo de elemento;@HTML_x0020_File_x0020_Type,Tipo de archivo HTML;@File_x0020_Type,Tipo de archivo;@IsCheckedoutToLocal,Está desprotegido en local;@_SourceUrl,Dirección URL de origen;@_HasCopyDestinations,Tiene destinos de copia;@ContentTypeId,Id. de tipos de contenido;@_ModerationStatus,Estado de aprobación;@_UIVersion,Versión de IU;@Created_x0020_Date,Creado;@FileRef,Dirección URL;@File_x0020_Size,Tamaño de archivo;@_UIVersionString,Versión;@ParentVersionString,Versión del origen (documento convertido);@ParentLeafName,Nombre del origen (documento convertido);@TemplateUrl,Vinculo de la plantilla;</datafields>

<XSL>

<xsl:stylesheet

xmlns:x="http://www.w3.org/2001/XMLSchema"

xmlns:d="http://schemas.microsoft.com/sharepoint/dsp"

version="1.0"

exclude-result-prefixes="dt s z rs xsl msxsl ddwrt"

xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"

xmlns:asp="http://schemas.microsoft.com/ASPNET/20"

xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer"

xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

xmlns:msxsl="urn:schemas-microsoft-com:xslt"

xmlns:SharePoint="Microsoft.SharePoint.WebControls"

xmlns:ddwrt2="urn:frontpage:internal"

xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882"

xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"

xmlns:rs="urn:schemas-microsoft-com:rowset"

xmlns:z="#RowsetSchema">

<xsl:output method="html" indent="no"/>

<xsl:decimal-format NaN=""/>

<xsl:param name="dvt_apos">'</xsl:param>

<xsl:param name="ListID">{2256D73A-FF33-4F07-A8E4-EBC8B69C47D9}</xsl:param>

<xsl:variable name="dvt_1_automode">0</xsl:variable>

<xsl:variable name="CountRow" select="count(//Row)" ></xsl:variable>

<xsl:variable name="listName" select="self::text"></xsl:variable>

<xsl:template match="/" xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:SharePoint="Microsoft.SharePoint.WebControls">

<xsl:call-template name="dvt_1"/>

</xsl:template>

<xsl:template name="dvt_1">

<xsl:variable name="dvt_StyleName">Table</xsl:variable>

<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row"/>

<xsl:variable name="dvt_RowCount" select="count($Rows)" />

<xsl:variable name="dvt_IsEmpty" select="$dvt_RowCount = 0" />

<xsl:choose>

<xsl:when test="$dvt_IsEmpty">

<xsl:call-template name="dvt_1.empty" />

</xsl:when>

<xsl:otherwise>

<xsl:call-template name="dvt_1.header">

<xsl:with-param name="Rows" select="$Rows"/>

</xsl:call-template>

<table border="0" width="100%" cellpadding="2" cellspacing="0">

<tr valign="top">

<xsl:if test="$dvt_1_automode = ‘1’" ddwrt:cf_ignore="1">

<th class="ms-vh" width="1%" nowrap="nowrap"></th>

</xsl:if>

<th class="ms-vh" nowrap="" align="left">

<input type="checkbox" id="chSelectAll">

<xsl:attribute name="onClick">javascript:SelectAllRow(<xsl:value-of select="$CountRow"></xsl:value-of>);</xsl:attribute>

</input>

</th>

<th class="ms-vh" nowrap="" align="left">Id</th>

<th class="ms-vh" nowrap="" align="left">Tipo</th>

<th class="ms-vh" nowrap="" align="left">Título</th>

<th class="ms-vh" nowrap="" align="left">Fecha Creación</th>

<th class="ms-vh" nowrap="" align="left">Creado por</th>

<th class="ms-vh" nowrap="" align="left">Modificado por</th>

</tr>

<xsl:call-template name="dvt_1.body">

<xsl:with-param name="Rows" select="$Rows"/>

</xsl:call-template>

</table></xsl:otherwise>

</xsl:choose>

</xsl:template>

<xsl:template name="dvt_1.body">

<xsl:param name="Rows"/>

<xsl:for-each select="$Rows">

<xsl:call-template name="dvt_1.rowview">

<xsl:with-param name="Pos" select="concat(‘_’, position())" />

</xsl:call-template>

</xsl:for-each>

</xsl:template>

<xsl:template name="dvt_1.rowview">

<xsl:param name="Pos" />

<tr>

<xsl:attribute name="id">row<xsl:value-of select="$Pos"></xsl:value-of></xsl:attribute>

<xsl:if test="position() mod 2 = 1">

<xsl:attribute name="class">ms-alternating</xsl:attribute>

</xsl:if>

<xsl:if test="$dvt_1_automode = ‘1’" ddwrt:cf_ignore="1">

<td class="ms-vb" width="1%" nowrap="nowrap">

<span ddwrt:amkeyfield="ID" ddwrt:amkeyvalue="ddwrt:EscapeDelims(string(@ID))" ddwrt:ammode="view"></span>

</td>

</xsl:if>

<td class="ms-vb">

<input type="checkbox">

<xsl:attribute name="id">chk<xsl:value-of select="$Pos"></xsl:value-of></xsl:attribute>

<xsl:attribute name="onclick">javascript:SelectRow(‘<xsl:value-of select="$Pos"></xsl:value-of>’);</xsl:attribute>

</input>

</td>

<td class="ms-vb" align="left">

<xsl:value-of select="format-number(@ID, ‘#,##0.#;-#,##0.#’)"/>

</td>

<td class="ms-vb" align="left">

<xsl:if test="@DocIcon=’docx’">

<img border="0" src="icdocx.gif" width="16" height="16" />

</xsl:if>

<xsl:if test="@DocIcon=’doc’">

<img border="0" src="_layouts/images/icdocx.gif" width="16" height="16" />

</xsl:if>

<xsl:if test="@DocIcon=’xlsx’">

<img border="0" src="_layouts/images/icxlsx.gif" width="16" height="16" />

</xsl:if>

<xsl:if test="@DocIcon=’xls’">

<img border="0" src="_layouts/images/icxlsx.gif" width="16" height="16" />

</xsl:if>

</td>

<td class="ms-vb" align="left">

<a>

<xsl:attribute name="href"><xsl:value-of select="@FileRef"></xsl:value-of></xsl:attribute>

<xsl:value-of select="@Title"/>

</a>

</td>

<td class="ms-vb" align="left">

<xsl:value-of select="ddwrt:FormatDate(string(@_DCDateCreated), 3082, 1)"/>

</td>

<td class="ms-vb" align="left">

<xsl:value-of select="@Author" disable-output-escaping="yes"/>

</td>

<td class="ms-vb" align="left">

<xsl:value-of select="@Editor" disable-output-escaping="yes"/>

</td>

</tr>

</xsl:template>

<xsl:template name="dvt_1.header">

<xsl:param name="Rows" />

<table cellSpacing="0" class="ms-menutoolbar" cellPadding="0" border="0" width="100%">

<tr>

<td class="ms-toolbar" width="50%">

Documentos de la lista

</td>

<td class="ms-toolbar" align="left" width="30%">

<a>

<xsl:attribute name="href">javascript:EliminarDocSeleccionados(‘<xsl:value-of select="$CountRow"></xsl:value-of>’);</xsl:attribute>

Eliminar Seleccionados

</a>

</td>

<td class="ms-toolbar" align="left" width="20%"><xsl:value-of select="count(/dsQueryResponse/Rows/Row)" />

documentos activos

<xsl:text xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" ddwrt:nbsp-preserve="yes" disable-output-escaping="yes">&amp;nbsp; </xsl:text>

</td>

<td class="ms-toolbar" align="left" width="20%">

</td>

</tr>

</table>

</xsl:template>

<xsl:template name="dvt_1.empty">

<xsl:variable name="dvt_ViewEmptyText">No hay elementos que mostrar en esta vista.</xsl:variable>

<table border="0" width="100%">

<tr>

<td class="ms-vb">

<xsl:value-of select="$dvt_ViewEmptyText" />

</td>

</tr>

</table>

</xsl:template>

</xsl:stylesheet>

</XSL>

</WebPartPages:DataFormWebPart>

</asp:Content>

<asp:Content id="Content2" runat="server" contentplaceholderid="PlaceHolderAdditionalPageHead">

<script type="text/javascript" src="soap.js" ID="SoapJs"></script>

<script type="text/javascript" src="Utilidades.js" ID="UtilidadesJs"></script>

</asp:Content>

 

Para acceder al código de archivo soap.js deberán acceder post de la demostración 2 que se encuentra el código fuente completo del mismo.

Código Fuente – Utilidades.js aspx 

var chk = "chk";

var row = "row";

var strGuidLista;

var strNameLista;

var tipoDoc;

var successResponse;

var errorResponse;

function SetTipoDocumento(strDocTipo)

{

tipoDoc = strDocTipo;

}

function SelectAllRow(countRow)

{

var eleInput;

var eleRow;

for(var i = 1; i <= countRow; i ++)

{

eleInput= document.getElementById(chk+"_"+i);

eleRow = document.getElementById(row+"_"+i);

if(eleInput.checked)

{

eleInput.checked = false;

eleRow.className = "";

itemSelected = false;

}

else

{

eleInput.checked = true;

eleRow.className = "ms-topNavFlyOutsHover";

itemSelected = true;

}

}

}

function SelectRow(idRow)

{

var elmInput = document.getElementById(chk+idRow);

var eleRow = document.getElementById(row+idRow);

if(elmInput.checked)

{

eleRow.className = "ms-topNavFlyOutsHover";

}

else

{

eleRow.className = "";

}

}

function EliminarDocSeleccionados(cntRows)

{

var docSel;

var arrayDocBorrar = new Array();

var boolEleSel = false;

for(i=1; i<=cntRows;i++)

{

docSel = document.getElementById(chk+"_"+i);

if(docSel.checked)

{

boolEleSel = true;

InvocarWebServiceDelete(i);

}

}

if(!boolEleSel)

{

alert("Debe Seleccionar un elemento.");

}

}

function ArmarParametroUpdate(idDoc)

{

var strUpdate = "<Batch OnError=’Continue’>";

strUpdate += "<Method ID=’1′ Cmd=’Delete’>";

strUpdate += "<Field Name=’Id’>" + idDoc + "</Field>";

//strUpdate += "<Field Name=’FileRef’>http://192.168.0.72:8082/webcast/Documents/<i>File</i></Field>";

strUpdate += "</Method></Batch>";

alert(strUpdate);

return strUpdate;

}

function OnLoadListsStart(){

alert("Comienza invocación al WebService.");

}

function OnLoadListsComplete(pStrXml){

alert(pStrXml);

}

function OnLoadListsError(){

alert(‘Se produjo un error en la invocación.’);

}

function InvocarWebServiceDelete(idDoc)

{

var lUrlWebService = ‘/webcast/_vti_bin/Lists.asmx’;

var lSoapActionNamespace = ‘http://schemas.microsoft.com/sharepoint/soap/’;

var lSoapAction = ‘UpdateListItems’;

var lParameters = new Array();

lParameters[0] = ‘listName’;

lParameters[1] = ‘Documentos’;

lParameters[2] = ‘updates’;

lParameters[3] = ArmarParametroUpdate(idDoc);

CallWebService(lUrlWebService,lSoapActionNamespace,lSoapAction,lParameters,

OnLoadListsStart,OnLoadListsComplete,OnLoadListsError);

}

Muchas gracias a los que asistieron y nos hicieron llegar sus comentarios……… 

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *