I am passing the page id component id and template id to a aspx page as querystring with this java script:
var masterTabControl = $controls.getControl($("#MasterTabControl"),
"Tridion.Controls.TabControl");
p.compPresTab = masterTabControl.getPage("ComponentPresentationsTab");
p.selectedComponentPresentation = p.compPresTab.getSelectedComponentPresentation();
p.selectedComp = p.selectedComponentPresentation.getComponentId();
window.open("http://" + location.hostname + ":path/test.aspx?pgId=" + pageId +
"&comId=" + p.selectedComponentPresentation.getComponentId() +
"&comTmpId=" +
p.selectedComponentPresentation.getComponentTemplateId(),
"myWindow", "status = 1,
toolbar=no,width=300,height=200,resizable=no,scrollbars=yes");
Now on the test.aspx page i am reading the id and with some additional information from the user i am saving it into a text file.
On a button click on popup test.aspx page i am saving it in text file:
sLogDetails = PageId + "| " + ComponentId + "|" + ComponentTemplateId +
"|" + text ;
//Move the contents to the temp file other than the existing one.
using (var sr = new StreamReader(permanentFile))
{
using (var sw = new StreamWriter(@"" + tempFile , true))
{
string line;
while ((line = sr.ReadLine()) != null)
{
string[] parts = line.Split('|');
PageId = parts[0].Trim();
ComponentId = parts[1].Trim();
ComponentTemplateId = parts[2].Trim();
//Check there exist same record already
if (SPageId != PageId.Trim() || SComponentId != ComponentId.Trim()
|| SComponentTemplateId != ComponentTemplateId.Trim())
sw.WriteLine(line);
}
//Delete the Permanent file & create permanent file from temporary file
File.Delete(permanentFile);
File.Move(tempFile, permanentFile);
// Insert changes to the Permanent file
using (StreamWriter w = File.AppendText(permanentFile))
{
// Close the writer and underlying file.
w.WriteLine(sLogDetails);
w.Flush();
w.Close();
}
If the id is already present in the text file then i am populating it in the text field on popup test.aspx page like :
using (StreamReader r = File.OpenText(strPath + "Log.txt"))
{
string line;
while ((line = r.ReadLine()) != null)
{
// Console.WriteLine(line);
string[] parts = line.Split('|');
PageId=parts[0].Trim();
ComponentId = parts[1].Trim();
ComponentTemplateId = parts[2].Trim();
//If there exist a record populate the data fields
if (SPageId == PageId.Trim() && SComponentId == ComponentId.Trim()
&& SComponentTemplateId == ComponentTemplateId.Trim())
{
txtRuleName.Text = (string)parts[3];
}
}
r.Close();
}
Now I am getting stuck here. When it's populating in the text field, user can edit the text area in popup test.aspx page and on click of ok it will get saved in text file. And if user is closing the page window without "save & Close", then the changes made by him in text field should not get saved in text file. It should revert back to old one.
Any idea how can i make it?