html:
<div id='textAreaUrl'>---</div>
js:
$('#textAreaUrl').text(top.location)
Copy paste the url onto Chrome and start debugging with Developer Tools (F12)
Showing posts with label HTML. Show all posts
Showing posts with label HTML. Show all posts
Monday, October 9, 2017
Wednesday, October 4, 2017
Spotfire - Replace and refresh data and onclick button loading event (HTML and JS)
ironPython:
import System
import Spotfire.Dxp.Application
from Spotfire.Dxp.Data import *
from Spotfire.Dxp.Data.Import import DataTableDataSource
from Spotfire.Dxp.Data import CalculatedColumn
from System.IO import FileStream, FileMode, File, MemoryStream, SeekOrigin, StreamWriter, StreamReader
import System.String
from Spotfire.Dxp.Data.Import import TextDataReaderSettings
from Spotfire.Dxp.Data.Import import TextFileDataSource
import clr
clr.AddReference("System.Windows.Forms")
import System.Windows.Forms as WinForms
from Spotfire.Dxp.Framework.ApplicationModel import NotificationService
from System.Windows.Forms import OpenFileDialog
from System.Collections.Generic import List, Dictionary
from Spotfire.Dxp.Application.Visuals import HtmlTextArea
from Spotfire.Dxp.Framework.ApplicationModel import *
#get data source location
file_loc = OpenFileDialog()
file_loc.InitialDirectory
file_loc.ShowDialog()
try: #validate the source
ds = Document.Data.CreateFileDataSource(file_loc.FileName)
#since source_tbl is linked to source, need to replace it
source_tbl = Document.Data.Tables["well_attributes"].ReplaceData(ds)
except ValueError:
WinForms.MessageBox.Show("No file selected! Please select the file to refresh.")
#refresh text area
vis.As[HtmlTextArea]().HtmlContent += " " # Force re-render
raise #Rethrow the original exception, so I get a stack trace to it.
except IOError:
WinForms.MessageBox.Show("Please select the right file type.")
vis.As[HtmlTextArea]().HtmlContent += " "
raise
#notification service
notify = Application.GetService[NotificationService]();
# Tables(s) to refresh - change/add more if required
Tbls = List[DataTable]()
Tbls.Add(Document.Data.Tables['myTableName'])
# After tables are refreshed, update html
def afterLoad(exception, Document=Document, notify=notify):
if not exception:
# Hide the loading div
newHtml = vis.As[HtmlTextArea]().HtmlContent
oldDiv = '<div id="loading" style="display:inline">'
newDiv = '<div id="loading" style="display:none">'
newHtml = newHtml.Replace(oldDiv,newDiv)
# Apply change
vis.As[HtmlTextArea]().HtmlContent = newHtml;
vis.As[HtmlTextArea]().HtmlContent += " " # Force re-render
else:
notify.AddErrorNotification("Error refreshing table(s)","Error details",str(exception))
# Refresh table(s)
Document.Data.Tables.RefreshAsync(Tbls, afterLoad)
#message box after successful load and refresh data
WinForms.MessageBox.Show("Data has been successfully refreshed! ")
HTML:
<p style="text-indent: 4em;"> <font size="2"><strong> Please click to select well_attributes file (.csv file) to refresh:</strong></font>
<div id="clicker" style="visibility: visible;">
<SpotfireControl id="67e98bb593da44afaf6cfda44a8030e2" />
<font color="red" size="2"><strong>
<div id="loading"
style="display: none;">Refreshing...Please wait. DO NOT load file again!
</div></strong></font>
</div>
import System
import Spotfire.Dxp.Application
from Spotfire.Dxp.Data import *
from Spotfire.Dxp.Data.Import import DataTableDataSource
from Spotfire.Dxp.Data import CalculatedColumn
from System.IO import FileStream, FileMode, File, MemoryStream, SeekOrigin, StreamWriter, StreamReader
import System.String
from Spotfire.Dxp.Data.Import import TextDataReaderSettings
from Spotfire.Dxp.Data.Import import TextFileDataSource
import clr
clr.AddReference("System.Windows.Forms")
import System.Windows.Forms as WinForms
from Spotfire.Dxp.Framework.ApplicationModel import NotificationService
from System.Windows.Forms import OpenFileDialog
from System.Collections.Generic import List, Dictionary
from Spotfire.Dxp.Application.Visuals import HtmlTextArea
from Spotfire.Dxp.Framework.ApplicationModel import *
#get data source location
file_loc = OpenFileDialog()
file_loc.InitialDirectory
file_loc.ShowDialog()
try: #validate the source
ds = Document.Data.CreateFileDataSource(file_loc.FileName)
#since source_tbl is linked to source, need to replace it
source_tbl = Document.Data.Tables["well_attributes"].ReplaceData(ds)
except ValueError:
WinForms.MessageBox.Show("No file selected! Please select the file to refresh.")
#refresh text area
vis.As[HtmlTextArea]().HtmlContent += " " # Force re-render
raise #Rethrow the original exception, so I get a stack trace to it.
except IOError:
WinForms.MessageBox.Show("Please select the right file type.")
vis.As[HtmlTextArea]().HtmlContent += " "
raise
#notification service
notify = Application.GetService[NotificationService]();
# Tables(s) to refresh - change/add more if required
Tbls = List[DataTable]()
Tbls.Add(Document.Data.Tables['myTableName'])
# After tables are refreshed, update html
def afterLoad(exception, Document=Document, notify=notify):
if not exception:
# Hide the loading div
newHtml = vis.As[HtmlTextArea]().HtmlContent
oldDiv = '<div id="loading" style="display:inline">'
newDiv = '<div id="loading" style="display:none">'
newHtml = newHtml.Replace(oldDiv,newDiv)
# Apply change
vis.As[HtmlTextArea]().HtmlContent = newHtml;
vis.As[HtmlTextArea]().HtmlContent += " " # Force re-render
else:
notify.AddErrorNotification("Error refreshing table(s)","Error details",str(exception))
# Refresh table(s)
Document.Data.Tables.RefreshAsync(Tbls, afterLoad)
#message box after successful load and refresh data
WinForms.MessageBox.Show("Data has been successfully refreshed! ")
HTML:
<p style="text-indent: 4em;"> <font size="2"><strong> Please click to select well_attributes file (.csv file) to refresh:</strong></font>
<div id="clicker" style="visibility: visible;">
<SpotfireControl id="67e98bb593da44afaf6cfda44a8030e2" />
<font color="red" size="2"><strong>
<div id="loading"
style="display: none;">Refreshing...Please wait. DO NOT load file again!
</div></strong></font>
</div>
Javascript:
$('#67e98bb593da44afaf6cfda44a8030e2').click(function() {
// Show the loading prompt
$('#loading').css('display', 'inline');
// Click the python button
$('#clickerpy input').click()
// disable the refresh button
document.getElementById("67e98bb593da44afaf6cfda44a8030e2").disabled = true
});
Subscribe to:
Posts (Atom)