User Recipe: Journal Editor


The Journal Editor is used to modify existing journal entries. Although this page could be done as a standard update record page with the minimal form elements needed, our recipe takes the concept a step further by including a listing of all the current entries. Journal entriesespecially those in a workgroup environmentare often reactive to other entries. By including both the balance of the journal and the actual entry being edited, it's easier to reference other thoughts and opinions.

To properly handle all the functionality on the page, three recordsets are needed. In addition to Journals and Entries, we'll also include an UpdateEntries recordset that will hold the values being modified.

Step 1: Implement Journal Editor Design

Like many of the other pages in this application, the layout for the Journal Editor is divided into two sections. The top part of the page displays the currently selected entry and allows it to be edited, while the bottom part displays all the journal entries.

1.

Create a page for the Journal Editor recipe, either from a template or from the File > New dialog.

In the Journal folder, locate the folder for your server model and open the journal_editor page there.

2.

In the content area of your page, create a header for the page and an area to hold both the general journal information and the specific entries.

From the Snippets panel, drag the Recipes > Journal > Wireframes > Journal Editor - Wireframe snippet into the Content editable region.

3.

Add labels and table cells to hold the journal information (name, owner, and description) and, below that, a two-row, two-column table for the journal entries.

Place your cursor in the first row below the words JOURNAL EDITOR and insert the Recipes > Journal > Forms > Journal Editor - Edit Message snippet.

Place your cursor in the bottom row of the wireframe and insert the Recipes > Journal > ContentTables > View Journal - Content Table snippet [r6-13].

r6-13.


4.

Save the page.

Step 2: Add Database Components

Two of the recordsets needed for this page have been used beforeJournal and Entries. The third one, UpdateEntries, is necessary to complete the primary function of the pageediting the selected entry.

Note

As noted in other recipes, when an identical recordset is used on one or more pages, you can copy the recordset from one page and paste it into the other. Be sure to use the Copy and Paste commands from the Bindings panel context menus for these operations.


1.

From the Bindings panel, choose Add (+) and select Recordset.

2.

In the dialog's simple view, enter an appropriate name for the recordset.

Enter Journal in the Name field.

3.

Choose a connection (data source) to use.

Select Recipes from the Connection list.

4.

Choose the table in the data source to work with.

Select Journals (journals for PHP) from the Table list.

5.

Leave the Columns option set to All.

6.

In the Filter area of the Recordset dialog, set the four Filter list elements like this:

JournalID

= (Equals)

URL Parameter

ID


7.

Leave the Sort option set to None and click OK to close the dialog.

Now, we'll insert the Entries recordset from which we'll gather the journal entries for display at the bottom of the page.

1.

From the Bindings panel, choose Add (+) and select Recordset.

2.

In the dialog's simple view, enter an appropriate name for the recordset.

Enter Entries in the Name field.

3.

Choose a connection (data source) to use.

Select Recipes from the Connection list.

4.

Choose the table in the data source to work with.

Select JournalEntries (journalentries for PHP) from the Table list.

5.

Leave the Columns option set to All.

6.

In the Filter area of the Recordset dialog, set the four Filter list elements like this:

EnTRyJournal

= (Equals)

URL Parameter

ID


7.

Leave the Sort option set to None and click OK to close the dialog.

Our final recordset is called UpdateEntries and consists of the data designed to be modified on the page. The recordset is filtered by applying the URL parameter EditID to its match in the EntryID key field.

ColdFusion and PHP users will also need to add a hidden form field so that the Update Record server behavior, inserted later, will work properly.

1.

From the Bindings panel, choose Add (+) and select Recordset.

2.

In the dialog's simple view, enter an appropriate name for the recordset.

Enter UpdateEntries in the Name field.

3.

Choose a connection (data source) to use.

Select Recipes from the Connection list.

4.

Choose the table in the data source to work with.

Select JournalEntries (journalentries in PHP) from the Table list.

5.

Leave the Columns option set to All.

6.

In the Filter area of the Recordset dialog, set the four Filter list elements like this:

EnTRyID

= (Equals)

URL Parameter

EditID


7.

Leave the Sort option set to None and click OK to close the dialog.

For PHP and ColdFusion

The following steps are for ColdFusion and PHP only.

1.

From the Forms tab of the Insert bar, drag a Hidden Field form element onto the table cell next to the explanatory text.

2.

Enter EditID as the name for the hidden element on the Property inspector.

3.

Click the lightning bolt icon to open the Dynamic Data dialog.

4.

From the Entries recordset, choose EntryID and click OK to close the dialog.

Step 3: Data Binding Process

In this step, we'll bind data from all three recordsets. The Journal recordset is used only once to display the current journal title. All the form elements are pulled from the UpdateEntries recordset. As before, the Entries recordset is the source for the data fields that display the journal's entries. In addition, we'll use that recordset to set up a dynamic link allowing any entry listed to also be edited.

1.

From the Bindings panel, expand the Journal recordset.

2.

Place the data source fields from Journal onto the page in their respective areas:

Drag JournalTitle into the cell next to the Journal Name label.

3.

In the Bindings panel, expand the UpdateEntries recordset.

4.

Place the data fields from UpdateEntries onto the page.

Drag EntryTitle into the PostTitle text field.

 

Drag EntryBy into the PostBy text field.

 

Drag EntryText into the MessagePost text field.


Now, we'll pull our data fields from the Entries recordset.

5.

In the Bindings panel, expand the Entries recordset.

6.

Place the data fields from Entries onto the page.

Drag EntryDate into the cell below the Date/Time label.

 

Select the term [EntryTitle] in the placeholder text at the top of the content area and drag EntryTitle from the Bindings panel onto the selection.

 

Select the term [EntryBy] in the placeholder text at the top of the content area and drag EntryBy from the Bindings panel onto the selection.

 

Select the term [EntryText] in the placeholder text at the top of the content area and drag EntryText from the Bindings panel onto the selection.


Now let's add our date and time string.

7.

Place the cursor where you want the date and time to appear.

Place your cursor in the cell next to the Current Date/Time label.

8.

Insert the following code:

From the Snippets panel, open the Recipes > Journal > Custom Code folder for your server model and insert the Current Date & Time - Dynamic Text snippet.

[View full width]

<%=FormatDateTime(Now(), 1) & " " & FormatDateTime (Now(), 3)%>


<%=new Date().toLocaleString()%>


[View full width]

<cfoutput>#LSDateFormat(Now(), "ddd, mmmm dd, yyyy")#</cfoutput>


<?php echo date("l, F j, Y h:i:s A"); ?>


9.

Be sure to save your page.

With the rest of our data fields bound, it's time to create a link for editing the separate entries.

1.

Select the text or image you want to serve as the link.

Choose the text [edit] below the Journal Description label.

2.

Click the folder icon next to the Link field in the Property inspector.

The Select File dialog opens.

3.

Choose Parameters at the bottom of the dialog.

4.

In the Name column of the Parameters dialog, enter the variable name.

Enter ID in the Name column.

5.

In the Value column, enter the dynamic value of the current survey's ID.

Click the lightning bolt icon next to the Value column and, from the Dynamic Data dialog, choose JournalID from the Journal recordset. When you're done, click OK to close the Dynamic Data dialog.

6.

Choose Add (+) to insert another parameter.

7.

Enter a name for the entry ID variable in the Name column.

Enter EditID in the Name column.

8.

Select the dynamic data for the value.

Click the lightning bolt icon next to the Value column and, from the Dynamic Data dialog, choose EntryID from the Entries recordset. When you're done, click OK once to close the Dynamic Data dialog, and again to close the Parameters dialog.

9.

In the Select File dialog, select the file that will be used to edit the survey information.

Choose journal_editor in the Journal folder for your server model.

10.

When you're done, click OK to insert the link [r6-14].

r6-14.


Step 4: Add Repeat Region

To show all the entries of a journal, a Repeat Region server behavior is necessary.

1.

Select any of the dynamic data fields in the entries content area.

2.

From the Tag Selector, choose the table row tag.

Select the <tr> tag from the Tag Selector.

3.

From the Server Behaviors panel, choose Add (+) and select Repeat Region.

4.

In the Repeat Region dialog, choose the recordset.

Choose Entries from the Recordset list.

5.

Set the Show option to display the number of records you want.

Choose Show All Records.

6.

Click OK when you're done and save your page.

Step 5: Update RecordNew Journal

The raison d'être of the Journal Editor is to modify an existing entry. After the entry is modified, the Update Record server behavior stores the changes.

For ASP

1.

From the Server Behaviors panel, choose Add (+) and select Update Record.

2.

In the Update Record dialog, select the data source connection.

Choose Recipes from the Connection list.

3.

Choose the table containing the data you are updating.

From the Table to Update list, choose JournalEntries.

4.

Choose the recordset from which to get data source fields.

From the Select Record From field, choose UpdateEntries.

5.

Set the primary key for the recordset.

From the Unique Key Column list, choose EntryID and make sure the Numeric option is selected.

6.

Select the file you want to appear when the update is complete.

For the After Updating, Go To field, select the journal.asp page.

7.

Choose the form on the page from which to get the values.

From the Get Values From list, choose JournalEditor.

8.

In the Form Elements area, set the form elements to their corresponding data source fields.

Set the PostTitle form element to update the EntryTitle data source field as Text.

 

Set the PostBy form element to update the EntryBy data source field as Text.

 

Set the MessagePost form element to update the EntryText data source field as Text.


9.

Make sure your entries are correct, and then click OK to close.

For ColdFusion and PHP

1.

From the Server Behaviors panel, choose Add (+) and select Update Record.

2.

In the Update Record dialog, choose the current form.

Select JournalEditor from the Submit Values From list.

3.

Select your data source from the list.

Choose Recipes from the Data Source list.

4.

Enter your user name and password, if needed.

5.

From the list, select the table in the data source into which to insert.

Choose JournalEntries (journalentries for PHP) from the Insert Into Table list.

6.

Set the data source fields to their corresponding form elements.

As the Primary Key, EntryID selects the record using FORM.EditID as a Numeric type for ColdFusion and Integer for PHP.

 

Set EntryTitle to get its value from the FORM.PostTitle form element as Text.

 

Set EntryBy to get its value from the FORM.PostBy form element as Text.

 

Set EntryText to get its value from the FORM.MessagePost form element as Text.

 

EntryDate should be set not to get a value.

 

EntryJournal should be set not to get a value.


7.

In the After Inserting, Go To field, enter the path to the file you want displayed after the record is updated.

Choose Browse and select journal.cfm or journal.php as appropriate.

8.

Check your entries to verify they are correct and, if so, click OK.

Step 6: Add Refresh Code

The final task for this page is to set up the Refresh link. When this link is clicked, changes to the current record are discarded and the previously stored values are inserted for editing.

1.

Select the text you want to apply the reset action to.

Choose the text Refresh in the upper right of the content area.

2.

Add the following as a link in the Property inspector:

From the Snippets panel, insert the Recipes > Journal > ClientJavaScript > Journal Editor - Refresh snippet. The snippet includes all the code necessary for creating the link and can just be dropped on the selected text.

javascript:document.JournalEditor.reset()

3.

Save your page.

We're finished with this page. Try it out by choosing Edit for a particular entry from the View Journal or Journal Publisher page; use only test entries, however, as you'll note that if you elect to update the recordeven without making changesthe time/date stamp is updated.

There's just one more page to complete for the entire recipe: Journal Archive.




Macromedia Dreamweaver 8 Recipes
Macromedia Dreamweaver 8 Recipes
ISBN: 0321393910
EAN: 2147483647
Year: 2003
Pages: 121

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net