Home : Autosave Web Text Annotation edits without hiding the editor
Q10327 - HOWTO: Autosave Web Text Annotation edits without hiding the editor

Legacy Controls NOTICE

This article references our legacy Web Forms Web Viewing controls (WebImageViewer, WebAnnotationViewer, WebThumbnailViewer). It is preserved for archival purposes, but support strongly recommends using our modern HTML5 web controls: WebDocumentViewer, WebDocumentThumbnailer instead)

http://atalasupport.net/demos/LegacyDemos-11.1/WebViewingDemo.zip

Main Article Content

Problem: User edits text and does not hide the editor by clicking off the annotation.  The text then does not persist on the server when a RemoteInvoke is done (like saving the annotations to a file or database).

Solution: Keep track of text changes and force the annotation to update after a period of inactivity.  In this example, we'll update after 1 second.

Atalasoft.Utils.InitClientScript(myPageLoad);

function myPageLoad() {
 WebAnnotationViewer1.AnnotationEditorShown = OnEditorShown;
}

function OnEditorShown(e) {
 if (e.annotation && e.annotation.getType() == 'TextData') {
  AutoSaveTextEdits(e.annotation);
 }
}


function AutoSaveTextEdits(ann) {
 var _ann = ann;
 var _editor = null;
 var _txtChangedEvt = function () { };
 var _chging = null;
 if (_ann != null) {
  _editor = _ann.getEditorObject();
  _txtChangedEvt = _editor.onchange;
  _editor.onchange = __AutoSaveTextChanged;
  _editor.onkeydown = __AutoSaveTextChanged;
  WebAnnotationViewer1.AnnotationEditorHidden = __AutoSaveEditorHidden;
 }

 function __AutoSaveTextChanged() {
  _txtChangedEvt();
  __AutoSaveClearTimeout();
  _chging = setTimeout(__AutoSaveBufferUpdate, 1000);
 }
 
 function __AutoSaveEditorHidden() {
  __AutoSaveClearTimeout();
  WebAnnotationViewer1.AnnotationEditorHidden = function () { };
 }

 function __AutoSaveClearTimeout() {
  if (_chging != null) {
  clearTimeout(_chging);
  }
 }

 function __AutoSaveBufferUpdate() {
  _chging = null;
  _ann.Update();
 }
}

Related Articles
No Related Articles Available.

Article Attachments
No Attachments Available.

Related External Links
No Related Links Available.
Help us improve this article...
What did you think of this article?

poor 
1
2
3
4
5
6
7
8
9
10

 excellent
Tell us why you rated the content this way. (optional)
 
Approved Comments...
No user comments available for this article.

Powered By InstantKB.NET v1.3
Copyright © 2002, 2019. InstantASP Ltd. All Rights Reserved