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.