HTML String on Object Property Won't Update - dom

I have an object constructor that sets some properties, and later uses them to concatenate a string to write to the DOM. I can see that this works in some cases, but not in others.
function Fighter(name, level, attackPts, defencePts, imgSource) {
// TRUNCATED PROPERTY ASSIGNMENTS AREA:
this.attackPts = attackPts;
this.defencePts = defencePts;
// DOM ELEMENT CONSTRUCTORS:
this.img = "style='background: #444 url(" + imgSource + ") no-repeat center'";
this.char_card_name = "<h3>" + this.name + "</h3>";
this.char_card_hitdef = "<h4>" + this.attackPts + "/" + this.defencePts + "</h4>";
this.char_card = "<div class='fighter " + faction + "' " + "id='" + this.name + "'>" + this.img + this.char_card_name + this.char_card_hitdef + "</div>";
In a game function later on I modify the attack and defense points for this "Fighter" object, and that works as expected, and my console.log() tests verify that the concatenated properties also update . . . . up until the final string to pull it all together and display:
this.char_card = "<div class='fighter " + faction + "' " + "id='" + this.name + "'>" + this.img + this.char_card_name + this.char_card_hitdef + "</div>";
When I log this property, those attack and defense numbers don't budge, even though they update successfully in the previous property, this.char_card_hitdef
What could I be overlooking here? I crawled all over the web looking for scope or variable reference issues, but my log statements bring me right back to this one pinching point.

Because you are still in the constructor, you need to refer to the variables without this. that are a parameter AND property of the Object Fighter.
So change
this.char_card = "<div class='fighter " + faction + "' " + "id='" + this.name + "'>" + this.img + this.char_card_name + this.char_card_hitdef + "</div>";
to
this.char_card = "<div class='fighter " + faction + "' " + "id='" + name + "'>" + this.img + this.char_card_name + this.char_card_hitdef + "</div>"
And all other properties that refer to properties above them.
You can read more about constructors here

Related

Project taking too long to build and run after adding complex query

I have integrated SQLite.swift framework in one of my swift project and everything was working fine until i added the below query. After adding the below query project is taking too long to build. I waited for 30 mins but still project is n't complied.
do
{
let stmt = try DB!.prepare ("SELECT e." + ENDPOINT_ID + " as _id, lk." + HUB_ID + ", e." + X_ENDPOINT_ID + ", e." + ENDPOINT_DESC + ", e." + ENDPOINT_TYPE_ID +", et." + ENDPOINT_STATUS_MIN + ", et." + ENDPOINT_STATUS_MAX + ", e." + ENDPOINT_STATUS + " FROM " + TABLE_ENDPOINT + " as e INNER JOIN " + TABLE_ENDPOINT_TYPE + " as et " +
" ON e." + ENDPOINT_TYPE_ID + " = et." + ENDPOINT_TYPE_ID +
" INNER JOIN " + TABLE_LINKING + " as lk " +
" ON e." + ENDPOINT_ID + " = lk." + ENDPOINT_ID +
" INNER JOIN " + TABLE_NODE + " as n " +
" ON lk." + NODE_ID + " = n." + NODE_ID +
" INNER JOIN " + TABLE_NODE_TYPE + " as nt " +
" ON n." + NODE_TYPE_ID + " = nt." + NODE_TYPE_ID +
" WHERE lk." + SECTION_ID + "=" + section_Id +
" AND nt." + NODE_CATEGORY + " = "S" " +
" ORDER BY e." + ENDPOINT_ID + " ASC")
let arr = Array(try stmt.run)
print("\(arr)")
return arr
} catch {
print("failed: \(error)")
return []
}
If i comment the above code and try to run the project it takes hardly a minute to run the project but after adding this code, it's taking hell lot of time. I have waited for almost 30 mins but still the project is not compiled nor it's throwing any error.
Thanks in advance for help
The Swift compiler has difficulties to deal with big string literals. See also this question for further hints.
I would recommend to split up the sql and to build a string variable in small steps:
var sql = "SELECT e." + ENDPOINT_ID
sql = sql + HUB_ID + ", e."
sql = sql + X_ENDPOINT_ID + ", e."
...
let stmt = try DB!.prepare(sql)
let query = (TABLE_ENDPOINT.select(TABLE_ENDPOINT[ENDPOINT_ID], TABLE_LINKING[HUB_ID], TABLE_ENDPOINT[ETCT_ENDPOINT_ID], TABLE_ENDPOINT[ENDPOINT_DESC], TABLE_ENDPOINT[ENDPOINT_TYPE_ID], TABLE_ENDPOINT_TYPE[ENDPOINT_STATUS_MIN], TABLE_ENDPOINT_TYPE[ENDPOINT_STATUS_MAX], TABLE_ENDPOINT[ENDPOINT_STATUS]).join(TABLE_ENDPOINT_TYPE, on: TABLE_ENDPOINT[ENDPOINT_TYPE_ID] == TABLE_ENDPOINT_TYPE[ENDPOINT_TYPE_ID]).join(TABLE_LINKING, on: TABLE_ENDPOINT[ENDPOINT_ID] == TABLE_LINKING[ENDPOINT_ID]).join(TABLE_NODE, on: TABLE_LINKING[NODE_ID] == TABLE_NODE[NODE_ID]).join(TABLE_NODE_TYPE, on: TABLE_NODE[NODE_TYPE_ID] == TABLE_NODE_TYPE[NODE_TYPE_ID])
.filter(TABLE_LINKING[SECTION_ID] == section_Id && TABLE_NODE_TYPE[NODE_CATEGORY] == "S")
.order(TABLE_ENDPOINT[ENDPOINT_ID].asc))
let arr = Array(try DB!.prepare(query))

Retargeting in Fb,Google

I have a campaign and pixel Id for Fb and Google both which looks something like this.
Can some one tell me how can I implement retargeting pixel in FB, google. What are the changes do I need to make in this dynamicaly generated Pixel script?
PixelScript = PixelScript + "<script>(function(){" + Environment.NewLine +
"window._fbds = window._fbds || {};" + Environment.NewLine +
"_fbds.pixelId = " + FB_Pixel + ";" + Environment.NewLine +
"var fbds = document.createElement(\"script\");" + Environment.NewLine +
"fbds.async = true;" + Environment.NewLine +
"fbds.src = \"//connect.facebook.net/en_US/fbds.js\";" + Environment.NewLine +
"var s = document.getElementsByTagName(\"script\")[0];" + Environment.NewLine +
"s.parentNode.insertBefore(fbds, s);" + Environment.NewLine +
"})();" + Environment.NewLine +
"window._fbq = window._fbq || [];" + Environment.NewLine +
"window._fbq.push([\"track\", \"PixelInitialized\", {}]);" + Environment.NewLine +
"</script>" + Environment.NewLine +
"<noscript><img height=\"1\" width=\"1\" border=\"0\" alt=\"\" style=\"display:none\" src=\"https://www.facebook.com/tr?id=" + FB_Pixel + "&ev=NoScript\" /></noscript>";
The given pixel is enough to drop cookies on the website. No need to add anything.

Trying to use Mustasche in Tinymce preview

As the title suggests I am trying to get Mustasche templates to work in the Tinymce preview but it does not work.
In Tinymce Plugins/Preview/plugin.js
previewHtml = (
'<!DOCTYPE html>' +
'<html>' +
'<head>' +
'<script type="text/javascript" src="~/Scripts/mustache.js"></script>' +
headHtml +
'</head>' +
'<body id="' + bodyId + '" class="mce-content-body ' + bodyClass + '"' + dirAttr + '>' +
editor.getContent() +
'</body>' +
'</html>'
);
Stuff to preview:
var obj1 = { user: "John", age: 22, country: "United States" };
{{obj1.user}}
It is fixed now and this is how it's done:
In Tinymce Plugins/Preview/plugin.js
var json = $.parseJSON($('#yourtextarea').val());
previewHtml = (
'<!DOCTYPE html>' +
'<html>' +
'<head>' +
headHtml +
'</head>' +
'<body id="' + bodyId + '" class="mce-content-body ' +
bodyClass + '"' + dirAttr + '>' +
Mustache.to_html(editor.getContent(),json)
+
'</body>' +
'</html>'
);

Management API - Create VM - InvalidXmlRequest - The request body XML was invalid or not correctly specified

I am getting error while creating virtual machine from Azure REST management API. Could someone please point me what wrong I am POSTing in below XML
ERROR --- <Error xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><Code>InvalidXmlRequest</Code><Message>The request body's XML was invalid or not correctly specified.</Message></Error>
My POST string:
" <Deployment xmlns=\"http://schemas.microsoft.com/windowsazure\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">" +
" <Name>SomeName</Name>" +
" <DeploymentSlot>Production</DeploymentSlot>" +
" <Label>SomeLabel</Label>" +
" <RoleList>" +
" <Role>" +
" <RoleName>SomeRoleName</RoleName>" +
" <RoleType>PersistentVMRole</RoleType>" +
" <ConfigurationSets>" +
" <ConfigurationSet i:type=\"WindowsProvisioningConfigurationSet\">" +
" <ConfigurationSetType>WindowsProvisioningConfiguration</ConfigurationSetType>" +
" <ComputerName>SomeCompName</ComputerName>" +
" <AdminPassword>Admin098</AdminPassword>" +
" <EnableAutomaticUpdates>true</EnableAutomaticUpdates>" +
" <ResetPasswordOnFirstLogon>false</ResetPasswordOnFirstLogon>" +
" </ConfigurationSet>" +
" <ConfigurationSet i:type=\"NetworkConfigurationSet\">" +
" <ConfigurationSetType>NetworkConfiguration</ConfigurationSetType>" +
" <InputEndpoints>" +
" <InputEndpoint>" +
" <LocalPort>3389</LocalPort>" +
" <Name>RemoteDesktop</Name>" +
" <Protocol>tcp</Protocol>" +
" </InputEndpoint>" +
" </InputEndpoints>" +
" </ConfigurationSet>" +
" </ConfigurationSets>" +
" <OSVirtualHardDisk>" +
" <DiskName>SomeDiskName-0-20121007173943</DiskName>" +
" <MediaLink>http://portalvhdsrx7q659n2n5j2.blob.core.windows.net/public/myvhd0008980.vhd</MediaLink>" +
" <SourceImageName>MSFT__Win2K8R2SP1-Datacenter-201208.01-en.us-30GB.vhd</SourceImageName>" +
" </OSVirtualHardDisk>" +
" <RoleSize>Small</RoleSize>" +
" </Role>" +
" </RoleList>" +
" </Deployment>"
Hi,
Added AdminUsername also. But still getting error. DateTime of request - 04-11 17:30:03.759
<Error xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><Code>InvalidXmlRequest</Code><Message>The request body's XML was invalid or not correctly specified.</Message></Error>
POST string
<Deployment xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> <Name>SomeName</Name> <DeploymentSlot>Production</DeploymentSlot> <Label>SomeLabel</Label> <RoleList> <Role> <RoleName>SomeRoleName</RoleName> <RoleType>PersistentVMRole</RoleType> <ConfigurationSets> <ConfigurationSet i:type="WindowsProvisioningConfigurationSet"> <ConfigurationSetType>WindowsProvisioningConfiguration</ConfigurationSetType> <ComputerName>SomeCompName</ComputerName> <AdminPassword>Admin098</AdminPassword> <AdminUsername>AwesomeAdmin</AdminUsername> <EnableAutomaticUpdates>true</EnableAutomaticUpdates> <ResetPasswordOnFirstLogon>false</ResetPasswordOnFirstLogon> </ConfigurationSet> <ConfigurationSet i:type="NetworkConfigurationSet"> <ConfigurationSetType>NetworkConfiguration</ConfigurationSetType> <InputEndpoints> <InputEndpoint> <LocalPort>3389</LocalPort> <Name>RemoteDesktop</Name> <Protocol>tcp</Protocol> </InputEndpoint> </InputEndpoints> </ConfigurationSet> </ConfigurationSets> <OSVirtualHardDisk> <DiskName>SomeDiskName-0-20121007173943</DiskName> <MediaLink>http://portalvhdsrx7q659n2n5j2.blob.core.windows.net/public/myvhd0008980.vhd</MediaLink> <SourceImageName>MSFT__Win2K8R2SP1-Datacenter-201208.01-en.us-30GB.vhd</SourceImageName> </OSVirtualHardDisk> <RoleSize>Small</RoleSize> </Role> </RoleList> </Deployment>
Try by adding AdminUsername node after AdminPassword node.
" <Deployment xmlns=\"http://schemas.microsoft.com/windowsazure\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">" +
" <Name>SomeName</Name>" +
" <DeploymentSlot>Production</DeploymentSlot>" +
" <Label>SomeLabel</Label>" +
" <RoleList>" +
" <Role>" +
" <RoleName>SomeRoleName</RoleName>" +
" <RoleType>PersistentVMRole</RoleType>" +
" <ConfigurationSets>" +
" <ConfigurationSet i:type=\"WindowsProvisioningConfigurationSet\">" +
" <ConfigurationSetType>WindowsProvisioningConfiguration</ConfigurationSetType>" +
" <ComputerName>SomeCompName</ComputerName>" +
" <AdminPassword>Admin098</AdminPassword>" +
" <AdminUsername>AwesomeAdmin</AdminUsername>" +
" <EnableAutomaticUpdates>true</EnableAutomaticUpdates>" +
" <ResetPasswordOnFirstLogon>false</ResetPasswordOnFirstLogon>" +
" </ConfigurationSet>" +
" <ConfigurationSet i:type=\"NetworkConfigurationSet\">" +
" <ConfigurationSetType>NetworkConfiguration</ConfigurationSetType>" +
" <InputEndpoints>" +
" <InputEndpoint>" +
" <LocalPort>3389</LocalPort>" +
" <Name>RemoteDesktop</Name>" +
" <Protocol>tcp</Protocol>" +
" </InputEndpoint>" +
" </InputEndpoints>" +
" </ConfigurationSet>" +
" </ConfigurationSets>" +
" <OSVirtualHardDisk>" +
" <DiskName>SomeDiskName-0-20121007173943</DiskName>" +
" <MediaLink>http://portalvhdsrx7q659n2n5j2.blob.core.windows.net/public/myvhd0008980.vhd</MediaLink>" +
" <SourceImageName>MSFT__Win2K8R2SP1-Datacenter-201208.01-en.us-30GB.vhd</SourceImageName>" +
" </OSVirtualHardDisk>" +
" <RoleSize>Small</RoleSize>" +
" </Role>" +
" </RoleList>" +
" </Deployment>"

Checking User Agent in Wicket

I am using wicket 1.5 and I am not able to see in the getClientInfo() method
(WebRequest)RequestCycle.get().getRequest()
I saw the other place this code
WebClientInfo clientInfo = (WebClientInfo)WebRequestCycle.get().getClientInfo();
But I am not able to see any WebRequestCycle in Wicket 1.5.
Any ideas how to check the user agent in Wicket 1.5?
The easiest way is to use
WebSession.get().getClientInfo().getUserAgent();
On newer Wicket Versions (6 or newer), you should use:
WebClientInfo clientInfo = new WebClientInfo(getRequestCycle());
System.out.println("Client: " + clientInfo.getUserAgent());
System.out.println("Navigator: " + clientInfo.getProperties().getNavigatorAppName() + ", version " + clientInfo.getProperties().getNavigatorAppVersion() + ", codName: " + clientInfo.getProperties().getNavigatorAppCodeName() + ", plataform: " + clientInfo.getProperties().getNavigatorPlatform() + ", AppCodName: " + clientInfo.getProperties().getNavigatorAppCodeName());
System.out.println("NavigatorUserAgent: " + clientInfo.getProperties().getNavigatorUserAgent());
System.out.println("Tamanho da tela (Width x Height): " + clientInfo.getProperties().getScreenWidth() + " x " + clientInfo.getProperties().getScreenHeight() );
You can also do:
((WebRequest) getRequest()).getHeader("User-Agent")