Difference between revisions of "How to add a Comment field to the User page"

From AbleCommerce Wiki
Jump to: navigation, search
(New page: Introduction Sometimes there may be need to store comments for a particular user. It may be something like "What a swell guy" or it could even be "Problem customer: high RMA rate". Regardl...)
 
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Introduction
+
'''Introduction'''
 +
 
 
Sometimes there may be need to store comments for a particular user. It may be something like "What a swell guy" or it could even be "Problem customer: high RMA rate".
 
Sometimes there may be need to store comments for a particular user. It may be something like "What a swell guy" or it could even be "Problem customer: high RMA rate".
 
Regardless of your reasons, it would be nice to have such a feature. Fortunately, the field exists in the database. It's just been left off the Edit User page for some reason. This modification describes how to easily add the field to the screen.
 
Regardless of your reasons, it would be nice to have such a feature. Fortunately, the field exists in the database. It's just been left off the Edit User page for some reason. This modification describes how to easily add the field to the screen.
Line 8: Line 9:
  
 
Edit the file and find this section of code in the HTML section towards the end of the file:  
 
Edit the file and find this section of code in the HTML section towards the end of the file:  
 
+
<code><pre>
 
                     <asp:DropDownList ID="Residence" runat="server">
 
                     <asp:DropDownList ID="Residence" runat="server">
 
                     <asp:ListItem Text="This is a residence" Value="1"></asp:ListItem>
 
                     <asp:ListItem Text="This is a residence" Value="1"></asp:ListItem>
Line 15: Line 16:
 
                     </td>
 
                     </td>
 
                     </tr>
 
                     </tr>
 
+
</pre></code>
  
 
and replace all of it with this code:
 
and replace all of it with this code:
  
 +
<code><pre>
 
                     <asp:DropDownList ID="Residence" runat="server">
 
                     <asp:DropDownList ID="Residence" runat="server">
 
                                 <asp:ListItem Text="This is a residence" Value="1"></asp:ListItem>
 
                                 <asp:ListItem Text="This is a residence" Value="1"></asp:ListItem>
Line 32: Line 34:
 
                     TextMode="MultiLine" Width="445px"></asp:TextBox></td>
 
                     TextMode="MultiLine" Width="445px"></asp:TextBox></td>
 
                     </tr>
 
                     </tr>
 +
</pre></code>
  
 
We've changed the screen display but the page doesn't know how to save or load the actual field contents. Let's do that next....
 
We've changed the screen display but the page doesn't know how to save or load the actual field contents. Let's do that next....
Line 40: Line 43:
  
 
First, find this line of code in the InitializeForm function near the beginning:
 
First, find this line of code in the InitializeForm function near the beginning:
 
+
<code><pre>
Residence.SelectedIndex = (address.Residence ? 0 : 1);
+
  codeResidence.SelectedIndex = (address.Residence ? 0 : 1);
 +
</pre></code>
  
 
and add this line immediately below it:
 
and add this line immediately below it:
 
+
<code><pre>
  Comment.Text = _User.Comment;
+
  Comment.Text = _User.Comment;
 
+
</pre></code>
 
Now, find this line of code further down in the SaveUser() function:
 
Now, find this line of code further down in the SaveUser() function:
 
+
<code><pre>
address.Residence = (Residence.SelectedIndex == 0);
+
  address.Residence = (Residence.SelectedIndex == 0);
 
+
</pre></code>
 
and add this line immediately below it:
 
and add this line immediately below it:
  
_User.Comment = Comment.Text;
+
<code><pre>
 
+
  _User.Comment = Comment.Text;
 +
</pre></code>
 
Save the page.
 
Save the page.
  
Line 64: Line 69:
  
 
Having the ability to store comments with a particular user account can give an admin useful insight into the customer. Any opportunity to know more about who you are dealing with is an opportunity to succeed. Knowledge truly is power.
 
Having the ability to store comments with a particular user account can give an admin useful insight into the customer. Any opportunity to know more about who you are dealing with is an opportunity to succeed. Knowledge truly is power.
 +
 +
==Reference==
 +
Originally posted in forums by Joe Payne http://forums.ablecommerce.com/viewtopic.php?f=47&t=6813
 +
 +
[[Category:AbleCommerce 7]]

Latest revision as of 11:32, 15 August 2013

Introduction

Sometimes there may be need to store comments for a particular user. It may be something like "What a swell guy" or it could even be "Problem customer: high RMA rate". Regardless of your reasons, it would be nice to have such a feature. Fortunately, the field exists in the database. It's just been left off the Edit User page for some reason. This modification describes how to easily add the field to the screen.

HTML Changes

The file we're going to change is ~/Admin/People/Users/EditUser.aspx. There is no code-behind file, so all the changes will occur in the same file.

Edit the file and find this section of code in the HTML section towards the end of the file:

                    <asp:DropDownList ID="Residence" runat="server">
                    <asp:ListItem Text="This is a residence" Value="1"></asp:ListItem>
                    <asp:ListItem Text="This is a business" Value="0"></asp:ListItem>
                    </asp:DropDownList>
                    </td>
                    </tr>

and replace all of it with this code:

                    <asp:DropDownList ID="Residence" runat="server">
                                <asp:ListItem Text="This is a residence" Value="1"></asp:ListItem>
                                <asp:ListItem Text="This is a business" Value="0"></asp:ListItem>
                            </asp:DropDownList>
                        </td>
                    </tr>
                    <tr>
                        <th class="rowHeader">
                            Comment:</th>
                        <td colspan="3">
                            <asp:TextBox ID="Comment" runat="server" Height="95px" 
                     TextMode="MultiLine" Width="445px"></asp:TextBox></td>
                    </tr>

We've changed the screen display but the page doesn't know how to save or load the actual field contents. Let's do that next....

Code Changes

There are two changes to made in the code. One reads the existing Comment field value into the page. The other writes it back to the User record before the record is saved.

First, find this line of code in the InitializeForm function near the beginning:

   codeResidence.SelectedIndex = (address.Residence ? 0 : 1);

and add this line immediately below it:

   Comment.Text = _User.Comment;

Now, find this line of code further down in the SaveUser() function:

   address.Residence = (Residence.SelectedIndex == 0);

and add this line immediately below it:

   _User.Comment = Comment.Text;

Save the page.

Testing

Go ahead and pull up your User page and edit any user. You should now see a large, unlimited text box below the address area. Try it out and type something into it, then Save the user. Return to your Dashboard, then again to the User page. Pull up the User and see if your changes were saved.

Conclusion

Having the ability to store comments with a particular user account can give an admin useful insight into the customer. Any opportunity to know more about who you are dealing with is an opportunity to succeed. Knowledge truly is power.

Reference

Originally posted in forums by Joe Payne http://forums.ablecommerce.com/viewtopic.php?f=47&t=6813