ready = true;
return;
}
// process the results and figure out if we need to update our state
Note n = null;
for (int i = 0; i < notes.length; ++i) {
n = notes[i];
// server sent us a totally new record -- just store it
if (!noteData.containsKey(n.getName())) {
noteData.put(n.getName(), n);
gears.updateNote(n);
continue;
}
// record exists -- check if server version is more recent & handle it
Note current = noteData.get(n.getName());
if (!current.getVersion().equals(n.getVersion())) {
current.setVersion(n.getVersion());
if (current.getText().equals(n.getText())) {
// versions don't match but text is same anyway
gears.updateNote(current); // to update version...
localDirty = false;
lastData = current.getText();
} else if (current.getName().equals(rtw.getName()) && localDirty
&& Window.confirm(REPLACE_CONF_TEXT)) {
// if versions don't match, ask user for permission to override
gears.updateNote(current); // to update version...
// we are proceeding w/ local data, so don't touch UI
} else {
// user rejected override, or else was not current note
current.setText(n.getText());
gears.updateNote(current);
localDirty = false;
lastData = current.getText();
// don't forget to update UI state...
if (rtw.getName().equals(current.getName())) {
rtw.setHTML(current.getText());
}
}
continue;
}
}
// in the special case of startup, check for default value
if (isInit) {
Note def = noteData.get("default");
if (def != null) {
rtw.setHTML(def.getText());
}
}
ready = true;
}
});