SharePoint: Extended DVWP-Part 2: Add a backup editing template for DVWP

Source: Internet
Author: User
Document directory
  • Audit of delete operations
  • A backup editing template is required.
  • Delete
  • Analysis and editing template
  • Analysis and editing template Composition
  • Step 1: Create a New ParameterBinding variable
  • Step 2: Modify the form operation link
  • Step 2: Call the remove template
  • Step 2: Copy and edit the template to a new "remove" template.

Just like a feast with many dishes, the range of this series has changed from delicious to delicious, from bread to whole wheat, from pie to lamb chops, from water to wine. Hopefully, these will trigger your appetite and make you want to explore SharePoint DVWP, learn what it can do, and explore more possibilities.
Okay, prepare your knives and forks. We have some barbecues coming soon (yes! There are also desserts !)
If you are not ready yet, there is now a good opportunity to improve your XSLT skills to learn Marc Anderson's series of "unlocking the mystery of XSLT markup for SharePoint data view Web Components.

Audit of delete operations

In this series, we have gone deep into the inside of DVWP, but now I want to bring your attention back to the beginning. In section 1st: Layout enhancement-rearranging columns in default and edit templatesDefaultValue template andEditTemplate. One of the most important points is that we need to modify each template because they share the template title row but have their own data rows.
When we goInsertIn the template, you have to change the layout of data rows again.
In Part 5-9, we have processed these links: Calling workflows, passing variables, and so on. The following section 15-23 details the components of the DVWP editing template. Then, in an instance, we write changes to the list items into an audit list to implement list audit. (The insertion of list items is easy to audit by starting the workflow at the time of creation .) In the previous article, we modified the editing template to accommodate multiple rows of data, added a bar label, and added a colored border outside the editing/inserting form to indicate different form states.
Now let's take a look at how to keep the delete operation records in the audit list.

A backup editing template is required.

Back to "Part 1: Analysis list form operation link", we found that the deletion link generated by DVWP does not have its own template. It only deletes list items and redraws lists.

Delete
<A href = "javascript: {ddwrt: GenFireServerEvent (concat ('_ cancel ;__ delete = {', $ KeyField, '=', $ KeyValue ,'}; __commit ')} "> Delete </a>

The delete link is used to re-paint the DVWP using the default template, but does not contain the deleted list items. It actually executes three functions:

1,Cancel(Used to prevent the form from executing the regular commit function );

2,Delete(Used to pass the ID of the list item to be deleted to the function to be deleted); and

3,Commit(Used to submit a delete operation for execution ).

Note that there is no verification for whether the object should be deleted; it is only an operation (of course, we can easily recover it through the recycle bin ). In future blog posts, we will modify the execution method.

To bring up a confirmation dialog box, you can call PreSaveAction () on the delete form operation link.
But what if you want to save this record to the audit list and record a valid Date? In this case, you need to enter a valid Date before deleting the record from the master list and store it in the audit list.
Further, you may need to record the causes of different deletion records. For example, the reason for deleting an employee's record may be resignation (initiated by the employee) or dismissal (initiated by the company ).
To delete these items, you must follow these steps.


The "delete" template we will create

Analysis and editing template

Let's take a look at the built-in XSLT for editing templates to find the part that must be copied to create a backup template.

1. Open SharePoint Designer (SPD), and then
2. Open the site where the DVWP form containing your multi-project view is located,
3. Make sure that you have modified DVWP so that it can be edited (see extended DVWP-1st for more information)
4. Hover over your webpart and click on the right-arrow (chevron) Hover your mouse over your WebPart, and then click the right angle bracket icon in the upper right corner.


5. Click the data view preview drop-down box and select "Edit template"

Note the changes on the page so that you can modify the column of this list item.

Edit template (after modification)

Analysis and editing template Composition

Click the control in the upper left corner of the editing template. In the Code pane, you will find that this template is completely contained in An XSLT template.

<xsl:template name="dvt_1.rowedit">    <xsl:param name="Pos" />    <tr>        . . .    </tr></xsl:template>

To create and delete a template, We will copy the XSLT.

However, we also need to figure out how to call and when to call the template. SearchCall-template name = "dvt_1.rowedit", You will find a script that looks like this:

<xsl:if test="not($dvt_HideGroupDetail)" ddwrt:cf_ignore="1">    <xsl:choose>        <xsl:when test="$dvt_1_form_editkey = ddwrt:EscapeDelims(string(@ID))">            <xsl:call-template name="dvt_1.rowedit">                <xsl:with-param name="Pos" select="concat('_', position())" />            </xsl:call-template>        </xsl:when>        <xsl:otherwise>            <xsl:call-template name="dvt_1.rowview" />        </xsl:otherwise>    </xsl:choose></xsl:if>

We need to determine when to call the deleted XSL template, so add an xsl: when in this selection statement. The Edit template is called when $ dvt_effecform_editkey is equal to the @ ID of the list item. We will call our template in a similar way. So where is $ dvt_1_form_editkey assigned? Search for some of them (without $) to find the answer.
Wow! When we jump back to the ParameterBindings node, we find this:

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

This is where it is declared, but where is it assigned a value? Continue to search down.

<xsl:otherwise><tr>    <td class="ms-vb" width="1%" nowrap="">        <a href="javascript: {ddwrt:GenFireServerEvent(concat('__cancel;dvt_1_form_editkey={',$KeyValue,'}'))}">update</a>    </td>    <td class="ms-vb" width="1%" nowrap="" style="border-left:1px black solid; padding-left:3px">        <a href="javascript: {ddwrt:GenFireServerEvent(concat('__cancel;__delete={',$KeyField,'=',$KeyValue,'};__commit'))}">remove</a>    </td></tr></xsl:otherwise>

Oh! The value assigned when we click the link. At the same time, it is noted that deleting does not currently work in the same way: it passes a KeyField to delete list items. Therefore, we need to modify this part.

Where else is it used? The discovery of another search:

<xsl:stylesheet . . .>        <xsl:output method="html" indent="no"/>        <xsl:param name="dvt_adhocmode">sort</xsl:param>        <xsl:decimal-format NaN=""/>        <xsl:param name="dvt_apos">'</xsl:param>        <xsl:param name="dvt_1_form_editkey" />        <xsl:param name="dvt_1_form_insertmode" />        <xsl:param name="dvt_groupfield" />

Stylesheet also requires a parameter declaration so that it can be used.
OK. Therefore, we need:

1. Create a New ParameterBinding variable for stylesheet and a new xsl: param;
2. Modify the remove form operation and return an ID to the page so that DVWP can know which list items are being deleted;
3. Tell the template to display the alternate editing template for the function to be deleted
4. Copy the existing rowedit template to create the new template we want to draw. Then,
5. Modify the new backup template so that it can be drawn and run as needed.

Step 1: Create a New ParameterBinding variable

Therefore, let's create our own version of the edit key...

<ParameterBinding Name="dvt_1_form_editkey" Location="Postback;Connection"/><ParameterBinding Name="dvt_1_form_removekey" Location="Postback;Connection"/>

... And stylesheet parameters.

<xsl:param name="dvt_1_form_editkey" /><xsl:param name="dvt_1_form_removekey" />
Step 2: Modify the form operation link

It now looks like an update link.

<xsl:otherwise><tr>    <td class="ms-vb" width="1%" nowrap="">        <a href="javascript: {ddwrt:GenFireServerEvent(concat('__cancel;dvt_1_form_editkey={',$KeyValue,'}'))}">update</a>    </td>    <td class="ms-vb" width="1%" nowrap="" style="border-left:1px black solid; padding-left:3px">        <a href="javascript: {ddwrt:GenFireServerEvent(concat('__cancel;dvt_1_form_removekey={',$KeyValue,'}'))}">remove</a>    </td></tr></xsl:otherwise>
Step 2: Call the remove template

We only need to add another xsl: when to choose. The condition is that when dvt_1_form_removekey is the current row.

<xsl:if test="not($dvt_HideGroupDetail)" ddwrt:cf_ignore="1">    <xsl:choose>        <xsl:when test="$dvt_1_form_editkey = ddwrt:EscapeDelims(string(@ID))">            <xsl:call-template name="dvt_1.rowedit">                <xsl:with-param name="Pos" select="concat('_', position())" />            </xsl:call-template>        </xsl:when>        <xsl:when test="$dvt_1_form_removekey = ddwrt:EscapeDelims(string(@ID))">            <xsl:call-template name="dvt_1.rowremove">                <xsl:with-param name="Pos" select="concat('_', position())" />            </xsl:call-template>        </xsl:when>        <xsl:otherwise>            <xsl:call-template name="dvt_1.rowview" />        </xsl:otherwise>    </xsl:choose></xsl:if>
Step 2: Copy and edit the template to a new "remove" template.

(We simply call it the remove template)

<xsl:template name="dvt_1.rowedit">    <xsl:param name="Pos" />    <tr>        . . .    </tr></xsl:template><xsl:template name="dvt_1.rowremove">    <xsl:param name="Pos" />    <tr>        . . .    </tr></xsl:template>

Next time: Continue to expand the DVWP series. We will discuss Step 1: Modify the remove template.

 

References

SharePoint: Extending the DVWP-Part 27: Adding an Alternate Edit Template to a DVWP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.