Implementing Updates

The easiest way of implementing updates would have been to bind the details view to the master view.  This technique is used in an excellent video tutorial on Channel 9.  I decided to adopt a different method for three reasons, two of which I will mention here.  I wanted the user’s changes to be submitted by clicking the OK button in the popup window.  With data binding in place, however, the master view, which is visible in the background, would update whenever the user tabbed away from a field in the details view.  The user could be confused about whether his changes had already been submitted.  If the user clicked cancel in the popup window, I of course wanted any changes he had made to be forgotten; and yet I could not find an automatic way to undo the changes.  For these reasons, together with a third, more important one, I chose to perform the update manually.  As it turned out, this too was straightforward.  I added a handler to the OK button of my popup window by setting its OnOkScript parameter:

OnOkScript

In the application init handler, I also created AdoNetDataContext component with my Mix Data Service as it source.  I assigned this component to a global variable dataContext, as I wanted it to be available throughout my application.

dataContext

In my webpage, I changed the dataprovider of my DataView to this new dataContext:

ChangedDataProvider

The function handling the OK button is simple:

SubmitChangeFunction

I use the get_selectedIndex method of the Presenters DataView to find which item is being edited.  I then use the get_items method to access the array of items.  To inform the DataView of the changes being made to its data, it is necessary to use the Sys.Observer.setValue method.  This method takes three parameters: first, the object to be changed; second, the name of the property to be changed; and third, the new value of that property.  The setValue method changes the data in memory.  To store the new data in the database, the saveChanges method of our dataContext is used.  This method can be called without any parameters, but here I have added two callbacks, and set the third parameter, the context, to the name of the operation being performed.

Advertisements

3 Responses to “Implementing Updates”

  1. Shane Says:

    Get posts! Keep up the good work.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: