views:

365

answers:

1

I am working on an app that auto saves content while a user works on their content. I currently have two types of content saves. Save Draft (brand new content) and Update Draft (existing content).

The issue I am having is when a user first goes to create new content, the Save Draft method is called. The very next auto save should call the Update Draft to update the current content.

All of this is brought together with two variables. url.convID (conversation id) and form.messageID (message id).

Ok here is some code.

     // auto save method.
 function autoSave(){
                 savePath = 'view_message.cfm?action=autoSave' +
 '<cfif isDefined("url.convID") neq 0>&convID=<cfoutput>#url.convID#</cfoutput></cfif>&folderID=<cfoutput>#url.folderID#</cfoutput><cfif isDefined("url.profile")>&profile=<cfoutput>#url.profile#</cfoutput></cfif><cfif isDefined("url.isDraft")>&isDraft</cfif>';
   ColdFusion.Ajax.submitForm("compForm", savePath, setSaveTime);    
   autoSaveEvery(30000);  
 }
 // auto save timer
 function autoSaveEvery(ms) {
  var timeout=setTimeout("autoSave()",ms);
 }


 // display autosaved message
 function setSaveTime(res) {
  if (res) {
   document.getElementById('messageArea').innerHTML = 'Autosaved at ' + nowFormated();    
  }
 }

The auto save method is first called when a user first starts typing and is triggered 30 seconds after they first start typing. When the auto save is triggered the following code is run.

      if(url.action eq 'autoSave'){
   if(isDefined('form')){
    form = duplicate(form);
    if(isDefined('url.isDraft')){
     conversationUpdateSave(form);     
    }else{
     messageDraft(form);
    }
   }
  }

This code then calls one of two methods:

     function messageDraft(form){
  REReplace(form.messageContent,"<[Ss][CcTt][RrYy][IiLl][PpEe][Tt]?[^>]*>.*?</[Ss][CcTt][RrYy][IiLl][PpEe][Tt]?>","","ALL");
  REReplaceNoCase(form.messageContent,"</?(a|applet|base|embed|form|frame|frameset|iframe|ilayer|input|link|meta|noframes|noscript|object|param|sound|style|script|select|textarea|table|td|tr|tbody|th)[^>]*>","","ALL");
  ReplaceNoCase(form.messageContent,"onmouseover|onmouseout|onclick|onmousedown|onkeydown|onkeyup","","ALL");
  LEFT(ReplaceNoCase(form.messageContent,"'","&##39;","All"),3000);
  messageVO.setReceiverID(memberCT.getMemberID());
  messageVO.setSenderID(lomemberCT.getMemberID());
  messageVO.setMessageContent(form.messageContent);
  messageVO.setSendMessage(false);



  memberGW = createObject("component","com.model.gateway.MessagesGW");
  messageCT = memberGW.sMessage_Create(messageVO);

  if(url.convID eq 0){
   messageVO.setConversationID(messageCT.getConversationID());
   url.convID    = messageCT.getConversationID();
  }

  form.messageID    = messageCT.getMessageID();
  messageCT    = messageDisplay();
 }
 // update a previously saved draft 
 function conversationUpdateSave(form){
  messageVO.setConversationID(url.convID);
  messageVO.setMessageID(form.messageID); 
  messageVO.setMessageContent(form.messageContent);
  messageVO.setSendMessage(false);

  memberGW = createObject("component","com.model.gateway.MessagesGW");
  messageCT = memberGW.sMessage_Update(messageVO);

  messageCT    = messageDisplay();
 }

So the issue as I see it is. When the messageDraft method is called, the url.convID is not being set so that the subsequent calls to autosave call the method conversationUpdateSave.

I am fairly new to the ajax portion of this problem and any help anyone can shoot my way would be greatly appreciated.

+2  A: 

you don't need to post all those code to ask that question. :)

Instead of passing the convID through Url scpe, have u considered using Session? Have the Session remember the of the new convID, so any request without ID will use the convID in Session instead?

Or... have the first (or all) save call return the convID to the client, then the client will use that convID on the auto-save calls later.

Henry
The issue I am facing is I have tried that. But the client does not get updated on my response back. Mind you could be doing it incorrectly, but there really is only one way to return a value from a method. Any info you can throw my way based on the code above would be greatly appreciated.As for storing things in the session. I would prefer not to use session variables in this case. My ideal case would be to update the client from the returning method.
Tempname
where in the code you tried to do that? I don't see any return nor cfreturn in the code you posted above. You may want to use jQuery (easier/cleaner to me) to post the form, and use the callback to append the returned value to form post url (or.. hidden input value to go along with POST).
Henry
It was part of my messageDraft() method, but I removed it prior to posting my original post. More or less this is what I did in my messageDraft() methodvar convID = 0;// after my call to my cfcconvID = messageCT.getConversationID();return convID;Then in my autosave check I would so something like this.if(url.convID neq 0){ conversationUpdateSave(form); }else{ messageDraft(form);}This works correctly. The issue I am having is, I am not quite sure how to update the client so that it that returned conversation id is now a valid variable for the subsuquent calls.
Tempname
You have to somehow update the savePath in JavaScript after you received the returned convID on the first call. :) Again, use jQuery, easier.
Henry