JSTreeGrid cell editing on selection - jstree

I am using jsTreeGrid to do a row edit on a selection using this action..
function demo_rename() {
var ref = $('#jstree_demo').jstree(true),
sel = ref.get_selected();
if(!sel.length) {
return false;
}
sel = sel[0];
ref.edit(sel);
};
How I can edit a cell on selection using the same jsTreeGrid library?

Add these lines after set = sel[0];:
var column_number = 1; //assume second column
var current_value = $("#jsgrid_" + sel + "_col"+ column_number +" > span").html();
$("#jsgrid_" + sel + "_col"+ column_number +" > span").html("<input type='text' value='"+ current_value +"' />");
$("#jsgrid_" + sel + "_col"+ column_number +" > span > input").keypress(function(e){
if(e.keyCode)
{
var new_value = $(this).val();
$(this).parent().html(new_value);
}
});
and remove ref.edit(sel);

Related

Featherlight Image Count Index/Total [Indexing Error]

I am trying to add Image count in a Featherlight Gallery.
Example : Image 1 of 6 (somewhere beside/below an image)
$.featherlightGallery.prototype.afterContent = function(){
var object = this.$instance,
target = this.$currentTarget,
parent = target.parent(),
caption = parent.find('.wp-caption-text'),
galParent = target.parents('.gallery-item'),
jetParent = target.parents('.tiled-gallery-item');
$('<div class="count">Image ' + (currentNavigation() + 1)+' of ' + slides().length + '</div>').html(object.find('.featherlight-content'));
if (0 !== galParent.length) {
caption = galParent.find('.wp-caption-text');
} else if (0 !== jetParent.length) {
caption = jetParent.find('.tiled-gallery-caption');
}
object.find('.caption').remove();
if (0 !== caption.length) {
$('<div class="caption">').text(caption.text()).appendTo(object.find('.featherlight-content'));
}
}
It throws me back with the error : currentNavigation is not defined
You need to call this.currentNavigation()
Omg! I got it! I guess it was a fluke! After trying a few probabilities, this is the final answer. I hope someone may find this useful ;D
$.featherlightGallery.prototype.afterContent = function(){
var object = this.$instance,
target = this.$currentTarget,
parent = target.parent(),
caption = parent.find('.wp-caption-text'),
galParent = target.parents('.gallery-item'),
jetParent = target.parents('.tiled-gallery-item');
var sc = $('<div class="count">Image ' + (this.currentNavigation() + 1) + ' of ' + this.slides().length + '</div>');
sc.appendTo(object.find('.featherlight-content'));
object.find('.count').remove();
if (0 !== sc.length) {
sc.appendTo(object.find('.featherlight-content'));
}
if (0 !== galParent.length) {
caption = galParent.find('.wp-caption-text');
} else if (0 !== jetParent.length) {
caption = jetParent.find('.tiled-gallery-caption');
}
object.find('.caption').remove();
if (0 !== caption.length) {
$('<div class="caption">').text(caption.text()).appendTo(object.find('.featherlight-content'));
}
}

Enterprise Architect - How to set column key to Autonum?

I have a bunch of tables with Id int primary keys. However, I forgot to set AutoNum to True in the UI. Since changing all hundreds of tables is tedious, how can I set this property for all Id columns?
I have built a script that runs through each table and detects the Id column:
var package as EA.Package;
package = Repository.GetTreeSelectedPackage();
var tablesEnumerator = new Enumerator(package.Elements);
while (!tablesEnumerator.atEnd()) {
var table as EA.Element;
table = tablesEnumerator.item();
var methodsEnumerator = new Enumerator(table.Methods);
while (!methodsEnumerator.atEnd()) {
var method as EA.Method;
method = methodsEnumerator.item();
if (method.Name !== "Id") { continue; }
Session.Output(method.Name);
// Now what?!
}
}
I have searched for AutoNum in EnterpriseArchitect docs and APIs, but was unable to find suitable references.
According to Autonum in Column Properties inaccessible you can actually change the AutoNum behaviour via API with the means of TaggedValues. So there is no need of direct SQL updates to the database.
Setting the tagged values property and AutoNum on the Id attribute (not the method of the table seems to do the magic. It tried it via the builtin script engine and it works:
Before running the script
After running the script
The update script
!INC Local Scripts.EAConstants-JScript
function main()
{
var package = Repository.GetTreeSelectedPackage();
var elements as EA.Collection;
elements = package.Elements;
Session.Output("Elements Count " + elements.Count);
for ( var ec = 0 ; ec < elements.Count ; ec++ )
{
var element as EA.Element;
element = elements.GetAt(ec);
if("Table" != element.MetaType) continue;
Session.Output("Element: Name '" + element.Name + "' [" + element.ElementGUID + "] '" + element.MetaType + "'.");
var attributes as EA.Collection;
attributes = element.Attributes;
for ( var ac = 0; ac < attributes.Count ; ac++)
{
var attribute as EA.Attribute;
attribute = attributes.GetAt(ac);
if("Id" != attribute.Name) continue;
Session.Output("Attribute: Name '" + attribute.Name + "' [" + attribute.AttributeGUID + "] in element '"+ element.Name + "' [" + element.MetaType + "].");
var hasTvProperty = false;
var hasTvAutonum = false;
var taggedValues as EA.Collection;
taggedValues = attribute.TaggedValues;
Session.Output("TaggedValues: Count " + taggedValues.Count);
for ( var tc = 0; tc < taggedValues.Count; tc++)
{
var taggedValue as EA.TaggedValue;
taggedValue = taggedValues.GetAt(tc);
if("property" != taggedValue.Name && "AutoNum" != taggedValue.Name) continue;
Session.Output("TaggedValue: Name '" + taggedValue.Name + "'. Value '" + taggedValue.Value + "'");
if("property" != taggedValue.Name)
{
taggedValue.Value = "AutoNum=1;StartNum=1;Increment=1;";
taggedValue.Update();
element.Update();
hasTvProperty = true;
}
if("AutoNum" != taggedValue.Name)
{
taggedValue.Value = "True";
taggedValue.Update();
element.Update();
hasTvAutonum = true;
}
}
if(!hasTvProperty)
{
var tv = taggedValues.AddNew("property", "AutoNum=1;StartNum=1;Increment=1;");
tv.Update();
element.Update();
}
if(!hasTvAutonum)
{
var tv = taggedValues.AddNew("AutoNum", "True");
tv.Update();
element.Update();
}
break;
}
}
}
main();
Content of the t_attributetags table

JavaScript - Hangman - Logic Issue

I'm trying to get my Hangman game to check if the letter is found in the word, but as of now it's checking if that letter is found in every character of the word. It won't allow me to guess again after the first guess.
setScreen("WelcomeScreen");
//variables
var WordArray = ["apple", "word", "quiz"];
var currentWord = "";
var wrongCounter = 0;
var bodyPartCounter = 0;
var Guess = "";
//Welcome Screen Code
onEvent("letsGoBtn", "click", function () {
setScreen("playingHangmanScreen");
generateWord();
setUpScreenElements();
});
function generateWord() {
currentWord = WordArray[randomNumber(0,2)];
console.log(currentWord);
}
function setUpScreenElements(){
for (var i = 0; i < currentWord.length; i++) {
showElement("letterArea" + [i]);
}
var showCorrectHint = "hintWord" + currentWord;
showElement(showCorrectHint);
console.log(showCorrectHint);
}
//Guessing Code
onEvent("submitBtn", "click", function () {
Guess = getText("guessInputTxt");
console.log("The guess for " + currentWord + " is: " + Guess);
checkGuess();
});
function checkGuess() {
for (var i = 0; i < currentWord.length; i++) {
if (Guess == currentWord.charAt([i])) {
setText("letterArea" + [i], Guess);
console.log("Correctly guessed letter is: " + currentWord.charAt([i]));
}
else {
wrongCounter++;
console.log("wrongCounter for " + currentWord + " is: " + wrongCounter);
if (wrongCounter == currentWord.length) {
bodyPartCounter++;
showElement("wrongGuessImg" + bodyPartCounter);
setText("livesLeftNumber", (6-bodyPartCounter));
}
if (bodyPartCounter === 6) {
setScreen("gameOverScreen");
}
}
}
resetGuessInput();
}
function resetGuessInput () {
setText("guessInputTxt", " ");
Guess = " ";
wrongCounter = 0;
}
//Game Over Screen and Play Again Button
onEvent("playAgainBtn", "click", function () {
hideElement("hintWord" + currentWord);
generateWord();
setUpScreenElements();
setScreen("playingHangmanScreen");
for (var i = 0; i <currentWord.length; i++) {
setText("letterArea" + [i], " ");
}
for (var j = 1; j < 7; j++) {
hideElement("wrongGuessImg" + [j]);
}
bodyPartCounter = 0;
wrongCounter = 0;
setText("livesLeftNumber", "6");
});
//Victory Screen
onEvent("goHomeBtn", "click", function() {
setScreen("WelcomeScreen");
});
I've attached the code, as well as, included the link to see the app in action.
Here's a link to the app
Thanks in advance!
The checkGuess function needs to first determine where the letter appears in the word (or not), and then update the board one time, instead of updating it for each character:
function checkGuess() {
var foundAtIndex = -1;
for (var i = 0; i < currentWord.length; i++) {
if (Guess == currentWord.charAt([i])) {
foundAtIndex = i;
break;
}
}
if (foundAtIndex >= 0) {
setText("letterArea" + [foundAtIndex], Guess);
// etc...
Luckily, Javascript provides a nice IndexOf function for strings, so you can remove the loop entirely and condense that first part into:
var foundAtIndex = currentWord.indexOf(Guess);

Chart.js click on labels, using bar chart

i need help with my Chart.js interactivity. When I click on the label, I need to return the column(index) number at which I clicked.
I tried to use getElementsAtEvent but it only work if I click directly at chart.
This http://jsfiddle.net/yxz2sjam/ is pretty much what I am looking for but getPointsAtEvent is no longer available in the new versions.
canvas.onclick = function (evt) {
var points = chart.getPointsAtEvent(evt);
alert(chart.datasets[0].points.indexOf(points[0]));
};
I also found this http://jsfiddle.net/1Lngmtz7/ but it isn't working with bar chart.
var ctx = document.getElementById("myChart").getContext("2d");
var myRadarChart = new Chart(ctx, {
type: 'radar',
data: data
})
$('#myChart').click(function (e) {
var helpers = Chart.helpers;
var eventPosition = helpers.getRelativePosition(e, myRadarChart.chart);
var mouseX = eventPosition.x;
var mouseY = eventPosition.y;
var activePoints = [];
helpers.each(myRadarChart.scale.ticks, function (label, index) {
for (var i = this.getValueCount() - 1; i >= 0; i--) {
var pointLabelPosition = this.getPointPosition(i, this.getDistanceFromCenterForValue(this.options.reverse ? this.min : this.max) + 5);
var pointLabelFontSize = helpers.getValueOrDefault(this.options.pointLabels.fontSize, Chart.defaults.global.defaultFontSize);
var pointLabeFontStyle = helpers.getValueOrDefault(this.options.pointLabels.fontStyle, Chart.defaults.global.defaultFontStyle);
var pointLabeFontFamily = helpers.getValueOrDefault(this.options.pointLabels.fontFamily, Chart.defaults.global.defaultFontFamily);
var pointLabeFont = helpers.fontString(pointLabelFontSize, pointLabeFontStyle, pointLabeFontFamily);
ctx.font = pointLabeFont;
var labelsCount = this.pointLabels.length,
halfLabelsCount = this.pointLabels.length / 2,
quarterLabelsCount = halfLabelsCount / 2,
upperHalf = (i < quarterLabelsCount || i > labelsCount - quarterLabelsCount),
exactQuarter = (i === quarterLabelsCount || i === labelsCount - quarterLabelsCount);
var width = ctx.measureText(this.pointLabels[i]).width;
var height = pointLabelFontSize;
var x, y;
if (i === 0 || i === halfLabelsCount)
x = pointLabelPosition.x - width / 2;
else if (i < halfLabelsCount)
x = pointLabelPosition.x;
else
x = pointLabelPosition.x - width;
if (exactQuarter)
y = pointLabelPosition.y - height / 2;
else if (upperHalf)
y = pointLabelPosition.y - height;
else
y = pointLabelPosition.y
if ((mouseY >= y && mouseY <= y + height) && (mouseX >= x && mouseX <= x + width))
activePoints.push({ index: i, label: this.pointLabels[i] });
}
}, myRadarChart.scale);
var firstPoint = activePoints[0];
if (firstPoint !== undefined) {
alert(firstPoint.index + ': ' + firstPoint.label);
}
});
Thank for response.
I solve the problem with
document.getElementById("chart").onclick = function(e)
{
var activeElement = weatherMainChart.lastTooltipActive;
console.log(activeElement[0]._index);
};
this solution register clicks on chart and label, then I restricted it with e.layerY to register only clicks on label section.
document.getElementById("chart").onclick = function(e)
{
var activeElement = weatherMainChart.lastTooltipActive;
if(e.layerY > 843 && e.layerY < 866 && activeElement[0] !== undefined)
console.log(activeElement[0]._index);
};
If you add a click handler through the onClick option you can use the following code using the getElementsAtEventForMode() call:
function handleClick(evt) {
var col;
switch(chartType) {
case "horizontalBar":
this.getElementsAtEventForMode(evt, "y", 1).forEach(function(item) { col = item._index });
break;
case "bar":
this.getElementsAtEventForMode(evt, "x", 1).forEach(function(item) { col = item._index });
break;
}
if (!col) {
return;
}
alert("Column " + col + " was selected");
};
You'll probably need to add extra switch checks for other chart types but I'm sure you get the idea.
Using version 2.4.0, i created an onClick Event, and inside it
var activeIndex = localChart.tooltip._lastActive[0]._index;
var clickCoordinates = Chart.helpers.getRelativePosition(e, localChart.chart);
if (clickCoordinates.y >= 530) { //custom value, depends on chart style,size, etc
alert("clicked on " + localChart.data.labels[activeIndex]);
}
I Solved this problem with single or multiple label click you will be find using true/false
First you need to set your chartJs Id click
below code SessionChart = Your ChartJs ID e.g. ("myChart") I was replace it for my Id
document.getElementById("SessionChart").onclick = function (evt) {
var meta = SubscriberSessionChart.getDatasetMeta(0);
if (meta.$filler.chart.legend.legendItems[0].text.toLowerCase() "sessions")
{
if (meta.$filler.chart.legend.legendItems[0].hidden) {
sessionHidden = true;
}
}
}
here "sessions" = first label text
meta.$filler.chart.legend.legendItems[0].text.toLowerCase() = is your first label
from Array so you can get multiple label's click here true / false
if (meta.$filler.chart.legend.legendItems[0].hidden) = your label is not active then
you will get hidden true otherwise you will get false if not tick on label
by default label tick hidden is false in chart js

Why does my webpage submit the form when it loads, but no submit button has been clicked?

The windows.pageload event handler submits the page on page load. My intention is for this to wire the event handler to the submit event when the form submit button is clicked. What did I do wrong? Thanks!
function submit_data () {
var parent1Phone = $("parent1Phone").value;
var areaCode = parent1Phone.substring(0,3);
var prefix = parent1Phone.substring(4,7);
var suffix = parent1Phone.substring(8,12);
var firstName = $("firstName").value;
var lastName = $("lastName").value;
var sportID = $("sportID").value;
var entryFrom = $("entryFrom").value;
var linkSource = codeSource;
var primaryEmail = $("primaryEmail").value;
var graduationYear = $("graduationYear").value;
var postalCode = $("postalCode").value;
var parent1FirstName = $("parent1FirstName").value;
var parent1LastName = $("parent1LastName").value;
var parent1Relationship = $("parent1Relationship").value;
var parent1Phone1= areaCode;
var parent1Phone2 = prefix;
var parent1Phone3 = suffix;
var parent1PhoneType = $("parent1PhoneType").value; //No validation required. No non-choice allowed.
var parent1Email = $("parent1Email").value;
var parent1EmailConfirm = $("parent1Email").value;
var successDestination = success;
var errorDestination = failure;
var url = "http://recruit- match.ncsasports.org/fasttrack/saefentry/submitFullFormRemote.go?";
window.location.href = url + "firstName="+ firstName + "&lastName=" + "&lastName=" + lastName +"&sportID=" + sportID + "&entryFrom=" + entryFrom + "&linkSource=" + linkSource + "&primaryEmail=" + primaryEmail +"&graduationYear=" + graduationYear + "&postalCode=" + postalCode + "&parent1FirstName=" + parent1FirstName + "&parent1LastName=" + parent1LastName + "&parent1Relationship=" + parent1Relationship + "&parent1Phone1=" + parent1Phone1 + "&parent1Phone2=" + parent1Phone2 + "&parent1Phone3=" + parent1Phone3 + "&parent1PhoneType=" + parent1PhoneType + "&parent1Email=" + parent1Email + "&parent1EmailConfirm=" + parent1Email + "&successDestination=" + successDestination + "&errorDestination=" + errorDestination;
}
function prepareEventHandlers() {
$("frmNcsa").onclick = submit_data();
}
window.onload = function() {
prepareEventHandlers();
}
You are calling submit_data in the assignment $("frmNcsa").onclick = submit_data();, it should be $("#frmNcsa").click(submit_data);
assuming all the strings passed to the jQuery function are the ids of elements, they shold be prepended with #.