1
0

Use javascript to set items

This commit is contained in:
Scott Graves
2017-02-16 19:22:40 -06:00
parent 4f04e4d58f
commit 8b568612bc
4 changed files with 42 additions and 13 deletions

View File

@@ -58,11 +58,11 @@
<table>
<tr>
<td style="text-align: right">Client Version:</td>
<td id="ClientVersion"></td>
<td id="ID_ClientVersion"></td>
</tr>
<tr>
<td style="text-align: right">Server Version:</td>
<td id="ServerVersion"></td>
<td id="ID_ServerVersion"></td>
</tr>
</table>
</div>

View File

@@ -96,8 +96,6 @@ CSiaDriveDlg::CSiaDriveDlg(CWnd* pParent /*=NULL*/)
void CSiaDriveDlg::DoDataExchange(CDataExchange* pDX)
{
CDHtmlDialog::DoDataExchange(pDX);
DDX_DHtml_ElementInnerText(pDX, _T("ServerVersion"), _serverVersion);
DDX_DHtml_ElementInnerText(pDX, _T("ClientVersion"), _clientVersion);
DDX_DHtml_ElementInnerText(pDX, _T("WalletBalanceTotal"), _walletBalanceTotal);
DDX_DHtml_ElementInnerText(pDX, _T("WalletBalanceConfirmed"), _walletBalanceConfirmed);
DDX_DHtml_ElementInnerText(pDX, _T("WalletBalanceUnconfirmed"), _walletBalanceUnconfirmed);
@@ -188,7 +186,7 @@ void CSiaDriveDlg::OnPaint()
}
}
BOOL CSiaDriveDlg::CallClientScript(LPCTSTR pStrFuncName, const json& json, CComVariant* pOutVarRes)
BOOL CSiaDriveDlg::CallClientScript(LPCTSTR pStrFuncName, const String& data, CComVariant* pOutVarRes)
{
BOOL bRes = FALSE;
CComVariant vaResult;
@@ -205,7 +203,7 @@ BOOL CSiaDriveDlg::CallClientScript(LPCTSTR pStrFuncName, const json& json, CCom
if (SUCCEEDED(spScript->GetIDsOfNames(IID_NULL, &bstrMember, 1, LOCALE_USER_DEFAULT, &dispid)))
{
VARIANT v[1];
v[0] = CComVariant(CA2W(json.dump().c_str()));
v[0] = CComVariant(data.c_str());
//Putting parameters
DISPPARAMS dispparams;
@@ -234,6 +232,12 @@ BOOL CSiaDriveDlg::CallClientScript(LPCTSTR pStrFuncName, const json& json, CCom
return bRes;
}
BOOL CSiaDriveDlg::CallClientScript(LPCTSTR pStrFuncName, const json& json, CComVariant* pOutVarRes)
{
String data = CA2W(json.dump().c_str());
return CallClientScript(pStrFuncName, data, pOutVarRes);
}
// The system calls this function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CSiaDriveDlg::OnQueryDragIcon()
@@ -307,12 +311,22 @@ BOOL CSiaDriveDlg::PreTranslateMessage(MSG* pMsg)
return CDHtmlDialog::PreTranslateMessage(pMsg);
}
void CSiaDriveDlg::SetClientVersion(const String& version)
{
CallClientScript(L"setClientVersion", version, nullptr);
}
void CSiaDriveDlg::SetServerVersion(const String& version)
{
CallClientScript(L"setServerVersion", version, nullptr);
}
void CSiaDriveDlg::OnDocumentComplete(LPDISPATCH, LPCTSTR)
{
KillTimer(IDT_UPDATE);
_serverVersion = L"x.x.x";
_clientVersion = L"1.0.0";
SetServerVersion(L"x.x.x.");
SetClientVersion(L"1.0.0");
_walletBalanceConfirmed = L"";
_walletBalanceUnconfirmed = L"";
_walletBalanceTotal = L"";
@@ -344,8 +358,8 @@ void CSiaDriveDlg::OnTimer(UINT_PTR nIDEvent)
bool CSiaDriveDlg::UpdateSiaInfo()
{
_serverVersion = _siaApi.GetServerVersion().c_str();
if (_serverVersion.GetLength())
const String serverVersion = _siaApi.GetServerVersion();
if (serverVersion.length())
{
if (_siaApi.GetWallet()->Refresh())
{
@@ -367,13 +381,14 @@ bool CSiaDriveDlg::UpdateSiaInfo()
_siaApi.GetWallet()->GetAddress(address);
_walletAddress = address.c_str();
}
SetServerVersion(serverVersion);
return true;
}
}
}
}
_serverVersion = L"x.x.x";
SetServerVersion(L"x.x.x");
_walletAddress = _walletBalanceConfirmed = _walletBalanceUnconfirmed = _walletBalanceTotal = L"";
return false;

View File

@@ -58,12 +58,13 @@ private:
HRESULT GetDomNodeAndElementById(const String& id, CComPtr<IHTMLDOMNode>& node, CComPtr<IHTMLElement>& elem);
HRESULT GetDomNodeById(const String& id, CComPtr<IHTMLDOMNode>& node);
BOOL CallClientScript(LPCTSTR pStrFuncName, const json& json, CComVariant* pOutVarRes);
BOOL CallClientScript(LPCTSTR pStrFuncName, const String& string, CComVariant* pOutVarRes);
void SetServerVersion(const String& version);
void SetClientVersion(const String& version);
private:
CSiaDriveConfig _siaConfig;
CSiaApi _siaApi;
CString _serverVersion;
CString _clientVersion;
CString _walletBalanceConfirmed;
CString _walletBalanceTotal;
CString _walletBalanceUnconfirmed;

View File

@@ -1,5 +1,18 @@
function setInnerText(elementName, data) {
var elem = document.getElementById(elementName);
elem.innerText = data;
}
function setClientVersion(version) {
setInnerText("ID_ClientVersion", version);
}
function setServerVersion(version) {
setInnerText("ID_ServerVersion", version);
}
function setAvailableDrives(driveList) {
driveList = Array.isArray(driveList) ? driveList : JSON.parse(driveList);