crazedsanity / cs-battletrack

PHP-Based web application for tracking data in traditional paper-and-pencil role playing games.
http://www.crazedsanity.com/projects/cs-battletrack
Other
1 stars 1 forks source link

Fix AJAX updating #52

Closed crazedsanity closed 7 years ago

crazedsanity commented 10 years ago

The current methodology behind performing AJAX updates is a little broken. The current method (as of v0.9.14) is a modification of the original, which made the assumption that the field would not be changed until the server responded that the update was OK (updates only occurred when the input lost focus, which lead to the possibility of data loss).

A better way should use the ".data" elements in JQuery. Basically, this:

(call this function mark_as_dirty)

  1. mark field "dirty"
  2. put blank value in .data['original]` (ONLY if it does not exist)
  3. start a timer to handle update after ~3000ms of no activity.
  4. handle update immediately after input loses focus (destroy timer)

Once a field is being processed:

  1. mark field as "updating"
  2. set value for inputId.data['sent-value']
  3. send AJAX request, specifically using value in inputId.data['sent-value']

When the server response comes back:

  1. if current value matches inputId.data['sent-value'], mark "updated", else...
  2. set .data['original'] to the value in inputId.data['sent-value'] and delete the latter.
  3. call mark_as_dirty()
crazedsanity commented 7 years ago

This is resolved in v0.4.0.