I have created a simple GUI with 2 textboxes and 1 button. The button handler goes as below
function handleButton1(e)
{
var app = UiApp.getActiveApplication();
var v1 = e.parameter.TextBox1;
var v2 = e.parameter.TextBox2;
Logger.log(v1);
app.getElementById("TextBox1").setText(v2);
app.getElementById("TextBox2").setText(v1);
return app;
}
When I run the app the textbox values are TextBox1 and TextBox2.
When press button then both the textbox value displayed is undefined.
Where am I going wrong.
With a server-side click handler, you need to explicitly include values in the handler event by using .addCallbackElement(). If you do so, the current value of the named elements you add will be included in the event delivered to your handler.
Since you are seeing undefined, it's likely that you didn't add the callbacks. You should have something like this in your UI definition:
var handler = app.createServerHandler('handleButton1')
.addCallbackElement(textBox1)
.addCallbackElement(textBox2);
button.addClickHandler(handler);
The name of the element will be used to label the callback value (.setName()), while the id will be used to access the element in your handler (.setId()).
Here's a working version of your script:
function doGet() {
var app = UiApp.createApplication();
var textBox1 = app.createTextBox().setName("TextBox1").setId("TextBox1");
var textBox2 = app.createTextBox().setName("TextBox2").setId("TextBox2");
var button = app.createButton('Swap Contents');
app.add(textBox1).add(textBox2).add(button);
var handler = app.createServerHandler('handleButton1')
.addCallbackElement(textBox1)
.addCallbackElement(textBox2);
button.addClickHandler(handler);
return app;
}
function handleButton1(e)
{
//Logger.log(JSON.stringify(e));
var app = UiApp.getActiveApplication();
var v1 = e.parameter.TextBox1;
var v2 = e.parameter.TextBox2;
app.getElementById("TextBox1").setText(v2);
app.getElementById("TextBox2").setText(v1);
return app;
}
Related
What will be the possible reason for the Drag And Drop functionality stopped working for me with Protractor.net c#?
Used http://marceljuenemann.github.io/angular-drag-and-drop-lists/demo/#/advanced to test this feature. But didn't worked for me.
Here is the sample code i tried:
Wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("//h3[.='Container (effects allowed: all)']")));
var elem = NgDriver.FindElement(By.XPath("//h3[.='Container (effects allowed: all)']"));
IWebElement parentElement = elem.FindElement(By.XPath(".."));
IWebElement mov = parentElement.FindElement(NgBy.Repeater("item in container.items"));
Wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("//h3[.='Container (effects allowed: move)']")));
var drropElem = NgDriver.FindElement(By.XPath("//h3[.='Container (effects allowed: move)']"));
IWebElement parentElement2 = drropElem.FindElement(By.XPath(".."));
IWebElement mov2 = parentElement2.FindElement(NgBy.Repeater("item in container.items"));
Actions builder = new Actions(Driver);
Actions action = builder.ClickAndHold(mov);
builder.Build();
action.Perform();
builder = new Actions(Driver);
action = builder.MoveToElement(mov2);
builder.Release(mov2);
builder.Build();
action.Perform();
Also Tried with DragAndDrop() function in thee Action .
Any help will be appreciated.
Create a Javscript file named "drop.js" and set the following content.
function e(e,t,n,i){var r=a.createEvent("DragEvent");r.initMouseEvent(t,!0,!0,o,0,0,0,c,g,!1,!1,!1,!1,0,null),Object.defineProperty(r,"dataTransfer",{get:function(){return d}}),e.dispatchEvent(r),o.setTimeout(i,n)}var t=arguments[0],n=arguments[1],i=arguments[2]||0,r=arguments[3]||0;if(!t.draggable)throw new Error("Source element is not draggable.");var a=t.ownerDocument,o=a.defaultView,l=t.getBoundingClientRect(),u=n?n.getBoundingClientRect():l,c=l.left+(l.width>>1),g=l.top+(l.height>>1),s=u.left+(u.width>>1)+i,f=u.top+(u.height>>1)+r,d=Object.create(Object.prototype,{_items:{value:{}},effectAllowed:{value:"all",writable:!0},dropEffect:{value:"move",writable:!0},files:{get:function(){return this._items.Files}},types:{get:function(){return Object.keys(this._items)}},setData:{value:function(e,t){this._items[e]=t}},getData:{value:function(e){return this._items[e]}},clearData:{value:function(e){delete this._items[e]}},setDragImage:{value:function(e){}}});if(n=a.elementFromPoint(s,f),!n)throw new Error("The target element is not interactable and need to be scrolled into the view.");u=n.getBoundingClientRect(),e(t,"dragstart",101,function(){var i=n.getBoundingClientRect();c=i.left+s-u.left,g=i.top+f-u.top,e(n,"dragenter",1,function(){e(n,"dragover",101,function(){n=a.elementFromPoint(c,g),e(n,"drop",1,function(){e(t,"dragend",1,callback)})})})})
And in your code
string jsScript = Path.Combine(currentDirectory, "JavaScript", "drop.js");
if (File.Exists(jsScript))
{
string dragAndDropScript = File.ReadAllText(jsScript);
IJavaScriptExecutor jse = (IJavaScriptExecutor)NgDriver;
jse.ExecuteScript(dragAndDropScript, dragFrom, dragTo);
}
drafFrom and dragTo are the controls used for dragging and dripping. These control should contain attributes like "draggable" or "dropable" in their HTML tag.
I have created a select interaction for my ol3 map and attached a select event handler.
selectInteraction = new ol.interaction.Select({
...
});
selectInteraction.on('select', function (evt) {
???;
});
How do I interrogate 'evt' to determine:
Which feature was clicked to fire the event?
The ID and other attributes of this feature?
Whether the feature was selected or deselected?
The select event emitted by the ol.SelectInteraction is documented here.
As you can see, evt.selected will be an array of all features that were just selected. It will not contain already selected features which are kept selected when clicking a new feature while the addCondition is true. These are the clicked features that were not already selected and matched the filters to be included in the selection.
Likewise, evt.deselected will contain any features that were just deselected.
You can get the ID and properties of each feature with:
var featureID = feature.getId()
var properties = feature.getProperties()
var someSpecificProperty = feature.get("property-name")
See the docs for ol.Feature for more info on the feature and it's attributes.
Here are some items that should help you.. evt.selected gets you the features that are selected. This example is on a clustered layer and you can use the get function on features selected to retrieve properties from the object selected. If you don't know properties available to you then use console.dir(evt) to examine the object using the console.
selectInteraction.on('select', function(evt){
var coord = evt.mapBrowserEvent.coordinate;
var selItems = evt.selected;
var sellength = selItems.length;
var rptFrame = parent.window.frames["rptframe"];
for (var i = 0; i < sellength; i++) {
var label = selItems[i].get('l');
var url = selItems[i].get('url');
if (url) {
rptFrame.location.href = url;
} else {
var feaObj = selItems[i].get('features');
if (feaObj.length == 1) {
url = feaObj[0].get('url');
rptFrame.location.href = url;
} else {
writeMultiSelect(rptFrame,selItems);
}
}
}
});
We have a customised TFS workflow, I want to be able to access the Reasons I can close a Bug (change the state from Active to Closed) from TFS so that we don't have to update our code every time we want to tweak our process.
This is what I have so far:
WorkItemType wiType = this.GetWorkItemStore().Projects[this.ProjectName].WorkItemTypes["Bug"];
var reason = wiType.FieldDefinitions["Reason"];
var state = wiType.FieldDefinitions["State"];
var filterList = new FieldFilterList();
FieldFilter filter = new FieldFilter(wiType.FieldDefinitions[CoreField.State], "Active");
filterList.Add(filter);
var allowedReasons = reason.FilteredAllowedValues(filterList);
However I'm not getting any results. I'd like to get a list of all the reasons why I can close a bug (Not Reproduceable, Fixed etc)
There isn't any easy way to get the transition via API directly as I know since the API read the allowed values from database directly.
The alternative way would be export the workitemtype definition via WorkItemType.Export() method and then get the information from it. Vaccano's answer in this question provided the entire code sample you can use.
Edited to give an example of how I solved this using the above recommendation:
public static List<Transition> GetTransistions(this WorkItemType workItemType)
{
List<Transition> currentTransistions;
// See if this WorkItemType has already had it's transistions figured out.
_allTransistions.TryGetValue(workItemType, out currentTransistions);
if (currentTransistions != null)
return currentTransistions;
// Get this worktype type as xml
XmlDocument workItemTypeXml = workItemType.Export(false);
// Create a dictionary to allow us to look up the "to" state using a "from" state.
var newTransistions = new List<Transition>();
// get the transistions node.
XmlNodeList transitionsList = workItemTypeXml.GetElementsByTagName("TRANSITIONS");
// As there is only one transistions item we can just get the first
XmlNode transitions = transitionsList[0];
// Iterate all the transitions
foreach (XmlNode transition in transitions)
{
XmlElement defaultReasonNode = transition["REASONS"]["DEFAULTREASON"];
var defaultReason = defaultReasonNode.Attributes["value"].Value;
var otherReasons = new List<string>();
XmlNodeList otherReasonsNodes = transition["REASONS"].SelectNodes("REASON");
foreach (XmlNode reasonNode in otherReasonsNodes)
{
var reason = reasonNode.Attributes["value"].Value;
otherReasons.Add(reason);
}
// save off the transistion
newTransistions.Add(new Transition
{
From = transition.Attributes["from"].Value,
To = transition.Attributes["to"].Value,
DefaultReason = defaultReason,
OtherReasons = otherReasons
});
}
// Save off this transition so we don't do it again if it is needed.
_allTransistions.Add(workItemType, newTransistions);
return newTransistions;
}
I have a knockout custom binding that wraps functionality to an image crop library (https://github.com/fengyuanchen/cropper .) I’m catching the cropend.cropper event to (eventually) attach the cropped output to an observable.
I’m using:
knockout 3.3
jquery 2.1.4
cropper 2.0
Here is the binding handler:
ko.bindingHandlers.cropper = {
init: function (element, valueAccessor, allBindings, viewModel, bindingContext) {
var $element = $(element);
var value = ko.unwrap(valueAccessor());
var a = 1;
ko.utils.registerEventHandler(element, "cropend.cropper", function (event) {
var previewOutputObservable = allBindings.get('previewOutput');
var valueAccessorFromAllBindings = allBindings.get('cropper');
var b = 1;
});
$element.cropper(value);
},
update: function(element, valueAccessor, allBindings, viewModel, bindingContext) {
var $element = $(element);
var value = ko.unwrap(valueAccessor());
var c = 1;
}
};
And here is the element I'm binding to:
<img class="img-responsive" data-bind="attr: {'src': sampleObservable}, cropper: { aspectRatio: 16/9 }, previewOutput: cropPreview "/>
When I put a breakpoint (in chrome) on var b = 1; none of the parameters in the init are defined except allBindings. I’ve seen several examples use this general pattern though (e.g. here). What am I doing wrong?
The outer variables are accessible through a closure context. Chrome tries to optimize the context by only including variables that are actually accessed in the closure code. Since element wasn't accessed in your code, it's not part of the context. This is a good feature as it means that variables that aren't used in any closure can be safely disposed.
This is either an issue with the Chrome debugging tools or a 'feature' of knockout.
Before var b = 1 I added the line var newValue = element. I put a breakpoint on that line and lo and behold the element parameter now has values.
It seems like the variables aren't initialized until they're used in the current context.
I am trying to set a variable to the selected value of a select menu inside the select menus handler. The problem is that my variable isn't recognized within the context of the select handler and if I pass the select handler the variables context I can no longer access the value of the selected variable. Does any one know a work around?
function object(){
this.testVar;
this.handler;
}
function makeObject(){
var result = new object();
result.testVar;
result.handler = handler;
return result;
}
function handler(){
alert($(this).val());
alert(this.testVar);
//ultimately this is what I want to do
this.testVar = $(this).val();
}
//If I do it this way $(this).val() is defined but not testVar
$("#test-select").on("change", {
testdata: this.testVar
}, this.handler);
//If I do it this way testVar is defined but not $(this).val()
$("#test-select").on("change", {
testdata: this.testVar
}, $.proxy(this.handler,this));
You need to decide which context you want the handler to execute in, and pass the other context as a parameter to your handler function.
When the handler is called, 'this' will initially refer to the changed HTML element. When you are setting up the listener, 'this' will refer to the object setting it up.
One example would be:
function handler(obj) {
alert($(this).val()); // this is the test-select object.
alert(obj.testVar);
}
var self = this;
$("#test-select").on("change", {
testdata: this.testVar
}, function() { self.handler(self); });